2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
36 #undef SHARED /* XXX */
41 #include <sys/param.h>
43 #include <sys/ioctl.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
50 #ifndef AFS_LINUX20_ENV
52 #include <netinet/if_ether.h>
56 /* included early because of name conflict on IOPEN */
57 #include <sys/inode.h>
61 #endif /* AFS_HPUX_ENV */
65 #include <afs/assert.h>
68 #include <afs/afsint.h>
69 #include <afs/vldbint.h>
70 #include <afs/errors.h>
71 #include <afs/ihandle.h>
72 #include <afs/vnode.h>
73 #include <afs/volume.h>
74 #include <afs/ptclient.h>
75 #include <afs/ptuser.h>
76 #include <afs/prs_fs.h>
79 #include <rx/rx_globals.h>
81 #if ! defined(AFS_SGI_ENV) && ! defined(AFS_AIX32_ENV) && ! defined(AFS_NT40_ENV) && ! defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
84 #if !defined(AFS_NT40_ENV)
87 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
89 #include <sys/statfs.h>
90 #include <sys/lockf.h>
92 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
97 #include <afs/cellconfig.h>
101 #include <afs/partition.h>
102 #include "viced_prototypes.h"
105 #include "callback.h"
106 #include <afs/unified_afs.h>
107 #include <afs/audit.h>
108 #include <afs/afsutil.h>
111 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
112 extern void FidZap(DirHandle * file);
113 extern void FidZero(DirHandle * file);
115 #ifdef AFS_PTHREAD_ENV
116 pthread_mutex_t fileproc_glock_mutex;
117 #endif /* AFS_PTHREAD_ENV */
120 #define afs_stat stat64
121 #define afs_fstat fstat64
122 #define afs_open open64
123 #else /* !O_LARGEFILE */
124 #define afs_stat stat
125 #define afs_fstat fstat
126 #define afs_open open
127 #endif /* !O_LARGEFILE */
130 /* Useful local defines used by this module */
133 #define MustNOTBeDIR 1
137 #define TVS_SSTATUS 2
140 #define TVS_MKDIR 0x10
142 #define CHK_FETCH 0x10
143 #define CHK_FETCHDATA 0x10
144 #define CHK_FETCHACL 0x11
145 #define CHK_FETCHSTATUS 0x12
146 #define CHK_STOREDATA 0x00
147 #define CHK_STOREACL 0x01
148 #define CHK_STORESTATUS 0x02
150 #define OWNERREAD 0400
151 #define OWNERWRITE 0200
152 #define OWNEREXEC 0100
153 #ifdef USE_GROUP_PERMS
154 #define GROUPREAD 0040
155 #define GROUPWRITE 0020
156 #define GROUPREXEC 0010
159 /* The following errors were not defined in NT. They are given unique
160 * names here to avoid any potential collision.
162 #define FSERR_ELOOP 90
163 #define FSERR_EOPNOTSUPP 122
164 #define FSERR_ECONNREFUSED 130
166 #define NOTACTIVECALL 0
169 #define CREATE_SGUID_ADMIN_ONLY 1
171 extern struct afsconf_dir *confDir;
172 extern afs_int32 dataVersionHigh;
175 static struct AFSCallStatistics AFSCallStats;
176 #if FS_STATS_DETAILED
177 struct fs_stats_FullPerfStats afs_FullPerfStats;
178 extern int AnonymousID;
179 #endif /* FS_STATS_DETAILED */
180 #if OPENAFS_VOL_STATS
181 static const char nullString[] = "";
182 #endif /* OPENAFS_VOL_STATS */
185 afs_int32 NothingYet;
188 struct afs_FSStats afs_fsstats;
193 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
195 extern afs_int32 implicitAdminRights;
196 extern afs_int32 readonlyServer;
197 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
198 extern afs_fsize_t CopyOnWrite_maxsize;
201 * Externals used by the xstat code.
203 extern VolPkgStats VStats;
204 extern int CEs, CEBlocks;
206 extern int HTs, HTBlocks;
208 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
209 register struct rx_call *Call, afs_sfsize_t Pos,
210 afs_sfsize_t Len, afs_int32 Int64Mode,
211 #if FS_STATS_DETAILED
212 afs_sfsize_t * a_bytesToFetchP,
213 afs_sfsize_t * a_bytesFetchedP
214 #endif /* FS_STATS_DETAILED */
217 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
218 struct AFSFid *Fid, struct client *client,
219 register struct rx_call *Call, afs_fsize_t Pos,
220 afs_fsize_t Length, afs_fsize_t FileLength,
222 #if FS_STATS_DETAILED
223 afs_sfsize_t * a_bytesToStoreP,
224 afs_sfsize_t * a_bytesStoredP
225 #endif /* FS_STATS_DETAILED */
228 #ifdef AFS_SGI_XFS_IOPS_ENV
229 #include <afs/xfsattrs.h>
231 GetLinkCount(Volume * avp, struct stat *astat)
233 if (!strcmp("xfs", astat->st_fstype)) {
234 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
236 return astat->st_nlink;
239 #define GetLinkCount(V, S) (S)->st_nlink
243 SpareComp(Volume * avolp)
245 register afs_int32 temp;
249 temp = V_maxquota(avolp);
251 /* no matter; doesn't check in this case */
255 temp = (temp * PctSpare) / 100;
266 * Set the volume synchronization parameter for this volume. If it changes,
267 * the Cache Manager knows that the volume must be purged from the stat cache.
270 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
273 /* date volume instance was created */
276 async->spare1 = avol->header->diskstuff.creationDate;
289 * Note that this function always returns a held host, so
290 * that CallPostamble can block without the host's disappearing.
291 * Call returns rx connection in passed in *tconn
294 CallPreamble(register struct rx_call *acall, int activecall,
295 struct rx_connection **tconn, struct host **ahostp)
298 struct client *tclient;
301 char hoststr[16], hoststr2[16];
302 #ifdef AFS_PTHREAD_ENV
303 struct ubik_client *uclient;
308 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
311 *tconn = rx_ConnectionOf(acall);
315 tclient = h_FindClient_r(*tconn);
317 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
321 thost = tclient->host;
322 if (tclient->prfail == 1) { /* couldn't get the CPS */
324 h_ReleaseClient_r(tclient);
326 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
330 retry_flag = 0; /* Retry once */
332 /* Take down the old connection and re-read the key file */
334 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
335 #ifdef AFS_PTHREAD_ENV
336 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
338 /* Is it still necessary to drop this? We hit the net, we should... */
344 code = hpr_Initialize(&uclient);
347 assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
350 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
353 h_ReleaseClient_r(tclient);
356 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
360 tclient->prfail = 2; /* Means re-eval client's cps */
361 h_ReleaseClient_r(tclient);
366 tclient->LastCall = thost->LastCall = FT_ApproxTime();
367 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
368 thost->ActiveCall = thost->LastCall;
371 if (thost->hostFlags & HOSTDELETED) {
373 ("Discarded a packet for deleted host %s:%d\n",
374 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
375 code = VBUSY; /* raced, so retry */
376 } else if ((thost->hostFlags & VENUSDOWN)
377 || (thost->hostFlags & HFE_LATER)) {
378 if (BreakDelayedCallBacks_r(thost)) {
380 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
381 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
382 ntohs(rxr_PortOf(*tconn))));
383 if (MultiProbeAlternateAddress_r(thost)) {
385 ("MultiProbe failed to find new address for host %s:%d\n",
386 afs_inet_ntoa_r(thost->host, hoststr),
387 ntohs(thost->port)));
391 ("MultiProbe found new address for host %s:%d\n",
392 afs_inet_ntoa_r(thost->host, hoststr),
393 ntohs(thost->port)));
394 if (BreakDelayedCallBacks_r(thost)) {
396 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
397 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
398 ntohs(rxr_PortOf(*tconn))));
407 h_ReleaseClient_r(tclient);
417 CallPostamble(register struct rx_connection *aconn, afs_int32 ret,
421 struct client *tclient;
425 tclient = h_FindClient_r(aconn);
428 thost = tclient->host;
429 if (thost->hostFlags & HERRORTRANS)
431 h_ReleaseClient_r(tclient);
434 if (ahost != thost) {
435 /* host/client recycle */
436 char hoststr[16], hoststr2[16];
437 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
439 afs_inet_ntoa_r(ahost->host, hoststr),
442 afs_inet_ntoa_r(thost->host, hoststr2),
446 /* return the reference taken in CallPreamble */
450 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
451 afs_inet_ntoa_r(thost->host, hoststr),
456 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
457 * does not decrement refcount on client->host */
462 return (translate ? sys_error_to_et(ret) : ret);
466 * Returns the volume and vnode pointers associated with file Fid; the lock
467 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
468 * are incremented and they must be eventualy released.
471 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
474 Error local_errorCode, errorCode = -1;
475 static struct timeval restartedat = { 0, 0 };
477 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
479 if ((*volptr) == 0) {
484 #ifdef AFS_DEMAND_ATTACH_FS
492 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
497 if ((errorCode == VOFFLINE) && (VInit < 2)) {
498 /* The volume we want may not be attached yet because
499 * the volume initialization is not yet complete.
500 * We can do several things:
501 * 1. return -1, which will cause users to see
502 * "connection timed out". This is more or
503 * less the same as always, except that the servers
504 * may appear to bounce up and down while they
505 * are actually restarting.
506 * 2. return VBUSY which will cause clients to
507 * sleep and retry for 6.5 - 15 minutes, depending
508 * on what version of the CM they are running. If
509 * the file server takes longer than that interval
510 * to attach the desired volume, then the application
511 * will see an ENODEV or EIO. This approach has
512 * the advantage that volumes which have been attached
513 * are immediately available, it keeps the server's
514 * immediate backlog low, and the call is interruptible
515 * by the user. Users see "waiting for busy volume."
516 * 3. sleep here and retry. Some people like this approach
517 * because there is no danger of seeing errors. However,
518 * this approach only works with a bounded number of
519 * clients, since the pending queues will grow without
520 * stopping. It might be better to find a way to take
521 * this call and stick it back on a queue in order to
522 * recycle this thread for a different request.
523 * 4. Return a new error code, which new cache managers will
524 * know enough to interpret as "sleep and retry", without
525 * the upper bound of 6-15 minutes that is imposed by the
526 * VBUSY handling. Users will see "waiting for
527 * busy volume," so they know that something is
528 * happening. Old cache managers must be able to do
529 * something reasonable with this, for instance, mark the
530 * server down. Fortunately, any error code < 0
531 * will elicit that behavior. See #1.
532 * 5. Some combination of the above. I like doing #2 for 10
533 * minutes, followed by #4. 3.1b and 3.2 cache managers
534 * will be fine as long as the restart period is
535 * not longer than 6.5 minutes, otherwise they may
536 * return ENODEV to users. 3.3 cache managers will be
537 * fine for 10 minutes, then will return
538 * ETIMEDOUT. 3.4 cache managers will just wait
539 * until the call works or fails definitively.
540 * NB. The problem with 2,3,4,5 is that old clients won't
541 * fail over to an alternate read-only replica while this
542 * server is restarting. 3.4 clients will fail over right away.
544 if (restartedat.tv_sec == 0) {
545 /* I'm not really worried about when we restarted, I'm */
546 /* just worried about when the first VBUSY was returned. */
547 FT_GetTimeOfDay(&restartedat, 0);
550 afs_perfstats.fs_nBusies++;
553 return (busyonrst ? VBUSY : restarting);
556 FT_GetTimeOfDay(&now, 0);
557 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
560 afs_perfstats.fs_nBusies++;
563 return (busyonrst ? VBUSY : restarting);
569 /* allow read operations on busy volume.
570 * must check local_errorCode because demand attach fs
571 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
572 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
573 #ifdef AFS_DEMAND_ATTACH_FS
574 /* DAFS case is complicated by the fact that local_errorCode can
575 * be VBUSY in cases where the volume is truly offline */
577 /* volume is in VOL_STATE_UNATTACHED */
580 #endif /* AFS_DEMAND_ATTACH_FS */
583 } else if (errorCode)
590 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
593 if ((*vptr)->disk.uniquifier != fid->Unique) {
594 VPutVnode(&fileCode, *vptr);
595 assert(fileCode == 0);
597 return (VNOVNODE); /* return the right error code, at least */
603 * This routine returns the ACL associated with the targetptr. If the
604 * targetptr isn't a directory, we access its parent dir and get the ACL
605 * thru the parent; in such case the parent's vnode is returned in
609 SetAccessList(Vnode ** targetptr, Volume ** volume,
610 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
611 AFSFid * Fid, int Lock)
613 if ((*targetptr)->disk.type == vDirectory) {
615 *ACL = VVnodeACL(*targetptr);
616 *ACLSize = VAclSize(*targetptr);
624 parentvnode = (*targetptr)->disk.parent;
625 VPutVnode(&errorCode, *targetptr);
629 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
632 *ACL = VVnodeACL(*parent);
633 *ACLSize = VAclSize(*parent);
634 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
636 if ((*targetptr)->disk.parent != parentvnode) {
637 VPutVnode(&errorCode, *parent);
648 /* Must not be called with H_LOCK held */
650 client_CheckRights(struct client *client, struct acl_accessList *ACL,
654 ObtainReadLock(&client->lock);
655 if (client->CPS.prlist_len > 0 && !client->deleted &&
656 client->host && !(client->host->hostFlags & HOSTDELETED))
657 acl_CheckRights(ACL, &client->CPS, rights);
658 ReleaseReadLock(&client->lock);
661 /* Must not be called with H_LOCK held */
663 client_HasAsMember(struct client *client, afs_int32 id)
667 ObtainReadLock(&client->lock);
668 if (client->CPS.prlist_len > 0 && !client->deleted &&
669 client->host && !(client->host->hostFlags & HOSTDELETED))
670 code = acl_IsAMember(id, &client->CPS);
671 ReleaseReadLock(&client->lock);
676 * Compare the directory's ACL with the user's access rights in the client
677 * connection and return the user's and everybody else's access permissions
678 * in rights and anyrights, respectively
681 GetRights(struct client *client, struct acl_accessList *ACL,
682 afs_int32 * rights, afs_int32 * anyrights)
684 extern prlist SystemAnyUserCPS;
685 afs_int32 hrights = 0;
686 #ifndef AFS_PTHREAD_ENV
690 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
691 ViceLog(0, ("CheckRights failed\n"));
696 client_CheckRights(client, ACL, rights);
698 /* wait if somebody else is already doing the getCPS call */
700 while (client->host->hostFlags & HCPS_INPROGRESS) {
701 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
702 #ifdef AFS_PTHREAD_ENV
703 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
704 #else /* AFS_PTHREAD_ENV */
706 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
707 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
708 #endif /* AFS_PTHREAD_ENV */
711 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
714 ("CheckRights: len=%u, for host=%s:%d\n",
715 client->host->hcps.prlist_len,
716 afs_inet_ntoa_r(client->host->host, hoststr),
717 ntohs(client->host->port)));
719 acl_CheckRights(ACL, &client->host->hcps, &hrights);
721 /* Allow system:admin the rights given with the -implicit option */
722 if (client_HasAsMember(client, SystemId))
723 *rights |= implicitAdminRights;
726 *anyrights |= hrights;
733 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
734 * a System:Administrator)
737 VanillaUser(struct client *client)
739 if (client_HasAsMember(client, SystemId))
740 return (0); /* not a system administrator, then you're "vanilla" */
747 * This unusual afs_int32-parameter routine encapsulates all volume package related
748 * operations together in a single function; it's called by almost all AFS
752 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
753 Vnode ** targetptr, int chkforDir, Vnode ** parent,
754 struct client **client, int locktype, afs_int32 * rights,
755 afs_int32 * anyrights)
757 struct acl_accessList *aCL; /* Internal access List */
758 int aCLSize; /* size of the access list */
759 Error errorCode = 0; /* return code to caller */
761 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
764 if (chkforDir == MustNOTBeDIR
765 && ((*targetptr)->disk.type == vDirectory))
767 else if (chkforDir == MustBeDIR
768 && ((*targetptr)->disk.type != vDirectory))
772 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
773 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
774 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
776 if (chkforDir == MustBeDIR)
777 assert((*parent) == 0);
779 if ((errorCode = GetClient(tcon, client)) != 0)
784 GetRights(*client, aCL, rights, anyrights);
785 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
786 if ((*targetptr)->disk.type != vDirectory) {
787 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
788 if ((*targetptr)->disk.owner == (*client)->ViceId)
789 (*rights) |= PRSFS_ADMINISTER;
791 (*rights) &= ~PRSFS_ADMINISTER;
793 #ifdef ADMIN_IMPLICIT_LOOKUP
794 /* admins get automatic lookup on everything */
795 if (!VanillaUser(*client))
796 (*rights) |= PRSFS_LOOKUP;
797 #endif /* ADMIN_IMPLICIT_LOOKUP */
800 } /*GetVolumePackage */
804 * This is the opposite of GetVolumePackage(), and is always used at the end of
805 * AFS calls to put back all used vnodes and the volume in the proper order!
808 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
809 Vnode * parentptr, Volume * volptr, struct client **client)
811 Error fileCode = 0; /* Error code returned by the volume package */
813 if (parentwhentargetnotdir) {
814 VPutVnode(&fileCode, parentwhentargetnotdir);
815 assert(!fileCode || (fileCode == VSALVAGE));
818 VPutVnode(&fileCode, targetptr);
819 assert(!fileCode || (fileCode == VSALVAGE));
822 VPutVnode(&fileCode, parentptr);
823 assert(!fileCode || (fileCode == VSALVAGE));
831 } /*PutVolumePackage */
834 VolumeOwner(register struct client *client, register Vnode * targetptr)
836 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
839 return (client->ViceId == owner);
842 * We don't have to check for host's cps since only regular
843 * viceid are volume owners.
845 return (client_HasAsMember(client, owner));
851 VolumeRootVnode(Vnode * targetptr)
853 return ((targetptr->vnodeNumber == ROOTVNODE)
854 && (targetptr->disk.uniquifier == 1));
856 } /*VolumeRootVnode */
859 * Check if target file has the proper access permissions for the Fetch
860 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
861 * StoreStatus) related calls
863 /* this code should probably just set a "priv" flag where all the audit events
864 * are now, and only generate the audit event once at the end of the routine,
865 * thus only generating the event if all the checks succeed, but only because
866 * of the privilege XXX
869 Check_PermissionRights(Vnode * targetptr, struct client *client,
870 afs_int32 rights, int CallingRoutine,
871 AFSStoreStatus * InStatus)
874 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
875 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
876 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
878 if (CallingRoutine & CHK_FETCH) {
879 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
880 if (targetptr->disk.type == vDirectory
881 || targetptr->disk.type == vSymlink) {
882 if (!(rights & PRSFS_LOOKUP)
883 #ifdef ADMIN_IMPLICIT_LOOKUP
884 /* grant admins fetch on all directories */
885 && VanillaUser(client)
886 #endif /* ADMIN_IMPLICIT_LOOKUP */
887 && !VolumeOwner(client, targetptr))
890 /* must have read access, or be owner and have insert access */
891 if (!(rights & PRSFS_READ)
892 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
895 if (CallingRoutine == CHK_FETCHDATA
896 && targetptr->disk.type == vFile)
897 #ifdef USE_GROUP_PERMS
898 if (!OWNSp(client, targetptr)
899 && !client_HasAsMember(client, targetptr->disk.owner)) {
901 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
905 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
910 * The check with the ownership below is a kludge to allow
911 * reading of files created with no read permission. The owner
912 * of the file is always allowed to read it.
914 if ((client->ViceId != targetptr->disk.owner)
915 && VanillaUser(client))
917 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
918 modeBits) ? 0 : EACCES);
920 } else { /* !VanillaUser(client) && !FetchData */
922 osi_audit(PrivilegeEvent, 0, AUD_ID,
923 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
926 } else { /* a store operation */
927 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
928 && (CallingRoutine != CHK_STOREACL)
929 && (targetptr->disk.type == vFile)) {
930 /* bypass protection checks on first store after a create
931 * for the creator; also prevent chowns during this time
932 * unless you are a system administrator */
933 /****** InStatus->Owner && UnixModeBits better be SET!! */
934 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
937 else if (VanillaUser(client))
938 return (EPERM); /* Was EACCES */
940 osi_audit(PrivilegeEvent, 0, AUD_ID,
941 (client ? client->ViceId : 0), AUD_INT,
942 CallingRoutine, AUD_END);
945 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
946 osi_audit(PrivilegeEvent, 0, AUD_ID,
947 (client ? client->ViceId : 0), AUD_INT,
948 CallingRoutine, AUD_END);
950 if (readonlyServer) {
953 if (CallingRoutine == CHK_STOREACL) {
954 if (!(rights & PRSFS_ADMINISTER)
955 && !VolumeOwner(client, targetptr))
957 } else { /* store data or status */
958 /* watch for chowns and chgrps */
959 if (CHOWN(InStatus, targetptr)
960 || CHGRP(InStatus, targetptr)) {
963 else if (VanillaUser(client))
964 return (EPERM); /* Was EACCES */
966 osi_audit(PrivilegeEvent, 0, AUD_ID,
967 (client ? client->ViceId : 0), AUD_INT,
968 CallingRoutine, AUD_END);
970 /* must be sysadmin to set suid/sgid bits */
971 if ((InStatus->Mask & AFS_SETMODE) &&
973 (InStatus->UnixModeBits & 0xc00) != 0) {
975 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
979 if (VanillaUser(client))
982 osi_audit(PrivSetID, 0, AUD_ID,
983 (client ? client->ViceId : 0), AUD_INT,
984 CallingRoutine, AUD_END);
986 if (CallingRoutine == CHK_STOREDATA) {
989 if (!(rights & PRSFS_WRITE))
991 /* Next thing is tricky. We want to prevent people
992 * from writing files sans 0200 bit, but we want
993 * creating new files with 0444 mode to work. We
994 * don't check the 0200 bit in the "you are the owner"
995 * path above, but here we check the bit. However, if
996 * you're a system administrator, we ignore the 0200
997 * bit anyway, since you may have fchowned the file,
999 #ifdef USE_GROUP_PERMS
1000 if ((targetptr->disk.type == vFile)
1001 && VanillaUser(client)) {
1002 if (!OWNSp(client, targetptr)
1003 && !client_HasAsMember(client, targetptr->disk.owner)) {
1005 ((GROUPWRITE & targetptr->disk.modeBits)
1009 ((OWNERWRITE & targetptr->disk.modeBits)
1014 if ((targetptr->disk.type != vDirectory)
1015 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1018 if (VanillaUser(client))
1021 osi_audit(PrivilegeEvent, 0, AUD_ID,
1022 (client ? client->ViceId : 0),
1023 AUD_INT, CallingRoutine, AUD_END);
1025 } else { /* a status store */
1028 if (targetptr->disk.type == vDirectory) {
1029 if (!(rights & PRSFS_DELETE)
1030 && !(rights & PRSFS_INSERT))
1032 } else { /* a file or symlink */
1033 if (!(rights & PRSFS_WRITE))
1043 } /*Check_PermissionRights */
1047 * The Access List information is converted from its internal form in the
1048 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1049 * external form and returned back to the caller, via the AccessList
1053 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1054 struct AFSOpaque *AccessList)
1056 char *eACL; /* External access list placeholder */
1058 if (acl_Externalize_pr
1059 (hpr_IdToName, (targetptr->disk.type ==
1060 vDirectory ? VVnodeACL(targetptr) :
1061 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1064 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1065 acl_FreeExternalACL(&eACL);
1068 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1069 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1071 acl_FreeExternalACL(&eACL);
1074 } /*RXFetch_AccessList */
1078 * The Access List information is converted from its external form in the
1079 * input AccessList structure to the internal representation and copied into
1080 * the target dir's vnode storage.
1083 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1085 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1087 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1090 if ((newACL->size + 4) > VAclSize(targetptr))
1092 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1093 acl_FreeACL(&newACL);
1096 } /*RXStore_AccessList */
1099 /* In our current implementation, each successive data store (new file
1100 * data version) creates a new inode. This function creates the new
1101 * inode, copies the old inode's contents to the new one, remove the old
1102 * inode (i.e. decrement inode count -- if it's currently used the delete
1103 * will be delayed), and modify some fields (i.e. vnode's
1104 * disk.inodeNumber and cloned)
1106 #define COPYBUFFSIZE 8192
1107 #define MAXFSIZE (~(afs_fsize_t) 0)
1109 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_fsize_t off, afs_fsize_t len)
1111 Inode ino, nearInode;
1114 register afs_fsize_t size;
1115 register int length;
1117 int rc; /* return code */
1118 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1119 FdHandle_t *targFdP; /* Source Inode file handle */
1120 FdHandle_t *newFdP; /* Dest Inode file handle */
1122 if (targetptr->disk.type == vDirectory)
1123 DFlush(); /* just in case? */
1125 VN_GET_LEN(size, targetptr);
1133 buff = (char *)malloc(COPYBUFFSIZE);
1138 ino = VN_GET_INO(targetptr);
1139 if (!VALID_INO(ino)) {
1141 VTakeOffline(volptr);
1142 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1146 targFdP = IH_OPEN(targetptr->handle);
1147 if (targFdP == NULL) {
1150 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1151 targetptr->vnodeNumber, V_id(volptr), rc));
1153 VTakeOffline(volptr);
1157 nearInode = VN_GET_INO(targetptr);
1159 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1160 VPartitionPath(V_partition(volptr)), nearInode,
1161 V_id(volptr), targetptr->vnodeNumber,
1162 targetptr->disk.uniquifier,
1163 (int)targetptr->disk.dataVersion);
1164 if (!VALID_INO(ino)) {
1166 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1167 volptr->partition->name, V_id(volptr), errno));
1172 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1173 newFdP = IH_OPEN(newH);
1174 assert(newFdP != NULL);
1176 FDH_SEEK(targFdP, off, SEEK_SET);
1177 FDH_SEEK(newFdP, off, SEEK_SET);
1179 if (size > COPYBUFFSIZE) { /* more than a buffer */
1180 length = COPYBUFFSIZE;
1181 size -= COPYBUFFSIZE;
1186 rdlen = FDH_READ(targFdP, buff, length);
1187 if (rdlen == length)
1188 wrlen = FDH_WRITE(newFdP, buff, length);
1191 /* Callers of this function are not prepared to recover
1192 * from error that put the filesystem in an inconsistent
1193 * state. Make sure that we force the volume off-line if
1194 * we some error other than ENOSPC - 4.29.99)
1196 * In case we are unable to write the required bytes, and the
1197 * error code indicates that the disk is full, we roll-back to
1198 * the initial state.
1200 if ((rdlen != length) || (wrlen != length)) {
1201 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1203 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1204 volptr->partition->name, V_id(volptr)));
1205 /* remove destination inode which was partially copied till now */
1206 FDH_REALLYCLOSE(newFdP);
1208 FDH_REALLYCLOSE(targFdP);
1209 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1212 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1213 rc, V_id(volptr), volptr->partition->name));
1214 VTakeOffline(volptr);
1220 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1221 V_id(volptr), volptr->partition->name, length, rdlen,
1223 #if defined(AFS_DEMAND_ATTACH_FS)
1224 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1226 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1228 /* Decrement this inode so salvager doesn't find it. */
1229 FDH_REALLYCLOSE(newFdP);
1231 FDH_REALLYCLOSE(targFdP);
1232 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1234 VTakeOffline(volptr);
1238 #ifndef AFS_PTHREAD_ENV
1240 #endif /* !AFS_PTHREAD_ENV */
1242 FDH_REALLYCLOSE(targFdP);
1243 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1244 V_parentId(volptr));
1246 IH_RELEASE(targetptr->handle);
1248 rc = FDH_SYNC(newFdP);
1251 targetptr->handle = newH;
1252 VN_SET_INO(targetptr, ino);
1253 targetptr->disk.cloned = 0;
1254 /* Internal change to vnode, no user level change to volume - def 5445 */
1255 targetptr->changed_oldTime = 1;
1257 return 0; /* success */
1261 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_fsize_t off, afs_fsize_t size) {
1262 char *buff = (char *)malloc(COPYBUFFSIZE);
1263 register int length;
1268 FDH_SEEK(targFdP, off, SEEK_SET);
1269 FDH_SEEK(newFdP, off, SEEK_SET);
1271 if (size > FDH_SIZE(targFdP) - off) size = FDH_SIZE(targFdP) - off;
1273 if (size > COPYBUFFSIZE) { /* more than a buffer */
1274 length = COPYBUFFSIZE;
1275 size -= COPYBUFFSIZE;
1280 rdlen = FDH_READ(targFdP, buff, length);
1281 if (rdlen == length)
1282 wrlen = FDH_WRITE(newFdP, buff, length);
1286 if ((rdlen != length) || (wrlen != length)) {
1287 /* no error recovery, at the worst we'll have a "hole" in the file */
1298 * Common code to handle with removing the Name (file when it's called from
1299 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1300 * given directory, parentptr.
1302 int DT1 = 0, DT0 = 0;
1304 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1305 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1307 DirHandle childdir; /* Handle for dir package I/O */
1308 Error errorCode = 0;
1311 /* watch for invalid names */
1312 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1314 if (parentptr->disk.cloned) {
1315 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1316 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1318 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1324 /* check that the file is in the directory */
1325 SetDirHandle(dir, parentptr);
1326 if (Lookup(dir, Name, fileFid))
1328 fileFid->Volume = V_id(volptr);
1330 /* just-in-case check for something causing deadlock */
1331 if (fileFid->Vnode == parentptr->vnodeNumber)
1334 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1338 if (ChkForDir == MustBeDIR) {
1339 if ((*targetptr)->disk.type != vDirectory)
1341 } else if ((*targetptr)->disk.type == vDirectory)
1344 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1346 * If the uniquifiers dont match then instead of asserting
1347 * take the volume offline and return VSALVAGE
1349 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1350 VTakeOffline(volptr);
1352 ("Volume %u now offline, must be salvaged.\n",
1354 errorCode = VSALVAGE;
1358 if (ChkForDir == MustBeDIR) {
1359 SetDirHandle(&childdir, *targetptr);
1360 if (IsEmpty(&childdir) != 0)
1362 DZap((afs_int32 *) &childdir);
1364 (*targetptr)->delete = 1;
1365 } else if ((--(*targetptr)->disk.linkCount) == 0)
1366 (*targetptr)->delete = 1;
1367 if ((*targetptr)->delete) {
1368 if (VN_GET_INO(*targetptr)) {
1370 IH_REALLYCLOSE((*targetptr)->handle);
1372 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1373 V_parentId(volptr));
1374 IH_RELEASE((*targetptr)->handle);
1375 if (errorCode == -1) {
1377 ("DT: inode=%s, name=%s, errno=%d\n",
1378 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1380 if (errno != ENOENT)
1382 VTakeOffline(volptr);
1384 ("Volume %u now offline, must be salvaged.\n",
1392 VN_SET_INO(*targetptr, (Inode) 0);
1394 afs_fsize_t adjLength;
1395 VN_GET_LEN(adjLength, *targetptr);
1396 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1400 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1402 code = Delete(dir, (char *)Name);
1405 ("Error %d deleting %s\n", code,
1406 (((*targetptr)->disk.type ==
1407 Directory) ? "directory" : "file")));
1408 VTakeOffline(volptr);
1410 ("Volume %u now offline, must be salvaged.\n",
1423 * This routine updates the parent directory's status block after the
1424 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1425 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1429 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1430 int author, int linkcount,
1431 #if FS_STATS_DETAILED
1432 char a_inSameNetwork
1433 #endif /* FS_STATS_DETAILED */
1436 afs_fsize_t newlength; /* Holds new directory length */
1437 afs_fsize_t parentLength;
1439 #if FS_STATS_DETAILED
1440 Date currDate; /*Current date */
1441 int writeIdx; /*Write index to bump */
1442 int timeIdx; /*Authorship time index to bump */
1443 #endif /* FS_STATS_DETAILED */
1445 parentptr->disk.dataVersion++;
1446 newlength = (afs_fsize_t) Length(dir);
1448 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1449 * (create, symlink, link, makedir) so we need to check if we have enough space
1450 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1451 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1453 VN_GET_LEN(parentLength, parentptr);
1454 if (nBlocks(newlength) != nBlocks(parentLength)) {
1455 VAdjustDiskUsage(&errorCode, volptr,
1456 (nBlocks(newlength) - nBlocks(parentLength)),
1457 (nBlocks(newlength) - nBlocks(parentLength)));
1459 VN_SET_LEN(parentptr, newlength);
1461 #if FS_STATS_DETAILED
1463 * Update directory write stats for this volume. Note that the auth
1464 * counter is located immediately after its associated ``distance''
1467 if (a_inSameNetwork)
1468 writeIdx = VOL_STATS_SAME_NET;
1470 writeIdx = VOL_STATS_DIFF_NET;
1471 V_stat_writes(volptr, writeIdx)++;
1472 if (author != AnonymousID) {
1473 V_stat_writes(volptr, writeIdx + 1)++;
1477 * Update the volume's authorship information in response to this
1478 * directory operation. Get the current time, decide to which time
1479 * slot this operation belongs, and bump the appropriate slot.
1481 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1483 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1484 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1485 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1486 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1487 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1488 if (parentptr->disk.author == author) {
1489 V_stat_dirSameAuthor(volptr, timeIdx)++;
1491 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1493 #endif /* FS_STATS_DETAILED */
1495 parentptr->disk.author = author;
1496 parentptr->disk.linkCount = linkcount;
1497 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1498 parentptr->disk.serverModifyTime = FT_ApproxTime();
1499 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1504 * Update the target file's (or dir's) status block after the specified
1505 * operation is complete. Note that some other fields maybe updated by
1506 * the individual module.
1509 /* XXX INCOMPLETE - More attention is needed here! */
1511 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1512 struct client *client, AFSStoreStatus * InStatus,
1513 Vnode * parentptr, Volume * volptr,
1516 #if FS_STATS_DETAILED
1517 Date currDate; /*Current date */
1518 int writeIdx; /*Write index to bump */
1519 int timeIdx; /*Authorship time index to bump */
1520 #endif /* FS_STATS_DETAILED */
1522 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1523 targetptr->disk.parent = parentptr->vnodeNumber;
1524 VN_SET_LEN(targetptr, length);
1525 /* targetptr->disk.group = 0; save some cycles */
1526 targetptr->disk.modeBits = 0777;
1527 targetptr->disk.owner = client->ViceId;
1528 targetptr->disk.dataVersion = 0; /* consistent with the client */
1529 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1530 /* the inode was created in Alloc_NewVnode() */
1532 #if FS_STATS_DETAILED
1534 * Update file write stats for this volume. Note that the auth
1535 * counter is located immediately after its associated ``distance''
1538 if (client->InSameNetwork)
1539 writeIdx = VOL_STATS_SAME_NET;
1541 writeIdx = VOL_STATS_DIFF_NET;
1542 V_stat_writes(volptr, writeIdx)++;
1543 if (client->ViceId != AnonymousID) {
1544 V_stat_writes(volptr, writeIdx + 1)++;
1548 * We only count operations that DON'T involve creating new objects
1549 * (files, symlinks, directories) or simply setting status as
1550 * authorship-change operations.
1552 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1554 * Update the volume's authorship information in response to this
1555 * file operation. Get the current time, decide to which time
1556 * slot this operation belongs, and bump the appropriate slot.
1558 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1561 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1562 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1563 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1564 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1565 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1566 VOL_STATS_TIME_IDX_5);
1567 if (targetptr->disk.author == client->ViceId) {
1568 V_stat_fileSameAuthor(volptr, timeIdx)++;
1570 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1573 #endif /* FS_STATS_DETAILED */
1575 if (!(Caller & TVS_SSTATUS))
1576 targetptr->disk.author = client->ViceId;
1577 if (Caller & TVS_SDATA) {
1578 targetptr->disk.dataVersion++;
1579 if (VanillaUser(client)) {
1580 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1581 #ifdef CREATE_SGUID_ADMIN_ONLY
1582 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1586 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1587 /* store status, must explicitly request to change the date */
1588 if (InStatus->Mask & AFS_SETMODTIME)
1589 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1590 } else { /* other: date always changes, but perhaps to what is specified by caller */
1591 targetptr->disk.unixModifyTime =
1592 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1593 ClientModTime : FT_ApproxTime());
1595 if (InStatus->Mask & AFS_SETOWNER) {
1596 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1597 if (VanillaUser(client)) {
1598 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1599 #ifdef CREATE_SGUID_ADMIN_ONLY
1600 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1603 targetptr->disk.owner = InStatus->Owner;
1604 if (VolumeRootVnode(targetptr)) {
1605 Error errorCode = 0; /* what should be done with this? */
1607 V_owner(targetptr->volumePtr) = InStatus->Owner;
1608 VUpdateVolume(&errorCode, targetptr->volumePtr);
1611 if (InStatus->Mask & AFS_SETMODE) {
1612 int modebits = InStatus->UnixModeBits;
1613 #define CREATE_SGUID_ADMIN_ONLY 1
1614 #ifdef CREATE_SGUID_ADMIN_ONLY
1615 if (VanillaUser(client))
1616 modebits = modebits & 0777;
1618 if (VanillaUser(client)) {
1619 targetptr->disk.modeBits = modebits;
1621 targetptr->disk.modeBits = modebits;
1624 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1625 CHK_STOREDATA, AUD_END);
1629 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1630 CHK_STORESTATUS, AUD_END);
1637 targetptr->disk.serverModifyTime = FT_ApproxTime();
1638 if (InStatus->Mask & AFS_SETGROUP)
1639 targetptr->disk.group = InStatus->Group;
1640 /* vnode changed : to be written back by VPutVnode */
1641 targetptr->changed_newTime = 1;
1643 } /*Update_TargetVnodeStatus */
1647 * Fills the CallBack structure with the expiration time and type of callback
1648 * structure. Warning: this function is currently incomplete.
1651 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1653 /* CallBackTime could not be 0 */
1654 if (CallBackTime == 0) {
1655 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1656 CallBack->ExpirationTime = 0;
1658 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1659 CallBack->CallBackVersion = CALLBACK_VERSION;
1660 CallBack->CallBackType = CB_SHARED; /* The default for now */
1662 } /*SetCallBackStruct */
1666 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1667 * allocation; if some error occured (exceeded volume quota or partition
1668 * was full, or whatever), it frees the space back and returns the code.
1669 * We usually pre-adjust the volume space to make sure that there's
1670 * enough space before consuming some.
1673 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1674 afs_sfsize_t checkLength)
1679 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1681 VAdjustDiskUsage(&nc, volptr, -length, 0);
1682 if (rc == VOVERQUOTA) {
1684 ("Volume %u (%s) is full\n", V_id(volptr),
1688 if (rc == VDISKFULL) {
1690 ("Partition %s that contains volume %u is full\n",
1691 volptr->partition->name, V_id(volptr)));
1694 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1699 } /*AdjustDiskUsage */
1702 * Common code that handles the creation of a new file (SAFS_CreateFile and
1703 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1706 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1707 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1708 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1710 Error errorCode = 0; /* Error code returned back */
1713 Inode nearInode; /* hint for inode allocation in solaris */
1716 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1717 BlocksPreallocatedForVnode))) {
1719 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1720 (afs_intmax_t) BlocksPreallocatedForVnode));
1724 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1725 if (errorCode != 0) {
1726 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1729 OutFid->Volume = V_id(volptr);
1730 OutFid->Vnode = (*targetptr)->vnodeNumber;
1731 OutFid->Unique = (*targetptr)->disk.uniquifier;
1733 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1735 /* create the inode now itself */
1737 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1738 VPartitionPath(V_partition(volptr)), nearInode,
1739 V_id(volptr), (*targetptr)->vnodeNumber,
1740 (*targetptr)->disk.uniquifier, 1);
1742 /* error in creating inode */
1743 if (!VALID_INO(inode)) {
1745 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1746 (*targetptr)->volumePtr->header->diskstuff.id,
1747 (*targetptr)->vnodeNumber, errno));
1748 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1749 (*targetptr)->delete = 1; /* delete vnode */
1752 VN_SET_INO(*targetptr, inode);
1753 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1755 /* copy group from parent dir */
1756 (*targetptr)->disk.group = parentptr->disk.group;
1758 if (parentptr->disk.cloned) {
1759 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1760 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1761 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1762 /* delete the vnode previously allocated */
1763 (*targetptr)->delete = 1;
1764 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1765 IH_REALLYCLOSE((*targetptr)->handle);
1766 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1768 ("Alloc_NewVnode: partition %s idec %s failed\n",
1769 volptr->partition->name, PrintInode(NULL, inode)));
1770 IH_RELEASE((*targetptr)->handle);
1776 /* add the name to the directory */
1777 SetDirHandle(dir, parentptr);
1778 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1779 (*targetptr)->delete = 1;
1780 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1781 IH_REALLYCLOSE((*targetptr)->handle);
1782 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1784 ("Alloc_NewVnode: partition %s idec %s failed\n",
1785 volptr->partition->name, PrintInode(NULL, inode)));
1786 IH_RELEASE((*targetptr)->handle);
1792 } /*Alloc_NewVnode */
1796 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1800 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1802 int Time; /* Used for time */
1803 int writeVnode = targetptr->changed_oldTime; /* save original status */
1805 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1806 Time = FT_ApproxTime();
1807 switch (LockingType) {
1810 if (Time > targetptr->disk.lock.lockTime)
1811 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1813 Time += AFS_LOCKWAIT;
1814 if (LockingType == LockRead) {
1815 if ( !(rights & PRSFS_LOCK) &&
1816 !(rights & PRSFS_WRITE) &&
1817 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1820 if (targetptr->disk.lock.lockCount >= 0) {
1821 ++(targetptr->disk.lock.lockCount);
1822 targetptr->disk.lock.lockTime = Time;
1825 } else if (LockingType == LockWrite) {
1826 if ( !(rights & PRSFS_WRITE) &&
1827 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1830 if (targetptr->disk.lock.lockCount == 0) {
1831 targetptr->disk.lock.lockCount = -1;
1832 targetptr->disk.lock.lockTime = Time;
1838 Time += AFS_LOCKWAIT;
1839 if (targetptr->disk.lock.lockCount != 0)
1840 targetptr->disk.lock.lockTime = Time;
1845 if ((--targetptr->disk.lock.lockCount) <= 0)
1846 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1850 targetptr->changed_oldTime = writeVnode; /* restore old status */
1851 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1854 } /*HandleLocking */
1856 /* Checks if caller has the proper AFS and Unix (WRITE) access permission to the target directory; Prfs_Mode refers to the AFS Mode operation while rights contains the caller's access permissions to the directory. */
1859 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1863 if (!(rights & Prfs_Mode))
1865 if ((targetptr->disk.type != vDirectory)
1866 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1872 * If some flags (i.e. min or max quota) are set, the volume's in disk
1873 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1874 * update, if applicable.
1877 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1878 char *Name, char *OfflineMsg, char *Motd)
1880 Error errorCode = 0;
1882 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1883 V_minquota(volptr) = StoreVolStatus->MinQuota;
1884 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1885 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1886 if (strlen(OfflineMsg) > 0) {
1887 strcpy(V_offlineMessage(volptr), OfflineMsg);
1889 if (strlen(Name) > 0) {
1890 strcpy(V_name(volptr), Name);
1892 #if OPENAFS_VOL_STATS
1894 * We don't overwrite the motd field, since it's now being used
1898 if (strlen(Motd) > 0) {
1899 strcpy(V_motd(volptr), Motd);
1901 #endif /* FS_STATS_DETAILED */
1902 VUpdateVolume(&errorCode, volptr);
1905 } /*RXUpdate_VolumeStatus */
1909 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1910 char **motd, Volume * volptr)
1914 status->Vid = V_id(volptr);
1915 status->ParentId = V_parentId(volptr);
1916 status->Online = V_inUse(volptr);
1917 status->InService = V_inService(volptr);
1918 status->Blessed = V_blessed(volptr);
1919 status->NeedsSalvage = V_needsSalvaged(volptr);
1920 if (VolumeWriteable(volptr))
1921 status->Type = ReadWrite;
1923 status->Type = ReadOnly;
1924 status->MinQuota = V_minquota(volptr);
1925 status->MaxQuota = V_maxquota(volptr);
1926 status->BlocksInUse = V_diskused(volptr);
1927 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1928 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1930 /* now allocate and copy these things; they're freed by the RXGEN stub */
1931 temp = strlen(V_name(volptr)) + 1;
1932 *name = malloc(temp);
1934 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1937 strcpy(*name, V_name(volptr));
1938 temp = strlen(V_offlineMessage(volptr)) + 1;
1939 *offMsg = malloc(temp);
1941 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1944 strcpy(*offMsg, V_offlineMessage(volptr));
1945 #if OPENAFS_VOL_STATS
1948 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1951 strcpy(*motd, nullString);
1953 temp = strlen(V_motd(volptr)) + 1;
1954 *motd = malloc(temp);
1956 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1959 strcpy(*motd, V_motd(volptr));
1960 #endif /* FS_STATS_DETAILED */
1962 } /*RXGetVolumeStatus */
1966 FileNameOK(register char *aname)
1968 register afs_int32 i, tc;
1971 /* watch for @sys on the right */
1972 if (strcmp(aname + i - 4, "@sys") == 0)
1975 while ((tc = *aname++)) {
1977 return 0; /* very bad character to encounter */
1979 return 1; /* file name is ok */
1985 * This variant of symlink is expressly to support the AFS/DFS translator
1986 * and is not supported by the AFS fileserver. We just return EINVAL.
1987 * The cache manager should not generate this call to an AFS cache manager.
1990 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1991 char *LinkContents, struct AFSStoreStatus *InStatus,
1992 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1993 struct AFSFetchStatus *OutDirStatus,
1994 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2000 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2001 struct FsCmdInputs * Inputs,
2002 struct FsCmdOutputs * Outputs)
2006 switch (Inputs->command) {
2010 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2011 Inputs->command, Outputs->code));
2016 static struct afs_buffer {
2017 struct afs_buffer *next;
2018 } *freeBufferList = 0;
2019 static int afs_buffersAlloced = 0;
2022 FreeSendBuffer(register struct afs_buffer *adata)
2025 afs_buffersAlloced--;
2026 adata->next = freeBufferList;
2027 freeBufferList = adata;
2031 } /*FreeSendBuffer */
2033 /* allocate space for sender */
2037 register struct afs_buffer *tp;
2040 afs_buffersAlloced++;
2041 if (!freeBufferList) {
2044 tmp = malloc(sendBufSize);
2046 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2051 tp = freeBufferList;
2052 freeBufferList = tp->next;
2056 } /*AllocSendBuffer */
2057 #endif /* AFS_NT40_ENV */
2060 * This routine returns the status info associated with the targetptr vnode
2061 * in the AFSFetchStatus structure. Some of the newer fields, such as
2062 * SegSize and Group are not yet implemented
2066 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2067 afs_int32 anyrights, Vnode * parentptr)
2069 /* initialize return status from a vnode */
2070 status->InterfaceVersion = 1;
2071 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2072 status->errorCode = 0;
2073 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2074 if (targetptr->disk.type == vFile)
2075 status->FileType = File;
2076 else if (targetptr->disk.type == vDirectory)
2077 status->FileType = Directory;
2078 else if (targetptr->disk.type == vSymlink)
2079 status->FileType = SymbolicLink;
2081 status->FileType = Invalid; /*invalid type field */
2082 status->LinkCount = targetptr->disk.linkCount;
2084 afs_fsize_t targetLen;
2085 VN_GET_LEN(targetLen, targetptr);
2086 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2088 status->DataVersion = targetptr->disk.dataVersion;
2089 status->Author = targetptr->disk.author;
2090 status->Owner = targetptr->disk.owner;
2091 status->CallerAccess = rights;
2092 status->AnonymousAccess = anyrights;
2093 status->UnixModeBits = targetptr->disk.modeBits;
2094 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2095 status->ParentVnode =
2096 (status->FileType ==
2097 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2098 status->ParentUnique =
2099 (status->FileType ==
2100 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2101 status->ServerModTime = targetptr->disk.serverModifyTime;
2102 status->Group = targetptr->disk.group;
2103 status->lockCount = targetptr->disk.lock.lockCount;
2104 status->errorCode = 0;
2110 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2111 afs_sfsize_t Pos, afs_sfsize_t Len,
2112 struct AFSFetchStatus *OutStatus,
2113 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2116 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2117 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2118 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2119 Error errorCode = 0; /* return code to caller */
2120 Error fileCode = 0; /* return code from vol package */
2121 Volume *volptr = 0; /* pointer to the volume */
2122 struct client *client = 0; /* pointer to the client data */
2123 struct rx_connection *tcon; /* the connection we're part of */
2125 afs_int32 rights, anyrights; /* rights for this and any user */
2126 struct client *t_client = NULL; /* tmp ptr to client data */
2127 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2128 #if FS_STATS_DETAILED
2129 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2130 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2131 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2132 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2133 struct timeval elapsedTime; /* Transfer time */
2134 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2135 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2136 int readIdx; /* Index of read stats array to bump */
2137 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2140 * Set our stats pointers, remember when the RPC operation started, and
2141 * tally the operation.
2143 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2144 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2148 FT_GetTimeOfDay(&opStartTime, 0);
2149 #endif /* FS_STATS_DETAILED */
2152 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2155 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2157 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2160 /* Get ptr to client data for user Id for logging */
2161 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2162 logHostAddr.s_addr = rxr_HostOf(tcon);
2164 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2165 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2166 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2168 * Get volume/vnode for the fetched file; caller's access rights to
2169 * it are also returned
2172 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2173 &parentwhentargetnotdir, &client, READ_LOCK,
2174 &rights, &anyrights)))
2177 SetVolumeSync(Sync, volptr);
2179 #if FS_STATS_DETAILED
2181 * Remember that another read operation was performed.
2184 if (client->InSameNetwork)
2185 readIdx = VOL_STATS_SAME_NET;
2187 readIdx = VOL_STATS_DIFF_NET;
2188 V_stat_reads(volptr, readIdx)++;
2189 if (client->ViceId != AnonymousID) {
2190 V_stat_reads(volptr, readIdx + 1)++;
2193 #endif /* FS_STATS_DETAILED */
2194 /* Check whether the caller has permission access to fetch the data */
2196 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2200 * Drop the read lock on the parent directory after saving the parent
2201 * vnode information we need to pass to GetStatus
2203 if (parentwhentargetnotdir != NULL) {
2204 tparentwhentargetnotdir = *parentwhentargetnotdir;
2205 VPutVnode(&fileCode, parentwhentargetnotdir);
2206 assert(!fileCode || (fileCode == VSALVAGE));
2207 parentwhentargetnotdir = NULL;
2209 #if FS_STATS_DETAILED
2211 * Remember when the data transfer started.
2213 FT_GetTimeOfDay(&xferStartTime, 0);
2214 #endif /* FS_STATS_DETAILED */
2216 /* actually do the data transfer */
2217 #if FS_STATS_DETAILED
2219 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2220 &bytesToXfer, &bytesXferred);
2223 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2225 #endif /* FS_STATS_DETAILED */
2227 #if FS_STATS_DETAILED
2229 * At this point, the data transfer is done, for good or ill. Remember
2230 * when the transfer ended, bump the number of successes/failures, and
2231 * integrate the transfer size and elapsed time into the stats. If the
2232 * operation failed, we jump to the appropriate point.
2234 FT_GetTimeOfDay(&xferStopTime, 0);
2236 (xferP->numXfers)++;
2238 (xferP->numSuccesses)++;
2241 * Bump the xfer sum by the number of bytes actually sent, NOT the
2244 tot_bytesXferred += bytesXferred;
2245 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2246 tot_bytesXferred &= 0x3FF;
2247 if (bytesXferred < xferP->minBytes)
2248 xferP->minBytes = bytesXferred;
2249 if (bytesXferred > xferP->maxBytes)
2250 xferP->maxBytes = bytesXferred;
2253 * Tally the size of the object. Note: we tally the actual size,
2254 * NOT the number of bytes that made it out over the wire.
2256 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2257 (xferP->count[0])++;
2258 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2259 (xferP->count[1])++;
2260 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2261 (xferP->count[2])++;
2262 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2263 (xferP->count[3])++;
2264 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2265 (xferP->count[4])++;
2266 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2267 (xferP->count[5])++;
2268 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2269 (xferP->count[6])++;
2270 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2271 (xferP->count[7])++;
2273 (xferP->count[8])++;
2275 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2276 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2277 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2278 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2279 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2281 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2282 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2287 * Finally, go off to tell our caller the bad news in case the
2292 #endif /* FS_STATS_DETAILED */
2294 /* write back the OutStatus from the target vnode */
2295 GetStatus(targetptr, OutStatus, rights, anyrights,
2296 &tparentwhentargetnotdir);
2298 /* if a r/w volume, promise a callback to the caller */
2299 if (VolumeWriteable(volptr))
2300 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2302 struct AFSFid myFid;
2303 memset(&myFid, 0, sizeof(struct AFSFid));
2304 myFid.Volume = Fid->Volume;
2305 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2309 /* Update and store volume/vnode and parent vnodes back */
2310 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2312 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2313 errorCode = CallPostamble(tcon, errorCode, thost);
2315 #if FS_STATS_DETAILED
2316 FT_GetTimeOfDay(&opStopTime, 0);
2317 if (errorCode == 0) {
2319 (opP->numSuccesses)++;
2320 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2321 fs_stats_AddTo((opP->sumTime), elapsedTime);
2322 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2323 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2324 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2326 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2327 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2331 #endif /* FS_STATS_DETAILED */
2333 osi_auditU(acall, FetchDataEvent, errorCode,
2334 AUD_ID, t_client ? t_client->ViceId : 0,
2335 AUD_FID, Fid, AUD_END);
2338 } /*SRXAFS_FetchData */
2341 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2342 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2343 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2345 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2350 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2351 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2352 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2355 afs_sfsize_t tPos, tLen;
2357 #ifdef AFS_64BIT_ENV
2358 tPos = (afs_sfsize_t) Pos;
2359 tLen = (afs_sfsize_t) Len;
2360 #else /* AFS_64BIT_ENV */
2361 if (Pos.high || Len.high)
2365 #endif /* AFS_64BIT_ENV */
2368 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2374 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2375 struct AFSOpaque * AccessList,
2376 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2378 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2379 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2380 Error errorCode = 0; /* return error code to caller */
2381 Volume *volptr = 0; /* pointer to the volume */
2382 struct client *client = 0; /* pointer to the client data */
2383 afs_int32 rights, anyrights; /* rights for this and any user */
2384 struct rx_connection *tcon = rx_ConnectionOf(acall);
2386 struct client *t_client = NULL; /* tmp ptr to client data */
2387 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2388 #if FS_STATS_DETAILED
2389 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2390 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2391 struct timeval elapsedTime; /* Transfer time */
2394 * Set our stats pointer, remember when the RPC operation started, and
2395 * tally the operation.
2397 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2401 FT_GetTimeOfDay(&opStartTime, 0);
2402 #endif /* FS_STATS_DETAILED */
2405 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2408 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2410 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2413 /* Get ptr to client data for user Id for logging */
2414 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2415 logHostAddr.s_addr = rxr_HostOf(tcon);
2417 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2418 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2419 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2421 AccessList->AFSOpaque_len = 0;
2422 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2423 if (!AccessList->AFSOpaque_val) {
2424 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2429 * Get volume/vnode for the fetched file; caller's access rights to it
2433 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2434 &parentwhentargetnotdir, &client, READ_LOCK,
2435 &rights, &anyrights)))
2438 SetVolumeSync(Sync, volptr);
2440 /* Check whether we have permission to fetch the ACL */
2442 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2445 /* Get the Access List from the dir's vnode */
2447 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2450 /* Get OutStatus back From the target Vnode */
2451 GetStatus(targetptr, OutStatus, rights, anyrights,
2452 parentwhentargetnotdir);
2455 /* Update and store volume/vnode and parent vnodes back */
2456 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2459 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2460 AccessList->AFSOpaque_val));
2461 errorCode = CallPostamble(tcon, errorCode, thost);
2463 #if FS_STATS_DETAILED
2464 FT_GetTimeOfDay(&opStopTime, 0);
2465 if (errorCode == 0) {
2467 (opP->numSuccesses)++;
2468 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2469 fs_stats_AddTo((opP->sumTime), elapsedTime);
2470 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2471 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2472 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2474 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2475 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2479 #endif /* FS_STATS_DETAILED */
2481 osi_auditU(acall, FetchACLEvent, errorCode,
2482 AUD_ID, t_client ? t_client->ViceId : 0,
2484 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2486 } /*SRXAFS_FetchACL */
2490 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2491 * merged into it when possible.
2495 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2496 struct AFSFetchStatus *OutStatus,
2497 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2499 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2500 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2501 Error errorCode = 0; /* return code to caller */
2502 Volume *volptr = 0; /* pointer to the volume */
2503 struct client *client = 0; /* pointer to the client data */
2504 afs_int32 rights, anyrights; /* rights for this and any user */
2505 struct client *t_client = NULL; /* tmp ptr to client data */
2506 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2507 struct rx_connection *tcon = rx_ConnectionOf(acall);
2509 /* Get ptr to client data for user Id for logging */
2510 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2511 logHostAddr.s_addr = rxr_HostOf(tcon);
2513 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2514 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2515 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2517 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2520 * Get volume/vnode for the fetched file; caller's rights to it are
2524 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2525 &parentwhentargetnotdir, &client, READ_LOCK,
2526 &rights, &anyrights)))
2527 goto Bad_FetchStatus;
2529 /* set volume synchronization information */
2530 SetVolumeSync(Sync, volptr);
2532 /* Are we allowed to fetch Fid's status? */
2533 if (targetptr->disk.type != vDirectory) {
2535 Check_PermissionRights(targetptr, client, rights,
2536 CHK_FETCHSTATUS, 0))) {
2537 if (rx_GetCallAbortCode(acall) == errorCode)
2538 rx_SetCallAbortCode(acall, 0);
2539 goto Bad_FetchStatus;
2543 /* set OutStatus From the Fid */
2544 GetStatus(targetptr, OutStatus, rights, anyrights,
2545 parentwhentargetnotdir);
2547 /* If a r/w volume, also set the CallBack state */
2548 if (VolumeWriteable(volptr))
2549 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2551 struct AFSFid myFid;
2552 memset(&myFid, 0, sizeof(struct AFSFid));
2553 myFid.Volume = Fid->Volume;
2554 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2558 /* Update and store volume/vnode and parent vnodes back */
2559 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2561 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2564 } /*SAFSS_FetchStatus */
2568 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2569 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2570 struct AFSVolSync * Sync)
2574 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2575 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2576 Error errorCode = 0; /* return code to caller */
2577 Volume *volptr = 0; /* pointer to the volume */
2578 struct client *client = 0; /* pointer to the client data */
2579 afs_int32 rights, anyrights; /* rights for this and any user */
2580 register struct AFSFid *tfid; /* file id we're dealing with now */
2581 struct rx_connection *tcon = rx_ConnectionOf(acall);
2583 struct client *t_client = NULL; /* tmp pointer to the client data */
2584 #if FS_STATS_DETAILED
2585 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2586 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2587 struct timeval elapsedTime; /* Transfer time */
2590 * Set our stats pointer, remember when the RPC operation started, and
2591 * tally the operation.
2593 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2597 FT_GetTimeOfDay(&opStartTime, 0);
2598 #endif /* FS_STATS_DETAILED */
2600 ViceLog(1, ("SAFS_BulkStatus\n"));
2602 AFSCallStats.TotalCalls++;
2604 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2605 if (nfiles <= 0) { /* Sanity check */
2607 goto Audit_and_Return;
2610 /* allocate space for return output parameters */
2611 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2612 malloc(nfiles * sizeof(struct AFSFetchStatus));
2613 if (!OutStats->AFSBulkStats_val) {
2614 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2617 OutStats->AFSBulkStats_len = nfiles;
2618 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2619 malloc(nfiles * sizeof(struct AFSCallBack));
2620 if (!CallBacks->AFSCBs_val) {
2621 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2624 CallBacks->AFSCBs_len = nfiles;
2626 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2627 goto Bad_BulkStatus;
2629 tfid = Fids->AFSCBFids_val;
2630 for (i = 0; i < nfiles; i++, tfid++) {
2632 * Get volume/vnode for the fetched file; caller's rights to it
2636 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2637 &parentwhentargetnotdir, &client, READ_LOCK,
2638 &rights, &anyrights)))
2639 goto Bad_BulkStatus;
2640 /* set volume synchronization information, but only once per call */
2642 SetVolumeSync(Sync, volptr);
2644 /* Are we allowed to fetch Fid's status? */
2645 if (targetptr->disk.type != vDirectory) {
2647 Check_PermissionRights(targetptr, client, rights,
2648 CHK_FETCHSTATUS, 0))) {
2649 if (rx_GetCallAbortCode(acall) == errorCode)
2650 rx_SetCallAbortCode(acall, 0);
2651 goto Bad_BulkStatus;
2655 /* set OutStatus From the Fid */
2656 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2657 anyrights, parentwhentargetnotdir);
2659 /* If a r/w volume, also set the CallBack state */
2660 if (VolumeWriteable(volptr))
2661 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2662 &CallBacks->AFSCBs_val[i]);
2664 struct AFSFid myFid;
2665 memset(&myFid, 0, sizeof(struct AFSFid));
2666 myFid.Volume = tfid->Volume;
2667 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2668 &CallBacks->AFSCBs_val[i]);
2671 /* put back the file ID and volume */
2672 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2674 parentwhentargetnotdir = (Vnode *) 0;
2675 targetptr = (Vnode *) 0;
2676 volptr = (Volume *) 0;
2677 client = (struct client *)0;
2681 /* Update and store volume/vnode and parent vnodes back */
2682 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2684 errorCode = CallPostamble(tcon, errorCode, thost);
2686 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2688 #if FS_STATS_DETAILED
2689 FT_GetTimeOfDay(&opStopTime, 0);
2690 if (errorCode == 0) {
2692 (opP->numSuccesses)++;
2693 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2694 fs_stats_AddTo((opP->sumTime), elapsedTime);
2695 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2696 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2697 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2699 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2700 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2704 #endif /* FS_STATS_DETAILED */
2707 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2708 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2709 AUD_ID, t_client ? t_client->ViceId : 0,
2710 AUD_FIDS, Fids, AUD_END);
2713 } /*SRXAFS_BulkStatus */
2717 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2718 struct AFSBulkStats * OutStats,
2719 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2723 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2724 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2725 Error errorCode = 0; /* return code to caller */
2726 Volume *volptr = 0; /* pointer to the volume */
2727 struct client *client = 0; /* pointer to the client data */
2728 afs_int32 rights, anyrights; /* rights for this and any user */
2729 register struct AFSFid *tfid; /* file id we're dealing with now */
2730 struct rx_connection *tcon;
2732 struct client *t_client = NULL; /* tmp ptr to client data */
2733 AFSFetchStatus *tstatus;
2734 int VolSync_set = 0;
2735 #if FS_STATS_DETAILED
2736 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2737 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2738 struct timeval elapsedTime; /* Transfer time */
2741 * Set our stats pointer, remember when the RPC operation started, and
2742 * tally the operation.
2744 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2748 FT_GetTimeOfDay(&opStartTime, 0);
2749 #endif /* FS_STATS_DETAILED */
2751 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2753 AFSCallStats.TotalCalls++;
2755 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2756 if (nfiles <= 0) { /* Sanity check */
2758 goto Audit_and_Return;
2761 /* allocate space for return output parameters */
2762 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2763 malloc(nfiles * sizeof(struct AFSFetchStatus));
2764 if (!OutStats->AFSBulkStats_val) {
2765 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2768 OutStats->AFSBulkStats_len = nfiles;
2769 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2770 malloc(nfiles * sizeof(struct AFSCallBack));
2771 if (!CallBacks->AFSCBs_val) {
2772 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2775 CallBacks->AFSCBs_len = nfiles;
2777 /* Zero out return values to avoid leaking information on partial succes */
2778 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2779 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2780 memset(Sync, 0, sizeof(*Sync));
2782 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2783 goto Bad_InlineBulkStatus;
2786 tfid = Fids->AFSCBFids_val;
2787 for (i = 0; i < nfiles; i++, tfid++) {
2789 * Get volume/vnode for the fetched file; caller's rights to it
2793 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2794 &parentwhentargetnotdir, &client, READ_LOCK,
2795 &rights, &anyrights))) {
2796 tstatus = &OutStats->AFSBulkStats_val[i];
2797 tstatus->errorCode = errorCode;
2798 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2800 parentwhentargetnotdir = (Vnode *) 0;
2801 targetptr = (Vnode *) 0;
2802 volptr = (Volume *) 0;
2803 client = (struct client *)0;
2807 /* set volume synchronization information, but only once per call */
2809 SetVolumeSync(Sync, volptr);
2813 /* Are we allowed to fetch Fid's status? */
2814 if (targetptr->disk.type != vDirectory) {
2816 Check_PermissionRights(targetptr, client, rights,
2817 CHK_FETCHSTATUS, 0))) {
2818 tstatus = &OutStats->AFSBulkStats_val[i];
2819 tstatus->errorCode = errorCode;
2820 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2821 (Vnode *) 0, volptr, &client);
2822 parentwhentargetnotdir = (Vnode *) 0;
2823 targetptr = (Vnode *) 0;
2824 volptr = (Volume *) 0;
2825 client = (struct client *)0;
2830 /* set OutStatus From the Fid */
2831 GetStatus(targetptr,
2832 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2833 rights, anyrights, parentwhentargetnotdir);
2835 /* If a r/w volume, also set the CallBack state */
2836 if (VolumeWriteable(volptr))
2837 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2838 &CallBacks->AFSCBs_val[i]);
2840 struct AFSFid myFid;
2841 memset(&myFid, 0, sizeof(struct AFSFid));
2842 myFid.Volume = tfid->Volume;
2843 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2844 &CallBacks->AFSCBs_val[i]);
2847 /* put back the file ID and volume */
2848 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2850 parentwhentargetnotdir = (Vnode *) 0;
2851 targetptr = (Vnode *) 0;
2852 volptr = (Volume *) 0;
2853 client = (struct client *)0;
2856 Bad_InlineBulkStatus:
2857 /* Update and store volume/vnode and parent vnodes back */
2858 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2860 errorCode = CallPostamble(tcon, errorCode, thost);
2862 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2864 #if FS_STATS_DETAILED
2865 FT_GetTimeOfDay(&opStopTime, 0);
2866 if (errorCode == 0) {
2868 (opP->numSuccesses)++;
2869 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2870 fs_stats_AddTo((opP->sumTime), elapsedTime);
2871 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2872 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2873 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2875 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2876 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2880 #endif /* FS_STATS_DETAILED */
2883 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2884 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2885 AUD_ID, t_client ? t_client->ViceId : 0,
2886 AUD_FIDS, Fids, AUD_END);
2889 } /*SRXAFS_InlineBulkStatus */
2893 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2894 struct AFSFetchStatus * OutStatus,
2895 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2898 struct rx_connection *tcon;
2900 struct client *t_client = NULL; /* tmp ptr to client data */
2901 #if FS_STATS_DETAILED
2902 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2903 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2904 struct timeval elapsedTime; /* Transfer time */
2907 * Set our stats pointer, remember when the RPC operation started, and
2908 * tally the operation.
2910 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2914 FT_GetTimeOfDay(&opStartTime, 0);
2915 #endif /* FS_STATS_DETAILED */
2917 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2918 goto Bad_FetchStatus;
2920 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2923 code = CallPostamble(tcon, code, thost);
2925 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2927 #if FS_STATS_DETAILED
2928 FT_GetTimeOfDay(&opStopTime, 0);
2931 (opP->numSuccesses)++;
2932 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2933 fs_stats_AddTo((opP->sumTime), elapsedTime);
2934 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2935 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2936 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2938 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2939 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2943 #endif /* FS_STATS_DETAILED */
2945 osi_auditU(acall, FetchStatusEvent, code,
2946 AUD_ID, t_client ? t_client->ViceId : 0,
2947 AUD_FID, Fid, AUD_END);
2950 } /*SRXAFS_FetchStatus */
2954 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2955 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2956 afs_fsize_t Length, afs_fsize_t FileLength,
2957 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2959 Vnode *targetptr = 0; /* pointer to input fid */
2960 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2961 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2962 Error errorCode = 0; /* return code for caller */
2963 Error fileCode = 0; /* return code from vol package */
2964 Volume *volptr = 0; /* pointer to the volume header */
2965 struct client *client = 0; /* pointer to client structure */
2966 afs_int32 rights, anyrights; /* rights for this and any user */
2967 struct client *t_client = NULL; /* tmp ptr to client data */
2968 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2969 struct rx_connection *tcon;
2971 #if FS_STATS_DETAILED
2972 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2973 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2974 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2975 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2976 struct timeval elapsedTime; /* Transfer time */
2977 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2978 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2979 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2982 * Set our stats pointers, remember when the RPC operation started, and
2983 * tally the operation.
2985 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2986 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2991 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2993 FT_GetTimeOfDay(&opStartTime, 0);
2994 #endif /* FS_STATS_DETAILED */
2997 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2999 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3002 /* Get ptr to client data for user Id for logging */
3003 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3004 logHostAddr.s_addr = rxr_HostOf(tcon);
3006 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3007 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3008 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3011 * Get associated volume/vnode for the stored file; caller's rights
3015 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3016 &parentwhentargetnotdir, &client, WRITE_LOCK,
3017 &rights, &anyrights))) {
3021 /* set volume synchronization information */
3022 SetVolumeSync(Sync, volptr);
3024 if ((targetptr->disk.type == vSymlink)) {
3025 /* Should we return a better error code here??? */
3030 /* Check if we're allowed to store the data */
3032 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3038 * Drop the read lock on the parent directory after saving the parent
3039 * vnode information we need to pass to GetStatus
3041 if (parentwhentargetnotdir != NULL) {
3042 tparentwhentargetnotdir = *parentwhentargetnotdir;
3043 VPutVnode(&fileCode, parentwhentargetnotdir);
3044 assert(!fileCode || (fileCode == VSALVAGE));
3045 parentwhentargetnotdir = NULL;
3047 #if FS_STATS_DETAILED
3049 * Remember when the data transfer started.
3051 FT_GetTimeOfDay(&xferStartTime, 0);
3052 #endif /* FS_STATS_DETAILED */
3054 /* Do the actual storing of the data */
3055 #if FS_STATS_DETAILED
3057 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3058 FileLength, (InStatus->Mask & AFS_FSYNC),
3059 &bytesToXfer, &bytesXferred);
3062 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3063 FileLength, (InStatus->Mask & AFS_FSYNC));
3064 if (errorCode && (!targetptr->changed_newTime))
3066 #endif /* FS_STATS_DETAILED */
3067 #if FS_STATS_DETAILED
3069 * At this point, the data transfer is done, for good or ill. Remember
3070 * when the transfer ended, bump the number of successes/failures, and
3071 * integrate the transfer size and elapsed time into the stats. If the
3072 * operation failed, we jump to the appropriate point.
3074 FT_GetTimeOfDay(&xferStopTime, 0);
3076 (xferP->numXfers)++;
3078 (xferP->numSuccesses)++;
3081 * Bump the xfer sum by the number of bytes actually sent, NOT the
3084 tot_bytesXferred += bytesXferred;
3085 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3086 tot_bytesXferred &= 0x3FF;
3087 if (bytesXferred < xferP->minBytes)
3088 xferP->minBytes = bytesXferred;
3089 if (bytesXferred > xferP->maxBytes)
3090 xferP->maxBytes = bytesXferred;
3093 * Tally the size of the object. Note: we tally the actual size,
3094 * NOT the number of bytes that made it out over the wire.
3096 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3097 (xferP->count[0])++;
3098 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3099 (xferP->count[1])++;
3100 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3101 (xferP->count[2])++;
3102 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3103 (xferP->count[3])++;
3104 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3105 (xferP->count[4])++;
3106 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3107 (xferP->count[5])++;
3108 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3109 (xferP->count[6])++;
3110 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3111 (xferP->count[7])++;
3113 (xferP->count[8])++;
3115 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3116 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3117 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3118 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3119 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3121 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3122 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3127 * Finally, go off to tell our caller the bad news in case the
3130 if (errorCode && (!targetptr->changed_newTime))
3132 #endif /* FS_STATS_DETAILED */
3134 /* Update the status of the target's vnode */
3135 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3136 targetptr, volptr, 0);
3138 /* Get the updated File's status back to the caller */
3139 GetStatus(targetptr, OutStatus, rights, anyrights,
3140 &tparentwhentargetnotdir);
3143 /* Update and store volume/vnode and parent vnodes back */
3144 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3146 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3148 errorCode = CallPostamble(tcon, errorCode, thost);
3150 #if FS_STATS_DETAILED
3151 FT_GetTimeOfDay(&opStopTime, 0);
3152 if (errorCode == 0) {
3154 (opP->numSuccesses)++;
3155 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3156 fs_stats_AddTo((opP->sumTime), elapsedTime);
3157 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3158 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3159 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3161 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3162 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3166 #endif /* FS_STATS_DETAILED */
3167 osi_auditU(acall, StoreDataEvent, errorCode,
3168 AUD_ID, t_client ? t_client->ViceId : 0,
3169 AUD_FID, Fid, AUD_END);
3171 } /*common_StoreData64 */
3174 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3175 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3176 afs_uint32 Length, afs_uint32 FileLength,
3177 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3179 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3180 (0x7fffffff - Pos) < Length)
3183 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3185 } /*SRXAFS_StoreData */
3188 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3189 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3190 afs_uint64 Length, afs_uint64 FileLength,
3191 struct AFSFetchStatus * OutStatus,
3192 struct AFSVolSync * Sync)
3196 afs_fsize_t tLength;
3197 afs_fsize_t tFileLength;
3199 #ifdef AFS_64BIT_ENV
3200 tPos = (afs_fsize_t) Pos;
3201 tLength = (afs_fsize_t) Length;
3202 tFileLength = (afs_fsize_t) FileLength;
3203 #else /* AFS_64BIT_ENV */
3204 if (FileLength.high)
3207 tLength = Length.low;
3208 tFileLength = FileLength.low;
3209 #endif /* AFS_64BIT_ENV */
3212 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3218 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3219 struct AFSOpaque * AccessList,
3220 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3222 Vnode *targetptr = 0; /* pointer to input fid */
3223 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3224 Error errorCode = 0; /* return code for caller */
3225 struct AFSStoreStatus InStatus; /* Input status for fid */
3226 Volume *volptr = 0; /* pointer to the volume header */
3227 struct client *client = 0; /* pointer to client structure */
3228 afs_int32 rights, anyrights; /* rights for this and any user */
3229 struct rx_connection *tcon;
3231 struct client *t_client = NULL; /* tmp ptr to client data */
3232 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3233 #if FS_STATS_DETAILED
3234 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3235 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3236 struct timeval elapsedTime; /* Transfer time */
3239 * Set our stats pointer, remember when the RPC operation started, and
3240 * tally the operation.
3242 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3246 FT_GetTimeOfDay(&opStartTime, 0);
3247 #endif /* FS_STATS_DETAILED */
3248 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3251 /* Get ptr to client data for user Id for logging */
3252 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3253 logHostAddr.s_addr = rxr_HostOf(tcon);
3255 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3256 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3257 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3259 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3261 InStatus.Mask = 0; /* not storing any status */
3264 * Get associated volume/vnode for the target dir; caller's rights
3265 * are also returned.
3268 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3269 &parentwhentargetnotdir, &client, WRITE_LOCK,
3270 &rights, &anyrights))) {
3274 /* set volume synchronization information */
3275 SetVolumeSync(Sync, volptr);
3277 /* Check if we have permission to change the dir's ACL */
3279 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3284 /* Build and store the new Access List for the dir */
3285 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3289 targetptr->changed_newTime = 1; /* status change of directory */
3291 /* convert the write lock to a read lock before breaking callbacks */
3292 VVnodeWriteToRead(&errorCode, targetptr);
3293 assert(!errorCode || errorCode == VSALVAGE);
3295 /* break call backs on the directory */
3296 BreakCallBack(client->host, Fid, 0);
3298 /* Get the updated dir's status back to the caller */
3299 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3302 /* Update and store volume/vnode and parent vnodes back */
3303 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3305 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3306 errorCode = CallPostamble(tcon, errorCode, thost);
3308 #if FS_STATS_DETAILED
3309 FT_GetTimeOfDay(&opStopTime, 0);
3310 if (errorCode == 0) {
3312 (opP->numSuccesses)++;
3313 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3314 fs_stats_AddTo((opP->sumTime), elapsedTime);
3315 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3316 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3317 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3319 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3320 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3324 #endif /* FS_STATS_DETAILED */
3326 osi_auditU(acall, StoreACLEvent, errorCode,
3327 AUD_ID, t_client ? t_client->ViceId : 0,
3328 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3331 } /*SRXAFS_StoreACL */
3335 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3336 * should be merged when possible.
3339 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3340 struct AFSStoreStatus *InStatus,
3341 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3343 Vnode *targetptr = 0; /* pointer to input fid */
3344 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3345 Error errorCode = 0; /* return code for caller */
3346 Volume *volptr = 0; /* pointer to the volume header */
3347 struct client *client = 0; /* pointer to client structure */
3348 afs_int32 rights, anyrights; /* rights for this and any user */
3349 struct client *t_client = NULL; /* tmp ptr to client data */
3350 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3351 struct rx_connection *tcon = rx_ConnectionOf(acall);
3353 /* Get ptr to client data for user Id for logging */
3354 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3355 logHostAddr.s_addr = rxr_HostOf(tcon);
3357 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3358 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3359 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3361 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3364 * Get volume/vnode for the target file; caller's rights to it are
3368 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3369 &parentwhentargetnotdir, &client, WRITE_LOCK,
3370 &rights, &anyrights))) {
3371 goto Bad_StoreStatus;
3374 /* set volume synchronization information */
3375 SetVolumeSync(Sync, volptr);
3377 /* Check if the caller has proper permissions to store status to Fid */
3379 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3381 goto Bad_StoreStatus;
3384 * Check for a symbolic link; we can't chmod these (otherwise could
3385 * change a symlink to a mt pt or vice versa)
3387 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3389 goto Bad_StoreStatus;
3392 /* Update the status of the target's vnode */
3393 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3394 (parentwhentargetnotdir ? parentwhentargetnotdir
3395 : targetptr), volptr, 0);
3397 /* convert the write lock to a read lock before breaking callbacks */
3398 VVnodeWriteToRead(&errorCode, targetptr);
3399 assert(!errorCode || errorCode == VSALVAGE);
3401 /* Break call backs on Fid */
3402 BreakCallBack(client->host, Fid, 0);
3404 /* Return the updated status back to caller */
3405 GetStatus(targetptr, OutStatus, rights, anyrights,
3406 parentwhentargetnotdir);
3409 /* Update and store volume/vnode and parent vnodes back */
3410 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3412 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3415 } /*SAFSS_StoreStatus */
3419 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3420 struct AFSStoreStatus * InStatus,
3421 struct AFSFetchStatus * OutStatus,
3422 struct AFSVolSync * Sync)
3425 struct rx_connection *tcon;
3427 struct client *t_client = NULL; /* tmp ptr to client data */
3428 #if FS_STATS_DETAILED
3429 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3430 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3431 struct timeval elapsedTime; /* Transfer time */
3434 * Set our stats pointer, remember when the RPC operation started, and
3435 * tally the operation.
3437 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3441 FT_GetTimeOfDay(&opStartTime, 0);
3442 #endif /* FS_STATS_DETAILED */
3444 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3445 goto Bad_StoreStatus;
3447 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3450 code = CallPostamble(tcon, code, thost);
3452 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3454 #if FS_STATS_DETAILED
3455 FT_GetTimeOfDay(&opStopTime, 0);
3458 (opP->numSuccesses)++;
3459 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3460 fs_stats_AddTo((opP->sumTime), elapsedTime);
3461 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3462 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3463 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3465 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3466 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3470 #endif /* FS_STATS_DETAILED */
3472 osi_auditU(acall, StoreStatusEvent, code,
3473 AUD_ID, t_client ? t_client->ViceId : 0,
3474 AUD_FID, Fid, AUD_END);
3477 } /*SRXAFS_StoreStatus */
3481 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3482 * merged in when possible.
3485 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3486 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3488 Vnode *parentptr = 0; /* vnode of input Directory */
3489 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3490 Vnode *targetptr = 0; /* file to be deleted */
3491 Volume *volptr = 0; /* pointer to the volume header */
3492 AFSFid fileFid; /* area for Fid from the directory */
3493 Error errorCode = 0; /* error code */
3494 DirHandle dir; /* Handle for dir package I/O */
3495 struct client *client = 0; /* pointer to client structure */
3496 afs_int32 rights, anyrights; /* rights for this and any user */
3497 struct client *t_client; /* tmp ptr to client data */
3498 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3499 struct rx_connection *tcon = rx_ConnectionOf(acall);
3502 /* Get ptr to client data for user Id for logging */
3503 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3504 logHostAddr.s_addr = rxr_HostOf(tcon);
3506 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3507 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3508 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3510 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3513 * Get volume/vnode for the parent dir; caller's access rights are
3517 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3518 &parentwhentargetnotdir, &client, WRITE_LOCK,
3519 &rights, &anyrights))) {
3520 goto Bad_RemoveFile;
3522 /* set volume synchronization information */
3523 SetVolumeSync(Sync, volptr);
3525 /* Does the caller has delete (& write) access to the parent directory? */
3526 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3527 goto Bad_RemoveFile;
3530 /* Actually delete the desired file */
3532 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3534 goto Bad_RemoveFile;
3537 /* Update the vnode status of the parent dir */
3538 #if FS_STATS_DETAILED
3539 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3540 parentptr->disk.linkCount,
3541 client->InSameNetwork);
3543 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3544 parentptr->disk.linkCount);
3545 #endif /* FS_STATS_DETAILED */
3547 /* Return the updated parent dir's status back to caller */
3548 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3550 /* Handle internal callback state for the parent and the deleted file */
3551 if (targetptr->disk.linkCount == 0) {
3552 /* no references left, discard entry */
3553 DeleteFileCallBacks(&fileFid);
3554 /* convert the parent lock to a read lock before breaking callbacks */
3555 VVnodeWriteToRead(&errorCode, parentptr);
3556 assert(!errorCode || errorCode == VSALVAGE);
3558 /* convert the parent lock to a read lock before breaking callbacks */
3559 VVnodeWriteToRead(&errorCode, parentptr);
3560 assert(!errorCode || errorCode == VSALVAGE);
3561 /* convert the target lock to a read lock before breaking callbacks */
3562 VVnodeWriteToRead(&errorCode, targetptr);
3563 assert(!errorCode || errorCode == VSALVAGE);
3564 /* tell all the file has changed */
3565 BreakCallBack(client->host, &fileFid, 1);
3568 /* break call back on the directory */
3569 BreakCallBack(client->host, DirFid, 0);
3572 /* Update and store volume/vnode and parent vnodes back */
3573 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3576 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3579 } /*SAFSS_RemoveFile */
3583 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3584 struct AFSFetchStatus * OutDirStatus,
3585 struct AFSVolSync * Sync)
3588 struct rx_connection *tcon;
3590 struct client *t_client = NULL; /* tmp ptr to client data */
3591 #if FS_STATS_DETAILED
3592 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3593 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3594 struct timeval elapsedTime; /* Transfer time */
3597 * Set our stats pointer, remember when the RPC operation started, and
3598 * tally the operation.
3600 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3604 FT_GetTimeOfDay(&opStartTime, 0);
3605 #endif /* FS_STATS_DETAILED */
3607 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3608 goto Bad_RemoveFile;
3610 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3613 code = CallPostamble(tcon, code, thost);
3615 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3617 #if FS_STATS_DETAILED
3618 FT_GetTimeOfDay(&opStopTime, 0);
3621 (opP->numSuccesses)++;
3622 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3623 fs_stats_AddTo((opP->sumTime), elapsedTime);
3624 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3625 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3626 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3628 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3629 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3633 #endif /* FS_STATS_DETAILED */
3635 osi_auditU(acall, RemoveFileEvent, code,
3636 AUD_ID, t_client ? t_client->ViceId : 0,
3637 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3640 } /*SRXAFS_RemoveFile */
3644 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3645 * be merged in when possible.
3648 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3649 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3650 struct AFSFetchStatus *OutFidStatus,
3651 struct AFSFetchStatus *OutDirStatus,
3652 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3654 Vnode *parentptr = 0; /* vnode of input Directory */
3655 Vnode *targetptr = 0; /* vnode of the new file */
3656 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3657 Volume *volptr = 0; /* pointer to the volume header */
3658 Error errorCode = 0; /* error code */
3659 DirHandle dir; /* Handle for dir package I/O */
3660 struct client *client = 0; /* pointer to client structure */
3661 afs_int32 rights, anyrights; /* rights for this and any user */
3662 struct client *t_client; /* tmp ptr to client data */
3663 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3664 struct rx_connection *tcon = rx_ConnectionOf(acall);
3668 /* Get ptr to client data for user Id for logging */
3669 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3670 logHostAddr.s_addr = rxr_HostOf(tcon);
3672 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3673 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3674 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3676 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3678 if (!FileNameOK(Name)) {
3680 goto Bad_CreateFile;
3684 * Get associated volume/vnode for the parent dir; caller long are
3688 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3689 &parentwhentargetnotdir, &client, WRITE_LOCK,
3690 &rights, &anyrights))) {
3691 goto Bad_CreateFile;
3694 /* set volume synchronization information */
3695 SetVolumeSync(Sync, volptr);
3697 /* Can we write (and insert) onto the parent directory? */
3698 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3699 goto Bad_CreateFile;
3701 /* get a new vnode for the file to be created and set it up */
3703 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3704 vFile, nBlocks(0)))) {
3705 goto Bad_CreateFile;
3708 /* update the status of the parent vnode */
3709 #if FS_STATS_DETAILED
3710 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3711 parentptr->disk.linkCount,
3712 client->InSameNetwork);
3714 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3715 parentptr->disk.linkCount);
3716 #endif /* FS_STATS_DETAILED */
3718 /* update the status of the new file's vnode */
3719 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3720 parentptr, volptr, 0);
3722 /* 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 */
3723 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3724 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3726 /* convert the write lock to a read lock before breaking callbacks */
3727 VVnodeWriteToRead(&errorCode, parentptr);
3728 assert(!errorCode || errorCode == VSALVAGE);
3730 /* break call back on parent dir */
3731 BreakCallBack(client->host, DirFid, 0);
3733 /* Return a callback promise for the newly created file to the caller */
3734 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3737 /* Update and store volume/vnode and parent vnodes back */
3738 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3741 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3744 } /*SAFSS_CreateFile */
3748 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3749 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3750 struct AFSFetchStatus * OutFidStatus,
3751 struct AFSFetchStatus * OutDirStatus,
3752 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3755 struct rx_connection *tcon;
3757 struct client *t_client = NULL; /* tmp ptr to client data */
3758 #if FS_STATS_DETAILED
3759 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3760 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3761 struct timeval elapsedTime; /* Transfer time */
3764 * Set our stats pointer, remember when the RPC operation started, and
3765 * tally the operation.
3767 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3771 FT_GetTimeOfDay(&opStartTime, 0);
3772 #endif /* FS_STATS_DETAILED */
3774 memset(OutFid, 0, sizeof(struct AFSFid));
3776 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3777 goto Bad_CreateFile;
3780 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3781 OutDirStatus, CallBack, Sync);
3784 code = CallPostamble(tcon, code, thost);
3786 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3788 #if FS_STATS_DETAILED
3789 FT_GetTimeOfDay(&opStopTime, 0);
3792 (opP->numSuccesses)++;
3793 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3794 fs_stats_AddTo((opP->sumTime), elapsedTime);
3795 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3796 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3797 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3799 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3800 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3804 #endif /* FS_STATS_DETAILED */
3806 osi_auditU(acall, CreateFileEvent, code,
3807 AUD_ID, t_client ? t_client->ViceId : 0,
3808 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3811 } /*SRXAFS_CreateFile */
3815 * This routine is called exclusively from SRXAFS_Rename(), and should be
3816 * merged in when possible.
3819 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3820 struct AFSFid *NewDirFid, char *NewName,
3821 struct AFSFetchStatus *OutOldDirStatus,
3822 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3824 Vnode *oldvptr = 0; /* vnode of the old Directory */
3825 Vnode *newvptr = 0; /* vnode of the new Directory */
3826 Vnode *fileptr = 0; /* vnode of the file to move */
3827 Vnode *newfileptr = 0; /* vnode of the file to delete */
3828 Vnode *testvptr = 0; /* used in directory tree walk */
3829 Vnode *parent = 0; /* parent for use in SetAccessList */
3830 Error errorCode = 0; /* error code */
3831 Error fileCode = 0; /* used when writing Vnodes */
3832 VnodeId testnode; /* used in directory tree walk */
3833 AFSFid fileFid; /* Fid of file to move */
3834 AFSFid newFileFid; /* Fid of new file */
3835 DirHandle olddir; /* Handle for dir package I/O */
3836 DirHandle newdir; /* Handle for dir package I/O */
3837 DirHandle filedir; /* Handle for dir package I/O */
3838 DirHandle newfiledir; /* Handle for dir package I/O */
3839 Volume *volptr = 0; /* pointer to the volume header */
3840 struct client *client = 0; /* pointer to client structure */
3841 afs_int32 rights, anyrights; /* rights for this and any user */
3842 afs_int32 newrights; /* rights for this user */
3843 afs_int32 newanyrights; /* rights for any user */
3844 int doDelete; /* deleted the rename target (ref count now 0) */
3846 struct client *t_client; /* tmp ptr to client data */
3847 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3848 struct rx_connection *tcon = rx_ConnectionOf(acall);
3853 FidZero(&newfiledir);
3855 /* Get ptr to client data for user Id for logging */
3856 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3857 logHostAddr.s_addr = rxr_HostOf(tcon);
3859 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3860 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3861 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3862 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3864 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3866 if (!FileNameOK(NewName)) {
3870 if (OldDirFid->Volume != NewDirFid->Volume) {
3875 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3876 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3877 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3883 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3885 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3886 &parent, &client, WRITE_LOCK, &rights,
3891 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3893 newrights = rights, newanyrights = anyrights;
3896 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3897 MustBeDIR, &parent, &client, WRITE_LOCK,
3898 &newrights, &newanyrights))) {
3904 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3905 &parent, &client, WRITE_LOCK, &newrights,
3911 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3912 &parent, &client, WRITE_LOCK, &rights,
3919 /* set volume synchronization information */
3920 SetVolumeSync(Sync, volptr);
3922 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3925 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3929 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3930 * call to CopyOnWrite returns error, it is not necessary to revert back
3931 * the effects of the first call because the contents of the volume is
3932 * not modified, it is only replicated.
3934 if (oldvptr->disk.cloned) {
3935 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3936 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3939 SetDirHandle(&olddir, oldvptr);
3940 if (newvptr->disk.cloned) {
3941 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3942 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3946 SetDirHandle(&newdir, newvptr);
3948 /* Lookup the file to delete its vnode */
3949 if (Lookup(&olddir, OldName, &fileFid)) {
3953 if (fileFid.Vnode == oldvptr->vnodeNumber
3954 || fileFid.Vnode == newvptr->vnodeNumber) {
3955 errorCode = FSERR_ELOOP;
3958 fileFid.Volume = V_id(volptr);
3959 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3960 if (errorCode != 0) {
3962 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3963 OldName, errorCode));
3964 VTakeOffline(volptr);
3967 if (fileptr->disk.uniquifier != fileFid.Unique) {
3969 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3971 VTakeOffline(volptr);
3976 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3977 && fileptr->disk.linkCount != 1) {
3979 * Hard links exist to this file - cannot move one of the links to
3980 * a new directory because of AFS restrictions (this is the same
3981 * reason that links cannot be made across directories, i.e.
3988 /* Lookup the new file */
3989 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3990 if (readonlyServer) {
3991 errorCode = VREADONLY;
3994 if (!(newrights & PRSFS_DELETE)) {
3998 if (newFileFid.Vnode == oldvptr->vnodeNumber
3999 || newFileFid.Vnode == newvptr->vnodeNumber
4000 || newFileFid.Vnode == fileFid.Vnode) {
4004 newFileFid.Volume = V_id(volptr);
4006 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4007 if (errorCode != 0) {
4009 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4010 NewName, errorCode));
4011 VTakeOffline(volptr);
4014 if (fileptr->disk.uniquifier != fileFid.Unique) {
4016 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4018 VTakeOffline(volptr);
4022 SetDirHandle(&newfiledir, newfileptr);
4023 /* Now check that we're moving directories over directories properly, etc.
4024 * return proper POSIX error codes:
4025 * if fileptr is a file and new is a dir: EISDIR.
4026 * if fileptr is a dir and new is a file: ENOTDIR.
4027 * Also, dir to be removed must be empty, of course.
4029 if (newfileptr->disk.type == vDirectory) {
4030 if (fileptr->disk.type != vDirectory) {
4034 if ((IsEmpty(&newfiledir))) {
4039 if (fileptr->disk.type == vDirectory) {
4040 errorCode = ENOTDIR;
4047 * ok - now we check that the old name is not above new name in the
4048 * directory structure. This is to prevent removing a subtree alltogether
4050 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4051 afs_int32 forpass = 0, vnum = 0, top = 0;
4052 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4053 if (testnode > vnum) vnum = testnode;
4054 if (forpass > vnum) {
4055 errorCode = FSERR_ELOOP;
4058 if (testnode == oldvptr->vnodeNumber) {
4059 testnode = oldvptr->disk.parent;
4062 if ((testnode == fileptr->vnodeNumber)
4063 || (testnode == newvptr->vnodeNumber)) {
4064 errorCode = FSERR_ELOOP;
4067 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4068 errorCode = FSERR_ELOOP;
4071 if (testnode == 1) top = 1;
4072 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4073 assert(errorCode == 0);
4074 testnode = testvptr->disk.parent;
4075 VPutVnode(&errorCode, testvptr);
4076 if ((top == 1) && (testnode != 0)) {
4077 VTakeOffline(volptr);
4079 ("Volume %u now offline, must be salvaged.\n",
4084 assert(errorCode == 0);
4087 /* Do the CopyonWrite first before modifying anything else. Copying is
4088 * required because we may have to change entries for ..
4090 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
4091 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4092 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4096 /* If the new name exists already, delete it and the file it points to */
4099 /* Delete NewName from its directory */
4100 code = Delete(&newdir, NewName);
4103 /* Drop the link count */
4104 newfileptr->disk.linkCount--;
4105 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4106 afs_fsize_t newSize;
4107 VN_GET_LEN(newSize, newfileptr);
4108 VAdjustDiskUsage((Error *) & errorCode, volptr,
4109 (afs_sfsize_t) - nBlocks(newSize), 0);
4110 if (VN_GET_INO(newfileptr)) {
4111 IH_REALLYCLOSE(newfileptr->handle);
4113 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4114 V_parentId(volptr));
4115 IH_RELEASE(newfileptr->handle);
4116 if (errorCode == -1) {
4118 ("Del: inode=%s, name=%s, errno=%d\n",
4119 PrintInode(NULL, VN_GET_INO(newfileptr)),
4121 if ((errno != ENOENT) && (errno != EIO)
4122 && (errno != ENXIO))
4123 ViceLog(0, ("Do we need to fsck?"));
4126 VN_SET_INO(newfileptr, (Inode) 0);
4127 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4130 /* Link count did not drop to zero.
4131 * Mark NewName vnode as changed - updates stime.
4133 newfileptr->changed_newTime = 1;
4138 * If the create below fails, and the delete above worked, we have
4139 * removed the new name and not replaced it. This is not very likely,
4140 * but possible. We could try to put the old file back, but it is
4141 * highly unlikely that it would work since it would involve issuing
4144 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4147 /* Delete the old name */
4148 assert(Delete(&olddir, (char *)OldName) == 0);
4150 /* if the directory length changes, reflect it in the statistics */
4151 #if FS_STATS_DETAILED
4152 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4153 oldvptr->disk.linkCount, client->InSameNetwork);
4154 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4155 newvptr->disk.linkCount, client->InSameNetwork);
4157 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4158 oldvptr->disk.linkCount);
4159 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4160 newvptr->disk.linkCount);
4161 #endif /* FS_STATS_DETAILED */
4163 if (oldvptr == newvptr)
4164 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4166 fileptr->disk.parent = newvptr->vnodeNumber;
4167 fileptr->changed_newTime = 1; /* status change of moved file */
4169 /* if we are dealing with a rename of a directory */
4170 if (fileptr->disk.type == vDirectory) {
4171 assert(!fileptr->disk.cloned);
4172 SetDirHandle(&filedir, fileptr);
4173 /* fix .. to point to the correct place */
4174 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4175 assert(Create(&filedir, "..", NewDirFid) == 0);
4176 fileptr->disk.dataVersion++;
4177 /* if the parent directories are different the link counts have to be */
4178 /* changed due to .. in the renamed directory */
4179 if (oldvptr != newvptr) {
4180 oldvptr->disk.linkCount--;
4181 newvptr->disk.linkCount++;
4185 /* set up return status */
4186 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4187 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4188 if (newfileptr && doDelete) {
4189 DeleteFileCallBacks(&newFileFid); /* no other references */
4194 /* convert the write locks to a read locks before breaking callbacks */
4195 VVnodeWriteToRead(&errorCode, newvptr);
4196 assert(!errorCode || errorCode == VSALVAGE);
4197 if (oldvptr != newvptr) {
4198 VVnodeWriteToRead(&errorCode, oldvptr);
4199 assert(!errorCode || errorCode == VSALVAGE);
4201 if (newfileptr && !doDelete) {
4202 /* convert the write lock to a read lock before breaking callbacks */
4203 VVnodeWriteToRead(&errorCode, newfileptr);
4204 assert(!errorCode || errorCode == VSALVAGE);
4207 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4208 BreakCallBack(client->host, NewDirFid, 0);
4209 if (oldvptr != newvptr) {
4210 BreakCallBack(client->host, OldDirFid, 0);
4211 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4212 BreakCallBack(client->host, &fileFid, 0);
4215 /* Note: it is not necessary to break the callback */
4217 DeleteFileCallBacks(&newFileFid); /* no other references */
4219 /* other's still exist (with wrong link count) */
4220 BreakCallBack(client->host, &newFileFid, 1);
4225 VPutVnode(&fileCode, newfileptr);
4226 assert(fileCode == 0);
4228 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4229 newvptr : 0), oldvptr, volptr, &client);
4233 FidZap(&newfiledir);
4234 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4241 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4242 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4243 struct AFSFetchStatus * OutOldDirStatus,
4244 struct AFSFetchStatus * OutNewDirStatus,
4245 struct AFSVolSync * Sync)
4248 struct rx_connection *tcon;
4250 struct client *t_client = NULL; /* tmp ptr to client data */
4251 #if FS_STATS_DETAILED
4252 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4253 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4254 struct timeval elapsedTime; /* Transfer time */
4257 * Set our stats pointer, remember when the RPC operation started, and
4258 * tally the operation.
4260 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4264 FT_GetTimeOfDay(&opStartTime, 0);
4265 #endif /* FS_STATS_DETAILED */
4267 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4271 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4272 OutOldDirStatus, OutNewDirStatus, Sync);
4275 code = CallPostamble(tcon, code, thost);
4277 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4279 #if FS_STATS_DETAILED
4280 FT_GetTimeOfDay(&opStopTime, 0);
4283 (opP->numSuccesses)++;
4284 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4285 fs_stats_AddTo((opP->sumTime), elapsedTime);
4286 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4287 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4288 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4290 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4291 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4295 #endif /* FS_STATS_DETAILED */
4297 osi_auditU(acall, RenameFileEvent, code,
4298 AUD_ID, t_client ? t_client->ViceId : 0,
4299 AUD_FID, OldDirFid, AUD_STR, OldName,
4300 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4303 } /*SRXAFS_Rename */
4307 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4308 * merged into it when possible.
4311 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4312 char *LinkContents, struct AFSStoreStatus *InStatus,
4313 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4314 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4316 Vnode *parentptr = 0; /* vnode of input Directory */
4317 Vnode *targetptr = 0; /* vnode of the new link */
4318 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4319 Error errorCode = 0; /* error code */
4321 DirHandle dir; /* Handle for dir package I/O */
4322 Volume *volptr = 0; /* pointer to the volume header */
4323 struct client *client = 0; /* pointer to client structure */
4324 afs_int32 rights, anyrights; /* rights for this and any user */
4325 struct client *t_client; /* tmp ptr to client data */
4326 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4328 struct rx_connection *tcon = rx_ConnectionOf(acall);
4332 /* Get ptr to client data for user Id for logging */
4333 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4334 logHostAddr.s_addr = rxr_HostOf(tcon);
4336 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4337 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4338 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4340 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4342 if (!FileNameOK(Name)) {
4348 * Get the vnode and volume for the parent dir along with the caller's
4352 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4353 &parentwhentargetnotdir, &client, WRITE_LOCK,
4354 &rights, &anyrights))) {
4358 /* set volume synchronization information */
4359 SetVolumeSync(Sync, volptr);
4361 /* Does the caller has insert (and write) access to the parent directory? */
4362 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4367 * If we're creating a mount point (any x bits clear), we must have
4368 * administer access to the directory, too. Always allow sysadmins
4371 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4372 if (readonlyServer) {
4373 errorCode = VREADONLY;
4377 * We have a mountpoint, 'cause we're trying to set the Unix mode
4378 * bits to something with some x bits missing (default mode bits
4379 * if AFS_SETMODE is false is 0777)
4381 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4387 /* get a new vnode for the symlink and set it up */
4389 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4390 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4394 /* update the status of the parent vnode */
4395 #if FS_STATS_DETAILED
4396 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4397 parentptr->disk.linkCount,
4398 client->InSameNetwork);
4400 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4401 parentptr->disk.linkCount);
4402 #endif /* FS_STATS_DETAILED */
4404 /* update the status of the new symbolic link file vnode */
4405 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4406 parentptr, volptr, strlen((char *)LinkContents));
4408 /* Write the contents of the symbolic link name into the target inode */
4409 fdP = IH_OPEN(targetptr->handle);
4411 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4413 VTakeOffline(volptr);
4414 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4418 len = strlen((char *) LinkContents);
4419 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4421 ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4424 * Set up and return modified status for the parent dir and new symlink
4427 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4428 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4430 /* convert the write lock to a read lock before breaking callbacks */
4431 VVnodeWriteToRead(&errorCode, parentptr);
4432 assert(!errorCode || errorCode == VSALVAGE);
4434 /* break call back on the parent dir */
4435 BreakCallBack(client->host, DirFid, 0);
4438 /* Write the all modified vnodes (parent, new files) and volume back */
4439 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4442 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4443 return ( errorCode ? errorCode : code );
4445 } /*SAFSS_Symlink */
4449 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4450 struct AFSFid *DirFid, /* Parent dir's fid */
4451 char *Name, /* File name to create */
4452 char *LinkContents, /* Contents of the new created file */
4453 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4454 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4455 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4456 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4457 struct AFSVolSync *Sync)
4460 struct rx_connection *tcon;
4462 struct client *t_client = NULL; /* tmp ptr to client data */
4463 #if FS_STATS_DETAILED
4464 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4465 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4466 struct timeval elapsedTime; /* Transfer time */
4469 * Set our stats pointer, remember when the RPC operation started, and
4470 * tally the operation.
4472 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4476 FT_GetTimeOfDay(&opStartTime, 0);
4477 #endif /* FS_STATS_DETAILED */
4479 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4483 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4484 OutFidStatus, OutDirStatus, Sync);
4487 code = CallPostamble(tcon, code, thost);
4489 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4491 #if FS_STATS_DETAILED
4492 FT_GetTimeOfDay(&opStopTime, 0);
4495 (opP->numSuccesses)++;
4496 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4497 fs_stats_AddTo((opP->sumTime), elapsedTime);
4498 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4499 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4500 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4502 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4503 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4507 #endif /* FS_STATS_DETAILED */
4509 osi_auditU(acall, SymlinkEvent, code,
4510 AUD_ID, t_client ? t_client->ViceId : 0,
4511 AUD_FID, DirFid, AUD_STR, Name,
4512 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4515 } /*SRXAFS_Symlink */
4519 * This routine is called exclusively by SRXAFS_Link(), and should be
4520 * merged into it when possible.
4523 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4524 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4525 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4527 Vnode *parentptr = 0; /* vnode of input Directory */
4528 Vnode *targetptr = 0; /* vnode of the new file */
4529 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4530 Volume *volptr = 0; /* pointer to the volume header */
4531 Error errorCode = 0; /* error code */
4532 DirHandle dir; /* Handle for dir package I/O */
4533 struct client *client = 0; /* pointer to client structure */
4534 afs_int32 rights, anyrights; /* rights for this and any user */
4535 struct client *t_client; /* tmp ptr to client data */
4536 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4537 struct rx_connection *tcon = rx_ConnectionOf(acall);
4541 /* Get ptr to client data for user Id for logging */
4542 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4543 logHostAddr.s_addr = rxr_HostOf(tcon);
4545 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4546 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4547 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4548 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4550 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4552 if (DirFid->Volume != ExistingFid->Volume) {
4556 if (!FileNameOK(Name)) {
4562 * Get the vnode and volume for the parent dir along with the caller's
4566 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4567 &parentwhentargetnotdir, &client, WRITE_LOCK,
4568 &rights, &anyrights))) {
4572 /* set volume synchronization information */
4573 SetVolumeSync(Sync, volptr);
4575 /* Can the caller insert into the parent directory? */
4576 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4580 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4581 /* AFS fileservers always have directory vnodes that are odd. */
4586 /* get the file vnode */
4588 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4591 if (targetptr->disk.type != vFile) {
4595 if (targetptr->disk.parent != DirFid->Vnode) {
4599 if (parentptr->disk.cloned) {
4600 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4601 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4602 goto Bad_Link; /* disk full error */
4605 /* add the name to the directory */
4606 SetDirHandle(&dir, parentptr);
4607 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4611 /* update the status in the parent vnode */
4612 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4613 #if FS_STATS_DETAILED
4614 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4615 parentptr->disk.linkCount,
4616 client->InSameNetwork);
4618 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4619 parentptr->disk.linkCount);
4620 #endif /* FS_STATS_DETAILED */
4622 targetptr->disk.linkCount++;
4623 targetptr->disk.author = client->ViceId;
4624 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4626 /* set up return status */
4627 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4628 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4630 /* convert the write locks to read locks before breaking callbacks */
4631 VVnodeWriteToRead(&errorCode, targetptr);
4632 assert(!errorCode || errorCode == VSALVAGE);
4633 VVnodeWriteToRead(&errorCode, parentptr);
4634 assert(!errorCode || errorCode == VSALVAGE);
4636 /* break call back on DirFid */
4637 BreakCallBack(client->host, DirFid, 0);
4639 * We also need to break the callback for the file that is hard-linked since part
4640 * of its status (like linkcount) is changed
4642 BreakCallBack(client->host, ExistingFid, 0);
4645 /* Write the all modified vnodes (parent, new files) and volume back */
4646 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4649 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4656 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4657 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4658 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4661 struct rx_connection *tcon;
4663 struct client *t_client = NULL; /* tmp ptr to client data */
4664 #if FS_STATS_DETAILED
4665 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4666 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4667 struct timeval elapsedTime; /* Transfer time */
4670 * Set our stats pointer, remember when the RPC operation started, and
4671 * tally the operation.
4673 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4677 FT_GetTimeOfDay(&opStartTime, 0);
4678 #endif /* FS_STATS_DETAILED */
4680 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4684 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4685 OutDirStatus, Sync);
4688 code = CallPostamble(tcon, code, thost);
4690 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4692 #if FS_STATS_DETAILED
4693 FT_GetTimeOfDay(&opStopTime, 0);
4696 (opP->numSuccesses)++;
4697 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4698 fs_stats_AddTo((opP->sumTime), elapsedTime);
4699 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4700 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4701 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4703 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4704 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4708 #endif /* FS_STATS_DETAILED */
4710 osi_auditU(acall, LinkEvent, code,
4711 AUD_ID, t_client ? t_client->ViceId : 0,
4712 AUD_FID, DirFid, AUD_STR, Name,
4713 AUD_FID, ExistingFid, AUD_END);
4720 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4721 * merged into it when possible.
4724 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4725 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4726 struct AFSFetchStatus *OutFidStatus,
4727 struct AFSFetchStatus *OutDirStatus,
4728 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4730 Vnode *parentptr = 0; /* vnode of input Directory */
4731 Vnode *targetptr = 0; /* vnode of the new file */
4732 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4733 Volume *volptr = 0; /* pointer to the volume header */
4734 Error errorCode = 0; /* error code */
4735 struct acl_accessList *newACL; /* Access list */
4736 int newACLSize; /* Size of access list */
4737 DirHandle dir; /* Handle for dir package I/O */
4738 DirHandle parentdir; /* Handle for dir package I/O */
4739 struct client *client = 0; /* pointer to client structure */
4740 afs_int32 rights, anyrights; /* rights for this and any user */
4741 struct client *t_client; /* tmp ptr to client data */
4742 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4743 struct rx_connection *tcon = rx_ConnectionOf(acall);
4746 FidZero(&parentdir);
4748 /* Get ptr to client data for user Id for logging */
4749 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4750 logHostAddr.s_addr = rxr_HostOf(tcon);
4752 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4753 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4754 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4756 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4758 if (!FileNameOK(Name)) {
4764 * Get the vnode and volume for the parent dir along with the caller's
4768 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4769 &parentwhentargetnotdir, &client, WRITE_LOCK,
4770 &rights, &anyrights))) {
4774 /* set volume synchronization information */
4775 SetVolumeSync(Sync, volptr);
4777 /* Write access to the parent directory? */
4778 #ifdef DIRCREATE_NEED_WRITE
4780 * requires w access for the user to create a directory. this
4781 * closes a loophole in the current security arrangement, since a
4782 * user with i access only can create a directory and get the
4783 * implcit a access that goes with dir ownership, and proceed to
4784 * subvert quota in the volume.
4786 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4787 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4789 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4790 #endif /* DIRCREATE_NEED_WRITE */
4793 #define EMPTYDIRBLOCKS 2
4794 /* get a new vnode and set it up */
4796 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4797 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4801 /* Update the status for the parent dir */
4802 #if FS_STATS_DETAILED
4803 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4804 parentptr->disk.linkCount + 1,
4805 client->InSameNetwork);
4807 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4808 parentptr->disk.linkCount + 1);
4809 #endif /* FS_STATS_DETAILED */
4811 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4812 assert((SetAccessList
4813 (&targetptr, &volptr, &newACL, &newACLSize,
4814 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4815 assert(parentwhentargetnotdir == 0);
4816 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4818 /* update the status for the target vnode */
4819 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4820 parentptr, volptr, 0);
4822 /* Actually create the New directory in the directory package */
4823 SetDirHandle(&dir, targetptr);
4824 assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4826 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4828 /* set up return status */
4829 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4830 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4832 /* convert the write lock to a read lock before breaking callbacks */
4833 VVnodeWriteToRead(&errorCode, parentptr);
4834 assert(!errorCode || errorCode == VSALVAGE);
4836 /* break call back on DirFid */
4837 BreakCallBack(client->host, DirFid, 0);
4839 /* Return a callback promise to caller */
4840 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4843 /* Write the all modified vnodes (parent, new files) and volume back */
4844 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4848 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4851 } /*SAFSS_MakeDir */
4855 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4856 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4857 struct AFSFetchStatus * OutFidStatus,
4858 struct AFSFetchStatus * OutDirStatus,
4859 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4862 struct rx_connection *tcon;
4864 struct client *t_client = NULL; /* tmp ptr to client data */
4865 #if FS_STATS_DETAILED
4866 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4867 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4868 struct timeval elapsedTime; /* Transfer time */
4871 * Set our stats pointer, remember when the RPC operation started, and
4872 * tally the operation.
4874 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4878 FT_GetTimeOfDay(&opStartTime, 0);
4879 #endif /* FS_STATS_DETAILED */
4880 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4884 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4885 OutDirStatus, CallBack, Sync);
4888 code = CallPostamble(tcon, code, thost);
4890 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4892 #if FS_STATS_DETAILED
4893 FT_GetTimeOfDay(&opStopTime, 0);
4896 (opP->numSuccesses)++;
4897 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4898 fs_stats_AddTo((opP->sumTime), elapsedTime);
4899 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4900 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4901 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4903 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4904 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4908 #endif /* FS_STATS_DETAILED */
4910 osi_auditU(acall, MakeDirEvent, code,
4911 AUD_ID, t_client ? t_client->ViceId : 0,
4912 AUD_FID, DirFid, AUD_STR, Name,
4913 AUD_FID, OutFid, AUD_END);
4916 } /*SRXAFS_MakeDir */
4920 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4921 * merged into it when possible.
4924 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4925 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4927 Vnode *parentptr = 0; /* vnode of input Directory */
4928 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4929 Vnode *targetptr = 0; /* file to be deleted */
4930 AFSFid fileFid; /* area for Fid from the directory */
4931 Error errorCode = 0; /* error code */
4932 DirHandle dir; /* Handle for dir package I/O */
4933 Volume *volptr = 0; /* pointer to the volume header */
4934 struct client *client = 0; /* pointer to client structure */
4935 afs_int32 rights, anyrights; /* rights for this and any user */
4936 Vnode debugvnode1, debugvnode2;
4937 struct client *t_client; /* tmp ptr to client data */
4938 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4939 struct rx_connection *tcon = rx_ConnectionOf(acall);
4943 /* Get ptr to client data for user Id for logging */
4944 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4945 logHostAddr.s_addr = rxr_HostOf(tcon);
4947 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4948 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4949 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4951 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4954 * Get the vnode and volume for the parent dir along with the caller's
4958 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4959 &parentwhentargetnotdir, &client, WRITE_LOCK,
4960 &rights, &anyrights))) {
4963 debugvnode1 = *parentptr;
4965 /* set volume synchronization information */
4966 SetVolumeSync(Sync, volptr);
4968 /* Does the caller has delete (&write) access to the parent dir? */
4969 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4973 debugvnode2 = *parentptr;
4974 /* Do the actual delete of the desired (empty) directory, Name */
4976 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4981 /* Update the status for the parent dir; link count is also adjusted */
4982 #if FS_STATS_DETAILED
4983 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4984 parentptr->disk.linkCount - 1,
4985 client->InSameNetwork);
4987 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4988 parentptr->disk.linkCount - 1);
4989 #endif /* FS_STATS_DETAILED */
4991 /* Return to the caller the updated parent dir status */
4992 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4995 * Note: it is not necessary to break the callback on fileFid, since
4996 * refcount is now 0, so no one should be able to refer to the dir
4999 DeleteFileCallBacks(&fileFid);
5001 /* convert the write lock to a read lock before breaking callbacks */
5002 VVnodeWriteToRead(&errorCode, parentptr);
5003 assert(!errorCode || errorCode == VSALVAGE);
5005 /* break call back on DirFid and fileFid */
5006 BreakCallBack(client->host, DirFid, 0);
5009 /* Write the all modified vnodes (parent, new files) and volume back */
5010 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5013 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5016 } /*SAFSS_RemoveDir */
5020 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5021 struct AFSFetchStatus * OutDirStatus,
5022 struct AFSVolSync * Sync)
5025 struct rx_connection *tcon;
5027 struct client *t_client = NULL; /* tmp ptr to client data */
5028 #if FS_STATS_DETAILED
5029 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5030 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5031 struct timeval elapsedTime; /* Transfer time */
5034 * Set our stats pointer, remember when the RPC operation started, and
5035 * tally the operation.
5037 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5041 FT_GetTimeOfDay(&opStartTime, 0);
5042 #endif /* FS_STATS_DETAILED */
5044 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5047 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5050 code = CallPostamble(tcon, code, thost);
5052 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5054 #if FS_STATS_DETAILED
5055 FT_GetTimeOfDay(&opStopTime, 0);
5058 (opP->numSuccesses)++;
5059 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5060 fs_stats_AddTo((opP->sumTime), elapsedTime);
5061 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5062 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5063 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5065 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5066 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5070 #endif /* FS_STATS_DETAILED */
5072 osi_auditU(acall, RemoveDirEvent, code,
5073 AUD_ID, t_client ? t_client->ViceId : 0,
5074 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5077 } /*SRXAFS_RemoveDir */
5081 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5082 * merged into it when possible.
5085 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5086 struct AFSVolSync *Sync)
5088 Vnode *targetptr = 0; /* vnode of input file */
5089 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5090 Error errorCode = 0; /* error code */
5091 Volume *volptr = 0; /* pointer to the volume header */
5092 struct client *client = 0; /* pointer to client structure */
5093 afs_int32 rights, anyrights; /* rights for this and any user */
5094 struct client *t_client; /* tmp ptr to client data */
5095 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5096 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5097 struct rx_connection *tcon = rx_ConnectionOf(acall);
5099 if (type != LockRead && type != LockWrite) {
5103 /* Get ptr to client data for user Id for logging */
5104 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5105 logHostAddr.s_addr = rxr_HostOf(tcon);
5107 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5108 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5109 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5111 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5114 * Get the vnode and volume for the desired file along with the caller's
5118 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5119 &parentwhentargetnotdir, &client, WRITE_LOCK,
5120 &rights, &anyrights))) {
5124 /* set volume synchronization information */
5125 SetVolumeSync(Sync, volptr);
5127 /* Handle the particular type of set locking, type */
5128 errorCode = HandleLocking(targetptr, client, rights, type);
5131 /* Write the all modified vnodes (parent, new files) and volume back */
5132 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5135 if ((errorCode == VREADONLY) && (type == LockRead))
5136 errorCode = 0; /* allow read locks on RO volumes without saving state */
5138 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5141 } /*SAFSS_SetLock */
5145 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5146 ViceLockType type, struct AFSVolSync * Sync)
5148 return SRXAFS_SetLock(acall, Fid, type, Sync);
5149 } /*SRXAFS_OldSetLock */
5153 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5154 struct AFSVolSync * Sync)
5157 struct rx_connection *tcon;
5159 struct client *t_client = NULL; /* tmp ptr to client data */
5160 #if FS_STATS_DETAILED
5161 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5162 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5163 struct timeval elapsedTime; /* Transfer time */
5166 * Set our stats pointer, remember when the RPC operation started, and
5167 * tally the operation.
5169 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5173 FT_GetTimeOfDay(&opStartTime, 0);
5174 #endif /* FS_STATS_DETAILED */
5176 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5179 code = SAFSS_SetLock(acall, Fid, type, Sync);
5182 code = CallPostamble(tcon, code, thost);
5184 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5186 #if FS_STATS_DETAILED
5187 FT_GetTimeOfDay(&opStopTime, 0);
5190 (opP->numSuccesses)++;
5191 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5192 fs_stats_AddTo((opP->sumTime), elapsedTime);
5193 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5194 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5195 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5197 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5198 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5202 #endif /* FS_STATS_DETAILED */
5204 osi_auditU(acall, SetLockEvent, code,
5205 AUD_ID, t_client ? t_client->ViceId : 0,
5206 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5208 } /*SRXAFS_SetLock */
5212 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5213 * merged into it when possible.
5216 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5217 struct AFSVolSync *Sync)
5219 Vnode *targetptr = 0; /* vnode of input file */
5220 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5221 Error errorCode = 0; /* error code */
5222 Volume *volptr = 0; /* pointer to the volume header */
5223 struct client *client = 0; /* pointer to client structure */
5224 afs_int32 rights, anyrights; /* rights for this and any user */
5225 struct client *t_client; /* tmp ptr to client data */
5226 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5227 struct rx_connection *tcon = rx_ConnectionOf(acall);
5229 /* Get ptr to client data for user Id for logging */
5230 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5231 logHostAddr.s_addr = rxr_HostOf(tcon);
5233 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5234 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5235 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5237 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5240 * Get the vnode and volume for the desired file along with the caller's
5244 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5245 &parentwhentargetnotdir, &client, WRITE_LOCK,
5246 &rights, &anyrights))) {
5247 goto Bad_ExtendLock;
5250 /* set volume synchronization information */
5251 SetVolumeSync(Sync, volptr);
5253 /* Handle the actual lock extension */
5254 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5257 /* Put back file's vnode and volume */
5258 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5261 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5262 errorCode = 0; /* under our generous policy re RO vols */
5264 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5267 } /*SAFSS_ExtendLock */
5271 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5272 struct AFSVolSync * Sync)
5274 return SRXAFS_ExtendLock(acall, Fid, Sync);
5275 } /*SRXAFS_OldExtendLock */
5279 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5280 struct AFSVolSync * Sync)
5283 struct rx_connection *tcon;
5285 struct client *t_client = NULL; /* tmp ptr to client data */
5286 #if FS_STATS_DETAILED
5287 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5288 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5289 struct timeval elapsedTime; /* Transfer time */
5292 * Set our stats pointer, remember when the RPC operation started, and
5293 * tally the operation.
5295 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5299 FT_GetTimeOfDay(&opStartTime, 0);
5300 #endif /* FS_STATS_DETAILED */
5302 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5303 goto Bad_ExtendLock;
5305 code = SAFSS_ExtendLock(acall, Fid, Sync);
5308 code = CallPostamble(tcon, code, thost);
5310 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5312 #if FS_STATS_DETAILED
5313 FT_GetTimeOfDay(&opStopTime, 0);
5316 (opP->numSuccesses)++;
5317 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5318 fs_stats_AddTo((opP->sumTime), elapsedTime);
5319 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5320 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5321 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5323 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5324 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5328 #endif /* FS_STATS_DETAILED */
5330 osi_auditU(acall, ExtendLockEvent, code,
5331 AUD_ID, t_client ? t_client->ViceId : 0,
5332 AUD_FID, Fid, AUD_END);
5335 } /*SRXAFS_ExtendLock */
5339 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5340 * merged into it when possible.
5343 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5344 struct AFSVolSync *Sync)
5346 Vnode *targetptr = 0; /* vnode of input file */
5347 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5348 Error errorCode = 0; /* error code */
5349 Volume *volptr = 0; /* pointer to the volume header */
5350 struct client *client = 0; /* pointer to client structure */
5351 afs_int32 rights, anyrights; /* rights for this and any user */
5352 struct client *t_client; /* tmp ptr to client data */
5353 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5354 struct rx_connection *tcon = rx_ConnectionOf(acall);
5356 /* Get ptr to client data for user Id for logging */
5357 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5358 logHostAddr.s_addr = rxr_HostOf(tcon);
5360 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5361 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5362 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5364 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5367 * Get the vnode and volume for the desired file along with the caller's
5371 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5372 &parentwhentargetnotdir, &client, WRITE_LOCK,
5373 &rights, &anyrights))) {
5374 goto Bad_ReleaseLock;
5377 /* set volume synchronization information */
5378 SetVolumeSync(Sync, volptr);
5380 /* Handle the actual lock release */
5381 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5382 goto Bad_ReleaseLock;
5384 /* if no more locks left, a callback would be triggered here */
5385 if (targetptr->disk.lock.lockCount <= 0) {
5386 /* convert the write lock to a read lock before breaking callbacks */
5387 VVnodeWriteToRead(&errorCode, targetptr);
5388 assert(!errorCode || errorCode == VSALVAGE);
5389 BreakCallBack(client->host, Fid, 0);
5393 /* Put back file's vnode and volume */
5394 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5397 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5398 errorCode = 0; /* under our generous policy re RO vols */
5400 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5403 } /*SAFSS_ReleaseLock */
5407 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5408 struct AFSVolSync * Sync)
5410 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5411 } /*SRXAFS_OldReleaseLock */
5415 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5416 struct AFSVolSync * Sync)
5419 struct rx_connection *tcon;
5421 struct client *t_client = NULL; /* tmp ptr to client data */
5422 #if FS_STATS_DETAILED
5423 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5424 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5425 struct timeval elapsedTime; /* Transfer time */
5428 * Set our stats pointer, remember when the RPC operation started, and
5429 * tally the operation.
5431 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5435 FT_GetTimeOfDay(&opStartTime, 0);
5436 #endif /* FS_STATS_DETAILED */
5438 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5439 goto Bad_ReleaseLock;
5441 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5444 code = CallPostamble(tcon, code, thost);
5446 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5448 #if FS_STATS_DETAILED
5449 FT_GetTimeOfDay(&opStopTime, 0);
5452 (opP->numSuccesses)++;
5453 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5454 fs_stats_AddTo((opP->sumTime), elapsedTime);
5455 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5456 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5457 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5459 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5460 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5464 #endif /* FS_STATS_DETAILED */
5466 osi_auditU(acall, ReleaseLockEvent, code,
5467 AUD_ID, t_client ? t_client->ViceId : 0,
5468 AUD_FID, Fid, AUD_END);
5471 } /*SRXAFS_ReleaseLock */
5475 SetSystemStats(struct AFSStatistics *stats)
5477 /* Fix this sometime soon.. */
5478 /* Because hey, it's not like we have a network monitoring protocol... */
5479 struct timeval time;
5481 /* this works on all system types */
5482 FT_GetTimeOfDay(&time, 0);
5483 stats->CurrentTime = time.tv_sec;
5484 } /*SetSystemStats */
5487 SetAFSStats(struct AFSStatistics *stats)
5489 extern afs_int32 StartTime, CurrentConnections;
5493 stats->CurrentMsgNumber = 0;
5494 stats->OldestMsgNumber = 0;
5495 stats->StartTime = StartTime;
5496 stats->CurrentConnections = CurrentConnections;
5497 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5498 stats->TotalFetchs =
5499 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5500 AFSCallStats.FetchStatus;
5501 stats->FetchDatas = AFSCallStats.FetchData;
5502 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5503 seconds = AFSCallStats.AccumFetchTime / 1000;
5506 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5507 stats->TotalStores =
5508 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5509 AFSCallStats.StoreStatus;
5510 stats->StoreDatas = AFSCallStats.StoreData;
5511 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5512 seconds = AFSCallStats.AccumStoreTime / 1000;
5515 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5517 stats->ProcessSize = -1; /* TODO: */
5519 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5522 h_GetWorkStats((int *)&(stats->WorkStations),
5523 (int *)&(stats->ActiveWorkStations), (int *)0,
5524 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5528 /* Get disk related information from all AFS partitions. */
5531 SetVolumeStats(struct AFSStatistics *stats)
5533 struct DiskPartition64 *part;
5536 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5537 part = part->next) {
5538 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5539 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5540 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5541 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5544 while (i < AFS_MSTATDISKS) {
5545 stats->Disks[i].TotalBlocks = -1;
5548 } /*SetVolumeStats */
5551 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5554 struct rx_connection *tcon = rx_ConnectionOf(acall);
5556 struct client *t_client = NULL; /* tmp ptr to client data */
5557 #if FS_STATS_DETAILED
5558 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5559 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5560 struct timeval elapsedTime; /* Transfer time */
5563 * Set our stats pointer, remember when the RPC operation started, and
5564 * tally the operation.
5566 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5570 FT_GetTimeOfDay(&opStartTime, 0);
5571 #endif /* FS_STATS_DETAILED */
5573 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5574 goto Bad_GetStatistics;
5576 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5578 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5580 memset(Statistics, 0, sizeof(*Statistics));
5581 SetAFSStats((struct AFSStatistics *)Statistics);
5582 SetVolumeStats((struct AFSStatistics *)Statistics);
5583 SetSystemStats((struct AFSStatistics *)Statistics);
5586 code = CallPostamble(tcon, code, thost);
5588 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5590 #if FS_STATS_DETAILED
5591 FT_GetTimeOfDay(&opStopTime, 0);
5594 (opP->numSuccesses)++;
5595 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5596 fs_stats_AddTo((opP->sumTime), elapsedTime);
5597 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5598 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5599 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5601 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5602 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5606 #endif /* FS_STATS_DETAILED */
5608 osi_auditU(acall, GetStatisticsEvent, code,
5609 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5611 } /*SRXAFS_GetStatistics */
5615 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5617 extern afs_int32 StartTime, CurrentConnections;
5620 struct rx_connection *tcon = rx_ConnectionOf(acall);
5622 struct client *t_client = NULL; /* tmp ptr to client data */
5623 struct timeval time;
5624 #if FS_STATS_DETAILED
5625 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5626 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5627 struct timeval elapsedTime; /* Transfer time */
5630 * Set our stats pointer, remember when the RPC operation started, and
5631 * tally the operation.
5633 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5637 FT_GetTimeOfDay(&opStartTime, 0);
5638 #endif /* FS_STATS_DETAILED */
5640 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5641 goto Bad_GetStatistics64;
5643 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5644 Statistics->ViceStatistics64_val =
5645 malloc(statsVersion*sizeof(afs_int64));
5646 Statistics->ViceStatistics64_len = statsVersion;
5648 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5649 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5650 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5652 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5653 AFSCallStats.TotalCalls;
5654 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5655 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5656 AFSCallStats.FetchStatus;
5657 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5658 AFSCallStats.FetchData;
5659 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5660 AFSCallStats.TotalFetchedBytes;
5661 seconds = AFSCallStats.AccumFetchTime / 1000;
5664 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5665 AFSCallStats.TotalFetchedBytes / seconds;
5666 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5667 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5668 AFSCallStats.StoreStatus;
5669 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5670 AFSCallStats.StoreData;
5671 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5672 AFSCallStats.TotalStoredBytes;
5673 seconds = AFSCallStats.AccumStoreTime / 1000;
5676 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5677 AFSCallStats.TotalStoredBytes / seconds;
5679 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5681 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5682 (afs_int32) ((long)sbrk(0) >> 10);
5685 h_GetWorkStats((int *)&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5686 (int *)&(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5688 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5692 /* this works on all system types */
5693 FT_GetTimeOfDay(&time, 0);
5694 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5696 Bad_GetStatistics64:
5697 code = CallPostamble(tcon, code, thost);
5699 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5701 #if FS_STATS_DETAILED
5702 FT_GetTimeOfDay(&opStopTime, 0);
5705 (opP->numSuccesses)++;
5706 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5707 fs_stats_AddTo((opP->sumTime), elapsedTime);
5708 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5709 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5710 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5712 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5713 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5717 #endif /* FS_STATS_DETAILED */
5719 osi_auditU(acall, GetStatisticsEvent, code,
5720 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5722 } /*SRXAFS_GetStatistics */
5725 /*------------------------------------------------------------------------
5726 * EXPORTED SRXAFS_XStatsVersion
5729 * Routine called by the server-side RPC interface to implement
5730 * pulling out the xstat version number for the File Server.
5733 * a_versionP : Ptr to the version number variable to set.
5739 * Nothing interesting.
5743 *------------------------------------------------------------------------*/
5746 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5747 { /*SRXAFS_XStatsVersion */
5749 struct client *t_client = NULL; /* tmp ptr to client data */
5750 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5751 #if FS_STATS_DETAILED
5752 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5753 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5754 struct timeval elapsedTime; /* Transfer time */
5757 * Set our stats pointer, remember when the RPC operation started, and
5758 * tally the operation.
5760 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5764 FT_GetTimeOfDay(&opStartTime, 0);
5765 #endif /* FS_STATS_DETAILED */
5767 *a_versionP = AFS_XSTAT_VERSION;
5769 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5771 #if FS_STATS_DETAILED
5772 FT_GetTimeOfDay(&opStopTime, 0);
5773 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5774 fs_stats_AddTo((opP->sumTime), elapsedTime);
5775 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5776 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5777 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5779 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5780 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5783 (opP->numSuccesses)++;
5785 #endif /* FS_STATS_DETAILED */
5787 osi_auditU(a_call, XStatsVersionEvent, 0,
5788 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5790 } /*SRXAFS_XStatsVersion */
5793 /*------------------------------------------------------------------------
5794 * PRIVATE FillPerfValues
5797 * Routine called to fill a regular performance data structure.
5800 * a_perfP : Ptr to perf structure to fill
5806 * Various collections need this info, so the guts were put in
5807 * this separate routine.
5811 *------------------------------------------------------------------------*/
5814 FillPerfValues(struct afs_PerfStats *a_perfP)
5815 { /*FillPerfValues */
5817 int dir_Buffers; /*# buffers in use by dir package */
5818 int dir_Calls; /*# read calls in dir package */
5819 int dir_IOs; /*# I/O ops in dir package */
5822 * Vnode cache section.
5824 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5825 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5826 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5827 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5828 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5829 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5830 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5831 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5832 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5833 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5834 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5835 SplitInt64(VStats.hdr_gets, hi, lo);
5836 a_perfP->vcache_H_Gets = lo;
5837 SplitInt64(VStats.hdr_loads, hi, lo);
5838 a_perfP->vcache_H_Replacements = lo;
5841 * Directory section.
5843 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5844 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5845 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5846 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5851 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5852 a_perfP->rx_noPackets_RcvClass =
5853 (afs_int32) rx_stats.receivePktAllocFailures;
5854 a_perfP->rx_noPackets_SendClass =
5855 (afs_int32) rx_stats.sendPktAllocFailures;
5856 a_perfP->rx_noPackets_SpecialClass =
5857 (afs_int32) rx_stats.specialPktAllocFailures;
5858 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5859 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5860 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5861 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5862 a_perfP->rx_noPacketBuffersOnRead =
5863 (afs_int32) rx_stats.noPacketBuffersOnRead;
5864 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5865 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5866 a_perfP->rx_packetsRead_RcvClass =
5867 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5868 a_perfP->rx_packetsRead_SendClass =
5869 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5870 a_perfP->rx_packetsRead_SpecialClass =
5871 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5872 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5873 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5874 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5875 a_perfP->rx_spuriousPacketsRead =
5876 (afs_int32) rx_stats.spuriousPacketsRead;
5877 a_perfP->rx_packetsSent_RcvClass =
5878 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5879 a_perfP->rx_packetsSent_SendClass =
5880 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5881 a_perfP->rx_packetsSent_SpecialClass =
5882 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5883 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5884 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5885 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5886 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5887 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5888 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5889 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5890 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5891 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5892 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5893 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5894 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5895 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5896 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5897 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5898 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5899 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5900 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5901 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5902 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5904 a_perfP->host_NumHostEntries = HTs;
5905 a_perfP->host_HostBlocks = HTBlocks;
5906 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5907 &(a_perfP->host_HostsInSameNetOrSubnet),
5908 &(a_perfP->host_HostsInDiffSubnet),
5909 &(a_perfP->host_HostsInDiffNetwork));
5910 a_perfP->host_NumClients = CEs;
5911 a_perfP->host_ClientBlocks = CEBlocks;
5913 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5914 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5915 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5916 } /*FillPerfValues */
5919 /*------------------------------------------------------------------------
5920 * EXPORTED SRXAFS_GetXStats
5923 * Routine called by the server-side callback RPC interface to
5924 * implement getting the given data collection from the extended
5925 * File Server statistics.
5928 * a_call : Ptr to Rx call on which this request came in.
5929 * a_clientVersionNum : Client version number.
5930 * a_opCode : Desired operation.
5931 * a_serverVersionNumP : Ptr to version number to set.
5932 * a_timeP : Ptr to time value (seconds) to set.
5933 * a_dataP : Ptr to variable array structure to return
5940 * Nothing interesting.
5944 *------------------------------------------------------------------------*/
5947 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5948 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5949 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5950 { /*SRXAFS_GetXStats */
5952 register int code; /*Return value */
5953 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5954 afs_int32 dataBytes; /*Bytes in data buffer */
5955 #if FS_STATS_DETAILED
5956 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5957 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5958 struct timeval elapsedTime; /* Transfer time */
5961 * Set our stats pointer, remember when the RPC operation started, and
5962 * tally the operation.
5964 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5968 FT_GetTimeOfDay(&opStartTime, 0);
5969 #endif /* FS_STATS_DETAILED */
5972 * Record the time of day and the server version number.
5974 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5975 *a_timeP = FT_ApproxTime();
5978 * Stuff the appropriate data in there (assume victory)
5983 ("Received GetXStats call for collection %d\n",
5984 a_collectionNumber));
5988 * We're not keeping stats, so just return successfully with
5991 a_dataP->AFS_CollData_len = 0;
5992 a_dataP->AFS_CollData_val = NULL;
5995 switch (a_collectionNumber) {
5996 case AFS_XSTATSCOLL_CALL_INFO:
5998 * Pass back all the call-count-related data.
6000 * >>> We are forced to allocate a separate area in which to
6001 * >>> put this stuff in by the RPC stub generator, since it
6002 * >>> will be freed at the tail end of the server stub code.
6006 * I don't think call-level stats are being collected yet
6007 * for the File Server.
6009 dataBytes = sizeof(struct afs_Stats);
6010 dataBuffP = (afs_int32 *) malloc(dataBytes);
6011 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6012 a_dataP->AFS_CollData_len = dataBytes >> 2;
6013 a_dataP->AFS_CollData_val = dataBuffP;
6015 a_dataP->AFS_CollData_len = 0;
6016 a_dataP->AFS_CollData_val = NULL;
6020 case AFS_XSTATSCOLL_PERF_INFO:
6022 * Pass back all the regular performance-related data.
6024 * >>> We are forced to allocate a separate area in which to
6025 * >>> put this stuff in by the RPC stub generator, since it
6026 * >>> will be freed at the tail end of the server stub code.
6029 afs_perfstats.numPerfCalls++;
6030 FillPerfValues(&afs_perfstats);
6033 * Don't overwrite the spares at the end.
6036 dataBytes = sizeof(struct afs_PerfStats);
6037 dataBuffP = (afs_int32 *) malloc(dataBytes);
6038 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6039 a_dataP->AFS_CollData_len = dataBytes >> 2;
6040 a_dataP->AFS_CollData_val = dataBuffP;
6043 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6045 * Pass back the full collection of performance-related data.
6046 * We have to stuff the basic, overall numbers in, but the
6047 * detailed numbers are kept in the structure already.
6049 * >>> We are forced to allocate a separate area in which to
6050 * >>> put this stuff in by the RPC stub generator, since it
6051 * >>> will be freed at the tail end of the server stub code.
6054 afs_perfstats.numPerfCalls++;
6055 #if FS_STATS_DETAILED
6056 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6057 FillPerfValues(&afs_FullPerfStats.overall);
6060 * Don't overwrite the spares at the end.
6063 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6064 dataBuffP = (afs_int32 *) malloc(dataBytes);
6065 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6066 a_dataP->AFS_CollData_len = dataBytes >> 2;
6067 a_dataP->AFS_CollData_val = dataBuffP;
6071 case AFS_XSTATSCOLL_CBSTATS:
6072 afs_perfstats.numPerfCalls++;
6074 dataBytes = sizeof(struct cbcounters);
6075 dataBuffP = (afs_int32 *) malloc(dataBytes);
6077 extern struct cbcounters cbstuff;
6078 dataBuffP[0]=cbstuff.DeleteFiles;
6079 dataBuffP[1]=cbstuff.DeleteCallBacks;
6080 dataBuffP[2]=cbstuff.BreakCallBacks;
6081 dataBuffP[3]=cbstuff.AddCallBacks;
6082 dataBuffP[4]=cbstuff.GotSomeSpaces;
6083 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6084 dataBuffP[6]=cbstuff.nFEs;
6085 dataBuffP[7]=cbstuff.nCBs;
6086 dataBuffP[8]=cbstuff.nblks;
6087 dataBuffP[9]=cbstuff.CBsTimedOut;
6088 dataBuffP[10]=cbstuff.nbreakers;
6089 dataBuffP[11]=cbstuff.GSS1;
6090 dataBuffP[12]=cbstuff.GSS2;
6091 dataBuffP[13]=cbstuff.GSS3;
6092 dataBuffP[14]=cbstuff.GSS4;
6093 dataBuffP[15]=cbstuff.GSS5;
6096 a_dataP->AFS_CollData_len = dataBytes >> 2;
6097 a_dataP->AFS_CollData_val = dataBuffP;
6103 * Illegal collection number.
6105 a_dataP->AFS_CollData_len = 0;
6106 a_dataP->AFS_CollData_val = NULL;
6108 } /*Switch on collection number */
6110 #if FS_STATS_DETAILED
6111 FT_GetTimeOfDay(&opStopTime, 0);
6114 (opP->numSuccesses)++;
6115 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6116 fs_stats_AddTo((opP->sumTime), elapsedTime);
6117 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6118 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6119 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6121 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6122 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6126 #endif /* FS_STATS_DETAILED */
6130 } /*SRXAFS_GetXStats */
6134 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6135 struct AFSCBs *CallBackArray)
6137 afs_int32 errorCode = 0;
6139 struct client *client = 0;
6140 struct rx_connection *tcon;
6142 #if FS_STATS_DETAILED
6143 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6144 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6145 struct timeval elapsedTime; /* Transfer time */
6148 * Set our stats pointer, remember when the RPC operation started, and
6149 * tally the operation.
6152 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6156 FT_GetTimeOfDay(&opStartTime, 0);
6157 #endif /* FS_STATS_DETAILED */
6161 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6162 FidArray->AFSCBFids_len));
6165 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6167 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6168 goto Bad_GiveUpCallBacks;
6170 if (!FidArray && !CallBackArray) {
6172 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6173 (tcon->peer ? tcon->peer->host : 0)));
6174 errorCode = GetClient(tcon, &client);
6177 DeleteAllCallBacks_r(client->host, 1);
6182 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6184 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6185 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6186 (tcon->peer ? tcon->peer->host : 0)));
6188 goto Bad_GiveUpCallBacks;
6191 errorCode = GetClient(tcon, &client);
6193 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6194 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6195 DeleteCallBack(client->host, fid);
6201 Bad_GiveUpCallBacks:
6202 errorCode = CallPostamble(tcon, errorCode, thost);
6204 #if FS_STATS_DETAILED
6205 FT_GetTimeOfDay(&opStopTime, 0);
6206 if (errorCode == 0) {
6208 (opP->numSuccesses)++;
6209 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6210 fs_stats_AddTo((opP->sumTime), elapsedTime);
6211 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6212 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6213 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6215 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6216 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6220 #endif /* FS_STATS_DETAILED */
6223 } /*common_GiveUpCallBacks */
6227 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6228 struct AFSCBs * CallBackArray)
6230 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6231 } /*SRXAFS_GiveUpCallBacks */
6234 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6236 return common_GiveUpCallBacks(acall, 0, 0);
6237 } /*SRXAFS_GiveUpAllCallBacks */
6241 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6242 struct AFSVolumeInfo * avolinfo)
6244 return (VNOVOL); /* XXX Obsolete routine XXX */
6246 } /*SRXAFS_NGetVolumeInfo */
6250 * Dummy routine. Should never be called (the cache manager should only
6251 * invoke this interface when communicating with a AFS/DFS Protocol
6255 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6256 char *afs_name_p, struct AFSFid * afs_fid_p,
6257 struct AFSFetchStatus * afs_status_p,
6258 struct AFSFetchStatus * afs_dir_status_p,
6259 struct AFSCallBack * afs_callback_p,
6260 struct AFSVolSync * afs_sync_p)
6267 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6270 struct rx_connection *tcon;
6272 afs_uint32 *dataBuffP;
6273 afs_int32 dataBytes;
6276 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6277 afs_FullPerfStats.overall.fs_nGetCaps++;
6279 ViceLog(2, ("SAFS_GetCapabilties\n"));
6281 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6284 dataBytes = 1 * sizeof(afs_int32);
6285 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6286 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6287 #if defined(AFS_64BIT_ENV)
6288 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6291 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6293 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6294 capabilities->Capabilities_val = dataBuffP;
6297 code = CallPostamble(tcon, code, thost);
6304 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6305 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6309 afs_int32 nids, naddrs;
6310 afs_int32 *vd, *addr;
6311 Error errorCode = 0; /* return code to caller */
6312 struct client *client = 0;
6314 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6316 AFSCallStats.TotalCalls++;
6318 nids = vids->ViceIds_len; /* # of users in here */
6319 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6320 if (nids < 0 || naddrs < 0) {
6325 vd = vids->ViceIds_val;
6326 for (i = 0; i < nids; i++, vd++) {
6329 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6333 client->prfail = 2; /* Means re-eval client's cps */
6336 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6339 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6340 free(client->CPS.prlist_val);
6341 client->CPS.prlist_val = NULL;
6342 client->CPS.prlist_len = 0;
6344 ReleaseWriteLock(&client->lock);
6348 addr = addrs->IPAddrs_val;
6349 for (i = 0; i < naddrs; i++, addr++) {
6351 h_flushhostcps(*addr, htons(7001));
6355 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6357 } /*SRXAFS_FlushCPS */
6359 /* worthless hack to let CS keep running ancient software */
6361 afs_vtoi(register char *aname)
6363 register afs_int32 temp;
6367 while ((tc = *aname++)) {
6368 if (tc > '9' || tc < '0')
6369 return 0; /* invalid name */
6377 * may get name or #, but must handle all weird cases (recognize readonly
6378 * or backup volumes by name or #
6381 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6382 register struct VolumeInfo *av)
6384 register int i, j, vol;
6385 afs_int32 mask, whichType;
6386 afs_uint32 *serverHost, *typePtr;
6388 /* figure out what type we want if by name */
6390 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6391 whichType = BACKVOL;
6392 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6397 vol = afs_vtoi(aname);
6399 vol = ave->volumeId[whichType];
6402 * Now vol has volume # we're interested in. Next, figure out the type
6403 * of the volume by looking finding it in the vldb entry
6405 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6408 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6411 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6412 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6413 whichType = BACKVOL;
6415 return EINVAL; /* error: can't find volume in vldb entry */
6417 typePtr = &av->Type0;
6418 serverHost = &av->Server0;
6420 av->Type = whichType;
6421 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6422 if (ave->flags & VLF_RWEXISTS)
6423 typePtr[RWVOL] = ave->volumeId[RWVOL];
6424 if (ave->flags & VLF_ROEXISTS)
6425 typePtr[ROVOL] = ave->volumeId[ROVOL];
6426 if (ave->flags & VLF_BACKEXISTS)
6427 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6429 for (i = 0, j = 0; i < ave->nServers; i++) {
6430 if ((ave->serverFlags[i] & mask) == 0)
6431 continue; /* wrong volume */
6432 serverHost[j] = ave->serverNumber[i];
6435 av->ServerCount = j;
6437 serverHost[j++] = 0; /* bogus 8, but compat only now */
6442 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6444 static struct rx_connection *vlConn = 0;
6445 static int down = 0;
6446 static afs_int32 lastDownTime = 0;
6447 struct vldbentry tve;
6448 struct rx_securityClass *vlSec;
6449 register afs_int32 code;
6452 vlSec = rxnull_NewClientSecurityObject();
6454 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6455 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6457 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6458 return 1; /* failure */
6461 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6463 down = 0; /* call worked */
6466 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6472 /* otherwise convert to old format vldb entry */
6473 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6483 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6484 struct VolumeInfo * avolinfo)
6487 struct rx_connection *tcon;
6489 #if FS_STATS_DETAILED
6490 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6491 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6492 struct timeval elapsedTime; /* Transfer time */
6495 * Set our stats pointer, remember when the RPC operation started, and
6496 * tally the operation.
6498 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6502 FT_GetTimeOfDay(&opStartTime, 0);
6503 #endif /* FS_STATS_DETAILED */
6504 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6505 goto Bad_GetVolumeInfo;
6508 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6510 code = TryLocalVLServer(avolid, avolinfo);
6512 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6513 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6514 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6515 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6518 code = CallPostamble(tcon, code, thost);
6520 #if FS_STATS_DETAILED
6521 FT_GetTimeOfDay(&opStopTime, 0);
6524 (opP->numSuccesses)++;
6525 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6526 fs_stats_AddTo((opP->sumTime), elapsedTime);
6527 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6528 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6529 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6531 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6532 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6536 #endif /* FS_STATS_DETAILED */
6540 } /*SRXAFS_GetVolumeInfo */
6544 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6545 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6546 char **OfflineMsg, char **Motd)
6548 Vnode *targetptr = 0; /* vnode of the new file */
6549 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6550 Error errorCode = 0; /* error code */
6551 Volume *volptr = 0; /* pointer to the volume header */
6552 struct client *client = 0; /* pointer to client entry */
6553 afs_int32 rights, anyrights; /* rights for this and any user */
6555 struct rx_connection *tcon;
6557 struct client *t_client = NULL; /* tmp ptr to client data */
6558 #if FS_STATS_DETAILED
6559 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6560 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6561 struct timeval elapsedTime; /* Transfer time */
6564 * Set our stats pointer, remember when the RPC operation started, and
6565 * tally the operation.
6568 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6572 FT_GetTimeOfDay(&opStartTime, 0);
6573 #endif /* FS_STATS_DETAILED */
6575 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6576 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6577 goto Bad_GetVolumeStatus;
6580 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6584 goto Bad_GetVolumeStatus;
6586 dummyFid.Volume = avolid, dummyFid.Vnode =
6587 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6590 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6591 &parentwhentargetnotdir, &client, READ_LOCK,
6592 &rights, &anyrights)))
6593 goto Bad_GetVolumeStatus;
6595 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6597 goto Bad_GetVolumeStatus;
6599 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6601 Bad_GetVolumeStatus:
6602 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6604 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6605 /* next is to guarantee out strings exist for stub */
6607 *Name = (char *)malloc(1);
6611 *Motd = (char *)malloc(1);
6614 if (*OfflineMsg == 0) {
6615 *OfflineMsg = (char *)malloc(1);
6618 errorCode = CallPostamble(tcon, errorCode, thost);
6620 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6622 #if FS_STATS_DETAILED
6623 FT_GetTimeOfDay(&opStopTime, 0);
6624 if (errorCode == 0) {
6626 (opP->numSuccesses)++;
6627 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6628 fs_stats_AddTo((opP->sumTime), elapsedTime);
6629 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6630 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6631 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6633 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6634 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6638 #endif /* FS_STATS_DETAILED */
6640 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6641 AUD_ID, t_client ? t_client->ViceId : 0,
6642 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6645 } /*SRXAFS_GetVolumeStatus */
6649 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6650 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6651 char *OfflineMsg, char *Motd)
6653 Vnode *targetptr = 0; /* vnode of the new file */
6654 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6655 Error errorCode = 0; /* error code */
6656 Volume *volptr = 0; /* pointer to the volume header */
6657 struct client *client = 0; /* pointer to client entry */
6658 afs_int32 rights, anyrights; /* rights for this and any user */
6660 struct rx_connection *tcon = rx_ConnectionOf(acall);
6662 struct client *t_client = NULL; /* tmp ptr to client data */
6663 #if FS_STATS_DETAILED
6664 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6665 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6666 struct timeval elapsedTime; /* Transfer time */
6669 * Set our stats pointer, remember when the RPC operation started, and
6670 * tally the operation.
6673 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6677 FT_GetTimeOfDay(&opStartTime, 0);
6678 #endif /* FS_STATS_DETAILED */
6680 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6681 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6682 goto Bad_SetVolumeStatus;
6685 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6689 goto Bad_SetVolumeStatus;
6691 dummyFid.Volume = avolid, dummyFid.Vnode =
6692 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6695 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6696 &parentwhentargetnotdir, &client, READ_LOCK,
6697 &rights, &anyrights)))
6698 goto Bad_SetVolumeStatus;
6700 if (readonlyServer) {
6701 errorCode = VREADONLY;
6702 goto Bad_SetVolumeStatus;
6704 if (VanillaUser(client)) {
6706 goto Bad_SetVolumeStatus;
6710 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6712 Bad_SetVolumeStatus:
6713 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6715 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6716 errorCode = CallPostamble(tcon, errorCode, thost);
6718 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6720 #if FS_STATS_DETAILED
6721 FT_GetTimeOfDay(&opStopTime, 0);
6722 if (errorCode == 0) {
6724 (opP->numSuccesses)++;
6725 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6726 fs_stats_AddTo((opP->sumTime), elapsedTime);
6727 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6728 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6729 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6731 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6732 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6736 #endif /* FS_STATS_DETAILED */
6738 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6739 AUD_ID, t_client ? t_client->ViceId : 0,
6740 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6742 } /*SRXAFS_SetVolumeStatus */
6744 #define DEFAULTVOLUME "root.afs"
6747 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6753 struct rx_connection *tcon;
6755 Error errorCode = 0;
6757 #if FS_STATS_DETAILED
6758 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6759 struct timeval opStartTime; /* Start time for RPC op */
6761 struct timeval opStopTime;
6762 struct timeval elapsedTime; /* Transfer time */
6766 * Set our stats pointer, remember when the RPC operation started, and
6767 * tally the operation.
6769 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6773 FT_GetTimeOfDay(&opStartTime, 0);
6774 #endif /* FS_STATS_DETAILED */
6776 return FSERR_EOPNOTSUPP;
6779 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6780 goto Bad_GetRootVolume;
6782 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6785 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6787 strcpy(temp, DEFAULTVOLUME);
6789 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6790 lockf(fd, F_LOCK, 0);
6794 len = read(fd, temp, 256);
6795 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6796 lockf(fd, F_ULOCK, 0);
6801 if (temp[len - 1] == '\n')
6805 *VolumeName = temp; /* freed by rx server-side stub */
6808 errorCode = CallPostamble(tcon, errorCode, thost);
6810 #if FS_STATS_DETAILED
6811 FT_GetTimeOfDay(&opStopTime, 0);
6812 if (errorCode == 0) {
6814 (opP->numSuccesses)++;
6815 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6816 fs_stats_AddTo((opP->sumTime), elapsedTime);
6817 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6818 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6819 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6821 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6822 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6826 #endif /* FS_STATS_DETAILED */
6831 } /*SRXAFS_GetRootVolume */
6834 /* still works because a struct CBS is the same as a struct AFSOpaque */
6836 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6837 struct AFSOpaque * Token)
6840 struct rx_connection *tcon;
6842 #if FS_STATS_DETAILED
6843 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6844 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6845 struct timeval elapsedTime; /* Transfer time */
6848 * Set our stats pointer, remember when the RPC operation started, and
6849 * tally the operation.
6851 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6855 FT_GetTimeOfDay(&opStartTime, 0);
6856 #endif /* FS_STATS_DETAILED */
6858 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6859 goto Bad_CheckToken;
6861 code = FSERR_ECONNREFUSED;
6864 code = CallPostamble(tcon, code, thost);
6866 #if FS_STATS_DETAILED
6867 FT_GetTimeOfDay(&opStopTime, 0);
6870 (opP->numSuccesses)++;
6871 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6872 fs_stats_AddTo((opP->sumTime), elapsedTime);
6873 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6874 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6875 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6877 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6878 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6882 #endif /* FS_STATS_DETAILED */
6886 } /*SRXAFS_CheckToken */
6889 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6890 afs_uint32 * USeconds)
6893 struct rx_connection *tcon;
6896 #if FS_STATS_DETAILED
6897 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6898 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6899 struct timeval elapsedTime; /* Transfer time */
6902 * Set our stats pointer, remember when the RPC operation started, and
6903 * tally the operation.
6905 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6909 FT_GetTimeOfDay(&opStartTime, 0);
6910 #endif /* FS_STATS_DETAILED */
6912 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6916 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6918 FT_GetTimeOfDay(&tpl, 0);
6919 *Seconds = tpl.tv_sec;
6920 *USeconds = tpl.tv_usec;
6922 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6925 code = CallPostamble(tcon, code, thost);
6927 #if FS_STATS_DETAILED
6928 FT_GetTimeOfDay(&opStopTime, 0);
6929 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6932 (opP->numSuccesses)++;
6933 fs_stats_AddTo((opP->sumTime), elapsedTime);
6934 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6935 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6936 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6938 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6939 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6943 #endif /* FS_STATS_DETAILED */
6947 } /*SRXAFS_GetTime */
6954 * Implement a client's data fetch using Rx.
6957 * volptr : Ptr to the given volume's info.
6958 * targetptr : Pointer to the vnode involved.
6959 * Call : Ptr to the Rx call involved.
6960 * Pos : Offset within the file.
6961 * Len : Length in bytes to read; this value is bogus!
6962 * if FS_STATS_DETAILED
6963 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6965 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6971 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6972 register struct rx_call * Call, afs_sfsize_t Pos,
6973 afs_sfsize_t Len, afs_int32 Int64Mode,
6974 #if FS_STATS_DETAILED
6975 afs_sfsize_t * a_bytesToFetchP,
6976 afs_sfsize_t * a_bytesFetchedP
6977 #endif /* FS_STATS_DETAILED */
6980 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6981 Error errorCode = 0; /* Returned error code to caller */
6985 register char *tbuffer;
6986 #else /* AFS_NT40_ENV */
6987 struct iovec tiov[RX_MAXIOVECS];
6989 #endif /* AFS_NT40_ENV */
6993 #if FS_STATS_DETAILED
6995 * Initialize the byte count arguments.
6997 (*a_bytesToFetchP) = 0;
6998 (*a_bytesFetchedP) = 0;
6999 #endif /* FS_STATS_DETAILED */
7003 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
7004 (afs_uintmax_t) Len));
7006 if (!VN_GET_INO(targetptr)) {
7007 afs_int32 zero = htonl(0);
7009 * This is used for newly created files; we simply send 0 bytes
7010 * back to make the cache manager happy...
7013 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7014 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7017 FT_GetTimeOfDay(&StartTime, 0);
7018 ihP = targetptr->handle;
7021 VTakeOffline(volptr);
7022 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7026 optSize = sendBufSize;
7027 tlen = FDH_SIZE(fdP);
7029 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7032 VTakeOffline(volptr);
7033 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7041 if (Pos + Len > tlen) /* get length we should send */
7042 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7044 (void)FDH_SEEK(fdP, Pos, 0);
7046 afs_int32 high, low;
7047 SplitOffsetOrSize(Len, high, low);
7048 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7051 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7054 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7056 #if FS_STATS_DETAILED
7057 (*a_bytesToFetchP) = Len;
7058 #endif /* FS_STATS_DETAILED */
7060 tbuffer = AllocSendBuffer();
7061 #endif /* AFS_NT40_ENV */
7069 errorCode = FDH_READ(fdP, tbuffer, wlen);
7070 if (errorCode != wlen) {
7072 FreeSendBuffer((struct afs_buffer *)tbuffer);
7073 VTakeOffline(volptr);
7074 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7078 errorCode = rx_Write(Call, tbuffer, wlen);
7079 #else /* AFS_NT40_ENV */
7080 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7081 if (errorCode <= 0) {
7086 errorCode = FDH_READV(fdP, tiov, tnio);
7087 if (errorCode != wlen) {
7089 VTakeOffline(volptr);
7090 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7094 errorCode = rx_Writev(Call, tiov, tnio, wlen);
7095 #endif /* AFS_NT40_ENV */
7096 #if FS_STATS_DETAILED
7098 * Bump the number of bytes actually sent by the number from this
7101 (*a_bytesFetchedP) += errorCode;
7102 #endif /* FS_STATS_DETAILED */
7103 if (errorCode != wlen) {
7106 FreeSendBuffer((struct afs_buffer *)tbuffer);
7107 #endif /* AFS_NT40_ENV */
7113 FreeSendBuffer((struct afs_buffer *)tbuffer);
7114 #endif /* AFS_NT40_ENV */
7116 FT_GetTimeOfDay(&StopTime, 0);
7118 /* Adjust all Fetch Data related stats */
7120 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7121 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7122 AFSCallStats.AccumFetchTime +=
7123 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7124 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7126 afs_fsize_t targLen;
7127 VN_GET_LEN(targLen, targetptr);
7128 AFSCallStats.TotalFetchedBytes += targLen;
7129 AFSCallStats.FetchSize1++;
7130 if (targLen < SIZE2)
7131 AFSCallStats.FetchSize2++;
7132 else if (targLen < SIZE3)
7133 AFSCallStats.FetchSize3++;
7134 else if (targLen < SIZE4)
7135 AFSCallStats.FetchSize4++;
7137 AFSCallStats.FetchSize5++;
7142 } /*FetchData_RXStyle */
7145 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7146 afs_sfsize_t * size)
7148 #ifdef AFS_NAMEI_ENV
7150 lhp = IH_OPEN(V_linkHandle(vp));
7154 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7156 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7161 *size = OS_SIZE(fdP->fd_fd);
7162 return (*size == -1) ? -1 : 0;
7164 struct afs_stat status;
7166 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7170 *lc = GetLinkCount(vp, &status);
7171 *size = status.st_size;
7180 * Implement a client's data store using Rx.
7183 * volptr : Ptr to the given volume's info.
7184 * targetptr : Pointer to the vnode involved.
7185 * Call : Ptr to the Rx call involved.
7186 * Pos : Offset within the file.
7187 * Len : Length in bytes to store; this value is bogus!
7188 * if FS_STATS_DETAILED
7189 * a_bytesToStoreP : Set to the number of bytes to be stored to
7191 * a_bytesStoredP : Set to the actual number of bytes stored to
7196 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7197 struct client * client, register struct rx_call * Call,
7198 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7200 #if FS_STATS_DETAILED
7201 afs_sfsize_t * a_bytesToStoreP,
7202 afs_sfsize_t * a_bytesStoredP
7203 #endif /* FS_STATS_DETAILED */
7206 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7207 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7208 Error errorCode = 0; /* Returned error code to caller */
7210 register char *tbuffer; /* data copying buffer */
7211 #else /* AFS_NT40_ENV */
7212 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7213 int tnio; /* temp for iovec size */
7214 #endif /* AFS_NT40_ENV */
7215 afs_sfsize_t tlen; /* temp for xfr length */
7216 Inode tinode; /* inode for I/O */
7217 afs_int32 optSize; /* optimal transfer size */
7218 afs_sfsize_t DataLength = 0; /* size of inode */
7219 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7220 afs_fsize_t NewLength; /* size after this store completes */
7221 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7222 int linkCount = 0; /* link count on inode */
7223 afs_fsize_t CoW_off, CoW_len;
7224 FdHandle_t *fdP, *origfdP = NULL;
7225 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7227 #if FS_STATS_DETAILED
7229 * Initialize the byte count arguments.
7231 (*a_bytesToStoreP) = 0;
7232 (*a_bytesStoredP) = 0;
7233 #endif /* FS_STATS_DETAILED */
7236 * We break the callbacks here so that the following signal will not
7239 BreakCallBack(client->host, Fid, 0);
7241 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7242 /* the inode should have been created in Alloc_NewVnode */
7243 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7245 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7246 Fid->Volume, Fid->Vnode, Fid->Unique,
7247 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7248 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7249 return ENOENT; /* is this proper error code? */
7252 * See if the file has several links (from other volumes). If it
7253 * does, then we have to make a copy before changing it to avoid
7254 *changing read-only clones of this dude
7257 ("StoreData_RXStyle : Opening inode %s\n",
7258 PrintInode(NULL, VN_GET_INO(targetptr))));
7259 fdP = IH_OPEN(targetptr->handle);
7262 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7264 VTakeOffline(volptr);
7265 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7270 if (linkCount != 1) {
7273 ("StoreData_RXStyle : inode %s has more than onelink\n",
7274 PrintInode(NULL, VN_GET_INO(targetptr))));
7275 /* other volumes share this data, better copy it first */
7277 /* Adjust the disk block count by the creation of the new inode.
7278 * We call the special VDiskUsage so we don't adjust the volume's
7279 * quota since we don't want to penalyze the user for afs's internal
7280 * mechanisms (i.e. copy on write overhead.) Also the right size
7281 * of the disk will be recorded...
7284 VN_GET_LEN(size, targetptr);
7285 volptr->partition->flags &= ~PART_DONTUPDATE;
7286 VSetPartitionDiskUsage(volptr->partition);
7287 volptr->partition->flags |= PART_DONTUPDATE;
7288 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7289 volptr->partition->flags &= ~PART_DONTUPDATE;
7294 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7295 CopyOnWrite_calls++;
7296 if (CoW_len == 0) CopyOnWrite_size0++;
7297 if (Pos == 0) CopyOnWrite_off0++;
7298 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7300 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7301 "off 0x0 size 0x%llx\n",
7302 afs_printable_VolumeId_u(V_id(volptr)),
7303 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7304 V_name(volptr), Pos));
7305 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7306 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7307 volptr->partition->flags &= ~PART_DONTUPDATE;
7311 volptr->partition->flags &= ~PART_DONTUPDATE;
7312 VSetPartitionDiskUsage(volptr->partition);
7313 fdP = IH_OPEN(targetptr->handle);
7316 ("StoreData : Reopen after CopyOnWrite failed\n"));
7321 tinode = VN_GET_INO(targetptr);
7323 if (!VALID_INO(tinode)) {
7324 VTakeOffline(volptr);
7325 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7330 /* compute new file length */
7331 NewLength = DataLength;
7332 if (FileLength < NewLength)
7333 /* simulate truncate */
7334 NewLength = FileLength;
7335 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7336 if (Pos + Length > NewLength)
7337 NewLength = Pos + Length; /* and write */
7339 /* adjust the disk block count by the difference in the files */
7341 afs_fsize_t targSize;
7342 VN_GET_LEN(targSize, targetptr);
7343 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7346 AdjustDiskUsage(volptr, adjustSize,
7347 adjustSize - SpareComp(volptr)))) {
7349 if (origfdP) FDH_CLOSE(origfdP);
7353 /* can signal cache manager to proceed from close now */
7354 /* this bit means that the locks are set and protections are OK */
7355 rx_SetLocalStatus(Call, 1);
7357 FT_GetTimeOfDay(&StartTime, 0);
7359 optSize = sendBufSize;
7361 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7362 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7363 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7365 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7366 if (FileLength < DataLength)
7367 FDH_TRUNC(fdP, FileLength);
7369 FDH_SEEK(fdP, Pos, 0);
7370 bytesTransfered = 0;
7372 tbuffer = AllocSendBuffer();
7373 #endif /* AFS_NT40_ENV */
7374 /* if length == 0, the loop below isn't going to do anything, including
7375 * extend the length of the inode, which it must do, since the file system
7376 * assumes that the inode length == vnode's file length. So, we extend
7377 * the file length manually if need be. Note that if file is bigger than
7378 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7379 * do what we're going to do below.
7381 if (Length == 0 && Pos > TruncatedLength) {
7382 /* Set the file's length; we've already done an lseek to the right
7385 errorCode = FDH_WRITE(fdP, &tlen, 1);
7388 errorCode = FDH_TRUNC(fdP, Pos);
7390 /* have some data to copy */
7391 #if FS_STATS_DETAILED
7392 (*a_bytesToStoreP) = Length;
7393 #endif /* FS_STATS_DETAILED */
7396 if (bytesTransfered >= Length) {
7400 tlen = Length - bytesTransfered; /* how much more to do */
7402 rlen = optSize; /* bound by buffer size */
7406 errorCode = rx_Read(Call, tbuffer, rlen);
7407 #else /* AFS_NT40_ENV */
7408 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7409 #endif /* AFS_NT40_ENV */
7410 if (errorCode <= 0) {
7414 #if FS_STATS_DETAILED
7415 (*a_bytesStoredP) += errorCode;
7416 #endif /* FS_STATS_DETAILED */
7419 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7420 #else /* AFS_NT40_ENV */
7421 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7422 #endif /* AFS_NT40_ENV */
7423 if (errorCode != rlen) {
7424 errorCode = VDISKFULL;
7427 bytesTransfered += rlen;
7432 FreeSendBuffer((struct afs_buffer *)tbuffer);
7433 #endif /* AFS_NT40_ENV */
7438 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7439 /* something went wrong: adjust size and return */
7440 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7441 /* changed_newTime is tested in StoreData to detemine if we
7442 * need to update the target vnode.
7444 targetptr->changed_newTime = 1;
7445 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7446 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7447 if (origfdP) FDH_CLOSE(origfdP);
7449 /* set disk usage to be correct */
7450 VAdjustDiskUsage(&errorCode, volptr,
7451 (afs_sfsize_t) (nBlocks(nfSize) -
7452 nBlocks(NewLength)), 0);
7455 if (origfdP) { /* finish CopyOnWrite */
7456 if ( (CoW_off = Pos + Length) < NewLength) {
7457 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7458 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7459 "off 0x%llx size 0x%llx returns %d\n",
7460 afs_printable_VolumeId_u(V_id(volptr)),
7461 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7462 V_name(volptr), CoW_off, CoW_len, errorCode));
7468 FT_GetTimeOfDay(&StopTime, 0);
7470 VN_SET_LEN(targetptr, NewLength);
7472 /* Update all StoreData related stats */
7474 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7475 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7476 AFSCallStats.StoreSize1++; /* Piggybacked data */
7478 afs_fsize_t targLen;
7479 VN_GET_LEN(targLen, targetptr);
7480 if (targLen < SIZE2)
7481 AFSCallStats.StoreSize2++;
7482 else if (targLen < SIZE3)
7483 AFSCallStats.StoreSize3++;
7484 else if (targLen < SIZE4)
7485 AFSCallStats.StoreSize4++;
7487 AFSCallStats.StoreSize5++;
7492 } /*StoreData_RXStyle */
7494 static int sys2et[512];
7497 init_sys_error_to_et(void)
7499 memset(&sys2et, 0, sizeof(sys2et));
7500 sys2et[EPERM] = UAEPERM;
7501 sys2et[ENOENT] = UAENOENT;
7502 sys2et[ESRCH] = UAESRCH;
7503 sys2et[EINTR] = UAEINTR;
7504 sys2et[EIO] = UAEIO;
7505 sys2et[ENXIO] = UAENXIO;
7506 sys2et[E2BIG] = UAE2BIG;
7507 sys2et[ENOEXEC] = UAENOEXEC;
7508 sys2et[EBADF] = UAEBADF;
7509 sys2et[ECHILD] = UAECHILD;
7510 sys2et[EAGAIN] = UAEAGAIN;
7511 sys2et[ENOMEM] = UAENOMEM;
7512 sys2et[EACCES] = UAEACCES;
7513 sys2et[EFAULT] = UAEFAULT;
7514 sys2et[ENOTBLK] = UAENOTBLK;
7515 sys2et[EBUSY] = UAEBUSY;
7516 sys2et[EEXIST] = UAEEXIST;
7517 sys2et[EXDEV] = UAEXDEV;
7518 sys2et[ENODEV] = UAENODEV;
7519 sys2et[ENOTDIR] = UAENOTDIR;
7520 sys2et[EISDIR] = UAEISDIR;
7521 sys2et[EINVAL] = UAEINVAL;
7522 sys2et[ENFILE] = UAENFILE;
7523 sys2et[EMFILE] = UAEMFILE;
7524 sys2et[ENOTTY] = UAENOTTY;
7525 sys2et[ETXTBSY] = UAETXTBSY;
7526 sys2et[EFBIG] = UAEFBIG;
7527 sys2et[ENOSPC] = UAENOSPC;
7528 sys2et[ESPIPE] = UAESPIPE;
7529 sys2et[EROFS] = UAEROFS;
7530 sys2et[EMLINK] = UAEMLINK;
7531 sys2et[EPIPE] = UAEPIPE;
7532 sys2et[EDOM] = UAEDOM;
7533 sys2et[ERANGE] = UAERANGE;
7534 sys2et[EDEADLK] = UAEDEADLK;
7535 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7536 sys2et[ENOLCK] = UAENOLCK;
7537 sys2et[ENOSYS] = UAENOSYS;
7538 #if (ENOTEMPTY != EEXIST)
7539 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7541 sys2et[ELOOP] = UAELOOP;
7542 #if (EWOULDBLOCK != EAGAIN)
7543 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7545 sys2et[ENOMSG] = UAENOMSG;
7546 sys2et[EIDRM] = UAEIDRM;
7547 sys2et[ECHRNG] = UAECHRNG;
7548 sys2et[EL2NSYNC] = UAEL2NSYNC;
7549 sys2et[EL3HLT] = UAEL3HLT;
7550 sys2et[EL3RST] = UAEL3RST;
7551 sys2et[ELNRNG] = UAELNRNG;
7552 sys2et[EUNATCH] = UAEUNATCH;
7553 sys2et[ENOCSI] = UAENOCSI;
7554 sys2et[EL2HLT] = UAEL2HLT;
7555 sys2et[EBADE] = UAEBADE;
7556 sys2et[EBADR] = UAEBADR;
7557 sys2et[EXFULL] = UAEXFULL;
7558 sys2et[ENOANO] = UAENOANO;
7559 sys2et[EBADRQC] = UAEBADRQC;
7560 sys2et[EBADSLT] = UAEBADSLT;
7561 sys2et[EDEADLK] = UAEDEADLK;
7562 sys2et[EBFONT] = UAEBFONT;
7563 sys2et[ENOSTR] = UAENOSTR;
7564 sys2et[ENODATA] = UAENODATA;
7565 sys2et[ETIME] = UAETIME;
7566 sys2et[ENOSR] = UAENOSR;
7567 sys2et[ENONET] = UAENONET;
7568 sys2et[ENOPKG] = UAENOPKG;
7569 sys2et[EREMOTE] = UAEREMOTE;
7570 sys2et[ENOLINK] = UAENOLINK;
7571 sys2et[EADV] = UAEADV;
7572 sys2et[ESRMNT] = UAESRMNT;
7573 sys2et[ECOMM] = UAECOMM;
7574 sys2et[EPROTO] = UAEPROTO;
7575 sys2et[EMULTIHOP] = UAEMULTIHOP;
7576 sys2et[EDOTDOT] = UAEDOTDOT;
7577 sys2et[EBADMSG] = UAEBADMSG;
7578 sys2et[EOVERFLOW] = UAEOVERFLOW;
7579 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7580 sys2et[EBADFD] = UAEBADFD;
7581 sys2et[EREMCHG] = UAEREMCHG;
7582 sys2et[ELIBACC] = UAELIBACC;
7583 sys2et[ELIBBAD] = UAELIBBAD;
7584 sys2et[ELIBSCN] = UAELIBSCN;
7585 sys2et[ELIBMAX] = UAELIBMAX;
7586 sys2et[ELIBEXEC] = UAELIBEXEC;
7587 sys2et[EILSEQ] = UAEILSEQ;
7588 sys2et[ERESTART] = UAERESTART;
7589 sys2et[ESTRPIPE] = UAESTRPIPE;
7590 sys2et[EUSERS] = UAEUSERS;
7591 sys2et[ENOTSOCK] = UAENOTSOCK;
7592 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7593 sys2et[EMSGSIZE] = UAEMSGSIZE;
7594 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7595 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7596 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7597 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7598 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7599 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7600 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7601 sys2et[EADDRINUSE] = UAEADDRINUSE;
7602 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7603 sys2et[ENETDOWN] = UAENETDOWN;
7604 sys2et[ENETUNREACH] = UAENETUNREACH;
7605 sys2et[ENETRESET] = UAENETRESET;
7606 sys2et[ECONNABORTED] = UAECONNABORTED;
7607 sys2et[ECONNRESET] = UAECONNRESET;
7608 sys2et[ENOBUFS] = UAENOBUFS;
7609 sys2et[EISCONN] = UAEISCONN;
7610 sys2et[ENOTCONN] = UAENOTCONN;
7611 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7612 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7613 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7614 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7615 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7616 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7617 sys2et[EALREADY] = UAEALREADY;
7618 sys2et[EINPROGRESS] = UAEINPROGRESS;
7619 sys2et[ESTALE] = UAESTALE;
7620 sys2et[EUCLEAN] = UAEUCLEAN;
7621 sys2et[ENOTNAM] = UAENOTNAM;
7622 sys2et[ENAVAIL] = UAENAVAIL;
7623 sys2et[EISNAM] = UAEISNAM;
7624 sys2et[EREMOTEIO] = UAEREMOTEIO;
7625 sys2et[EDQUOT] = UAEDQUOT;
7626 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7627 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7629 sys2et[EIO] = UAEIO;
7633 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7634 * - pass back the connection, client, and host from CallPreamble
7635 * - keep a ref on the client, which we don't now
7636 * - keep a hold on the host, which we already do
7637 * - pass the connection, client, and host down into SAFSS_*, and use
7638 * them instead of independently discovering them via rx_ConnectionOf
7639 * (safe) and rx_GetSpecific (not so safe)
7640 * The idea being that we decide what client and host we're going to use
7641 * when CallPreamble is called, and stay consistent throughout the call.
7642 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7646 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7648 Error errorCode = 0;
7649 struct rx_connection *tcon;
7650 struct host *tcallhost;
7651 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7653 struct client *tclient;
7654 static struct rx_securityClass *sc = 0;
7656 struct rx_connection *conn;
7659 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7660 goto Bad_CallBackRxConnAddr1;
7662 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7666 tclient = h_FindClient_r(tcon);
7669 goto Bad_CallBackRxConnAddr;
7671 thost = tclient->host;
7673 /* nothing more can be done */
7674 if ( !thost->interface )
7675 goto Bad_CallBackRxConnAddr;
7677 /* the only address is the primary interface */
7678 /* can't change when there's only 1 address, anyway */
7679 if ( thost->interface->numberOfInterfaces <= 1 )
7680 goto Bad_CallBackRxConnAddr;
7682 /* initialise a security object only once */
7684 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7686 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7688 if ( *addr == thost->interface->addr[i] ) {
7693 if ( *addr != thost->interface->addr[i] )
7694 goto Bad_CallBackRxConnAddr;
7696 conn = rx_NewConnection (thost->interface->addr[i],
7697 thost->port, 1, sc, 0);
7698 rx_SetConnDeadTime(conn, 2);
7699 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7701 errorCode = RXAFSCB_Probe(conn);
7704 if ( thost->callback_rxcon )
7705 rx_DestroyConnection(thost->callback_rxcon);
7706 thost->callback_rxcon = conn;
7708 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7709 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7710 h_ReleaseClient_r(tclient);
7711 /* The hold on thost will be released by CallPostamble */
7713 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7716 rx_DestroyConnection(conn);
7718 Bad_CallBackRxConnAddr:
7719 h_ReleaseClient_r(tclient);
7720 /* The hold on thost will be released by CallPostamble */
7724 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7725 Bad_CallBackRxConnAddr1:
7726 return errorCode; /* failure */
7730 sys_error_to_et(afs_int32 in)
7734 if (in < 0 || in > 511)
7736 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7738 if (sys2et[in] != 0)