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 */
122 /* Useful local defines used by this module */
125 #define MustNOTBeDIR 1
129 #define TVS_SSTATUS 2
132 #define TVS_MKDIR 0x10
134 #define CHK_FETCH 0x10
135 #define CHK_FETCHDATA 0x10
136 #define CHK_FETCHACL 0x11
137 #define CHK_FETCHSTATUS 0x12
138 #define CHK_STOREDATA 0x00
139 #define CHK_STOREACL 0x01
140 #define CHK_STORESTATUS 0x02
142 #define OWNERREAD 0400
143 #define OWNERWRITE 0200
144 #define OWNEREXEC 0100
145 #ifdef USE_GROUP_PERMS
146 #define GROUPREAD 0040
147 #define GROUPWRITE 0020
148 #define GROUPREXEC 0010
151 /* The following errors were not defined in NT. They are given unique
152 * names here to avoid any potential collision.
154 #define FSERR_ELOOP 90
155 #define FSERR_EOPNOTSUPP 122
156 #define FSERR_ECONNREFUSED 130
158 #define NOTACTIVECALL 0
161 #define CREATE_SGUID_ADMIN_ONLY 1
163 extern struct afsconf_dir *confDir;
164 extern afs_int32 dataVersionHigh;
167 static struct AFSCallStatistics AFSCallStats;
168 #if FS_STATS_DETAILED
169 struct fs_stats_FullPerfStats afs_FullPerfStats;
170 extern int AnonymousID;
171 #endif /* FS_STATS_DETAILED */
172 #if OPENAFS_VOL_STATS
173 static const char nullString[] = "";
174 #endif /* OPENAFS_VOL_STATS */
177 afs_int32 NothingYet;
180 struct afs_FSStats afs_fsstats;
185 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
187 extern afs_int32 implicitAdminRights;
188 extern afs_int32 readonlyServer;
189 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
190 extern afs_fsize_t CopyOnWrite_maxsize;
193 * Externals used by the xstat code.
195 extern VolPkgStats VStats;
196 extern int CEs, CEBlocks;
198 extern int HTs, HTBlocks;
200 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
201 struct rx_call *Call, afs_sfsize_t Pos,
202 afs_sfsize_t Len, afs_int32 Int64Mode,
203 #if FS_STATS_DETAILED
204 afs_sfsize_t * a_bytesToFetchP,
205 afs_sfsize_t * a_bytesFetchedP
206 #endif /* FS_STATS_DETAILED */
209 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
210 struct AFSFid *Fid, struct client *client,
211 struct rx_call *Call, afs_fsize_t Pos,
212 afs_fsize_t Length, afs_fsize_t FileLength,
214 #if FS_STATS_DETAILED
215 afs_sfsize_t * a_bytesToStoreP,
216 afs_sfsize_t * a_bytesStoredP
217 #endif /* FS_STATS_DETAILED */
220 #ifdef AFS_SGI_XFS_IOPS_ENV
221 #include <afs/xfsattrs.h>
223 GetLinkCount(Volume * avp, struct stat *astat)
225 if (!strcmp("xfs", astat->st_fstype)) {
226 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
228 return astat->st_nlink;
231 #define GetLinkCount(V, S) (S)->st_nlink
235 SpareComp(Volume * avolp)
241 temp = V_maxquota(avolp);
243 /* no matter; doesn't check in this case */
247 temp = (temp * PctSpare) / 100;
258 * Set the volume synchronization parameter for this volume. If it changes,
259 * the Cache Manager knows that the volume must be purged from the stat cache.
262 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
265 /* date volume instance was created */
268 async->spare1 = avol->header->diskstuff.creationDate;
281 * Verify that the on-disk size for a vnode matches the length in the vnode
284 * @param[in] vp Volume pointer
285 * @param[in] vnp Vnode pointer
286 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
287 * and CheckLength itself will determine the on-disk size.
289 * @return operation status
290 * @retval 0 lengths match
291 * @retval nonzero Error; either the lengths do not match or there was an
292 * error determining the on-disk size. The volume should be
293 * taken offline and salvaged.
296 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
299 VN_GET_LEN(vlen, vnp);
304 fdP = IH_OPEN(vnp->handle);
306 ViceLog(0, ("CheckLength: cannot open inode for fid %lu.%lu.%lu\n",
307 afs_printable_uint32_lu(vp->hashid),
308 afs_printable_uint32_lu(Vn_id(vnp)),
309 afs_printable_uint32_lu(vnp->disk.uniquifier)));
312 alen = FDH_SIZE(fdP);
315 afs_int64 alen64 = alen;
316 ViceLog(0, ("CheckLength: cannot get size for inode for fid "
317 "%lu.%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
318 afs_printable_uint32_lu(vp->hashid),
319 afs_printable_uint32_lu(Vn_id(vnp)),
320 afs_printable_uint32_lu(vnp->disk.uniquifier),
327 afs_int64 alen64 = alen, vlen64 = vlen;
328 ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index "
329 "%lld inode %lld ); volume must be salvaged\n",
330 afs_printable_uint32_lu(vp->hashid),
331 afs_printable_uint32_lu(Vn_id(vnp)),
332 afs_printable_uint32_lu(vnp->disk.uniquifier),
340 * Note that this function always returns a held host, so
341 * that CallPostamble can block without the host's disappearing.
342 * Call returns rx connection in passed in *tconn
345 CallPreamble(struct rx_call *acall, int activecall,
346 struct rx_connection **tconn, struct host **ahostp)
349 struct client *tclient;
352 char hoststr[16], hoststr2[16];
353 #ifdef AFS_PTHREAD_ENV
354 struct ubik_client *uclient;
359 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
362 *tconn = rx_ConnectionOf(acall);
366 tclient = h_FindClient_r(*tconn);
368 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
372 thost = tclient->host;
373 if (tclient->prfail == 1) { /* couldn't get the CPS */
375 h_ReleaseClient_r(tclient);
377 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
381 retry_flag = 0; /* Retry once */
383 /* Take down the old connection and re-read the key file */
385 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
386 #ifdef AFS_PTHREAD_ENV
387 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
389 /* Is it still necessary to drop this? We hit the net, we should... */
395 code = hpr_Initialize(&uclient);
398 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
401 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
404 h_ReleaseClient_r(tclient);
407 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
411 tclient->prfail = 2; /* Means re-eval client's cps */
412 h_ReleaseClient_r(tclient);
417 tclient->LastCall = thost->LastCall = FT_ApproxTime();
418 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
419 thost->ActiveCall = thost->LastCall;
422 if (thost->hostFlags & HOSTDELETED) {
424 ("Discarded a packet for deleted host %s:%d\n",
425 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
426 code = VBUSY; /* raced, so retry */
427 } else if ((thost->hostFlags & VENUSDOWN)
428 || (thost->hostFlags & HFE_LATER)) {
429 if (BreakDelayedCallBacks_r(thost)) {
431 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
432 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
433 ntohs(rxr_PortOf(*tconn))));
434 if (MultiProbeAlternateAddress_r(thost)) {
436 ("MultiProbe failed to find new address for host %s:%d\n",
437 afs_inet_ntoa_r(thost->host, hoststr),
438 ntohs(thost->port)));
442 ("MultiProbe found new address for host %s:%d\n",
443 afs_inet_ntoa_r(thost->host, hoststr),
444 ntohs(thost->port)));
445 if (BreakDelayedCallBacks_r(thost)) {
447 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
448 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
449 ntohs(rxr_PortOf(*tconn))));
458 h_ReleaseClient_r(tclient);
468 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
472 struct client *tclient;
476 tclient = h_FindClient_r(aconn);
479 thost = tclient->host;
480 if (thost->hostFlags & HERRORTRANS)
482 h_ReleaseClient_r(tclient);
485 if (ahost != thost) {
486 /* host/client recycle */
487 char hoststr[16], hoststr2[16];
488 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
490 afs_inet_ntoa_r(ahost->host, hoststr),
493 afs_inet_ntoa_r(thost->host, hoststr2),
497 /* return the reference taken in CallPreamble */
501 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
502 afs_inet_ntoa_r(thost->host, hoststr),
507 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
508 * does not decrement refcount on client->host */
513 return (translate ? sys_error_to_et(ret) : ret);
517 * Returns the volume and vnode pointers associated with file Fid; the lock
518 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
519 * are incremented and they must be eventualy released.
522 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
523 Vnode ** vptr, int lock)
526 Error local_errorCode, errorCode = -1;
527 static struct timeval restartedat = { 0, 0 };
529 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
531 if ((*volptr) == 0) {
536 #ifdef AFS_DEMAND_ATTACH_FS
542 #ifdef AFS_PTHREAD_ENV
543 static const struct timespec timeout_ts = { 0, 0 };
544 static const struct timespec * const ts = &timeout_ts;
546 static const struct timespec * const ts = NULL;
550 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
551 fid->Volume, ts, cbv);
556 if ((errorCode == VOFFLINE) && (VInit < 2)) {
557 /* The volume we want may not be attached yet because
558 * the volume initialization is not yet complete.
559 * We can do several things:
560 * 1. return -1, which will cause users to see
561 * "connection timed out". This is more or
562 * less the same as always, except that the servers
563 * may appear to bounce up and down while they
564 * are actually restarting.
565 * 2. return VBUSY which will cause clients to
566 * sleep and retry for 6.5 - 15 minutes, depending
567 * on what version of the CM they are running. If
568 * the file server takes longer than that interval
569 * to attach the desired volume, then the application
570 * will see an ENODEV or EIO. This approach has
571 * the advantage that volumes which have been attached
572 * are immediately available, it keeps the server's
573 * immediate backlog low, and the call is interruptible
574 * by the user. Users see "waiting for busy volume."
575 * 3. sleep here and retry. Some people like this approach
576 * because there is no danger of seeing errors. However,
577 * this approach only works with a bounded number of
578 * clients, since the pending queues will grow without
579 * stopping. It might be better to find a way to take
580 * this call and stick it back on a queue in order to
581 * recycle this thread for a different request.
582 * 4. Return a new error code, which new cache managers will
583 * know enough to interpret as "sleep and retry", without
584 * the upper bound of 6-15 minutes that is imposed by the
585 * VBUSY handling. Users will see "waiting for
586 * busy volume," so they know that something is
587 * happening. Old cache managers must be able to do
588 * something reasonable with this, for instance, mark the
589 * server down. Fortunately, any error code < 0
590 * will elicit that behavior. See #1.
591 * 5. Some combination of the above. I like doing #2 for 10
592 * minutes, followed by #4. 3.1b and 3.2 cache managers
593 * will be fine as long as the restart period is
594 * not longer than 6.5 minutes, otherwise they may
595 * return ENODEV to users. 3.3 cache managers will be
596 * fine for 10 minutes, then will return
597 * ETIMEDOUT. 3.4 cache managers will just wait
598 * until the call works or fails definitively.
599 * NB. The problem with 2,3,4,5 is that old clients won't
600 * fail over to an alternate read-only replica while this
601 * server is restarting. 3.4 clients will fail over right away.
603 if (restartedat.tv_sec == 0) {
604 /* I'm not really worried about when we restarted, I'm */
605 /* just worried about when the first VBUSY was returned. */
606 FT_GetTimeOfDay(&restartedat, 0);
609 afs_perfstats.fs_nBusies++;
612 return (busyonrst ? VBUSY : restarting);
615 FT_GetTimeOfDay(&now, 0);
616 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
619 afs_perfstats.fs_nBusies++;
622 return (busyonrst ? VBUSY : restarting);
628 /* allow read operations on busy volume.
629 * must check local_errorCode because demand attach fs
630 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
631 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
632 #ifdef AFS_DEMAND_ATTACH_FS
633 /* DAFS case is complicated by the fact that local_errorCode can
634 * be VBUSY in cases where the volume is truly offline */
636 /* volume is in VOL_STATE_UNATTACHED */
639 #endif /* AFS_DEMAND_ATTACH_FS */
642 } else if (errorCode)
649 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
652 if ((*vptr)->disk.uniquifier != fid->Unique) {
653 VPutVnode(&fileCode, *vptr);
654 osi_Assert(fileCode == 0);
656 return (VNOVNODE); /* return the right error code, at least */
661 static_inline afs_int32
662 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
664 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
668 * This routine returns the ACL associated with the targetptr. If the
669 * targetptr isn't a directory, we access its parent dir and get the ACL
670 * thru the parent; in such case the parent's vnode is returned in
674 SetAccessList(Vnode ** targetptr, Volume ** volume,
675 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
676 AFSFid * Fid, int Lock)
678 if ((*targetptr)->disk.type == vDirectory) {
680 *ACL = VVnodeACL(*targetptr);
681 *ACLSize = VAclSize(*targetptr);
684 osi_Assert(Fid != 0);
689 parentvnode = (*targetptr)->disk.parent;
690 VPutVnode(&errorCode, *targetptr);
694 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
697 *ACL = VVnodeACL(*parent);
698 *ACLSize = VAclSize(*parent);
699 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
701 if ((*targetptr)->disk.parent != parentvnode) {
702 VPutVnode(&errorCode, *parent);
713 /* Must not be called with H_LOCK held */
715 client_CheckRights(struct client *client, struct acl_accessList *ACL,
719 ObtainReadLock(&client->lock);
720 if (client->CPS.prlist_len > 0 && !client->deleted &&
721 client->host && !(client->host->hostFlags & HOSTDELETED))
722 acl_CheckRights(ACL, &client->CPS, rights);
723 ReleaseReadLock(&client->lock);
726 /* Must not be called with H_LOCK held */
728 client_HasAsMember(struct client *client, afs_int32 id)
732 ObtainReadLock(&client->lock);
733 if (client->CPS.prlist_len > 0 && !client->deleted &&
734 client->host && !(client->host->hostFlags & HOSTDELETED))
735 code = acl_IsAMember(id, &client->CPS);
736 ReleaseReadLock(&client->lock);
741 * Compare the directory's ACL with the user's access rights in the client
742 * connection and return the user's and everybody else's access permissions
743 * in rights and anyrights, respectively
746 GetRights(struct client *client, struct acl_accessList *ACL,
747 afs_int32 * rights, afs_int32 * anyrights)
749 extern prlist SystemAnyUserCPS;
750 afs_int32 hrights = 0;
751 #ifndef AFS_PTHREAD_ENV
755 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
756 ViceLog(0, ("CheckRights failed\n"));
761 client_CheckRights(client, ACL, rights);
763 /* wait if somebody else is already doing the getCPS call */
765 while (client->host->hostFlags & HCPS_INPROGRESS) {
766 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
767 #ifdef AFS_PTHREAD_ENV
768 CV_WAIT(&client->host->cond, &host_glock_mutex);
769 #else /* AFS_PTHREAD_ENV */
771 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
772 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
773 #endif /* AFS_PTHREAD_ENV */
776 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
779 ("CheckRights: len=%u, for host=%s:%d\n",
780 client->host->hcps.prlist_len,
781 afs_inet_ntoa_r(client->host->host, hoststr),
782 ntohs(client->host->port)));
784 acl_CheckRights(ACL, &client->host->hcps, &hrights);
786 /* Allow system:admin the rights given with the -implicit option */
787 if (client_HasAsMember(client, SystemId))
788 *rights |= implicitAdminRights;
791 *anyrights |= hrights;
798 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
799 * a System:Administrator)
802 VanillaUser(struct client *client)
804 if (client_HasAsMember(client, SystemId))
805 return (0); /* not a system administrator, then you're "vanilla" */
812 * This unusual afs_int32-parameter routine encapsulates all volume package related
813 * operations together in a single function; it's called by almost all AFS
817 GetVolumePackageWithCall(struct rx_connection *tcon, struct VCallByVol *cbv,
818 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
819 int chkforDir, Vnode ** parent, struct client **client,
820 int locktype, afs_int32 * rights, afs_int32 * anyrights)
822 struct acl_accessList *aCL; /* Internal access List */
823 int aCLSize; /* size of the access list */
824 Error errorCode = 0; /* return code to caller */
826 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
829 if (chkforDir == MustNOTBeDIR
830 && ((*targetptr)->disk.type == vDirectory))
832 else if (chkforDir == MustBeDIR
833 && ((*targetptr)->disk.type != vDirectory))
837 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
838 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
839 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
841 if (chkforDir == MustBeDIR)
842 osi_Assert((*parent) == 0);
844 if ((errorCode = GetClient(tcon, client)) != 0)
849 GetRights(*client, aCL, rights, anyrights);
850 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
851 if ((*targetptr)->disk.type != vDirectory) {
852 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
853 if ((*targetptr)->disk.owner == (*client)->ViceId)
854 (*rights) |= PRSFS_ADMINISTER;
856 (*rights) &= ~PRSFS_ADMINISTER;
858 #ifdef ADMIN_IMPLICIT_LOOKUP
859 /* admins get automatic lookup on everything */
860 if (!VanillaUser(*client))
861 (*rights) |= PRSFS_LOOKUP;
862 #endif /* ADMIN_IMPLICIT_LOOKUP */
865 } /*GetVolumePackage */
867 static_inline afs_int32
868 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
869 Vnode ** targetptr, int chkforDir, Vnode ** parent,
870 struct client **client, int locktype, afs_int32 * rights,
871 afs_int32 * anyrights)
873 return GetVolumePackageWithCall(tcon, NULL, Fid, volptr, targetptr,
874 chkforDir, parent, client, locktype,
880 * This is the opposite of GetVolumePackage(), and is always used at the end of
881 * AFS calls to put back all used vnodes and the volume in the proper order!
884 PutVolumePackageWithCall(Vnode * parentwhentargetnotdir, Vnode * targetptr,
885 Vnode * parentptr, Volume * volptr,
886 struct client **client, struct VCallByVol *cbv)
888 Error fileCode = 0; /* Error code returned by the volume package */
890 if (parentwhentargetnotdir) {
891 VPutVnode(&fileCode, parentwhentargetnotdir);
892 osi_Assert(!fileCode || (fileCode == VSALVAGE));
895 VPutVnode(&fileCode, targetptr);
896 osi_Assert(!fileCode || (fileCode == VSALVAGE));
899 VPutVnode(&fileCode, parentptr);
900 osi_Assert(!fileCode || (fileCode == VSALVAGE));
903 VPutVolumeWithCall(volptr, cbv);
908 } /*PutVolumePackage */
911 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
912 Vnode * parentptr, Volume * volptr, struct client **client)
914 PutVolumePackageWithCall(parentwhentargetnotdir, targetptr, parentptr,
915 volptr, client, NULL);
919 VolumeOwner(struct client *client, Vnode * targetptr)
921 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
924 return (client->ViceId == owner);
927 * We don't have to check for host's cps since only regular
928 * viceid are volume owners.
930 return (client_HasAsMember(client, owner));
936 VolumeRootVnode(Vnode * targetptr)
938 return ((targetptr->vnodeNumber == ROOTVNODE)
939 && (targetptr->disk.uniquifier == 1));
941 } /*VolumeRootVnode */
944 * Check if target file has the proper access permissions for the Fetch
945 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
946 * StoreStatus) related calls
948 /* this code should probably just set a "priv" flag where all the audit events
949 * are now, and only generate the audit event once at the end of the routine,
950 * thus only generating the event if all the checks succeed, but only because
951 * of the privilege XXX
954 Check_PermissionRights(Vnode * targetptr, struct client *client,
955 afs_int32 rights, int CallingRoutine,
956 AFSStoreStatus * InStatus)
959 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
960 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
961 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
963 if (CallingRoutine & CHK_FETCH) {
964 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
965 if (targetptr->disk.type == vDirectory
966 || targetptr->disk.type == vSymlink) {
967 if (!(rights & PRSFS_LOOKUP)
968 #ifdef ADMIN_IMPLICIT_LOOKUP
969 /* grant admins fetch on all directories */
970 && VanillaUser(client)
971 #endif /* ADMIN_IMPLICIT_LOOKUP */
972 && !VolumeOwner(client, targetptr))
975 /* must have read access, or be owner and have insert access */
976 if (!(rights & PRSFS_READ)
977 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
978 && (client->ViceId != AnonymousID))))
981 if (CallingRoutine == CHK_FETCHDATA
982 && targetptr->disk.type == vFile)
983 #ifdef USE_GROUP_PERMS
984 if (!OWNSp(client, targetptr)
985 && !client_HasAsMember(client, targetptr->disk.owner)) {
987 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
991 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
996 * The check with the ownership below is a kludge to allow
997 * reading of files created with no read permission. The owner
998 * of the file is always allowed to read it.
1000 if ((client->ViceId != targetptr->disk.owner)
1001 && VanillaUser(client))
1003 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
1004 modeBits) ? 0 : EACCES);
1006 } else { /* !VanillaUser(client) && !FetchData */
1008 osi_audit(PrivilegeEvent, 0, AUD_ID,
1009 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
1012 } else { /* a store operation */
1013 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1014 && (CallingRoutine != CHK_STOREACL)
1015 && (targetptr->disk.type == vFile)) {
1016 /* bypass protection checks on first store after a create
1017 * for the creator; also prevent chowns during this time
1018 * unless you are a system administrator */
1019 /****** InStatus->Owner && UnixModeBits better be SET!! */
1020 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1023 else if (VanillaUser(client))
1024 return (EPERM); /* Was EACCES */
1026 osi_audit(PrivilegeEvent, 0, AUD_ID,
1027 (client ? client->ViceId : 0), AUD_INT,
1028 CallingRoutine, AUD_END);
1031 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1032 osi_audit(PrivilegeEvent, 0, AUD_ID,
1033 (client ? client->ViceId : 0), AUD_INT,
1034 CallingRoutine, AUD_END);
1036 if (readonlyServer) {
1039 if (CallingRoutine == CHK_STOREACL) {
1040 if (!(rights & PRSFS_ADMINISTER)
1041 && !VolumeOwner(client, targetptr))
1043 } else { /* store data or status */
1044 /* watch for chowns and chgrps */
1045 if (CHOWN(InStatus, targetptr)
1046 || CHGRP(InStatus, targetptr)) {
1049 else if (VanillaUser(client))
1050 return (EPERM); /* Was EACCES */
1052 osi_audit(PrivilegeEvent, 0, AUD_ID,
1053 (client ? client->ViceId : 0), AUD_INT,
1054 CallingRoutine, AUD_END);
1056 /* must be sysadmin to set suid/sgid bits */
1057 if ((InStatus->Mask & AFS_SETMODE) &&
1059 (InStatus->UnixModeBits & 0xc00) != 0) {
1061 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1065 if (VanillaUser(client))
1068 osi_audit(PrivSetID, 0, AUD_ID,
1069 (client ? client->ViceId : 0), AUD_INT,
1070 CallingRoutine, AUD_END);
1072 if (CallingRoutine == CHK_STOREDATA) {
1075 if (!(rights & PRSFS_WRITE))
1077 /* Next thing is tricky. We want to prevent people
1078 * from writing files sans 0200 bit, but we want
1079 * creating new files with 0444 mode to work. We
1080 * don't check the 0200 bit in the "you are the owner"
1081 * path above, but here we check the bit. However, if
1082 * you're a system administrator, we ignore the 0200
1083 * bit anyway, since you may have fchowned the file,
1085 #ifdef USE_GROUP_PERMS
1086 if ((targetptr->disk.type == vFile)
1087 && VanillaUser(client)) {
1088 if (!OWNSp(client, targetptr)
1089 && !client_HasAsMember(client, targetptr->disk.owner)) {
1091 ((GROUPWRITE & targetptr->disk.modeBits)
1095 ((OWNERWRITE & targetptr->disk.modeBits)
1100 if ((targetptr->disk.type != vDirectory)
1101 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1104 if (VanillaUser(client))
1107 osi_audit(PrivilegeEvent, 0, AUD_ID,
1108 (client ? client->ViceId : 0),
1109 AUD_INT, CallingRoutine, AUD_END);
1111 } else { /* a status store */
1114 if (targetptr->disk.type == vDirectory) {
1115 if (!(rights & PRSFS_DELETE)
1116 && !(rights & PRSFS_INSERT))
1118 } else { /* a file or symlink */
1119 if (!(rights & PRSFS_WRITE))
1129 } /*Check_PermissionRights */
1133 * The Access List information is converted from its internal form in the
1134 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1135 * external form and returned back to the caller, via the AccessList
1139 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1140 struct AFSOpaque *AccessList)
1142 char *eACL; /* External access list placeholder */
1144 if (acl_Externalize_pr
1145 (hpr_IdToName, (targetptr->disk.type ==
1146 vDirectory ? VVnodeACL(targetptr) :
1147 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1150 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1151 acl_FreeExternalACL(&eACL);
1154 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1155 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1157 acl_FreeExternalACL(&eACL);
1160 } /*RXFetch_AccessList */
1164 * The Access List information is converted from its external form in the
1165 * input AccessList structure to the internal representation and copied into
1166 * the target dir's vnode storage.
1169 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1171 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1173 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1176 if ((newACL->size + 4) > VAclSize(targetptr))
1178 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1179 acl_FreeACL(&newACL);
1182 } /*RXStore_AccessList */
1185 /* In our current implementation, each successive data store (new file
1186 * data version) creates a new inode. This function creates the new
1187 * inode, copies the old inode's contents to the new one, remove the old
1188 * inode (i.e. decrement inode count -- if it's currently used the delete
1189 * will be delayed), and modify some fields (i.e. vnode's
1190 * disk.inodeNumber and cloned)
1192 #define COPYBUFFSIZE 8192
1193 #define MAXFSIZE (~(afs_fsize_t) 0)
1195 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1197 Inode ino, nearInode;
1204 int rc; /* return code */
1205 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1206 FdHandle_t *targFdP; /* Source Inode file handle */
1207 FdHandle_t *newFdP; /* Dest Inode file handle */
1209 if (targetptr->disk.type == vDirectory)
1210 DFlush(); /* just in case? */
1212 VN_GET_LEN(size, targetptr);
1220 buff = (char *)malloc(COPYBUFFSIZE);
1225 ino = VN_GET_INO(targetptr);
1226 if (!VALID_INO(ino)) {
1228 VTakeOffline(volptr);
1229 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1233 targFdP = IH_OPEN(targetptr->handle);
1234 if (targFdP == NULL) {
1237 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1238 targetptr->vnodeNumber, V_id(volptr), rc));
1240 VTakeOffline(volptr);
1244 nearInode = VN_GET_INO(targetptr);
1246 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1247 VPartitionPath(V_partition(volptr)), nearInode,
1248 V_id(volptr), targetptr->vnodeNumber,
1249 targetptr->disk.uniquifier,
1250 (int)targetptr->disk.dataVersion);
1251 if (!VALID_INO(ino)) {
1253 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1254 volptr->partition->name, V_id(volptr), errno));
1259 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1260 newFdP = IH_OPEN(newH);
1261 osi_Assert(newFdP != NULL);
1265 if (size > COPYBUFFSIZE) { /* more than a buffer */
1266 length = COPYBUFFSIZE;
1267 size -= COPYBUFFSIZE;
1272 rdlen = FDH_PREAD(targFdP, buff, length, done);
1273 if (rdlen == length) {
1274 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1278 /* Callers of this function are not prepared to recover
1279 * from error that put the filesystem in an inconsistent
1280 * state. Make sure that we force the volume off-line if
1281 * we some error other than ENOSPC - 4.29.99)
1283 * In case we are unable to write the required bytes, and the
1284 * error code indicates that the disk is full, we roll-back to
1285 * the initial state.
1287 if ((rdlen != length) || (wrlen != length)) {
1288 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1290 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1291 volptr->partition->name, V_id(volptr)));
1292 /* remove destination inode which was partially copied till now */
1293 FDH_REALLYCLOSE(newFdP);
1295 FDH_REALLYCLOSE(targFdP);
1296 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1299 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1300 rc, V_id(volptr), volptr->partition->name));
1301 VTakeOffline(volptr);
1306 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1307 * since we never do any I/O anywhere near 2^32 bytes at a
1308 * time, just case to an unsigned int for printing */
1311 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1312 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1313 (unsigned)wrlen, errno));
1314 #if defined(AFS_DEMAND_ATTACH_FS)
1315 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1317 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1319 /* Decrement this inode so salvager doesn't find it. */
1320 FDH_REALLYCLOSE(newFdP);
1322 FDH_REALLYCLOSE(targFdP);
1323 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1325 VTakeOffline(volptr);
1329 #ifndef AFS_PTHREAD_ENV
1331 #endif /* !AFS_PTHREAD_ENV */
1333 FDH_REALLYCLOSE(targFdP);
1334 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1335 V_parentId(volptr));
1337 IH_RELEASE(targetptr->handle);
1339 rc = FDH_SYNC(newFdP);
1340 osi_Assert(rc == 0);
1342 targetptr->handle = newH;
1343 VN_SET_INO(targetptr, ino);
1344 targetptr->disk.cloned = 0;
1345 /* Internal change to vnode, no user level change to volume - def 5445 */
1346 targetptr->changed_oldTime = 1;
1348 return 0; /* success */
1352 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1355 char *buff = malloc(COPYBUFFSIZE);
1360 afs_foff_t done = off;
1362 if (size > FDH_SIZE(targFdP) - off)
1363 size = FDH_SIZE(targFdP) - off;
1366 if (size > COPYBUFFSIZE) { /* more than a buffer */
1367 length = COPYBUFFSIZE;
1368 size -= COPYBUFFSIZE;
1373 rdlen = FDH_PREAD(targFdP, buff, length, done);
1374 if (rdlen == length) {
1375 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1381 if ((rdlen != length) || (wrlen != length)) {
1382 /* no error recovery, at the worst we'll have a "hole"
1394 * Common code to handle with removing the Name (file when it's called from
1395 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1396 * given directory, parentptr.
1398 int DT1 = 0, DT0 = 0;
1400 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1401 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1403 DirHandle childdir; /* Handle for dir package I/O */
1404 Error errorCode = 0;
1408 /* watch for invalid names */
1409 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1412 if (CheckLength(volptr, parentptr, -1)) {
1413 VTakeOffline_r(volptr);
1417 if (parentptr->disk.cloned) {
1418 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1419 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1421 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1427 /* check that the file is in the directory */
1428 SetDirHandle(dir, parentptr);
1429 if (Lookup(dir, Name, fileFid))
1431 fileFid->Volume = V_id(volptr);
1433 /* just-in-case check for something causing deadlock */
1434 if (fileFid->Vnode == parentptr->vnodeNumber)
1437 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1441 if (ChkForDir == MustBeDIR) {
1442 if ((*targetptr)->disk.type != vDirectory)
1444 } else if ((*targetptr)->disk.type == vDirectory)
1447 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1449 * If the uniquifiers dont match then instead of asserting
1450 * take the volume offline and return VSALVAGE
1452 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1453 VTakeOffline(volptr);
1455 ("Volume %u now offline, must be salvaged.\n",
1457 errorCode = VSALVAGE;
1461 if (ChkForDir == MustBeDIR) {
1462 SetDirHandle(&childdir, *targetptr);
1463 if (IsEmpty(&childdir) != 0)
1465 DZap((afs_int32 *) &childdir);
1467 (*targetptr)->delete = 1;
1468 } else if ((--(*targetptr)->disk.linkCount) == 0)
1469 (*targetptr)->delete = 1;
1470 if ((*targetptr)->delete) {
1471 if (VN_GET_INO(*targetptr)) {
1473 IH_REALLYCLOSE((*targetptr)->handle);
1475 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1476 V_parentId(volptr));
1477 IH_RELEASE((*targetptr)->handle);
1478 if (errorCode == -1) {
1480 ("DT: inode=%s, name=%s, errno=%d\n",
1481 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1483 if (errno != ENOENT)
1485 VTakeOffline(volptr);
1487 ("Volume %u now offline, must be salvaged.\n",
1495 VN_SET_INO(*targetptr, (Inode) 0);
1497 afs_fsize_t adjLength;
1498 VN_GET_LEN(adjLength, *targetptr);
1499 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1503 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1505 code = Delete(dir, (char *)Name);
1508 ("Error %d deleting %s\n", code,
1509 (((*targetptr)->disk.type ==
1510 Directory) ? "directory" : "file")));
1511 VTakeOffline(volptr);
1513 ("Volume %u now offline, must be salvaged.\n",
1526 * This routine updates the parent directory's status block after the
1527 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1528 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1532 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1533 int author, int linkcount,
1534 #if FS_STATS_DETAILED
1535 char a_inSameNetwork
1536 #endif /* FS_STATS_DETAILED */
1539 afs_fsize_t newlength; /* Holds new directory length */
1540 afs_fsize_t parentLength;
1542 #if FS_STATS_DETAILED
1543 Date currDate; /*Current date */
1544 int writeIdx; /*Write index to bump */
1545 int timeIdx; /*Authorship time index to bump */
1546 #endif /* FS_STATS_DETAILED */
1548 parentptr->disk.dataVersion++;
1549 newlength = (afs_fsize_t) Length(dir);
1551 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1552 * (create, symlink, link, makedir) so we need to check if we have enough space
1553 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1554 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1556 VN_GET_LEN(parentLength, parentptr);
1557 if (nBlocks(newlength) != nBlocks(parentLength)) {
1558 VAdjustDiskUsage(&errorCode, volptr,
1559 (nBlocks(newlength) - nBlocks(parentLength)),
1560 (nBlocks(newlength) - nBlocks(parentLength)));
1562 VN_SET_LEN(parentptr, newlength);
1564 #if FS_STATS_DETAILED
1566 * Update directory write stats for this volume. Note that the auth
1567 * counter is located immediately after its associated ``distance''
1570 if (a_inSameNetwork)
1571 writeIdx = VOL_STATS_SAME_NET;
1573 writeIdx = VOL_STATS_DIFF_NET;
1574 V_stat_writes(volptr, writeIdx)++;
1575 if (author != AnonymousID) {
1576 V_stat_writes(volptr, writeIdx + 1)++;
1580 * Update the volume's authorship information in response to this
1581 * directory operation. Get the current time, decide to which time
1582 * slot this operation belongs, and bump the appropriate slot.
1584 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1586 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1587 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1588 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1589 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1590 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1591 if (parentptr->disk.author == author) {
1592 V_stat_dirSameAuthor(volptr, timeIdx)++;
1594 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1596 #endif /* FS_STATS_DETAILED */
1598 parentptr->disk.author = author;
1599 parentptr->disk.linkCount = linkcount;
1600 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1601 parentptr->disk.serverModifyTime = FT_ApproxTime();
1602 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1607 * Update the target file's (or dir's) status block after the specified
1608 * operation is complete. Note that some other fields maybe updated by
1609 * the individual module.
1612 /* XXX INCOMPLETE - More attention is needed here! */
1614 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1615 struct client *client, AFSStoreStatus * InStatus,
1616 Vnode * parentptr, Volume * volptr,
1619 #if FS_STATS_DETAILED
1620 Date currDate; /*Current date */
1621 int writeIdx; /*Write index to bump */
1622 int timeIdx; /*Authorship time index to bump */
1623 #endif /* FS_STATS_DETAILED */
1625 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1626 targetptr->disk.parent = parentptr->vnodeNumber;
1627 VN_SET_LEN(targetptr, length);
1628 /* targetptr->disk.group = 0; save some cycles */
1629 targetptr->disk.modeBits = 0777;
1630 targetptr->disk.owner = client->ViceId;
1631 targetptr->disk.dataVersion = 0; /* consistent with the client */
1632 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1633 /* the inode was created in Alloc_NewVnode() */
1635 #if FS_STATS_DETAILED
1637 * Update file write stats for this volume. Note that the auth
1638 * counter is located immediately after its associated ``distance''
1641 if (client->InSameNetwork)
1642 writeIdx = VOL_STATS_SAME_NET;
1644 writeIdx = VOL_STATS_DIFF_NET;
1645 V_stat_writes(volptr, writeIdx)++;
1646 if (client->ViceId != AnonymousID) {
1647 V_stat_writes(volptr, writeIdx + 1)++;
1651 * We only count operations that DON'T involve creating new objects
1652 * (files, symlinks, directories) or simply setting status as
1653 * authorship-change operations.
1655 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1657 * Update the volume's authorship information in response to this
1658 * file operation. Get the current time, decide to which time
1659 * slot this operation belongs, and bump the appropriate slot.
1661 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1664 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1665 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1666 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1667 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1668 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1669 VOL_STATS_TIME_IDX_5);
1670 if (targetptr->disk.author == client->ViceId) {
1671 V_stat_fileSameAuthor(volptr, timeIdx)++;
1673 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1676 #endif /* FS_STATS_DETAILED */
1678 if (!(Caller & TVS_SSTATUS))
1679 targetptr->disk.author = client->ViceId;
1680 if (Caller & TVS_SDATA) {
1681 targetptr->disk.dataVersion++;
1682 if (VanillaUser(client)) {
1683 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1684 #ifdef CREATE_SGUID_ADMIN_ONLY
1685 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1689 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1690 /* store status, must explicitly request to change the date */
1691 if (InStatus->Mask & AFS_SETMODTIME)
1692 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1693 } else { /* other: date always changes, but perhaps to what is specified by caller */
1694 targetptr->disk.unixModifyTime =
1695 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1696 ClientModTime : FT_ApproxTime());
1698 if (InStatus->Mask & AFS_SETOWNER) {
1699 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1700 if (VanillaUser(client)) {
1701 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1702 #ifdef CREATE_SGUID_ADMIN_ONLY
1703 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1706 targetptr->disk.owner = InStatus->Owner;
1707 if (VolumeRootVnode(targetptr)) {
1708 Error errorCode = 0; /* what should be done with this? */
1710 V_owner(targetptr->volumePtr) = InStatus->Owner;
1711 VUpdateVolume(&errorCode, targetptr->volumePtr);
1714 if (InStatus->Mask & AFS_SETMODE) {
1715 int modebits = InStatus->UnixModeBits;
1716 #define CREATE_SGUID_ADMIN_ONLY 1
1717 #ifdef CREATE_SGUID_ADMIN_ONLY
1718 if (VanillaUser(client))
1719 modebits = modebits & 0777;
1721 if (VanillaUser(client)) {
1722 targetptr->disk.modeBits = modebits;
1724 targetptr->disk.modeBits = modebits;
1727 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1728 CHK_STOREDATA, AUD_END);
1732 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1733 CHK_STORESTATUS, AUD_END);
1740 targetptr->disk.serverModifyTime = FT_ApproxTime();
1741 if (InStatus->Mask & AFS_SETGROUP)
1742 targetptr->disk.group = InStatus->Group;
1743 /* vnode changed : to be written back by VPutVnode */
1744 targetptr->changed_newTime = 1;
1746 } /*Update_TargetVnodeStatus */
1750 * Fills the CallBack structure with the expiration time and type of callback
1751 * structure. Warning: this function is currently incomplete.
1754 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1756 /* CallBackTime could not be 0 */
1757 if (CallBackTime == 0) {
1758 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1759 CallBack->ExpirationTime = 0;
1761 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1762 CallBack->CallBackVersion = CALLBACK_VERSION;
1763 CallBack->CallBackType = CB_SHARED; /* The default for now */
1765 } /*SetCallBackStruct */
1769 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1770 * allocation; if some error occured (exceeded volume quota or partition
1771 * was full, or whatever), it frees the space back and returns the code.
1772 * We usually pre-adjust the volume space to make sure that there's
1773 * enough space before consuming some.
1776 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1777 afs_sfsize_t checkLength)
1782 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1784 VAdjustDiskUsage(&nc, volptr, -length, 0);
1785 if (rc == VOVERQUOTA) {
1787 ("Volume %u (%s) is full\n", V_id(volptr),
1791 if (rc == VDISKFULL) {
1793 ("Partition %s that contains volume %u is full\n",
1794 volptr->partition->name, V_id(volptr)));
1797 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1802 } /*AdjustDiskUsage */
1805 * Common code that handles the creation of a new file (SAFS_CreateFile and
1806 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1809 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1810 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1811 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1813 Error errorCode = 0; /* Error code returned back */
1816 Inode nearInode; /* hint for inode allocation in solaris */
1820 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1821 BlocksPreallocatedForVnode))) {
1823 ("Insufficient space to allocate %lld blocks\n",
1824 (afs_intmax_t) BlocksPreallocatedForVnode));
1828 if (CheckLength(volptr, parentptr, -1)) {
1829 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1830 VTakeOffline_r(volptr);
1834 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1835 if (errorCode != 0) {
1836 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1839 OutFid->Volume = V_id(volptr);
1840 OutFid->Vnode = (*targetptr)->vnodeNumber;
1841 OutFid->Unique = (*targetptr)->disk.uniquifier;
1843 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1845 /* create the inode now itself */
1847 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1848 VPartitionPath(V_partition(volptr)), nearInode,
1849 V_id(volptr), (*targetptr)->vnodeNumber,
1850 (*targetptr)->disk.uniquifier, 1);
1852 /* error in creating inode */
1853 if (!VALID_INO(inode)) {
1855 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1856 (*targetptr)->volumePtr->header->diskstuff.id,
1857 (*targetptr)->vnodeNumber, errno));
1858 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1859 (*targetptr)->delete = 1; /* delete vnode */
1862 VN_SET_INO(*targetptr, inode);
1863 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1865 /* copy group from parent dir */
1866 (*targetptr)->disk.group = parentptr->disk.group;
1868 if (parentptr->disk.cloned) {
1869 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1870 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1871 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1872 /* delete the vnode previously allocated */
1873 (*targetptr)->delete = 1;
1874 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1875 IH_REALLYCLOSE((*targetptr)->handle);
1876 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1878 ("Alloc_NewVnode: partition %s idec %s failed\n",
1879 volptr->partition->name, PrintInode(stmp, inode)));
1880 IH_RELEASE((*targetptr)->handle);
1886 /* add the name to the directory */
1887 SetDirHandle(dir, parentptr);
1888 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1889 (*targetptr)->delete = 1;
1890 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1891 IH_REALLYCLOSE((*targetptr)->handle);
1892 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1894 ("Alloc_NewVnode: partition %s idec %s failed\n",
1895 volptr->partition->name, PrintInode(stmp, inode)));
1896 IH_RELEASE((*targetptr)->handle);
1902 } /*Alloc_NewVnode */
1906 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1910 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1912 int Time; /* Used for time */
1913 int writeVnode = targetptr->changed_oldTime; /* save original status */
1915 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1916 Time = FT_ApproxTime();
1917 switch (LockingType) {
1920 if (Time > targetptr->disk.lock.lockTime)
1921 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1923 Time += AFS_LOCKWAIT;
1924 if (LockingType == LockRead) {
1925 if ( !(rights & PRSFS_LOCK) &&
1926 !(rights & PRSFS_WRITE) &&
1927 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1930 if (targetptr->disk.lock.lockCount >= 0) {
1931 ++(targetptr->disk.lock.lockCount);
1932 targetptr->disk.lock.lockTime = Time;
1935 } else if (LockingType == LockWrite) {
1936 if ( !(rights & PRSFS_WRITE) &&
1937 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1940 if (targetptr->disk.lock.lockCount == 0) {
1941 targetptr->disk.lock.lockCount = -1;
1942 targetptr->disk.lock.lockTime = Time;
1948 Time += AFS_LOCKWAIT;
1949 if (targetptr->disk.lock.lockCount != 0)
1950 targetptr->disk.lock.lockTime = Time;
1955 if ((--targetptr->disk.lock.lockCount) <= 0)
1956 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1960 targetptr->changed_oldTime = writeVnode; /* restore old status */
1961 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1964 } /*HandleLocking */
1966 /* 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. */
1969 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1973 if (!(rights & Prfs_Mode))
1975 if ((targetptr->disk.type != vDirectory)
1976 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1982 * If some flags (i.e. min or max quota) are set, the volume's in disk
1983 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1984 * update, if applicable.
1987 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1988 char *Name, char *OfflineMsg, char *Motd)
1990 Error errorCode = 0;
1992 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1993 V_minquota(volptr) = StoreVolStatus->MinQuota;
1994 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1995 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1996 if (strlen(OfflineMsg) > 0) {
1997 strcpy(V_offlineMessage(volptr), OfflineMsg);
1999 if (strlen(Name) > 0) {
2000 strcpy(V_name(volptr), Name);
2002 #if OPENAFS_VOL_STATS
2004 * We don't overwrite the motd field, since it's now being used
2008 if (strlen(Motd) > 0) {
2009 strcpy(V_motd(volptr), Motd);
2011 #endif /* FS_STATS_DETAILED */
2012 VUpdateVolume(&errorCode, volptr);
2015 } /*RXUpdate_VolumeStatus */
2019 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2020 char **motd, Volume * volptr)
2024 status->Vid = V_id(volptr);
2025 status->ParentId = V_parentId(volptr);
2026 status->Online = V_inUse(volptr);
2027 status->InService = V_inService(volptr);
2028 status->Blessed = V_blessed(volptr);
2029 status->NeedsSalvage = V_needsSalvaged(volptr);
2030 if (VolumeWriteable(volptr))
2031 status->Type = ReadWrite;
2033 status->Type = ReadOnly;
2034 status->MinQuota = V_minquota(volptr);
2035 status->MaxQuota = V_maxquota(volptr);
2036 status->BlocksInUse = V_diskused(volptr);
2037 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
2038 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
2040 /* now allocate and copy these things; they're freed by the RXGEN stub */
2041 temp = strlen(V_name(volptr)) + 1;
2042 *name = malloc(temp);
2044 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2045 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2047 strcpy(*name, V_name(volptr));
2048 temp = strlen(V_offlineMessage(volptr)) + 1;
2049 *offMsg = malloc(temp);
2051 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2052 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2054 strcpy(*offMsg, V_offlineMessage(volptr));
2055 #if OPENAFS_VOL_STATS
2058 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2059 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2061 strcpy(*motd, nullString);
2063 temp = strlen(V_motd(volptr)) + 1;
2064 *motd = malloc(temp);
2066 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2067 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2069 strcpy(*motd, V_motd(volptr));
2070 #endif /* FS_STATS_DETAILED */
2072 } /*RXGetVolumeStatus */
2076 FileNameOK(char *aname)
2081 /* watch for @sys on the right */
2082 if (strcmp(aname + i - 4, "@sys") == 0)
2085 while ((tc = *aname++)) {
2087 return 0; /* very bad character to encounter */
2089 return 1; /* file name is ok */
2095 * This variant of symlink is expressly to support the AFS/DFS translator
2096 * and is not supported by the AFS fileserver. We just return EINVAL.
2097 * The cache manager should not generate this call to an AFS cache manager.
2100 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2101 char *LinkContents, struct AFSStoreStatus *InStatus,
2102 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2103 struct AFSFetchStatus *OutDirStatus,
2104 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2110 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2111 struct FsCmdInputs * Inputs,
2112 struct FsCmdOutputs * Outputs)
2116 switch (Inputs->command) {
2120 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2121 Inputs->command, Outputs->code));
2126 static struct afs_buffer {
2127 struct afs_buffer *next;
2128 } *freeBufferList = 0;
2129 static int afs_buffersAlloced = 0;
2132 FreeSendBuffer(struct afs_buffer *adata)
2135 afs_buffersAlloced--;
2136 adata->next = freeBufferList;
2137 freeBufferList = adata;
2141 } /*FreeSendBuffer */
2143 /* allocate space for sender */
2145 AllocSendBuffer(void)
2147 struct afs_buffer *tp;
2150 afs_buffersAlloced++;
2151 if (!freeBufferList) {
2154 tmp = malloc(sendBufSize);
2156 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2157 osi_Panic("Failed malloc in AllocSendBuffer\n");
2161 tp = freeBufferList;
2162 freeBufferList = tp->next;
2166 } /*AllocSendBuffer */
2167 #endif /* HAVE_PIOV */
2170 * This routine returns the status info associated with the targetptr vnode
2171 * in the AFSFetchStatus structure. Some of the newer fields, such as
2172 * SegSize and Group are not yet implemented
2176 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2177 afs_int32 anyrights, Vnode * parentptr)
2179 /* initialize return status from a vnode */
2180 status->InterfaceVersion = 1;
2181 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2182 status->errorCode = 0;
2183 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2184 if (targetptr->disk.type == vFile)
2185 status->FileType = File;
2186 else if (targetptr->disk.type == vDirectory)
2187 status->FileType = Directory;
2188 else if (targetptr->disk.type == vSymlink)
2189 status->FileType = SymbolicLink;
2191 status->FileType = Invalid; /*invalid type field */
2192 status->LinkCount = targetptr->disk.linkCount;
2194 afs_fsize_t targetLen;
2195 VN_GET_LEN(targetLen, targetptr);
2196 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2198 status->DataVersion = targetptr->disk.dataVersion;
2199 status->Author = targetptr->disk.author;
2200 status->Owner = targetptr->disk.owner;
2201 status->CallerAccess = rights;
2202 status->AnonymousAccess = anyrights;
2203 status->UnixModeBits = targetptr->disk.modeBits;
2204 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2205 status->ParentVnode =
2206 (status->FileType ==
2207 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2208 status->ParentUnique =
2209 (status->FileType ==
2210 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2211 status->ServerModTime = targetptr->disk.serverModifyTime;
2212 status->Group = targetptr->disk.group;
2213 status->lockCount = targetptr->disk.lock.lockCount;
2214 status->errorCode = 0;
2220 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2221 afs_sfsize_t Pos, afs_sfsize_t Len,
2222 struct AFSFetchStatus *OutStatus,
2223 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2226 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2227 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2228 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2229 Error errorCode = 0; /* return code to caller */
2230 Error fileCode = 0; /* return code from vol package */
2231 Volume *volptr = 0; /* pointer to the volume */
2232 struct client *client = 0; /* pointer to the client data */
2233 struct rx_connection *tcon; /* the connection we're part of */
2235 afs_int32 rights, anyrights; /* rights for this and any user */
2236 struct client *t_client = NULL; /* tmp ptr to client data */
2237 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2238 struct VCallByVol tcbv, *cbv = NULL;
2239 #if FS_STATS_DETAILED
2240 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2241 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2242 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2243 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2244 struct timeval elapsedTime; /* Transfer time */
2245 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2246 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2247 int readIdx; /* Index of read stats array to bump */
2248 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2251 * Set our stats pointers, remember when the RPC operation started, and
2252 * tally the operation.
2254 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2255 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2259 FT_GetTimeOfDay(&opStartTime, 0);
2260 #endif /* FS_STATS_DETAILED */
2263 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2266 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2268 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2271 /* Get ptr to client data for user Id for logging */
2272 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2273 logHostAddr.s_addr = rxr_HostOf(tcon);
2275 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2276 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2277 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2279 queue_NodeInit(&tcbv);
2284 * Get volume/vnode for the fetched file; caller's access rights to
2285 * it are also returned
2288 GetVolumePackageWithCall(tcon, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2289 &parentwhentargetnotdir, &client, READ_LOCK,
2290 &rights, &anyrights)))
2293 SetVolumeSync(Sync, volptr);
2295 #if FS_STATS_DETAILED
2297 * Remember that another read operation was performed.
2300 if (client->InSameNetwork)
2301 readIdx = VOL_STATS_SAME_NET;
2303 readIdx = VOL_STATS_DIFF_NET;
2304 V_stat_reads(volptr, readIdx)++;
2305 if (client->ViceId != AnonymousID) {
2306 V_stat_reads(volptr, readIdx + 1)++;
2309 #endif /* FS_STATS_DETAILED */
2310 /* Check whether the caller has permission access to fetch the data */
2312 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2316 * Drop the read lock on the parent directory after saving the parent
2317 * vnode information we need to pass to GetStatus
2319 if (parentwhentargetnotdir != NULL) {
2320 tparentwhentargetnotdir = *parentwhentargetnotdir;
2321 VPutVnode(&fileCode, parentwhentargetnotdir);
2322 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2323 parentwhentargetnotdir = NULL;
2325 #if FS_STATS_DETAILED
2327 * Remember when the data transfer started.
2329 FT_GetTimeOfDay(&xferStartTime, 0);
2330 #endif /* FS_STATS_DETAILED */
2332 /* actually do the data transfer */
2333 #if FS_STATS_DETAILED
2335 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2336 &bytesToXfer, &bytesXferred);
2339 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2341 #endif /* FS_STATS_DETAILED */
2343 #if FS_STATS_DETAILED
2345 * At this point, the data transfer is done, for good or ill. Remember
2346 * when the transfer ended, bump the number of successes/failures, and
2347 * integrate the transfer size and elapsed time into the stats. If the
2348 * operation failed, we jump to the appropriate point.
2350 FT_GetTimeOfDay(&xferStopTime, 0);
2352 (xferP->numXfers)++;
2354 (xferP->numSuccesses)++;
2357 * Bump the xfer sum by the number of bytes actually sent, NOT the
2360 tot_bytesXferred += bytesXferred;
2361 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2362 tot_bytesXferred &= 0x3FF;
2363 if (bytesXferred < xferP->minBytes)
2364 xferP->minBytes = bytesXferred;
2365 if (bytesXferred > xferP->maxBytes)
2366 xferP->maxBytes = bytesXferred;
2369 * Tally the size of the object. Note: we tally the actual size,
2370 * NOT the number of bytes that made it out over the wire.
2372 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2373 (xferP->count[0])++;
2374 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2375 (xferP->count[1])++;
2376 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2377 (xferP->count[2])++;
2378 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2379 (xferP->count[3])++;
2380 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2381 (xferP->count[4])++;
2382 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2383 (xferP->count[5])++;
2384 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2385 (xferP->count[6])++;
2386 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2387 (xferP->count[7])++;
2389 (xferP->count[8])++;
2391 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2392 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2393 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2394 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2395 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2397 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2398 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2403 * Finally, go off to tell our caller the bad news in case the
2408 #endif /* FS_STATS_DETAILED */
2410 /* write back the OutStatus from the target vnode */
2411 GetStatus(targetptr, OutStatus, rights, anyrights,
2412 &tparentwhentargetnotdir);
2414 /* if a r/w volume, promise a callback to the caller */
2415 if (VolumeWriteable(volptr))
2416 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2418 struct AFSFid myFid;
2419 memset(&myFid, 0, sizeof(struct AFSFid));
2420 myFid.Volume = Fid->Volume;
2421 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2425 /* Update and store volume/vnode and parent vnodes back */
2426 (void)PutVolumePackageWithCall(parentwhentargetnotdir, targetptr,
2427 (Vnode *) 0, volptr, &client, cbv);
2428 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2429 errorCode = CallPostamble(tcon, errorCode, thost);
2431 #if FS_STATS_DETAILED
2432 FT_GetTimeOfDay(&opStopTime, 0);
2433 if (errorCode == 0) {
2435 (opP->numSuccesses)++;
2436 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2437 fs_stats_AddTo((opP->sumTime), elapsedTime);
2438 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2439 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2440 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2442 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2443 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2447 #endif /* FS_STATS_DETAILED */
2449 osi_auditU(acall, FetchDataEvent, errorCode,
2450 AUD_ID, t_client ? t_client->ViceId : 0,
2451 AUD_FID, Fid, AUD_END);
2454 } /*SRXAFS_FetchData */
2457 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2458 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2459 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2461 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2466 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2467 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2468 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2471 afs_sfsize_t tPos, tLen;
2473 tPos = (afs_sfsize_t) Pos;
2474 tLen = (afs_sfsize_t) Len;
2477 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2483 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2484 struct AFSOpaque * AccessList,
2485 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2487 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2488 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2489 Error errorCode = 0; /* return error code to caller */
2490 Volume *volptr = 0; /* pointer to the volume */
2491 struct client *client = 0; /* pointer to the client data */
2492 afs_int32 rights, anyrights; /* rights for this and any user */
2493 struct rx_connection *tcon = rx_ConnectionOf(acall);
2495 struct client *t_client = NULL; /* tmp ptr to client data */
2496 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2497 #if FS_STATS_DETAILED
2498 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2499 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2500 struct timeval elapsedTime; /* Transfer time */
2503 * Set our stats pointer, remember when the RPC operation started, and
2504 * tally the operation.
2506 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2510 FT_GetTimeOfDay(&opStartTime, 0);
2511 #endif /* FS_STATS_DETAILED */
2514 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2517 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2519 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2522 /* Get ptr to client data for user Id for logging */
2523 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2524 logHostAddr.s_addr = rxr_HostOf(tcon);
2526 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2527 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2528 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2530 AccessList->AFSOpaque_len = 0;
2531 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2532 if (!AccessList->AFSOpaque_val) {
2533 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2534 osi_Panic("Failed malloc in SRXAFS_FetchACL\n");
2538 * Get volume/vnode for the fetched file; caller's access rights to it
2542 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2543 &parentwhentargetnotdir, &client, READ_LOCK,
2544 &rights, &anyrights)))
2547 SetVolumeSync(Sync, volptr);
2549 /* Check whether we have permission to fetch the ACL */
2551 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2554 /* Get the Access List from the dir's vnode */
2556 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2559 /* Get OutStatus back From the target Vnode */
2560 GetStatus(targetptr, OutStatus, rights, anyrights,
2561 parentwhentargetnotdir);
2564 /* Update and store volume/vnode and parent vnodes back */
2565 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2568 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2569 AccessList->AFSOpaque_val));
2570 errorCode = CallPostamble(tcon, errorCode, thost);
2572 #if FS_STATS_DETAILED
2573 FT_GetTimeOfDay(&opStopTime, 0);
2574 if (errorCode == 0) {
2576 (opP->numSuccesses)++;
2577 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2578 fs_stats_AddTo((opP->sumTime), elapsedTime);
2579 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2580 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2581 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2583 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2584 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2588 #endif /* FS_STATS_DETAILED */
2590 osi_auditU(acall, FetchACLEvent, errorCode,
2591 AUD_ID, t_client ? t_client->ViceId : 0,
2593 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2595 } /*SRXAFS_FetchACL */
2599 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2600 * merged into it when possible.
2604 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2605 struct AFSFetchStatus *OutStatus,
2606 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2608 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2609 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2610 Error errorCode = 0; /* return code to caller */
2611 Volume *volptr = 0; /* pointer to the volume */
2612 struct client *client = 0; /* pointer to the client data */
2613 afs_int32 rights, anyrights; /* rights for this and any user */
2614 struct client *t_client = NULL; /* tmp ptr to client data */
2615 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2616 struct rx_connection *tcon = rx_ConnectionOf(acall);
2618 /* Get ptr to client data for user Id for logging */
2619 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2620 logHostAddr.s_addr = rxr_HostOf(tcon);
2622 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2623 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2624 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2626 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2629 * Get volume/vnode for the fetched file; caller's rights to it are
2633 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2634 &parentwhentargetnotdir, &client, READ_LOCK,
2635 &rights, &anyrights)))
2636 goto Bad_FetchStatus;
2638 /* set volume synchronization information */
2639 SetVolumeSync(Sync, volptr);
2641 /* Are we allowed to fetch Fid's status? */
2642 if (targetptr->disk.type != vDirectory) {
2644 Check_PermissionRights(targetptr, client, rights,
2645 CHK_FETCHSTATUS, 0))) {
2646 if (rx_GetCallAbortCode(acall) == errorCode)
2647 rx_SetCallAbortCode(acall, 0);
2648 goto Bad_FetchStatus;
2652 /* set OutStatus From the Fid */
2653 GetStatus(targetptr, OutStatus, rights, anyrights,
2654 parentwhentargetnotdir);
2656 /* If a r/w volume, also set the CallBack state */
2657 if (VolumeWriteable(volptr))
2658 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2660 struct AFSFid myFid;
2661 memset(&myFid, 0, sizeof(struct AFSFid));
2662 myFid.Volume = Fid->Volume;
2663 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2667 /* Update and store volume/vnode and parent vnodes back */
2668 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2670 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2673 } /*SAFSS_FetchStatus */
2677 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2678 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2679 struct AFSVolSync * Sync)
2683 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2684 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2685 Error errorCode = 0; /* return code to caller */
2686 Volume *volptr = 0; /* pointer to the volume */
2687 struct client *client = 0; /* pointer to the client data */
2688 afs_int32 rights, anyrights; /* rights for this and any user */
2689 struct AFSFid *tfid; /* file id we're dealing with now */
2690 struct rx_connection *tcon = rx_ConnectionOf(acall);
2692 struct client *t_client = NULL; /* tmp pointer to the client data */
2693 #if FS_STATS_DETAILED
2694 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2695 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2696 struct timeval elapsedTime; /* Transfer time */
2699 * Set our stats pointer, remember when the RPC operation started, and
2700 * tally the operation.
2702 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2706 FT_GetTimeOfDay(&opStartTime, 0);
2707 #endif /* FS_STATS_DETAILED */
2709 ViceLog(1, ("SAFS_BulkStatus\n"));
2711 AFSCallStats.TotalCalls++;
2713 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2714 if (nfiles <= 0) { /* Sanity check */
2716 goto Audit_and_Return;
2719 /* allocate space for return output parameters */
2720 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2721 malloc(nfiles * sizeof(struct AFSFetchStatus));
2722 if (!OutStats->AFSBulkStats_val) {
2723 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2724 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2726 OutStats->AFSBulkStats_len = nfiles;
2727 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2728 malloc(nfiles * sizeof(struct AFSCallBack));
2729 if (!CallBacks->AFSCBs_val) {
2730 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2731 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2733 CallBacks->AFSCBs_len = nfiles;
2735 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2736 goto Bad_BulkStatus;
2738 tfid = Fids->AFSCBFids_val;
2739 for (i = 0; i < nfiles; i++, tfid++) {
2741 * Get volume/vnode for the fetched file; caller's rights to it
2745 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2746 &parentwhentargetnotdir, &client, READ_LOCK,
2747 &rights, &anyrights)))
2748 goto Bad_BulkStatus;
2749 /* set volume synchronization information, but only once per call */
2751 SetVolumeSync(Sync, volptr);
2753 /* Are we allowed to fetch Fid's status? */
2754 if (targetptr->disk.type != vDirectory) {
2756 Check_PermissionRights(targetptr, client, rights,
2757 CHK_FETCHSTATUS, 0))) {
2758 if (rx_GetCallAbortCode(acall) == errorCode)
2759 rx_SetCallAbortCode(acall, 0);
2760 goto Bad_BulkStatus;
2764 /* set OutStatus From the Fid */
2765 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2766 anyrights, parentwhentargetnotdir);
2768 /* If a r/w volume, also set the CallBack state */
2769 if (VolumeWriteable(volptr))
2770 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2771 &CallBacks->AFSCBs_val[i]);
2773 struct AFSFid myFid;
2774 memset(&myFid, 0, sizeof(struct AFSFid));
2775 myFid.Volume = tfid->Volume;
2776 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2777 &CallBacks->AFSCBs_val[i]);
2780 /* put back the file ID and volume */
2781 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2783 parentwhentargetnotdir = (Vnode *) 0;
2784 targetptr = (Vnode *) 0;
2785 volptr = (Volume *) 0;
2786 client = (struct client *)0;
2790 /* Update and store volume/vnode and parent vnodes back */
2791 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2793 errorCode = CallPostamble(tcon, errorCode, thost);
2795 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2797 #if FS_STATS_DETAILED
2798 FT_GetTimeOfDay(&opStopTime, 0);
2799 if (errorCode == 0) {
2801 (opP->numSuccesses)++;
2802 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2803 fs_stats_AddTo((opP->sumTime), elapsedTime);
2804 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2805 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2806 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2808 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2809 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2813 #endif /* FS_STATS_DETAILED */
2816 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2817 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2818 AUD_ID, t_client ? t_client->ViceId : 0,
2819 AUD_FIDS, Fids, AUD_END);
2822 } /*SRXAFS_BulkStatus */
2826 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2827 struct AFSBulkStats * OutStats,
2828 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2832 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2833 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2834 Error errorCode = 0; /* return code to caller */
2835 Volume *volptr = 0; /* pointer to the volume */
2836 struct client *client = 0; /* pointer to the client data */
2837 afs_int32 rights, anyrights; /* rights for this and any user */
2838 struct AFSFid *tfid; /* file id we're dealing with now */
2839 struct rx_connection *tcon;
2841 struct client *t_client = NULL; /* tmp ptr to client data */
2842 AFSFetchStatus *tstatus;
2843 int VolSync_set = 0;
2844 #if FS_STATS_DETAILED
2845 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2846 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2847 struct timeval elapsedTime; /* Transfer time */
2850 * Set our stats pointer, remember when the RPC operation started, and
2851 * tally the operation.
2853 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2857 FT_GetTimeOfDay(&opStartTime, 0);
2858 #endif /* FS_STATS_DETAILED */
2860 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2862 AFSCallStats.TotalCalls++;
2864 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2865 if (nfiles <= 0) { /* Sanity check */
2867 goto Audit_and_Return;
2870 /* allocate space for return output parameters */
2871 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2872 malloc(nfiles * sizeof(struct AFSFetchStatus));
2873 if (!OutStats->AFSBulkStats_val) {
2874 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2875 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2877 OutStats->AFSBulkStats_len = nfiles;
2878 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2879 malloc(nfiles * sizeof(struct AFSCallBack));
2880 if (!CallBacks->AFSCBs_val) {
2881 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2882 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2884 CallBacks->AFSCBs_len = nfiles;
2886 /* Zero out return values to avoid leaking information on partial succes */
2887 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2888 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2889 memset(Sync, 0, sizeof(*Sync));
2891 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2892 goto Bad_InlineBulkStatus;
2895 tfid = Fids->AFSCBFids_val;
2896 for (i = 0; i < nfiles; i++, tfid++) {
2898 * Get volume/vnode for the fetched file; caller's rights to it
2902 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2903 &parentwhentargetnotdir, &client, READ_LOCK,
2904 &rights, &anyrights))) {
2905 tstatus = &OutStats->AFSBulkStats_val[i];
2906 tstatus->errorCode = errorCode;
2907 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2909 parentwhentargetnotdir = (Vnode *) 0;
2910 targetptr = (Vnode *) 0;
2911 volptr = (Volume *) 0;
2912 client = (struct client *)0;
2916 /* set volume synchronization information, but only once per call */
2918 SetVolumeSync(Sync, volptr);
2922 /* Are we allowed to fetch Fid's status? */
2923 if (targetptr->disk.type != vDirectory) {
2925 Check_PermissionRights(targetptr, client, rights,
2926 CHK_FETCHSTATUS, 0))) {
2927 tstatus = &OutStats->AFSBulkStats_val[i];
2928 tstatus->errorCode = errorCode;
2929 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2930 (Vnode *) 0, volptr, &client);
2931 parentwhentargetnotdir = (Vnode *) 0;
2932 targetptr = (Vnode *) 0;
2933 volptr = (Volume *) 0;
2934 client = (struct client *)0;
2939 /* set OutStatus From the Fid */
2940 GetStatus(targetptr,
2941 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2942 rights, anyrights, parentwhentargetnotdir);
2944 /* If a r/w volume, also set the CallBack state */
2945 if (VolumeWriteable(volptr))
2946 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2947 &CallBacks->AFSCBs_val[i]);
2949 struct AFSFid myFid;
2950 memset(&myFid, 0, sizeof(struct AFSFid));
2951 myFid.Volume = tfid->Volume;
2952 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2953 &CallBacks->AFSCBs_val[i]);
2956 /* put back the file ID and volume */
2957 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2959 parentwhentargetnotdir = (Vnode *) 0;
2960 targetptr = (Vnode *) 0;
2961 volptr = (Volume *) 0;
2962 client = (struct client *)0;
2965 Bad_InlineBulkStatus:
2966 /* Update and store volume/vnode and parent vnodes back */
2967 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2969 errorCode = CallPostamble(tcon, errorCode, thost);
2971 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2973 #if FS_STATS_DETAILED
2974 FT_GetTimeOfDay(&opStopTime, 0);
2975 if (errorCode == 0) {
2977 (opP->numSuccesses)++;
2978 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2979 fs_stats_AddTo((opP->sumTime), elapsedTime);
2980 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2981 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2982 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2984 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2985 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2989 #endif /* FS_STATS_DETAILED */
2992 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2993 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2994 AUD_ID, t_client ? t_client->ViceId : 0,
2995 AUD_FIDS, Fids, AUD_END);
2998 } /*SRXAFS_InlineBulkStatus */
3002 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
3003 struct AFSFetchStatus * OutStatus,
3004 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3007 struct rx_connection *tcon;
3009 struct client *t_client = NULL; /* tmp ptr to client data */
3010 #if FS_STATS_DETAILED
3011 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3012 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3013 struct timeval elapsedTime; /* Transfer time */
3016 * Set our stats pointer, remember when the RPC operation started, and
3017 * tally the operation.
3019 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
3023 FT_GetTimeOfDay(&opStartTime, 0);
3024 #endif /* FS_STATS_DETAILED */
3026 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3027 goto Bad_FetchStatus;
3029 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
3032 code = CallPostamble(tcon, code, thost);
3034 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3036 #if FS_STATS_DETAILED
3037 FT_GetTimeOfDay(&opStopTime, 0);
3040 (opP->numSuccesses)++;
3041 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3042 fs_stats_AddTo((opP->sumTime), elapsedTime);
3043 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3044 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3045 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3047 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3048 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3052 #endif /* FS_STATS_DETAILED */
3054 osi_auditU(acall, FetchStatusEvent, code,
3055 AUD_ID, t_client ? t_client->ViceId : 0,
3056 AUD_FID, Fid, AUD_END);
3059 } /*SRXAFS_FetchStatus */
3063 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
3064 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
3065 afs_fsize_t Length, afs_fsize_t FileLength,
3066 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3068 Vnode *targetptr = 0; /* pointer to input fid */
3069 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3070 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
3071 Error errorCode = 0; /* return code for caller */
3072 Error fileCode = 0; /* return code from vol package */
3073 Volume *volptr = 0; /* pointer to the volume header */
3074 struct client *client = 0; /* pointer to client structure */
3075 afs_int32 rights, anyrights; /* rights for this and any user */
3076 struct client *t_client = NULL; /* tmp ptr to client data */
3077 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3078 struct rx_connection *tcon;
3080 #if FS_STATS_DETAILED
3081 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3082 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
3083 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3084 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
3085 struct timeval elapsedTime; /* Transfer time */
3086 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
3087 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
3088 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
3091 * Set our stats pointers, remember when the RPC operation started, and
3092 * tally the operation.
3094 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
3095 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
3100 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3102 FT_GetTimeOfDay(&opStartTime, 0);
3103 #endif /* FS_STATS_DETAILED */
3106 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3108 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3111 /* Get ptr to client data for user Id for logging */
3112 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3113 logHostAddr.s_addr = rxr_HostOf(tcon);
3115 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3116 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3117 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3120 * Get associated volume/vnode for the stored file; caller's rights
3124 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3125 &parentwhentargetnotdir, &client, WRITE_LOCK,
3126 &rights, &anyrights))) {
3130 /* set volume synchronization information */
3131 SetVolumeSync(Sync, volptr);
3133 if ((targetptr->disk.type == vSymlink)) {
3134 /* Should we return a better error code here??? */
3139 /* Check if we're allowed to store the data */
3141 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3147 * Drop the read lock on the parent directory after saving the parent
3148 * vnode information we need to pass to GetStatus
3150 if (parentwhentargetnotdir != NULL) {
3151 tparentwhentargetnotdir = *parentwhentargetnotdir;
3152 VPutVnode(&fileCode, parentwhentargetnotdir);
3153 osi_Assert(!fileCode || (fileCode == VSALVAGE));
3154 parentwhentargetnotdir = NULL;
3156 #if FS_STATS_DETAILED
3158 * Remember when the data transfer started.
3160 FT_GetTimeOfDay(&xferStartTime, 0);
3161 #endif /* FS_STATS_DETAILED */
3163 /* Do the actual storing of the data */
3164 #if FS_STATS_DETAILED
3166 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3167 FileLength, (InStatus->Mask & AFS_FSYNC),
3168 &bytesToXfer, &bytesXferred);
3171 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3172 FileLength, (InStatus->Mask & AFS_FSYNC));
3173 if (errorCode && (!targetptr->changed_newTime))
3175 #endif /* FS_STATS_DETAILED */
3176 #if FS_STATS_DETAILED
3178 * At this point, the data transfer is done, for good or ill. Remember
3179 * when the transfer ended, bump the number of successes/failures, and
3180 * integrate the transfer size and elapsed time into the stats. If the
3181 * operation failed, we jump to the appropriate point.
3183 FT_GetTimeOfDay(&xferStopTime, 0);
3185 (xferP->numXfers)++;
3187 (xferP->numSuccesses)++;
3190 * Bump the xfer sum by the number of bytes actually sent, NOT the
3193 tot_bytesXferred += bytesXferred;
3194 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3195 tot_bytesXferred &= 0x3FF;
3196 if (bytesXferred < xferP->minBytes)
3197 xferP->minBytes = bytesXferred;
3198 if (bytesXferred > xferP->maxBytes)
3199 xferP->maxBytes = bytesXferred;
3202 * Tally the size of the object. Note: we tally the actual size,
3203 * NOT the number of bytes that made it out over the wire.
3205 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3206 (xferP->count[0])++;
3207 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3208 (xferP->count[1])++;
3209 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3210 (xferP->count[2])++;
3211 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3212 (xferP->count[3])++;
3213 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3214 (xferP->count[4])++;
3215 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3216 (xferP->count[5])++;
3217 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3218 (xferP->count[6])++;
3219 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3220 (xferP->count[7])++;
3222 (xferP->count[8])++;
3224 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3225 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3226 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3227 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3228 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3230 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3231 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3236 * Finally, go off to tell our caller the bad news in case the
3239 if (errorCode && (!targetptr->changed_newTime))
3241 #endif /* FS_STATS_DETAILED */
3243 /* Update the status of the target's vnode */
3244 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3245 targetptr, volptr, 0);
3247 /* Get the updated File's status back to the caller */
3248 GetStatus(targetptr, OutStatus, rights, anyrights,
3249 &tparentwhentargetnotdir);
3252 /* Update and store volume/vnode and parent vnodes back */
3253 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3255 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3257 errorCode = CallPostamble(tcon, errorCode, thost);
3259 #if FS_STATS_DETAILED
3260 FT_GetTimeOfDay(&opStopTime, 0);
3261 if (errorCode == 0) {
3263 (opP->numSuccesses)++;
3264 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3265 fs_stats_AddTo((opP->sumTime), elapsedTime);
3266 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3267 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3268 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3270 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3271 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3275 #endif /* FS_STATS_DETAILED */
3276 osi_auditU(acall, StoreDataEvent, errorCode,
3277 AUD_ID, t_client ? t_client->ViceId : 0,
3278 AUD_FID, Fid, AUD_END);
3280 } /*common_StoreData64 */
3283 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3284 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3285 afs_uint32 Length, afs_uint32 FileLength,
3286 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3288 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3289 (0x7fffffff - Pos) < Length)
3292 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3294 } /*SRXAFS_StoreData */
3297 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3298 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3299 afs_uint64 Length, afs_uint64 FileLength,
3300 struct AFSFetchStatus * OutStatus,
3301 struct AFSVolSync * Sync)
3305 afs_fsize_t tLength;
3306 afs_fsize_t tFileLength;
3308 tPos = (afs_fsize_t) Pos;
3309 tLength = (afs_fsize_t) Length;
3310 tFileLength = (afs_fsize_t) FileLength;
3313 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3319 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3320 struct AFSOpaque * AccessList,
3321 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3323 Vnode *targetptr = 0; /* pointer to input fid */
3324 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3325 Error errorCode = 0; /* return code for caller */
3326 struct AFSStoreStatus InStatus; /* Input status for fid */
3327 Volume *volptr = 0; /* pointer to the volume header */
3328 struct client *client = 0; /* pointer to client structure */
3329 afs_int32 rights, anyrights; /* rights for this and any user */
3330 struct rx_connection *tcon;
3332 struct client *t_client = NULL; /* tmp ptr to client data */
3333 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3334 #if FS_STATS_DETAILED
3335 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3336 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3337 struct timeval elapsedTime; /* Transfer time */
3340 * Set our stats pointer, remember when the RPC operation started, and
3341 * tally the operation.
3343 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3347 FT_GetTimeOfDay(&opStartTime, 0);
3348 #endif /* FS_STATS_DETAILED */
3349 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3352 /* Get ptr to client data for user Id for logging */
3353 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3354 logHostAddr.s_addr = rxr_HostOf(tcon);
3356 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3357 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3358 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3360 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3362 InStatus.Mask = 0; /* not storing any status */
3365 * Get associated volume/vnode for the target dir; caller's rights
3366 * are also returned.
3369 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3370 &parentwhentargetnotdir, &client, WRITE_LOCK,
3371 &rights, &anyrights))) {
3375 /* set volume synchronization information */
3376 SetVolumeSync(Sync, volptr);
3378 /* Check if we have permission to change the dir's ACL */
3380 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3385 /* Build and store the new Access List for the dir */
3386 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3390 targetptr->changed_newTime = 1; /* status change of directory */
3392 /* convert the write lock to a read lock before breaking callbacks */
3393 VVnodeWriteToRead(&errorCode, targetptr);
3394 osi_Assert(!errorCode || errorCode == VSALVAGE);
3396 /* break call backs on the directory */
3397 BreakCallBack(client->host, Fid, 0);
3399 /* Get the updated dir's status back to the caller */
3400 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3403 /* Update and store volume/vnode and parent vnodes back */
3404 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3406 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3407 errorCode = CallPostamble(tcon, errorCode, thost);
3409 #if FS_STATS_DETAILED
3410 FT_GetTimeOfDay(&opStopTime, 0);
3411 if (errorCode == 0) {
3413 (opP->numSuccesses)++;
3414 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3415 fs_stats_AddTo((opP->sumTime), elapsedTime);
3416 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3417 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3418 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3420 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3421 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3425 #endif /* FS_STATS_DETAILED */
3427 osi_auditU(acall, StoreACLEvent, errorCode,
3428 AUD_ID, t_client ? t_client->ViceId : 0,
3429 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3432 } /*SRXAFS_StoreACL */
3436 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3437 * should be merged when possible.
3440 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3441 struct AFSStoreStatus *InStatus,
3442 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3444 Vnode *targetptr = 0; /* pointer to input fid */
3445 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3446 Error errorCode = 0; /* return code for caller */
3447 Volume *volptr = 0; /* pointer to the volume header */
3448 struct client *client = 0; /* pointer to client structure */
3449 afs_int32 rights, anyrights; /* rights for this and any user */
3450 struct client *t_client = NULL; /* tmp ptr to client data */
3451 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3452 struct rx_connection *tcon = rx_ConnectionOf(acall);
3454 /* Get ptr to client data for user Id for logging */
3455 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3456 logHostAddr.s_addr = rxr_HostOf(tcon);
3458 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3459 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3460 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3462 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3465 * Get volume/vnode for the target file; caller's rights to it are
3469 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3470 &parentwhentargetnotdir, &client, WRITE_LOCK,
3471 &rights, &anyrights))) {
3472 goto Bad_StoreStatus;
3475 /* set volume synchronization information */
3476 SetVolumeSync(Sync, volptr);
3478 /* Check if the caller has proper permissions to store status to Fid */
3480 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3482 goto Bad_StoreStatus;
3485 * Check for a symbolic link; we can't chmod these (otherwise could
3486 * change a symlink to a mt pt or vice versa)
3488 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3490 goto Bad_StoreStatus;
3493 /* Update the status of the target's vnode */
3494 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3495 (parentwhentargetnotdir ? parentwhentargetnotdir
3496 : targetptr), volptr, 0);
3498 /* convert the write lock to a read lock before breaking callbacks */
3499 VVnodeWriteToRead(&errorCode, targetptr);
3500 osi_Assert(!errorCode || errorCode == VSALVAGE);
3502 /* Break call backs on Fid */
3503 BreakCallBack(client->host, Fid, 0);
3505 /* Return the updated status back to caller */
3506 GetStatus(targetptr, OutStatus, rights, anyrights,
3507 parentwhentargetnotdir);
3510 /* Update and store volume/vnode and parent vnodes back */
3511 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3513 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3516 } /*SAFSS_StoreStatus */
3520 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3521 struct AFSStoreStatus * InStatus,
3522 struct AFSFetchStatus * OutStatus,
3523 struct AFSVolSync * Sync)
3526 struct rx_connection *tcon;
3528 struct client *t_client = NULL; /* tmp ptr to client data */
3529 #if FS_STATS_DETAILED
3530 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3531 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3532 struct timeval elapsedTime; /* Transfer time */
3535 * Set our stats pointer, remember when the RPC operation started, and
3536 * tally the operation.
3538 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3542 FT_GetTimeOfDay(&opStartTime, 0);
3543 #endif /* FS_STATS_DETAILED */
3545 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3546 goto Bad_StoreStatus;
3548 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3551 code = CallPostamble(tcon, code, thost);
3553 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3555 #if FS_STATS_DETAILED
3556 FT_GetTimeOfDay(&opStopTime, 0);
3559 (opP->numSuccesses)++;
3560 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3561 fs_stats_AddTo((opP->sumTime), elapsedTime);
3562 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3563 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3564 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3566 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3567 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3571 #endif /* FS_STATS_DETAILED */
3573 osi_auditU(acall, StoreStatusEvent, code,
3574 AUD_ID, t_client ? t_client->ViceId : 0,
3575 AUD_FID, Fid, AUD_END);
3578 } /*SRXAFS_StoreStatus */
3582 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3583 * merged in when possible.
3586 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3587 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3589 Vnode *parentptr = 0; /* vnode of input Directory */
3590 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3591 Vnode *targetptr = 0; /* file to be deleted */
3592 Volume *volptr = 0; /* pointer to the volume header */
3593 AFSFid fileFid; /* area for Fid from the directory */
3594 Error errorCode = 0; /* error code */
3595 DirHandle dir; /* Handle for dir package I/O */
3596 struct client *client = 0; /* pointer to client structure */
3597 afs_int32 rights, anyrights; /* rights for this and any user */
3598 struct client *t_client; /* tmp ptr to client data */
3599 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3600 struct rx_connection *tcon = rx_ConnectionOf(acall);
3603 /* Get ptr to client data for user Id for logging */
3604 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3605 logHostAddr.s_addr = rxr_HostOf(tcon);
3607 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3608 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3609 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3611 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3614 * Get volume/vnode for the parent dir; caller's access rights are
3618 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3619 &parentwhentargetnotdir, &client, WRITE_LOCK,
3620 &rights, &anyrights))) {
3621 goto Bad_RemoveFile;
3623 /* set volume synchronization information */
3624 SetVolumeSync(Sync, volptr);
3626 /* Does the caller has delete (& write) access to the parent directory? */
3627 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3628 goto Bad_RemoveFile;
3631 /* Actually delete the desired file */
3633 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3635 goto Bad_RemoveFile;
3638 /* Update the vnode status of the parent dir */
3639 #if FS_STATS_DETAILED
3640 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3641 parentptr->disk.linkCount,
3642 client->InSameNetwork);
3644 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3645 parentptr->disk.linkCount);
3646 #endif /* FS_STATS_DETAILED */
3648 /* Return the updated parent dir's status back to caller */
3649 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3651 /* Handle internal callback state for the parent and the deleted file */
3652 if (targetptr->disk.linkCount == 0) {
3653 /* no references left, discard entry */
3654 DeleteFileCallBacks(&fileFid);
3655 /* convert the parent lock to a read lock before breaking callbacks */
3656 VVnodeWriteToRead(&errorCode, parentptr);
3657 osi_Assert(!errorCode || errorCode == VSALVAGE);
3659 /* convert the parent lock to a read lock before breaking callbacks */
3660 VVnodeWriteToRead(&errorCode, parentptr);
3661 osi_Assert(!errorCode || errorCode == VSALVAGE);
3662 /* convert the target lock to a read lock before breaking callbacks */
3663 VVnodeWriteToRead(&errorCode, targetptr);
3664 osi_Assert(!errorCode || errorCode == VSALVAGE);
3665 /* tell all the file has changed */
3666 BreakCallBack(client->host, &fileFid, 1);
3669 /* break call back on the directory */
3670 BreakCallBack(client->host, DirFid, 0);
3673 /* Update and store volume/vnode and parent vnodes back */
3674 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3677 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3680 } /*SAFSS_RemoveFile */
3684 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3685 struct AFSFetchStatus * OutDirStatus,
3686 struct AFSVolSync * Sync)
3689 struct rx_connection *tcon;
3691 struct client *t_client = NULL; /* tmp ptr to client data */
3692 #if FS_STATS_DETAILED
3693 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3694 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3695 struct timeval elapsedTime; /* Transfer time */
3698 * Set our stats pointer, remember when the RPC operation started, and
3699 * tally the operation.
3701 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3705 FT_GetTimeOfDay(&opStartTime, 0);
3706 #endif /* FS_STATS_DETAILED */
3708 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3709 goto Bad_RemoveFile;
3711 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3714 code = CallPostamble(tcon, code, thost);
3716 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3718 #if FS_STATS_DETAILED
3719 FT_GetTimeOfDay(&opStopTime, 0);
3722 (opP->numSuccesses)++;
3723 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3724 fs_stats_AddTo((opP->sumTime), elapsedTime);
3725 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3726 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3727 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3729 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3730 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3734 #endif /* FS_STATS_DETAILED */
3736 osi_auditU(acall, RemoveFileEvent, code,
3737 AUD_ID, t_client ? t_client->ViceId : 0,
3738 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3741 } /*SRXAFS_RemoveFile */
3745 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3746 * be merged in when possible.
3749 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3750 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3751 struct AFSFetchStatus *OutFidStatus,
3752 struct AFSFetchStatus *OutDirStatus,
3753 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3755 Vnode *parentptr = 0; /* vnode of input Directory */
3756 Vnode *targetptr = 0; /* vnode of the new file */
3757 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3758 Volume *volptr = 0; /* pointer to the volume header */
3759 Error errorCode = 0; /* error code */
3760 DirHandle dir; /* Handle for dir package I/O */
3761 struct client *client = 0; /* pointer to client structure */
3762 afs_int32 rights, anyrights; /* rights for this and any user */
3763 struct client *t_client; /* tmp ptr to client data */
3764 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3765 struct rx_connection *tcon = rx_ConnectionOf(acall);
3769 /* Get ptr to client data for user Id for logging */
3770 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3771 logHostAddr.s_addr = rxr_HostOf(tcon);
3773 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3774 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3775 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3777 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3779 if (!FileNameOK(Name)) {
3781 goto Bad_CreateFile;
3785 * Get associated volume/vnode for the parent dir; caller long are
3789 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3790 &parentwhentargetnotdir, &client, WRITE_LOCK,
3791 &rights, &anyrights))) {
3792 goto Bad_CreateFile;
3795 /* set volume synchronization information */
3796 SetVolumeSync(Sync, volptr);
3798 /* Can we write (and insert) onto the parent directory? */
3799 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3800 goto Bad_CreateFile;
3802 /* get a new vnode for the file to be created and set it up */
3804 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3805 vFile, nBlocks(0)))) {
3806 goto Bad_CreateFile;
3809 /* update the status of the parent vnode */
3810 #if FS_STATS_DETAILED
3811 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3812 parentptr->disk.linkCount,
3813 client->InSameNetwork);
3815 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3816 parentptr->disk.linkCount);
3817 #endif /* FS_STATS_DETAILED */
3819 /* update the status of the new file's vnode */
3820 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3821 parentptr, volptr, 0);
3823 /* 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 */
3824 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3825 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3827 /* convert the write lock to a read lock before breaking callbacks */
3828 VVnodeWriteToRead(&errorCode, parentptr);
3829 osi_Assert(!errorCode || errorCode == VSALVAGE);
3831 /* break call back on parent dir */
3832 BreakCallBack(client->host, DirFid, 0);
3834 /* Return a callback promise for the newly created file to the caller */
3835 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3838 /* Update and store volume/vnode and parent vnodes back */
3839 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3842 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3845 } /*SAFSS_CreateFile */
3849 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3850 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3851 struct AFSFetchStatus * OutFidStatus,
3852 struct AFSFetchStatus * OutDirStatus,
3853 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3856 struct rx_connection *tcon;
3858 struct client *t_client = NULL; /* tmp ptr to client data */
3859 #if FS_STATS_DETAILED
3860 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3861 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3862 struct timeval elapsedTime; /* Transfer time */
3865 * Set our stats pointer, remember when the RPC operation started, and
3866 * tally the operation.
3868 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3872 FT_GetTimeOfDay(&opStartTime, 0);
3873 #endif /* FS_STATS_DETAILED */
3875 memset(OutFid, 0, sizeof(struct AFSFid));
3877 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3878 goto Bad_CreateFile;
3881 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3882 OutDirStatus, CallBack, Sync);
3885 code = CallPostamble(tcon, code, thost);
3887 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3889 #if FS_STATS_DETAILED
3890 FT_GetTimeOfDay(&opStopTime, 0);
3893 (opP->numSuccesses)++;
3894 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3895 fs_stats_AddTo((opP->sumTime), elapsedTime);
3896 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3897 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3898 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3900 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3901 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3905 #endif /* FS_STATS_DETAILED */
3907 osi_auditU(acall, CreateFileEvent, code,
3908 AUD_ID, t_client ? t_client->ViceId : 0,
3909 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3912 } /*SRXAFS_CreateFile */
3916 * This routine is called exclusively from SRXAFS_Rename(), and should be
3917 * merged in when possible.
3920 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3921 struct AFSFid *NewDirFid, char *NewName,
3922 struct AFSFetchStatus *OutOldDirStatus,
3923 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3925 Vnode *oldvptr = 0; /* vnode of the old Directory */
3926 Vnode *newvptr = 0; /* vnode of the new Directory */
3927 Vnode *fileptr = 0; /* vnode of the file to move */
3928 Vnode *newfileptr = 0; /* vnode of the file to delete */
3929 Vnode *testvptr = 0; /* used in directory tree walk */
3930 Vnode *parent = 0; /* parent for use in SetAccessList */
3931 Error errorCode = 0; /* error code */
3932 Error fileCode = 0; /* used when writing Vnodes */
3933 VnodeId testnode; /* used in directory tree walk */
3934 AFSFid fileFid; /* Fid of file to move */
3935 AFSFid newFileFid; /* Fid of new file */
3936 DirHandle olddir; /* Handle for dir package I/O */
3937 DirHandle newdir; /* Handle for dir package I/O */
3938 DirHandle filedir; /* Handle for dir package I/O */
3939 DirHandle newfiledir; /* Handle for dir package I/O */
3940 Volume *volptr = 0; /* pointer to the volume header */
3941 struct client *client = 0; /* pointer to client structure */
3942 afs_int32 rights, anyrights; /* rights for this and any user */
3943 afs_int32 newrights; /* rights for this user */
3944 afs_int32 newanyrights; /* rights for any user */
3945 int doDelete; /* deleted the rename target (ref count now 0) */
3947 int updatefile = 0; /* are we changing the renamed file? (we do this
3948 * if we need to update .. on a renamed dir) */
3949 struct client *t_client; /* tmp ptr to client data */
3950 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3951 struct rx_connection *tcon = rx_ConnectionOf(acall);
3957 FidZero(&newfiledir);
3959 /* Get ptr to client data for user Id for logging */
3960 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3961 logHostAddr.s_addr = rxr_HostOf(tcon);
3963 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3964 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3965 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3966 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3968 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3970 if (!FileNameOK(NewName)) {
3974 if (OldDirFid->Volume != NewDirFid->Volume) {
3979 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3980 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3981 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3987 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3989 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3990 &parent, &client, WRITE_LOCK, &rights,
3995 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3997 newrights = rights, newanyrights = anyrights;
4000 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
4001 MustBeDIR, &parent, &client, WRITE_LOCK,
4002 &newrights, &newanyrights))) {
4008 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
4009 &parent, &client, WRITE_LOCK, &newrights,
4015 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
4016 &parent, &client, WRITE_LOCK, &rights,
4023 /* set volume synchronization information */
4024 SetVolumeSync(Sync, volptr);
4026 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
4029 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
4033 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
4034 * call to CopyOnWrite returns error, it is not necessary to revert back
4035 * the effects of the first call because the contents of the volume is
4036 * not modified, it is only replicated.
4038 if (oldvptr->disk.cloned) {
4039 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
4040 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
4043 SetDirHandle(&olddir, oldvptr);
4044 if (newvptr->disk.cloned) {
4045 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
4046 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
4050 SetDirHandle(&newdir, newvptr);
4052 /* Lookup the file to delete its vnode */
4053 if (Lookup(&olddir, OldName, &fileFid)) {
4057 if (fileFid.Vnode == oldvptr->vnodeNumber
4058 || fileFid.Vnode == newvptr->vnodeNumber) {
4059 errorCode = FSERR_ELOOP;
4062 fileFid.Volume = V_id(volptr);
4063 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
4064 if (errorCode != 0) {
4066 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
4067 OldName, errorCode));
4068 VTakeOffline(volptr);
4071 if (fileptr->disk.uniquifier != fileFid.Unique) {
4073 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
4075 VTakeOffline(volptr);
4080 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
4081 && fileptr->disk.linkCount != 1) {
4083 * Hard links exist to this file - cannot move one of the links to
4084 * a new directory because of AFS restrictions (this is the same
4085 * reason that links cannot be made across directories, i.e.
4092 /* Lookup the new file */
4093 if (!(Lookup(&newdir, NewName, &newFileFid))) {
4094 if (readonlyServer) {
4095 errorCode = VREADONLY;
4098 if (!(newrights & PRSFS_DELETE)) {
4102 if (newFileFid.Vnode == oldvptr->vnodeNumber
4103 || newFileFid.Vnode == newvptr->vnodeNumber
4104 || newFileFid.Vnode == fileFid.Vnode) {
4108 newFileFid.Volume = V_id(volptr);
4110 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4111 if (errorCode != 0) {
4113 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4114 NewName, errorCode));
4115 VTakeOffline(volptr);
4118 if (fileptr->disk.uniquifier != fileFid.Unique) {
4120 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4122 VTakeOffline(volptr);
4126 SetDirHandle(&newfiledir, newfileptr);
4127 /* Now check that we're moving directories over directories properly, etc.
4128 * return proper POSIX error codes:
4129 * if fileptr is a file and new is a dir: EISDIR.
4130 * if fileptr is a dir and new is a file: ENOTDIR.
4131 * Also, dir to be removed must be empty, of course.
4133 if (newfileptr->disk.type == vDirectory) {
4134 if (fileptr->disk.type != vDirectory) {
4138 if ((IsEmpty(&newfiledir))) {
4143 if (fileptr->disk.type == vDirectory) {
4144 errorCode = ENOTDIR;
4151 * ok - now we check that the old name is not above new name in the
4152 * directory structure. This is to prevent removing a subtree alltogether
4154 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4155 afs_int32 forpass = 0, vnum = 0, top = 0;
4156 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4157 if (testnode > vnum) vnum = testnode;
4158 if (forpass > vnum) {
4159 errorCode = FSERR_ELOOP;
4162 if (testnode == oldvptr->vnodeNumber) {
4163 testnode = oldvptr->disk.parent;
4166 if ((testnode == fileptr->vnodeNumber)
4167 || (testnode == newvptr->vnodeNumber)) {
4168 errorCode = FSERR_ELOOP;
4171 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4172 errorCode = FSERR_ELOOP;
4175 if (testnode == 1) top = 1;
4176 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4177 osi_Assert(errorCode == 0);
4178 testnode = testvptr->disk.parent;
4179 VPutVnode(&errorCode, testvptr);
4180 if ((top == 1) && (testnode != 0)) {
4181 VTakeOffline(volptr);
4183 ("Volume %u now offline, must be salvaged.\n",
4188 osi_Assert(errorCode == 0);
4192 if (fileptr->disk.type == vDirectory) {
4193 SetDirHandle(&filedir, fileptr);
4194 if (oldvptr != newvptr) {
4195 /* we always need to update .. if we've moving fileptr to a
4196 * different directory */
4199 struct AFSFid unused;
4201 code = Lookup(&filedir, "..", &unused);
4202 if (code == ENOENT) {
4203 /* only update .. if it doesn't already exist */
4209 /* Do the CopyonWrite first before modifying anything else. Copying is
4210 * required when we have to change entries for ..
4212 if (updatefile && (fileptr->disk.cloned)) {
4213 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4214 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4218 /* If the new name exists already, delete it and the file it points to */
4221 /* Delete NewName from its directory */
4222 code = Delete(&newdir, NewName);
4223 osi_Assert(code == 0);
4225 /* Drop the link count */
4226 newfileptr->disk.linkCount--;
4227 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4228 afs_fsize_t newSize;
4229 VN_GET_LEN(newSize, newfileptr);
4230 VAdjustDiskUsage((Error *) & errorCode, volptr,
4231 (afs_sfsize_t) - nBlocks(newSize), 0);
4232 if (VN_GET_INO(newfileptr)) {
4233 IH_REALLYCLOSE(newfileptr->handle);
4235 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4236 V_parentId(volptr));
4237 IH_RELEASE(newfileptr->handle);
4238 if (errorCode == -1) {
4240 ("Del: inode=%s, name=%s, errno=%d\n",
4241 PrintInode(stmp, VN_GET_INO(newfileptr)),
4243 if ((errno != ENOENT) && (errno != EIO)
4244 && (errno != ENXIO))
4245 ViceLog(0, ("Do we need to fsck?"));
4248 VN_SET_INO(newfileptr, (Inode) 0);
4249 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4252 /* Link count did not drop to zero.
4253 * Mark NewName vnode as changed - updates stime.
4255 newfileptr->changed_newTime = 1;
4260 * If the create below fails, and the delete above worked, we have
4261 * removed the new name and not replaced it. This is not very likely,
4262 * but possible. We could try to put the old file back, but it is
4263 * highly unlikely that it would work since it would involve issuing
4266 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4269 /* Delete the old name */
4270 osi_Assert(Delete(&olddir, (char *)OldName) == 0);
4272 /* if the directory length changes, reflect it in the statistics */
4273 #if FS_STATS_DETAILED
4274 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4275 oldvptr->disk.linkCount, client->InSameNetwork);
4276 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4277 newvptr->disk.linkCount, client->InSameNetwork);
4279 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4280 oldvptr->disk.linkCount);
4281 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4282 newvptr->disk.linkCount);
4283 #endif /* FS_STATS_DETAILED */
4285 if (oldvptr == newvptr)
4286 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4288 if (fileptr->disk.parent != newvptr->vnodeNumber) {
4289 fileptr->disk.parent = newvptr->vnodeNumber;
4290 fileptr->changed_newTime = 1;
4293 /* if we are dealing with a rename of a directory, and we need to
4294 * update the .. entry of that directory */
4296 osi_Assert(!fileptr->disk.cloned);
4298 fileptr->changed_newTime = 1; /* status change of moved file */
4300 /* fix .. to point to the correct place */
4301 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4302 osi_Assert(Create(&filedir, "..", NewDirFid) == 0);
4303 fileptr->disk.dataVersion++;
4305 /* if the parent directories are different the link counts have to be */
4306 /* changed due to .. in the renamed directory */
4307 if (oldvptr != newvptr) {
4308 oldvptr->disk.linkCount--;
4309 newvptr->disk.linkCount++;
4313 /* set up return status */
4314 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4315 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4316 if (newfileptr && doDelete) {
4317 DeleteFileCallBacks(&newFileFid); /* no other references */
4322 /* convert the write locks to a read locks before breaking callbacks */
4323 VVnodeWriteToRead(&errorCode, newvptr);
4324 osi_Assert(!errorCode || errorCode == VSALVAGE);
4325 if (oldvptr != newvptr) {
4326 VVnodeWriteToRead(&errorCode, oldvptr);
4327 osi_Assert(!errorCode || errorCode == VSALVAGE);
4329 if (newfileptr && !doDelete) {
4330 /* convert the write lock to a read lock before breaking callbacks */
4331 VVnodeWriteToRead(&errorCode, newfileptr);
4332 osi_Assert(!errorCode || errorCode == VSALVAGE);
4335 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4336 BreakCallBack(client->host, NewDirFid, 0);
4337 if (oldvptr != newvptr) {
4338 BreakCallBack(client->host, OldDirFid, 0);
4341 /* if a dir moved, .. changed */
4342 /* we do not give an AFSFetchStatus structure back to the
4343 * originating client, and the file's status has changed, so be
4344 * sure to send a callback break. In theory the client knows
4345 * enough to know that the callback could be broken implicitly,
4346 * but that may not be clear, and some client implementations
4347 * may not know to. */
4348 BreakCallBack(client->host, &fileFid, 1);
4351 /* Note: it is not necessary to break the callback */
4353 DeleteFileCallBacks(&newFileFid); /* no other references */
4355 /* other's still exist (with wrong link count) */
4356 BreakCallBack(client->host, &newFileFid, 1);
4361 VPutVnode(&fileCode, newfileptr);
4362 osi_Assert(fileCode == 0);
4364 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4365 newvptr : 0), oldvptr, volptr, &client);
4369 FidZap(&newfiledir);
4370 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4377 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4378 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4379 struct AFSFetchStatus * OutOldDirStatus,
4380 struct AFSFetchStatus * OutNewDirStatus,
4381 struct AFSVolSync * Sync)
4384 struct rx_connection *tcon;
4386 struct client *t_client = NULL; /* tmp ptr to client data */
4387 #if FS_STATS_DETAILED
4388 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4389 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4390 struct timeval elapsedTime; /* Transfer time */
4393 * Set our stats pointer, remember when the RPC operation started, and
4394 * tally the operation.
4396 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4400 FT_GetTimeOfDay(&opStartTime, 0);
4401 #endif /* FS_STATS_DETAILED */
4403 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4407 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4408 OutOldDirStatus, OutNewDirStatus, Sync);
4411 code = CallPostamble(tcon, code, thost);
4413 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4415 #if FS_STATS_DETAILED
4416 FT_GetTimeOfDay(&opStopTime, 0);
4419 (opP->numSuccesses)++;
4420 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4421 fs_stats_AddTo((opP->sumTime), elapsedTime);
4422 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4423 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4424 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4426 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4427 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4431 #endif /* FS_STATS_DETAILED */
4433 osi_auditU(acall, RenameFileEvent, code,
4434 AUD_ID, t_client ? t_client->ViceId : 0,
4435 AUD_FID, OldDirFid, AUD_STR, OldName,
4436 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4439 } /*SRXAFS_Rename */
4443 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4444 * merged into it when possible.
4447 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4448 char *LinkContents, struct AFSStoreStatus *InStatus,
4449 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4450 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4452 Vnode *parentptr = 0; /* vnode of input Directory */
4453 Vnode *targetptr = 0; /* vnode of the new link */
4454 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4455 Error errorCode = 0; /* error code */
4458 DirHandle dir; /* Handle for dir package I/O */
4459 Volume *volptr = 0; /* pointer to the volume header */
4460 struct client *client = 0; /* pointer to client structure */
4461 afs_int32 rights, anyrights; /* rights for this and any user */
4462 struct client *t_client; /* tmp ptr to client data */
4463 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4465 struct rx_connection *tcon = rx_ConnectionOf(acall);
4469 /* Get ptr to client data for user Id for logging */
4470 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4471 logHostAddr.s_addr = rxr_HostOf(tcon);
4473 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4474 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4475 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4477 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4479 if (!FileNameOK(Name)) {
4485 * Get the vnode and volume for the parent dir along with the caller's
4489 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4490 &parentwhentargetnotdir, &client, WRITE_LOCK,
4491 &rights, &anyrights))) {
4495 /* set volume synchronization information */
4496 SetVolumeSync(Sync, volptr);
4498 /* Does the caller has insert (and write) access to the parent directory? */
4499 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4504 * If we're creating a mount point (any x bits clear), we must have
4505 * administer access to the directory, too. Always allow sysadmins
4508 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4509 if (readonlyServer) {
4510 errorCode = VREADONLY;
4514 * We have a mountpoint, 'cause we're trying to set the Unix mode
4515 * bits to something with some x bits missing (default mode bits
4516 * if AFS_SETMODE is false is 0777)
4518 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4524 /* get a new vnode for the symlink and set it up */
4526 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4527 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4531 /* update the status of the parent vnode */
4532 #if FS_STATS_DETAILED
4533 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4534 parentptr->disk.linkCount,
4535 client->InSameNetwork);
4537 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4538 parentptr->disk.linkCount);
4539 #endif /* FS_STATS_DETAILED */
4541 /* update the status of the new symbolic link file vnode */
4542 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4543 parentptr, volptr, strlen((char *)LinkContents));
4545 /* Write the contents of the symbolic link name into the target inode */
4546 fdP = IH_OPEN(targetptr->handle);
4548 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4550 VTakeOffline(volptr);
4551 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4555 len = strlen((char *) LinkContents);
4556 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4558 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4561 * Set up and return modified status for the parent dir and new symlink
4564 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4565 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4567 /* convert the write lock to a read lock before breaking callbacks */
4568 VVnodeWriteToRead(&errorCode, parentptr);
4569 osi_Assert(!errorCode || errorCode == VSALVAGE);
4571 /* break call back on the parent dir */
4572 BreakCallBack(client->host, DirFid, 0);
4575 /* Write the all modified vnodes (parent, new files) and volume back */
4576 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4579 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4580 return ( errorCode ? errorCode : code );
4582 } /*SAFSS_Symlink */
4586 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4587 struct AFSFid *DirFid, /* Parent dir's fid */
4588 char *Name, /* File name to create */
4589 char *LinkContents, /* Contents of the new created file */
4590 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4591 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4592 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4593 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4594 struct AFSVolSync *Sync)
4597 struct rx_connection *tcon;
4599 struct client *t_client = NULL; /* tmp ptr to client data */
4600 #if FS_STATS_DETAILED
4601 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4602 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4603 struct timeval elapsedTime; /* Transfer time */
4606 * Set our stats pointer, remember when the RPC operation started, and
4607 * tally the operation.
4609 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4613 FT_GetTimeOfDay(&opStartTime, 0);
4614 #endif /* FS_STATS_DETAILED */
4616 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4620 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4621 OutFidStatus, OutDirStatus, Sync);
4624 code = CallPostamble(tcon, code, thost);
4626 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4628 #if FS_STATS_DETAILED
4629 FT_GetTimeOfDay(&opStopTime, 0);
4632 (opP->numSuccesses)++;
4633 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4634 fs_stats_AddTo((opP->sumTime), elapsedTime);
4635 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4636 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4637 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4639 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4640 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4644 #endif /* FS_STATS_DETAILED */
4646 osi_auditU(acall, SymlinkEvent, code,
4647 AUD_ID, t_client ? t_client->ViceId : 0,
4648 AUD_FID, DirFid, AUD_STR, Name,
4649 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4652 } /*SRXAFS_Symlink */
4656 * This routine is called exclusively by SRXAFS_Link(), and should be
4657 * merged into it when possible.
4660 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4661 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4662 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4664 Vnode *parentptr = 0; /* vnode of input Directory */
4665 Vnode *targetptr = 0; /* vnode of the new file */
4666 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4667 Volume *volptr = 0; /* pointer to the volume header */
4668 Error errorCode = 0; /* error code */
4669 DirHandle dir; /* Handle for dir package I/O */
4670 struct client *client = 0; /* pointer to client structure */
4671 afs_int32 rights, anyrights; /* rights for this and any user */
4672 struct client *t_client; /* tmp ptr to client data */
4673 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4674 struct rx_connection *tcon = rx_ConnectionOf(acall);
4678 /* Get ptr to client data for user Id for logging */
4679 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4680 logHostAddr.s_addr = rxr_HostOf(tcon);
4682 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4683 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4684 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4685 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4687 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4689 if (DirFid->Volume != ExistingFid->Volume) {
4693 if (!FileNameOK(Name)) {
4699 * Get the vnode and volume for the parent dir along with the caller's
4703 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4704 &parentwhentargetnotdir, &client, WRITE_LOCK,
4705 &rights, &anyrights))) {
4709 /* set volume synchronization information */
4710 SetVolumeSync(Sync, volptr);
4712 /* Can the caller insert into the parent directory? */
4713 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4717 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4718 /* AFS fileservers always have directory vnodes that are odd. */
4723 /* get the file vnode */
4725 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4728 if (targetptr->disk.type != vFile) {
4732 if (targetptr->disk.parent != DirFid->Vnode) {
4736 if (parentptr->disk.cloned) {
4737 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4738 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4739 goto Bad_Link; /* disk full error */
4742 /* add the name to the directory */
4743 SetDirHandle(&dir, parentptr);
4744 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4748 /* update the status in the parent vnode */
4749 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4750 #if FS_STATS_DETAILED
4751 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4752 parentptr->disk.linkCount,
4753 client->InSameNetwork);
4755 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4756 parentptr->disk.linkCount);
4757 #endif /* FS_STATS_DETAILED */
4759 targetptr->disk.linkCount++;
4760 targetptr->disk.author = client->ViceId;
4761 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4763 /* set up return status */
4764 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4765 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4767 /* convert the write locks to read locks before breaking callbacks */
4768 VVnodeWriteToRead(&errorCode, targetptr);
4769 osi_Assert(!errorCode || errorCode == VSALVAGE);
4770 VVnodeWriteToRead(&errorCode, parentptr);
4771 osi_Assert(!errorCode || errorCode == VSALVAGE);
4773 /* break call back on DirFid */
4774 BreakCallBack(client->host, DirFid, 0);
4776 * We also need to break the callback for the file that is hard-linked since part
4777 * of its status (like linkcount) is changed
4779 BreakCallBack(client->host, ExistingFid, 0);
4782 /* Write the all modified vnodes (parent, new files) and volume back */
4783 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4786 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4793 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4794 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4795 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4798 struct rx_connection *tcon;
4800 struct client *t_client = NULL; /* tmp ptr to client data */
4801 #if FS_STATS_DETAILED
4802 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4803 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4804 struct timeval elapsedTime; /* Transfer time */
4807 * Set our stats pointer, remember when the RPC operation started, and
4808 * tally the operation.
4810 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4814 FT_GetTimeOfDay(&opStartTime, 0);
4815 #endif /* FS_STATS_DETAILED */
4817 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4821 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4822 OutDirStatus, Sync);
4825 code = CallPostamble(tcon, code, thost);
4827 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4829 #if FS_STATS_DETAILED
4830 FT_GetTimeOfDay(&opStopTime, 0);
4833 (opP->numSuccesses)++;
4834 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4835 fs_stats_AddTo((opP->sumTime), elapsedTime);
4836 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4837 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4838 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4840 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4841 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4845 #endif /* FS_STATS_DETAILED */
4847 osi_auditU(acall, LinkEvent, code,
4848 AUD_ID, t_client ? t_client->ViceId : 0,
4849 AUD_FID, DirFid, AUD_STR, Name,
4850 AUD_FID, ExistingFid, AUD_END);
4857 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4858 * merged into it when possible.
4861 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4862 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4863 struct AFSFetchStatus *OutFidStatus,
4864 struct AFSFetchStatus *OutDirStatus,
4865 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4867 Vnode *parentptr = 0; /* vnode of input Directory */
4868 Vnode *targetptr = 0; /* vnode of the new file */
4869 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4870 Volume *volptr = 0; /* pointer to the volume header */
4871 Error errorCode = 0; /* error code */
4872 struct acl_accessList *newACL; /* Access list */
4873 int newACLSize; /* Size of access list */
4874 DirHandle dir; /* Handle for dir package I/O */
4875 DirHandle parentdir; /* Handle for dir package I/O */
4876 struct client *client = 0; /* pointer to client structure */
4877 afs_int32 rights, anyrights; /* rights for this and any user */
4878 struct client *t_client; /* tmp ptr to client data */
4879 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4880 struct rx_connection *tcon = rx_ConnectionOf(acall);
4883 FidZero(&parentdir);
4885 /* Get ptr to client data for user Id for logging */
4886 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4887 logHostAddr.s_addr = rxr_HostOf(tcon);
4889 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4890 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4891 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4893 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4895 if (!FileNameOK(Name)) {
4901 * Get the vnode and volume for the parent dir along with the caller's
4905 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4906 &parentwhentargetnotdir, &client, WRITE_LOCK,
4907 &rights, &anyrights))) {
4911 /* set volume synchronization information */
4912 SetVolumeSync(Sync, volptr);
4914 /* Write access to the parent directory? */
4915 #ifdef DIRCREATE_NEED_WRITE
4917 * requires w access for the user to create a directory. this
4918 * closes a loophole in the current security arrangement, since a
4919 * user with i access only can create a directory and get the
4920 * implcit a access that goes with dir ownership, and proceed to
4921 * subvert quota in the volume.
4923 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4924 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4926 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4927 #endif /* DIRCREATE_NEED_WRITE */
4930 #define EMPTYDIRBLOCKS 2
4931 /* get a new vnode and set it up */
4933 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4934 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4938 /* Update the status for the parent dir */
4939 #if FS_STATS_DETAILED
4940 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4941 parentptr->disk.linkCount + 1,
4942 client->InSameNetwork);
4944 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4945 parentptr->disk.linkCount + 1);
4946 #endif /* FS_STATS_DETAILED */
4948 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4949 osi_Assert((SetAccessList
4950 (&targetptr, &volptr, &newACL, &newACLSize,
4951 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4952 osi_Assert(parentwhentargetnotdir == 0);
4953 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4955 /* update the status for the target vnode */
4956 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4957 parentptr, volptr, 0);
4959 /* Actually create the New directory in the directory package */
4960 SetDirHandle(&dir, targetptr);
4961 osi_Assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4963 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4965 /* set up return status */
4966 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4967 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4969 /* convert the write lock to a read lock before breaking callbacks */
4970 VVnodeWriteToRead(&errorCode, parentptr);
4971 osi_Assert(!errorCode || errorCode == VSALVAGE);
4973 /* break call back on DirFid */
4974 BreakCallBack(client->host, DirFid, 0);
4976 /* Return a callback promise to caller */
4977 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4980 /* Write the all modified vnodes (parent, new files) and volume back */
4981 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4985 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4988 } /*SAFSS_MakeDir */
4992 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4993 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4994 struct AFSFetchStatus * OutFidStatus,
4995 struct AFSFetchStatus * OutDirStatus,
4996 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4999 struct rx_connection *tcon;
5001 struct client *t_client = NULL; /* tmp ptr to client data */
5002 #if FS_STATS_DETAILED
5003 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5004 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5005 struct timeval elapsedTime; /* Transfer time */
5008 * Set our stats pointer, remember when the RPC operation started, and
5009 * tally the operation.
5011 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
5015 FT_GetTimeOfDay(&opStartTime, 0);
5016 #endif /* FS_STATS_DETAILED */
5017 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5021 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
5022 OutDirStatus, CallBack, Sync);
5025 code = CallPostamble(tcon, code, thost);
5027 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5029 #if FS_STATS_DETAILED
5030 FT_GetTimeOfDay(&opStopTime, 0);
5033 (opP->numSuccesses)++;
5034 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5035 fs_stats_AddTo((opP->sumTime), elapsedTime);
5036 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5037 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5038 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5040 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5041 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5045 #endif /* FS_STATS_DETAILED */
5047 osi_auditU(acall, MakeDirEvent, code,
5048 AUD_ID, t_client ? t_client->ViceId : 0,
5049 AUD_FID, DirFid, AUD_STR, Name,
5050 AUD_FID, OutFid, AUD_END);
5053 } /*SRXAFS_MakeDir */
5057 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
5058 * merged into it when possible.
5061 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
5062 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
5064 Vnode *parentptr = 0; /* vnode of input Directory */
5065 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5066 Vnode *targetptr = 0; /* file to be deleted */
5067 AFSFid fileFid; /* area for Fid from the directory */
5068 Error errorCode = 0; /* error code */
5069 DirHandle dir; /* Handle for dir package I/O */
5070 Volume *volptr = 0; /* pointer to the volume header */
5071 struct client *client = 0; /* pointer to client structure */
5072 afs_int32 rights, anyrights; /* rights for this and any user */
5073 struct client *t_client; /* tmp ptr to client data */
5074 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5075 struct rx_connection *tcon = rx_ConnectionOf(acall);
5079 /* Get ptr to client data for user Id for logging */
5080 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5081 logHostAddr.s_addr = rxr_HostOf(tcon);
5083 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
5084 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
5085 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5087 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
5090 * Get the vnode and volume for the parent dir along with the caller's
5094 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
5095 &parentwhentargetnotdir, &client, WRITE_LOCK,
5096 &rights, &anyrights))) {
5100 /* set volume synchronization information */
5101 SetVolumeSync(Sync, volptr);
5103 /* Does the caller has delete (&write) access to the parent dir? */
5104 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
5108 /* Do the actual delete of the desired (empty) directory, Name */
5110 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
5115 /* Update the status for the parent dir; link count is also adjusted */
5116 #if FS_STATS_DETAILED
5117 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5118 parentptr->disk.linkCount - 1,
5119 client->InSameNetwork);
5121 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5122 parentptr->disk.linkCount - 1);
5123 #endif /* FS_STATS_DETAILED */
5125 /* Return to the caller the updated parent dir status */
5126 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
5129 * Note: it is not necessary to break the callback on fileFid, since
5130 * refcount is now 0, so no one should be able to refer to the dir
5133 DeleteFileCallBacks(&fileFid);
5135 /* convert the write lock to a read lock before breaking callbacks */
5136 VVnodeWriteToRead(&errorCode, parentptr);
5137 osi_Assert(!errorCode || errorCode == VSALVAGE);
5139 /* break call back on DirFid and fileFid */
5140 BreakCallBack(client->host, DirFid, 0);
5143 /* Write the all modified vnodes (parent, new files) and volume back */
5144 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5147 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5150 } /*SAFSS_RemoveDir */
5154 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5155 struct AFSFetchStatus * OutDirStatus,
5156 struct AFSVolSync * Sync)
5159 struct rx_connection *tcon;
5161 struct client *t_client = NULL; /* tmp ptr to client data */
5162 #if FS_STATS_DETAILED
5163 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5164 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5165 struct timeval elapsedTime; /* Transfer time */
5168 * Set our stats pointer, remember when the RPC operation started, and
5169 * tally the operation.
5171 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5175 FT_GetTimeOfDay(&opStartTime, 0);
5176 #endif /* FS_STATS_DETAILED */
5178 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5181 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5184 code = CallPostamble(tcon, code, thost);
5186 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5188 #if FS_STATS_DETAILED
5189 FT_GetTimeOfDay(&opStopTime, 0);
5192 (opP->numSuccesses)++;
5193 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5194 fs_stats_AddTo((opP->sumTime), elapsedTime);
5195 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5196 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5197 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5199 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5200 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5204 #endif /* FS_STATS_DETAILED */
5206 osi_auditU(acall, RemoveDirEvent, code,
5207 AUD_ID, t_client ? t_client->ViceId : 0,
5208 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5211 } /*SRXAFS_RemoveDir */
5215 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5216 * merged into it when possible.
5219 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5220 struct AFSVolSync *Sync)
5222 Vnode *targetptr = 0; /* vnode of input file */
5223 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5224 Error errorCode = 0; /* error code */
5225 Volume *volptr = 0; /* pointer to the volume header */
5226 struct client *client = 0; /* pointer to client structure */
5227 afs_int32 rights, anyrights; /* rights for this and any user */
5228 struct client *t_client; /* tmp ptr to client data */
5229 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5230 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5231 struct rx_connection *tcon = rx_ConnectionOf(acall);
5233 if (type != LockRead && type != LockWrite) {
5237 /* Get ptr to client data for user Id for logging */
5238 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5239 logHostAddr.s_addr = rxr_HostOf(tcon);
5241 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5242 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5243 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5245 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5248 * Get the vnode and volume for the desired file along with the caller's
5252 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5253 &parentwhentargetnotdir, &client, WRITE_LOCK,
5254 &rights, &anyrights))) {
5258 /* set volume synchronization information */
5259 SetVolumeSync(Sync, volptr);
5261 /* Handle the particular type of set locking, type */
5262 errorCode = HandleLocking(targetptr, client, rights, type);
5265 /* Write the all modified vnodes (parent, new files) and volume back */
5266 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5269 if ((errorCode == VREADONLY) && (type == LockRead))
5270 errorCode = 0; /* allow read locks on RO volumes without saving state */
5272 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5275 } /*SAFSS_SetLock */
5279 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5280 ViceLockType type, struct AFSVolSync * Sync)
5282 return SRXAFS_SetLock(acall, Fid, type, Sync);
5283 } /*SRXAFS_OldSetLock */
5287 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5288 struct AFSVolSync * Sync)
5291 struct rx_connection *tcon;
5293 struct client *t_client = NULL; /* tmp ptr to client data */
5294 #if FS_STATS_DETAILED
5295 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5296 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5297 struct timeval elapsedTime; /* Transfer time */
5300 * Set our stats pointer, remember when the RPC operation started, and
5301 * tally the operation.
5303 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5307 FT_GetTimeOfDay(&opStartTime, 0);
5308 #endif /* FS_STATS_DETAILED */
5310 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5313 code = SAFSS_SetLock(acall, Fid, type, Sync);
5316 code = CallPostamble(tcon, code, thost);
5318 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5320 #if FS_STATS_DETAILED
5321 FT_GetTimeOfDay(&opStopTime, 0);
5324 (opP->numSuccesses)++;
5325 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5326 fs_stats_AddTo((opP->sumTime), elapsedTime);
5327 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5328 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5329 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5331 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5332 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5336 #endif /* FS_STATS_DETAILED */
5338 osi_auditU(acall, SetLockEvent, code,
5339 AUD_ID, t_client ? t_client->ViceId : 0,
5340 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5342 } /*SRXAFS_SetLock */
5346 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5347 * merged into it when possible.
5350 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5351 struct AFSVolSync *Sync)
5353 Vnode *targetptr = 0; /* vnode of input file */
5354 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5355 Error errorCode = 0; /* error code */
5356 Volume *volptr = 0; /* pointer to the volume header */
5357 struct client *client = 0; /* pointer to client structure */
5358 afs_int32 rights, anyrights; /* rights for this and any user */
5359 struct client *t_client; /* tmp ptr to client data */
5360 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5361 struct rx_connection *tcon = rx_ConnectionOf(acall);
5363 /* Get ptr to client data for user Id for logging */
5364 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5365 logHostAddr.s_addr = rxr_HostOf(tcon);
5367 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5368 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5369 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5371 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5374 * Get the vnode and volume for the desired file along with the caller's
5378 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5379 &parentwhentargetnotdir, &client, WRITE_LOCK,
5380 &rights, &anyrights))) {
5381 goto Bad_ExtendLock;
5384 /* set volume synchronization information */
5385 SetVolumeSync(Sync, volptr);
5387 /* Handle the actual lock extension */
5388 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5391 /* Put back file's vnode and volume */
5392 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5395 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5396 errorCode = 0; /* under our generous policy re RO vols */
5398 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5401 } /*SAFSS_ExtendLock */
5405 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5406 struct AFSVolSync * Sync)
5408 return SRXAFS_ExtendLock(acall, Fid, Sync);
5409 } /*SRXAFS_OldExtendLock */
5413 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5414 struct AFSVolSync * Sync)
5417 struct rx_connection *tcon;
5419 struct client *t_client = NULL; /* tmp ptr to client data */
5420 #if FS_STATS_DETAILED
5421 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5422 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5423 struct timeval elapsedTime; /* Transfer time */
5426 * Set our stats pointer, remember when the RPC operation started, and
5427 * tally the operation.
5429 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5433 FT_GetTimeOfDay(&opStartTime, 0);
5434 #endif /* FS_STATS_DETAILED */
5436 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5437 goto Bad_ExtendLock;
5439 code = SAFSS_ExtendLock(acall, Fid, Sync);
5442 code = CallPostamble(tcon, code, thost);
5444 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5446 #if FS_STATS_DETAILED
5447 FT_GetTimeOfDay(&opStopTime, 0);
5450 (opP->numSuccesses)++;
5451 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5452 fs_stats_AddTo((opP->sumTime), elapsedTime);
5453 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5454 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5455 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5457 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5458 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5462 #endif /* FS_STATS_DETAILED */
5464 osi_auditU(acall, ExtendLockEvent, code,
5465 AUD_ID, t_client ? t_client->ViceId : 0,
5466 AUD_FID, Fid, AUD_END);
5469 } /*SRXAFS_ExtendLock */
5473 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5474 * merged into it when possible.
5477 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5478 struct AFSVolSync *Sync)
5480 Vnode *targetptr = 0; /* vnode of input file */
5481 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5482 Error errorCode = 0; /* error code */
5483 Volume *volptr = 0; /* pointer to the volume header */
5484 struct client *client = 0; /* pointer to client structure */
5485 afs_int32 rights, anyrights; /* rights for this and any user */
5486 struct client *t_client; /* tmp ptr to client data */
5487 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5488 struct rx_connection *tcon = rx_ConnectionOf(acall);
5490 /* Get ptr to client data for user Id for logging */
5491 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5492 logHostAddr.s_addr = rxr_HostOf(tcon);
5494 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5495 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5496 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5498 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5501 * Get the vnode and volume for the desired file along with the caller's
5505 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5506 &parentwhentargetnotdir, &client, WRITE_LOCK,
5507 &rights, &anyrights))) {
5508 goto Bad_ReleaseLock;
5511 /* set volume synchronization information */
5512 SetVolumeSync(Sync, volptr);
5514 /* Handle the actual lock release */
5515 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5516 goto Bad_ReleaseLock;
5518 /* if no more locks left, a callback would be triggered here */
5519 if (targetptr->disk.lock.lockCount <= 0) {
5520 /* convert the write lock to a read lock before breaking callbacks */
5521 VVnodeWriteToRead(&errorCode, targetptr);
5522 osi_Assert(!errorCode || errorCode == VSALVAGE);
5523 BreakCallBack(client->host, Fid, 0);
5527 /* Put back file's vnode and volume */
5528 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5531 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5532 errorCode = 0; /* under our generous policy re RO vols */
5534 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5537 } /*SAFSS_ReleaseLock */
5541 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5542 struct AFSVolSync * Sync)
5544 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5545 } /*SRXAFS_OldReleaseLock */
5549 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5550 struct AFSVolSync * Sync)
5553 struct rx_connection *tcon;
5555 struct client *t_client = NULL; /* tmp ptr to client data */
5556 #if FS_STATS_DETAILED
5557 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5558 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5559 struct timeval elapsedTime; /* Transfer time */
5562 * Set our stats pointer, remember when the RPC operation started, and
5563 * tally the operation.
5565 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5569 FT_GetTimeOfDay(&opStartTime, 0);
5570 #endif /* FS_STATS_DETAILED */
5572 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5573 goto Bad_ReleaseLock;
5575 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5578 code = CallPostamble(tcon, code, thost);
5580 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5582 #if FS_STATS_DETAILED
5583 FT_GetTimeOfDay(&opStopTime, 0);
5586 (opP->numSuccesses)++;
5587 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5588 fs_stats_AddTo((opP->sumTime), elapsedTime);
5589 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5590 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5591 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5593 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5594 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5598 #endif /* FS_STATS_DETAILED */
5600 osi_auditU(acall, ReleaseLockEvent, code,
5601 AUD_ID, t_client ? t_client->ViceId : 0,
5602 AUD_FID, Fid, AUD_END);
5605 } /*SRXAFS_ReleaseLock */
5609 SetSystemStats(struct AFSStatistics *stats)
5611 /* Fix this sometime soon.. */
5612 /* Because hey, it's not like we have a network monitoring protocol... */
5613 struct timeval time;
5615 /* this works on all system types */
5616 FT_GetTimeOfDay(&time, 0);
5617 stats->CurrentTime = time.tv_sec;
5618 } /*SetSystemStats */
5621 SetAFSStats(struct AFSStatistics *stats)
5623 extern afs_int32 StartTime, CurrentConnections;
5627 stats->CurrentMsgNumber = 0;
5628 stats->OldestMsgNumber = 0;
5629 stats->StartTime = StartTime;
5630 stats->CurrentConnections = CurrentConnections;
5631 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5632 stats->TotalFetchs =
5633 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5634 AFSCallStats.FetchStatus;
5635 stats->FetchDatas = AFSCallStats.FetchData;
5636 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5637 seconds = AFSCallStats.AccumFetchTime / 1000;
5640 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5641 stats->TotalStores =
5642 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5643 AFSCallStats.StoreStatus;
5644 stats->StoreDatas = AFSCallStats.StoreData;
5645 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5646 seconds = AFSCallStats.AccumStoreTime / 1000;
5649 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5651 stats->ProcessSize = -1; /* TODO: */
5653 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5656 h_GetWorkStats((int *)&(stats->WorkStations),
5657 (int *)&(stats->ActiveWorkStations), (int *)0,
5658 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5662 /* Get disk related information from all AFS partitions. */
5665 SetVolumeStats(struct AFSStatistics *stats)
5667 struct DiskPartition64 *part;
5670 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5671 part = part->next) {
5672 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5673 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5674 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5675 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5678 while (i < AFS_MSTATDISKS) {
5679 stats->Disks[i].TotalBlocks = -1;
5682 } /*SetVolumeStats */
5685 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5688 struct rx_connection *tcon = rx_ConnectionOf(acall);
5690 struct client *t_client = NULL; /* tmp ptr to client data */
5691 #if FS_STATS_DETAILED
5692 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5693 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5694 struct timeval elapsedTime; /* Transfer time */
5697 * Set our stats pointer, remember when the RPC operation started, and
5698 * tally the operation.
5700 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5704 FT_GetTimeOfDay(&opStartTime, 0);
5705 #endif /* FS_STATS_DETAILED */
5707 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5708 goto Bad_GetStatistics;
5710 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5712 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5714 memset(Statistics, 0, sizeof(*Statistics));
5715 SetAFSStats((struct AFSStatistics *)Statistics);
5716 SetVolumeStats((struct AFSStatistics *)Statistics);
5717 SetSystemStats((struct AFSStatistics *)Statistics);
5720 code = CallPostamble(tcon, code, thost);
5722 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5724 #if FS_STATS_DETAILED
5725 FT_GetTimeOfDay(&opStopTime, 0);
5728 (opP->numSuccesses)++;
5729 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5730 fs_stats_AddTo((opP->sumTime), elapsedTime);
5731 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5732 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5733 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5735 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5736 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5740 #endif /* FS_STATS_DETAILED */
5742 osi_auditU(acall, GetStatisticsEvent, code,
5743 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5745 } /*SRXAFS_GetStatistics */
5749 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5751 extern afs_int32 StartTime, CurrentConnections;
5754 struct rx_connection *tcon = rx_ConnectionOf(acall);
5756 struct client *t_client = NULL; /* tmp ptr to client data */
5757 struct timeval time;
5758 #if FS_STATS_DETAILED
5759 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5760 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5761 struct timeval elapsedTime; /* Transfer time */
5764 * Set our stats pointer, remember when the RPC operation started, and
5765 * tally the operation.
5767 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5771 FT_GetTimeOfDay(&opStartTime, 0);
5772 #endif /* FS_STATS_DETAILED */
5774 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5775 goto Bad_GetStatistics64;
5777 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5778 Statistics->ViceStatistics64_val =
5779 malloc(statsVersion*sizeof(afs_int64));
5780 Statistics->ViceStatistics64_len = statsVersion;
5782 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5783 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5784 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5786 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5787 AFSCallStats.TotalCalls;
5788 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5789 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5790 AFSCallStats.FetchStatus;
5791 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5792 AFSCallStats.FetchData;
5793 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5794 AFSCallStats.TotalFetchedBytes;
5795 seconds = AFSCallStats.AccumFetchTime / 1000;
5798 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5799 AFSCallStats.TotalFetchedBytes / seconds;
5800 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5801 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5802 AFSCallStats.StoreStatus;
5803 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5804 AFSCallStats.StoreData;
5805 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5806 AFSCallStats.TotalStoredBytes;
5807 seconds = AFSCallStats.AccumStoreTime / 1000;
5810 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5811 AFSCallStats.TotalStoredBytes / seconds;
5813 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5815 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5816 (afs_int32) ((long)sbrk(0) >> 10);
5819 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5820 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5822 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5826 /* this works on all system types */
5827 FT_GetTimeOfDay(&time, 0);
5828 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5830 Bad_GetStatistics64:
5831 code = CallPostamble(tcon, code, thost);
5833 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5835 #if FS_STATS_DETAILED
5836 FT_GetTimeOfDay(&opStopTime, 0);
5839 (opP->numSuccesses)++;
5840 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5841 fs_stats_AddTo((opP->sumTime), elapsedTime);
5842 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5843 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5844 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5846 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5847 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5851 #endif /* FS_STATS_DETAILED */
5853 osi_auditU(acall, GetStatisticsEvent, code,
5854 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5856 } /*SRXAFS_GetStatistics */
5859 /*------------------------------------------------------------------------
5860 * EXPORTED SRXAFS_XStatsVersion
5863 * Routine called by the server-side RPC interface to implement
5864 * pulling out the xstat version number for the File Server.
5867 * a_versionP : Ptr to the version number variable to set.
5873 * Nothing interesting.
5877 *------------------------------------------------------------------------*/
5880 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5881 { /*SRXAFS_XStatsVersion */
5883 struct client *t_client = NULL; /* tmp ptr to client data */
5884 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5885 #if FS_STATS_DETAILED
5886 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5887 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5888 struct timeval elapsedTime; /* Transfer time */
5891 * Set our stats pointer, remember when the RPC operation started, and
5892 * tally the operation.
5894 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5898 FT_GetTimeOfDay(&opStartTime, 0);
5899 #endif /* FS_STATS_DETAILED */
5901 *a_versionP = AFS_XSTAT_VERSION;
5903 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5905 #if FS_STATS_DETAILED
5906 FT_GetTimeOfDay(&opStopTime, 0);
5907 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5908 fs_stats_AddTo((opP->sumTime), elapsedTime);
5909 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5910 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5911 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5913 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5914 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5917 (opP->numSuccesses)++;
5919 #endif /* FS_STATS_DETAILED */
5921 osi_auditU(a_call, XStatsVersionEvent, 0,
5922 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5924 } /*SRXAFS_XStatsVersion */
5927 /*------------------------------------------------------------------------
5928 * PRIVATE FillPerfValues
5931 * Routine called to fill a regular performance data structure.
5934 * a_perfP : Ptr to perf structure to fill
5940 * Various collections need this info, so the guts were put in
5941 * this separate routine.
5945 *------------------------------------------------------------------------*/
5948 FillPerfValues(struct afs_PerfStats *a_perfP)
5949 { /*FillPerfValues */
5951 int dir_Buffers; /*# buffers in use by dir package */
5952 int dir_Calls; /*# read calls in dir package */
5953 int dir_IOs; /*# I/O ops in dir package */
5954 struct rx_statistics *stats;
5957 * Vnode cache section.
5959 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5960 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5961 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5962 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5963 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5964 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5965 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5966 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5967 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5968 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5969 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5970 SplitInt64(VStats.hdr_gets, hi, lo);
5971 a_perfP->vcache_H_Gets = lo;
5972 SplitInt64(VStats.hdr_loads, hi, lo);
5973 a_perfP->vcache_H_Replacements = lo;
5976 * Directory section.
5978 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5979 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5980 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5981 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5986 stats = rx_GetStatistics();
5988 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5989 a_perfP->rx_noPackets_RcvClass =
5990 (afs_int32) stats->receivePktAllocFailures;
5991 a_perfP->rx_noPackets_SendClass =
5992 (afs_int32) stats->sendPktAllocFailures;
5993 a_perfP->rx_noPackets_SpecialClass =
5994 (afs_int32) stats->specialPktAllocFailures;
5995 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5996 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5997 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5998 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5999 a_perfP->rx_noPacketBuffersOnRead =
6000 (afs_int32) stats->noPacketBuffersOnRead;
6001 a_perfP->rx_selects = (afs_int32) stats->selects;
6002 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
6003 a_perfP->rx_packetsRead_RcvClass =
6004 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
6005 a_perfP->rx_packetsRead_SendClass =
6006 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
6007 a_perfP->rx_packetsRead_SpecialClass =
6008 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
6009 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
6010 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
6011 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
6012 a_perfP->rx_spuriousPacketsRead =
6013 (afs_int32) stats->spuriousPacketsRead;
6014 a_perfP->rx_packetsSent_RcvClass =
6015 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
6016 a_perfP->rx_packetsSent_SendClass =
6017 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
6018 a_perfP->rx_packetsSent_SpecialClass =
6019 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
6020 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
6021 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
6022 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
6023 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
6024 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
6025 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
6026 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
6027 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
6028 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
6029 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
6030 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
6031 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
6032 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
6033 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
6034 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
6035 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
6036 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
6037 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
6038 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
6039 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
6041 a_perfP->host_NumHostEntries = HTs;
6042 a_perfP->host_HostBlocks = HTBlocks;
6043 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
6044 &(a_perfP->host_HostsInSameNetOrSubnet),
6045 &(a_perfP->host_HostsInDiffSubnet),
6046 &(a_perfP->host_HostsInDiffNetwork));
6047 a_perfP->host_NumClients = CEs;
6048 a_perfP->host_ClientBlocks = CEBlocks;
6050 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
6051 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
6052 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
6053 rx_FreeStatistics(&stats);
6054 } /*FillPerfValues */
6057 /*------------------------------------------------------------------------
6058 * EXPORTED SRXAFS_GetXStats
6061 * Routine called by the server-side callback RPC interface to
6062 * implement getting the given data collection from the extended
6063 * File Server statistics.
6066 * a_call : Ptr to Rx call on which this request came in.
6067 * a_clientVersionNum : Client version number.
6068 * a_opCode : Desired operation.
6069 * a_serverVersionNumP : Ptr to version number to set.
6070 * a_timeP : Ptr to time value (seconds) to set.
6071 * a_dataP : Ptr to variable array structure to return
6078 * Nothing interesting.
6082 *------------------------------------------------------------------------*/
6085 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
6086 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
6087 afs_int32 * a_timeP, AFS_CollData * a_dataP)
6088 { /*SRXAFS_GetXStats */
6090 int code; /*Return value */
6091 afs_int32 *dataBuffP; /*Ptr to data to be returned */
6092 afs_int32 dataBytes; /*Bytes in data buffer */
6093 #if FS_STATS_DETAILED
6094 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6095 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6096 struct timeval elapsedTime; /* Transfer time */
6099 * Set our stats pointer, remember when the RPC operation started, and
6100 * tally the operation.
6102 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
6106 FT_GetTimeOfDay(&opStartTime, 0);
6107 #endif /* FS_STATS_DETAILED */
6110 * Record the time of day and the server version number.
6112 *a_srvVersionNumP = AFS_XSTAT_VERSION;
6113 *a_timeP = FT_ApproxTime();
6116 * Stuff the appropriate data in there (assume victory)
6121 ("Received GetXStats call for collection %d\n",
6122 a_collectionNumber));
6126 * We're not keeping stats, so just return successfully with
6129 a_dataP->AFS_CollData_len = 0;
6130 a_dataP->AFS_CollData_val = NULL;
6133 switch (a_collectionNumber) {
6134 case AFS_XSTATSCOLL_CALL_INFO:
6136 * Pass back all the call-count-related data.
6138 * >>> We are forced to allocate a separate area in which to
6139 * >>> put this stuff in by the RPC stub generator, since it
6140 * >>> will be freed at the tail end of the server stub code.
6144 * I don't think call-level stats are being collected yet
6145 * for the File Server.
6147 dataBytes = sizeof(struct afs_Stats);
6148 dataBuffP = (afs_int32 *) malloc(dataBytes);
6149 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6150 a_dataP->AFS_CollData_len = dataBytes >> 2;
6151 a_dataP->AFS_CollData_val = dataBuffP;
6153 a_dataP->AFS_CollData_len = 0;
6154 a_dataP->AFS_CollData_val = NULL;
6158 case AFS_XSTATSCOLL_PERF_INFO:
6160 * Pass back all the regular performance-related data.
6162 * >>> We are forced to allocate a separate area in which to
6163 * >>> put this stuff in by the RPC stub generator, since it
6164 * >>> will be freed at the tail end of the server stub code.
6167 afs_perfstats.numPerfCalls++;
6168 FillPerfValues(&afs_perfstats);
6171 * Don't overwrite the spares at the end.
6174 dataBytes = sizeof(struct afs_PerfStats);
6175 dataBuffP = (afs_int32 *) malloc(dataBytes);
6176 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6177 a_dataP->AFS_CollData_len = dataBytes >> 2;
6178 a_dataP->AFS_CollData_val = dataBuffP;
6181 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6183 * Pass back the full collection of performance-related data.
6184 * We have to stuff the basic, overall numbers in, but the
6185 * detailed numbers are kept in the structure already.
6187 * >>> We are forced to allocate a separate area in which to
6188 * >>> put this stuff in by the RPC stub generator, since it
6189 * >>> will be freed at the tail end of the server stub code.
6192 afs_perfstats.numPerfCalls++;
6193 #if FS_STATS_DETAILED
6194 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6195 FillPerfValues(&afs_FullPerfStats.overall);
6198 * Don't overwrite the spares at the end.
6201 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6202 dataBuffP = (afs_int32 *) malloc(dataBytes);
6203 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6204 a_dataP->AFS_CollData_len = dataBytes >> 2;
6205 a_dataP->AFS_CollData_val = dataBuffP;
6209 case AFS_XSTATSCOLL_CBSTATS:
6210 afs_perfstats.numPerfCalls++;
6212 dataBytes = sizeof(struct cbcounters);
6213 dataBuffP = (afs_int32 *) malloc(dataBytes);
6215 extern struct cbcounters cbstuff;
6216 dataBuffP[0]=cbstuff.DeleteFiles;
6217 dataBuffP[1]=cbstuff.DeleteCallBacks;
6218 dataBuffP[2]=cbstuff.BreakCallBacks;
6219 dataBuffP[3]=cbstuff.AddCallBacks;
6220 dataBuffP[4]=cbstuff.GotSomeSpaces;
6221 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6222 dataBuffP[6]=cbstuff.nFEs;
6223 dataBuffP[7]=cbstuff.nCBs;
6224 dataBuffP[8]=cbstuff.nblks;
6225 dataBuffP[9]=cbstuff.CBsTimedOut;
6226 dataBuffP[10]=cbstuff.nbreakers;
6227 dataBuffP[11]=cbstuff.GSS1;
6228 dataBuffP[12]=cbstuff.GSS2;
6229 dataBuffP[13]=cbstuff.GSS3;
6230 dataBuffP[14]=cbstuff.GSS4;
6231 dataBuffP[15]=cbstuff.GSS5;
6234 a_dataP->AFS_CollData_len = dataBytes >> 2;
6235 a_dataP->AFS_CollData_val = dataBuffP;
6241 * Illegal collection number.
6243 a_dataP->AFS_CollData_len = 0;
6244 a_dataP->AFS_CollData_val = NULL;
6246 } /*Switch on collection number */
6248 #if FS_STATS_DETAILED
6249 FT_GetTimeOfDay(&opStopTime, 0);
6252 (opP->numSuccesses)++;
6253 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6254 fs_stats_AddTo((opP->sumTime), elapsedTime);
6255 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6256 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6257 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6259 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6260 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6264 #endif /* FS_STATS_DETAILED */
6268 } /*SRXAFS_GetXStats */
6272 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6273 struct AFSCBs *CallBackArray)
6275 afs_int32 errorCode = 0;
6277 struct client *client = 0;
6278 struct rx_connection *tcon;
6280 #if FS_STATS_DETAILED
6281 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6282 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6283 struct timeval elapsedTime; /* Transfer time */
6286 * Set our stats pointer, remember when the RPC operation started, and
6287 * tally the operation.
6290 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6294 FT_GetTimeOfDay(&opStartTime, 0);
6295 #endif /* FS_STATS_DETAILED */
6299 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6300 FidArray->AFSCBFids_len));
6303 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6305 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6306 goto Bad_GiveUpCallBacks;
6308 if (!FidArray && !CallBackArray) {
6310 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6311 (tcon->peer ? tcon->peer->host : 0)));
6312 errorCode = GetClient(tcon, &client);
6315 DeleteAllCallBacks_r(client->host, 1);
6320 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6322 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6323 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6324 (tcon->peer ? tcon->peer->host : 0)));
6326 goto Bad_GiveUpCallBacks;
6329 errorCode = GetClient(tcon, &client);
6331 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6332 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6333 DeleteCallBack(client->host, fid);
6339 Bad_GiveUpCallBacks:
6340 errorCode = CallPostamble(tcon, errorCode, thost);
6342 #if FS_STATS_DETAILED
6343 FT_GetTimeOfDay(&opStopTime, 0);
6344 if (errorCode == 0) {
6346 (opP->numSuccesses)++;
6347 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6348 fs_stats_AddTo((opP->sumTime), elapsedTime);
6349 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6350 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6351 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6353 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6354 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6358 #endif /* FS_STATS_DETAILED */
6361 } /*common_GiveUpCallBacks */
6365 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6366 struct AFSCBs * CallBackArray)
6368 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6369 } /*SRXAFS_GiveUpCallBacks */
6372 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6374 return common_GiveUpCallBacks(acall, 0, 0);
6375 } /*SRXAFS_GiveUpAllCallBacks */
6379 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6380 struct AFSVolumeInfo * avolinfo)
6382 return (VNOVOL); /* XXX Obsolete routine XXX */
6384 } /*SRXAFS_NGetVolumeInfo */
6388 * Dummy routine. Should never be called (the cache manager should only
6389 * invoke this interface when communicating with a AFS/DFS Protocol
6393 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6394 char *afs_name_p, struct AFSFid * afs_fid_p,
6395 struct AFSFetchStatus * afs_status_p,
6396 struct AFSFetchStatus * afs_dir_status_p,
6397 struct AFSCallBack * afs_callback_p,
6398 struct AFSVolSync * afs_sync_p)
6405 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6408 struct rx_connection *tcon;
6410 afs_uint32 *dataBuffP;
6411 afs_int32 dataBytes;
6414 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6415 afs_FullPerfStats.overall.fs_nGetCaps++;
6417 ViceLog(2, ("SAFS_GetCapabilties\n"));
6419 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6422 dataBytes = 1 * sizeof(afs_int32);
6423 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6424 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6425 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6427 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6429 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6430 capabilities->Capabilities_val = dataBuffP;
6433 code = CallPostamble(tcon, code, thost);
6440 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6441 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6445 afs_int32 nids, naddrs;
6446 afs_int32 *vd, *addr;
6447 Error errorCode = 0; /* return code to caller */
6448 struct client *client = 0;
6450 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6452 AFSCallStats.TotalCalls++;
6454 nids = vids->ViceIds_len; /* # of users in here */
6455 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6456 if (nids < 0 || naddrs < 0) {
6461 vd = vids->ViceIds_val;
6462 for (i = 0; i < nids; i++, vd++) {
6465 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6469 client->prfail = 2; /* Means re-eval client's cps */
6472 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6475 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6476 free(client->CPS.prlist_val);
6477 client->CPS.prlist_val = NULL;
6478 client->CPS.prlist_len = 0;
6480 ReleaseWriteLock(&client->lock);
6484 addr = addrs->IPAddrs_val;
6485 for (i = 0; i < naddrs; i++, addr++) {
6487 h_flushhostcps(*addr, htons(7001));
6491 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6493 } /*SRXAFS_FlushCPS */
6495 /* worthless hack to let CS keep running ancient software */
6497 afs_vtoi(char *aname)
6503 while ((tc = *aname++)) {
6504 if (tc > '9' || tc < '0')
6505 return 0; /* invalid name */
6513 * may get name or #, but must handle all weird cases (recognize readonly
6514 * or backup volumes by name or #
6517 CopyVolumeEntry(char *aname, struct vldbentry *ave,
6518 struct VolumeInfo *av)
6521 afs_int32 mask, whichType;
6522 afs_uint32 *serverHost, *typePtr;
6524 /* figure out what type we want if by name */
6526 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6527 whichType = BACKVOL;
6528 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6533 vol = afs_vtoi(aname);
6535 vol = ave->volumeId[whichType];
6538 * Now vol has volume # we're interested in. Next, figure out the type
6539 * of the volume by looking finding it in the vldb entry
6541 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6544 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6547 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6548 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6549 whichType = BACKVOL;
6551 return EINVAL; /* error: can't find volume in vldb entry */
6553 typePtr = &av->Type0;
6554 serverHost = &av->Server0;
6556 av->Type = whichType;
6557 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6558 if (ave->flags & VLF_RWEXISTS)
6559 typePtr[RWVOL] = ave->volumeId[RWVOL];
6560 if (ave->flags & VLF_ROEXISTS)
6561 typePtr[ROVOL] = ave->volumeId[ROVOL];
6562 if (ave->flags & VLF_BACKEXISTS)
6563 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6565 for (i = 0, j = 0; i < ave->nServers; i++) {
6566 if ((ave->serverFlags[i] & mask) == 0)
6567 continue; /* wrong volume */
6568 serverHost[j] = ave->serverNumber[i];
6571 av->ServerCount = j;
6573 serverHost[j++] = 0; /* bogus 8, but compat only now */
6578 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6580 static struct rx_connection *vlConn = 0;
6581 static int down = 0;
6582 static afs_int32 lastDownTime = 0;
6583 struct vldbentry tve;
6584 struct rx_securityClass *vlSec;
6588 vlSec = rxnull_NewClientSecurityObject();
6590 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6591 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6593 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6594 return 1; /* failure */
6597 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6599 down = 0; /* call worked */
6602 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6608 /* otherwise convert to old format vldb entry */
6609 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6619 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6620 struct VolumeInfo * avolinfo)
6623 struct rx_connection *tcon;
6625 #if FS_STATS_DETAILED
6626 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6627 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6628 struct timeval elapsedTime; /* Transfer time */
6631 * Set our stats pointer, remember when the RPC operation started, and
6632 * tally the operation.
6634 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6638 FT_GetTimeOfDay(&opStartTime, 0);
6639 #endif /* FS_STATS_DETAILED */
6640 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6641 goto Bad_GetVolumeInfo;
6644 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6646 code = TryLocalVLServer(avolid, avolinfo);
6648 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6649 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6650 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6651 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6654 code = CallPostamble(tcon, code, thost);
6656 #if FS_STATS_DETAILED
6657 FT_GetTimeOfDay(&opStopTime, 0);
6660 (opP->numSuccesses)++;
6661 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6662 fs_stats_AddTo((opP->sumTime), elapsedTime);
6663 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6664 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6665 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6667 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6668 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6672 #endif /* FS_STATS_DETAILED */
6676 } /*SRXAFS_GetVolumeInfo */
6680 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6681 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6682 char **OfflineMsg, char **Motd)
6684 Vnode *targetptr = 0; /* vnode of the new file */
6685 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6686 Error errorCode = 0; /* error code */
6687 Volume *volptr = 0; /* pointer to the volume header */
6688 struct client *client = 0; /* pointer to client entry */
6689 afs_int32 rights, anyrights; /* rights for this and any user */
6691 struct rx_connection *tcon;
6693 struct client *t_client = NULL; /* tmp ptr to client data */
6694 #if FS_STATS_DETAILED
6695 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6696 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6697 struct timeval elapsedTime; /* Transfer time */
6700 * Set our stats pointer, remember when the RPC operation started, and
6701 * tally the operation.
6704 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6708 FT_GetTimeOfDay(&opStartTime, 0);
6709 #endif /* FS_STATS_DETAILED */
6711 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6712 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6713 goto Bad_GetVolumeStatus;
6716 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6720 goto Bad_GetVolumeStatus;
6722 dummyFid.Volume = avolid, dummyFid.Vnode =
6723 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6726 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6727 &parentwhentargetnotdir, &client, READ_LOCK,
6728 &rights, &anyrights)))
6729 goto Bad_GetVolumeStatus;
6731 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6733 goto Bad_GetVolumeStatus;
6735 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6737 Bad_GetVolumeStatus:
6738 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6740 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6741 /* next is to guarantee out strings exist for stub */
6743 *Name = (char *)malloc(1);
6747 *Motd = (char *)malloc(1);
6750 if (*OfflineMsg == 0) {
6751 *OfflineMsg = (char *)malloc(1);
6754 errorCode = CallPostamble(tcon, errorCode, thost);
6756 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6758 #if FS_STATS_DETAILED
6759 FT_GetTimeOfDay(&opStopTime, 0);
6760 if (errorCode == 0) {
6762 (opP->numSuccesses)++;
6763 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6764 fs_stats_AddTo((opP->sumTime), elapsedTime);
6765 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6766 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6767 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6769 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6770 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6774 #endif /* FS_STATS_DETAILED */
6776 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6777 AUD_ID, t_client ? t_client->ViceId : 0,
6778 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6781 } /*SRXAFS_GetVolumeStatus */
6785 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6786 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6787 char *OfflineMsg, char *Motd)
6789 Vnode *targetptr = 0; /* vnode of the new file */
6790 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6791 Error errorCode = 0; /* error code */
6792 Volume *volptr = 0; /* pointer to the volume header */
6793 struct client *client = 0; /* pointer to client entry */
6794 afs_int32 rights, anyrights; /* rights for this and any user */
6796 struct rx_connection *tcon = rx_ConnectionOf(acall);
6798 struct client *t_client = NULL; /* tmp ptr to client data */
6799 #if FS_STATS_DETAILED
6800 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6801 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6802 struct timeval elapsedTime; /* Transfer time */
6805 * Set our stats pointer, remember when the RPC operation started, and
6806 * tally the operation.
6809 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6813 FT_GetTimeOfDay(&opStartTime, 0);
6814 #endif /* FS_STATS_DETAILED */
6816 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6817 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6818 goto Bad_SetVolumeStatus;
6821 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6825 goto Bad_SetVolumeStatus;
6827 dummyFid.Volume = avolid, dummyFid.Vnode =
6828 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6831 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6832 &parentwhentargetnotdir, &client, READ_LOCK,
6833 &rights, &anyrights)))
6834 goto Bad_SetVolumeStatus;
6836 if (readonlyServer) {
6837 errorCode = VREADONLY;
6838 goto Bad_SetVolumeStatus;
6840 if (VanillaUser(client)) {
6842 goto Bad_SetVolumeStatus;
6846 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6848 Bad_SetVolumeStatus:
6849 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6851 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6852 errorCode = CallPostamble(tcon, errorCode, thost);
6854 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6856 #if FS_STATS_DETAILED
6857 FT_GetTimeOfDay(&opStopTime, 0);
6858 if (errorCode == 0) {
6860 (opP->numSuccesses)++;
6861 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6862 fs_stats_AddTo((opP->sumTime), elapsedTime);
6863 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6864 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6865 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6867 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6868 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6872 #endif /* FS_STATS_DETAILED */
6874 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6875 AUD_ID, t_client ? t_client->ViceId : 0,
6876 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6878 } /*SRXAFS_SetVolumeStatus */
6880 #define DEFAULTVOLUME "root.afs"
6883 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6889 struct rx_connection *tcon;
6891 Error errorCode = 0;
6893 #if FS_STATS_DETAILED
6894 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6895 struct timeval opStartTime; /* Start time for RPC op */
6897 struct timeval opStopTime;
6898 struct timeval elapsedTime; /* Transfer time */
6902 * Set our stats pointer, remember when the RPC operation started, and
6903 * tally the operation.
6905 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6909 FT_GetTimeOfDay(&opStartTime, 0);
6910 #endif /* FS_STATS_DETAILED */
6912 return FSERR_EOPNOTSUPP;
6915 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6916 goto Bad_GetRootVolume;
6918 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6921 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6923 strcpy(temp, DEFAULTVOLUME);
6925 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6926 lockf(fd, F_LOCK, 0);
6930 len = read(fd, temp, 256);
6931 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6932 lockf(fd, F_ULOCK, 0);
6937 if (temp[len - 1] == '\n')
6941 *VolumeName = temp; /* freed by rx server-side stub */
6944 errorCode = CallPostamble(tcon, errorCode, thost);
6946 #if FS_STATS_DETAILED
6947 FT_GetTimeOfDay(&opStopTime, 0);
6948 if (errorCode == 0) {
6950 (opP->numSuccesses)++;
6951 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6952 fs_stats_AddTo((opP->sumTime), elapsedTime);
6953 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6954 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6955 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6957 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6958 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6962 #endif /* FS_STATS_DETAILED */
6967 } /*SRXAFS_GetRootVolume */
6970 /* still works because a struct CBS is the same as a struct AFSOpaque */
6972 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6973 struct AFSOpaque * Token)
6976 struct rx_connection *tcon;
6978 #if FS_STATS_DETAILED
6979 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6980 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6981 struct timeval elapsedTime; /* Transfer time */
6984 * Set our stats pointer, remember when the RPC operation started, and
6985 * tally the operation.
6987 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6991 FT_GetTimeOfDay(&opStartTime, 0);
6992 #endif /* FS_STATS_DETAILED */
6994 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6995 goto Bad_CheckToken;
6997 code = FSERR_ECONNREFUSED;
7000 code = CallPostamble(tcon, code, thost);
7002 #if FS_STATS_DETAILED
7003 FT_GetTimeOfDay(&opStopTime, 0);
7006 (opP->numSuccesses)++;
7007 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
7008 fs_stats_AddTo((opP->sumTime), elapsedTime);
7009 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
7010 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
7011 fs_stats_TimeAssign((opP->minTime), elapsedTime);
7013 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
7014 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
7018 #endif /* FS_STATS_DETAILED */
7022 } /*SRXAFS_CheckToken */
7025 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
7026 afs_uint32 * USeconds)
7029 struct rx_connection *tcon;
7032 #if FS_STATS_DETAILED
7033 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
7034 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
7035 struct timeval elapsedTime; /* Transfer time */
7038 * Set our stats pointer, remember when the RPC operation started, and
7039 * tally the operation.
7041 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
7045 FT_GetTimeOfDay(&opStartTime, 0);
7046 #endif /* FS_STATS_DETAILED */
7048 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
7052 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
7054 FT_GetTimeOfDay(&tpl, 0);
7055 *Seconds = tpl.tv_sec;
7056 *USeconds = tpl.tv_usec;
7058 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
7061 code = CallPostamble(tcon, code, thost);
7063 #if FS_STATS_DETAILED
7064 FT_GetTimeOfDay(&opStopTime, 0);
7065 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
7068 (opP->numSuccesses)++;
7069 fs_stats_AddTo((opP->sumTime), elapsedTime);
7070 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
7071 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
7072 fs_stats_TimeAssign((opP->minTime), elapsedTime);
7074 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
7075 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
7079 #endif /* FS_STATS_DETAILED */
7083 } /*SRXAFS_GetTime */
7090 * Implement a client's data fetch using Rx.
7093 * volptr : Ptr to the given volume's info.
7094 * targetptr : Pointer to the vnode involved.
7095 * Call : Ptr to the Rx call involved.
7096 * Pos : Offset within the file.
7097 * Len : Length in bytes to read; this value is bogus!
7098 * if FS_STATS_DETAILED
7099 * a_bytesToFetchP : Set to the number of bytes to be fetched from
7101 * a_bytesFetchedP : Set to the actual number of bytes fetched from
7107 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
7108 struct rx_call * Call, afs_sfsize_t Pos,
7109 afs_sfsize_t Len, afs_int32 Int64Mode,
7110 #if FS_STATS_DETAILED
7111 afs_sfsize_t * a_bytesToFetchP,
7112 afs_sfsize_t * a_bytesFetchedP
7113 #endif /* FS_STATS_DETAILED */
7116 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
7121 #else /* HAVE_PIOV */
7122 struct iovec tiov[RX_MAXIOVECS];
7124 #endif /* HAVE_PIOV */
7128 #if FS_STATS_DETAILED
7130 * Initialize the byte count arguments.
7132 (*a_bytesToFetchP) = 0;
7133 (*a_bytesFetchedP) = 0;
7134 #endif /* FS_STATS_DETAILED */
7138 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
7139 (afs_uintmax_t) Len));
7141 if (!VN_GET_INO(targetptr)) {
7142 afs_int32 zero = htonl(0);
7144 * This is used for newly created files; we simply send 0 bytes
7145 * back to make the cache manager happy...
7148 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7149 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7152 FT_GetTimeOfDay(&StartTime, 0);
7153 ihP = targetptr->handle;
7156 VTakeOffline(volptr);
7157 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7161 optSize = sendBufSize;
7162 tlen = FDH_SIZE(fdP);
7164 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7167 VTakeOffline(volptr);
7168 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7172 if (CheckLength(volptr, targetptr, tlen)) {
7174 VTakeOffline(volptr);
7181 if (Pos + Len > tlen) /* get length we should send */
7182 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7185 afs_int32 high, low;
7186 SplitOffsetOrSize(Len, high, low);
7187 osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7190 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7193 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7195 #if FS_STATS_DETAILED
7196 (*a_bytesToFetchP) = Len;
7197 #endif /* FS_STATS_DETAILED */
7199 tbuffer = AllocSendBuffer();
7200 #endif /* HAVE_PIOV */
7209 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
7210 if (nBytes != wlen) {
7212 FreeSendBuffer((struct afs_buffer *)tbuffer);
7213 VTakeOffline(volptr);
7214 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7218 nBytes = rx_Write(Call, tbuffer, wlen);
7219 #else /* HAVE_PIOV */
7220 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7226 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
7227 if (nBytes != wlen) {
7229 VTakeOffline(volptr);
7230 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7234 nBytes = rx_Writev(Call, tiov, tnio, wlen);
7235 #endif /* HAVE_PIOV */
7237 #if FS_STATS_DETAILED
7239 * Bump the number of bytes actually sent by the number from this
7242 (*a_bytesFetchedP) += nBytes;
7243 #endif /* FS_STATS_DETAILED */
7244 if (nBytes != wlen) {
7248 FreeSendBuffer((struct afs_buffer *)tbuffer);
7249 #endif /* HAVE_PIOV */
7250 err = VIsGoingOffline(volptr);
7259 FreeSendBuffer((struct afs_buffer *)tbuffer);
7260 #endif /* HAVE_PIOV */
7262 FT_GetTimeOfDay(&StopTime, 0);
7264 /* Adjust all Fetch Data related stats */
7266 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7267 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7268 AFSCallStats.AccumFetchTime +=
7269 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7270 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7272 afs_fsize_t targLen;
7273 VN_GET_LEN(targLen, targetptr);
7274 AFSCallStats.TotalFetchedBytes += targLen;
7275 AFSCallStats.FetchSize1++;
7276 if (targLen < SIZE2)
7277 AFSCallStats.FetchSize2++;
7278 else if (targLen < SIZE3)
7279 AFSCallStats.FetchSize3++;
7280 else if (targLen < SIZE4)
7281 AFSCallStats.FetchSize4++;
7283 AFSCallStats.FetchSize5++;
7288 } /*FetchData_RXStyle */
7291 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7292 afs_sfsize_t * size)
7294 #ifdef AFS_NAMEI_ENV
7296 lhp = IH_OPEN(V_linkHandle(vp));
7299 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
7303 *size = OS_SIZE(fdP->fd_fd);
7304 return (*size == -1) ? -1 : 0;
7306 struct afs_stat status;
7308 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7312 *lc = GetLinkCount(vp, &status);
7313 *size = status.st_size;
7322 * Implement a client's data store using Rx.
7325 * volptr : Ptr to the given volume's info.
7326 * targetptr : Pointer to the vnode involved.
7327 * Call : Ptr to the Rx call involved.
7328 * Pos : Offset within the file.
7329 * Len : Length in bytes to store; this value is bogus!
7330 * if FS_STATS_DETAILED
7331 * a_bytesToStoreP : Set to the number of bytes to be stored to
7333 * a_bytesStoredP : Set to the actual number of bytes stored to
7338 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7339 struct client * client, struct rx_call * Call,
7340 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7342 #if FS_STATS_DETAILED
7343 afs_sfsize_t * a_bytesToStoreP,
7344 afs_sfsize_t * a_bytesStoredP
7345 #endif /* FS_STATS_DETAILED */
7348 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7349 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7350 Error errorCode = 0; /* Returned error code to caller */
7352 char *tbuffer; /* data copying buffer */
7353 #else /* HAVE_PIOV */
7354 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7355 int tnio; /* temp for iovec size */
7356 #endif /* HAVE_PIOV */
7357 afs_sfsize_t tlen; /* temp for xfr length */
7358 Inode tinode; /* inode for I/O */
7359 afs_int32 optSize; /* optimal transfer size */
7360 afs_sfsize_t DataLength = 0; /* size of inode */
7361 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7362 afs_fsize_t NewLength; /* size after this store completes */
7363 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7364 int linkCount = 0; /* link count on inode */
7365 afs_fsize_t CoW_off, CoW_len;
7367 FdHandle_t *fdP, *origfdP = NULL;
7368 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7371 #if FS_STATS_DETAILED
7373 * Initialize the byte count arguments.
7375 (*a_bytesToStoreP) = 0;
7376 (*a_bytesStoredP) = 0;
7377 #endif /* FS_STATS_DETAILED */
7380 * We break the callbacks here so that the following signal will not
7383 BreakCallBack(client->host, Fid, 0);
7385 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7386 /* the inode should have been created in Alloc_NewVnode */
7387 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7389 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7390 Fid->Volume, Fid->Vnode, Fid->Unique,
7391 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7392 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7393 return ENOENT; /* is this proper error code? */
7396 * See if the file has several links (from other volumes). If it
7397 * does, then we have to make a copy before changing it to avoid
7398 *changing read-only clones of this dude
7401 ("StoreData_RXStyle : Opening inode %s\n",
7402 PrintInode(stmp, VN_GET_INO(targetptr))));
7403 fdP = IH_OPEN(targetptr->handle);
7406 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7408 VTakeOffline(volptr);
7409 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7413 if (CheckLength(volptr, targetptr, DataLength)) {
7415 VTakeOffline(volptr);
7419 if (linkCount != 1) {
7422 ("StoreData_RXStyle : inode %s has more than onelink\n",
7423 PrintInode(stmp, VN_GET_INO(targetptr))));
7424 /* other volumes share this data, better copy it first */
7426 /* Adjust the disk block count by the creation of the new inode.
7427 * We call the special VDiskUsage so we don't adjust the volume's
7428 * quota since we don't want to penalyze the user for afs's internal
7429 * mechanisms (i.e. copy on write overhead.) Also the right size
7430 * of the disk will be recorded...
7433 VN_GET_LEN(size, targetptr);
7434 volptr->partition->flags &= ~PART_DONTUPDATE;
7435 VSetPartitionDiskUsage(volptr->partition);
7436 volptr->partition->flags |= PART_DONTUPDATE;
7437 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7438 volptr->partition->flags &= ~PART_DONTUPDATE;
7443 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7444 CopyOnWrite_calls++;
7445 if (CoW_len == 0) CopyOnWrite_size0++;
7446 if (Pos == 0) CopyOnWrite_off0++;
7447 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7449 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7450 "off 0x0 size 0x%llx\n",
7451 afs_printable_VolumeId_u(V_id(volptr)),
7452 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7453 V_name(volptr), Pos));
7454 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7455 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7456 volptr->partition->flags &= ~PART_DONTUPDATE;
7460 volptr->partition->flags &= ~PART_DONTUPDATE;
7461 VSetPartitionDiskUsage(volptr->partition);
7462 fdP = IH_OPEN(targetptr->handle);
7465 ("StoreData : Reopen after CopyOnWrite failed\n"));
7466 FDH_REALLYCLOSE(origfdP);
7470 tinode = VN_GET_INO(targetptr);
7472 if (!VALID_INO(tinode)) {
7473 VTakeOffline(volptr);
7474 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7479 /* compute new file length */
7480 NewLength = DataLength;
7481 if (FileLength < NewLength)
7482 /* simulate truncate */
7483 NewLength = FileLength;
7484 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7485 if (Pos + Length > NewLength)
7486 NewLength = Pos + Length; /* and write */
7488 /* adjust the disk block count by the difference in the files */
7490 afs_fsize_t targSize;
7491 VN_GET_LEN(targSize, targetptr);
7492 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7495 AdjustDiskUsage(volptr, adjustSize,
7496 adjustSize - SpareComp(volptr)))) {
7498 if (origfdP) FDH_REALLYCLOSE(origfdP);
7502 /* can signal cache manager to proceed from close now */
7503 /* this bit means that the locks are set and protections are OK */
7504 rx_SetLocalStatus(Call, 1);
7506 FT_GetTimeOfDay(&StartTime, 0);
7508 optSize = sendBufSize;
7510 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7511 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7512 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7514 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7515 if (FileLength < DataLength)
7516 FDH_TRUNC(fdP, FileLength);
7517 bytesTransfered = 0;
7519 tbuffer = AllocSendBuffer();
7520 #endif /* HAVE_PIOV */
7521 /* if length == 0, the loop below isn't going to do anything, including
7522 * extend the length of the inode, which it must do, since the file system
7523 * assumes that the inode length == vnode's file length. So, we extend
7524 * the file length manually if need be. Note that if file is bigger than
7525 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7526 * do what we're going to do below.
7528 if (Length == 0 && Pos > TruncatedLength) {
7529 /* Set the file's length; we've already done an lseek to the right
7532 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
7537 errorCode = FDH_TRUNC(fdP, Pos);
7539 /* have some data to copy */
7540 #if FS_STATS_DETAILED
7541 (*a_bytesToStoreP) = Length;
7542 #endif /* FS_STATS_DETAILED */
7545 if (bytesTransfered >= Length) {
7549 tlen = Length - bytesTransfered; /* how much more to do */
7551 rlen = optSize; /* bound by buffer size */
7555 errorCode = rx_Read(Call, tbuffer, rlen);
7556 #else /* HAVE_PIOV */
7557 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7558 #endif /* HAVE_PIOV */
7559 if (errorCode <= 0) {
7563 #if FS_STATS_DETAILED
7564 (*a_bytesStoredP) += errorCode;
7565 #endif /* FS_STATS_DETAILED */
7568 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
7569 #else /* HAVE_PIOV */
7570 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
7571 #endif /* HAVE_PIOV */
7572 if (nBytes != rlen) {
7573 errorCode = VDISKFULL;
7576 bytesTransfered += rlen;
7582 FreeSendBuffer((struct afs_buffer *)tbuffer);
7583 #endif /* HAVE_PIOV */
7588 afs_sfsize_t nfSize = FDH_SIZE(fdP);
7589 osi_Assert(nfSize >= 0);
7590 /* something went wrong: adjust size and return */
7591 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7592 /* changed_newTime is tested in StoreData to detemine if we
7593 * need to update the target vnode.
7595 targetptr->changed_newTime = 1;
7596 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7597 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7598 if (origfdP) FDH_REALLYCLOSE(origfdP);
7600 /* set disk usage to be correct */
7601 VAdjustDiskUsage(&errorCode, volptr,
7602 (afs_sfsize_t) (nBlocks(nfSize) -
7603 nBlocks(NewLength)), 0);
7606 if (origfdP) { /* finish CopyOnWrite */
7607 if ( (CoW_off = Pos + Length) < NewLength) {
7608 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7609 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7610 "off 0x%llx size 0x%llx returns %d\n",
7611 afs_printable_VolumeId_u(V_id(volptr)),
7612 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7613 V_name(volptr), CoW_off, CoW_len, errorCode));
7615 FDH_REALLYCLOSE(origfdP);
7619 FT_GetTimeOfDay(&StopTime, 0);
7621 VN_SET_LEN(targetptr, NewLength);
7623 /* Update all StoreData related stats */
7625 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7626 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7627 AFSCallStats.StoreSize1++; /* Piggybacked data */
7629 afs_fsize_t targLen;
7630 VN_GET_LEN(targLen, targetptr);
7631 if (targLen < SIZE2)
7632 AFSCallStats.StoreSize2++;
7633 else if (targLen < SIZE3)
7634 AFSCallStats.StoreSize3++;
7635 else if (targLen < SIZE4)
7636 AFSCallStats.StoreSize4++;
7638 AFSCallStats.StoreSize5++;
7643 } /*StoreData_RXStyle */
7645 static int sys2et[512];
7648 init_sys_error_to_et(void)
7650 memset(&sys2et, 0, sizeof(sys2et));
7651 sys2et[EPERM] = UAEPERM;
7652 sys2et[ENOENT] = UAENOENT;
7653 sys2et[ESRCH] = UAESRCH;
7654 sys2et[EINTR] = UAEINTR;
7655 sys2et[EIO] = UAEIO;
7656 sys2et[ENXIO] = UAENXIO;
7657 sys2et[E2BIG] = UAE2BIG;
7658 sys2et[ENOEXEC] = UAENOEXEC;
7659 sys2et[EBADF] = UAEBADF;
7660 sys2et[ECHILD] = UAECHILD;
7661 sys2et[EAGAIN] = UAEAGAIN;
7662 sys2et[ENOMEM] = UAENOMEM;
7663 sys2et[EACCES] = UAEACCES;
7664 sys2et[EFAULT] = UAEFAULT;
7665 sys2et[ENOTBLK] = UAENOTBLK;
7666 sys2et[EBUSY] = UAEBUSY;
7667 sys2et[EEXIST] = UAEEXIST;
7668 sys2et[EXDEV] = UAEXDEV;
7669 sys2et[ENODEV] = UAENODEV;
7670 sys2et[ENOTDIR] = UAENOTDIR;
7671 sys2et[EISDIR] = UAEISDIR;
7672 sys2et[EINVAL] = UAEINVAL;
7673 sys2et[ENFILE] = UAENFILE;
7674 sys2et[EMFILE] = UAEMFILE;
7675 sys2et[ENOTTY] = UAENOTTY;
7676 sys2et[ETXTBSY] = UAETXTBSY;
7677 sys2et[EFBIG] = UAEFBIG;
7678 sys2et[ENOSPC] = UAENOSPC;
7679 sys2et[ESPIPE] = UAESPIPE;
7680 sys2et[EROFS] = UAEROFS;
7681 sys2et[EMLINK] = UAEMLINK;
7682 sys2et[EPIPE] = UAEPIPE;
7683 sys2et[EDOM] = UAEDOM;
7684 sys2et[ERANGE] = UAERANGE;
7685 sys2et[EDEADLK] = UAEDEADLK;
7686 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7687 sys2et[ENOLCK] = UAENOLCK;
7688 sys2et[ENOSYS] = UAENOSYS;
7689 #if (ENOTEMPTY != EEXIST)
7690 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7692 sys2et[ELOOP] = UAELOOP;
7693 #if (EWOULDBLOCK != EAGAIN)
7694 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7696 sys2et[ENOMSG] = UAENOMSG;
7697 sys2et[EIDRM] = UAEIDRM;
7698 sys2et[ECHRNG] = UAECHRNG;
7699 sys2et[EL2NSYNC] = UAEL2NSYNC;
7700 sys2et[EL3HLT] = UAEL3HLT;
7701 sys2et[EL3RST] = UAEL3RST;
7702 sys2et[ELNRNG] = UAELNRNG;
7703 sys2et[EUNATCH] = UAEUNATCH;
7704 sys2et[ENOCSI] = UAENOCSI;
7705 sys2et[EL2HLT] = UAEL2HLT;
7706 sys2et[EBADE] = UAEBADE;
7707 sys2et[EBADR] = UAEBADR;
7708 sys2et[EXFULL] = UAEXFULL;
7709 sys2et[ENOANO] = UAENOANO;
7710 sys2et[EBADRQC] = UAEBADRQC;
7711 sys2et[EBADSLT] = UAEBADSLT;
7712 sys2et[EDEADLK] = UAEDEADLK;
7713 sys2et[EBFONT] = UAEBFONT;
7714 sys2et[ENOSTR] = UAENOSTR;
7715 sys2et[ENODATA] = UAENODATA;
7716 sys2et[ETIME] = UAETIME;
7717 sys2et[ENOSR] = UAENOSR;
7718 sys2et[ENONET] = UAENONET;
7719 sys2et[ENOPKG] = UAENOPKG;
7720 sys2et[EREMOTE] = UAEREMOTE;
7721 sys2et[ENOLINK] = UAENOLINK;
7722 sys2et[EADV] = UAEADV;
7723 sys2et[ESRMNT] = UAESRMNT;
7724 sys2et[ECOMM] = UAECOMM;
7725 sys2et[EPROTO] = UAEPROTO;
7726 sys2et[EMULTIHOP] = UAEMULTIHOP;
7727 sys2et[EDOTDOT] = UAEDOTDOT;
7728 sys2et[EBADMSG] = UAEBADMSG;
7729 sys2et[EOVERFLOW] = UAEOVERFLOW;
7730 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7731 sys2et[EBADFD] = UAEBADFD;
7732 sys2et[EREMCHG] = UAEREMCHG;
7733 sys2et[ELIBACC] = UAELIBACC;
7734 sys2et[ELIBBAD] = UAELIBBAD;
7735 sys2et[ELIBSCN] = UAELIBSCN;
7736 sys2et[ELIBMAX] = UAELIBMAX;
7737 sys2et[ELIBEXEC] = UAELIBEXEC;
7738 sys2et[EILSEQ] = UAEILSEQ;
7739 sys2et[ERESTART] = UAERESTART;
7740 sys2et[ESTRPIPE] = UAESTRPIPE;
7741 sys2et[EUSERS] = UAEUSERS;
7742 sys2et[ENOTSOCK] = UAENOTSOCK;
7743 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7744 sys2et[EMSGSIZE] = UAEMSGSIZE;
7745 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7746 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7747 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7748 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7749 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7750 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7751 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7752 sys2et[EADDRINUSE] = UAEADDRINUSE;
7753 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7754 sys2et[ENETDOWN] = UAENETDOWN;
7755 sys2et[ENETUNREACH] = UAENETUNREACH;
7756 sys2et[ENETRESET] = UAENETRESET;
7757 sys2et[ECONNABORTED] = UAECONNABORTED;
7758 sys2et[ECONNRESET] = UAECONNRESET;
7759 sys2et[ENOBUFS] = UAENOBUFS;
7760 sys2et[EISCONN] = UAEISCONN;
7761 sys2et[ENOTCONN] = UAENOTCONN;
7762 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7763 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7764 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7765 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7766 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7767 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7768 sys2et[EALREADY] = UAEALREADY;
7769 sys2et[EINPROGRESS] = UAEINPROGRESS;
7770 sys2et[ESTALE] = UAESTALE;
7771 sys2et[EUCLEAN] = UAEUCLEAN;
7772 sys2et[ENOTNAM] = UAENOTNAM;
7773 sys2et[ENAVAIL] = UAENAVAIL;
7774 sys2et[EISNAM] = UAEISNAM;
7775 sys2et[EREMOTEIO] = UAEREMOTEIO;
7776 sys2et[EDQUOT] = UAEDQUOT;
7777 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7778 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7780 sys2et[EIO] = UAEIO;
7784 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7785 * - pass back the connection, client, and host from CallPreamble
7786 * - keep a ref on the client, which we don't now
7787 * - keep a hold on the host, which we already do
7788 * - pass the connection, client, and host down into SAFSS_*, and use
7789 * them instead of independently discovering them via rx_ConnectionOf
7790 * (safe) and rx_GetSpecific (not so safe)
7791 * The idea being that we decide what client and host we're going to use
7792 * when CallPreamble is called, and stay consistent throughout the call.
7793 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7797 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7799 Error errorCode = 0;
7800 struct rx_connection *tcon;
7801 struct host *tcallhost;
7802 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7804 struct client *tclient;
7805 static struct rx_securityClass *sc = 0;
7807 struct rx_connection *conn;
7810 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7811 goto Bad_CallBackRxConnAddr1;
7813 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7817 tclient = h_FindClient_r(tcon);
7820 goto Bad_CallBackRxConnAddr;
7822 thost = tclient->host;
7824 /* nothing more can be done */
7825 if ( !thost->interface )
7826 goto Bad_CallBackRxConnAddr;
7828 /* the only address is the primary interface */
7829 /* can't change when there's only 1 address, anyway */
7830 if ( thost->interface->numberOfInterfaces <= 1 )
7831 goto Bad_CallBackRxConnAddr;
7833 /* initialise a security object only once */
7835 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7837 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7839 if ( *addr == thost->interface->addr[i] ) {
7844 if ( *addr != thost->interface->addr[i] )
7845 goto Bad_CallBackRxConnAddr;
7847 conn = rx_NewConnection (thost->interface->addr[i],
7848 thost->port, 1, sc, 0);
7849 rx_SetConnDeadTime(conn, 2);
7850 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7852 errorCode = RXAFSCB_Probe(conn);
7855 if ( thost->callback_rxcon )
7856 rx_DestroyConnection(thost->callback_rxcon);
7857 thost->callback_rxcon = conn;
7859 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7860 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7861 h_ReleaseClient_r(tclient);
7862 /* The hold on thost will be released by CallPostamble */
7864 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7867 rx_DestroyConnection(conn);
7869 Bad_CallBackRxConnAddr:
7870 h_ReleaseClient_r(tclient);
7871 /* The hold on thost will be released by CallPostamble */
7875 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7876 Bad_CallBackRxConnAddr1:
7877 return errorCode; /* failure */
7881 sys_error_to_et(afs_int32 in)
7885 if (in < 0 || in > 511)
7887 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7889 if (sys2et[in] != 0)