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>
37 #undef SHARED /* XXX */
42 #include <sys/param.h>
44 #include <sys/ioctl.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
51 #ifndef AFS_LINUX20_ENV
53 #ifndef AFS_ARM_DARWIN_ENV
54 #include <netinet/if_ether.h>
59 /* included early because of name conflict on IOPEN */
60 #include <sys/inode.h>
64 #endif /* AFS_HPUX_ENV */
68 #include <afs/afs_assert.h>
71 #include <afs/afsint.h>
72 #include <afs/vldbint.h>
73 #include <afs/errors.h>
74 #include <afs/ihandle.h>
75 #include <afs/vnode.h>
76 #include <afs/volume.h>
77 #include <afs/ptclient.h>
78 #include <afs/ptuser.h>
79 #include <afs/prs_fs.h>
82 #include <rx/rx_globals.h>
84 #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)
87 #if !defined(AFS_NT40_ENV)
90 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
92 #include <sys/statfs.h>
93 #include <sys/lockf.h>
95 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
100 #include <afs/cellconfig.h>
101 #include <afs/keys.h>
104 #include <afs/partition.h>
105 #include "viced_prototypes.h"
108 #include "callback.h"
109 #include <afs/unified_afs.h>
110 #include <afs/audit.h>
111 #include <afs/afsutil.h>
114 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
115 extern void FidZap(DirHandle * file);
116 extern void FidZero(DirHandle * file);
118 #ifdef AFS_PTHREAD_ENV
119 pthread_mutex_t fileproc_glock_mutex;
120 #endif /* AFS_PTHREAD_ENV */
123 #define afs_stat stat64
124 #define afs_fstat fstat64
125 #define afs_open open64
126 #else /* !O_LARGEFILE */
127 #define afs_stat stat
128 #define afs_fstat fstat
129 #define afs_open open
130 #endif /* !O_LARGEFILE */
133 /* Useful local defines used by this module */
136 #define MustNOTBeDIR 1
140 #define TVS_SSTATUS 2
143 #define TVS_MKDIR 0x10
145 #define CHK_FETCH 0x10
146 #define CHK_FETCHDATA 0x10
147 #define CHK_FETCHACL 0x11
148 #define CHK_FETCHSTATUS 0x12
149 #define CHK_STOREDATA 0x00
150 #define CHK_STOREACL 0x01
151 #define CHK_STORESTATUS 0x02
153 #define OWNERREAD 0400
154 #define OWNERWRITE 0200
155 #define OWNEREXEC 0100
156 #ifdef USE_GROUP_PERMS
157 #define GROUPREAD 0040
158 #define GROUPWRITE 0020
159 #define GROUPREXEC 0010
162 /* The following errors were not defined in NT. They are given unique
163 * names here to avoid any potential collision.
165 #define FSERR_ELOOP 90
166 #define FSERR_EOPNOTSUPP 122
167 #define FSERR_ECONNREFUSED 130
169 #define NOTACTIVECALL 0
172 #define CREATE_SGUID_ADMIN_ONLY 1
174 extern struct afsconf_dir *confDir;
175 extern afs_int32 dataVersionHigh;
178 static struct AFSCallStatistics AFSCallStats;
179 #if FS_STATS_DETAILED
180 struct fs_stats_FullPerfStats afs_FullPerfStats;
181 extern int AnonymousID;
182 #endif /* FS_STATS_DETAILED */
183 #if OPENAFS_VOL_STATS
184 static const char nullString[] = "";
185 #endif /* OPENAFS_VOL_STATS */
188 afs_int32 NothingYet;
191 struct afs_FSStats afs_fsstats;
196 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
198 extern afs_int32 implicitAdminRights;
199 extern afs_int32 readonlyServer;
200 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
201 extern afs_fsize_t CopyOnWrite_maxsize;
204 * Externals used by the xstat code.
206 extern VolPkgStats VStats;
207 extern int CEs, CEBlocks;
209 extern int HTs, HTBlocks;
211 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
212 struct rx_call *Call, afs_sfsize_t Pos,
213 afs_sfsize_t Len, afs_int32 Int64Mode,
214 #if FS_STATS_DETAILED
215 afs_sfsize_t * a_bytesToFetchP,
216 afs_sfsize_t * a_bytesFetchedP
217 #endif /* FS_STATS_DETAILED */
220 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
221 struct AFSFid *Fid, struct client *client,
222 struct rx_call *Call, afs_fsize_t Pos,
223 afs_fsize_t Length, afs_fsize_t FileLength,
225 #if FS_STATS_DETAILED
226 afs_sfsize_t * a_bytesToStoreP,
227 afs_sfsize_t * a_bytesStoredP
228 #endif /* FS_STATS_DETAILED */
231 #ifdef AFS_SGI_XFS_IOPS_ENV
232 #include <afs/xfsattrs.h>
234 GetLinkCount(Volume * avp, struct stat *astat)
236 if (!strcmp("xfs", astat->st_fstype)) {
237 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
239 return astat->st_nlink;
242 #define GetLinkCount(V, S) (S)->st_nlink
246 SpareComp(Volume * avolp)
252 temp = V_maxquota(avolp);
254 /* no matter; doesn't check in this case */
258 temp = (temp * PctSpare) / 100;
269 * Set the volume synchronization parameter for this volume. If it changes,
270 * the Cache Manager knows that the volume must be purged from the stat cache.
273 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
276 /* date volume instance was created */
279 async->spare1 = avol->header->diskstuff.creationDate;
292 * Note that this function always returns a held host, so
293 * that CallPostamble can block without the host's disappearing.
294 * Call returns rx connection in passed in *tconn
297 CallPreamble(struct rx_call *acall, int activecall,
298 struct rx_connection **tconn, struct host **ahostp)
301 struct client *tclient;
304 char hoststr[16], hoststr2[16];
305 #ifdef AFS_PTHREAD_ENV
306 struct ubik_client *uclient;
311 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
314 *tconn = rx_ConnectionOf(acall);
318 tclient = h_FindClient_r(*tconn);
320 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
324 thost = tclient->host;
325 if (tclient->prfail == 1) { /* couldn't get the CPS */
327 h_ReleaseClient_r(tclient);
329 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
333 retry_flag = 0; /* Retry once */
335 /* Take down the old connection and re-read the key file */
337 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
338 #ifdef AFS_PTHREAD_ENV
339 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
341 /* Is it still necessary to drop this? We hit the net, we should... */
347 code = hpr_Initialize(&uclient);
350 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
353 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
356 h_ReleaseClient_r(tclient);
359 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
363 tclient->prfail = 2; /* Means re-eval client's cps */
364 h_ReleaseClient_r(tclient);
369 tclient->LastCall = thost->LastCall = FT_ApproxTime();
370 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
371 thost->ActiveCall = thost->LastCall;
374 if (thost->hostFlags & HOSTDELETED) {
376 ("Discarded a packet for deleted host %s:%d\n",
377 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
378 code = VBUSY; /* raced, so retry */
379 } else if ((thost->hostFlags & VENUSDOWN)
380 || (thost->hostFlags & HFE_LATER)) {
381 if (BreakDelayedCallBacks_r(thost)) {
383 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
384 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
385 ntohs(rxr_PortOf(*tconn))));
386 if (MultiProbeAlternateAddress_r(thost)) {
388 ("MultiProbe failed to find new address for host %s:%d\n",
389 afs_inet_ntoa_r(thost->host, hoststr),
390 ntohs(thost->port)));
394 ("MultiProbe found new address for host %s:%d\n",
395 afs_inet_ntoa_r(thost->host, hoststr),
396 ntohs(thost->port)));
397 if (BreakDelayedCallBacks_r(thost)) {
399 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
400 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
401 ntohs(rxr_PortOf(*tconn))));
410 h_ReleaseClient_r(tclient);
420 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
424 struct client *tclient;
428 tclient = h_FindClient_r(aconn);
431 thost = tclient->host;
432 if (thost->hostFlags & HERRORTRANS)
434 h_ReleaseClient_r(tclient);
437 if (ahost != thost) {
438 /* host/client recycle */
439 char hoststr[16], hoststr2[16];
440 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
442 afs_inet_ntoa_r(ahost->host, hoststr),
445 afs_inet_ntoa_r(thost->host, hoststr2),
449 /* return the reference taken in CallPreamble */
453 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
454 afs_inet_ntoa_r(thost->host, hoststr),
459 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
460 * does not decrement refcount on client->host */
465 return (translate ? sys_error_to_et(ret) : ret);
469 * Returns the volume and vnode pointers associated with file Fid; the lock
470 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
471 * are incremented and they must be eventualy released.
474 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
475 Vnode ** vptr, int lock)
478 Error local_errorCode, errorCode = -1;
479 static struct timeval restartedat = { 0, 0 };
481 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
483 if ((*volptr) == 0) {
488 #ifdef AFS_DEMAND_ATTACH_FS
494 #ifdef AFS_PTHREAD_ENV
495 static const struct timespec timeout_ts = { 0, 0 };
496 static const struct timespec * const ts = &timeout_ts;
498 static const struct timespec * const ts = NULL;
502 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
503 fid->Volume, ts, cbv);
508 if ((errorCode == VOFFLINE) && (VInit < 2)) {
509 /* The volume we want may not be attached yet because
510 * the volume initialization is not yet complete.
511 * We can do several things:
512 * 1. return -1, which will cause users to see
513 * "connection timed out". This is more or
514 * less the same as always, except that the servers
515 * may appear to bounce up and down while they
516 * are actually restarting.
517 * 2. return VBUSY which will cause clients to
518 * sleep and retry for 6.5 - 15 minutes, depending
519 * on what version of the CM they are running. If
520 * the file server takes longer than that interval
521 * to attach the desired volume, then the application
522 * will see an ENODEV or EIO. This approach has
523 * the advantage that volumes which have been attached
524 * are immediately available, it keeps the server's
525 * immediate backlog low, and the call is interruptible
526 * by the user. Users see "waiting for busy volume."
527 * 3. sleep here and retry. Some people like this approach
528 * because there is no danger of seeing errors. However,
529 * this approach only works with a bounded number of
530 * clients, since the pending queues will grow without
531 * stopping. It might be better to find a way to take
532 * this call and stick it back on a queue in order to
533 * recycle this thread for a different request.
534 * 4. Return a new error code, which new cache managers will
535 * know enough to interpret as "sleep and retry", without
536 * the upper bound of 6-15 minutes that is imposed by the
537 * VBUSY handling. Users will see "waiting for
538 * busy volume," so they know that something is
539 * happening. Old cache managers must be able to do
540 * something reasonable with this, for instance, mark the
541 * server down. Fortunately, any error code < 0
542 * will elicit that behavior. See #1.
543 * 5. Some combination of the above. I like doing #2 for 10
544 * minutes, followed by #4. 3.1b and 3.2 cache managers
545 * will be fine as long as the restart period is
546 * not longer than 6.5 minutes, otherwise they may
547 * return ENODEV to users. 3.3 cache managers will be
548 * fine for 10 minutes, then will return
549 * ETIMEDOUT. 3.4 cache managers will just wait
550 * until the call works or fails definitively.
551 * NB. The problem with 2,3,4,5 is that old clients won't
552 * fail over to an alternate read-only replica while this
553 * server is restarting. 3.4 clients will fail over right away.
555 if (restartedat.tv_sec == 0) {
556 /* I'm not really worried about when we restarted, I'm */
557 /* just worried about when the first VBUSY was returned. */
558 FT_GetTimeOfDay(&restartedat, 0);
561 afs_perfstats.fs_nBusies++;
564 return (busyonrst ? VBUSY : restarting);
567 FT_GetTimeOfDay(&now, 0);
568 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
571 afs_perfstats.fs_nBusies++;
574 return (busyonrst ? VBUSY : restarting);
580 /* allow read operations on busy volume.
581 * must check local_errorCode because demand attach fs
582 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
583 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
584 #ifdef AFS_DEMAND_ATTACH_FS
585 /* DAFS case is complicated by the fact that local_errorCode can
586 * be VBUSY in cases where the volume is truly offline */
588 /* volume is in VOL_STATE_UNATTACHED */
591 #endif /* AFS_DEMAND_ATTACH_FS */
594 } else if (errorCode)
601 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
604 if ((*vptr)->disk.uniquifier != fid->Unique) {
605 VPutVnode(&fileCode, *vptr);
606 osi_Assert(fileCode == 0);
608 return (VNOVNODE); /* return the right error code, at least */
613 static_inline afs_int32
614 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
616 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
620 * This routine returns the ACL associated with the targetptr. If the
621 * targetptr isn't a directory, we access its parent dir and get the ACL
622 * thru the parent; in such case the parent's vnode is returned in
626 SetAccessList(Vnode ** targetptr, Volume ** volume,
627 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
628 AFSFid * Fid, int Lock)
630 if ((*targetptr)->disk.type == vDirectory) {
632 *ACL = VVnodeACL(*targetptr);
633 *ACLSize = VAclSize(*targetptr);
636 osi_Assert(Fid != 0);
641 parentvnode = (*targetptr)->disk.parent;
642 VPutVnode(&errorCode, *targetptr);
646 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
649 *ACL = VVnodeACL(*parent);
650 *ACLSize = VAclSize(*parent);
651 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
653 if ((*targetptr)->disk.parent != parentvnode) {
654 VPutVnode(&errorCode, *parent);
665 /* Must not be called with H_LOCK held */
667 client_CheckRights(struct client *client, struct acl_accessList *ACL,
671 ObtainReadLock(&client->lock);
672 if (client->CPS.prlist_len > 0 && !client->deleted &&
673 client->host && !(client->host->hostFlags & HOSTDELETED))
674 acl_CheckRights(ACL, &client->CPS, rights);
675 ReleaseReadLock(&client->lock);
678 /* Must not be called with H_LOCK held */
680 client_HasAsMember(struct client *client, afs_int32 id)
684 ObtainReadLock(&client->lock);
685 if (client->CPS.prlist_len > 0 && !client->deleted &&
686 client->host && !(client->host->hostFlags & HOSTDELETED))
687 code = acl_IsAMember(id, &client->CPS);
688 ReleaseReadLock(&client->lock);
693 * Compare the directory's ACL with the user's access rights in the client
694 * connection and return the user's and everybody else's access permissions
695 * in rights and anyrights, respectively
698 GetRights(struct client *client, struct acl_accessList *ACL,
699 afs_int32 * rights, afs_int32 * anyrights)
701 extern prlist SystemAnyUserCPS;
702 afs_int32 hrights = 0;
703 #ifndef AFS_PTHREAD_ENV
707 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
708 ViceLog(0, ("CheckRights failed\n"));
713 client_CheckRights(client, ACL, rights);
715 /* wait if somebody else is already doing the getCPS call */
717 while (client->host->hostFlags & HCPS_INPROGRESS) {
718 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
719 #ifdef AFS_PTHREAD_ENV
720 CV_WAIT(&client->host->cond, &host_glock_mutex);
721 #else /* AFS_PTHREAD_ENV */
723 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
724 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
725 #endif /* AFS_PTHREAD_ENV */
728 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
731 ("CheckRights: len=%u, for host=%s:%d\n",
732 client->host->hcps.prlist_len,
733 afs_inet_ntoa_r(client->host->host, hoststr),
734 ntohs(client->host->port)));
736 acl_CheckRights(ACL, &client->host->hcps, &hrights);
738 /* Allow system:admin the rights given with the -implicit option */
739 if (client_HasAsMember(client, SystemId))
740 *rights |= implicitAdminRights;
743 *anyrights |= hrights;
750 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
751 * a System:Administrator)
754 VanillaUser(struct client *client)
756 if (client_HasAsMember(client, SystemId))
757 return (0); /* not a system administrator, then you're "vanilla" */
764 * This unusual afs_int32-parameter routine encapsulates all volume package related
765 * operations together in a single function; it's called by almost all AFS
769 GetVolumePackageWithCall(struct rx_connection *tcon, struct VCallByVol *cbv,
770 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
771 int chkforDir, Vnode ** parent, struct client **client,
772 int locktype, afs_int32 * rights, afs_int32 * anyrights)
774 struct acl_accessList *aCL; /* Internal access List */
775 int aCLSize; /* size of the access list */
776 Error errorCode = 0; /* return code to caller */
778 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
781 if (chkforDir == MustNOTBeDIR
782 && ((*targetptr)->disk.type == vDirectory))
784 else if (chkforDir == MustBeDIR
785 && ((*targetptr)->disk.type != vDirectory))
789 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
790 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
791 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
793 if (chkforDir == MustBeDIR)
794 osi_Assert((*parent) == 0);
796 if ((errorCode = GetClient(tcon, client)) != 0)
801 GetRights(*client, aCL, rights, anyrights);
802 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
803 if ((*targetptr)->disk.type != vDirectory) {
804 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
805 if ((*targetptr)->disk.owner == (*client)->ViceId)
806 (*rights) |= PRSFS_ADMINISTER;
808 (*rights) &= ~PRSFS_ADMINISTER;
810 #ifdef ADMIN_IMPLICIT_LOOKUP
811 /* admins get automatic lookup on everything */
812 if (!VanillaUser(*client))
813 (*rights) |= PRSFS_LOOKUP;
814 #endif /* ADMIN_IMPLICIT_LOOKUP */
817 } /*GetVolumePackage */
819 static_inline afs_int32
820 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
821 Vnode ** targetptr, int chkforDir, Vnode ** parent,
822 struct client **client, int locktype, afs_int32 * rights,
823 afs_int32 * anyrights)
825 return GetVolumePackageWithCall(tcon, NULL, Fid, volptr, targetptr,
826 chkforDir, parent, client, locktype,
832 * This is the opposite of GetVolumePackage(), and is always used at the end of
833 * AFS calls to put back all used vnodes and the volume in the proper order!
836 PutVolumePackageWithCall(Vnode * parentwhentargetnotdir, Vnode * targetptr,
837 Vnode * parentptr, Volume * volptr,
838 struct client **client, struct VCallByVol *cbv)
840 Error fileCode = 0; /* Error code returned by the volume package */
842 if (parentwhentargetnotdir) {
843 VPutVnode(&fileCode, parentwhentargetnotdir);
844 osi_Assert(!fileCode || (fileCode == VSALVAGE));
847 VPutVnode(&fileCode, targetptr);
848 osi_Assert(!fileCode || (fileCode == VSALVAGE));
851 VPutVnode(&fileCode, parentptr);
852 osi_Assert(!fileCode || (fileCode == VSALVAGE));
855 VPutVolumeWithCall(volptr, cbv);
860 } /*PutVolumePackage */
863 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
864 Vnode * parentptr, Volume * volptr, struct client **client)
866 PutVolumePackageWithCall(parentwhentargetnotdir, targetptr, parentptr,
867 volptr, client, NULL);
871 VolumeOwner(struct client *client, Vnode * targetptr)
873 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
876 return (client->ViceId == owner);
879 * We don't have to check for host's cps since only regular
880 * viceid are volume owners.
882 return (client_HasAsMember(client, owner));
888 VolumeRootVnode(Vnode * targetptr)
890 return ((targetptr->vnodeNumber == ROOTVNODE)
891 && (targetptr->disk.uniquifier == 1));
893 } /*VolumeRootVnode */
896 * Check if target file has the proper access permissions for the Fetch
897 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
898 * StoreStatus) related calls
900 /* this code should probably just set a "priv" flag where all the audit events
901 * are now, and only generate the audit event once at the end of the routine,
902 * thus only generating the event if all the checks succeed, but only because
903 * of the privilege XXX
906 Check_PermissionRights(Vnode * targetptr, struct client *client,
907 afs_int32 rights, int CallingRoutine,
908 AFSStoreStatus * InStatus)
911 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
912 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
913 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
915 if (CallingRoutine & CHK_FETCH) {
916 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
917 if (targetptr->disk.type == vDirectory
918 || targetptr->disk.type == vSymlink) {
919 if (!(rights & PRSFS_LOOKUP)
920 #ifdef ADMIN_IMPLICIT_LOOKUP
921 /* grant admins fetch on all directories */
922 && VanillaUser(client)
923 #endif /* ADMIN_IMPLICIT_LOOKUP */
924 && !VolumeOwner(client, targetptr))
927 /* must have read access, or be owner and have insert access */
928 if (!(rights & PRSFS_READ)
929 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
930 && (client->ViceId != AnonymousID))))
933 if (CallingRoutine == CHK_FETCHDATA
934 && targetptr->disk.type == vFile)
935 #ifdef USE_GROUP_PERMS
936 if (!OWNSp(client, targetptr)
937 && !client_HasAsMember(client, targetptr->disk.owner)) {
939 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
943 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
948 * The check with the ownership below is a kludge to allow
949 * reading of files created with no read permission. The owner
950 * of the file is always allowed to read it.
952 if ((client->ViceId != targetptr->disk.owner)
953 && VanillaUser(client))
955 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
956 modeBits) ? 0 : EACCES);
958 } else { /* !VanillaUser(client) && !FetchData */
960 osi_audit(PrivilegeEvent, 0, AUD_ID,
961 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
964 } else { /* a store operation */
965 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
966 && (CallingRoutine != CHK_STOREACL)
967 && (targetptr->disk.type == vFile)) {
968 /* bypass protection checks on first store after a create
969 * for the creator; also prevent chowns during this time
970 * unless you are a system administrator */
971 /****** InStatus->Owner && UnixModeBits better be SET!! */
972 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
975 else if (VanillaUser(client))
976 return (EPERM); /* Was EACCES */
978 osi_audit(PrivilegeEvent, 0, AUD_ID,
979 (client ? client->ViceId : 0), AUD_INT,
980 CallingRoutine, AUD_END);
983 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
984 osi_audit(PrivilegeEvent, 0, AUD_ID,
985 (client ? client->ViceId : 0), AUD_INT,
986 CallingRoutine, AUD_END);
988 if (readonlyServer) {
991 if (CallingRoutine == CHK_STOREACL) {
992 if (!(rights & PRSFS_ADMINISTER)
993 && !VolumeOwner(client, targetptr))
995 } else { /* store data or status */
996 /* watch for chowns and chgrps */
997 if (CHOWN(InStatus, targetptr)
998 || CHGRP(InStatus, targetptr)) {
1001 else if (VanillaUser(client))
1002 return (EPERM); /* Was EACCES */
1004 osi_audit(PrivilegeEvent, 0, AUD_ID,
1005 (client ? client->ViceId : 0), AUD_INT,
1006 CallingRoutine, AUD_END);
1008 /* must be sysadmin to set suid/sgid bits */
1009 if ((InStatus->Mask & AFS_SETMODE) &&
1011 (InStatus->UnixModeBits & 0xc00) != 0) {
1013 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1017 if (VanillaUser(client))
1020 osi_audit(PrivSetID, 0, AUD_ID,
1021 (client ? client->ViceId : 0), AUD_INT,
1022 CallingRoutine, AUD_END);
1024 if (CallingRoutine == CHK_STOREDATA) {
1027 if (!(rights & PRSFS_WRITE))
1029 /* Next thing is tricky. We want to prevent people
1030 * from writing files sans 0200 bit, but we want
1031 * creating new files with 0444 mode to work. We
1032 * don't check the 0200 bit in the "you are the owner"
1033 * path above, but here we check the bit. However, if
1034 * you're a system administrator, we ignore the 0200
1035 * bit anyway, since you may have fchowned the file,
1037 #ifdef USE_GROUP_PERMS
1038 if ((targetptr->disk.type == vFile)
1039 && VanillaUser(client)) {
1040 if (!OWNSp(client, targetptr)
1041 && !client_HasAsMember(client, targetptr->disk.owner)) {
1043 ((GROUPWRITE & targetptr->disk.modeBits)
1047 ((OWNERWRITE & targetptr->disk.modeBits)
1052 if ((targetptr->disk.type != vDirectory)
1053 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1056 if (VanillaUser(client))
1059 osi_audit(PrivilegeEvent, 0, AUD_ID,
1060 (client ? client->ViceId : 0),
1061 AUD_INT, CallingRoutine, AUD_END);
1063 } else { /* a status store */
1066 if (targetptr->disk.type == vDirectory) {
1067 if (!(rights & PRSFS_DELETE)
1068 && !(rights & PRSFS_INSERT))
1070 } else { /* a file or symlink */
1071 if (!(rights & PRSFS_WRITE))
1081 } /*Check_PermissionRights */
1085 * The Access List information is converted from its internal form in the
1086 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1087 * external form and returned back to the caller, via the AccessList
1091 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1092 struct AFSOpaque *AccessList)
1094 char *eACL; /* External access list placeholder */
1096 if (acl_Externalize_pr
1097 (hpr_IdToName, (targetptr->disk.type ==
1098 vDirectory ? VVnodeACL(targetptr) :
1099 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1102 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1103 acl_FreeExternalACL(&eACL);
1106 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1107 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1109 acl_FreeExternalACL(&eACL);
1112 } /*RXFetch_AccessList */
1116 * The Access List information is converted from its external form in the
1117 * input AccessList structure to the internal representation and copied into
1118 * the target dir's vnode storage.
1121 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1123 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1125 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1128 if ((newACL->size + 4) > VAclSize(targetptr))
1130 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1131 acl_FreeACL(&newACL);
1134 } /*RXStore_AccessList */
1137 /* In our current implementation, each successive data store (new file
1138 * data version) creates a new inode. This function creates the new
1139 * inode, copies the old inode's contents to the new one, remove the old
1140 * inode (i.e. decrement inode count -- if it's currently used the delete
1141 * will be delayed), and modify some fields (i.e. vnode's
1142 * disk.inodeNumber and cloned)
1144 #define COPYBUFFSIZE 8192
1145 #define MAXFSIZE (~(afs_fsize_t) 0)
1147 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1149 Inode ino, nearInode;
1156 int rc; /* return code */
1157 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1158 FdHandle_t *targFdP; /* Source Inode file handle */
1159 FdHandle_t *newFdP; /* Dest Inode file handle */
1161 if (targetptr->disk.type == vDirectory)
1162 DFlush(); /* just in case? */
1164 VN_GET_LEN(size, targetptr);
1172 buff = (char *)malloc(COPYBUFFSIZE);
1177 ino = VN_GET_INO(targetptr);
1178 if (!VALID_INO(ino)) {
1180 VTakeOffline(volptr);
1181 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1185 targFdP = IH_OPEN(targetptr->handle);
1186 if (targFdP == NULL) {
1189 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1190 targetptr->vnodeNumber, V_id(volptr), rc));
1192 VTakeOffline(volptr);
1196 nearInode = VN_GET_INO(targetptr);
1198 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1199 VPartitionPath(V_partition(volptr)), nearInode,
1200 V_id(volptr), targetptr->vnodeNumber,
1201 targetptr->disk.uniquifier,
1202 (int)targetptr->disk.dataVersion);
1203 if (!VALID_INO(ino)) {
1205 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1206 volptr->partition->name, V_id(volptr), errno));
1211 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1212 newFdP = IH_OPEN(newH);
1213 osi_Assert(newFdP != NULL);
1217 if (size > COPYBUFFSIZE) { /* more than a buffer */
1218 length = COPYBUFFSIZE;
1219 size -= COPYBUFFSIZE;
1224 rdlen = FDH_PREAD(targFdP, buff, length, done);
1225 if (rdlen == length) {
1226 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1230 /* Callers of this function are not prepared to recover
1231 * from error that put the filesystem in an inconsistent
1232 * state. Make sure that we force the volume off-line if
1233 * we some error other than ENOSPC - 4.29.99)
1235 * In case we are unable to write the required bytes, and the
1236 * error code indicates that the disk is full, we roll-back to
1237 * the initial state.
1239 if ((rdlen != length) || (wrlen != length)) {
1240 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1242 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1243 volptr->partition->name, V_id(volptr)));
1244 /* remove destination inode which was partially copied till now */
1245 FDH_REALLYCLOSE(newFdP);
1247 FDH_REALLYCLOSE(targFdP);
1248 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1251 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1252 rc, V_id(volptr), volptr->partition->name));
1253 VTakeOffline(volptr);
1258 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1259 * since we never do any I/O anywhere near 2^32 bytes at a
1260 * time, just case to an unsigned int for printing */
1263 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1264 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1265 (unsigned)wrlen, errno));
1266 #if defined(AFS_DEMAND_ATTACH_FS)
1267 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1269 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1271 /* Decrement this inode so salvager doesn't find it. */
1272 FDH_REALLYCLOSE(newFdP);
1274 FDH_REALLYCLOSE(targFdP);
1275 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1277 VTakeOffline(volptr);
1281 #ifndef AFS_PTHREAD_ENV
1283 #endif /* !AFS_PTHREAD_ENV */
1285 FDH_REALLYCLOSE(targFdP);
1286 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1287 V_parentId(volptr));
1289 IH_RELEASE(targetptr->handle);
1291 rc = FDH_SYNC(newFdP);
1292 osi_Assert(rc == 0);
1294 targetptr->handle = newH;
1295 VN_SET_INO(targetptr, ino);
1296 targetptr->disk.cloned = 0;
1297 /* Internal change to vnode, no user level change to volume - def 5445 */
1298 targetptr->changed_oldTime = 1;
1300 return 0; /* success */
1304 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1307 char *buff = malloc(COPYBUFFSIZE);
1312 afs_foff_t done = off;
1314 if (size > FDH_SIZE(targFdP) - off)
1315 size = FDH_SIZE(targFdP) - off;
1318 if (size > COPYBUFFSIZE) { /* more than a buffer */
1319 length = COPYBUFFSIZE;
1320 size -= COPYBUFFSIZE;
1325 rdlen = FDH_PREAD(targFdP, buff, length, done);
1326 if (rdlen == length) {
1327 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1333 if ((rdlen != length) || (wrlen != length)) {
1334 /* no error recovery, at the worst we'll have a "hole"
1346 * Common code to handle with removing the Name (file when it's called from
1347 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1348 * given directory, parentptr.
1350 int DT1 = 0, DT0 = 0;
1352 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1353 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1355 DirHandle childdir; /* Handle for dir package I/O */
1356 Error errorCode = 0;
1360 /* watch for invalid names */
1361 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1363 if (parentptr->disk.cloned) {
1364 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1365 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1367 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1373 /* check that the file is in the directory */
1374 SetDirHandle(dir, parentptr);
1375 if (Lookup(dir, Name, fileFid))
1377 fileFid->Volume = V_id(volptr);
1379 /* just-in-case check for something causing deadlock */
1380 if (fileFid->Vnode == parentptr->vnodeNumber)
1383 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1387 if (ChkForDir == MustBeDIR) {
1388 if ((*targetptr)->disk.type != vDirectory)
1390 } else if ((*targetptr)->disk.type == vDirectory)
1393 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1395 * If the uniquifiers dont match then instead of asserting
1396 * take the volume offline and return VSALVAGE
1398 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1399 VTakeOffline(volptr);
1401 ("Volume %u now offline, must be salvaged.\n",
1403 errorCode = VSALVAGE;
1407 if (ChkForDir == MustBeDIR) {
1408 SetDirHandle(&childdir, *targetptr);
1409 if (IsEmpty(&childdir) != 0)
1411 DZap((afs_int32 *) &childdir);
1413 (*targetptr)->delete = 1;
1414 } else if ((--(*targetptr)->disk.linkCount) == 0)
1415 (*targetptr)->delete = 1;
1416 if ((*targetptr)->delete) {
1417 if (VN_GET_INO(*targetptr)) {
1419 IH_REALLYCLOSE((*targetptr)->handle);
1421 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1422 V_parentId(volptr));
1423 IH_RELEASE((*targetptr)->handle);
1424 if (errorCode == -1) {
1426 ("DT: inode=%s, name=%s, errno=%d\n",
1427 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1429 if (errno != ENOENT)
1431 VTakeOffline(volptr);
1433 ("Volume %u now offline, must be salvaged.\n",
1441 VN_SET_INO(*targetptr, (Inode) 0);
1443 afs_fsize_t adjLength;
1444 VN_GET_LEN(adjLength, *targetptr);
1445 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1449 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1451 code = Delete(dir, (char *)Name);
1454 ("Error %d deleting %s\n", code,
1455 (((*targetptr)->disk.type ==
1456 Directory) ? "directory" : "file")));
1457 VTakeOffline(volptr);
1459 ("Volume %u now offline, must be salvaged.\n",
1472 * This routine updates the parent directory's status block after the
1473 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1474 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1478 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1479 int author, int linkcount,
1480 #if FS_STATS_DETAILED
1481 char a_inSameNetwork
1482 #endif /* FS_STATS_DETAILED */
1485 afs_fsize_t newlength; /* Holds new directory length */
1486 afs_fsize_t parentLength;
1488 #if FS_STATS_DETAILED
1489 Date currDate; /*Current date */
1490 int writeIdx; /*Write index to bump */
1491 int timeIdx; /*Authorship time index to bump */
1492 #endif /* FS_STATS_DETAILED */
1494 parentptr->disk.dataVersion++;
1495 newlength = (afs_fsize_t) Length(dir);
1497 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1498 * (create, symlink, link, makedir) so we need to check if we have enough space
1499 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1500 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1502 VN_GET_LEN(parentLength, parentptr);
1503 if (nBlocks(newlength) != nBlocks(parentLength)) {
1504 VAdjustDiskUsage(&errorCode, volptr,
1505 (nBlocks(newlength) - nBlocks(parentLength)),
1506 (nBlocks(newlength) - nBlocks(parentLength)));
1508 VN_SET_LEN(parentptr, newlength);
1510 #if FS_STATS_DETAILED
1512 * Update directory write stats for this volume. Note that the auth
1513 * counter is located immediately after its associated ``distance''
1516 if (a_inSameNetwork)
1517 writeIdx = VOL_STATS_SAME_NET;
1519 writeIdx = VOL_STATS_DIFF_NET;
1520 V_stat_writes(volptr, writeIdx)++;
1521 if (author != AnonymousID) {
1522 V_stat_writes(volptr, writeIdx + 1)++;
1526 * Update the volume's authorship information in response to this
1527 * directory operation. Get the current time, decide to which time
1528 * slot this operation belongs, and bump the appropriate slot.
1530 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1532 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1533 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1534 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1535 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1536 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1537 if (parentptr->disk.author == author) {
1538 V_stat_dirSameAuthor(volptr, timeIdx)++;
1540 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1542 #endif /* FS_STATS_DETAILED */
1544 parentptr->disk.author = author;
1545 parentptr->disk.linkCount = linkcount;
1546 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1547 parentptr->disk.serverModifyTime = FT_ApproxTime();
1548 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1553 * Update the target file's (or dir's) status block after the specified
1554 * operation is complete. Note that some other fields maybe updated by
1555 * the individual module.
1558 /* XXX INCOMPLETE - More attention is needed here! */
1560 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1561 struct client *client, AFSStoreStatus * InStatus,
1562 Vnode * parentptr, Volume * volptr,
1565 #if FS_STATS_DETAILED
1566 Date currDate; /*Current date */
1567 int writeIdx; /*Write index to bump */
1568 int timeIdx; /*Authorship time index to bump */
1569 #endif /* FS_STATS_DETAILED */
1571 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1572 targetptr->disk.parent = parentptr->vnodeNumber;
1573 VN_SET_LEN(targetptr, length);
1574 /* targetptr->disk.group = 0; save some cycles */
1575 targetptr->disk.modeBits = 0777;
1576 targetptr->disk.owner = client->ViceId;
1577 targetptr->disk.dataVersion = 0; /* consistent with the client */
1578 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1579 /* the inode was created in Alloc_NewVnode() */
1581 #if FS_STATS_DETAILED
1583 * Update file write stats for this volume. Note that the auth
1584 * counter is located immediately after its associated ``distance''
1587 if (client->InSameNetwork)
1588 writeIdx = VOL_STATS_SAME_NET;
1590 writeIdx = VOL_STATS_DIFF_NET;
1591 V_stat_writes(volptr, writeIdx)++;
1592 if (client->ViceId != AnonymousID) {
1593 V_stat_writes(volptr, writeIdx + 1)++;
1597 * We only count operations that DON'T involve creating new objects
1598 * (files, symlinks, directories) or simply setting status as
1599 * authorship-change operations.
1601 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1603 * Update the volume's authorship information in response to this
1604 * file operation. Get the current time, decide to which time
1605 * slot this operation belongs, and bump the appropriate slot.
1607 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1610 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1611 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1612 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1613 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1614 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1615 VOL_STATS_TIME_IDX_5);
1616 if (targetptr->disk.author == client->ViceId) {
1617 V_stat_fileSameAuthor(volptr, timeIdx)++;
1619 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1622 #endif /* FS_STATS_DETAILED */
1624 if (!(Caller & TVS_SSTATUS))
1625 targetptr->disk.author = client->ViceId;
1626 if (Caller & TVS_SDATA) {
1627 targetptr->disk.dataVersion++;
1628 if (VanillaUser(client)) {
1629 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1630 #ifdef CREATE_SGUID_ADMIN_ONLY
1631 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1635 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1636 /* store status, must explicitly request to change the date */
1637 if (InStatus->Mask & AFS_SETMODTIME)
1638 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1639 } else { /* other: date always changes, but perhaps to what is specified by caller */
1640 targetptr->disk.unixModifyTime =
1641 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1642 ClientModTime : FT_ApproxTime());
1644 if (InStatus->Mask & AFS_SETOWNER) {
1645 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1646 if (VanillaUser(client)) {
1647 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1648 #ifdef CREATE_SGUID_ADMIN_ONLY
1649 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1652 targetptr->disk.owner = InStatus->Owner;
1653 if (VolumeRootVnode(targetptr)) {
1654 Error errorCode = 0; /* what should be done with this? */
1656 V_owner(targetptr->volumePtr) = InStatus->Owner;
1657 VUpdateVolume(&errorCode, targetptr->volumePtr);
1660 if (InStatus->Mask & AFS_SETMODE) {
1661 int modebits = InStatus->UnixModeBits;
1662 #define CREATE_SGUID_ADMIN_ONLY 1
1663 #ifdef CREATE_SGUID_ADMIN_ONLY
1664 if (VanillaUser(client))
1665 modebits = modebits & 0777;
1667 if (VanillaUser(client)) {
1668 targetptr->disk.modeBits = modebits;
1670 targetptr->disk.modeBits = modebits;
1673 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1674 CHK_STOREDATA, AUD_END);
1678 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1679 CHK_STORESTATUS, AUD_END);
1686 targetptr->disk.serverModifyTime = FT_ApproxTime();
1687 if (InStatus->Mask & AFS_SETGROUP)
1688 targetptr->disk.group = InStatus->Group;
1689 /* vnode changed : to be written back by VPutVnode */
1690 targetptr->changed_newTime = 1;
1692 } /*Update_TargetVnodeStatus */
1696 * Fills the CallBack structure with the expiration time and type of callback
1697 * structure. Warning: this function is currently incomplete.
1700 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1702 /* CallBackTime could not be 0 */
1703 if (CallBackTime == 0) {
1704 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1705 CallBack->ExpirationTime = 0;
1707 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1708 CallBack->CallBackVersion = CALLBACK_VERSION;
1709 CallBack->CallBackType = CB_SHARED; /* The default for now */
1711 } /*SetCallBackStruct */
1715 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1716 * allocation; if some error occured (exceeded volume quota or partition
1717 * was full, or whatever), it frees the space back and returns the code.
1718 * We usually pre-adjust the volume space to make sure that there's
1719 * enough space before consuming some.
1722 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1723 afs_sfsize_t checkLength)
1728 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1730 VAdjustDiskUsage(&nc, volptr, -length, 0);
1731 if (rc == VOVERQUOTA) {
1733 ("Volume %u (%s) is full\n", V_id(volptr),
1737 if (rc == VDISKFULL) {
1739 ("Partition %s that contains volume %u is full\n",
1740 volptr->partition->name, V_id(volptr)));
1743 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1748 } /*AdjustDiskUsage */
1751 * Common code that handles the creation of a new file (SAFS_CreateFile and
1752 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1755 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1756 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1757 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1759 Error errorCode = 0; /* Error code returned back */
1762 Inode nearInode; /* hint for inode allocation in solaris */
1766 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1767 BlocksPreallocatedForVnode))) {
1769 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1770 (afs_intmax_t) BlocksPreallocatedForVnode));
1774 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1775 if (errorCode != 0) {
1776 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1779 OutFid->Volume = V_id(volptr);
1780 OutFid->Vnode = (*targetptr)->vnodeNumber;
1781 OutFid->Unique = (*targetptr)->disk.uniquifier;
1783 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1785 /* create the inode now itself */
1787 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1788 VPartitionPath(V_partition(volptr)), nearInode,
1789 V_id(volptr), (*targetptr)->vnodeNumber,
1790 (*targetptr)->disk.uniquifier, 1);
1792 /* error in creating inode */
1793 if (!VALID_INO(inode)) {
1795 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1796 (*targetptr)->volumePtr->header->diskstuff.id,
1797 (*targetptr)->vnodeNumber, errno));
1798 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1799 (*targetptr)->delete = 1; /* delete vnode */
1802 VN_SET_INO(*targetptr, inode);
1803 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1805 /* copy group from parent dir */
1806 (*targetptr)->disk.group = parentptr->disk.group;
1808 if (parentptr->disk.cloned) {
1809 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1810 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1811 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1812 /* delete the vnode previously allocated */
1813 (*targetptr)->delete = 1;
1814 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1815 IH_REALLYCLOSE((*targetptr)->handle);
1816 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1818 ("Alloc_NewVnode: partition %s idec %s failed\n",
1819 volptr->partition->name, PrintInode(stmp, inode)));
1820 IH_RELEASE((*targetptr)->handle);
1826 /* add the name to the directory */
1827 SetDirHandle(dir, parentptr);
1828 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1829 (*targetptr)->delete = 1;
1830 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1831 IH_REALLYCLOSE((*targetptr)->handle);
1832 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1834 ("Alloc_NewVnode: partition %s idec %s failed\n",
1835 volptr->partition->name, PrintInode(stmp, inode)));
1836 IH_RELEASE((*targetptr)->handle);
1842 } /*Alloc_NewVnode */
1846 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1850 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1852 int Time; /* Used for time */
1853 int writeVnode = targetptr->changed_oldTime; /* save original status */
1855 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1856 Time = FT_ApproxTime();
1857 switch (LockingType) {
1860 if (Time > targetptr->disk.lock.lockTime)
1861 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1863 Time += AFS_LOCKWAIT;
1864 if (LockingType == LockRead) {
1865 if ( !(rights & PRSFS_LOCK) &&
1866 !(rights & PRSFS_WRITE) &&
1867 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1870 if (targetptr->disk.lock.lockCount >= 0) {
1871 ++(targetptr->disk.lock.lockCount);
1872 targetptr->disk.lock.lockTime = Time;
1875 } else if (LockingType == LockWrite) {
1876 if ( !(rights & PRSFS_WRITE) &&
1877 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1880 if (targetptr->disk.lock.lockCount == 0) {
1881 targetptr->disk.lock.lockCount = -1;
1882 targetptr->disk.lock.lockTime = Time;
1888 Time += AFS_LOCKWAIT;
1889 if (targetptr->disk.lock.lockCount != 0)
1890 targetptr->disk.lock.lockTime = Time;
1895 if ((--targetptr->disk.lock.lockCount) <= 0)
1896 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1900 targetptr->changed_oldTime = writeVnode; /* restore old status */
1901 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1904 } /*HandleLocking */
1906 /* 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. */
1909 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1913 if (!(rights & Prfs_Mode))
1915 if ((targetptr->disk.type != vDirectory)
1916 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1922 * If some flags (i.e. min or max quota) are set, the volume's in disk
1923 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1924 * update, if applicable.
1927 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1928 char *Name, char *OfflineMsg, char *Motd)
1930 Error errorCode = 0;
1932 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1933 V_minquota(volptr) = StoreVolStatus->MinQuota;
1934 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1935 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1936 if (strlen(OfflineMsg) > 0) {
1937 strcpy(V_offlineMessage(volptr), OfflineMsg);
1939 if (strlen(Name) > 0) {
1940 strcpy(V_name(volptr), Name);
1942 #if OPENAFS_VOL_STATS
1944 * We don't overwrite the motd field, since it's now being used
1948 if (strlen(Motd) > 0) {
1949 strcpy(V_motd(volptr), Motd);
1951 #endif /* FS_STATS_DETAILED */
1952 VUpdateVolume(&errorCode, volptr);
1955 } /*RXUpdate_VolumeStatus */
1959 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1960 char **motd, Volume * volptr)
1964 status->Vid = V_id(volptr);
1965 status->ParentId = V_parentId(volptr);
1966 status->Online = V_inUse(volptr);
1967 status->InService = V_inService(volptr);
1968 status->Blessed = V_blessed(volptr);
1969 status->NeedsSalvage = V_needsSalvaged(volptr);
1970 if (VolumeWriteable(volptr))
1971 status->Type = ReadWrite;
1973 status->Type = ReadOnly;
1974 status->MinQuota = V_minquota(volptr);
1975 status->MaxQuota = V_maxquota(volptr);
1976 status->BlocksInUse = V_diskused(volptr);
1977 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1978 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1980 /* now allocate and copy these things; they're freed by the RXGEN stub */
1981 temp = strlen(V_name(volptr)) + 1;
1982 *name = malloc(temp);
1984 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1985 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1987 strcpy(*name, V_name(volptr));
1988 temp = strlen(V_offlineMessage(volptr)) + 1;
1989 *offMsg = malloc(temp);
1991 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1992 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1994 strcpy(*offMsg, V_offlineMessage(volptr));
1995 #if OPENAFS_VOL_STATS
1998 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1999 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2001 strcpy(*motd, nullString);
2003 temp = strlen(V_motd(volptr)) + 1;
2004 *motd = malloc(temp);
2006 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2007 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2009 strcpy(*motd, V_motd(volptr));
2010 #endif /* FS_STATS_DETAILED */
2012 } /*RXGetVolumeStatus */
2016 FileNameOK(char *aname)
2021 /* watch for @sys on the right */
2022 if (strcmp(aname + i - 4, "@sys") == 0)
2025 while ((tc = *aname++)) {
2027 return 0; /* very bad character to encounter */
2029 return 1; /* file name is ok */
2035 * This variant of symlink is expressly to support the AFS/DFS translator
2036 * and is not supported by the AFS fileserver. We just return EINVAL.
2037 * The cache manager should not generate this call to an AFS cache manager.
2040 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2041 char *LinkContents, struct AFSStoreStatus *InStatus,
2042 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2043 struct AFSFetchStatus *OutDirStatus,
2044 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2050 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2051 struct FsCmdInputs * Inputs,
2052 struct FsCmdOutputs * Outputs)
2056 switch (Inputs->command) {
2060 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2061 Inputs->command, Outputs->code));
2066 static struct afs_buffer {
2067 struct afs_buffer *next;
2068 } *freeBufferList = 0;
2069 static int afs_buffersAlloced = 0;
2072 FreeSendBuffer(struct afs_buffer *adata)
2075 afs_buffersAlloced--;
2076 adata->next = freeBufferList;
2077 freeBufferList = adata;
2081 } /*FreeSendBuffer */
2083 /* allocate space for sender */
2085 AllocSendBuffer(void)
2087 struct afs_buffer *tp;
2090 afs_buffersAlloced++;
2091 if (!freeBufferList) {
2094 tmp = malloc(sendBufSize);
2096 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2097 osi_Panic("Failed malloc in AllocSendBuffer\n");
2101 tp = freeBufferList;
2102 freeBufferList = tp->next;
2106 } /*AllocSendBuffer */
2107 #endif /* HAVE_PIOV */
2110 * This routine returns the status info associated with the targetptr vnode
2111 * in the AFSFetchStatus structure. Some of the newer fields, such as
2112 * SegSize and Group are not yet implemented
2116 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2117 afs_int32 anyrights, Vnode * parentptr)
2119 /* initialize return status from a vnode */
2120 status->InterfaceVersion = 1;
2121 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2122 status->errorCode = 0;
2123 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2124 if (targetptr->disk.type == vFile)
2125 status->FileType = File;
2126 else if (targetptr->disk.type == vDirectory)
2127 status->FileType = Directory;
2128 else if (targetptr->disk.type == vSymlink)
2129 status->FileType = SymbolicLink;
2131 status->FileType = Invalid; /*invalid type field */
2132 status->LinkCount = targetptr->disk.linkCount;
2134 afs_fsize_t targetLen;
2135 VN_GET_LEN(targetLen, targetptr);
2136 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2138 status->DataVersion = targetptr->disk.dataVersion;
2139 status->Author = targetptr->disk.author;
2140 status->Owner = targetptr->disk.owner;
2141 status->CallerAccess = rights;
2142 status->AnonymousAccess = anyrights;
2143 status->UnixModeBits = targetptr->disk.modeBits;
2144 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2145 status->ParentVnode =
2146 (status->FileType ==
2147 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2148 status->ParentUnique =
2149 (status->FileType ==
2150 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2151 status->ServerModTime = targetptr->disk.serverModifyTime;
2152 status->Group = targetptr->disk.group;
2153 status->lockCount = targetptr->disk.lock.lockCount;
2154 status->errorCode = 0;
2160 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2161 afs_sfsize_t Pos, afs_sfsize_t Len,
2162 struct AFSFetchStatus *OutStatus,
2163 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2166 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2167 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2168 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2169 Error errorCode = 0; /* return code to caller */
2170 Error fileCode = 0; /* return code from vol package */
2171 Volume *volptr = 0; /* pointer to the volume */
2172 struct client *client = 0; /* pointer to the client data */
2173 struct rx_connection *tcon; /* the connection we're part of */
2175 afs_int32 rights, anyrights; /* rights for this and any user */
2176 struct client *t_client = NULL; /* tmp ptr to client data */
2177 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2178 struct VCallByVol tcbv, *cbv = NULL;
2179 #if FS_STATS_DETAILED
2180 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2181 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2182 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2183 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2184 struct timeval elapsedTime; /* Transfer time */
2185 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2186 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2187 int readIdx; /* Index of read stats array to bump */
2188 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2191 * Set our stats pointers, remember when the RPC operation started, and
2192 * tally the operation.
2194 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2195 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2199 FT_GetTimeOfDay(&opStartTime, 0);
2200 #endif /* FS_STATS_DETAILED */
2203 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2206 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2208 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2211 /* Get ptr to client data for user Id for logging */
2212 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2213 logHostAddr.s_addr = rxr_HostOf(tcon);
2215 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2216 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2217 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2219 queue_NodeInit(&tcbv);
2224 * Get volume/vnode for the fetched file; caller's access rights to
2225 * it are also returned
2228 GetVolumePackageWithCall(tcon, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2229 &parentwhentargetnotdir, &client, READ_LOCK,
2230 &rights, &anyrights)))
2233 SetVolumeSync(Sync, volptr);
2235 #if FS_STATS_DETAILED
2237 * Remember that another read operation was performed.
2240 if (client->InSameNetwork)
2241 readIdx = VOL_STATS_SAME_NET;
2243 readIdx = VOL_STATS_DIFF_NET;
2244 V_stat_reads(volptr, readIdx)++;
2245 if (client->ViceId != AnonymousID) {
2246 V_stat_reads(volptr, readIdx + 1)++;
2249 #endif /* FS_STATS_DETAILED */
2250 /* Check whether the caller has permission access to fetch the data */
2252 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2256 * Drop the read lock on the parent directory after saving the parent
2257 * vnode information we need to pass to GetStatus
2259 if (parentwhentargetnotdir != NULL) {
2260 tparentwhentargetnotdir = *parentwhentargetnotdir;
2261 VPutVnode(&fileCode, parentwhentargetnotdir);
2262 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2263 parentwhentargetnotdir = NULL;
2265 #if FS_STATS_DETAILED
2267 * Remember when the data transfer started.
2269 FT_GetTimeOfDay(&xferStartTime, 0);
2270 #endif /* FS_STATS_DETAILED */
2272 /* actually do the data transfer */
2273 #if FS_STATS_DETAILED
2275 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2276 &bytesToXfer, &bytesXferred);
2279 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2281 #endif /* FS_STATS_DETAILED */
2283 #if FS_STATS_DETAILED
2285 * At this point, the data transfer is done, for good or ill. Remember
2286 * when the transfer ended, bump the number of successes/failures, and
2287 * integrate the transfer size and elapsed time into the stats. If the
2288 * operation failed, we jump to the appropriate point.
2290 FT_GetTimeOfDay(&xferStopTime, 0);
2292 (xferP->numXfers)++;
2294 (xferP->numSuccesses)++;
2297 * Bump the xfer sum by the number of bytes actually sent, NOT the
2300 tot_bytesXferred += bytesXferred;
2301 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2302 tot_bytesXferred &= 0x3FF;
2303 if (bytesXferred < xferP->minBytes)
2304 xferP->minBytes = bytesXferred;
2305 if (bytesXferred > xferP->maxBytes)
2306 xferP->maxBytes = bytesXferred;
2309 * Tally the size of the object. Note: we tally the actual size,
2310 * NOT the number of bytes that made it out over the wire.
2312 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2313 (xferP->count[0])++;
2314 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2315 (xferP->count[1])++;
2316 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2317 (xferP->count[2])++;
2318 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2319 (xferP->count[3])++;
2320 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2321 (xferP->count[4])++;
2322 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2323 (xferP->count[5])++;
2324 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2325 (xferP->count[6])++;
2326 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2327 (xferP->count[7])++;
2329 (xferP->count[8])++;
2331 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2332 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2333 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2334 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2335 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2337 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2338 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2343 * Finally, go off to tell our caller the bad news in case the
2348 #endif /* FS_STATS_DETAILED */
2350 /* write back the OutStatus from the target vnode */
2351 GetStatus(targetptr, OutStatus, rights, anyrights,
2352 &tparentwhentargetnotdir);
2354 /* if a r/w volume, promise a callback to the caller */
2355 if (VolumeWriteable(volptr))
2356 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2358 struct AFSFid myFid;
2359 memset(&myFid, 0, sizeof(struct AFSFid));
2360 myFid.Volume = Fid->Volume;
2361 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2365 /* Update and store volume/vnode and parent vnodes back */
2366 (void)PutVolumePackageWithCall(parentwhentargetnotdir, targetptr,
2367 (Vnode *) 0, volptr, &client, cbv);
2368 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2369 errorCode = CallPostamble(tcon, errorCode, thost);
2371 #if FS_STATS_DETAILED
2372 FT_GetTimeOfDay(&opStopTime, 0);
2373 if (errorCode == 0) {
2375 (opP->numSuccesses)++;
2376 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2377 fs_stats_AddTo((opP->sumTime), elapsedTime);
2378 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2379 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2380 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2382 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2383 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2387 #endif /* FS_STATS_DETAILED */
2389 osi_auditU(acall, FetchDataEvent, errorCode,
2390 AUD_ID, t_client ? t_client->ViceId : 0,
2391 AUD_FID, Fid, AUD_END);
2394 } /*SRXAFS_FetchData */
2397 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2398 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2399 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2401 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2406 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2407 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2408 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2411 afs_sfsize_t tPos, tLen;
2413 tPos = (afs_sfsize_t) Pos;
2414 tLen = (afs_sfsize_t) Len;
2417 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2423 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2424 struct AFSOpaque * AccessList,
2425 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2427 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2428 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2429 Error errorCode = 0; /* return error code to caller */
2430 Volume *volptr = 0; /* pointer to the volume */
2431 struct client *client = 0; /* pointer to the client data */
2432 afs_int32 rights, anyrights; /* rights for this and any user */
2433 struct rx_connection *tcon = rx_ConnectionOf(acall);
2435 struct client *t_client = NULL; /* tmp ptr to client data */
2436 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2437 #if FS_STATS_DETAILED
2438 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2439 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2440 struct timeval elapsedTime; /* Transfer time */
2443 * Set our stats pointer, remember when the RPC operation started, and
2444 * tally the operation.
2446 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2450 FT_GetTimeOfDay(&opStartTime, 0);
2451 #endif /* FS_STATS_DETAILED */
2454 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2457 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2459 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2462 /* Get ptr to client data for user Id for logging */
2463 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2464 logHostAddr.s_addr = rxr_HostOf(tcon);
2466 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2467 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2468 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2470 AccessList->AFSOpaque_len = 0;
2471 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2472 if (!AccessList->AFSOpaque_val) {
2473 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2474 osi_Panic("Failed malloc in SRXAFS_FetchACL\n");
2478 * Get volume/vnode for the fetched file; caller's access rights to it
2482 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2483 &parentwhentargetnotdir, &client, READ_LOCK,
2484 &rights, &anyrights)))
2487 SetVolumeSync(Sync, volptr);
2489 /* Check whether we have permission to fetch the ACL */
2491 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2494 /* Get the Access List from the dir's vnode */
2496 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2499 /* Get OutStatus back From the target Vnode */
2500 GetStatus(targetptr, OutStatus, rights, anyrights,
2501 parentwhentargetnotdir);
2504 /* Update and store volume/vnode and parent vnodes back */
2505 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2508 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2509 AccessList->AFSOpaque_val));
2510 errorCode = CallPostamble(tcon, errorCode, thost);
2512 #if FS_STATS_DETAILED
2513 FT_GetTimeOfDay(&opStopTime, 0);
2514 if (errorCode == 0) {
2516 (opP->numSuccesses)++;
2517 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2518 fs_stats_AddTo((opP->sumTime), elapsedTime);
2519 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2520 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2521 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2523 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2524 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2528 #endif /* FS_STATS_DETAILED */
2530 osi_auditU(acall, FetchACLEvent, errorCode,
2531 AUD_ID, t_client ? t_client->ViceId : 0,
2533 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2535 } /*SRXAFS_FetchACL */
2539 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2540 * merged into it when possible.
2544 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2545 struct AFSFetchStatus *OutStatus,
2546 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2548 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2549 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2550 Error errorCode = 0; /* return code to caller */
2551 Volume *volptr = 0; /* pointer to the volume */
2552 struct client *client = 0; /* pointer to the client data */
2553 afs_int32 rights, anyrights; /* rights for this and any user */
2554 struct client *t_client = NULL; /* tmp ptr to client data */
2555 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2556 struct rx_connection *tcon = rx_ConnectionOf(acall);
2558 /* Get ptr to client data for user Id for logging */
2559 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2560 logHostAddr.s_addr = rxr_HostOf(tcon);
2562 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2563 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2564 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2566 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2569 * Get volume/vnode for the fetched file; caller's rights to it are
2573 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2574 &parentwhentargetnotdir, &client, READ_LOCK,
2575 &rights, &anyrights)))
2576 goto Bad_FetchStatus;
2578 /* set volume synchronization information */
2579 SetVolumeSync(Sync, volptr);
2581 /* Are we allowed to fetch Fid's status? */
2582 if (targetptr->disk.type != vDirectory) {
2584 Check_PermissionRights(targetptr, client, rights,
2585 CHK_FETCHSTATUS, 0))) {
2586 if (rx_GetCallAbortCode(acall) == errorCode)
2587 rx_SetCallAbortCode(acall, 0);
2588 goto Bad_FetchStatus;
2592 /* set OutStatus From the Fid */
2593 GetStatus(targetptr, OutStatus, rights, anyrights,
2594 parentwhentargetnotdir);
2596 /* If a r/w volume, also set the CallBack state */
2597 if (VolumeWriteable(volptr))
2598 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2600 struct AFSFid myFid;
2601 memset(&myFid, 0, sizeof(struct AFSFid));
2602 myFid.Volume = Fid->Volume;
2603 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2607 /* Update and store volume/vnode and parent vnodes back */
2608 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2610 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2613 } /*SAFSS_FetchStatus */
2617 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2618 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2619 struct AFSVolSync * Sync)
2623 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2624 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2625 Error errorCode = 0; /* return code to caller */
2626 Volume *volptr = 0; /* pointer to the volume */
2627 struct client *client = 0; /* pointer to the client data */
2628 afs_int32 rights, anyrights; /* rights for this and any user */
2629 struct AFSFid *tfid; /* file id we're dealing with now */
2630 struct rx_connection *tcon = rx_ConnectionOf(acall);
2632 struct client *t_client = NULL; /* tmp pointer to the client data */
2633 #if FS_STATS_DETAILED
2634 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2635 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2636 struct timeval elapsedTime; /* Transfer time */
2639 * Set our stats pointer, remember when the RPC operation started, and
2640 * tally the operation.
2642 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2646 FT_GetTimeOfDay(&opStartTime, 0);
2647 #endif /* FS_STATS_DETAILED */
2649 ViceLog(1, ("SAFS_BulkStatus\n"));
2651 AFSCallStats.TotalCalls++;
2653 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2654 if (nfiles <= 0) { /* Sanity check */
2656 goto Audit_and_Return;
2659 /* allocate space for return output parameters */
2660 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2661 malloc(nfiles * sizeof(struct AFSFetchStatus));
2662 if (!OutStats->AFSBulkStats_val) {
2663 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2664 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2666 OutStats->AFSBulkStats_len = nfiles;
2667 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2668 malloc(nfiles * sizeof(struct AFSCallBack));
2669 if (!CallBacks->AFSCBs_val) {
2670 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2671 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2673 CallBacks->AFSCBs_len = nfiles;
2675 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2676 goto Bad_BulkStatus;
2678 tfid = Fids->AFSCBFids_val;
2679 for (i = 0; i < nfiles; i++, tfid++) {
2681 * Get volume/vnode for the fetched file; caller's rights to it
2685 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2686 &parentwhentargetnotdir, &client, READ_LOCK,
2687 &rights, &anyrights)))
2688 goto Bad_BulkStatus;
2689 /* set volume synchronization information, but only once per call */
2691 SetVolumeSync(Sync, volptr);
2693 /* Are we allowed to fetch Fid's status? */
2694 if (targetptr->disk.type != vDirectory) {
2696 Check_PermissionRights(targetptr, client, rights,
2697 CHK_FETCHSTATUS, 0))) {
2698 if (rx_GetCallAbortCode(acall) == errorCode)
2699 rx_SetCallAbortCode(acall, 0);
2700 goto Bad_BulkStatus;
2704 /* set OutStatus From the Fid */
2705 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2706 anyrights, parentwhentargetnotdir);
2708 /* If a r/w volume, also set the CallBack state */
2709 if (VolumeWriteable(volptr))
2710 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2711 &CallBacks->AFSCBs_val[i]);
2713 struct AFSFid myFid;
2714 memset(&myFid, 0, sizeof(struct AFSFid));
2715 myFid.Volume = tfid->Volume;
2716 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2717 &CallBacks->AFSCBs_val[i]);
2720 /* put back the file ID and volume */
2721 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2723 parentwhentargetnotdir = (Vnode *) 0;
2724 targetptr = (Vnode *) 0;
2725 volptr = (Volume *) 0;
2726 client = (struct client *)0;
2730 /* Update and store volume/vnode and parent vnodes back */
2731 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2733 errorCode = CallPostamble(tcon, errorCode, thost);
2735 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2737 #if FS_STATS_DETAILED
2738 FT_GetTimeOfDay(&opStopTime, 0);
2739 if (errorCode == 0) {
2741 (opP->numSuccesses)++;
2742 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2743 fs_stats_AddTo((opP->sumTime), elapsedTime);
2744 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2745 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2746 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2748 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2749 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2753 #endif /* FS_STATS_DETAILED */
2756 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2757 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2758 AUD_ID, t_client ? t_client->ViceId : 0,
2759 AUD_FIDS, Fids, AUD_END);
2762 } /*SRXAFS_BulkStatus */
2766 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2767 struct AFSBulkStats * OutStats,
2768 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2772 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2773 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2774 Error errorCode = 0; /* return code to caller */
2775 Volume *volptr = 0; /* pointer to the volume */
2776 struct client *client = 0; /* pointer to the client data */
2777 afs_int32 rights, anyrights; /* rights for this and any user */
2778 struct AFSFid *tfid; /* file id we're dealing with now */
2779 struct rx_connection *tcon;
2781 struct client *t_client = NULL; /* tmp ptr to client data */
2782 AFSFetchStatus *tstatus;
2783 int VolSync_set = 0;
2784 #if FS_STATS_DETAILED
2785 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2786 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2787 struct timeval elapsedTime; /* Transfer time */
2790 * Set our stats pointer, remember when the RPC operation started, and
2791 * tally the operation.
2793 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2797 FT_GetTimeOfDay(&opStartTime, 0);
2798 #endif /* FS_STATS_DETAILED */
2800 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2802 AFSCallStats.TotalCalls++;
2804 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2805 if (nfiles <= 0) { /* Sanity check */
2807 goto Audit_and_Return;
2810 /* allocate space for return output parameters */
2811 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2812 malloc(nfiles * sizeof(struct AFSFetchStatus));
2813 if (!OutStats->AFSBulkStats_val) {
2814 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2815 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2817 OutStats->AFSBulkStats_len = nfiles;
2818 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2819 malloc(nfiles * sizeof(struct AFSCallBack));
2820 if (!CallBacks->AFSCBs_val) {
2821 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2822 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2824 CallBacks->AFSCBs_len = nfiles;
2826 /* Zero out return values to avoid leaking information on partial succes */
2827 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2828 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2829 memset(Sync, 0, sizeof(*Sync));
2831 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2832 goto Bad_InlineBulkStatus;
2835 tfid = Fids->AFSCBFids_val;
2836 for (i = 0; i < nfiles; i++, tfid++) {
2838 * Get volume/vnode for the fetched file; caller's rights to it
2842 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2843 &parentwhentargetnotdir, &client, READ_LOCK,
2844 &rights, &anyrights))) {
2845 tstatus = &OutStats->AFSBulkStats_val[i];
2846 tstatus->errorCode = errorCode;
2847 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2849 parentwhentargetnotdir = (Vnode *) 0;
2850 targetptr = (Vnode *) 0;
2851 volptr = (Volume *) 0;
2852 client = (struct client *)0;
2856 /* set volume synchronization information, but only once per call */
2858 SetVolumeSync(Sync, volptr);
2862 /* Are we allowed to fetch Fid's status? */
2863 if (targetptr->disk.type != vDirectory) {
2865 Check_PermissionRights(targetptr, client, rights,
2866 CHK_FETCHSTATUS, 0))) {
2867 tstatus = &OutStats->AFSBulkStats_val[i];
2868 tstatus->errorCode = errorCode;
2869 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2870 (Vnode *) 0, volptr, &client);
2871 parentwhentargetnotdir = (Vnode *) 0;
2872 targetptr = (Vnode *) 0;
2873 volptr = (Volume *) 0;
2874 client = (struct client *)0;
2879 /* set OutStatus From the Fid */
2880 GetStatus(targetptr,
2881 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2882 rights, anyrights, parentwhentargetnotdir);
2884 /* If a r/w volume, also set the CallBack state */
2885 if (VolumeWriteable(volptr))
2886 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2887 &CallBacks->AFSCBs_val[i]);
2889 struct AFSFid myFid;
2890 memset(&myFid, 0, sizeof(struct AFSFid));
2891 myFid.Volume = tfid->Volume;
2892 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2893 &CallBacks->AFSCBs_val[i]);
2896 /* put back the file ID and volume */
2897 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2899 parentwhentargetnotdir = (Vnode *) 0;
2900 targetptr = (Vnode *) 0;
2901 volptr = (Volume *) 0;
2902 client = (struct client *)0;
2905 Bad_InlineBulkStatus:
2906 /* Update and store volume/vnode and parent vnodes back */
2907 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2909 errorCode = CallPostamble(tcon, errorCode, thost);
2911 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2913 #if FS_STATS_DETAILED
2914 FT_GetTimeOfDay(&opStopTime, 0);
2915 if (errorCode == 0) {
2917 (opP->numSuccesses)++;
2918 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2919 fs_stats_AddTo((opP->sumTime), elapsedTime);
2920 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2921 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2922 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2924 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2925 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2929 #endif /* FS_STATS_DETAILED */
2932 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2933 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2934 AUD_ID, t_client ? t_client->ViceId : 0,
2935 AUD_FIDS, Fids, AUD_END);
2938 } /*SRXAFS_InlineBulkStatus */
2942 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2943 struct AFSFetchStatus * OutStatus,
2944 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2947 struct rx_connection *tcon;
2949 struct client *t_client = NULL; /* tmp ptr to client data */
2950 #if FS_STATS_DETAILED
2951 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2952 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2953 struct timeval elapsedTime; /* Transfer time */
2956 * Set our stats pointer, remember when the RPC operation started, and
2957 * tally the operation.
2959 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2963 FT_GetTimeOfDay(&opStartTime, 0);
2964 #endif /* FS_STATS_DETAILED */
2966 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2967 goto Bad_FetchStatus;
2969 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2972 code = CallPostamble(tcon, code, thost);
2974 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2976 #if FS_STATS_DETAILED
2977 FT_GetTimeOfDay(&opStopTime, 0);
2980 (opP->numSuccesses)++;
2981 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2982 fs_stats_AddTo((opP->sumTime), elapsedTime);
2983 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2984 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2985 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2987 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2988 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2992 #endif /* FS_STATS_DETAILED */
2994 osi_auditU(acall, FetchStatusEvent, code,
2995 AUD_ID, t_client ? t_client->ViceId : 0,
2996 AUD_FID, Fid, AUD_END);
2999 } /*SRXAFS_FetchStatus */
3003 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
3004 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
3005 afs_fsize_t Length, afs_fsize_t FileLength,
3006 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3008 Vnode *targetptr = 0; /* pointer to input fid */
3009 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3010 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
3011 Error errorCode = 0; /* return code for caller */
3012 Error fileCode = 0; /* return code from vol package */
3013 Volume *volptr = 0; /* pointer to the volume header */
3014 struct client *client = 0; /* pointer to client structure */
3015 afs_int32 rights, anyrights; /* rights for this and any user */
3016 struct client *t_client = NULL; /* tmp ptr to client data */
3017 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3018 struct rx_connection *tcon;
3020 #if FS_STATS_DETAILED
3021 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3022 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
3023 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3024 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
3025 struct timeval elapsedTime; /* Transfer time */
3026 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
3027 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
3028 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
3031 * Set our stats pointers, remember when the RPC operation started, and
3032 * tally the operation.
3034 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
3035 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
3040 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3042 FT_GetTimeOfDay(&opStartTime, 0);
3043 #endif /* FS_STATS_DETAILED */
3046 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3048 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3051 /* Get ptr to client data for user Id for logging */
3052 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3053 logHostAddr.s_addr = rxr_HostOf(tcon);
3055 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3056 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3057 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3060 * Get associated volume/vnode for the stored file; caller's rights
3064 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3065 &parentwhentargetnotdir, &client, WRITE_LOCK,
3066 &rights, &anyrights))) {
3070 /* set volume synchronization information */
3071 SetVolumeSync(Sync, volptr);
3073 if ((targetptr->disk.type == vSymlink)) {
3074 /* Should we return a better error code here??? */
3079 /* Check if we're allowed to store the data */
3081 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3087 * Drop the read lock on the parent directory after saving the parent
3088 * vnode information we need to pass to GetStatus
3090 if (parentwhentargetnotdir != NULL) {
3091 tparentwhentargetnotdir = *parentwhentargetnotdir;
3092 VPutVnode(&fileCode, parentwhentargetnotdir);
3093 osi_Assert(!fileCode || (fileCode == VSALVAGE));
3094 parentwhentargetnotdir = NULL;
3096 #if FS_STATS_DETAILED
3098 * Remember when the data transfer started.
3100 FT_GetTimeOfDay(&xferStartTime, 0);
3101 #endif /* FS_STATS_DETAILED */
3103 /* Do the actual storing of the data */
3104 #if FS_STATS_DETAILED
3106 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3107 FileLength, (InStatus->Mask & AFS_FSYNC),
3108 &bytesToXfer, &bytesXferred);
3111 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3112 FileLength, (InStatus->Mask & AFS_FSYNC));
3113 if (errorCode && (!targetptr->changed_newTime))
3115 #endif /* FS_STATS_DETAILED */
3116 #if FS_STATS_DETAILED
3118 * At this point, the data transfer is done, for good or ill. Remember
3119 * when the transfer ended, bump the number of successes/failures, and
3120 * integrate the transfer size and elapsed time into the stats. If the
3121 * operation failed, we jump to the appropriate point.
3123 FT_GetTimeOfDay(&xferStopTime, 0);
3125 (xferP->numXfers)++;
3127 (xferP->numSuccesses)++;
3130 * Bump the xfer sum by the number of bytes actually sent, NOT the
3133 tot_bytesXferred += bytesXferred;
3134 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3135 tot_bytesXferred &= 0x3FF;
3136 if (bytesXferred < xferP->minBytes)
3137 xferP->minBytes = bytesXferred;
3138 if (bytesXferred > xferP->maxBytes)
3139 xferP->maxBytes = bytesXferred;
3142 * Tally the size of the object. Note: we tally the actual size,
3143 * NOT the number of bytes that made it out over the wire.
3145 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3146 (xferP->count[0])++;
3147 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3148 (xferP->count[1])++;
3149 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3150 (xferP->count[2])++;
3151 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3152 (xferP->count[3])++;
3153 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3154 (xferP->count[4])++;
3155 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3156 (xferP->count[5])++;
3157 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3158 (xferP->count[6])++;
3159 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3160 (xferP->count[7])++;
3162 (xferP->count[8])++;
3164 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3165 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3166 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3167 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3168 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3170 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3171 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3176 * Finally, go off to tell our caller the bad news in case the
3179 if (errorCode && (!targetptr->changed_newTime))
3181 #endif /* FS_STATS_DETAILED */
3183 /* Update the status of the target's vnode */
3184 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3185 targetptr, volptr, 0);
3187 /* Get the updated File's status back to the caller */
3188 GetStatus(targetptr, OutStatus, rights, anyrights,
3189 &tparentwhentargetnotdir);
3192 /* Update and store volume/vnode and parent vnodes back */
3193 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3195 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3197 errorCode = CallPostamble(tcon, errorCode, thost);
3199 #if FS_STATS_DETAILED
3200 FT_GetTimeOfDay(&opStopTime, 0);
3201 if (errorCode == 0) {
3203 (opP->numSuccesses)++;
3204 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3205 fs_stats_AddTo((opP->sumTime), elapsedTime);
3206 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3207 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3208 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3210 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3211 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3215 #endif /* FS_STATS_DETAILED */
3216 osi_auditU(acall, StoreDataEvent, errorCode,
3217 AUD_ID, t_client ? t_client->ViceId : 0,
3218 AUD_FID, Fid, AUD_END);
3220 } /*common_StoreData64 */
3223 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3224 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3225 afs_uint32 Length, afs_uint32 FileLength,
3226 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3228 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3229 (0x7fffffff - Pos) < Length)
3232 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3234 } /*SRXAFS_StoreData */
3237 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3238 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3239 afs_uint64 Length, afs_uint64 FileLength,
3240 struct AFSFetchStatus * OutStatus,
3241 struct AFSVolSync * Sync)
3245 afs_fsize_t tLength;
3246 afs_fsize_t tFileLength;
3248 tPos = (afs_fsize_t) Pos;
3249 tLength = (afs_fsize_t) Length;
3250 tFileLength = (afs_fsize_t) FileLength;
3253 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3259 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3260 struct AFSOpaque * AccessList,
3261 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3263 Vnode *targetptr = 0; /* pointer to input fid */
3264 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3265 Error errorCode = 0; /* return code for caller */
3266 struct AFSStoreStatus InStatus; /* Input status for fid */
3267 Volume *volptr = 0; /* pointer to the volume header */
3268 struct client *client = 0; /* pointer to client structure */
3269 afs_int32 rights, anyrights; /* rights for this and any user */
3270 struct rx_connection *tcon;
3272 struct client *t_client = NULL; /* tmp ptr to client data */
3273 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3274 #if FS_STATS_DETAILED
3275 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3276 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3277 struct timeval elapsedTime; /* Transfer time */
3280 * Set our stats pointer, remember when the RPC operation started, and
3281 * tally the operation.
3283 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3287 FT_GetTimeOfDay(&opStartTime, 0);
3288 #endif /* FS_STATS_DETAILED */
3289 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3292 /* Get ptr to client data for user Id for logging */
3293 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3294 logHostAddr.s_addr = rxr_HostOf(tcon);
3296 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3297 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3298 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3300 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3302 InStatus.Mask = 0; /* not storing any status */
3305 * Get associated volume/vnode for the target dir; caller's rights
3306 * are also returned.
3309 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3310 &parentwhentargetnotdir, &client, WRITE_LOCK,
3311 &rights, &anyrights))) {
3315 /* set volume synchronization information */
3316 SetVolumeSync(Sync, volptr);
3318 /* Check if we have permission to change the dir's ACL */
3320 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3325 /* Build and store the new Access List for the dir */
3326 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3330 targetptr->changed_newTime = 1; /* status change of directory */
3332 /* convert the write lock to a read lock before breaking callbacks */
3333 VVnodeWriteToRead(&errorCode, targetptr);
3334 osi_Assert(!errorCode || errorCode == VSALVAGE);
3336 /* break call backs on the directory */
3337 BreakCallBack(client->host, Fid, 0);
3339 /* Get the updated dir's status back to the caller */
3340 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3343 /* Update and store volume/vnode and parent vnodes back */
3344 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3346 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3347 errorCode = CallPostamble(tcon, errorCode, thost);
3349 #if FS_STATS_DETAILED
3350 FT_GetTimeOfDay(&opStopTime, 0);
3351 if (errorCode == 0) {
3353 (opP->numSuccesses)++;
3354 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3355 fs_stats_AddTo((opP->sumTime), elapsedTime);
3356 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3357 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3358 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3360 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3361 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3365 #endif /* FS_STATS_DETAILED */
3367 osi_auditU(acall, StoreACLEvent, errorCode,
3368 AUD_ID, t_client ? t_client->ViceId : 0,
3369 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3372 } /*SRXAFS_StoreACL */
3376 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3377 * should be merged when possible.
3380 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3381 struct AFSStoreStatus *InStatus,
3382 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3384 Vnode *targetptr = 0; /* pointer to input fid */
3385 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3386 Error errorCode = 0; /* return code for caller */
3387 Volume *volptr = 0; /* pointer to the volume header */
3388 struct client *client = 0; /* pointer to client structure */
3389 afs_int32 rights, anyrights; /* rights for this and any user */
3390 struct client *t_client = NULL; /* tmp ptr to client data */
3391 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3392 struct rx_connection *tcon = rx_ConnectionOf(acall);
3394 /* Get ptr to client data for user Id for logging */
3395 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3396 logHostAddr.s_addr = rxr_HostOf(tcon);
3398 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3399 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3400 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3402 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3405 * Get volume/vnode for the target file; caller's rights to it are
3409 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3410 &parentwhentargetnotdir, &client, WRITE_LOCK,
3411 &rights, &anyrights))) {
3412 goto Bad_StoreStatus;
3415 /* set volume synchronization information */
3416 SetVolumeSync(Sync, volptr);
3418 /* Check if the caller has proper permissions to store status to Fid */
3420 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3422 goto Bad_StoreStatus;
3425 * Check for a symbolic link; we can't chmod these (otherwise could
3426 * change a symlink to a mt pt or vice versa)
3428 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3430 goto Bad_StoreStatus;
3433 /* Update the status of the target's vnode */
3434 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3435 (parentwhentargetnotdir ? parentwhentargetnotdir
3436 : targetptr), volptr, 0);
3438 /* convert the write lock to a read lock before breaking callbacks */
3439 VVnodeWriteToRead(&errorCode, targetptr);
3440 osi_Assert(!errorCode || errorCode == VSALVAGE);
3442 /* Break call backs on Fid */
3443 BreakCallBack(client->host, Fid, 0);
3445 /* Return the updated status back to caller */
3446 GetStatus(targetptr, OutStatus, rights, anyrights,
3447 parentwhentargetnotdir);
3450 /* Update and store volume/vnode and parent vnodes back */
3451 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3453 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3456 } /*SAFSS_StoreStatus */
3460 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3461 struct AFSStoreStatus * InStatus,
3462 struct AFSFetchStatus * OutStatus,
3463 struct AFSVolSync * Sync)
3466 struct rx_connection *tcon;
3468 struct client *t_client = NULL; /* tmp ptr to client data */
3469 #if FS_STATS_DETAILED
3470 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3471 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3472 struct timeval elapsedTime; /* Transfer time */
3475 * Set our stats pointer, remember when the RPC operation started, and
3476 * tally the operation.
3478 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3482 FT_GetTimeOfDay(&opStartTime, 0);
3483 #endif /* FS_STATS_DETAILED */
3485 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3486 goto Bad_StoreStatus;
3488 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3491 code = CallPostamble(tcon, code, thost);
3493 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3495 #if FS_STATS_DETAILED
3496 FT_GetTimeOfDay(&opStopTime, 0);
3499 (opP->numSuccesses)++;
3500 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3501 fs_stats_AddTo((opP->sumTime), elapsedTime);
3502 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3503 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3504 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3506 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3507 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3511 #endif /* FS_STATS_DETAILED */
3513 osi_auditU(acall, StoreStatusEvent, code,
3514 AUD_ID, t_client ? t_client->ViceId : 0,
3515 AUD_FID, Fid, AUD_END);
3518 } /*SRXAFS_StoreStatus */
3522 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3523 * merged in when possible.
3526 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3527 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3529 Vnode *parentptr = 0; /* vnode of input Directory */
3530 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3531 Vnode *targetptr = 0; /* file to be deleted */
3532 Volume *volptr = 0; /* pointer to the volume header */
3533 AFSFid fileFid; /* area for Fid from the directory */
3534 Error errorCode = 0; /* error code */
3535 DirHandle dir; /* Handle for dir package I/O */
3536 struct client *client = 0; /* pointer to client structure */
3537 afs_int32 rights, anyrights; /* rights for this and any user */
3538 struct client *t_client; /* tmp ptr to client data */
3539 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3540 struct rx_connection *tcon = rx_ConnectionOf(acall);
3543 /* Get ptr to client data for user Id for logging */
3544 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3545 logHostAddr.s_addr = rxr_HostOf(tcon);
3547 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3548 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3549 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3551 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3554 * Get volume/vnode for the parent dir; caller's access rights are
3558 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3559 &parentwhentargetnotdir, &client, WRITE_LOCK,
3560 &rights, &anyrights))) {
3561 goto Bad_RemoveFile;
3563 /* set volume synchronization information */
3564 SetVolumeSync(Sync, volptr);
3566 /* Does the caller has delete (& write) access to the parent directory? */
3567 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3568 goto Bad_RemoveFile;
3571 /* Actually delete the desired file */
3573 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3575 goto Bad_RemoveFile;
3578 /* Update the vnode status of the parent dir */
3579 #if FS_STATS_DETAILED
3580 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3581 parentptr->disk.linkCount,
3582 client->InSameNetwork);
3584 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3585 parentptr->disk.linkCount);
3586 #endif /* FS_STATS_DETAILED */
3588 /* Return the updated parent dir's status back to caller */
3589 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3591 /* Handle internal callback state for the parent and the deleted file */
3592 if (targetptr->disk.linkCount == 0) {
3593 /* no references left, discard entry */
3594 DeleteFileCallBacks(&fileFid);
3595 /* convert the parent lock to a read lock before breaking callbacks */
3596 VVnodeWriteToRead(&errorCode, parentptr);
3597 osi_Assert(!errorCode || errorCode == VSALVAGE);
3599 /* convert the parent lock to a read lock before breaking callbacks */
3600 VVnodeWriteToRead(&errorCode, parentptr);
3601 osi_Assert(!errorCode || errorCode == VSALVAGE);
3602 /* convert the target lock to a read lock before breaking callbacks */
3603 VVnodeWriteToRead(&errorCode, targetptr);
3604 osi_Assert(!errorCode || errorCode == VSALVAGE);
3605 /* tell all the file has changed */
3606 BreakCallBack(client->host, &fileFid, 1);
3609 /* break call back on the directory */
3610 BreakCallBack(client->host, DirFid, 0);
3613 /* Update and store volume/vnode and parent vnodes back */
3614 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3617 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3620 } /*SAFSS_RemoveFile */
3624 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3625 struct AFSFetchStatus * OutDirStatus,
3626 struct AFSVolSync * Sync)
3629 struct rx_connection *tcon;
3631 struct client *t_client = NULL; /* tmp ptr to client data */
3632 #if FS_STATS_DETAILED
3633 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3634 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3635 struct timeval elapsedTime; /* Transfer time */
3638 * Set our stats pointer, remember when the RPC operation started, and
3639 * tally the operation.
3641 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3645 FT_GetTimeOfDay(&opStartTime, 0);
3646 #endif /* FS_STATS_DETAILED */
3648 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3649 goto Bad_RemoveFile;
3651 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3654 code = CallPostamble(tcon, code, thost);
3656 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3658 #if FS_STATS_DETAILED
3659 FT_GetTimeOfDay(&opStopTime, 0);
3662 (opP->numSuccesses)++;
3663 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3664 fs_stats_AddTo((opP->sumTime), elapsedTime);
3665 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3666 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3667 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3669 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3670 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3674 #endif /* FS_STATS_DETAILED */
3676 osi_auditU(acall, RemoveFileEvent, code,
3677 AUD_ID, t_client ? t_client->ViceId : 0,
3678 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3681 } /*SRXAFS_RemoveFile */
3685 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3686 * be merged in when possible.
3689 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3690 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3691 struct AFSFetchStatus *OutFidStatus,
3692 struct AFSFetchStatus *OutDirStatus,
3693 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3695 Vnode *parentptr = 0; /* vnode of input Directory */
3696 Vnode *targetptr = 0; /* vnode of the new file */
3697 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3698 Volume *volptr = 0; /* pointer to the volume header */
3699 Error errorCode = 0; /* error code */
3700 DirHandle dir; /* Handle for dir package I/O */
3701 struct client *client = 0; /* pointer to client structure */
3702 afs_int32 rights, anyrights; /* rights for this and any user */
3703 struct client *t_client; /* tmp ptr to client data */
3704 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3705 struct rx_connection *tcon = rx_ConnectionOf(acall);
3709 /* Get ptr to client data for user Id for logging */
3710 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3711 logHostAddr.s_addr = rxr_HostOf(tcon);
3713 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3714 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3715 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3717 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3719 if (!FileNameOK(Name)) {
3721 goto Bad_CreateFile;
3725 * Get associated volume/vnode for the parent dir; caller long are
3729 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3730 &parentwhentargetnotdir, &client, WRITE_LOCK,
3731 &rights, &anyrights))) {
3732 goto Bad_CreateFile;
3735 /* set volume synchronization information */
3736 SetVolumeSync(Sync, volptr);
3738 /* Can we write (and insert) onto the parent directory? */
3739 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3740 goto Bad_CreateFile;
3742 /* get a new vnode for the file to be created and set it up */
3744 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3745 vFile, nBlocks(0)))) {
3746 goto Bad_CreateFile;
3749 /* update the status of the parent vnode */
3750 #if FS_STATS_DETAILED
3751 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3752 parentptr->disk.linkCount,
3753 client->InSameNetwork);
3755 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3756 parentptr->disk.linkCount);
3757 #endif /* FS_STATS_DETAILED */
3759 /* update the status of the new file's vnode */
3760 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3761 parentptr, volptr, 0);
3763 /* 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 */
3764 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3765 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3767 /* convert the write lock to a read lock before breaking callbacks */
3768 VVnodeWriteToRead(&errorCode, parentptr);
3769 osi_Assert(!errorCode || errorCode == VSALVAGE);
3771 /* break call back on parent dir */
3772 BreakCallBack(client->host, DirFid, 0);
3774 /* Return a callback promise for the newly created file to the caller */
3775 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3778 /* Update and store volume/vnode and parent vnodes back */
3779 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3782 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3785 } /*SAFSS_CreateFile */
3789 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3790 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3791 struct AFSFetchStatus * OutFidStatus,
3792 struct AFSFetchStatus * OutDirStatus,
3793 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3796 struct rx_connection *tcon;
3798 struct client *t_client = NULL; /* tmp ptr to client data */
3799 #if FS_STATS_DETAILED
3800 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3801 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3802 struct timeval elapsedTime; /* Transfer time */
3805 * Set our stats pointer, remember when the RPC operation started, and
3806 * tally the operation.
3808 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3812 FT_GetTimeOfDay(&opStartTime, 0);
3813 #endif /* FS_STATS_DETAILED */
3815 memset(OutFid, 0, sizeof(struct AFSFid));
3817 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3818 goto Bad_CreateFile;
3821 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3822 OutDirStatus, CallBack, Sync);
3825 code = CallPostamble(tcon, code, thost);
3827 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3829 #if FS_STATS_DETAILED
3830 FT_GetTimeOfDay(&opStopTime, 0);
3833 (opP->numSuccesses)++;
3834 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3835 fs_stats_AddTo((opP->sumTime), elapsedTime);
3836 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3837 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3838 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3840 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3841 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3845 #endif /* FS_STATS_DETAILED */
3847 osi_auditU(acall, CreateFileEvent, code,
3848 AUD_ID, t_client ? t_client->ViceId : 0,
3849 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3852 } /*SRXAFS_CreateFile */
3856 * This routine is called exclusively from SRXAFS_Rename(), and should be
3857 * merged in when possible.
3860 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3861 struct AFSFid *NewDirFid, char *NewName,
3862 struct AFSFetchStatus *OutOldDirStatus,
3863 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3865 Vnode *oldvptr = 0; /* vnode of the old Directory */
3866 Vnode *newvptr = 0; /* vnode of the new Directory */
3867 Vnode *fileptr = 0; /* vnode of the file to move */
3868 Vnode *newfileptr = 0; /* vnode of the file to delete */
3869 Vnode *testvptr = 0; /* used in directory tree walk */
3870 Vnode *parent = 0; /* parent for use in SetAccessList */
3871 Error errorCode = 0; /* error code */
3872 Error fileCode = 0; /* used when writing Vnodes */
3873 VnodeId testnode; /* used in directory tree walk */
3874 AFSFid fileFid; /* Fid of file to move */
3875 AFSFid newFileFid; /* Fid of new file */
3876 DirHandle olddir; /* Handle for dir package I/O */
3877 DirHandle newdir; /* Handle for dir package I/O */
3878 DirHandle filedir; /* Handle for dir package I/O */
3879 DirHandle newfiledir; /* Handle for dir package I/O */
3880 Volume *volptr = 0; /* pointer to the volume header */
3881 struct client *client = 0; /* pointer to client structure */
3882 afs_int32 rights, anyrights; /* rights for this and any user */
3883 afs_int32 newrights; /* rights for this user */
3884 afs_int32 newanyrights; /* rights for any user */
3885 int doDelete; /* deleted the rename target (ref count now 0) */
3887 int updatefile = 0; /* are we changing the renamed file? (we do this
3888 * if we need to update .. on a renamed dir) */
3889 struct client *t_client; /* tmp ptr to client data */
3890 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3891 struct rx_connection *tcon = rx_ConnectionOf(acall);
3897 FidZero(&newfiledir);
3899 /* Get ptr to client data for user Id for logging */
3900 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3901 logHostAddr.s_addr = rxr_HostOf(tcon);
3903 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3904 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3905 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3906 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3908 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3910 if (!FileNameOK(NewName)) {
3914 if (OldDirFid->Volume != NewDirFid->Volume) {
3919 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3920 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3921 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3927 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3929 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3930 &parent, &client, WRITE_LOCK, &rights,
3935 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3937 newrights = rights, newanyrights = anyrights;
3940 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3941 MustBeDIR, &parent, &client, WRITE_LOCK,
3942 &newrights, &newanyrights))) {
3948 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3949 &parent, &client, WRITE_LOCK, &newrights,
3955 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3956 &parent, &client, WRITE_LOCK, &rights,
3963 /* set volume synchronization information */
3964 SetVolumeSync(Sync, volptr);
3966 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3969 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3973 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3974 * call to CopyOnWrite returns error, it is not necessary to revert back
3975 * the effects of the first call because the contents of the volume is
3976 * not modified, it is only replicated.
3978 if (oldvptr->disk.cloned) {
3979 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3980 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3983 SetDirHandle(&olddir, oldvptr);
3984 if (newvptr->disk.cloned) {
3985 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3986 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3990 SetDirHandle(&newdir, newvptr);
3992 /* Lookup the file to delete its vnode */
3993 if (Lookup(&olddir, OldName, &fileFid)) {
3997 if (fileFid.Vnode == oldvptr->vnodeNumber
3998 || fileFid.Vnode == newvptr->vnodeNumber) {
3999 errorCode = FSERR_ELOOP;
4002 fileFid.Volume = V_id(volptr);
4003 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
4004 if (errorCode != 0) {
4006 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
4007 OldName, errorCode));
4008 VTakeOffline(volptr);
4011 if (fileptr->disk.uniquifier != fileFid.Unique) {
4013 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
4015 VTakeOffline(volptr);
4020 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
4021 && fileptr->disk.linkCount != 1) {
4023 * Hard links exist to this file - cannot move one of the links to
4024 * a new directory because of AFS restrictions (this is the same
4025 * reason that links cannot be made across directories, i.e.
4032 /* Lookup the new file */
4033 if (!(Lookup(&newdir, NewName, &newFileFid))) {
4034 if (readonlyServer) {
4035 errorCode = VREADONLY;
4038 if (!(newrights & PRSFS_DELETE)) {
4042 if (newFileFid.Vnode == oldvptr->vnodeNumber
4043 || newFileFid.Vnode == newvptr->vnodeNumber
4044 || newFileFid.Vnode == fileFid.Vnode) {
4048 newFileFid.Volume = V_id(volptr);
4050 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4051 if (errorCode != 0) {
4053 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4054 NewName, errorCode));
4055 VTakeOffline(volptr);
4058 if (fileptr->disk.uniquifier != fileFid.Unique) {
4060 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4062 VTakeOffline(volptr);
4066 SetDirHandle(&newfiledir, newfileptr);
4067 /* Now check that we're moving directories over directories properly, etc.
4068 * return proper POSIX error codes:
4069 * if fileptr is a file and new is a dir: EISDIR.
4070 * if fileptr is a dir and new is a file: ENOTDIR.
4071 * Also, dir to be removed must be empty, of course.
4073 if (newfileptr->disk.type == vDirectory) {
4074 if (fileptr->disk.type != vDirectory) {
4078 if ((IsEmpty(&newfiledir))) {
4083 if (fileptr->disk.type == vDirectory) {
4084 errorCode = ENOTDIR;
4091 * ok - now we check that the old name is not above new name in the
4092 * directory structure. This is to prevent removing a subtree alltogether
4094 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4095 afs_int32 forpass = 0, vnum = 0, top = 0;
4096 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4097 if (testnode > vnum) vnum = testnode;
4098 if (forpass > vnum) {
4099 errorCode = FSERR_ELOOP;
4102 if (testnode == oldvptr->vnodeNumber) {
4103 testnode = oldvptr->disk.parent;
4106 if ((testnode == fileptr->vnodeNumber)
4107 || (testnode == newvptr->vnodeNumber)) {
4108 errorCode = FSERR_ELOOP;
4111 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4112 errorCode = FSERR_ELOOP;
4115 if (testnode == 1) top = 1;
4116 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4117 osi_Assert(errorCode == 0);
4118 testnode = testvptr->disk.parent;
4119 VPutVnode(&errorCode, testvptr);
4120 if ((top == 1) && (testnode != 0)) {
4121 VTakeOffline(volptr);
4123 ("Volume %u now offline, must be salvaged.\n",
4128 osi_Assert(errorCode == 0);
4132 if (fileptr->disk.type == vDirectory) {
4133 SetDirHandle(&filedir, fileptr);
4134 if (oldvptr != newvptr) {
4135 /* we always need to update .. if we've moving fileptr to a
4136 * different directory */
4139 struct AFSFid unused;
4141 code = Lookup(&filedir, "..", &unused);
4142 if (code == ENOENT) {
4143 /* only update .. if it doesn't already exist */
4149 /* Do the CopyonWrite first before modifying anything else. Copying is
4150 * required when we have to change entries for ..
4152 if (updatefile && (fileptr->disk.cloned)) {
4153 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4154 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4158 /* If the new name exists already, delete it and the file it points to */
4161 /* Delete NewName from its directory */
4162 code = Delete(&newdir, NewName);
4163 osi_Assert(code == 0);
4165 /* Drop the link count */
4166 newfileptr->disk.linkCount--;
4167 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4168 afs_fsize_t newSize;
4169 VN_GET_LEN(newSize, newfileptr);
4170 VAdjustDiskUsage((Error *) & errorCode, volptr,
4171 (afs_sfsize_t) - nBlocks(newSize), 0);
4172 if (VN_GET_INO(newfileptr)) {
4173 IH_REALLYCLOSE(newfileptr->handle);
4175 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4176 V_parentId(volptr));
4177 IH_RELEASE(newfileptr->handle);
4178 if (errorCode == -1) {
4180 ("Del: inode=%s, name=%s, errno=%d\n",
4181 PrintInode(stmp, VN_GET_INO(newfileptr)),
4183 if ((errno != ENOENT) && (errno != EIO)
4184 && (errno != ENXIO))
4185 ViceLog(0, ("Do we need to fsck?"));
4188 VN_SET_INO(newfileptr, (Inode) 0);
4189 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4192 /* Link count did not drop to zero.
4193 * Mark NewName vnode as changed - updates stime.
4195 newfileptr->changed_newTime = 1;
4200 * If the create below fails, and the delete above worked, we have
4201 * removed the new name and not replaced it. This is not very likely,
4202 * but possible. We could try to put the old file back, but it is
4203 * highly unlikely that it would work since it would involve issuing
4206 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4209 /* Delete the old name */
4210 osi_Assert(Delete(&olddir, (char *)OldName) == 0);
4212 /* if the directory length changes, reflect it in the statistics */
4213 #if FS_STATS_DETAILED
4214 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4215 oldvptr->disk.linkCount, client->InSameNetwork);
4216 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4217 newvptr->disk.linkCount, client->InSameNetwork);
4219 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4220 oldvptr->disk.linkCount);
4221 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4222 newvptr->disk.linkCount);
4223 #endif /* FS_STATS_DETAILED */
4225 if (oldvptr == newvptr)
4226 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4228 if (fileptr->disk.parent != newvptr->vnodeNumber) {
4229 fileptr->disk.parent = newvptr->vnodeNumber;
4230 fileptr->changed_newTime = 1;
4233 /* if we are dealing with a rename of a directory, and we need to
4234 * update the .. entry of that directory */
4236 osi_Assert(!fileptr->disk.cloned);
4238 fileptr->changed_newTime = 1; /* status change of moved file */
4240 /* fix .. to point to the correct place */
4241 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4242 osi_Assert(Create(&filedir, "..", NewDirFid) == 0);
4243 fileptr->disk.dataVersion++;
4245 /* if the parent directories are different the link counts have to be */
4246 /* changed due to .. in the renamed directory */
4247 if (oldvptr != newvptr) {
4248 oldvptr->disk.linkCount--;
4249 newvptr->disk.linkCount++;
4253 /* set up return status */
4254 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4255 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4256 if (newfileptr && doDelete) {
4257 DeleteFileCallBacks(&newFileFid); /* no other references */
4262 /* convert the write locks to a read locks before breaking callbacks */
4263 VVnodeWriteToRead(&errorCode, newvptr);
4264 osi_Assert(!errorCode || errorCode == VSALVAGE);
4265 if (oldvptr != newvptr) {
4266 VVnodeWriteToRead(&errorCode, oldvptr);
4267 osi_Assert(!errorCode || errorCode == VSALVAGE);
4269 if (newfileptr && !doDelete) {
4270 /* convert the write lock to a read lock before breaking callbacks */
4271 VVnodeWriteToRead(&errorCode, newfileptr);
4272 osi_Assert(!errorCode || errorCode == VSALVAGE);
4275 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4276 BreakCallBack(client->host, NewDirFid, 0);
4277 if (oldvptr != newvptr) {
4278 BreakCallBack(client->host, OldDirFid, 0);
4281 /* if a dir moved, .. changed */
4282 /* we do not give an AFSFetchStatus structure back to the
4283 * originating client, and the file's status has changed, so be
4284 * sure to send a callback break. In theory the client knows
4285 * enough to know that the callback could be broken implicitly,
4286 * but that may not be clear, and some client implementations
4287 * may not know to. */
4288 BreakCallBack(client->host, &fileFid, 1);
4291 /* Note: it is not necessary to break the callback */
4293 DeleteFileCallBacks(&newFileFid); /* no other references */
4295 /* other's still exist (with wrong link count) */
4296 BreakCallBack(client->host, &newFileFid, 1);
4301 VPutVnode(&fileCode, newfileptr);
4302 osi_Assert(fileCode == 0);
4304 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4305 newvptr : 0), oldvptr, volptr, &client);
4309 FidZap(&newfiledir);
4310 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4317 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4318 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4319 struct AFSFetchStatus * OutOldDirStatus,
4320 struct AFSFetchStatus * OutNewDirStatus,
4321 struct AFSVolSync * Sync)
4324 struct rx_connection *tcon;
4326 struct client *t_client = NULL; /* tmp ptr to client data */
4327 #if FS_STATS_DETAILED
4328 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4329 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4330 struct timeval elapsedTime; /* Transfer time */
4333 * Set our stats pointer, remember when the RPC operation started, and
4334 * tally the operation.
4336 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4340 FT_GetTimeOfDay(&opStartTime, 0);
4341 #endif /* FS_STATS_DETAILED */
4343 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4347 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4348 OutOldDirStatus, OutNewDirStatus, Sync);
4351 code = CallPostamble(tcon, code, thost);
4353 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4355 #if FS_STATS_DETAILED
4356 FT_GetTimeOfDay(&opStopTime, 0);
4359 (opP->numSuccesses)++;
4360 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4361 fs_stats_AddTo((opP->sumTime), elapsedTime);
4362 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4363 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4364 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4366 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4367 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4371 #endif /* FS_STATS_DETAILED */
4373 osi_auditU(acall, RenameFileEvent, code,
4374 AUD_ID, t_client ? t_client->ViceId : 0,
4375 AUD_FID, OldDirFid, AUD_STR, OldName,
4376 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4379 } /*SRXAFS_Rename */
4383 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4384 * merged into it when possible.
4387 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4388 char *LinkContents, struct AFSStoreStatus *InStatus,
4389 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4390 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4392 Vnode *parentptr = 0; /* vnode of input Directory */
4393 Vnode *targetptr = 0; /* vnode of the new link */
4394 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4395 Error errorCode = 0; /* error code */
4398 DirHandle dir; /* Handle for dir package I/O */
4399 Volume *volptr = 0; /* pointer to the volume header */
4400 struct client *client = 0; /* pointer to client structure */
4401 afs_int32 rights, anyrights; /* rights for this and any user */
4402 struct client *t_client; /* tmp ptr to client data */
4403 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4405 struct rx_connection *tcon = rx_ConnectionOf(acall);
4409 /* Get ptr to client data for user Id for logging */
4410 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4411 logHostAddr.s_addr = rxr_HostOf(tcon);
4413 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4414 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4415 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4417 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4419 if (!FileNameOK(Name)) {
4425 * Get the vnode and volume for the parent dir along with the caller's
4429 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4430 &parentwhentargetnotdir, &client, WRITE_LOCK,
4431 &rights, &anyrights))) {
4435 /* set volume synchronization information */
4436 SetVolumeSync(Sync, volptr);
4438 /* Does the caller has insert (and write) access to the parent directory? */
4439 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4444 * If we're creating a mount point (any x bits clear), we must have
4445 * administer access to the directory, too. Always allow sysadmins
4448 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4449 if (readonlyServer) {
4450 errorCode = VREADONLY;
4454 * We have a mountpoint, 'cause we're trying to set the Unix mode
4455 * bits to something with some x bits missing (default mode bits
4456 * if AFS_SETMODE is false is 0777)
4458 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4464 /* get a new vnode for the symlink and set it up */
4466 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4467 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4471 /* update the status of the parent vnode */
4472 #if FS_STATS_DETAILED
4473 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4474 parentptr->disk.linkCount,
4475 client->InSameNetwork);
4477 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4478 parentptr->disk.linkCount);
4479 #endif /* FS_STATS_DETAILED */
4481 /* update the status of the new symbolic link file vnode */
4482 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4483 parentptr, volptr, strlen((char *)LinkContents));
4485 /* Write the contents of the symbolic link name into the target inode */
4486 fdP = IH_OPEN(targetptr->handle);
4488 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4490 VTakeOffline(volptr);
4491 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4495 len = strlen((char *) LinkContents);
4496 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4498 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4501 * Set up and return modified status for the parent dir and new symlink
4504 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4505 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4507 /* convert the write lock to a read lock before breaking callbacks */
4508 VVnodeWriteToRead(&errorCode, parentptr);
4509 osi_Assert(!errorCode || errorCode == VSALVAGE);
4511 /* break call back on the parent dir */
4512 BreakCallBack(client->host, DirFid, 0);
4515 /* Write the all modified vnodes (parent, new files) and volume back */
4516 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4519 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4520 return ( errorCode ? errorCode : code );
4522 } /*SAFSS_Symlink */
4526 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4527 struct AFSFid *DirFid, /* Parent dir's fid */
4528 char *Name, /* File name to create */
4529 char *LinkContents, /* Contents of the new created file */
4530 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4531 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4532 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4533 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4534 struct AFSVolSync *Sync)
4537 struct rx_connection *tcon;
4539 struct client *t_client = NULL; /* tmp ptr to client data */
4540 #if FS_STATS_DETAILED
4541 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4542 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4543 struct timeval elapsedTime; /* Transfer time */
4546 * Set our stats pointer, remember when the RPC operation started, and
4547 * tally the operation.
4549 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4553 FT_GetTimeOfDay(&opStartTime, 0);
4554 #endif /* FS_STATS_DETAILED */
4556 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4560 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4561 OutFidStatus, OutDirStatus, Sync);
4564 code = CallPostamble(tcon, code, thost);
4566 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4568 #if FS_STATS_DETAILED
4569 FT_GetTimeOfDay(&opStopTime, 0);
4572 (opP->numSuccesses)++;
4573 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4574 fs_stats_AddTo((opP->sumTime), elapsedTime);
4575 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4576 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4577 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4579 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4580 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4584 #endif /* FS_STATS_DETAILED */
4586 osi_auditU(acall, SymlinkEvent, code,
4587 AUD_ID, t_client ? t_client->ViceId : 0,
4588 AUD_FID, DirFid, AUD_STR, Name,
4589 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4592 } /*SRXAFS_Symlink */
4596 * This routine is called exclusively by SRXAFS_Link(), and should be
4597 * merged into it when possible.
4600 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4601 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4602 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4604 Vnode *parentptr = 0; /* vnode of input Directory */
4605 Vnode *targetptr = 0; /* vnode of the new file */
4606 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4607 Volume *volptr = 0; /* pointer to the volume header */
4608 Error errorCode = 0; /* error code */
4609 DirHandle dir; /* Handle for dir package I/O */
4610 struct client *client = 0; /* pointer to client structure */
4611 afs_int32 rights, anyrights; /* rights for this and any user */
4612 struct client *t_client; /* tmp ptr to client data */
4613 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4614 struct rx_connection *tcon = rx_ConnectionOf(acall);
4618 /* Get ptr to client data for user Id for logging */
4619 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4620 logHostAddr.s_addr = rxr_HostOf(tcon);
4622 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4623 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4624 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4625 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4627 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4629 if (DirFid->Volume != ExistingFid->Volume) {
4633 if (!FileNameOK(Name)) {
4639 * Get the vnode and volume for the parent dir along with the caller's
4643 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4644 &parentwhentargetnotdir, &client, WRITE_LOCK,
4645 &rights, &anyrights))) {
4649 /* set volume synchronization information */
4650 SetVolumeSync(Sync, volptr);
4652 /* Can the caller insert into the parent directory? */
4653 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4657 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4658 /* AFS fileservers always have directory vnodes that are odd. */
4663 /* get the file vnode */
4665 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4668 if (targetptr->disk.type != vFile) {
4672 if (targetptr->disk.parent != DirFid->Vnode) {
4676 if (parentptr->disk.cloned) {
4677 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4678 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4679 goto Bad_Link; /* disk full error */
4682 /* add the name to the directory */
4683 SetDirHandle(&dir, parentptr);
4684 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4688 /* update the status in the parent vnode */
4689 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4690 #if FS_STATS_DETAILED
4691 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4692 parentptr->disk.linkCount,
4693 client->InSameNetwork);
4695 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4696 parentptr->disk.linkCount);
4697 #endif /* FS_STATS_DETAILED */
4699 targetptr->disk.linkCount++;
4700 targetptr->disk.author = client->ViceId;
4701 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4703 /* set up return status */
4704 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4705 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4707 /* convert the write locks to read locks before breaking callbacks */
4708 VVnodeWriteToRead(&errorCode, targetptr);
4709 osi_Assert(!errorCode || errorCode == VSALVAGE);
4710 VVnodeWriteToRead(&errorCode, parentptr);
4711 osi_Assert(!errorCode || errorCode == VSALVAGE);
4713 /* break call back on DirFid */
4714 BreakCallBack(client->host, DirFid, 0);
4716 * We also need to break the callback for the file that is hard-linked since part
4717 * of its status (like linkcount) is changed
4719 BreakCallBack(client->host, ExistingFid, 0);
4722 /* Write the all modified vnodes (parent, new files) and volume back */
4723 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4726 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4733 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4734 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4735 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4738 struct rx_connection *tcon;
4740 struct client *t_client = NULL; /* tmp ptr to client data */
4741 #if FS_STATS_DETAILED
4742 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4743 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4744 struct timeval elapsedTime; /* Transfer time */
4747 * Set our stats pointer, remember when the RPC operation started, and
4748 * tally the operation.
4750 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4754 FT_GetTimeOfDay(&opStartTime, 0);
4755 #endif /* FS_STATS_DETAILED */
4757 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4761 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4762 OutDirStatus, Sync);
4765 code = CallPostamble(tcon, code, thost);
4767 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4769 #if FS_STATS_DETAILED
4770 FT_GetTimeOfDay(&opStopTime, 0);
4773 (opP->numSuccesses)++;
4774 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4775 fs_stats_AddTo((opP->sumTime), elapsedTime);
4776 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4777 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4778 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4780 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4781 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4785 #endif /* FS_STATS_DETAILED */
4787 osi_auditU(acall, LinkEvent, code,
4788 AUD_ID, t_client ? t_client->ViceId : 0,
4789 AUD_FID, DirFid, AUD_STR, Name,
4790 AUD_FID, ExistingFid, AUD_END);
4797 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4798 * merged into it when possible.
4801 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4802 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4803 struct AFSFetchStatus *OutFidStatus,
4804 struct AFSFetchStatus *OutDirStatus,
4805 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4807 Vnode *parentptr = 0; /* vnode of input Directory */
4808 Vnode *targetptr = 0; /* vnode of the new file */
4809 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4810 Volume *volptr = 0; /* pointer to the volume header */
4811 Error errorCode = 0; /* error code */
4812 struct acl_accessList *newACL; /* Access list */
4813 int newACLSize; /* Size of access list */
4814 DirHandle dir; /* Handle for dir package I/O */
4815 DirHandle parentdir; /* Handle for dir package I/O */
4816 struct client *client = 0; /* pointer to client structure */
4817 afs_int32 rights, anyrights; /* rights for this and any user */
4818 struct client *t_client; /* tmp ptr to client data */
4819 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4820 struct rx_connection *tcon = rx_ConnectionOf(acall);
4823 FidZero(&parentdir);
4825 /* Get ptr to client data for user Id for logging */
4826 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4827 logHostAddr.s_addr = rxr_HostOf(tcon);
4829 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4830 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4831 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4833 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4835 if (!FileNameOK(Name)) {
4841 * Get the vnode and volume for the parent dir along with the caller's
4845 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4846 &parentwhentargetnotdir, &client, WRITE_LOCK,
4847 &rights, &anyrights))) {
4851 /* set volume synchronization information */
4852 SetVolumeSync(Sync, volptr);
4854 /* Write access to the parent directory? */
4855 #ifdef DIRCREATE_NEED_WRITE
4857 * requires w access for the user to create a directory. this
4858 * closes a loophole in the current security arrangement, since a
4859 * user with i access only can create a directory and get the
4860 * implcit a access that goes with dir ownership, and proceed to
4861 * subvert quota in the volume.
4863 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4864 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4866 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4867 #endif /* DIRCREATE_NEED_WRITE */
4870 #define EMPTYDIRBLOCKS 2
4871 /* get a new vnode and set it up */
4873 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4874 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4878 /* Update the status for the parent dir */
4879 #if FS_STATS_DETAILED
4880 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4881 parentptr->disk.linkCount + 1,
4882 client->InSameNetwork);
4884 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4885 parentptr->disk.linkCount + 1);
4886 #endif /* FS_STATS_DETAILED */
4888 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4889 osi_Assert((SetAccessList
4890 (&targetptr, &volptr, &newACL, &newACLSize,
4891 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4892 osi_Assert(parentwhentargetnotdir == 0);
4893 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4895 /* update the status for the target vnode */
4896 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4897 parentptr, volptr, 0);
4899 /* Actually create the New directory in the directory package */
4900 SetDirHandle(&dir, targetptr);
4901 osi_Assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4903 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4905 /* set up return status */
4906 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4907 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4909 /* convert the write lock to a read lock before breaking callbacks */
4910 VVnodeWriteToRead(&errorCode, parentptr);
4911 osi_Assert(!errorCode || errorCode == VSALVAGE);
4913 /* break call back on DirFid */
4914 BreakCallBack(client->host, DirFid, 0);
4916 /* Return a callback promise to caller */
4917 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4920 /* Write the all modified vnodes (parent, new files) and volume back */
4921 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4925 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4928 } /*SAFSS_MakeDir */
4932 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4933 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4934 struct AFSFetchStatus * OutFidStatus,
4935 struct AFSFetchStatus * OutDirStatus,
4936 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4939 struct rx_connection *tcon;
4941 struct client *t_client = NULL; /* tmp ptr to client data */
4942 #if FS_STATS_DETAILED
4943 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4944 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4945 struct timeval elapsedTime; /* Transfer time */
4948 * Set our stats pointer, remember when the RPC operation started, and
4949 * tally the operation.
4951 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4955 FT_GetTimeOfDay(&opStartTime, 0);
4956 #endif /* FS_STATS_DETAILED */
4957 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4961 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4962 OutDirStatus, CallBack, Sync);
4965 code = CallPostamble(tcon, code, thost);
4967 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4969 #if FS_STATS_DETAILED
4970 FT_GetTimeOfDay(&opStopTime, 0);
4973 (opP->numSuccesses)++;
4974 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4975 fs_stats_AddTo((opP->sumTime), elapsedTime);
4976 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4977 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4978 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4980 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4981 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4985 #endif /* FS_STATS_DETAILED */
4987 osi_auditU(acall, MakeDirEvent, code,
4988 AUD_ID, t_client ? t_client->ViceId : 0,
4989 AUD_FID, DirFid, AUD_STR, Name,
4990 AUD_FID, OutFid, AUD_END);
4993 } /*SRXAFS_MakeDir */
4997 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4998 * merged into it when possible.
5001 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
5002 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
5004 Vnode *parentptr = 0; /* vnode of input Directory */
5005 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5006 Vnode *targetptr = 0; /* file to be deleted */
5007 AFSFid fileFid; /* area for Fid from the directory */
5008 Error errorCode = 0; /* error code */
5009 DirHandle dir; /* Handle for dir package I/O */
5010 Volume *volptr = 0; /* pointer to the volume header */
5011 struct client *client = 0; /* pointer to client structure */
5012 afs_int32 rights, anyrights; /* rights for this and any user */
5013 struct client *t_client; /* tmp ptr to client data */
5014 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5015 struct rx_connection *tcon = rx_ConnectionOf(acall);
5019 /* Get ptr to client data for user Id for logging */
5020 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5021 logHostAddr.s_addr = rxr_HostOf(tcon);
5023 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
5024 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
5025 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5027 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
5030 * Get the vnode and volume for the parent dir along with the caller's
5034 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
5035 &parentwhentargetnotdir, &client, WRITE_LOCK,
5036 &rights, &anyrights))) {
5040 /* set volume synchronization information */
5041 SetVolumeSync(Sync, volptr);
5043 /* Does the caller has delete (&write) access to the parent dir? */
5044 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
5048 /* Do the actual delete of the desired (empty) directory, Name */
5050 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
5055 /* Update the status for the parent dir; link count is also adjusted */
5056 #if FS_STATS_DETAILED
5057 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5058 parentptr->disk.linkCount - 1,
5059 client->InSameNetwork);
5061 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5062 parentptr->disk.linkCount - 1);
5063 #endif /* FS_STATS_DETAILED */
5065 /* Return to the caller the updated parent dir status */
5066 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
5069 * Note: it is not necessary to break the callback on fileFid, since
5070 * refcount is now 0, so no one should be able to refer to the dir
5073 DeleteFileCallBacks(&fileFid);
5075 /* convert the write lock to a read lock before breaking callbacks */
5076 VVnodeWriteToRead(&errorCode, parentptr);
5077 osi_Assert(!errorCode || errorCode == VSALVAGE);
5079 /* break call back on DirFid and fileFid */
5080 BreakCallBack(client->host, DirFid, 0);
5083 /* Write the all modified vnodes (parent, new files) and volume back */
5084 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5087 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5090 } /*SAFSS_RemoveDir */
5094 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5095 struct AFSFetchStatus * OutDirStatus,
5096 struct AFSVolSync * Sync)
5099 struct rx_connection *tcon;
5101 struct client *t_client = NULL; /* tmp ptr to client data */
5102 #if FS_STATS_DETAILED
5103 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5104 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5105 struct timeval elapsedTime; /* Transfer time */
5108 * Set our stats pointer, remember when the RPC operation started, and
5109 * tally the operation.
5111 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5115 FT_GetTimeOfDay(&opStartTime, 0);
5116 #endif /* FS_STATS_DETAILED */
5118 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5121 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5124 code = CallPostamble(tcon, code, thost);
5126 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5128 #if FS_STATS_DETAILED
5129 FT_GetTimeOfDay(&opStopTime, 0);
5132 (opP->numSuccesses)++;
5133 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5134 fs_stats_AddTo((opP->sumTime), elapsedTime);
5135 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5136 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5137 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5139 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5140 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5144 #endif /* FS_STATS_DETAILED */
5146 osi_auditU(acall, RemoveDirEvent, code,
5147 AUD_ID, t_client ? t_client->ViceId : 0,
5148 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5151 } /*SRXAFS_RemoveDir */
5155 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5156 * merged into it when possible.
5159 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5160 struct AFSVolSync *Sync)
5162 Vnode *targetptr = 0; /* vnode of input file */
5163 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5164 Error errorCode = 0; /* error code */
5165 Volume *volptr = 0; /* pointer to the volume header */
5166 struct client *client = 0; /* pointer to client structure */
5167 afs_int32 rights, anyrights; /* rights for this and any user */
5168 struct client *t_client; /* tmp ptr to client data */
5169 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5170 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5171 struct rx_connection *tcon = rx_ConnectionOf(acall);
5173 if (type != LockRead && type != LockWrite) {
5177 /* Get ptr to client data for user Id for logging */
5178 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5179 logHostAddr.s_addr = rxr_HostOf(tcon);
5181 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5182 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5183 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5185 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5188 * Get the vnode and volume for the desired file along with the caller's
5192 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5193 &parentwhentargetnotdir, &client, WRITE_LOCK,
5194 &rights, &anyrights))) {
5198 /* set volume synchronization information */
5199 SetVolumeSync(Sync, volptr);
5201 /* Handle the particular type of set locking, type */
5202 errorCode = HandleLocking(targetptr, client, rights, type);
5205 /* Write the all modified vnodes (parent, new files) and volume back */
5206 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5209 if ((errorCode == VREADONLY) && (type == LockRead))
5210 errorCode = 0; /* allow read locks on RO volumes without saving state */
5212 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5215 } /*SAFSS_SetLock */
5219 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5220 ViceLockType type, struct AFSVolSync * Sync)
5222 return SRXAFS_SetLock(acall, Fid, type, Sync);
5223 } /*SRXAFS_OldSetLock */
5227 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5228 struct AFSVolSync * Sync)
5231 struct rx_connection *tcon;
5233 struct client *t_client = NULL; /* tmp ptr to client data */
5234 #if FS_STATS_DETAILED
5235 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5236 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5237 struct timeval elapsedTime; /* Transfer time */
5240 * Set our stats pointer, remember when the RPC operation started, and
5241 * tally the operation.
5243 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5247 FT_GetTimeOfDay(&opStartTime, 0);
5248 #endif /* FS_STATS_DETAILED */
5250 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5253 code = SAFSS_SetLock(acall, Fid, type, Sync);
5256 code = CallPostamble(tcon, code, thost);
5258 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5260 #if FS_STATS_DETAILED
5261 FT_GetTimeOfDay(&opStopTime, 0);
5264 (opP->numSuccesses)++;
5265 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5266 fs_stats_AddTo((opP->sumTime), elapsedTime);
5267 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5268 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5269 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5271 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5272 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5276 #endif /* FS_STATS_DETAILED */
5278 osi_auditU(acall, SetLockEvent, code,
5279 AUD_ID, t_client ? t_client->ViceId : 0,
5280 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5282 } /*SRXAFS_SetLock */
5286 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5287 * merged into it when possible.
5290 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5291 struct AFSVolSync *Sync)
5293 Vnode *targetptr = 0; /* vnode of input file */
5294 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5295 Error errorCode = 0; /* error code */
5296 Volume *volptr = 0; /* pointer to the volume header */
5297 struct client *client = 0; /* pointer to client structure */
5298 afs_int32 rights, anyrights; /* rights for this and any user */
5299 struct client *t_client; /* tmp ptr to client data */
5300 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5301 struct rx_connection *tcon = rx_ConnectionOf(acall);
5303 /* Get ptr to client data for user Id for logging */
5304 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5305 logHostAddr.s_addr = rxr_HostOf(tcon);
5307 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5308 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5309 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5311 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5314 * Get the vnode and volume for the desired file along with the caller's
5318 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5319 &parentwhentargetnotdir, &client, WRITE_LOCK,
5320 &rights, &anyrights))) {
5321 goto Bad_ExtendLock;
5324 /* set volume synchronization information */
5325 SetVolumeSync(Sync, volptr);
5327 /* Handle the actual lock extension */
5328 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5331 /* Put back file's vnode and volume */
5332 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5335 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5336 errorCode = 0; /* under our generous policy re RO vols */
5338 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5341 } /*SAFSS_ExtendLock */
5345 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5346 struct AFSVolSync * Sync)
5348 return SRXAFS_ExtendLock(acall, Fid, Sync);
5349 } /*SRXAFS_OldExtendLock */
5353 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5354 struct AFSVolSync * Sync)
5357 struct rx_connection *tcon;
5359 struct client *t_client = NULL; /* tmp ptr to client data */
5360 #if FS_STATS_DETAILED
5361 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5362 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5363 struct timeval elapsedTime; /* Transfer time */
5366 * Set our stats pointer, remember when the RPC operation started, and
5367 * tally the operation.
5369 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5373 FT_GetTimeOfDay(&opStartTime, 0);
5374 #endif /* FS_STATS_DETAILED */
5376 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5377 goto Bad_ExtendLock;
5379 code = SAFSS_ExtendLock(acall, Fid, Sync);
5382 code = CallPostamble(tcon, code, thost);
5384 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5386 #if FS_STATS_DETAILED
5387 FT_GetTimeOfDay(&opStopTime, 0);
5390 (opP->numSuccesses)++;
5391 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5392 fs_stats_AddTo((opP->sumTime), elapsedTime);
5393 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5394 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5395 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5397 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5398 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5402 #endif /* FS_STATS_DETAILED */
5404 osi_auditU(acall, ExtendLockEvent, code,
5405 AUD_ID, t_client ? t_client->ViceId : 0,
5406 AUD_FID, Fid, AUD_END);
5409 } /*SRXAFS_ExtendLock */
5413 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5414 * merged into it when possible.
5417 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5418 struct AFSVolSync *Sync)
5420 Vnode *targetptr = 0; /* vnode of input file */
5421 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5422 Error errorCode = 0; /* error code */
5423 Volume *volptr = 0; /* pointer to the volume header */
5424 struct client *client = 0; /* pointer to client structure */
5425 afs_int32 rights, anyrights; /* rights for this and any user */
5426 struct client *t_client; /* tmp ptr to client data */
5427 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5428 struct rx_connection *tcon = rx_ConnectionOf(acall);
5430 /* Get ptr to client data for user Id for logging */
5431 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5432 logHostAddr.s_addr = rxr_HostOf(tcon);
5434 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5435 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5436 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5438 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5441 * Get the vnode and volume for the desired file along with the caller's
5445 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5446 &parentwhentargetnotdir, &client, WRITE_LOCK,
5447 &rights, &anyrights))) {
5448 goto Bad_ReleaseLock;
5451 /* set volume synchronization information */
5452 SetVolumeSync(Sync, volptr);
5454 /* Handle the actual lock release */
5455 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5456 goto Bad_ReleaseLock;
5458 /* if no more locks left, a callback would be triggered here */
5459 if (targetptr->disk.lock.lockCount <= 0) {
5460 /* convert the write lock to a read lock before breaking callbacks */
5461 VVnodeWriteToRead(&errorCode, targetptr);
5462 osi_Assert(!errorCode || errorCode == VSALVAGE);
5463 BreakCallBack(client->host, Fid, 0);
5467 /* Put back file's vnode and volume */
5468 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5471 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5472 errorCode = 0; /* under our generous policy re RO vols */
5474 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5477 } /*SAFSS_ReleaseLock */
5481 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5482 struct AFSVolSync * Sync)
5484 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5485 } /*SRXAFS_OldReleaseLock */
5489 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5490 struct AFSVolSync * Sync)
5493 struct rx_connection *tcon;
5495 struct client *t_client = NULL; /* tmp ptr to client data */
5496 #if FS_STATS_DETAILED
5497 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5498 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5499 struct timeval elapsedTime; /* Transfer time */
5502 * Set our stats pointer, remember when the RPC operation started, and
5503 * tally the operation.
5505 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5509 FT_GetTimeOfDay(&opStartTime, 0);
5510 #endif /* FS_STATS_DETAILED */
5512 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5513 goto Bad_ReleaseLock;
5515 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5518 code = CallPostamble(tcon, code, thost);
5520 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5522 #if FS_STATS_DETAILED
5523 FT_GetTimeOfDay(&opStopTime, 0);
5526 (opP->numSuccesses)++;
5527 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5528 fs_stats_AddTo((opP->sumTime), elapsedTime);
5529 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5530 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5531 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5533 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5534 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5538 #endif /* FS_STATS_DETAILED */
5540 osi_auditU(acall, ReleaseLockEvent, code,
5541 AUD_ID, t_client ? t_client->ViceId : 0,
5542 AUD_FID, Fid, AUD_END);
5545 } /*SRXAFS_ReleaseLock */
5549 SetSystemStats(struct AFSStatistics *stats)
5551 /* Fix this sometime soon.. */
5552 /* Because hey, it's not like we have a network monitoring protocol... */
5553 struct timeval time;
5555 /* this works on all system types */
5556 FT_GetTimeOfDay(&time, 0);
5557 stats->CurrentTime = time.tv_sec;
5558 } /*SetSystemStats */
5561 SetAFSStats(struct AFSStatistics *stats)
5563 extern afs_int32 StartTime, CurrentConnections;
5567 stats->CurrentMsgNumber = 0;
5568 stats->OldestMsgNumber = 0;
5569 stats->StartTime = StartTime;
5570 stats->CurrentConnections = CurrentConnections;
5571 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5572 stats->TotalFetchs =
5573 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5574 AFSCallStats.FetchStatus;
5575 stats->FetchDatas = AFSCallStats.FetchData;
5576 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5577 seconds = AFSCallStats.AccumFetchTime / 1000;
5580 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5581 stats->TotalStores =
5582 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5583 AFSCallStats.StoreStatus;
5584 stats->StoreDatas = AFSCallStats.StoreData;
5585 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5586 seconds = AFSCallStats.AccumStoreTime / 1000;
5589 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5591 stats->ProcessSize = -1; /* TODO: */
5593 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5596 h_GetWorkStats((int *)&(stats->WorkStations),
5597 (int *)&(stats->ActiveWorkStations), (int *)0,
5598 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5602 /* Get disk related information from all AFS partitions. */
5605 SetVolumeStats(struct AFSStatistics *stats)
5607 struct DiskPartition64 *part;
5610 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5611 part = part->next) {
5612 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5613 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5614 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5615 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5618 while (i < AFS_MSTATDISKS) {
5619 stats->Disks[i].TotalBlocks = -1;
5622 } /*SetVolumeStats */
5625 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5628 struct rx_connection *tcon = rx_ConnectionOf(acall);
5630 struct client *t_client = NULL; /* tmp ptr to client data */
5631 #if FS_STATS_DETAILED
5632 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5633 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5634 struct timeval elapsedTime; /* Transfer time */
5637 * Set our stats pointer, remember when the RPC operation started, and
5638 * tally the operation.
5640 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5644 FT_GetTimeOfDay(&opStartTime, 0);
5645 #endif /* FS_STATS_DETAILED */
5647 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5648 goto Bad_GetStatistics;
5650 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5652 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5654 memset(Statistics, 0, sizeof(*Statistics));
5655 SetAFSStats((struct AFSStatistics *)Statistics);
5656 SetVolumeStats((struct AFSStatistics *)Statistics);
5657 SetSystemStats((struct AFSStatistics *)Statistics);
5660 code = CallPostamble(tcon, code, thost);
5662 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5664 #if FS_STATS_DETAILED
5665 FT_GetTimeOfDay(&opStopTime, 0);
5668 (opP->numSuccesses)++;
5669 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5670 fs_stats_AddTo((opP->sumTime), elapsedTime);
5671 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5672 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5673 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5675 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5676 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5680 #endif /* FS_STATS_DETAILED */
5682 osi_auditU(acall, GetStatisticsEvent, code,
5683 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5685 } /*SRXAFS_GetStatistics */
5689 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5691 extern afs_int32 StartTime, CurrentConnections;
5694 struct rx_connection *tcon = rx_ConnectionOf(acall);
5696 struct client *t_client = NULL; /* tmp ptr to client data */
5697 struct timeval time;
5698 #if FS_STATS_DETAILED
5699 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5700 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5701 struct timeval elapsedTime; /* Transfer time */
5704 * Set our stats pointer, remember when the RPC operation started, and
5705 * tally the operation.
5707 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5711 FT_GetTimeOfDay(&opStartTime, 0);
5712 #endif /* FS_STATS_DETAILED */
5714 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5715 goto Bad_GetStatistics64;
5717 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5718 Statistics->ViceStatistics64_val =
5719 malloc(statsVersion*sizeof(afs_int64));
5720 Statistics->ViceStatistics64_len = statsVersion;
5722 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5723 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5724 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5726 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5727 AFSCallStats.TotalCalls;
5728 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5729 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5730 AFSCallStats.FetchStatus;
5731 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5732 AFSCallStats.FetchData;
5733 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5734 AFSCallStats.TotalFetchedBytes;
5735 seconds = AFSCallStats.AccumFetchTime / 1000;
5738 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5739 AFSCallStats.TotalFetchedBytes / seconds;
5740 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5741 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5742 AFSCallStats.StoreStatus;
5743 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5744 AFSCallStats.StoreData;
5745 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5746 AFSCallStats.TotalStoredBytes;
5747 seconds = AFSCallStats.AccumStoreTime / 1000;
5750 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5751 AFSCallStats.TotalStoredBytes / seconds;
5753 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5755 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5756 (afs_int32) ((long)sbrk(0) >> 10);
5759 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5760 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5762 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5766 /* this works on all system types */
5767 FT_GetTimeOfDay(&time, 0);
5768 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5770 Bad_GetStatistics64:
5771 code = CallPostamble(tcon, code, thost);
5773 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5775 #if FS_STATS_DETAILED
5776 FT_GetTimeOfDay(&opStopTime, 0);
5779 (opP->numSuccesses)++;
5780 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5781 fs_stats_AddTo((opP->sumTime), elapsedTime);
5782 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5783 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5784 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5786 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5787 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5791 #endif /* FS_STATS_DETAILED */
5793 osi_auditU(acall, GetStatisticsEvent, code,
5794 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5796 } /*SRXAFS_GetStatistics */
5799 /*------------------------------------------------------------------------
5800 * EXPORTED SRXAFS_XStatsVersion
5803 * Routine called by the server-side RPC interface to implement
5804 * pulling out the xstat version number for the File Server.
5807 * a_versionP : Ptr to the version number variable to set.
5813 * Nothing interesting.
5817 *------------------------------------------------------------------------*/
5820 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5821 { /*SRXAFS_XStatsVersion */
5823 struct client *t_client = NULL; /* tmp ptr to client data */
5824 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5825 #if FS_STATS_DETAILED
5826 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5827 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5828 struct timeval elapsedTime; /* Transfer time */
5831 * Set our stats pointer, remember when the RPC operation started, and
5832 * tally the operation.
5834 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5838 FT_GetTimeOfDay(&opStartTime, 0);
5839 #endif /* FS_STATS_DETAILED */
5841 *a_versionP = AFS_XSTAT_VERSION;
5843 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5845 #if FS_STATS_DETAILED
5846 FT_GetTimeOfDay(&opStopTime, 0);
5847 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5848 fs_stats_AddTo((opP->sumTime), elapsedTime);
5849 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5850 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5851 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5853 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5854 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5857 (opP->numSuccesses)++;
5859 #endif /* FS_STATS_DETAILED */
5861 osi_auditU(a_call, XStatsVersionEvent, 0,
5862 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5864 } /*SRXAFS_XStatsVersion */
5867 /*------------------------------------------------------------------------
5868 * PRIVATE FillPerfValues
5871 * Routine called to fill a regular performance data structure.
5874 * a_perfP : Ptr to perf structure to fill
5880 * Various collections need this info, so the guts were put in
5881 * this separate routine.
5885 *------------------------------------------------------------------------*/
5888 FillPerfValues(struct afs_PerfStats *a_perfP)
5889 { /*FillPerfValues */
5891 int dir_Buffers; /*# buffers in use by dir package */
5892 int dir_Calls; /*# read calls in dir package */
5893 int dir_IOs; /*# I/O ops in dir package */
5894 struct rx_statistics *stats;
5897 * Vnode cache section.
5899 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5900 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5901 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5902 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5903 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5904 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5905 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5906 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5907 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5908 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5909 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5910 SplitInt64(VStats.hdr_gets, hi, lo);
5911 a_perfP->vcache_H_Gets = lo;
5912 SplitInt64(VStats.hdr_loads, hi, lo);
5913 a_perfP->vcache_H_Replacements = lo;
5916 * Directory section.
5918 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5919 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5920 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5921 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5926 stats = rx_GetStatistics();
5928 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5929 a_perfP->rx_noPackets_RcvClass =
5930 (afs_int32) stats->receivePktAllocFailures;
5931 a_perfP->rx_noPackets_SendClass =
5932 (afs_int32) stats->sendPktAllocFailures;
5933 a_perfP->rx_noPackets_SpecialClass =
5934 (afs_int32) stats->specialPktAllocFailures;
5935 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5936 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5937 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5938 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5939 a_perfP->rx_noPacketBuffersOnRead =
5940 (afs_int32) stats->noPacketBuffersOnRead;
5941 a_perfP->rx_selects = (afs_int32) stats->selects;
5942 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5943 a_perfP->rx_packetsRead_RcvClass =
5944 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5945 a_perfP->rx_packetsRead_SendClass =
5946 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5947 a_perfP->rx_packetsRead_SpecialClass =
5948 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5949 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5950 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5951 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5952 a_perfP->rx_spuriousPacketsRead =
5953 (afs_int32) stats->spuriousPacketsRead;
5954 a_perfP->rx_packetsSent_RcvClass =
5955 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5956 a_perfP->rx_packetsSent_SendClass =
5957 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5958 a_perfP->rx_packetsSent_SpecialClass =
5959 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5960 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5961 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5962 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
5963 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
5964 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
5965 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
5966 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
5967 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
5968 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
5969 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
5970 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
5971 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
5972 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
5973 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
5974 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
5975 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
5976 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
5977 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
5978 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
5979 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
5981 a_perfP->host_NumHostEntries = HTs;
5982 a_perfP->host_HostBlocks = HTBlocks;
5983 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5984 &(a_perfP->host_HostsInSameNetOrSubnet),
5985 &(a_perfP->host_HostsInDiffSubnet),
5986 &(a_perfP->host_HostsInDiffNetwork));
5987 a_perfP->host_NumClients = CEs;
5988 a_perfP->host_ClientBlocks = CEBlocks;
5990 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5991 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
5992 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5993 rx_FreeStatistics(&stats);
5994 } /*FillPerfValues */
5997 /*------------------------------------------------------------------------
5998 * EXPORTED SRXAFS_GetXStats
6001 * Routine called by the server-side callback RPC interface to
6002 * implement getting the given data collection from the extended
6003 * File Server statistics.
6006 * a_call : Ptr to Rx call on which this request came in.
6007 * a_clientVersionNum : Client version number.
6008 * a_opCode : Desired operation.
6009 * a_serverVersionNumP : Ptr to version number to set.
6010 * a_timeP : Ptr to time value (seconds) to set.
6011 * a_dataP : Ptr to variable array structure to return
6018 * Nothing interesting.
6022 *------------------------------------------------------------------------*/
6025 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
6026 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
6027 afs_int32 * a_timeP, AFS_CollData * a_dataP)
6028 { /*SRXAFS_GetXStats */
6030 int code; /*Return value */
6031 afs_int32 *dataBuffP; /*Ptr to data to be returned */
6032 afs_int32 dataBytes; /*Bytes in data buffer */
6033 #if FS_STATS_DETAILED
6034 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6035 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6036 struct timeval elapsedTime; /* Transfer time */
6039 * Set our stats pointer, remember when the RPC operation started, and
6040 * tally the operation.
6042 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
6046 FT_GetTimeOfDay(&opStartTime, 0);
6047 #endif /* FS_STATS_DETAILED */
6050 * Record the time of day and the server version number.
6052 *a_srvVersionNumP = AFS_XSTAT_VERSION;
6053 *a_timeP = FT_ApproxTime();
6056 * Stuff the appropriate data in there (assume victory)
6061 ("Received GetXStats call for collection %d\n",
6062 a_collectionNumber));
6066 * We're not keeping stats, so just return successfully with
6069 a_dataP->AFS_CollData_len = 0;
6070 a_dataP->AFS_CollData_val = NULL;
6073 switch (a_collectionNumber) {
6074 case AFS_XSTATSCOLL_CALL_INFO:
6076 * Pass back all the call-count-related data.
6078 * >>> We are forced to allocate a separate area in which to
6079 * >>> put this stuff in by the RPC stub generator, since it
6080 * >>> will be freed at the tail end of the server stub code.
6084 * I don't think call-level stats are being collected yet
6085 * for the File Server.
6087 dataBytes = sizeof(struct afs_Stats);
6088 dataBuffP = (afs_int32 *) malloc(dataBytes);
6089 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6090 a_dataP->AFS_CollData_len = dataBytes >> 2;
6091 a_dataP->AFS_CollData_val = dataBuffP;
6093 a_dataP->AFS_CollData_len = 0;
6094 a_dataP->AFS_CollData_val = NULL;
6098 case AFS_XSTATSCOLL_PERF_INFO:
6100 * Pass back all the regular performance-related data.
6102 * >>> We are forced to allocate a separate area in which to
6103 * >>> put this stuff in by the RPC stub generator, since it
6104 * >>> will be freed at the tail end of the server stub code.
6107 afs_perfstats.numPerfCalls++;
6108 FillPerfValues(&afs_perfstats);
6111 * Don't overwrite the spares at the end.
6114 dataBytes = sizeof(struct afs_PerfStats);
6115 dataBuffP = (afs_int32 *) malloc(dataBytes);
6116 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6117 a_dataP->AFS_CollData_len = dataBytes >> 2;
6118 a_dataP->AFS_CollData_val = dataBuffP;
6121 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6123 * Pass back the full collection of performance-related data.
6124 * We have to stuff the basic, overall numbers in, but the
6125 * detailed numbers are kept in the structure already.
6127 * >>> We are forced to allocate a separate area in which to
6128 * >>> put this stuff in by the RPC stub generator, since it
6129 * >>> will be freed at the tail end of the server stub code.
6132 afs_perfstats.numPerfCalls++;
6133 #if FS_STATS_DETAILED
6134 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6135 FillPerfValues(&afs_FullPerfStats.overall);
6138 * Don't overwrite the spares at the end.
6141 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6142 dataBuffP = (afs_int32 *) malloc(dataBytes);
6143 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6144 a_dataP->AFS_CollData_len = dataBytes >> 2;
6145 a_dataP->AFS_CollData_val = dataBuffP;
6149 case AFS_XSTATSCOLL_CBSTATS:
6150 afs_perfstats.numPerfCalls++;
6152 dataBytes = sizeof(struct cbcounters);
6153 dataBuffP = (afs_int32 *) malloc(dataBytes);
6155 extern struct cbcounters cbstuff;
6156 dataBuffP[0]=cbstuff.DeleteFiles;
6157 dataBuffP[1]=cbstuff.DeleteCallBacks;
6158 dataBuffP[2]=cbstuff.BreakCallBacks;
6159 dataBuffP[3]=cbstuff.AddCallBacks;
6160 dataBuffP[4]=cbstuff.GotSomeSpaces;
6161 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6162 dataBuffP[6]=cbstuff.nFEs;
6163 dataBuffP[7]=cbstuff.nCBs;
6164 dataBuffP[8]=cbstuff.nblks;
6165 dataBuffP[9]=cbstuff.CBsTimedOut;
6166 dataBuffP[10]=cbstuff.nbreakers;
6167 dataBuffP[11]=cbstuff.GSS1;
6168 dataBuffP[12]=cbstuff.GSS2;
6169 dataBuffP[13]=cbstuff.GSS3;
6170 dataBuffP[14]=cbstuff.GSS4;
6171 dataBuffP[15]=cbstuff.GSS5;
6174 a_dataP->AFS_CollData_len = dataBytes >> 2;
6175 a_dataP->AFS_CollData_val = dataBuffP;
6181 * Illegal collection number.
6183 a_dataP->AFS_CollData_len = 0;
6184 a_dataP->AFS_CollData_val = NULL;
6186 } /*Switch on collection number */
6188 #if FS_STATS_DETAILED
6189 FT_GetTimeOfDay(&opStopTime, 0);
6192 (opP->numSuccesses)++;
6193 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6194 fs_stats_AddTo((opP->sumTime), elapsedTime);
6195 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6196 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6197 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6199 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6200 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6204 #endif /* FS_STATS_DETAILED */
6208 } /*SRXAFS_GetXStats */
6212 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6213 struct AFSCBs *CallBackArray)
6215 afs_int32 errorCode = 0;
6217 struct client *client = 0;
6218 struct rx_connection *tcon;
6220 #if FS_STATS_DETAILED
6221 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6222 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6223 struct timeval elapsedTime; /* Transfer time */
6226 * Set our stats pointer, remember when the RPC operation started, and
6227 * tally the operation.
6230 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6234 FT_GetTimeOfDay(&opStartTime, 0);
6235 #endif /* FS_STATS_DETAILED */
6239 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6240 FidArray->AFSCBFids_len));
6243 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6245 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6246 goto Bad_GiveUpCallBacks;
6248 if (!FidArray && !CallBackArray) {
6250 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6251 (tcon->peer ? tcon->peer->host : 0)));
6252 errorCode = GetClient(tcon, &client);
6255 DeleteAllCallBacks_r(client->host, 1);
6260 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6262 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6263 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6264 (tcon->peer ? tcon->peer->host : 0)));
6266 goto Bad_GiveUpCallBacks;
6269 errorCode = GetClient(tcon, &client);
6271 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6272 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6273 DeleteCallBack(client->host, fid);
6279 Bad_GiveUpCallBacks:
6280 errorCode = CallPostamble(tcon, errorCode, thost);
6282 #if FS_STATS_DETAILED
6283 FT_GetTimeOfDay(&opStopTime, 0);
6284 if (errorCode == 0) {
6286 (opP->numSuccesses)++;
6287 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6288 fs_stats_AddTo((opP->sumTime), elapsedTime);
6289 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6290 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6291 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6293 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6294 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6298 #endif /* FS_STATS_DETAILED */
6301 } /*common_GiveUpCallBacks */
6305 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6306 struct AFSCBs * CallBackArray)
6308 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6309 } /*SRXAFS_GiveUpCallBacks */
6312 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6314 return common_GiveUpCallBacks(acall, 0, 0);
6315 } /*SRXAFS_GiveUpAllCallBacks */
6319 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6320 struct AFSVolumeInfo * avolinfo)
6322 return (VNOVOL); /* XXX Obsolete routine XXX */
6324 } /*SRXAFS_NGetVolumeInfo */
6328 * Dummy routine. Should never be called (the cache manager should only
6329 * invoke this interface when communicating with a AFS/DFS Protocol
6333 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6334 char *afs_name_p, struct AFSFid * afs_fid_p,
6335 struct AFSFetchStatus * afs_status_p,
6336 struct AFSFetchStatus * afs_dir_status_p,
6337 struct AFSCallBack * afs_callback_p,
6338 struct AFSVolSync * afs_sync_p)
6345 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6348 struct rx_connection *tcon;
6350 afs_uint32 *dataBuffP;
6351 afs_int32 dataBytes;
6354 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6355 afs_FullPerfStats.overall.fs_nGetCaps++;
6357 ViceLog(2, ("SAFS_GetCapabilties\n"));
6359 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6362 dataBytes = 1 * sizeof(afs_int32);
6363 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6364 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6365 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6367 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6369 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6370 capabilities->Capabilities_val = dataBuffP;
6373 code = CallPostamble(tcon, code, thost);
6380 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6381 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6385 afs_int32 nids, naddrs;
6386 afs_int32 *vd, *addr;
6387 Error errorCode = 0; /* return code to caller */
6388 struct client *client = 0;
6390 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6392 AFSCallStats.TotalCalls++;
6394 nids = vids->ViceIds_len; /* # of users in here */
6395 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6396 if (nids < 0 || naddrs < 0) {
6401 vd = vids->ViceIds_val;
6402 for (i = 0; i < nids; i++, vd++) {
6405 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6409 client->prfail = 2; /* Means re-eval client's cps */
6412 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6415 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6416 free(client->CPS.prlist_val);
6417 client->CPS.prlist_val = NULL;
6418 client->CPS.prlist_len = 0;
6420 ReleaseWriteLock(&client->lock);
6424 addr = addrs->IPAddrs_val;
6425 for (i = 0; i < naddrs; i++, addr++) {
6427 h_flushhostcps(*addr, htons(7001));
6431 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6433 } /*SRXAFS_FlushCPS */
6435 /* worthless hack to let CS keep running ancient software */
6437 afs_vtoi(char *aname)
6443 while ((tc = *aname++)) {
6444 if (tc > '9' || tc < '0')
6445 return 0; /* invalid name */
6453 * may get name or #, but must handle all weird cases (recognize readonly
6454 * or backup volumes by name or #
6457 CopyVolumeEntry(char *aname, struct vldbentry *ave,
6458 struct VolumeInfo *av)
6461 afs_int32 mask, whichType;
6462 afs_uint32 *serverHost, *typePtr;
6464 /* figure out what type we want if by name */
6466 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6467 whichType = BACKVOL;
6468 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6473 vol = afs_vtoi(aname);
6475 vol = ave->volumeId[whichType];
6478 * Now vol has volume # we're interested in. Next, figure out the type
6479 * of the volume by looking finding it in the vldb entry
6481 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6484 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6487 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6488 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6489 whichType = BACKVOL;
6491 return EINVAL; /* error: can't find volume in vldb entry */
6493 typePtr = &av->Type0;
6494 serverHost = &av->Server0;
6496 av->Type = whichType;
6497 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6498 if (ave->flags & VLF_RWEXISTS)
6499 typePtr[RWVOL] = ave->volumeId[RWVOL];
6500 if (ave->flags & VLF_ROEXISTS)
6501 typePtr[ROVOL] = ave->volumeId[ROVOL];
6502 if (ave->flags & VLF_BACKEXISTS)
6503 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6505 for (i = 0, j = 0; i < ave->nServers; i++) {
6506 if ((ave->serverFlags[i] & mask) == 0)
6507 continue; /* wrong volume */
6508 serverHost[j] = ave->serverNumber[i];
6511 av->ServerCount = j;
6513 serverHost[j++] = 0; /* bogus 8, but compat only now */
6518 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6520 static struct rx_connection *vlConn = 0;
6521 static int down = 0;
6522 static afs_int32 lastDownTime = 0;
6523 struct vldbentry tve;
6524 struct rx_securityClass *vlSec;
6528 vlSec = rxnull_NewClientSecurityObject();
6530 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6531 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6533 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6534 return 1; /* failure */
6537 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6539 down = 0; /* call worked */
6542 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6548 /* otherwise convert to old format vldb entry */
6549 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6559 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6560 struct VolumeInfo * avolinfo)
6563 struct rx_connection *tcon;
6565 #if FS_STATS_DETAILED
6566 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6567 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6568 struct timeval elapsedTime; /* Transfer time */
6571 * Set our stats pointer, remember when the RPC operation started, and
6572 * tally the operation.
6574 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6578 FT_GetTimeOfDay(&opStartTime, 0);
6579 #endif /* FS_STATS_DETAILED */
6580 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6581 goto Bad_GetVolumeInfo;
6584 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6586 code = TryLocalVLServer(avolid, avolinfo);
6588 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6589 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6590 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6591 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6594 code = CallPostamble(tcon, code, thost);
6596 #if FS_STATS_DETAILED
6597 FT_GetTimeOfDay(&opStopTime, 0);
6600 (opP->numSuccesses)++;
6601 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6602 fs_stats_AddTo((opP->sumTime), elapsedTime);
6603 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6604 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6605 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6607 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6608 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6612 #endif /* FS_STATS_DETAILED */
6616 } /*SRXAFS_GetVolumeInfo */
6620 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6621 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6622 char **OfflineMsg, char **Motd)
6624 Vnode *targetptr = 0; /* vnode of the new file */
6625 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6626 Error errorCode = 0; /* error code */
6627 Volume *volptr = 0; /* pointer to the volume header */
6628 struct client *client = 0; /* pointer to client entry */
6629 afs_int32 rights, anyrights; /* rights for this and any user */
6631 struct rx_connection *tcon;
6633 struct client *t_client = NULL; /* tmp ptr to client data */
6634 #if FS_STATS_DETAILED
6635 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6636 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6637 struct timeval elapsedTime; /* Transfer time */
6640 * Set our stats pointer, remember when the RPC operation started, and
6641 * tally the operation.
6644 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6648 FT_GetTimeOfDay(&opStartTime, 0);
6649 #endif /* FS_STATS_DETAILED */
6651 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6652 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6653 goto Bad_GetVolumeStatus;
6656 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6660 goto Bad_GetVolumeStatus;
6662 dummyFid.Volume = avolid, dummyFid.Vnode =
6663 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6666 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6667 &parentwhentargetnotdir, &client, READ_LOCK,
6668 &rights, &anyrights)))
6669 goto Bad_GetVolumeStatus;
6671 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6673 goto Bad_GetVolumeStatus;
6675 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6677 Bad_GetVolumeStatus:
6678 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6680 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6681 /* next is to guarantee out strings exist for stub */
6683 *Name = (char *)malloc(1);
6687 *Motd = (char *)malloc(1);
6690 if (*OfflineMsg == 0) {
6691 *OfflineMsg = (char *)malloc(1);
6694 errorCode = CallPostamble(tcon, errorCode, thost);
6696 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6698 #if FS_STATS_DETAILED
6699 FT_GetTimeOfDay(&opStopTime, 0);
6700 if (errorCode == 0) {
6702 (opP->numSuccesses)++;
6703 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6704 fs_stats_AddTo((opP->sumTime), elapsedTime);
6705 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6706 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6707 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6709 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6710 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6714 #endif /* FS_STATS_DETAILED */
6716 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6717 AUD_ID, t_client ? t_client->ViceId : 0,
6718 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6721 } /*SRXAFS_GetVolumeStatus */
6725 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6726 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6727 char *OfflineMsg, char *Motd)
6729 Vnode *targetptr = 0; /* vnode of the new file */
6730 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6731 Error errorCode = 0; /* error code */
6732 Volume *volptr = 0; /* pointer to the volume header */
6733 struct client *client = 0; /* pointer to client entry */
6734 afs_int32 rights, anyrights; /* rights for this and any user */
6736 struct rx_connection *tcon = rx_ConnectionOf(acall);
6738 struct client *t_client = NULL; /* tmp ptr to client data */
6739 #if FS_STATS_DETAILED
6740 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6741 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6742 struct timeval elapsedTime; /* Transfer time */
6745 * Set our stats pointer, remember when the RPC operation started, and
6746 * tally the operation.
6749 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6753 FT_GetTimeOfDay(&opStartTime, 0);
6754 #endif /* FS_STATS_DETAILED */
6756 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6757 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6758 goto Bad_SetVolumeStatus;
6761 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6765 goto Bad_SetVolumeStatus;
6767 dummyFid.Volume = avolid, dummyFid.Vnode =
6768 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6771 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6772 &parentwhentargetnotdir, &client, READ_LOCK,
6773 &rights, &anyrights)))
6774 goto Bad_SetVolumeStatus;
6776 if (readonlyServer) {
6777 errorCode = VREADONLY;
6778 goto Bad_SetVolumeStatus;
6780 if (VanillaUser(client)) {
6782 goto Bad_SetVolumeStatus;
6786 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6788 Bad_SetVolumeStatus:
6789 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6791 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6792 errorCode = CallPostamble(tcon, errorCode, thost);
6794 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6796 #if FS_STATS_DETAILED
6797 FT_GetTimeOfDay(&opStopTime, 0);
6798 if (errorCode == 0) {
6800 (opP->numSuccesses)++;
6801 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6802 fs_stats_AddTo((opP->sumTime), elapsedTime);
6803 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6804 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6805 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6807 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6808 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6812 #endif /* FS_STATS_DETAILED */
6814 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6815 AUD_ID, t_client ? t_client->ViceId : 0,
6816 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6818 } /*SRXAFS_SetVolumeStatus */
6820 #define DEFAULTVOLUME "root.afs"
6823 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6829 struct rx_connection *tcon;
6831 Error errorCode = 0;
6833 #if FS_STATS_DETAILED
6834 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6835 struct timeval opStartTime; /* Start time for RPC op */
6837 struct timeval opStopTime;
6838 struct timeval elapsedTime; /* Transfer time */
6842 * Set our stats pointer, remember when the RPC operation started, and
6843 * tally the operation.
6845 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6849 FT_GetTimeOfDay(&opStartTime, 0);
6850 #endif /* FS_STATS_DETAILED */
6852 return FSERR_EOPNOTSUPP;
6855 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6856 goto Bad_GetRootVolume;
6858 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6861 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6863 strcpy(temp, DEFAULTVOLUME);
6865 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6866 lockf(fd, F_LOCK, 0);
6870 len = read(fd, temp, 256);
6871 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6872 lockf(fd, F_ULOCK, 0);
6877 if (temp[len - 1] == '\n')
6881 *VolumeName = temp; /* freed by rx server-side stub */
6884 errorCode = CallPostamble(tcon, errorCode, thost);
6886 #if FS_STATS_DETAILED
6887 FT_GetTimeOfDay(&opStopTime, 0);
6888 if (errorCode == 0) {
6890 (opP->numSuccesses)++;
6891 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6892 fs_stats_AddTo((opP->sumTime), elapsedTime);
6893 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6894 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6895 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6897 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6898 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6902 #endif /* FS_STATS_DETAILED */
6907 } /*SRXAFS_GetRootVolume */
6910 /* still works because a struct CBS is the same as a struct AFSOpaque */
6912 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6913 struct AFSOpaque * Token)
6916 struct rx_connection *tcon;
6918 #if FS_STATS_DETAILED
6919 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6920 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6921 struct timeval elapsedTime; /* Transfer time */
6924 * Set our stats pointer, remember when the RPC operation started, and
6925 * tally the operation.
6927 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6931 FT_GetTimeOfDay(&opStartTime, 0);
6932 #endif /* FS_STATS_DETAILED */
6934 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6935 goto Bad_CheckToken;
6937 code = FSERR_ECONNREFUSED;
6940 code = CallPostamble(tcon, code, thost);
6942 #if FS_STATS_DETAILED
6943 FT_GetTimeOfDay(&opStopTime, 0);
6946 (opP->numSuccesses)++;
6947 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6948 fs_stats_AddTo((opP->sumTime), elapsedTime);
6949 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6950 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6951 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6953 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6954 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6958 #endif /* FS_STATS_DETAILED */
6962 } /*SRXAFS_CheckToken */
6965 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6966 afs_uint32 * USeconds)
6969 struct rx_connection *tcon;
6972 #if FS_STATS_DETAILED
6973 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6974 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6975 struct timeval elapsedTime; /* Transfer time */
6978 * Set our stats pointer, remember when the RPC operation started, and
6979 * tally the operation.
6981 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6985 FT_GetTimeOfDay(&opStartTime, 0);
6986 #endif /* FS_STATS_DETAILED */
6988 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6992 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6994 FT_GetTimeOfDay(&tpl, 0);
6995 *Seconds = tpl.tv_sec;
6996 *USeconds = tpl.tv_usec;
6998 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
7001 code = CallPostamble(tcon, code, thost);
7003 #if FS_STATS_DETAILED
7004 FT_GetTimeOfDay(&opStopTime, 0);
7005 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
7008 (opP->numSuccesses)++;
7009 fs_stats_AddTo((opP->sumTime), elapsedTime);
7010 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
7011 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
7012 fs_stats_TimeAssign((opP->minTime), elapsedTime);
7014 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
7015 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
7019 #endif /* FS_STATS_DETAILED */
7023 } /*SRXAFS_GetTime */
7030 * Implement a client's data fetch using Rx.
7033 * volptr : Ptr to the given volume's info.
7034 * targetptr : Pointer to the vnode involved.
7035 * Call : Ptr to the Rx call involved.
7036 * Pos : Offset within the file.
7037 * Len : Length in bytes to read; this value is bogus!
7038 * if FS_STATS_DETAILED
7039 * a_bytesToFetchP : Set to the number of bytes to be fetched from
7041 * a_bytesFetchedP : Set to the actual number of bytes fetched from
7047 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
7048 struct rx_call * Call, afs_sfsize_t Pos,
7049 afs_sfsize_t Len, afs_int32 Int64Mode,
7050 #if FS_STATS_DETAILED
7051 afs_sfsize_t * a_bytesToFetchP,
7052 afs_sfsize_t * a_bytesFetchedP
7053 #endif /* FS_STATS_DETAILED */
7056 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
7061 #else /* HAVE_PIOV */
7062 struct iovec tiov[RX_MAXIOVECS];
7064 #endif /* HAVE_PIOV */
7068 #if FS_STATS_DETAILED
7070 * Initialize the byte count arguments.
7072 (*a_bytesToFetchP) = 0;
7073 (*a_bytesFetchedP) = 0;
7074 #endif /* FS_STATS_DETAILED */
7078 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
7079 (afs_uintmax_t) Len));
7081 if (!VN_GET_INO(targetptr)) {
7082 afs_int32 zero = htonl(0);
7084 * This is used for newly created files; we simply send 0 bytes
7085 * back to make the cache manager happy...
7088 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7089 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7092 FT_GetTimeOfDay(&StartTime, 0);
7093 ihP = targetptr->handle;
7096 VTakeOffline(volptr);
7097 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7101 optSize = sendBufSize;
7102 tlen = FDH_SIZE(fdP);
7104 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7107 VTakeOffline(volptr);
7108 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7116 if (Pos + Len > tlen) /* get length we should send */
7117 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7120 afs_int32 high, low;
7121 SplitOffsetOrSize(Len, high, low);
7122 osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7125 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7128 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7130 #if FS_STATS_DETAILED
7131 (*a_bytesToFetchP) = Len;
7132 #endif /* FS_STATS_DETAILED */
7134 tbuffer = AllocSendBuffer();
7135 #endif /* HAVE_PIOV */
7144 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
7145 if (nBytes != wlen) {
7147 FreeSendBuffer((struct afs_buffer *)tbuffer);
7148 VTakeOffline(volptr);
7149 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7153 nBytes = rx_Write(Call, tbuffer, wlen);
7154 #else /* HAVE_PIOV */
7155 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7161 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
7162 if (nBytes != wlen) {
7164 VTakeOffline(volptr);
7165 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7169 nBytes = rx_Writev(Call, tiov, tnio, wlen);
7170 #endif /* HAVE_PIOV */
7172 #if FS_STATS_DETAILED
7174 * Bump the number of bytes actually sent by the number from this
7177 (*a_bytesFetchedP) += nBytes;
7178 #endif /* FS_STATS_DETAILED */
7179 if (nBytes != wlen) {
7183 FreeSendBuffer((struct afs_buffer *)tbuffer);
7184 #endif /* HAVE_PIOV */
7185 err = VIsGoingOffline(volptr);
7194 FreeSendBuffer((struct afs_buffer *)tbuffer);
7195 #endif /* HAVE_PIOV */
7197 FT_GetTimeOfDay(&StopTime, 0);
7199 /* Adjust all Fetch Data related stats */
7201 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7202 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7203 AFSCallStats.AccumFetchTime +=
7204 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7205 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7207 afs_fsize_t targLen;
7208 VN_GET_LEN(targLen, targetptr);
7209 AFSCallStats.TotalFetchedBytes += targLen;
7210 AFSCallStats.FetchSize1++;
7211 if (targLen < SIZE2)
7212 AFSCallStats.FetchSize2++;
7213 else if (targLen < SIZE3)
7214 AFSCallStats.FetchSize3++;
7215 else if (targLen < SIZE4)
7216 AFSCallStats.FetchSize4++;
7218 AFSCallStats.FetchSize5++;
7223 } /*FetchData_RXStyle */
7226 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7227 afs_sfsize_t * size)
7229 #ifdef AFS_NAMEI_ENV
7231 lhp = IH_OPEN(V_linkHandle(vp));
7234 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
7238 *size = OS_SIZE(fdP->fd_fd);
7239 return (*size == -1) ? -1 : 0;
7241 struct afs_stat status;
7243 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7247 *lc = GetLinkCount(vp, &status);
7248 *size = status.st_size;
7257 * Implement a client's data store using Rx.
7260 * volptr : Ptr to the given volume's info.
7261 * targetptr : Pointer to the vnode involved.
7262 * Call : Ptr to the Rx call involved.
7263 * Pos : Offset within the file.
7264 * Len : Length in bytes to store; this value is bogus!
7265 * if FS_STATS_DETAILED
7266 * a_bytesToStoreP : Set to the number of bytes to be stored to
7268 * a_bytesStoredP : Set to the actual number of bytes stored to
7273 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7274 struct client * client, struct rx_call * Call,
7275 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7277 #if FS_STATS_DETAILED
7278 afs_sfsize_t * a_bytesToStoreP,
7279 afs_sfsize_t * a_bytesStoredP
7280 #endif /* FS_STATS_DETAILED */
7283 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7284 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7285 Error errorCode = 0; /* Returned error code to caller */
7287 char *tbuffer; /* data copying buffer */
7288 #else /* HAVE_PIOV */
7289 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7290 int tnio; /* temp for iovec size */
7291 #endif /* HAVE_PIOV */
7292 afs_sfsize_t tlen; /* temp for xfr length */
7293 Inode tinode; /* inode for I/O */
7294 afs_int32 optSize; /* optimal transfer size */
7295 afs_sfsize_t DataLength = 0; /* size of inode */
7296 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7297 afs_fsize_t NewLength; /* size after this store completes */
7298 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7299 int linkCount = 0; /* link count on inode */
7300 afs_fsize_t CoW_off, CoW_len;
7302 FdHandle_t *fdP, *origfdP = NULL;
7303 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7306 #if FS_STATS_DETAILED
7308 * Initialize the byte count arguments.
7310 (*a_bytesToStoreP) = 0;
7311 (*a_bytesStoredP) = 0;
7312 #endif /* FS_STATS_DETAILED */
7315 * We break the callbacks here so that the following signal will not
7318 BreakCallBack(client->host, Fid, 0);
7320 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7321 /* the inode should have been created in Alloc_NewVnode */
7322 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7324 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7325 Fid->Volume, Fid->Vnode, Fid->Unique,
7326 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7327 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7328 return ENOENT; /* is this proper error code? */
7331 * See if the file has several links (from other volumes). If it
7332 * does, then we have to make a copy before changing it to avoid
7333 *changing read-only clones of this dude
7336 ("StoreData_RXStyle : Opening inode %s\n",
7337 PrintInode(stmp, VN_GET_INO(targetptr))));
7338 fdP = IH_OPEN(targetptr->handle);
7341 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7343 VTakeOffline(volptr);
7344 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7349 if (linkCount != 1) {
7352 ("StoreData_RXStyle : inode %s has more than onelink\n",
7353 PrintInode(stmp, VN_GET_INO(targetptr))));
7354 /* other volumes share this data, better copy it first */
7356 /* Adjust the disk block count by the creation of the new inode.
7357 * We call the special VDiskUsage so we don't adjust the volume's
7358 * quota since we don't want to penalyze the user for afs's internal
7359 * mechanisms (i.e. copy on write overhead.) Also the right size
7360 * of the disk will be recorded...
7363 VN_GET_LEN(size, targetptr);
7364 volptr->partition->flags &= ~PART_DONTUPDATE;
7365 VSetPartitionDiskUsage(volptr->partition);
7366 volptr->partition->flags |= PART_DONTUPDATE;
7367 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7368 volptr->partition->flags &= ~PART_DONTUPDATE;
7373 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7374 CopyOnWrite_calls++;
7375 if (CoW_len == 0) CopyOnWrite_size0++;
7376 if (Pos == 0) CopyOnWrite_off0++;
7377 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7379 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7380 "off 0x0 size 0x%llx\n",
7381 afs_printable_VolumeId_u(V_id(volptr)),
7382 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7383 V_name(volptr), Pos));
7384 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7385 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7386 volptr->partition->flags &= ~PART_DONTUPDATE;
7390 volptr->partition->flags &= ~PART_DONTUPDATE;
7391 VSetPartitionDiskUsage(volptr->partition);
7392 fdP = IH_OPEN(targetptr->handle);
7395 ("StoreData : Reopen after CopyOnWrite failed\n"));
7400 tinode = VN_GET_INO(targetptr);
7402 if (!VALID_INO(tinode)) {
7403 VTakeOffline(volptr);
7404 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7409 /* compute new file length */
7410 NewLength = DataLength;
7411 if (FileLength < NewLength)
7412 /* simulate truncate */
7413 NewLength = FileLength;
7414 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7415 if (Pos + Length > NewLength)
7416 NewLength = Pos + Length; /* and write */
7418 /* adjust the disk block count by the difference in the files */
7420 afs_fsize_t targSize;
7421 VN_GET_LEN(targSize, targetptr);
7422 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7425 AdjustDiskUsage(volptr, adjustSize,
7426 adjustSize - SpareComp(volptr)))) {
7428 if (origfdP) FDH_CLOSE(origfdP);
7432 /* can signal cache manager to proceed from close now */
7433 /* this bit means that the locks are set and protections are OK */
7434 rx_SetLocalStatus(Call, 1);
7436 FT_GetTimeOfDay(&StartTime, 0);
7438 optSize = sendBufSize;
7440 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7441 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7442 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7444 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7445 if (FileLength < DataLength)
7446 FDH_TRUNC(fdP, FileLength);
7447 bytesTransfered = 0;
7449 tbuffer = AllocSendBuffer();
7450 #endif /* HAVE_PIOV */
7451 /* if length == 0, the loop below isn't going to do anything, including
7452 * extend the length of the inode, which it must do, since the file system
7453 * assumes that the inode length == vnode's file length. So, we extend
7454 * the file length manually if need be. Note that if file is bigger than
7455 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7456 * do what we're going to do below.
7458 if (Length == 0 && Pos > TruncatedLength) {
7459 /* Set the file's length; we've already done an lseek to the right
7462 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
7467 errorCode = FDH_TRUNC(fdP, Pos);
7469 /* have some data to copy */
7470 #if FS_STATS_DETAILED
7471 (*a_bytesToStoreP) = Length;
7472 #endif /* FS_STATS_DETAILED */
7475 if (bytesTransfered >= Length) {
7479 tlen = Length - bytesTransfered; /* how much more to do */
7481 rlen = optSize; /* bound by buffer size */
7485 errorCode = rx_Read(Call, tbuffer, rlen);
7486 #else /* HAVE_PIOV */
7487 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7488 #endif /* HAVE_PIOV */
7489 if (errorCode <= 0) {
7493 #if FS_STATS_DETAILED
7494 (*a_bytesStoredP) += errorCode;
7495 #endif /* FS_STATS_DETAILED */
7498 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
7499 #else /* HAVE_PIOV */
7500 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
7501 #endif /* HAVE_PIOV */
7502 if (nBytes != rlen) {
7503 errorCode = VDISKFULL;
7506 bytesTransfered += rlen;
7512 FreeSendBuffer((struct afs_buffer *)tbuffer);
7513 #endif /* HAVE_PIOV */
7518 afs_sfsize_t nfSize = FDH_SIZE(fdP);
7519 osi_Assert(nfSize >= 0);
7520 /* something went wrong: adjust size and return */
7521 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7522 /* changed_newTime is tested in StoreData to detemine if we
7523 * need to update the target vnode.
7525 targetptr->changed_newTime = 1;
7526 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7527 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7528 if (origfdP) FDH_CLOSE(origfdP);
7530 /* set disk usage to be correct */
7531 VAdjustDiskUsage(&errorCode, volptr,
7532 (afs_sfsize_t) (nBlocks(nfSize) -
7533 nBlocks(NewLength)), 0);
7536 if (origfdP) { /* finish CopyOnWrite */
7537 if ( (CoW_off = Pos + Length) < NewLength) {
7538 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7539 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7540 "off 0x%llx size 0x%llx returns %d\n",
7541 afs_printable_VolumeId_u(V_id(volptr)),
7542 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7543 V_name(volptr), CoW_off, CoW_len, errorCode));
7549 FT_GetTimeOfDay(&StopTime, 0);
7551 VN_SET_LEN(targetptr, NewLength);
7553 /* Update all StoreData related stats */
7555 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7556 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7557 AFSCallStats.StoreSize1++; /* Piggybacked data */
7559 afs_fsize_t targLen;
7560 VN_GET_LEN(targLen, targetptr);
7561 if (targLen < SIZE2)
7562 AFSCallStats.StoreSize2++;
7563 else if (targLen < SIZE3)
7564 AFSCallStats.StoreSize3++;
7565 else if (targLen < SIZE4)
7566 AFSCallStats.StoreSize4++;
7568 AFSCallStats.StoreSize5++;
7573 } /*StoreData_RXStyle */
7575 static int sys2et[512];
7578 init_sys_error_to_et(void)
7580 memset(&sys2et, 0, sizeof(sys2et));
7581 sys2et[EPERM] = UAEPERM;
7582 sys2et[ENOENT] = UAENOENT;
7583 sys2et[ESRCH] = UAESRCH;
7584 sys2et[EINTR] = UAEINTR;
7585 sys2et[EIO] = UAEIO;
7586 sys2et[ENXIO] = UAENXIO;
7587 sys2et[E2BIG] = UAE2BIG;
7588 sys2et[ENOEXEC] = UAENOEXEC;
7589 sys2et[EBADF] = UAEBADF;
7590 sys2et[ECHILD] = UAECHILD;
7591 sys2et[EAGAIN] = UAEAGAIN;
7592 sys2et[ENOMEM] = UAENOMEM;
7593 sys2et[EACCES] = UAEACCES;
7594 sys2et[EFAULT] = UAEFAULT;
7595 sys2et[ENOTBLK] = UAENOTBLK;
7596 sys2et[EBUSY] = UAEBUSY;
7597 sys2et[EEXIST] = UAEEXIST;
7598 sys2et[EXDEV] = UAEXDEV;
7599 sys2et[ENODEV] = UAENODEV;
7600 sys2et[ENOTDIR] = UAENOTDIR;
7601 sys2et[EISDIR] = UAEISDIR;
7602 sys2et[EINVAL] = UAEINVAL;
7603 sys2et[ENFILE] = UAENFILE;
7604 sys2et[EMFILE] = UAEMFILE;
7605 sys2et[ENOTTY] = UAENOTTY;
7606 sys2et[ETXTBSY] = UAETXTBSY;
7607 sys2et[EFBIG] = UAEFBIG;
7608 sys2et[ENOSPC] = UAENOSPC;
7609 sys2et[ESPIPE] = UAESPIPE;
7610 sys2et[EROFS] = UAEROFS;
7611 sys2et[EMLINK] = UAEMLINK;
7612 sys2et[EPIPE] = UAEPIPE;
7613 sys2et[EDOM] = UAEDOM;
7614 sys2et[ERANGE] = UAERANGE;
7615 sys2et[EDEADLK] = UAEDEADLK;
7616 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7617 sys2et[ENOLCK] = UAENOLCK;
7618 sys2et[ENOSYS] = UAENOSYS;
7619 #if (ENOTEMPTY != EEXIST)
7620 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7622 sys2et[ELOOP] = UAELOOP;
7623 #if (EWOULDBLOCK != EAGAIN)
7624 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7626 sys2et[ENOMSG] = UAENOMSG;
7627 sys2et[EIDRM] = UAEIDRM;
7628 sys2et[ECHRNG] = UAECHRNG;
7629 sys2et[EL2NSYNC] = UAEL2NSYNC;
7630 sys2et[EL3HLT] = UAEL3HLT;
7631 sys2et[EL3RST] = UAEL3RST;
7632 sys2et[ELNRNG] = UAELNRNG;
7633 sys2et[EUNATCH] = UAEUNATCH;
7634 sys2et[ENOCSI] = UAENOCSI;
7635 sys2et[EL2HLT] = UAEL2HLT;
7636 sys2et[EBADE] = UAEBADE;
7637 sys2et[EBADR] = UAEBADR;
7638 sys2et[EXFULL] = UAEXFULL;
7639 sys2et[ENOANO] = UAENOANO;
7640 sys2et[EBADRQC] = UAEBADRQC;
7641 sys2et[EBADSLT] = UAEBADSLT;
7642 sys2et[EDEADLK] = UAEDEADLK;
7643 sys2et[EBFONT] = UAEBFONT;
7644 sys2et[ENOSTR] = UAENOSTR;
7645 sys2et[ENODATA] = UAENODATA;
7646 sys2et[ETIME] = UAETIME;
7647 sys2et[ENOSR] = UAENOSR;
7648 sys2et[ENONET] = UAENONET;
7649 sys2et[ENOPKG] = UAENOPKG;
7650 sys2et[EREMOTE] = UAEREMOTE;
7651 sys2et[ENOLINK] = UAENOLINK;
7652 sys2et[EADV] = UAEADV;
7653 sys2et[ESRMNT] = UAESRMNT;
7654 sys2et[ECOMM] = UAECOMM;
7655 sys2et[EPROTO] = UAEPROTO;
7656 sys2et[EMULTIHOP] = UAEMULTIHOP;
7657 sys2et[EDOTDOT] = UAEDOTDOT;
7658 sys2et[EBADMSG] = UAEBADMSG;
7659 sys2et[EOVERFLOW] = UAEOVERFLOW;
7660 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7661 sys2et[EBADFD] = UAEBADFD;
7662 sys2et[EREMCHG] = UAEREMCHG;
7663 sys2et[ELIBACC] = UAELIBACC;
7664 sys2et[ELIBBAD] = UAELIBBAD;
7665 sys2et[ELIBSCN] = UAELIBSCN;
7666 sys2et[ELIBMAX] = UAELIBMAX;
7667 sys2et[ELIBEXEC] = UAELIBEXEC;
7668 sys2et[EILSEQ] = UAEILSEQ;
7669 sys2et[ERESTART] = UAERESTART;
7670 sys2et[ESTRPIPE] = UAESTRPIPE;
7671 sys2et[EUSERS] = UAEUSERS;
7672 sys2et[ENOTSOCK] = UAENOTSOCK;
7673 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7674 sys2et[EMSGSIZE] = UAEMSGSIZE;
7675 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7676 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7677 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7678 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7679 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7680 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7681 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7682 sys2et[EADDRINUSE] = UAEADDRINUSE;
7683 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7684 sys2et[ENETDOWN] = UAENETDOWN;
7685 sys2et[ENETUNREACH] = UAENETUNREACH;
7686 sys2et[ENETRESET] = UAENETRESET;
7687 sys2et[ECONNABORTED] = UAECONNABORTED;
7688 sys2et[ECONNRESET] = UAECONNRESET;
7689 sys2et[ENOBUFS] = UAENOBUFS;
7690 sys2et[EISCONN] = UAEISCONN;
7691 sys2et[ENOTCONN] = UAENOTCONN;
7692 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7693 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7694 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7695 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7696 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7697 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7698 sys2et[EALREADY] = UAEALREADY;
7699 sys2et[EINPROGRESS] = UAEINPROGRESS;
7700 sys2et[ESTALE] = UAESTALE;
7701 sys2et[EUCLEAN] = UAEUCLEAN;
7702 sys2et[ENOTNAM] = UAENOTNAM;
7703 sys2et[ENAVAIL] = UAENAVAIL;
7704 sys2et[EISNAM] = UAEISNAM;
7705 sys2et[EREMOTEIO] = UAEREMOTEIO;
7706 sys2et[EDQUOT] = UAEDQUOT;
7707 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7708 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7710 sys2et[EIO] = UAEIO;
7714 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7715 * - pass back the connection, client, and host from CallPreamble
7716 * - keep a ref on the client, which we don't now
7717 * - keep a hold on the host, which we already do
7718 * - pass the connection, client, and host down into SAFSS_*, and use
7719 * them instead of independently discovering them via rx_ConnectionOf
7720 * (safe) and rx_GetSpecific (not so safe)
7721 * The idea being that we decide what client and host we're going to use
7722 * when CallPreamble is called, and stay consistent throughout the call.
7723 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7727 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7729 Error errorCode = 0;
7730 struct rx_connection *tcon;
7731 struct host *tcallhost;
7732 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7734 struct client *tclient;
7735 static struct rx_securityClass *sc = 0;
7737 struct rx_connection *conn;
7740 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7741 goto Bad_CallBackRxConnAddr1;
7743 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7747 tclient = h_FindClient_r(tcon);
7750 goto Bad_CallBackRxConnAddr;
7752 thost = tclient->host;
7754 /* nothing more can be done */
7755 if ( !thost->interface )
7756 goto Bad_CallBackRxConnAddr;
7758 /* the only address is the primary interface */
7759 /* can't change when there's only 1 address, anyway */
7760 if ( thost->interface->numberOfInterfaces <= 1 )
7761 goto Bad_CallBackRxConnAddr;
7763 /* initialise a security object only once */
7765 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7767 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7769 if ( *addr == thost->interface->addr[i] ) {
7774 if ( *addr != thost->interface->addr[i] )
7775 goto Bad_CallBackRxConnAddr;
7777 conn = rx_NewConnection (thost->interface->addr[i],
7778 thost->port, 1, sc, 0);
7779 rx_SetConnDeadTime(conn, 2);
7780 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7782 errorCode = RXAFSCB_Probe(conn);
7785 if ( thost->callback_rxcon )
7786 rx_DestroyConnection(thost->callback_rxcon);
7787 thost->callback_rxcon = conn;
7789 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7790 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7791 h_ReleaseClient_r(tclient);
7792 /* The hold on thost will be released by CallPostamble */
7794 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7797 rx_DestroyConnection(conn);
7799 Bad_CallBackRxConnAddr:
7800 h_ReleaseClient_r(tclient);
7801 /* The hold on thost will be released by CallPostamble */
7805 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7806 Bad_CallBackRxConnAddr1:
7807 return errorCode; /* failure */
7811 sys_error_to_et(afs_int32 in)
7815 if (in < 0 || in > 511)
7817 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7819 if (sys2et[in] != 0)