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>
35 #undef SHARED /* XXX */
42 #ifdef HAVE_NETINET_IF_ETHER_H
43 #include <netinet/if_ether.h>
46 #if !defined(AFS_SGI_ENV) && defined(HAVE_SYS_MAP_H)
50 #ifdef HAVE_SYS_STATFS_H
51 #include <sys/statfs.h>
54 #ifdef HAVE_SYS_LOCKF_H
55 #include <sys/lockf.h>
63 /* included early because of name conflict on IOPEN */
64 #include <sys/inode.h>
68 #endif /* AFS_HPUX_ENV */
72 #include <afs/afs_assert.h>
75 #include <afs/afsint.h>
76 #include <afs/vldbint.h>
77 #include <afs/errors.h>
78 #include <afs/ihandle.h>
79 #include <afs/vnode.h>
80 #include <afs/volume.h>
81 #include <afs/ptclient.h>
82 #include <afs/ptuser.h>
83 #include <afs/prs_fs.h>
86 #include <rx/rx_globals.h>
88 #include <afs/cellconfig.h>
91 #include <afs/partition.h>
92 #include "viced_prototypes.h"
96 #include <afs/unified_afs.h>
97 #include <afs/audit.h>
98 #include <afs/afsutil.h>
101 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
102 extern void FidZap(DirHandle * file);
103 extern void FidZero(DirHandle * file);
105 #ifdef AFS_PTHREAD_ENV
106 pthread_mutex_t fileproc_glock_mutex;
107 #endif /* AFS_PTHREAD_ENV */
109 /* Useful local defines used by this module */
112 #define MustNOTBeDIR 1
116 #define TVS_SSTATUS 2
119 #define TVS_MKDIR 0x10
121 #define CHK_FETCH 0x10
122 #define CHK_FETCHDATA 0x10
123 #define CHK_FETCHACL 0x11
124 #define CHK_FETCHSTATUS 0x12
125 #define CHK_STOREDATA 0x00
126 #define CHK_STOREACL 0x01
127 #define CHK_STORESTATUS 0x02
129 #define OWNERREAD 0400
130 #define OWNERWRITE 0200
131 #define OWNEREXEC 0100
132 #ifdef USE_GROUP_PERMS
133 #define GROUPREAD 0040
134 #define GROUPWRITE 0020
135 #define GROUPREXEC 0010
138 /* The following errors were not defined in NT. They are given unique
139 * names here to avoid any potential collision.
141 #define FSERR_ELOOP 90
142 #define FSERR_EOPNOTSUPP 122
143 #define FSERR_ECONNREFUSED 130
145 #define NOTACTIVECALL 0
148 #define CREATE_SGUID_ADMIN_ONLY 1
150 extern struct afsconf_dir *confDir;
151 extern afs_int32 dataVersionHigh;
154 static struct AFSCallStatistics AFSCallStats;
155 #if FS_STATS_DETAILED
156 struct fs_stats_FullPerfStats afs_FullPerfStats;
157 extern int AnonymousID;
158 #endif /* FS_STATS_DETAILED */
159 #if OPENAFS_VOL_STATS
160 static const char nullString[] = "";
161 #endif /* OPENAFS_VOL_STATS */
164 afs_int32 NothingYet;
167 struct afs_FSStats afs_fsstats;
172 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
174 extern afs_int32 implicitAdminRights;
175 extern afs_int32 readonlyServer;
176 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
177 extern afs_fsize_t CopyOnWrite_maxsize;
180 * Externals used by the xstat code.
182 extern VolPkgStats VStats;
183 extern int CEs, CEBlocks;
185 extern int HTs, HTBlocks;
187 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
188 struct rx_call *Call, afs_sfsize_t Pos,
189 afs_sfsize_t Len, afs_int32 Int64Mode,
190 #if FS_STATS_DETAILED
191 afs_sfsize_t * a_bytesToFetchP,
192 afs_sfsize_t * a_bytesFetchedP
193 #endif /* FS_STATS_DETAILED */
196 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
197 struct AFSFid *Fid, struct client *client,
198 struct rx_call *Call, afs_fsize_t Pos,
199 afs_fsize_t Length, afs_fsize_t FileLength,
201 #if FS_STATS_DETAILED
202 afs_sfsize_t * a_bytesToStoreP,
203 afs_sfsize_t * a_bytesStoredP
204 #endif /* FS_STATS_DETAILED */
207 #ifdef AFS_SGI_XFS_IOPS_ENV
208 #include <afs/xfsattrs.h>
210 GetLinkCount(Volume * avp, struct stat *astat)
212 if (!strcmp("xfs", astat->st_fstype)) {
213 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
215 return astat->st_nlink;
218 #define GetLinkCount(V, S) (S)->st_nlink
222 SpareComp(Volume * avolp)
228 temp = V_maxquota(avolp);
230 /* no matter; doesn't check in this case */
234 temp = (temp * PctSpare) / 100;
245 * Set the volume synchronization parameter for this volume. If it changes,
246 * the Cache Manager knows that the volume must be purged from the stat cache.
249 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
252 /* date volume instance was created */
255 async->spare1 = avol->header->diskstuff.creationDate;
268 * Verify that the on-disk size for a vnode matches the length in the vnode
271 * @param[in] vp Volume pointer
272 * @param[in] vnp Vnode pointer
273 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
274 * and CheckLength itself will determine the on-disk size.
276 * @return operation status
277 * @retval 0 lengths match
278 * @retval nonzero Error; either the lengths do not match or there was an
279 * error determining the on-disk size. The volume should be
280 * taken offline and salvaged.
283 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
286 VN_GET_LEN(vlen, vnp);
291 fdP = IH_OPEN(vnp->handle);
293 ViceLog(0, ("CheckLength: cannot open inode for fid %lu.%lu.%lu\n",
294 afs_printable_uint32_lu(vp->hashid),
295 afs_printable_uint32_lu(Vn_id(vnp)),
296 afs_printable_uint32_lu(vnp->disk.uniquifier)));
299 alen = FDH_SIZE(fdP);
302 afs_int64 alen64 = alen;
303 ViceLog(0, ("CheckLength: cannot get size for inode for fid "
304 "%lu.%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
305 afs_printable_uint32_lu(vp->hashid),
306 afs_printable_uint32_lu(Vn_id(vnp)),
307 afs_printable_uint32_lu(vnp->disk.uniquifier),
314 afs_int64 alen64 = alen, vlen64 = vlen;
315 ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index "
316 "%lld inode %lld ); volume must be salvaged\n",
317 afs_printable_uint32_lu(vp->hashid),
318 afs_printable_uint32_lu(Vn_id(vnp)),
319 afs_printable_uint32_lu(vnp->disk.uniquifier),
327 * Note that this function always returns a held host, so
328 * that CallPostamble can block without the host's disappearing.
329 * Call returns rx connection in passed in *tconn
332 CallPreamble(struct rx_call *acall, int activecall,
333 struct rx_connection **tconn, struct host **ahostp)
336 struct client *tclient;
339 char hoststr[16], hoststr2[16];
340 #ifdef AFS_PTHREAD_ENV
341 struct ubik_client *uclient;
346 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
349 *tconn = rx_ConnectionOf(acall);
353 tclient = h_FindClient_r(*tconn);
355 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
359 thost = tclient->host;
360 if (tclient->prfail == 1) { /* couldn't get the CPS */
362 h_ReleaseClient_r(tclient);
364 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
368 retry_flag = 0; /* Retry once */
370 /* Take down the old connection and re-read the key file */
372 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
373 #ifdef AFS_PTHREAD_ENV
374 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
376 /* Is it still necessary to drop this? We hit the net, we should... */
382 code = hpr_Initialize(&uclient);
385 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
388 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
391 h_ReleaseClient_r(tclient);
394 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
398 tclient->prfail = 2; /* Means re-eval client's cps */
399 h_ReleaseClient_r(tclient);
404 tclient->LastCall = thost->LastCall = FT_ApproxTime();
405 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
406 thost->ActiveCall = thost->LastCall;
409 if (thost->hostFlags & HOSTDELETED) {
411 ("Discarded a packet for deleted host %s:%d\n",
412 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
413 code = VBUSY; /* raced, so retry */
414 } else if ((thost->hostFlags & VENUSDOWN)
415 || (thost->hostFlags & HFE_LATER)) {
416 if (BreakDelayedCallBacks_r(thost)) {
418 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
419 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
420 ntohs(rxr_PortOf(*tconn))));
421 if (MultiProbeAlternateAddress_r(thost)) {
423 ("MultiProbe failed to find new address for host %s:%d\n",
424 afs_inet_ntoa_r(thost->host, hoststr),
425 ntohs(thost->port)));
429 ("MultiProbe found new address for host %s:%d\n",
430 afs_inet_ntoa_r(thost->host, hoststr),
431 ntohs(thost->port)));
432 if (BreakDelayedCallBacks_r(thost)) {
434 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
435 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
436 ntohs(rxr_PortOf(*tconn))));
445 h_ReleaseClient_r(tclient);
455 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
459 struct client *tclient;
463 tclient = h_FindClient_r(aconn);
466 thost = tclient->host;
467 if (thost->hostFlags & HERRORTRANS)
469 h_ReleaseClient_r(tclient);
472 if (ahost != thost) {
473 /* host/client recycle */
474 char hoststr[16], hoststr2[16];
475 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
477 afs_inet_ntoa_r(ahost->host, hoststr),
480 afs_inet_ntoa_r(thost->host, hoststr2),
484 /* return the reference taken in CallPreamble */
488 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
489 afs_inet_ntoa_r(thost->host, hoststr),
494 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
495 * does not decrement refcount on client->host */
500 return (translate ? sys_error_to_et(ret) : ret);
504 * Returns the volume and vnode pointers associated with file Fid; the lock
505 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
506 * are incremented and they must be eventualy released.
509 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
510 Vnode ** vptr, int lock)
513 Error local_errorCode, errorCode = -1;
514 static struct timeval restartedat = { 0, 0 };
516 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
518 if ((*volptr) == 0) {
523 #ifdef AFS_DEMAND_ATTACH_FS
529 #ifdef AFS_PTHREAD_ENV
530 static const struct timespec timeout_ts = { 0, 0 };
531 static const struct timespec * const ts = &timeout_ts;
533 static const struct timespec * const ts = NULL;
537 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
538 fid->Volume, ts, cbv);
543 if ((errorCode == VOFFLINE) && (VInit < 2)) {
544 /* The volume we want may not be attached yet because
545 * the volume initialization is not yet complete.
546 * We can do several things:
547 * 1. return -1, which will cause users to see
548 * "connection timed out". This is more or
549 * less the same as always, except that the servers
550 * may appear to bounce up and down while they
551 * are actually restarting.
552 * 2. return VBUSY which will cause clients to
553 * sleep and retry for 6.5 - 15 minutes, depending
554 * on what version of the CM they are running. If
555 * the file server takes longer than that interval
556 * to attach the desired volume, then the application
557 * will see an ENODEV or EIO. This approach has
558 * the advantage that volumes which have been attached
559 * are immediately available, it keeps the server's
560 * immediate backlog low, and the call is interruptible
561 * by the user. Users see "waiting for busy volume."
562 * 3. sleep here and retry. Some people like this approach
563 * because there is no danger of seeing errors. However,
564 * this approach only works with a bounded number of
565 * clients, since the pending queues will grow without
566 * stopping. It might be better to find a way to take
567 * this call and stick it back on a queue in order to
568 * recycle this thread for a different request.
569 * 4. Return a new error code, which new cache managers will
570 * know enough to interpret as "sleep and retry", without
571 * the upper bound of 6-15 minutes that is imposed by the
572 * VBUSY handling. Users will see "waiting for
573 * busy volume," so they know that something is
574 * happening. Old cache managers must be able to do
575 * something reasonable with this, for instance, mark the
576 * server down. Fortunately, any error code < 0
577 * will elicit that behavior. See #1.
578 * 5. Some combination of the above. I like doing #2 for 10
579 * minutes, followed by #4. 3.1b and 3.2 cache managers
580 * will be fine as long as the restart period is
581 * not longer than 6.5 minutes, otherwise they may
582 * return ENODEV to users. 3.3 cache managers will be
583 * fine for 10 minutes, then will return
584 * ETIMEDOUT. 3.4 cache managers will just wait
585 * until the call works or fails definitively.
586 * NB. The problem with 2,3,4,5 is that old clients won't
587 * fail over to an alternate read-only replica while this
588 * server is restarting. 3.4 clients will fail over right away.
590 if (restartedat.tv_sec == 0) {
591 /* I'm not really worried about when we restarted, I'm */
592 /* just worried about when the first VBUSY was returned. */
593 FT_GetTimeOfDay(&restartedat, 0);
596 afs_perfstats.fs_nBusies++;
599 return (busyonrst ? VBUSY : restarting);
602 FT_GetTimeOfDay(&now, 0);
603 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
606 afs_perfstats.fs_nBusies++;
609 return (busyonrst ? VBUSY : restarting);
615 /* allow read operations on busy volume.
616 * must check local_errorCode because demand attach fs
617 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
618 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
619 #ifdef AFS_DEMAND_ATTACH_FS
620 /* DAFS case is complicated by the fact that local_errorCode can
621 * be VBUSY in cases where the volume is truly offline */
623 /* volume is in VOL_STATE_UNATTACHED */
626 #endif /* AFS_DEMAND_ATTACH_FS */
629 } else if (errorCode)
636 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
639 if ((*vptr)->disk.uniquifier != fid->Unique) {
640 VPutVnode(&fileCode, *vptr);
641 osi_Assert(fileCode == 0);
643 return (VNOVNODE); /* return the right error code, at least */
648 static_inline afs_int32
649 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
651 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
655 * This routine returns the ACL associated with the targetptr. If the
656 * targetptr isn't a directory, we access its parent dir and get the ACL
657 * thru the parent; in such case the parent's vnode is returned in
661 SetAccessList(Vnode ** targetptr, Volume ** volume,
662 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
663 AFSFid * Fid, int Lock)
665 if ((*targetptr)->disk.type == vDirectory) {
667 *ACL = VVnodeACL(*targetptr);
668 *ACLSize = VAclSize(*targetptr);
671 osi_Assert(Fid != 0);
676 parentvnode = (*targetptr)->disk.parent;
677 VPutVnode(&errorCode, *targetptr);
681 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
684 *ACL = VVnodeACL(*parent);
685 *ACLSize = VAclSize(*parent);
686 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
688 if ((*targetptr)->disk.parent != parentvnode) {
689 VPutVnode(&errorCode, *parent);
700 /* Must not be called with H_LOCK held */
702 client_CheckRights(struct client *client, struct acl_accessList *ACL,
706 ObtainReadLock(&client->lock);
707 if (client->CPS.prlist_len > 0 && !client->deleted &&
708 client->host && !(client->host->hostFlags & HOSTDELETED))
709 acl_CheckRights(ACL, &client->CPS, rights);
710 ReleaseReadLock(&client->lock);
713 /* Must not be called with H_LOCK held */
715 client_HasAsMember(struct client *client, afs_int32 id)
719 ObtainReadLock(&client->lock);
720 if (client->CPS.prlist_len > 0 && !client->deleted &&
721 client->host && !(client->host->hostFlags & HOSTDELETED))
722 code = acl_IsAMember(id, &client->CPS);
723 ReleaseReadLock(&client->lock);
728 * Compare the directory's ACL with the user's access rights in the client
729 * connection and return the user's and everybody else's access permissions
730 * in rights and anyrights, respectively
733 GetRights(struct client *client, struct acl_accessList *ACL,
734 afs_int32 * rights, afs_int32 * anyrights)
736 extern prlist SystemAnyUserCPS;
737 afs_int32 hrights = 0;
738 #ifndef AFS_PTHREAD_ENV
742 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
743 ViceLog(0, ("CheckRights failed\n"));
748 client_CheckRights(client, ACL, rights);
750 /* wait if somebody else is already doing the getCPS call */
752 while (client->host->hostFlags & HCPS_INPROGRESS) {
753 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
754 #ifdef AFS_PTHREAD_ENV
755 CV_WAIT(&client->host->cond, &host_glock_mutex);
756 #else /* AFS_PTHREAD_ENV */
758 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
759 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
760 #endif /* AFS_PTHREAD_ENV */
763 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
766 ("CheckRights: len=%u, for host=%s:%d\n",
767 client->host->hcps.prlist_len,
768 afs_inet_ntoa_r(client->host->host, hoststr),
769 ntohs(client->host->port)));
771 acl_CheckRights(ACL, &client->host->hcps, &hrights);
773 /* Allow system:admin the rights given with the -implicit option */
774 if (client_HasAsMember(client, SystemId))
775 *rights |= implicitAdminRights;
778 *anyrights |= hrights;
785 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
786 * a System:Administrator)
789 VanillaUser(struct client *client)
791 if (client_HasAsMember(client, SystemId))
792 return (0); /* not a system administrator, then you're "vanilla" */
799 * This unusual afs_int32-parameter routine encapsulates all volume package related
800 * operations together in a single function; it's called by almost all AFS
804 GetVolumePackageWithCall(struct rx_connection *tcon, struct VCallByVol *cbv,
805 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
806 int chkforDir, Vnode ** parent, struct client **client,
807 int locktype, afs_int32 * rights, afs_int32 * anyrights)
809 struct acl_accessList *aCL; /* Internal access List */
810 int aCLSize; /* size of the access list */
811 Error errorCode = 0; /* return code to caller */
813 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
816 if (chkforDir == MustNOTBeDIR
817 && ((*targetptr)->disk.type == vDirectory))
819 else if (chkforDir == MustBeDIR
820 && ((*targetptr)->disk.type != vDirectory))
824 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
825 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
826 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
828 if (chkforDir == MustBeDIR)
829 osi_Assert((*parent) == 0);
831 if ((errorCode = GetClient(tcon, client)) != 0)
836 GetRights(*client, aCL, rights, anyrights);
837 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
838 if ((*targetptr)->disk.type != vDirectory) {
839 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
840 if ((*targetptr)->disk.owner == (*client)->ViceId)
841 (*rights) |= PRSFS_ADMINISTER;
843 (*rights) &= ~PRSFS_ADMINISTER;
845 #ifdef ADMIN_IMPLICIT_LOOKUP
846 /* admins get automatic lookup on everything */
847 if (!VanillaUser(*client))
848 (*rights) |= PRSFS_LOOKUP;
849 #endif /* ADMIN_IMPLICIT_LOOKUP */
852 } /*GetVolumePackage */
854 static_inline afs_int32
855 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
856 Vnode ** targetptr, int chkforDir, Vnode ** parent,
857 struct client **client, int locktype, afs_int32 * rights,
858 afs_int32 * anyrights)
860 return GetVolumePackageWithCall(tcon, NULL, Fid, volptr, targetptr,
861 chkforDir, parent, client, locktype,
867 * This is the opposite of GetVolumePackage(), and is always used at the end of
868 * AFS calls to put back all used vnodes and the volume in the proper order!
871 PutVolumePackageWithCall(Vnode * parentwhentargetnotdir, Vnode * targetptr,
872 Vnode * parentptr, Volume * volptr,
873 struct client **client, struct VCallByVol *cbv)
875 Error fileCode = 0; /* Error code returned by the volume package */
877 if (parentwhentargetnotdir) {
878 VPutVnode(&fileCode, parentwhentargetnotdir);
879 osi_Assert(!fileCode || (fileCode == VSALVAGE));
882 VPutVnode(&fileCode, targetptr);
883 osi_Assert(!fileCode || (fileCode == VSALVAGE));
886 VPutVnode(&fileCode, parentptr);
887 osi_Assert(!fileCode || (fileCode == VSALVAGE));
890 VPutVolumeWithCall(volptr, cbv);
895 } /*PutVolumePackage */
898 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
899 Vnode * parentptr, Volume * volptr, struct client **client)
901 PutVolumePackageWithCall(parentwhentargetnotdir, targetptr, parentptr,
902 volptr, client, NULL);
906 VolumeOwner(struct client *client, Vnode * targetptr)
908 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
911 return (client->ViceId == owner);
914 * We don't have to check for host's cps since only regular
915 * viceid are volume owners.
917 return (client_HasAsMember(client, owner));
923 VolumeRootVnode(Vnode * targetptr)
925 return ((targetptr->vnodeNumber == ROOTVNODE)
926 && (targetptr->disk.uniquifier == 1));
928 } /*VolumeRootVnode */
931 * Check if target file has the proper access permissions for the Fetch
932 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
933 * StoreStatus) related calls
935 /* this code should probably just set a "priv" flag where all the audit events
936 * are now, and only generate the audit event once at the end of the routine,
937 * thus only generating the event if all the checks succeed, but only because
938 * of the privilege XXX
941 Check_PermissionRights(Vnode * targetptr, struct client *client,
942 afs_int32 rights, int CallingRoutine,
943 AFSStoreStatus * InStatus)
946 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
947 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
948 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
950 if (CallingRoutine & CHK_FETCH) {
951 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
952 if (targetptr->disk.type == vDirectory
953 || targetptr->disk.type == vSymlink) {
954 if (!(rights & PRSFS_LOOKUP)
955 #ifdef ADMIN_IMPLICIT_LOOKUP
956 /* grant admins fetch on all directories */
957 && VanillaUser(client)
958 #endif /* ADMIN_IMPLICIT_LOOKUP */
959 && !VolumeOwner(client, targetptr))
962 /* must have read access, or be owner and have insert access */
963 if (!(rights & PRSFS_READ)
964 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
965 && (client->ViceId != AnonymousID))))
968 if (CallingRoutine == CHK_FETCHDATA
969 && targetptr->disk.type == vFile)
970 #ifdef USE_GROUP_PERMS
971 if (!OWNSp(client, targetptr)
972 && !client_HasAsMember(client, targetptr->disk.owner)) {
974 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
978 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
983 * The check with the ownership below is a kludge to allow
984 * reading of files created with no read permission. The owner
985 * of the file is always allowed to read it.
987 if ((client->ViceId != targetptr->disk.owner)
988 && VanillaUser(client))
990 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
991 modeBits) ? 0 : EACCES);
993 } else { /* !VanillaUser(client) && !FetchData */
995 osi_audit(PrivilegeEvent, 0, AUD_ID,
996 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
999 } else { /* a store operation */
1000 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1001 && (CallingRoutine != CHK_STOREACL)
1002 && (targetptr->disk.type == vFile)) {
1003 /* bypass protection checks on first store after a create
1004 * for the creator; also prevent chowns during this time
1005 * unless you are a system administrator */
1006 /****** InStatus->Owner && UnixModeBits better be SET!! */
1007 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1010 else if (VanillaUser(client))
1011 return (EPERM); /* Was EACCES */
1013 osi_audit(PrivilegeEvent, 0, AUD_ID,
1014 (client ? client->ViceId : 0), AUD_INT,
1015 CallingRoutine, AUD_END);
1018 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1019 osi_audit(PrivilegeEvent, 0, AUD_ID,
1020 (client ? client->ViceId : 0), AUD_INT,
1021 CallingRoutine, AUD_END);
1023 if (readonlyServer) {
1026 if (CallingRoutine == CHK_STOREACL) {
1027 if (!(rights & PRSFS_ADMINISTER)
1028 && !VolumeOwner(client, targetptr))
1030 } else { /* store data or status */
1031 /* watch for chowns and chgrps */
1032 if (CHOWN(InStatus, targetptr)
1033 || CHGRP(InStatus, targetptr)) {
1036 else if (VanillaUser(client))
1037 return (EPERM); /* Was EACCES */
1039 osi_audit(PrivilegeEvent, 0, AUD_ID,
1040 (client ? client->ViceId : 0), AUD_INT,
1041 CallingRoutine, AUD_END);
1043 /* must be sysadmin to set suid/sgid bits */
1044 if ((InStatus->Mask & AFS_SETMODE) &&
1046 (InStatus->UnixModeBits & 0xc00) != 0) {
1048 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1052 if (VanillaUser(client))
1055 osi_audit(PrivSetID, 0, AUD_ID,
1056 (client ? client->ViceId : 0), AUD_INT,
1057 CallingRoutine, AUD_END);
1059 if (CallingRoutine == CHK_STOREDATA) {
1062 if (!(rights & PRSFS_WRITE))
1064 /* Next thing is tricky. We want to prevent people
1065 * from writing files sans 0200 bit, but we want
1066 * creating new files with 0444 mode to work. We
1067 * don't check the 0200 bit in the "you are the owner"
1068 * path above, but here we check the bit. However, if
1069 * you're a system administrator, we ignore the 0200
1070 * bit anyway, since you may have fchowned the file,
1072 #ifdef USE_GROUP_PERMS
1073 if ((targetptr->disk.type == vFile)
1074 && VanillaUser(client)) {
1075 if (!OWNSp(client, targetptr)
1076 && !client_HasAsMember(client, targetptr->disk.owner)) {
1078 ((GROUPWRITE & targetptr->disk.modeBits)
1082 ((OWNERWRITE & targetptr->disk.modeBits)
1087 if ((targetptr->disk.type != vDirectory)
1088 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1091 if (VanillaUser(client))
1094 osi_audit(PrivilegeEvent, 0, AUD_ID,
1095 (client ? client->ViceId : 0),
1096 AUD_INT, CallingRoutine, AUD_END);
1098 } else { /* a status store */
1101 if (targetptr->disk.type == vDirectory) {
1102 if (!(rights & PRSFS_DELETE)
1103 && !(rights & PRSFS_INSERT))
1105 } else { /* a file or symlink */
1106 if (!(rights & PRSFS_WRITE))
1116 } /*Check_PermissionRights */
1120 * The Access List information is converted from its internal form in the
1121 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1122 * external form and returned back to the caller, via the AccessList
1126 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1127 struct AFSOpaque *AccessList)
1129 char *eACL; /* External access list placeholder */
1131 if (acl_Externalize_pr
1132 (hpr_IdToName, (targetptr->disk.type ==
1133 vDirectory ? VVnodeACL(targetptr) :
1134 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1137 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1138 acl_FreeExternalACL(&eACL);
1141 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1142 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1144 acl_FreeExternalACL(&eACL);
1147 } /*RXFetch_AccessList */
1151 * The Access List information is converted from its external form in the
1152 * input AccessList structure to the internal representation and copied into
1153 * the target dir's vnode storage.
1156 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1158 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1160 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1163 if ((newACL->size + 4) > VAclSize(targetptr))
1165 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1166 acl_FreeACL(&newACL);
1169 } /*RXStore_AccessList */
1172 /* In our current implementation, each successive data store (new file
1173 * data version) creates a new inode. This function creates the new
1174 * inode, copies the old inode's contents to the new one, remove the old
1175 * inode (i.e. decrement inode count -- if it's currently used the delete
1176 * will be delayed), and modify some fields (i.e. vnode's
1177 * disk.inodeNumber and cloned)
1179 #define COPYBUFFSIZE 8192
1180 #define MAXFSIZE (~(afs_fsize_t) 0)
1182 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1184 Inode ino, nearInode;
1191 int rc; /* return code */
1192 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1193 FdHandle_t *targFdP; /* Source Inode file handle */
1194 FdHandle_t *newFdP; /* Dest Inode file handle */
1196 if (targetptr->disk.type == vDirectory)
1197 DFlush(); /* just in case? */
1199 VN_GET_LEN(size, targetptr);
1207 buff = (char *)malloc(COPYBUFFSIZE);
1212 ino = VN_GET_INO(targetptr);
1213 if (!VALID_INO(ino)) {
1215 VTakeOffline(volptr);
1216 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1220 targFdP = IH_OPEN(targetptr->handle);
1221 if (targFdP == NULL) {
1224 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1225 targetptr->vnodeNumber, V_id(volptr), rc));
1227 VTakeOffline(volptr);
1231 nearInode = VN_GET_INO(targetptr);
1233 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1234 VPartitionPath(V_partition(volptr)), nearInode,
1235 V_id(volptr), targetptr->vnodeNumber,
1236 targetptr->disk.uniquifier,
1237 (int)targetptr->disk.dataVersion);
1238 if (!VALID_INO(ino)) {
1240 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1241 volptr->partition->name, V_id(volptr), errno));
1246 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1247 newFdP = IH_OPEN(newH);
1248 osi_Assert(newFdP != NULL);
1252 if (size > COPYBUFFSIZE) { /* more than a buffer */
1253 length = COPYBUFFSIZE;
1254 size -= COPYBUFFSIZE;
1259 rdlen = FDH_PREAD(targFdP, buff, length, done);
1260 if (rdlen == length) {
1261 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1265 /* Callers of this function are not prepared to recover
1266 * from error that put the filesystem in an inconsistent
1267 * state. Make sure that we force the volume off-line if
1268 * we some error other than ENOSPC - 4.29.99)
1270 * In case we are unable to write the required bytes, and the
1271 * error code indicates that the disk is full, we roll-back to
1272 * the initial state.
1274 if ((rdlen != length) || (wrlen != length)) {
1275 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1277 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1278 volptr->partition->name, V_id(volptr)));
1279 /* remove destination inode which was partially copied till now */
1280 FDH_REALLYCLOSE(newFdP);
1282 FDH_REALLYCLOSE(targFdP);
1283 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1286 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1287 rc, V_id(volptr), volptr->partition->name));
1288 VTakeOffline(volptr);
1293 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1294 * since we never do any I/O anywhere near 2^32 bytes at a
1295 * time, just case to an unsigned int for printing */
1298 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1299 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1300 (unsigned)wrlen, errno));
1301 #if defined(AFS_DEMAND_ATTACH_FS)
1302 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1304 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1306 /* Decrement this inode so salvager doesn't find it. */
1307 FDH_REALLYCLOSE(newFdP);
1309 FDH_REALLYCLOSE(targFdP);
1310 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1312 VTakeOffline(volptr);
1316 #ifndef AFS_PTHREAD_ENV
1318 #endif /* !AFS_PTHREAD_ENV */
1320 FDH_REALLYCLOSE(targFdP);
1321 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1322 V_parentId(volptr));
1324 IH_RELEASE(targetptr->handle);
1326 rc = FDH_SYNC(newFdP);
1327 osi_Assert(rc == 0);
1329 targetptr->handle = newH;
1330 VN_SET_INO(targetptr, ino);
1331 targetptr->disk.cloned = 0;
1332 /* Internal change to vnode, no user level change to volume - def 5445 */
1333 targetptr->changed_oldTime = 1;
1335 return 0; /* success */
1339 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1342 char *buff = malloc(COPYBUFFSIZE);
1347 afs_foff_t done = off;
1349 if (size > FDH_SIZE(targFdP) - off)
1350 size = FDH_SIZE(targFdP) - off;
1353 if (size > COPYBUFFSIZE) { /* more than a buffer */
1354 length = COPYBUFFSIZE;
1355 size -= COPYBUFFSIZE;
1360 rdlen = FDH_PREAD(targFdP, buff, length, done);
1361 if (rdlen == length) {
1362 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1368 if ((rdlen != length) || (wrlen != length)) {
1369 /* no error recovery, at the worst we'll have a "hole"
1381 * Common code to handle with removing the Name (file when it's called from
1382 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1383 * given directory, parentptr.
1385 int DT1 = 0, DT0 = 0;
1387 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1388 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1390 DirHandle childdir; /* Handle for dir package I/O */
1391 Error errorCode = 0;
1395 /* watch for invalid names */
1396 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1399 if (CheckLength(volptr, parentptr, -1)) {
1400 VTakeOffline_r(volptr);
1404 if (parentptr->disk.cloned) {
1405 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1406 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1408 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1414 /* check that the file is in the directory */
1415 SetDirHandle(dir, parentptr);
1416 if (Lookup(dir, Name, fileFid))
1418 fileFid->Volume = V_id(volptr);
1420 /* just-in-case check for something causing deadlock */
1421 if (fileFid->Vnode == parentptr->vnodeNumber)
1424 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1428 if (ChkForDir == MustBeDIR) {
1429 if ((*targetptr)->disk.type != vDirectory)
1431 } else if ((*targetptr)->disk.type == vDirectory)
1434 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1436 * If the uniquifiers dont match then instead of asserting
1437 * take the volume offline and return VSALVAGE
1439 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1440 VTakeOffline(volptr);
1442 ("Volume %u now offline, must be salvaged.\n",
1444 errorCode = VSALVAGE;
1448 if (ChkForDir == MustBeDIR) {
1449 SetDirHandle(&childdir, *targetptr);
1450 if (IsEmpty(&childdir) != 0)
1452 DZap((afs_int32 *) &childdir);
1454 (*targetptr)->delete = 1;
1455 } else if ((--(*targetptr)->disk.linkCount) == 0)
1456 (*targetptr)->delete = 1;
1457 if ((*targetptr)->delete) {
1458 if (VN_GET_INO(*targetptr)) {
1460 IH_REALLYCLOSE((*targetptr)->handle);
1462 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1463 V_parentId(volptr));
1464 IH_RELEASE((*targetptr)->handle);
1465 if (errorCode == -1) {
1467 ("DT: inode=%s, name=%s, errno=%d\n",
1468 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1470 if (errno != ENOENT)
1472 VTakeOffline(volptr);
1474 ("Volume %u now offline, must be salvaged.\n",
1482 VN_SET_INO(*targetptr, (Inode) 0);
1484 afs_fsize_t adjLength;
1485 VN_GET_LEN(adjLength, *targetptr);
1486 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1490 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1492 code = Delete(dir, (char *)Name);
1495 ("Error %d deleting %s\n", code,
1496 (((*targetptr)->disk.type ==
1497 Directory) ? "directory" : "file")));
1498 VTakeOffline(volptr);
1500 ("Volume %u now offline, must be salvaged.\n",
1513 * This routine updates the parent directory's status block after the
1514 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1515 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1519 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1520 int author, int linkcount,
1521 #if FS_STATS_DETAILED
1522 char a_inSameNetwork
1523 #endif /* FS_STATS_DETAILED */
1526 afs_fsize_t newlength; /* Holds new directory length */
1527 afs_fsize_t parentLength;
1529 #if FS_STATS_DETAILED
1530 Date currDate; /*Current date */
1531 int writeIdx; /*Write index to bump */
1532 int timeIdx; /*Authorship time index to bump */
1533 #endif /* FS_STATS_DETAILED */
1535 parentptr->disk.dataVersion++;
1536 newlength = (afs_fsize_t) Length(dir);
1538 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1539 * (create, symlink, link, makedir) so we need to check if we have enough space
1540 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1541 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1543 VN_GET_LEN(parentLength, parentptr);
1544 if (nBlocks(newlength) != nBlocks(parentLength)) {
1545 VAdjustDiskUsage(&errorCode, volptr,
1546 (nBlocks(newlength) - nBlocks(parentLength)),
1547 (nBlocks(newlength) - nBlocks(parentLength)));
1549 VN_SET_LEN(parentptr, newlength);
1551 #if FS_STATS_DETAILED
1553 * Update directory write stats for this volume. Note that the auth
1554 * counter is located immediately after its associated ``distance''
1557 if (a_inSameNetwork)
1558 writeIdx = VOL_STATS_SAME_NET;
1560 writeIdx = VOL_STATS_DIFF_NET;
1561 V_stat_writes(volptr, writeIdx)++;
1562 if (author != AnonymousID) {
1563 V_stat_writes(volptr, writeIdx + 1)++;
1567 * Update the volume's authorship information in response to this
1568 * directory operation. Get the current time, decide to which time
1569 * slot this operation belongs, and bump the appropriate slot.
1571 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1573 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1574 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1575 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1576 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1577 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1578 if (parentptr->disk.author == author) {
1579 V_stat_dirSameAuthor(volptr, timeIdx)++;
1581 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1583 #endif /* FS_STATS_DETAILED */
1585 parentptr->disk.author = author;
1586 parentptr->disk.linkCount = linkcount;
1587 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1588 parentptr->disk.serverModifyTime = FT_ApproxTime();
1589 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1594 * Update the target file's (or dir's) status block after the specified
1595 * operation is complete. Note that some other fields maybe updated by
1596 * the individual module.
1599 /* XXX INCOMPLETE - More attention is needed here! */
1601 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1602 struct client *client, AFSStoreStatus * InStatus,
1603 Vnode * parentptr, Volume * volptr,
1606 #if FS_STATS_DETAILED
1607 Date currDate; /*Current date */
1608 int writeIdx; /*Write index to bump */
1609 int timeIdx; /*Authorship time index to bump */
1610 #endif /* FS_STATS_DETAILED */
1612 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1613 targetptr->disk.parent = parentptr->vnodeNumber;
1614 VN_SET_LEN(targetptr, length);
1615 /* targetptr->disk.group = 0; save some cycles */
1616 targetptr->disk.modeBits = 0777;
1617 targetptr->disk.owner = client->ViceId;
1618 targetptr->disk.dataVersion = 0; /* consistent with the client */
1619 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1620 /* the inode was created in Alloc_NewVnode() */
1622 #if FS_STATS_DETAILED
1624 * Update file write stats for this volume. Note that the auth
1625 * counter is located immediately after its associated ``distance''
1628 if (client->InSameNetwork)
1629 writeIdx = VOL_STATS_SAME_NET;
1631 writeIdx = VOL_STATS_DIFF_NET;
1632 V_stat_writes(volptr, writeIdx)++;
1633 if (client->ViceId != AnonymousID) {
1634 V_stat_writes(volptr, writeIdx + 1)++;
1638 * We only count operations that DON'T involve creating new objects
1639 * (files, symlinks, directories) or simply setting status as
1640 * authorship-change operations.
1642 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1644 * Update the volume's authorship information in response to this
1645 * file operation. Get the current time, decide to which time
1646 * slot this operation belongs, and bump the appropriate slot.
1648 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1651 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1652 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1653 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1654 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1655 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1656 VOL_STATS_TIME_IDX_5);
1657 if (targetptr->disk.author == client->ViceId) {
1658 V_stat_fileSameAuthor(volptr, timeIdx)++;
1660 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1663 #endif /* FS_STATS_DETAILED */
1665 if (!(Caller & TVS_SSTATUS))
1666 targetptr->disk.author = client->ViceId;
1667 if (Caller & TVS_SDATA) {
1668 targetptr->disk.dataVersion++;
1669 if (VanillaUser(client)) {
1670 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1671 #ifdef CREATE_SGUID_ADMIN_ONLY
1672 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1676 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1677 /* store status, must explicitly request to change the date */
1678 if (InStatus->Mask & AFS_SETMODTIME)
1679 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1680 } else { /* other: date always changes, but perhaps to what is specified by caller */
1681 targetptr->disk.unixModifyTime =
1682 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1683 ClientModTime : FT_ApproxTime());
1685 if (InStatus->Mask & AFS_SETOWNER) {
1686 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1687 if (VanillaUser(client)) {
1688 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1689 #ifdef CREATE_SGUID_ADMIN_ONLY
1690 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1693 targetptr->disk.owner = InStatus->Owner;
1694 if (VolumeRootVnode(targetptr)) {
1695 Error errorCode = 0; /* what should be done with this? */
1697 V_owner(targetptr->volumePtr) = InStatus->Owner;
1698 VUpdateVolume(&errorCode, targetptr->volumePtr);
1701 if (InStatus->Mask & AFS_SETMODE) {
1702 int modebits = InStatus->UnixModeBits;
1703 #define CREATE_SGUID_ADMIN_ONLY 1
1704 #ifdef CREATE_SGUID_ADMIN_ONLY
1705 if (VanillaUser(client))
1706 modebits = modebits & 0777;
1708 if (VanillaUser(client)) {
1709 targetptr->disk.modeBits = modebits;
1711 targetptr->disk.modeBits = modebits;
1714 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1715 CHK_STOREDATA, AUD_END);
1719 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1720 CHK_STORESTATUS, AUD_END);
1727 targetptr->disk.serverModifyTime = FT_ApproxTime();
1728 if (InStatus->Mask & AFS_SETGROUP)
1729 targetptr->disk.group = InStatus->Group;
1730 /* vnode changed : to be written back by VPutVnode */
1731 targetptr->changed_newTime = 1;
1733 } /*Update_TargetVnodeStatus */
1737 * Fills the CallBack structure with the expiration time and type of callback
1738 * structure. Warning: this function is currently incomplete.
1741 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1743 /* CallBackTime could not be 0 */
1744 if (CallBackTime == 0) {
1745 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1746 CallBack->ExpirationTime = 0;
1748 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1749 CallBack->CallBackVersion = CALLBACK_VERSION;
1750 CallBack->CallBackType = CB_SHARED; /* The default for now */
1752 } /*SetCallBackStruct */
1756 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1757 * allocation; if some error occured (exceeded volume quota or partition
1758 * was full, or whatever), it frees the space back and returns the code.
1759 * We usually pre-adjust the volume space to make sure that there's
1760 * enough space before consuming some.
1763 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1764 afs_sfsize_t checkLength)
1769 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1771 VAdjustDiskUsage(&nc, volptr, -length, 0);
1772 if (rc == VOVERQUOTA) {
1774 ("Volume %u (%s) is full\n", V_id(volptr),
1778 if (rc == VDISKFULL) {
1780 ("Partition %s that contains volume %u is full\n",
1781 volptr->partition->name, V_id(volptr)));
1784 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1789 } /*AdjustDiskUsage */
1792 * Common code that handles the creation of a new file (SAFS_CreateFile and
1793 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1796 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1797 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1798 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1800 Error errorCode = 0; /* Error code returned back */
1803 Inode nearInode; /* hint for inode allocation in solaris */
1807 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1808 BlocksPreallocatedForVnode))) {
1810 ("Insufficient space to allocate %lld blocks\n",
1811 (afs_intmax_t) BlocksPreallocatedForVnode));
1815 if (CheckLength(volptr, parentptr, -1)) {
1816 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1817 VTakeOffline_r(volptr);
1821 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1822 if (errorCode != 0) {
1823 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1826 OutFid->Volume = V_id(volptr);
1827 OutFid->Vnode = (*targetptr)->vnodeNumber;
1828 OutFid->Unique = (*targetptr)->disk.uniquifier;
1830 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1832 /* create the inode now itself */
1834 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1835 VPartitionPath(V_partition(volptr)), nearInode,
1836 V_id(volptr), (*targetptr)->vnodeNumber,
1837 (*targetptr)->disk.uniquifier, 1);
1839 /* error in creating inode */
1840 if (!VALID_INO(inode)) {
1842 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1843 (*targetptr)->volumePtr->header->diskstuff.id,
1844 (*targetptr)->vnodeNumber, errno));
1845 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1846 (*targetptr)->delete = 1; /* delete vnode */
1849 VN_SET_INO(*targetptr, inode);
1850 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1852 /* copy group from parent dir */
1853 (*targetptr)->disk.group = parentptr->disk.group;
1855 if (parentptr->disk.cloned) {
1856 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1857 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1858 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1859 /* delete the vnode previously allocated */
1860 (*targetptr)->delete = 1;
1861 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1862 IH_REALLYCLOSE((*targetptr)->handle);
1863 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1865 ("Alloc_NewVnode: partition %s idec %s failed\n",
1866 volptr->partition->name, PrintInode(stmp, inode)));
1867 IH_RELEASE((*targetptr)->handle);
1873 /* add the name to the directory */
1874 SetDirHandle(dir, parentptr);
1875 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1876 (*targetptr)->delete = 1;
1877 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1878 IH_REALLYCLOSE((*targetptr)->handle);
1879 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1881 ("Alloc_NewVnode: partition %s idec %s failed\n",
1882 volptr->partition->name, PrintInode(stmp, inode)));
1883 IH_RELEASE((*targetptr)->handle);
1889 } /*Alloc_NewVnode */
1893 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1897 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1899 int Time; /* Used for time */
1900 int writeVnode = targetptr->changed_oldTime; /* save original status */
1902 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1903 Time = FT_ApproxTime();
1904 switch (LockingType) {
1907 if (Time > targetptr->disk.lock.lockTime)
1908 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1910 Time += AFS_LOCKWAIT;
1911 if (LockingType == LockRead) {
1912 if ( !(rights & PRSFS_LOCK) &&
1913 !(rights & PRSFS_WRITE) &&
1914 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1917 if (targetptr->disk.lock.lockCount >= 0) {
1918 ++(targetptr->disk.lock.lockCount);
1919 targetptr->disk.lock.lockTime = Time;
1922 } else if (LockingType == LockWrite) {
1923 if ( !(rights & PRSFS_WRITE) &&
1924 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1927 if (targetptr->disk.lock.lockCount == 0) {
1928 targetptr->disk.lock.lockCount = -1;
1929 targetptr->disk.lock.lockTime = Time;
1935 Time += AFS_LOCKWAIT;
1936 if (targetptr->disk.lock.lockCount != 0)
1937 targetptr->disk.lock.lockTime = Time;
1942 if ((--targetptr->disk.lock.lockCount) <= 0)
1943 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1947 targetptr->changed_oldTime = writeVnode; /* restore old status */
1948 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1951 } /*HandleLocking */
1953 /* 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. */
1956 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1960 if (!(rights & Prfs_Mode))
1962 if ((targetptr->disk.type != vDirectory)
1963 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1969 * If some flags (i.e. min or max quota) are set, the volume's in disk
1970 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1971 * update, if applicable.
1974 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1975 char *Name, char *OfflineMsg, char *Motd)
1977 Error errorCode = 0;
1979 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1980 V_minquota(volptr) = StoreVolStatus->MinQuota;
1981 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1982 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1983 if (strlen(OfflineMsg) > 0) {
1984 strcpy(V_offlineMessage(volptr), OfflineMsg);
1986 if (strlen(Name) > 0) {
1987 strcpy(V_name(volptr), Name);
1989 #if OPENAFS_VOL_STATS
1991 * We don't overwrite the motd field, since it's now being used
1995 if (strlen(Motd) > 0) {
1996 strcpy(V_motd(volptr), Motd);
1998 #endif /* FS_STATS_DETAILED */
1999 VUpdateVolume(&errorCode, volptr);
2002 } /*RXUpdate_VolumeStatus */
2006 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2007 char **motd, Volume * volptr)
2011 status->Vid = V_id(volptr);
2012 status->ParentId = V_parentId(volptr);
2013 status->Online = V_inUse(volptr);
2014 status->InService = V_inService(volptr);
2015 status->Blessed = V_blessed(volptr);
2016 status->NeedsSalvage = V_needsSalvaged(volptr);
2017 if (VolumeWriteable(volptr))
2018 status->Type = ReadWrite;
2020 status->Type = ReadOnly;
2021 status->MinQuota = V_minquota(volptr);
2022 status->MaxQuota = V_maxquota(volptr);
2023 status->BlocksInUse = V_diskused(volptr);
2024 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
2025 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
2027 /* now allocate and copy these things; they're freed by the RXGEN stub */
2028 temp = strlen(V_name(volptr)) + 1;
2029 *name = malloc(temp);
2031 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2033 strcpy(*name, V_name(volptr));
2034 temp = strlen(V_offlineMessage(volptr)) + 1;
2035 *offMsg = malloc(temp);
2037 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2039 strcpy(*offMsg, V_offlineMessage(volptr));
2040 #if OPENAFS_VOL_STATS
2043 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2045 strcpy(*motd, nullString);
2047 temp = strlen(V_motd(volptr)) + 1;
2048 *motd = malloc(temp);
2050 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2052 strcpy(*motd, V_motd(volptr));
2053 #endif /* FS_STATS_DETAILED */
2055 } /*RXGetVolumeStatus */
2059 FileNameOK(char *aname)
2064 /* watch for @sys on the right */
2065 if (strcmp(aname + i - 4, "@sys") == 0)
2068 while ((tc = *aname++)) {
2070 return 0; /* very bad character to encounter */
2072 return 1; /* file name is ok */
2078 * This variant of symlink is expressly to support the AFS/DFS translator
2079 * and is not supported by the AFS fileserver. We just return EINVAL.
2080 * The cache manager should not generate this call to an AFS cache manager.
2083 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2084 char *LinkContents, struct AFSStoreStatus *InStatus,
2085 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2086 struct AFSFetchStatus *OutDirStatus,
2087 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2093 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2094 struct FsCmdInputs * Inputs,
2095 struct FsCmdOutputs * Outputs)
2099 switch (Inputs->command) {
2103 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2104 Inputs->command, Outputs->code));
2109 static struct afs_buffer {
2110 struct afs_buffer *next;
2111 } *freeBufferList = 0;
2112 static int afs_buffersAlloced = 0;
2115 FreeSendBuffer(struct afs_buffer *adata)
2118 afs_buffersAlloced--;
2119 adata->next = freeBufferList;
2120 freeBufferList = adata;
2124 } /*FreeSendBuffer */
2126 /* allocate space for sender */
2128 AllocSendBuffer(void)
2130 struct afs_buffer *tp;
2133 afs_buffersAlloced++;
2134 if (!freeBufferList) {
2137 tmp = malloc(sendBufSize);
2139 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2143 tp = freeBufferList;
2144 freeBufferList = tp->next;
2148 } /*AllocSendBuffer */
2149 #endif /* HAVE_PIOV */
2152 * This routine returns the status info associated with the targetptr vnode
2153 * in the AFSFetchStatus structure. Some of the newer fields, such as
2154 * SegSize and Group are not yet implemented
2158 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2159 afs_int32 anyrights, Vnode * parentptr)
2161 /* initialize return status from a vnode */
2162 status->InterfaceVersion = 1;
2163 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2164 status->errorCode = 0;
2165 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2166 if (targetptr->disk.type == vFile)
2167 status->FileType = File;
2168 else if (targetptr->disk.type == vDirectory)
2169 status->FileType = Directory;
2170 else if (targetptr->disk.type == vSymlink)
2171 status->FileType = SymbolicLink;
2173 status->FileType = Invalid; /*invalid type field */
2174 status->LinkCount = targetptr->disk.linkCount;
2176 afs_fsize_t targetLen;
2177 VN_GET_LEN(targetLen, targetptr);
2178 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2180 status->DataVersion = targetptr->disk.dataVersion;
2181 status->Author = targetptr->disk.author;
2182 status->Owner = targetptr->disk.owner;
2183 status->CallerAccess = rights;
2184 status->AnonymousAccess = anyrights;
2185 status->UnixModeBits = targetptr->disk.modeBits;
2186 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2187 status->ParentVnode =
2188 (status->FileType ==
2189 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2190 status->ParentUnique =
2191 (status->FileType ==
2192 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2193 status->ServerModTime = targetptr->disk.serverModifyTime;
2194 status->Group = targetptr->disk.group;
2195 status->lockCount = targetptr->disk.lock.lockCount;
2196 status->errorCode = 0;
2202 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2203 afs_sfsize_t Pos, afs_sfsize_t Len,
2204 struct AFSFetchStatus *OutStatus,
2205 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2208 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2209 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2210 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2211 Error errorCode = 0; /* return code to caller */
2212 Error fileCode = 0; /* return code from vol package */
2213 Volume *volptr = 0; /* pointer to the volume */
2214 struct client *client = 0; /* pointer to the client data */
2215 struct rx_connection *tcon; /* the connection we're part of */
2217 afs_int32 rights, anyrights; /* rights for this and any user */
2218 struct client *t_client = NULL; /* tmp ptr to client data */
2219 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2220 struct VCallByVol tcbv, *cbv = NULL;
2221 #if FS_STATS_DETAILED
2222 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2223 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2224 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2225 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2226 struct timeval elapsedTime; /* Transfer time */
2227 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2228 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2229 int readIdx; /* Index of read stats array to bump */
2230 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2233 * Set our stats pointers, remember when the RPC operation started, and
2234 * tally the operation.
2236 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2237 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2241 FT_GetTimeOfDay(&opStartTime, 0);
2242 #endif /* FS_STATS_DETAILED */
2245 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2248 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2250 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2253 /* Get ptr to client data for user Id for logging */
2254 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2255 logHostAddr.s_addr = rxr_HostOf(tcon);
2257 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2258 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2259 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2261 queue_NodeInit(&tcbv);
2266 * Get volume/vnode for the fetched file; caller's access rights to
2267 * it are also returned
2270 GetVolumePackageWithCall(tcon, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2271 &parentwhentargetnotdir, &client, READ_LOCK,
2272 &rights, &anyrights)))
2275 SetVolumeSync(Sync, volptr);
2277 #if FS_STATS_DETAILED
2279 * Remember that another read operation was performed.
2282 if (client->InSameNetwork)
2283 readIdx = VOL_STATS_SAME_NET;
2285 readIdx = VOL_STATS_DIFF_NET;
2286 V_stat_reads(volptr, readIdx)++;
2287 if (client->ViceId != AnonymousID) {
2288 V_stat_reads(volptr, readIdx + 1)++;
2291 #endif /* FS_STATS_DETAILED */
2292 /* Check whether the caller has permission access to fetch the data */
2294 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2298 * Drop the read lock on the parent directory after saving the parent
2299 * vnode information we need to pass to GetStatus
2301 if (parentwhentargetnotdir != NULL) {
2302 tparentwhentargetnotdir = *parentwhentargetnotdir;
2303 VPutVnode(&fileCode, parentwhentargetnotdir);
2304 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2305 parentwhentargetnotdir = NULL;
2307 #if FS_STATS_DETAILED
2309 * Remember when the data transfer started.
2311 FT_GetTimeOfDay(&xferStartTime, 0);
2312 #endif /* FS_STATS_DETAILED */
2314 /* actually do the data transfer */
2315 #if FS_STATS_DETAILED
2317 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2318 &bytesToXfer, &bytesXferred);
2321 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2323 #endif /* FS_STATS_DETAILED */
2325 #if FS_STATS_DETAILED
2327 * At this point, the data transfer is done, for good or ill. Remember
2328 * when the transfer ended, bump the number of successes/failures, and
2329 * integrate the transfer size and elapsed time into the stats. If the
2330 * operation failed, we jump to the appropriate point.
2332 FT_GetTimeOfDay(&xferStopTime, 0);
2334 (xferP->numXfers)++;
2336 (xferP->numSuccesses)++;
2339 * Bump the xfer sum by the number of bytes actually sent, NOT the
2342 tot_bytesXferred += bytesXferred;
2343 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2344 tot_bytesXferred &= 0x3FF;
2345 if (bytesXferred < xferP->minBytes)
2346 xferP->minBytes = bytesXferred;
2347 if (bytesXferred > xferP->maxBytes)
2348 xferP->maxBytes = bytesXferred;
2351 * Tally the size of the object. Note: we tally the actual size,
2352 * NOT the number of bytes that made it out over the wire.
2354 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2355 (xferP->count[0])++;
2356 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2357 (xferP->count[1])++;
2358 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2359 (xferP->count[2])++;
2360 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2361 (xferP->count[3])++;
2362 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2363 (xferP->count[4])++;
2364 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2365 (xferP->count[5])++;
2366 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2367 (xferP->count[6])++;
2368 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2369 (xferP->count[7])++;
2371 (xferP->count[8])++;
2373 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2374 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2375 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2376 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2377 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2379 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2380 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2385 * Finally, go off to tell our caller the bad news in case the
2390 #endif /* FS_STATS_DETAILED */
2392 /* write back the OutStatus from the target vnode */
2393 GetStatus(targetptr, OutStatus, rights, anyrights,
2394 &tparentwhentargetnotdir);
2396 /* if a r/w volume, promise a callback to the caller */
2397 if (VolumeWriteable(volptr))
2398 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2400 struct AFSFid myFid;
2401 memset(&myFid, 0, sizeof(struct AFSFid));
2402 myFid.Volume = Fid->Volume;
2403 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2407 /* Update and store volume/vnode and parent vnodes back */
2408 (void)PutVolumePackageWithCall(parentwhentargetnotdir, targetptr,
2409 (Vnode *) 0, volptr, &client, cbv);
2410 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2411 errorCode = CallPostamble(tcon, errorCode, thost);
2413 #if FS_STATS_DETAILED
2414 FT_GetTimeOfDay(&opStopTime, 0);
2415 if (errorCode == 0) {
2417 (opP->numSuccesses)++;
2418 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2419 fs_stats_AddTo((opP->sumTime), elapsedTime);
2420 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2421 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2422 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2424 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2425 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2429 #endif /* FS_STATS_DETAILED */
2431 osi_auditU(acall, FetchDataEvent, errorCode,
2432 AUD_ID, t_client ? t_client->ViceId : 0,
2433 AUD_FID, Fid, AUD_END);
2436 } /*SRXAFS_FetchData */
2439 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2440 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2441 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2443 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2448 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2449 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2450 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2453 afs_sfsize_t tPos, tLen;
2455 tPos = (afs_sfsize_t) Pos;
2456 tLen = (afs_sfsize_t) Len;
2459 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2465 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2466 struct AFSOpaque * AccessList,
2467 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2469 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2470 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2471 Error errorCode = 0; /* return error code to caller */
2472 Volume *volptr = 0; /* pointer to the volume */
2473 struct client *client = 0; /* pointer to the client data */
2474 afs_int32 rights, anyrights; /* rights for this and any user */
2475 struct rx_connection *tcon = rx_ConnectionOf(acall);
2477 struct client *t_client = NULL; /* tmp ptr to client data */
2478 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2479 #if FS_STATS_DETAILED
2480 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2481 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2482 struct timeval elapsedTime; /* Transfer time */
2485 * Set our stats pointer, remember when the RPC operation started, and
2486 * tally the operation.
2488 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2492 FT_GetTimeOfDay(&opStartTime, 0);
2493 #endif /* FS_STATS_DETAILED */
2496 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2499 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2501 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2504 /* Get ptr to client data for user Id for logging */
2505 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2506 logHostAddr.s_addr = rxr_HostOf(tcon);
2508 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2509 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2510 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2512 AccessList->AFSOpaque_len = 0;
2513 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2514 if (!AccessList->AFSOpaque_val) {
2515 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2519 * Get volume/vnode for the fetched file; caller's access rights to it
2523 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2524 &parentwhentargetnotdir, &client, READ_LOCK,
2525 &rights, &anyrights)))
2528 SetVolumeSync(Sync, volptr);
2530 /* Check whether we have permission to fetch the ACL */
2532 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2535 /* Get the Access List from the dir's vnode */
2537 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2540 /* Get OutStatus back From the target Vnode */
2541 GetStatus(targetptr, OutStatus, rights, anyrights,
2542 parentwhentargetnotdir);
2545 /* Update and store volume/vnode and parent vnodes back */
2546 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2549 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2550 AccessList->AFSOpaque_val));
2551 errorCode = CallPostamble(tcon, errorCode, thost);
2553 #if FS_STATS_DETAILED
2554 FT_GetTimeOfDay(&opStopTime, 0);
2555 if (errorCode == 0) {
2557 (opP->numSuccesses)++;
2558 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2559 fs_stats_AddTo((opP->sumTime), elapsedTime);
2560 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2561 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2562 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2564 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2565 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2569 #endif /* FS_STATS_DETAILED */
2571 osi_auditU(acall, FetchACLEvent, errorCode,
2572 AUD_ID, t_client ? t_client->ViceId : 0,
2574 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2576 } /*SRXAFS_FetchACL */
2580 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2581 * merged into it when possible.
2585 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2586 struct AFSFetchStatus *OutStatus,
2587 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2589 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2590 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2591 Error errorCode = 0; /* return code to caller */
2592 Volume *volptr = 0; /* pointer to the volume */
2593 struct client *client = 0; /* pointer to the client data */
2594 afs_int32 rights, anyrights; /* rights for this and any user */
2595 struct client *t_client = NULL; /* tmp ptr to client data */
2596 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2597 struct rx_connection *tcon = rx_ConnectionOf(acall);
2599 /* Get ptr to client data for user Id for logging */
2600 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2601 logHostAddr.s_addr = rxr_HostOf(tcon);
2603 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2604 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2605 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2607 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2610 * Get volume/vnode for the fetched file; caller's rights to it are
2614 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2615 &parentwhentargetnotdir, &client, READ_LOCK,
2616 &rights, &anyrights)))
2617 goto Bad_FetchStatus;
2619 /* set volume synchronization information */
2620 SetVolumeSync(Sync, volptr);
2622 /* Are we allowed to fetch Fid's status? */
2623 if (targetptr->disk.type != vDirectory) {
2625 Check_PermissionRights(targetptr, client, rights,
2626 CHK_FETCHSTATUS, 0))) {
2627 if (rx_GetCallAbortCode(acall) == errorCode)
2628 rx_SetCallAbortCode(acall, 0);
2629 goto Bad_FetchStatus;
2633 /* set OutStatus From the Fid */
2634 GetStatus(targetptr, OutStatus, rights, anyrights,
2635 parentwhentargetnotdir);
2637 /* If a r/w volume, also set the CallBack state */
2638 if (VolumeWriteable(volptr))
2639 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2641 struct AFSFid myFid;
2642 memset(&myFid, 0, sizeof(struct AFSFid));
2643 myFid.Volume = Fid->Volume;
2644 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2648 /* Update and store volume/vnode and parent vnodes back */
2649 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2651 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2654 } /*SAFSS_FetchStatus */
2658 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2659 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2660 struct AFSVolSync * Sync)
2664 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2665 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2666 Error errorCode = 0; /* return code to caller */
2667 Volume *volptr = 0; /* pointer to the volume */
2668 struct client *client = 0; /* pointer to the client data */
2669 afs_int32 rights, anyrights; /* rights for this and any user */
2670 struct AFSFid *tfid; /* file id we're dealing with now */
2671 struct rx_connection *tcon = rx_ConnectionOf(acall);
2673 struct client *t_client = NULL; /* tmp pointer to the client data */
2674 #if FS_STATS_DETAILED
2675 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2676 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2677 struct timeval elapsedTime; /* Transfer time */
2680 * Set our stats pointer, remember when the RPC operation started, and
2681 * tally the operation.
2683 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2687 FT_GetTimeOfDay(&opStartTime, 0);
2688 #endif /* FS_STATS_DETAILED */
2690 ViceLog(1, ("SAFS_BulkStatus\n"));
2692 AFSCallStats.TotalCalls++;
2694 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2695 if (nfiles <= 0) { /* Sanity check */
2697 goto Audit_and_Return;
2700 /* allocate space for return output parameters */
2701 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2702 malloc(nfiles * sizeof(struct AFSFetchStatus));
2703 if (!OutStats->AFSBulkStats_val) {
2704 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2706 OutStats->AFSBulkStats_len = nfiles;
2707 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2708 malloc(nfiles * sizeof(struct AFSCallBack));
2709 if (!CallBacks->AFSCBs_val) {
2710 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2712 CallBacks->AFSCBs_len = nfiles;
2714 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2715 goto Bad_BulkStatus;
2717 tfid = Fids->AFSCBFids_val;
2718 for (i = 0; i < nfiles; i++, tfid++) {
2720 * Get volume/vnode for the fetched file; caller's rights to it
2724 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2725 &parentwhentargetnotdir, &client, READ_LOCK,
2726 &rights, &anyrights)))
2727 goto Bad_BulkStatus;
2728 /* set volume synchronization information, but only once per call */
2730 SetVolumeSync(Sync, volptr);
2732 /* Are we allowed to fetch Fid's status? */
2733 if (targetptr->disk.type != vDirectory) {
2735 Check_PermissionRights(targetptr, client, rights,
2736 CHK_FETCHSTATUS, 0))) {
2737 if (rx_GetCallAbortCode(acall) == errorCode)
2738 rx_SetCallAbortCode(acall, 0);
2739 goto Bad_BulkStatus;
2743 /* set OutStatus From the Fid */
2744 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2745 anyrights, parentwhentargetnotdir);
2747 /* If a r/w volume, also set the CallBack state */
2748 if (VolumeWriteable(volptr))
2749 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2750 &CallBacks->AFSCBs_val[i]);
2752 struct AFSFid myFid;
2753 memset(&myFid, 0, sizeof(struct AFSFid));
2754 myFid.Volume = tfid->Volume;
2755 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2756 &CallBacks->AFSCBs_val[i]);
2759 /* put back the file ID and volume */
2760 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2762 parentwhentargetnotdir = (Vnode *) 0;
2763 targetptr = (Vnode *) 0;
2764 volptr = (Volume *) 0;
2765 client = (struct client *)0;
2769 /* Update and store volume/vnode and parent vnodes back */
2770 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2772 errorCode = CallPostamble(tcon, errorCode, thost);
2774 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2776 #if FS_STATS_DETAILED
2777 FT_GetTimeOfDay(&opStopTime, 0);
2778 if (errorCode == 0) {
2780 (opP->numSuccesses)++;
2781 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2782 fs_stats_AddTo((opP->sumTime), elapsedTime);
2783 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2784 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2785 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2787 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2788 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2792 #endif /* FS_STATS_DETAILED */
2795 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2796 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2797 AUD_ID, t_client ? t_client->ViceId : 0,
2798 AUD_FIDS, Fids, AUD_END);
2801 } /*SRXAFS_BulkStatus */
2805 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2806 struct AFSBulkStats * OutStats,
2807 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2811 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2812 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2813 Error errorCode = 0; /* return code to caller */
2814 Volume *volptr = 0; /* pointer to the volume */
2815 struct client *client = 0; /* pointer to the client data */
2816 afs_int32 rights, anyrights; /* rights for this and any user */
2817 struct AFSFid *tfid; /* file id we're dealing with now */
2818 struct rx_connection *tcon;
2820 struct client *t_client = NULL; /* tmp ptr to client data */
2821 AFSFetchStatus *tstatus;
2822 int VolSync_set = 0;
2823 #if FS_STATS_DETAILED
2824 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2825 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2826 struct timeval elapsedTime; /* Transfer time */
2829 * Set our stats pointer, remember when the RPC operation started, and
2830 * tally the operation.
2832 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2836 FT_GetTimeOfDay(&opStartTime, 0);
2837 #endif /* FS_STATS_DETAILED */
2839 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2841 AFSCallStats.TotalCalls++;
2843 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2844 if (nfiles <= 0) { /* Sanity check */
2846 goto Audit_and_Return;
2849 /* allocate space for return output parameters */
2850 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2851 malloc(nfiles * sizeof(struct AFSFetchStatus));
2852 if (!OutStats->AFSBulkStats_val) {
2853 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2855 OutStats->AFSBulkStats_len = nfiles;
2856 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2857 malloc(nfiles * sizeof(struct AFSCallBack));
2858 if (!CallBacks->AFSCBs_val) {
2859 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2861 CallBacks->AFSCBs_len = nfiles;
2863 /* Zero out return values to avoid leaking information on partial succes */
2864 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2865 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2866 memset(Sync, 0, sizeof(*Sync));
2868 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2869 goto Bad_InlineBulkStatus;
2872 tfid = Fids->AFSCBFids_val;
2873 for (i = 0; i < nfiles; i++, tfid++) {
2875 * Get volume/vnode for the fetched file; caller's rights to it
2879 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2880 &parentwhentargetnotdir, &client, READ_LOCK,
2881 &rights, &anyrights))) {
2882 tstatus = &OutStats->AFSBulkStats_val[i];
2883 tstatus->errorCode = errorCode;
2884 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2886 parentwhentargetnotdir = (Vnode *) 0;
2887 targetptr = (Vnode *) 0;
2888 volptr = (Volume *) 0;
2889 client = (struct client *)0;
2893 /* set volume synchronization information, but only once per call */
2895 SetVolumeSync(Sync, volptr);
2899 /* Are we allowed to fetch Fid's status? */
2900 if (targetptr->disk.type != vDirectory) {
2902 Check_PermissionRights(targetptr, client, rights,
2903 CHK_FETCHSTATUS, 0))) {
2904 tstatus = &OutStats->AFSBulkStats_val[i];
2905 tstatus->errorCode = errorCode;
2906 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2907 (Vnode *) 0, volptr, &client);
2908 parentwhentargetnotdir = (Vnode *) 0;
2909 targetptr = (Vnode *) 0;
2910 volptr = (Volume *) 0;
2911 client = (struct client *)0;
2916 /* set OutStatus From the Fid */
2917 GetStatus(targetptr,
2918 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2919 rights, anyrights, parentwhentargetnotdir);
2921 /* If a r/w volume, also set the CallBack state */
2922 if (VolumeWriteable(volptr))
2923 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2924 &CallBacks->AFSCBs_val[i]);
2926 struct AFSFid myFid;
2927 memset(&myFid, 0, sizeof(struct AFSFid));
2928 myFid.Volume = tfid->Volume;
2929 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2930 &CallBacks->AFSCBs_val[i]);
2933 /* put back the file ID and volume */
2934 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2936 parentwhentargetnotdir = (Vnode *) 0;
2937 targetptr = (Vnode *) 0;
2938 volptr = (Volume *) 0;
2939 client = (struct client *)0;
2942 Bad_InlineBulkStatus:
2943 /* Update and store volume/vnode and parent vnodes back */
2944 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2946 errorCode = CallPostamble(tcon, errorCode, thost);
2948 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2950 #if FS_STATS_DETAILED
2951 FT_GetTimeOfDay(&opStopTime, 0);
2952 if (errorCode == 0) {
2954 (opP->numSuccesses)++;
2955 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2956 fs_stats_AddTo((opP->sumTime), elapsedTime);
2957 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2958 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2959 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2961 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2962 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2966 #endif /* FS_STATS_DETAILED */
2969 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2970 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2971 AUD_ID, t_client ? t_client->ViceId : 0,
2972 AUD_FIDS, Fids, AUD_END);
2975 } /*SRXAFS_InlineBulkStatus */
2979 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2980 struct AFSFetchStatus * OutStatus,
2981 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2984 struct rx_connection *tcon;
2986 struct client *t_client = NULL; /* tmp ptr to client data */
2987 #if FS_STATS_DETAILED
2988 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2989 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2990 struct timeval elapsedTime; /* Transfer time */
2993 * Set our stats pointer, remember when the RPC operation started, and
2994 * tally the operation.
2996 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
3000 FT_GetTimeOfDay(&opStartTime, 0);
3001 #endif /* FS_STATS_DETAILED */
3003 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3004 goto Bad_FetchStatus;
3006 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
3009 code = CallPostamble(tcon, code, thost);
3011 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3013 #if FS_STATS_DETAILED
3014 FT_GetTimeOfDay(&opStopTime, 0);
3017 (opP->numSuccesses)++;
3018 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3019 fs_stats_AddTo((opP->sumTime), elapsedTime);
3020 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3021 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3022 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3024 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3025 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3029 #endif /* FS_STATS_DETAILED */
3031 osi_auditU(acall, FetchStatusEvent, code,
3032 AUD_ID, t_client ? t_client->ViceId : 0,
3033 AUD_FID, Fid, AUD_END);
3036 } /*SRXAFS_FetchStatus */
3040 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
3041 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
3042 afs_fsize_t Length, afs_fsize_t FileLength,
3043 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3045 Vnode *targetptr = 0; /* pointer to input fid */
3046 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3047 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
3048 Error errorCode = 0; /* return code for caller */
3049 Error fileCode = 0; /* return code from vol package */
3050 Volume *volptr = 0; /* pointer to the volume header */
3051 struct client *client = 0; /* pointer to client structure */
3052 afs_int32 rights, anyrights; /* rights for this and any user */
3053 struct client *t_client = NULL; /* tmp ptr to client data */
3054 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3055 struct rx_connection *tcon;
3057 #if FS_STATS_DETAILED
3058 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3059 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
3060 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3061 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
3062 struct timeval elapsedTime; /* Transfer time */
3063 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
3064 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
3065 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
3068 * Set our stats pointers, remember when the RPC operation started, and
3069 * tally the operation.
3071 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
3072 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
3077 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3079 FT_GetTimeOfDay(&opStartTime, 0);
3080 #endif /* FS_STATS_DETAILED */
3083 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3085 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3088 /* Get ptr to client data for user Id for logging */
3089 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3090 logHostAddr.s_addr = rxr_HostOf(tcon);
3092 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3093 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3094 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3097 * Get associated volume/vnode for the stored file; caller's rights
3101 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3102 &parentwhentargetnotdir, &client, WRITE_LOCK,
3103 &rights, &anyrights))) {
3107 /* set volume synchronization information */
3108 SetVolumeSync(Sync, volptr);
3110 if ((targetptr->disk.type == vSymlink)) {
3111 /* Should we return a better error code here??? */
3116 /* Check if we're allowed to store the data */
3118 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3124 * Drop the read lock on the parent directory after saving the parent
3125 * vnode information we need to pass to GetStatus
3127 if (parentwhentargetnotdir != NULL) {
3128 tparentwhentargetnotdir = *parentwhentargetnotdir;
3129 VPutVnode(&fileCode, parentwhentargetnotdir);
3130 osi_Assert(!fileCode || (fileCode == VSALVAGE));
3131 parentwhentargetnotdir = NULL;
3133 #if FS_STATS_DETAILED
3135 * Remember when the data transfer started.
3137 FT_GetTimeOfDay(&xferStartTime, 0);
3138 #endif /* FS_STATS_DETAILED */
3140 /* Do the actual storing of the data */
3141 #if FS_STATS_DETAILED
3143 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3144 FileLength, (InStatus->Mask & AFS_FSYNC),
3145 &bytesToXfer, &bytesXferred);
3148 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3149 FileLength, (InStatus->Mask & AFS_FSYNC));
3150 if (errorCode && (!targetptr->changed_newTime))
3152 #endif /* FS_STATS_DETAILED */
3153 #if FS_STATS_DETAILED
3155 * At this point, the data transfer is done, for good or ill. Remember
3156 * when the transfer ended, bump the number of successes/failures, and
3157 * integrate the transfer size and elapsed time into the stats. If the
3158 * operation failed, we jump to the appropriate point.
3160 FT_GetTimeOfDay(&xferStopTime, 0);
3162 (xferP->numXfers)++;
3164 (xferP->numSuccesses)++;
3167 * Bump the xfer sum by the number of bytes actually sent, NOT the
3170 tot_bytesXferred += bytesXferred;
3171 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3172 tot_bytesXferred &= 0x3FF;
3173 if (bytesXferred < xferP->minBytes)
3174 xferP->minBytes = bytesXferred;
3175 if (bytesXferred > xferP->maxBytes)
3176 xferP->maxBytes = bytesXferred;
3179 * Tally the size of the object. Note: we tally the actual size,
3180 * NOT the number of bytes that made it out over the wire.
3182 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3183 (xferP->count[0])++;
3184 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3185 (xferP->count[1])++;
3186 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3187 (xferP->count[2])++;
3188 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3189 (xferP->count[3])++;
3190 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3191 (xferP->count[4])++;
3192 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3193 (xferP->count[5])++;
3194 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3195 (xferP->count[6])++;
3196 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3197 (xferP->count[7])++;
3199 (xferP->count[8])++;
3201 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3202 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3203 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3204 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3205 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3207 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3208 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3213 * Finally, go off to tell our caller the bad news in case the
3216 if (errorCode && (!targetptr->changed_newTime))
3218 #endif /* FS_STATS_DETAILED */
3220 /* Update the status of the target's vnode */
3221 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3222 targetptr, volptr, 0);
3224 /* Get the updated File's status back to the caller */
3225 GetStatus(targetptr, OutStatus, rights, anyrights,
3226 &tparentwhentargetnotdir);
3229 /* Update and store volume/vnode and parent vnodes back */
3230 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3232 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3234 errorCode = CallPostamble(tcon, errorCode, thost);
3236 #if FS_STATS_DETAILED
3237 FT_GetTimeOfDay(&opStopTime, 0);
3238 if (errorCode == 0) {
3240 (opP->numSuccesses)++;
3241 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3242 fs_stats_AddTo((opP->sumTime), elapsedTime);
3243 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3244 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3245 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3247 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3248 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3252 #endif /* FS_STATS_DETAILED */
3253 osi_auditU(acall, StoreDataEvent, errorCode,
3254 AUD_ID, t_client ? t_client->ViceId : 0,
3255 AUD_FID, Fid, AUD_END);
3257 } /*common_StoreData64 */
3260 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3261 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3262 afs_uint32 Length, afs_uint32 FileLength,
3263 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3265 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3266 (0x7fffffff - Pos) < Length)
3269 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3271 } /*SRXAFS_StoreData */
3274 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3275 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3276 afs_uint64 Length, afs_uint64 FileLength,
3277 struct AFSFetchStatus * OutStatus,
3278 struct AFSVolSync * Sync)
3282 afs_fsize_t tLength;
3283 afs_fsize_t tFileLength;
3285 tPos = (afs_fsize_t) Pos;
3286 tLength = (afs_fsize_t) Length;
3287 tFileLength = (afs_fsize_t) FileLength;
3290 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3296 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3297 struct AFSOpaque * AccessList,
3298 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3300 Vnode *targetptr = 0; /* pointer to input fid */
3301 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3302 Error errorCode = 0; /* return code for caller */
3303 struct AFSStoreStatus InStatus; /* Input status for fid */
3304 Volume *volptr = 0; /* pointer to the volume header */
3305 struct client *client = 0; /* pointer to client structure */
3306 afs_int32 rights, anyrights; /* rights for this and any user */
3307 struct rx_connection *tcon;
3309 struct client *t_client = NULL; /* tmp ptr to client data */
3310 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3311 #if FS_STATS_DETAILED
3312 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3313 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3314 struct timeval elapsedTime; /* Transfer time */
3317 * Set our stats pointer, remember when the RPC operation started, and
3318 * tally the operation.
3320 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3324 FT_GetTimeOfDay(&opStartTime, 0);
3325 #endif /* FS_STATS_DETAILED */
3326 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3329 /* Get ptr to client data for user Id for logging */
3330 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3331 logHostAddr.s_addr = rxr_HostOf(tcon);
3333 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3334 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3335 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3337 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3339 InStatus.Mask = 0; /* not storing any status */
3342 * Get associated volume/vnode for the target dir; caller's rights
3343 * are also returned.
3346 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3347 &parentwhentargetnotdir, &client, WRITE_LOCK,
3348 &rights, &anyrights))) {
3352 /* set volume synchronization information */
3353 SetVolumeSync(Sync, volptr);
3355 /* Check if we have permission to change the dir's ACL */
3357 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3362 /* Build and store the new Access List for the dir */
3363 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3367 targetptr->changed_newTime = 1; /* status change of directory */
3369 /* convert the write lock to a read lock before breaking callbacks */
3370 VVnodeWriteToRead(&errorCode, targetptr);
3371 osi_Assert(!errorCode || errorCode == VSALVAGE);
3373 /* break call backs on the directory */
3374 BreakCallBack(client->host, Fid, 0);
3376 /* Get the updated dir's status back to the caller */
3377 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3380 /* Update and store volume/vnode and parent vnodes back */
3381 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3383 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3384 errorCode = CallPostamble(tcon, errorCode, thost);
3386 #if FS_STATS_DETAILED
3387 FT_GetTimeOfDay(&opStopTime, 0);
3388 if (errorCode == 0) {
3390 (opP->numSuccesses)++;
3391 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3392 fs_stats_AddTo((opP->sumTime), elapsedTime);
3393 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3394 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3395 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3397 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3398 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3402 #endif /* FS_STATS_DETAILED */
3404 osi_auditU(acall, StoreACLEvent, errorCode,
3405 AUD_ID, t_client ? t_client->ViceId : 0,
3406 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3409 } /*SRXAFS_StoreACL */
3413 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3414 * should be merged when possible.
3417 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3418 struct AFSStoreStatus *InStatus,
3419 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3421 Vnode *targetptr = 0; /* pointer to input fid */
3422 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3423 Error errorCode = 0; /* return code for caller */
3424 Volume *volptr = 0; /* pointer to the volume header */
3425 struct client *client = 0; /* pointer to client structure */
3426 afs_int32 rights, anyrights; /* rights for this and any user */
3427 struct client *t_client = NULL; /* tmp ptr to client data */
3428 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3429 struct rx_connection *tcon = rx_ConnectionOf(acall);
3431 /* Get ptr to client data for user Id for logging */
3432 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3433 logHostAddr.s_addr = rxr_HostOf(tcon);
3435 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3436 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3437 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3439 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3442 * Get volume/vnode for the target file; caller's rights to it are
3446 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3447 &parentwhentargetnotdir, &client, WRITE_LOCK,
3448 &rights, &anyrights))) {
3449 goto Bad_StoreStatus;
3452 /* set volume synchronization information */
3453 SetVolumeSync(Sync, volptr);
3455 /* Check if the caller has proper permissions to store status to Fid */
3457 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3459 goto Bad_StoreStatus;
3462 * Check for a symbolic link; we can't chmod these (otherwise could
3463 * change a symlink to a mt pt or vice versa)
3465 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3467 goto Bad_StoreStatus;
3470 /* Update the status of the target's vnode */
3471 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3472 (parentwhentargetnotdir ? parentwhentargetnotdir
3473 : targetptr), volptr, 0);
3475 /* convert the write lock to a read lock before breaking callbacks */
3476 VVnodeWriteToRead(&errorCode, targetptr);
3477 osi_Assert(!errorCode || errorCode == VSALVAGE);
3479 /* Break call backs on Fid */
3480 BreakCallBack(client->host, Fid, 0);
3482 /* Return the updated status back to caller */
3483 GetStatus(targetptr, OutStatus, rights, anyrights,
3484 parentwhentargetnotdir);
3487 /* Update and store volume/vnode and parent vnodes back */
3488 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3490 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3493 } /*SAFSS_StoreStatus */
3497 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3498 struct AFSStoreStatus * InStatus,
3499 struct AFSFetchStatus * OutStatus,
3500 struct AFSVolSync * Sync)
3503 struct rx_connection *tcon;
3505 struct client *t_client = NULL; /* tmp ptr to client data */
3506 #if FS_STATS_DETAILED
3507 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3508 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3509 struct timeval elapsedTime; /* Transfer time */
3512 * Set our stats pointer, remember when the RPC operation started, and
3513 * tally the operation.
3515 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3519 FT_GetTimeOfDay(&opStartTime, 0);
3520 #endif /* FS_STATS_DETAILED */
3522 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3523 goto Bad_StoreStatus;
3525 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3528 code = CallPostamble(tcon, code, thost);
3530 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3532 #if FS_STATS_DETAILED
3533 FT_GetTimeOfDay(&opStopTime, 0);
3536 (opP->numSuccesses)++;
3537 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3538 fs_stats_AddTo((opP->sumTime), elapsedTime);
3539 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3540 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3541 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3543 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3544 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3548 #endif /* FS_STATS_DETAILED */
3550 osi_auditU(acall, StoreStatusEvent, code,
3551 AUD_ID, t_client ? t_client->ViceId : 0,
3552 AUD_FID, Fid, AUD_END);
3555 } /*SRXAFS_StoreStatus */
3559 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3560 * merged in when possible.
3563 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3564 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3566 Vnode *parentptr = 0; /* vnode of input Directory */
3567 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3568 Vnode *targetptr = 0; /* file to be deleted */
3569 Volume *volptr = 0; /* pointer to the volume header */
3570 AFSFid fileFid; /* area for Fid from the directory */
3571 Error errorCode = 0; /* error code */
3572 DirHandle dir; /* Handle for dir package I/O */
3573 struct client *client = 0; /* pointer to client structure */
3574 afs_int32 rights, anyrights; /* rights for this and any user */
3575 struct client *t_client; /* tmp ptr to client data */
3576 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3577 struct rx_connection *tcon = rx_ConnectionOf(acall);
3580 /* Get ptr to client data for user Id for logging */
3581 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3582 logHostAddr.s_addr = rxr_HostOf(tcon);
3584 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3585 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3586 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3588 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3591 * Get volume/vnode for the parent dir; caller's access rights are
3595 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3596 &parentwhentargetnotdir, &client, WRITE_LOCK,
3597 &rights, &anyrights))) {
3598 goto Bad_RemoveFile;
3600 /* set volume synchronization information */
3601 SetVolumeSync(Sync, volptr);
3603 /* Does the caller has delete (& write) access to the parent directory? */
3604 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3605 goto Bad_RemoveFile;
3608 /* Actually delete the desired file */
3610 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3612 goto Bad_RemoveFile;
3615 /* Update the vnode status of the parent dir */
3616 #if FS_STATS_DETAILED
3617 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3618 parentptr->disk.linkCount,
3619 client->InSameNetwork);
3621 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3622 parentptr->disk.linkCount);
3623 #endif /* FS_STATS_DETAILED */
3625 /* Return the updated parent dir's status back to caller */
3626 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3628 /* Handle internal callback state for the parent and the deleted file */
3629 if (targetptr->disk.linkCount == 0) {
3630 /* no references left, discard entry */
3631 DeleteFileCallBacks(&fileFid);
3632 /* convert the parent lock to a read lock before breaking callbacks */
3633 VVnodeWriteToRead(&errorCode, parentptr);
3634 osi_Assert(!errorCode || errorCode == VSALVAGE);
3636 /* convert the parent lock to a read lock before breaking callbacks */
3637 VVnodeWriteToRead(&errorCode, parentptr);
3638 osi_Assert(!errorCode || errorCode == VSALVAGE);
3639 /* convert the target lock to a read lock before breaking callbacks */
3640 VVnodeWriteToRead(&errorCode, targetptr);
3641 osi_Assert(!errorCode || errorCode == VSALVAGE);
3642 /* tell all the file has changed */
3643 BreakCallBack(client->host, &fileFid, 1);
3646 /* break call back on the directory */
3647 BreakCallBack(client->host, DirFid, 0);
3650 /* Update and store volume/vnode and parent vnodes back */
3651 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3654 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3657 } /*SAFSS_RemoveFile */
3661 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3662 struct AFSFetchStatus * OutDirStatus,
3663 struct AFSVolSync * Sync)
3666 struct rx_connection *tcon;
3668 struct client *t_client = NULL; /* tmp ptr to client data */
3669 #if FS_STATS_DETAILED
3670 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3671 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3672 struct timeval elapsedTime; /* Transfer time */
3675 * Set our stats pointer, remember when the RPC operation started, and
3676 * tally the operation.
3678 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3682 FT_GetTimeOfDay(&opStartTime, 0);
3683 #endif /* FS_STATS_DETAILED */
3685 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3686 goto Bad_RemoveFile;
3688 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3691 code = CallPostamble(tcon, code, thost);
3693 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3695 #if FS_STATS_DETAILED
3696 FT_GetTimeOfDay(&opStopTime, 0);
3699 (opP->numSuccesses)++;
3700 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3701 fs_stats_AddTo((opP->sumTime), elapsedTime);
3702 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3703 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3704 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3706 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3707 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3711 #endif /* FS_STATS_DETAILED */
3713 osi_auditU(acall, RemoveFileEvent, code,
3714 AUD_ID, t_client ? t_client->ViceId : 0,
3715 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3718 } /*SRXAFS_RemoveFile */
3722 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3723 * be merged in when possible.
3726 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3727 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3728 struct AFSFetchStatus *OutFidStatus,
3729 struct AFSFetchStatus *OutDirStatus,
3730 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3732 Vnode *parentptr = 0; /* vnode of input Directory */
3733 Vnode *targetptr = 0; /* vnode of the new file */
3734 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3735 Volume *volptr = 0; /* pointer to the volume header */
3736 Error errorCode = 0; /* error code */
3737 DirHandle dir; /* Handle for dir package I/O */
3738 struct client *client = 0; /* pointer to client structure */
3739 afs_int32 rights, anyrights; /* rights for this and any user */
3740 struct client *t_client; /* tmp ptr to client data */
3741 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3742 struct rx_connection *tcon = rx_ConnectionOf(acall);
3746 /* Get ptr to client data for user Id for logging */
3747 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3748 logHostAddr.s_addr = rxr_HostOf(tcon);
3750 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3751 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3752 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3754 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3756 if (!FileNameOK(Name)) {
3758 goto Bad_CreateFile;
3762 * Get associated volume/vnode for the parent dir; caller long are
3766 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3767 &parentwhentargetnotdir, &client, WRITE_LOCK,
3768 &rights, &anyrights))) {
3769 goto Bad_CreateFile;
3772 /* set volume synchronization information */
3773 SetVolumeSync(Sync, volptr);
3775 /* Can we write (and insert) onto the parent directory? */
3776 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3777 goto Bad_CreateFile;
3779 /* get a new vnode for the file to be created and set it up */
3781 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3782 vFile, nBlocks(0)))) {
3783 goto Bad_CreateFile;
3786 /* update the status of the parent vnode */
3787 #if FS_STATS_DETAILED
3788 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3789 parentptr->disk.linkCount,
3790 client->InSameNetwork);
3792 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3793 parentptr->disk.linkCount);
3794 #endif /* FS_STATS_DETAILED */
3796 /* update the status of the new file's vnode */
3797 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3798 parentptr, volptr, 0);
3800 /* 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 */
3801 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3802 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3804 /* convert the write lock to a read lock before breaking callbacks */
3805 VVnodeWriteToRead(&errorCode, parentptr);
3806 osi_Assert(!errorCode || errorCode == VSALVAGE);
3808 /* break call back on parent dir */
3809 BreakCallBack(client->host, DirFid, 0);
3811 /* Return a callback promise for the newly created file to the caller */
3812 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3815 /* Update and store volume/vnode and parent vnodes back */
3816 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3819 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3822 } /*SAFSS_CreateFile */
3826 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3827 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3828 struct AFSFetchStatus * OutFidStatus,
3829 struct AFSFetchStatus * OutDirStatus,
3830 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3833 struct rx_connection *tcon;
3835 struct client *t_client = NULL; /* tmp ptr to client data */
3836 #if FS_STATS_DETAILED
3837 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3838 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3839 struct timeval elapsedTime; /* Transfer time */
3842 * Set our stats pointer, remember when the RPC operation started, and
3843 * tally the operation.
3845 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3849 FT_GetTimeOfDay(&opStartTime, 0);
3850 #endif /* FS_STATS_DETAILED */
3852 memset(OutFid, 0, sizeof(struct AFSFid));
3854 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3855 goto Bad_CreateFile;
3858 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3859 OutDirStatus, CallBack, Sync);
3862 code = CallPostamble(tcon, code, thost);
3864 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3866 #if FS_STATS_DETAILED
3867 FT_GetTimeOfDay(&opStopTime, 0);
3870 (opP->numSuccesses)++;
3871 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3872 fs_stats_AddTo((opP->sumTime), elapsedTime);
3873 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3874 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3875 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3877 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3878 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3882 #endif /* FS_STATS_DETAILED */
3884 osi_auditU(acall, CreateFileEvent, code,
3885 AUD_ID, t_client ? t_client->ViceId : 0,
3886 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3889 } /*SRXAFS_CreateFile */
3893 * This routine is called exclusively from SRXAFS_Rename(), and should be
3894 * merged in when possible.
3897 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3898 struct AFSFid *NewDirFid, char *NewName,
3899 struct AFSFetchStatus *OutOldDirStatus,
3900 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3902 Vnode *oldvptr = 0; /* vnode of the old Directory */
3903 Vnode *newvptr = 0; /* vnode of the new Directory */
3904 Vnode *fileptr = 0; /* vnode of the file to move */
3905 Vnode *newfileptr = 0; /* vnode of the file to delete */
3906 Vnode *testvptr = 0; /* used in directory tree walk */
3907 Vnode *parent = 0; /* parent for use in SetAccessList */
3908 Error errorCode = 0; /* error code */
3909 Error fileCode = 0; /* used when writing Vnodes */
3910 VnodeId testnode; /* used in directory tree walk */
3911 AFSFid fileFid; /* Fid of file to move */
3912 AFSFid newFileFid; /* Fid of new file */
3913 DirHandle olddir; /* Handle for dir package I/O */
3914 DirHandle newdir; /* Handle for dir package I/O */
3915 DirHandle filedir; /* Handle for dir package I/O */
3916 DirHandle newfiledir; /* Handle for dir package I/O */
3917 Volume *volptr = 0; /* pointer to the volume header */
3918 struct client *client = 0; /* pointer to client structure */
3919 afs_int32 rights, anyrights; /* rights for this and any user */
3920 afs_int32 newrights; /* rights for this user */
3921 afs_int32 newanyrights; /* rights for any user */
3922 int doDelete; /* deleted the rename target (ref count now 0) */
3924 int updatefile = 0; /* are we changing the renamed file? (we do this
3925 * if we need to update .. on a renamed dir) */
3926 struct client *t_client; /* tmp ptr to client data */
3927 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3928 struct rx_connection *tcon = rx_ConnectionOf(acall);
3934 FidZero(&newfiledir);
3936 /* Get ptr to client data for user Id for logging */
3937 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3938 logHostAddr.s_addr = rxr_HostOf(tcon);
3940 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3941 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3942 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3943 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3945 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3947 if (!FileNameOK(NewName)) {
3951 if (OldDirFid->Volume != NewDirFid->Volume) {
3956 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3957 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3958 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3964 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3966 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3967 &parent, &client, WRITE_LOCK, &rights,
3972 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3974 newrights = rights, newanyrights = anyrights;
3977 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3978 MustBeDIR, &parent, &client, WRITE_LOCK,
3979 &newrights, &newanyrights))) {
3985 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3986 &parent, &client, WRITE_LOCK, &newrights,
3992 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3993 &parent, &client, WRITE_LOCK, &rights,
4000 /* set volume synchronization information */
4001 SetVolumeSync(Sync, volptr);
4003 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
4006 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
4010 if (CheckLength(volptr, oldvptr, -1) ||
4011 CheckLength(volptr, newvptr, -1)) {
4012 VTakeOffline(volptr);
4013 errorCode = VSALVAGE;
4017 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
4018 * call to CopyOnWrite returns error, it is not necessary to revert back
4019 * the effects of the first call because the contents of the volume is
4020 * not modified, it is only replicated.
4022 if (oldvptr->disk.cloned) {
4023 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
4024 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
4027 SetDirHandle(&olddir, oldvptr);
4028 if (newvptr->disk.cloned) {
4029 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
4030 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
4034 SetDirHandle(&newdir, newvptr);
4036 /* Lookup the file to delete its vnode */
4037 if (Lookup(&olddir, OldName, &fileFid)) {
4041 if (fileFid.Vnode == oldvptr->vnodeNumber
4042 || fileFid.Vnode == newvptr->vnodeNumber) {
4043 errorCode = FSERR_ELOOP;
4046 fileFid.Volume = V_id(volptr);
4047 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
4048 if (errorCode != 0) {
4050 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
4051 OldName, errorCode));
4052 VTakeOffline(volptr);
4055 if (fileptr->disk.uniquifier != fileFid.Unique) {
4057 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
4059 VTakeOffline(volptr);
4064 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
4065 && fileptr->disk.linkCount != 1) {
4067 * Hard links exist to this file - cannot move one of the links to
4068 * a new directory because of AFS restrictions (this is the same
4069 * reason that links cannot be made across directories, i.e.
4076 /* Lookup the new file */
4077 if (!(Lookup(&newdir, NewName, &newFileFid))) {
4078 if (readonlyServer) {
4079 errorCode = VREADONLY;
4082 if (!(newrights & PRSFS_DELETE)) {
4086 if (newFileFid.Vnode == oldvptr->vnodeNumber
4087 || newFileFid.Vnode == newvptr->vnodeNumber
4088 || newFileFid.Vnode == fileFid.Vnode) {
4092 newFileFid.Volume = V_id(volptr);
4094 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4095 if (errorCode != 0) {
4097 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4098 NewName, errorCode));
4099 VTakeOffline(volptr);
4102 if (fileptr->disk.uniquifier != fileFid.Unique) {
4104 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4106 VTakeOffline(volptr);
4110 SetDirHandle(&newfiledir, newfileptr);
4111 /* Now check that we're moving directories over directories properly, etc.
4112 * return proper POSIX error codes:
4113 * if fileptr is a file and new is a dir: EISDIR.
4114 * if fileptr is a dir and new is a file: ENOTDIR.
4115 * Also, dir to be removed must be empty, of course.
4117 if (newfileptr->disk.type == vDirectory) {
4118 if (fileptr->disk.type != vDirectory) {
4122 if ((IsEmpty(&newfiledir))) {
4127 if (fileptr->disk.type == vDirectory) {
4128 errorCode = ENOTDIR;
4135 * ok - now we check that the old name is not above new name in the
4136 * directory structure. This is to prevent removing a subtree alltogether
4138 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4139 afs_int32 forpass = 0, vnum = 0, top = 0;
4140 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4141 if (testnode > vnum) vnum = testnode;
4142 if (forpass > vnum) {
4143 errorCode = FSERR_ELOOP;
4146 if (testnode == oldvptr->vnodeNumber) {
4147 testnode = oldvptr->disk.parent;
4150 if ((testnode == fileptr->vnodeNumber)
4151 || (testnode == newvptr->vnodeNumber)) {
4152 errorCode = FSERR_ELOOP;
4155 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4156 errorCode = FSERR_ELOOP;
4159 if (testnode == 1) top = 1;
4160 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4161 osi_Assert(errorCode == 0);
4162 testnode = testvptr->disk.parent;
4163 VPutVnode(&errorCode, testvptr);
4164 if ((top == 1) && (testnode != 0)) {
4165 VTakeOffline(volptr);
4167 ("Volume %u now offline, must be salvaged.\n",
4172 osi_Assert(errorCode == 0);
4176 if (fileptr->disk.type == vDirectory) {
4177 SetDirHandle(&filedir, fileptr);
4178 if (oldvptr != newvptr) {
4179 /* we always need to update .. if we've moving fileptr to a
4180 * different directory */
4183 struct AFSFid unused;
4185 code = Lookup(&filedir, "..", &unused);
4186 if (code == ENOENT) {
4187 /* only update .. if it doesn't already exist */
4193 /* Do the CopyonWrite first before modifying anything else. Copying is
4194 * required when we have to change entries for ..
4196 if (updatefile && (fileptr->disk.cloned)) {
4197 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4198 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4202 /* If the new name exists already, delete it and the file it points to */
4205 /* Delete NewName from its directory */
4206 code = Delete(&newdir, NewName);
4207 osi_Assert(code == 0);
4209 /* Drop the link count */
4210 newfileptr->disk.linkCount--;
4211 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4212 afs_fsize_t newSize;
4213 VN_GET_LEN(newSize, newfileptr);
4214 VAdjustDiskUsage((Error *) & errorCode, volptr,
4215 (afs_sfsize_t) - nBlocks(newSize), 0);
4216 if (VN_GET_INO(newfileptr)) {
4217 IH_REALLYCLOSE(newfileptr->handle);
4219 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4220 V_parentId(volptr));
4221 IH_RELEASE(newfileptr->handle);
4222 if (errorCode == -1) {
4224 ("Del: inode=%s, name=%s, errno=%d\n",
4225 PrintInode(stmp, VN_GET_INO(newfileptr)),
4227 if ((errno != ENOENT) && (errno != EIO)
4228 && (errno != ENXIO))
4229 ViceLog(0, ("Do we need to fsck?"));
4232 VN_SET_INO(newfileptr, (Inode) 0);
4233 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4236 /* Link count did not drop to zero.
4237 * Mark NewName vnode as changed - updates stime.
4239 newfileptr->changed_newTime = 1;
4244 * If the create below fails, and the delete above worked, we have
4245 * removed the new name and not replaced it. This is not very likely,
4246 * but possible. We could try to put the old file back, but it is
4247 * highly unlikely that it would work since it would involve issuing
4250 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4253 /* Delete the old name */
4254 osi_Assert(Delete(&olddir, (char *)OldName) == 0);
4256 /* if the directory length changes, reflect it in the statistics */
4257 #if FS_STATS_DETAILED
4258 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4259 oldvptr->disk.linkCount, client->InSameNetwork);
4260 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4261 newvptr->disk.linkCount, client->InSameNetwork);
4263 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4264 oldvptr->disk.linkCount);
4265 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4266 newvptr->disk.linkCount);
4267 #endif /* FS_STATS_DETAILED */
4269 if (oldvptr == newvptr)
4270 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4272 if (fileptr->disk.parent != newvptr->vnodeNumber) {
4273 fileptr->disk.parent = newvptr->vnodeNumber;
4274 fileptr->changed_newTime = 1;
4277 /* if we are dealing with a rename of a directory, and we need to
4278 * update the .. entry of that directory */
4280 osi_Assert(!fileptr->disk.cloned);
4282 fileptr->changed_newTime = 1; /* status change of moved file */
4284 /* fix .. to point to the correct place */
4285 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4286 osi_Assert(Create(&filedir, "..", NewDirFid) == 0);
4287 fileptr->disk.dataVersion++;
4289 /* if the parent directories are different the link counts have to be */
4290 /* changed due to .. in the renamed directory */
4291 if (oldvptr != newvptr) {
4292 oldvptr->disk.linkCount--;
4293 newvptr->disk.linkCount++;
4297 /* set up return status */
4298 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4299 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4300 if (newfileptr && doDelete) {
4301 DeleteFileCallBacks(&newFileFid); /* no other references */
4306 /* convert the write locks to a read locks before breaking callbacks */
4307 VVnodeWriteToRead(&errorCode, newvptr);
4308 osi_Assert(!errorCode || errorCode == VSALVAGE);
4309 if (oldvptr != newvptr) {
4310 VVnodeWriteToRead(&errorCode, oldvptr);
4311 osi_Assert(!errorCode || errorCode == VSALVAGE);
4313 if (newfileptr && !doDelete) {
4314 /* convert the write lock to a read lock before breaking callbacks */
4315 VVnodeWriteToRead(&errorCode, newfileptr);
4316 osi_Assert(!errorCode || errorCode == VSALVAGE);
4319 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4320 BreakCallBack(client->host, NewDirFid, 0);
4321 if (oldvptr != newvptr) {
4322 BreakCallBack(client->host, OldDirFid, 0);
4325 /* if a dir moved, .. changed */
4326 /* we do not give an AFSFetchStatus structure back to the
4327 * originating client, and the file's status has changed, so be
4328 * sure to send a callback break. In theory the client knows
4329 * enough to know that the callback could be broken implicitly,
4330 * but that may not be clear, and some client implementations
4331 * may not know to. */
4332 BreakCallBack(client->host, &fileFid, 1);
4335 /* Note: it is not necessary to break the callback */
4337 DeleteFileCallBacks(&newFileFid); /* no other references */
4339 /* other's still exist (with wrong link count) */
4340 BreakCallBack(client->host, &newFileFid, 1);
4345 VPutVnode(&fileCode, newfileptr);
4346 osi_Assert(fileCode == 0);
4348 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4349 newvptr : 0), oldvptr, volptr, &client);
4353 FidZap(&newfiledir);
4354 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4361 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4362 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4363 struct AFSFetchStatus * OutOldDirStatus,
4364 struct AFSFetchStatus * OutNewDirStatus,
4365 struct AFSVolSync * Sync)
4368 struct rx_connection *tcon;
4370 struct client *t_client = NULL; /* tmp ptr to client data */
4371 #if FS_STATS_DETAILED
4372 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4373 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4374 struct timeval elapsedTime; /* Transfer time */
4377 * Set our stats pointer, remember when the RPC operation started, and
4378 * tally the operation.
4380 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4384 FT_GetTimeOfDay(&opStartTime, 0);
4385 #endif /* FS_STATS_DETAILED */
4387 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4391 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4392 OutOldDirStatus, OutNewDirStatus, Sync);
4395 code = CallPostamble(tcon, code, thost);
4397 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4399 #if FS_STATS_DETAILED
4400 FT_GetTimeOfDay(&opStopTime, 0);
4403 (opP->numSuccesses)++;
4404 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4405 fs_stats_AddTo((opP->sumTime), elapsedTime);
4406 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4407 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4408 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4410 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4411 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4415 #endif /* FS_STATS_DETAILED */
4417 osi_auditU(acall, RenameFileEvent, code,
4418 AUD_ID, t_client ? t_client->ViceId : 0,
4419 AUD_FID, OldDirFid, AUD_STR, OldName,
4420 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4423 } /*SRXAFS_Rename */
4427 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4428 * merged into it when possible.
4431 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4432 char *LinkContents, struct AFSStoreStatus *InStatus,
4433 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4434 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4436 Vnode *parentptr = 0; /* vnode of input Directory */
4437 Vnode *targetptr = 0; /* vnode of the new link */
4438 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4439 Error errorCode = 0; /* error code */
4442 DirHandle dir; /* Handle for dir package I/O */
4443 Volume *volptr = 0; /* pointer to the volume header */
4444 struct client *client = 0; /* pointer to client structure */
4445 afs_int32 rights, anyrights; /* rights for this and any user */
4446 struct client *t_client; /* tmp ptr to client data */
4447 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4449 struct rx_connection *tcon = rx_ConnectionOf(acall);
4453 /* Get ptr to client data for user Id for logging */
4454 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4455 logHostAddr.s_addr = rxr_HostOf(tcon);
4457 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4458 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4459 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4461 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4463 if (!FileNameOK(Name)) {
4469 * Get the vnode and volume for the parent dir along with the caller's
4473 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4474 &parentwhentargetnotdir, &client, WRITE_LOCK,
4475 &rights, &anyrights))) {
4479 /* set volume synchronization information */
4480 SetVolumeSync(Sync, volptr);
4482 /* Does the caller has insert (and write) access to the parent directory? */
4483 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4488 * If we're creating a mount point (any x bits clear), we must have
4489 * administer access to the directory, too. Always allow sysadmins
4492 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4493 if (readonlyServer) {
4494 errorCode = VREADONLY;
4498 * We have a mountpoint, 'cause we're trying to set the Unix mode
4499 * bits to something with some x bits missing (default mode bits
4500 * if AFS_SETMODE is false is 0777)
4502 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4508 /* get a new vnode for the symlink and set it up */
4510 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4511 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4515 /* update the status of the parent vnode */
4516 #if FS_STATS_DETAILED
4517 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4518 parentptr->disk.linkCount,
4519 client->InSameNetwork);
4521 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4522 parentptr->disk.linkCount);
4523 #endif /* FS_STATS_DETAILED */
4525 /* update the status of the new symbolic link file vnode */
4526 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4527 parentptr, volptr, strlen((char *)LinkContents));
4529 /* Write the contents of the symbolic link name into the target inode */
4530 fdP = IH_OPEN(targetptr->handle);
4532 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4534 VTakeOffline(volptr);
4535 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4539 len = strlen((char *) LinkContents);
4540 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4542 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4545 * Set up and return modified status for the parent dir and new symlink
4548 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4549 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4551 /* convert the write lock to a read lock before breaking callbacks */
4552 VVnodeWriteToRead(&errorCode, parentptr);
4553 osi_Assert(!errorCode || errorCode == VSALVAGE);
4555 /* break call back on the parent dir */
4556 BreakCallBack(client->host, DirFid, 0);
4559 /* Write the all modified vnodes (parent, new files) and volume back */
4560 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4563 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4564 return ( errorCode ? errorCode : code );
4566 } /*SAFSS_Symlink */
4570 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4571 struct AFSFid *DirFid, /* Parent dir's fid */
4572 char *Name, /* File name to create */
4573 char *LinkContents, /* Contents of the new created file */
4574 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4575 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4576 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4577 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4578 struct AFSVolSync *Sync)
4581 struct rx_connection *tcon;
4583 struct client *t_client = NULL; /* tmp ptr to client data */
4584 #if FS_STATS_DETAILED
4585 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4586 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4587 struct timeval elapsedTime; /* Transfer time */
4590 * Set our stats pointer, remember when the RPC operation started, and
4591 * tally the operation.
4593 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4597 FT_GetTimeOfDay(&opStartTime, 0);
4598 #endif /* FS_STATS_DETAILED */
4600 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4604 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4605 OutFidStatus, OutDirStatus, Sync);
4608 code = CallPostamble(tcon, code, thost);
4610 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4612 #if FS_STATS_DETAILED
4613 FT_GetTimeOfDay(&opStopTime, 0);
4616 (opP->numSuccesses)++;
4617 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4618 fs_stats_AddTo((opP->sumTime), elapsedTime);
4619 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4620 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4621 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4623 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4624 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4628 #endif /* FS_STATS_DETAILED */
4630 osi_auditU(acall, SymlinkEvent, code,
4631 AUD_ID, t_client ? t_client->ViceId : 0,
4632 AUD_FID, DirFid, AUD_STR, Name,
4633 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4636 } /*SRXAFS_Symlink */
4640 * This routine is called exclusively by SRXAFS_Link(), and should be
4641 * merged into it when possible.
4644 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4645 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4646 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4648 Vnode *parentptr = 0; /* vnode of input Directory */
4649 Vnode *targetptr = 0; /* vnode of the new file */
4650 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4651 Volume *volptr = 0; /* pointer to the volume header */
4652 Error errorCode = 0; /* error code */
4653 DirHandle dir; /* Handle for dir package I/O */
4654 struct client *client = 0; /* pointer to client structure */
4655 afs_int32 rights, anyrights; /* rights for this and any user */
4656 struct client *t_client; /* tmp ptr to client data */
4657 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4658 struct rx_connection *tcon = rx_ConnectionOf(acall);
4662 /* Get ptr to client data for user Id for logging */
4663 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4664 logHostAddr.s_addr = rxr_HostOf(tcon);
4666 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4667 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4668 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4669 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4671 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4673 if (DirFid->Volume != ExistingFid->Volume) {
4677 if (!FileNameOK(Name)) {
4683 * Get the vnode and volume for the parent dir along with the caller's
4687 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4688 &parentwhentargetnotdir, &client, WRITE_LOCK,
4689 &rights, &anyrights))) {
4693 /* set volume synchronization information */
4694 SetVolumeSync(Sync, volptr);
4696 /* Can the caller insert into the parent directory? */
4697 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4701 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4702 /* AFS fileservers always have directory vnodes that are odd. */
4707 if (CheckLength(volptr, parentptr, -1)) {
4708 VTakeOffline(volptr);
4709 errorCode = VSALVAGE;
4713 /* get the file vnode */
4715 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4718 if (targetptr->disk.type != vFile) {
4722 if (targetptr->disk.parent != DirFid->Vnode) {
4726 if (parentptr->disk.cloned) {
4727 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4728 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4729 goto Bad_Link; /* disk full error */
4732 /* add the name to the directory */
4733 SetDirHandle(&dir, parentptr);
4734 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4738 /* update the status in the parent vnode */
4739 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4740 #if FS_STATS_DETAILED
4741 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4742 parentptr->disk.linkCount,
4743 client->InSameNetwork);
4745 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4746 parentptr->disk.linkCount);
4747 #endif /* FS_STATS_DETAILED */
4749 targetptr->disk.linkCount++;
4750 targetptr->disk.author = client->ViceId;
4751 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4753 /* set up return status */
4754 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4755 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4757 /* convert the write locks to read locks before breaking callbacks */
4758 VVnodeWriteToRead(&errorCode, targetptr);
4759 osi_Assert(!errorCode || errorCode == VSALVAGE);
4760 VVnodeWriteToRead(&errorCode, parentptr);
4761 osi_Assert(!errorCode || errorCode == VSALVAGE);
4763 /* break call back on DirFid */
4764 BreakCallBack(client->host, DirFid, 0);
4766 * We also need to break the callback for the file that is hard-linked since part
4767 * of its status (like linkcount) is changed
4769 BreakCallBack(client->host, ExistingFid, 0);
4772 /* Write the all modified vnodes (parent, new files) and volume back */
4773 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4776 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4783 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4784 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4785 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4788 struct rx_connection *tcon;
4790 struct client *t_client = NULL; /* tmp ptr to client data */
4791 #if FS_STATS_DETAILED
4792 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4793 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4794 struct timeval elapsedTime; /* Transfer time */
4797 * Set our stats pointer, remember when the RPC operation started, and
4798 * tally the operation.
4800 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4804 FT_GetTimeOfDay(&opStartTime, 0);
4805 #endif /* FS_STATS_DETAILED */
4807 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4811 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4812 OutDirStatus, Sync);
4815 code = CallPostamble(tcon, code, thost);
4817 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4819 #if FS_STATS_DETAILED
4820 FT_GetTimeOfDay(&opStopTime, 0);
4823 (opP->numSuccesses)++;
4824 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4825 fs_stats_AddTo((opP->sumTime), elapsedTime);
4826 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4827 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4828 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4830 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4831 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4835 #endif /* FS_STATS_DETAILED */
4837 osi_auditU(acall, LinkEvent, code,
4838 AUD_ID, t_client ? t_client->ViceId : 0,
4839 AUD_FID, DirFid, AUD_STR, Name,
4840 AUD_FID, ExistingFid, AUD_END);
4847 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4848 * merged into it when possible.
4851 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4852 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4853 struct AFSFetchStatus *OutFidStatus,
4854 struct AFSFetchStatus *OutDirStatus,
4855 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4857 Vnode *parentptr = 0; /* vnode of input Directory */
4858 Vnode *targetptr = 0; /* vnode of the new file */
4859 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4860 Volume *volptr = 0; /* pointer to the volume header */
4861 Error errorCode = 0; /* error code */
4862 struct acl_accessList *newACL; /* Access list */
4863 int newACLSize; /* Size of access list */
4864 DirHandle dir; /* Handle for dir package I/O */
4865 DirHandle parentdir; /* Handle for dir package I/O */
4866 struct client *client = 0; /* pointer to client structure */
4867 afs_int32 rights, anyrights; /* rights for this and any user */
4868 struct client *t_client; /* tmp ptr to client data */
4869 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4870 struct rx_connection *tcon = rx_ConnectionOf(acall);
4873 FidZero(&parentdir);
4875 /* Get ptr to client data for user Id for logging */
4876 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4877 logHostAddr.s_addr = rxr_HostOf(tcon);
4879 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4880 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4881 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4883 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4885 if (!FileNameOK(Name)) {
4891 * Get the vnode and volume for the parent dir along with the caller's
4895 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4896 &parentwhentargetnotdir, &client, WRITE_LOCK,
4897 &rights, &anyrights))) {
4901 /* set volume synchronization information */
4902 SetVolumeSync(Sync, volptr);
4904 /* Write access to the parent directory? */
4905 #ifdef DIRCREATE_NEED_WRITE
4907 * requires w access for the user to create a directory. this
4908 * closes a loophole in the current security arrangement, since a
4909 * user with i access only can create a directory and get the
4910 * implcit a access that goes with dir ownership, and proceed to
4911 * subvert quota in the volume.
4913 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4914 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4916 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4917 #endif /* DIRCREATE_NEED_WRITE */
4920 #define EMPTYDIRBLOCKS 2
4921 /* get a new vnode and set it up */
4923 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4924 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4928 /* Update the status for the parent dir */
4929 #if FS_STATS_DETAILED
4930 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4931 parentptr->disk.linkCount + 1,
4932 client->InSameNetwork);
4934 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4935 parentptr->disk.linkCount + 1);
4936 #endif /* FS_STATS_DETAILED */
4938 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4939 osi_Assert((SetAccessList
4940 (&targetptr, &volptr, &newACL, &newACLSize,
4941 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4942 osi_Assert(parentwhentargetnotdir == 0);
4943 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4945 /* update the status for the target vnode */
4946 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4947 parentptr, volptr, 0);
4949 /* Actually create the New directory in the directory package */
4950 SetDirHandle(&dir, targetptr);
4951 osi_Assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4953 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4955 /* set up return status */
4956 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4957 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4959 /* convert the write lock to a read lock before breaking callbacks */
4960 VVnodeWriteToRead(&errorCode, parentptr);
4961 osi_Assert(!errorCode || errorCode == VSALVAGE);
4963 /* break call back on DirFid */
4964 BreakCallBack(client->host, DirFid, 0);
4966 /* Return a callback promise to caller */
4967 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4970 /* Write the all modified vnodes (parent, new files) and volume back */
4971 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4975 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4978 } /*SAFSS_MakeDir */
4982 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4983 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4984 struct AFSFetchStatus * OutFidStatus,
4985 struct AFSFetchStatus * OutDirStatus,
4986 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4989 struct rx_connection *tcon;
4991 struct client *t_client = NULL; /* tmp ptr to client data */
4992 #if FS_STATS_DETAILED
4993 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4994 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4995 struct timeval elapsedTime; /* Transfer time */
4998 * Set our stats pointer, remember when the RPC operation started, and
4999 * tally the operation.
5001 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
5005 FT_GetTimeOfDay(&opStartTime, 0);
5006 #endif /* FS_STATS_DETAILED */
5007 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5011 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
5012 OutDirStatus, CallBack, Sync);
5015 code = CallPostamble(tcon, code, thost);
5017 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5019 #if FS_STATS_DETAILED
5020 FT_GetTimeOfDay(&opStopTime, 0);
5023 (opP->numSuccesses)++;
5024 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5025 fs_stats_AddTo((opP->sumTime), elapsedTime);
5026 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5027 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5028 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5030 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5031 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5035 #endif /* FS_STATS_DETAILED */
5037 osi_auditU(acall, MakeDirEvent, code,
5038 AUD_ID, t_client ? t_client->ViceId : 0,
5039 AUD_FID, DirFid, AUD_STR, Name,
5040 AUD_FID, OutFid, AUD_END);
5043 } /*SRXAFS_MakeDir */
5047 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
5048 * merged into it when possible.
5051 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
5052 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
5054 Vnode *parentptr = 0; /* vnode of input Directory */
5055 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5056 Vnode *targetptr = 0; /* file to be deleted */
5057 AFSFid fileFid; /* area for Fid from the directory */
5058 Error errorCode = 0; /* error code */
5059 DirHandle dir; /* Handle for dir package I/O */
5060 Volume *volptr = 0; /* pointer to the volume header */
5061 struct client *client = 0; /* pointer to client structure */
5062 afs_int32 rights, anyrights; /* rights for this and any user */
5063 struct client *t_client; /* tmp ptr to client data */
5064 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5065 struct rx_connection *tcon = rx_ConnectionOf(acall);
5069 /* Get ptr to client data for user Id for logging */
5070 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5071 logHostAddr.s_addr = rxr_HostOf(tcon);
5073 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
5074 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
5075 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5077 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
5080 * Get the vnode and volume for the parent dir along with the caller's
5084 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
5085 &parentwhentargetnotdir, &client, WRITE_LOCK,
5086 &rights, &anyrights))) {
5090 /* set volume synchronization information */
5091 SetVolumeSync(Sync, volptr);
5093 /* Does the caller has delete (&write) access to the parent dir? */
5094 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
5098 /* Do the actual delete of the desired (empty) directory, Name */
5100 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
5105 /* Update the status for the parent dir; link count is also adjusted */
5106 #if FS_STATS_DETAILED
5107 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5108 parentptr->disk.linkCount - 1,
5109 client->InSameNetwork);
5111 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5112 parentptr->disk.linkCount - 1);
5113 #endif /* FS_STATS_DETAILED */
5115 /* Return to the caller the updated parent dir status */
5116 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
5119 * Note: it is not necessary to break the callback on fileFid, since
5120 * refcount is now 0, so no one should be able to refer to the dir
5123 DeleteFileCallBacks(&fileFid);
5125 /* convert the write lock to a read lock before breaking callbacks */
5126 VVnodeWriteToRead(&errorCode, parentptr);
5127 osi_Assert(!errorCode || errorCode == VSALVAGE);
5129 /* break call back on DirFid and fileFid */
5130 BreakCallBack(client->host, DirFid, 0);
5133 /* Write the all modified vnodes (parent, new files) and volume back */
5134 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5137 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5140 } /*SAFSS_RemoveDir */
5144 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5145 struct AFSFetchStatus * OutDirStatus,
5146 struct AFSVolSync * Sync)
5149 struct rx_connection *tcon;
5151 struct client *t_client = NULL; /* tmp ptr to client data */
5152 #if FS_STATS_DETAILED
5153 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5154 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5155 struct timeval elapsedTime; /* Transfer time */
5158 * Set our stats pointer, remember when the RPC operation started, and
5159 * tally the operation.
5161 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5165 FT_GetTimeOfDay(&opStartTime, 0);
5166 #endif /* FS_STATS_DETAILED */
5168 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5171 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5174 code = CallPostamble(tcon, code, thost);
5176 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5178 #if FS_STATS_DETAILED
5179 FT_GetTimeOfDay(&opStopTime, 0);
5182 (opP->numSuccesses)++;
5183 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5184 fs_stats_AddTo((opP->sumTime), elapsedTime);
5185 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5186 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5187 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5189 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5190 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5194 #endif /* FS_STATS_DETAILED */
5196 osi_auditU(acall, RemoveDirEvent, code,
5197 AUD_ID, t_client ? t_client->ViceId : 0,
5198 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5201 } /*SRXAFS_RemoveDir */
5205 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5206 * merged into it when possible.
5209 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5210 struct AFSVolSync *Sync)
5212 Vnode *targetptr = 0; /* vnode of input file */
5213 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5214 Error errorCode = 0; /* error code */
5215 Volume *volptr = 0; /* pointer to the volume header */
5216 struct client *client = 0; /* pointer to client structure */
5217 afs_int32 rights, anyrights; /* rights for this and any user */
5218 struct client *t_client; /* tmp ptr to client data */
5219 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5220 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5221 struct rx_connection *tcon = rx_ConnectionOf(acall);
5223 if (type != LockRead && type != LockWrite) {
5227 /* Get ptr to client data for user Id for logging */
5228 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5229 logHostAddr.s_addr = rxr_HostOf(tcon);
5231 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5232 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5233 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5235 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5238 * Get the vnode and volume for the desired file along with the caller's
5242 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5243 &parentwhentargetnotdir, &client, WRITE_LOCK,
5244 &rights, &anyrights))) {
5248 /* set volume synchronization information */
5249 SetVolumeSync(Sync, volptr);
5251 /* Handle the particular type of set locking, type */
5252 errorCode = HandleLocking(targetptr, client, rights, type);
5255 /* Write the all modified vnodes (parent, new files) and volume back */
5256 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5259 if ((errorCode == VREADONLY) && (type == LockRead))
5260 errorCode = 0; /* allow read locks on RO volumes without saving state */
5262 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5265 } /*SAFSS_SetLock */
5269 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5270 ViceLockType type, struct AFSVolSync * Sync)
5272 return SRXAFS_SetLock(acall, Fid, type, Sync);
5273 } /*SRXAFS_OldSetLock */
5277 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5278 struct AFSVolSync * Sync)
5281 struct rx_connection *tcon;
5283 struct client *t_client = NULL; /* tmp ptr to client data */
5284 #if FS_STATS_DETAILED
5285 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5286 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5287 struct timeval elapsedTime; /* Transfer time */
5290 * Set our stats pointer, remember when the RPC operation started, and
5291 * tally the operation.
5293 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5297 FT_GetTimeOfDay(&opStartTime, 0);
5298 #endif /* FS_STATS_DETAILED */
5300 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5303 code = SAFSS_SetLock(acall, Fid, type, Sync);
5306 code = CallPostamble(tcon, code, thost);
5308 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5310 #if FS_STATS_DETAILED
5311 FT_GetTimeOfDay(&opStopTime, 0);
5314 (opP->numSuccesses)++;
5315 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5316 fs_stats_AddTo((opP->sumTime), elapsedTime);
5317 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5318 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5319 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5321 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5322 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5326 #endif /* FS_STATS_DETAILED */
5328 osi_auditU(acall, SetLockEvent, code,
5329 AUD_ID, t_client ? t_client->ViceId : 0,
5330 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5332 } /*SRXAFS_SetLock */
5336 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5337 * merged into it when possible.
5340 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5341 struct AFSVolSync *Sync)
5343 Vnode *targetptr = 0; /* vnode of input file */
5344 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5345 Error errorCode = 0; /* error code */
5346 Volume *volptr = 0; /* pointer to the volume header */
5347 struct client *client = 0; /* pointer to client structure */
5348 afs_int32 rights, anyrights; /* rights for this and any user */
5349 struct client *t_client; /* tmp ptr to client data */
5350 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5351 struct rx_connection *tcon = rx_ConnectionOf(acall);
5353 /* Get ptr to client data for user Id for logging */
5354 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5355 logHostAddr.s_addr = rxr_HostOf(tcon);
5357 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5358 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5359 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5361 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5364 * Get the vnode and volume for the desired file along with the caller's
5368 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5369 &parentwhentargetnotdir, &client, WRITE_LOCK,
5370 &rights, &anyrights))) {
5371 goto Bad_ExtendLock;
5374 /* set volume synchronization information */
5375 SetVolumeSync(Sync, volptr);
5377 /* Handle the actual lock extension */
5378 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5381 /* Put back file's vnode and volume */
5382 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5385 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5386 errorCode = 0; /* under our generous policy re RO vols */
5388 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5391 } /*SAFSS_ExtendLock */
5395 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5396 struct AFSVolSync * Sync)
5398 return SRXAFS_ExtendLock(acall, Fid, Sync);
5399 } /*SRXAFS_OldExtendLock */
5403 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5404 struct AFSVolSync * Sync)
5407 struct rx_connection *tcon;
5409 struct client *t_client = NULL; /* tmp ptr to client data */
5410 #if FS_STATS_DETAILED
5411 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5412 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5413 struct timeval elapsedTime; /* Transfer time */
5416 * Set our stats pointer, remember when the RPC operation started, and
5417 * tally the operation.
5419 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5423 FT_GetTimeOfDay(&opStartTime, 0);
5424 #endif /* FS_STATS_DETAILED */
5426 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5427 goto Bad_ExtendLock;
5429 code = SAFSS_ExtendLock(acall, Fid, Sync);
5432 code = CallPostamble(tcon, code, thost);
5434 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5436 #if FS_STATS_DETAILED
5437 FT_GetTimeOfDay(&opStopTime, 0);
5440 (opP->numSuccesses)++;
5441 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5442 fs_stats_AddTo((opP->sumTime), elapsedTime);
5443 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5444 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5445 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5447 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5448 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5452 #endif /* FS_STATS_DETAILED */
5454 osi_auditU(acall, ExtendLockEvent, code,
5455 AUD_ID, t_client ? t_client->ViceId : 0,
5456 AUD_FID, Fid, AUD_END);
5459 } /*SRXAFS_ExtendLock */
5463 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5464 * merged into it when possible.
5467 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5468 struct AFSVolSync *Sync)
5470 Vnode *targetptr = 0; /* vnode of input file */
5471 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5472 Error errorCode = 0; /* error code */
5473 Volume *volptr = 0; /* pointer to the volume header */
5474 struct client *client = 0; /* pointer to client structure */
5475 afs_int32 rights, anyrights; /* rights for this and any user */
5476 struct client *t_client; /* tmp ptr to client data */
5477 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5478 struct rx_connection *tcon = rx_ConnectionOf(acall);
5480 /* Get ptr to client data for user Id for logging */
5481 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5482 logHostAddr.s_addr = rxr_HostOf(tcon);
5484 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5485 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5486 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5488 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5491 * Get the vnode and volume for the desired file along with the caller's
5495 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5496 &parentwhentargetnotdir, &client, WRITE_LOCK,
5497 &rights, &anyrights))) {
5498 goto Bad_ReleaseLock;
5501 /* set volume synchronization information */
5502 SetVolumeSync(Sync, volptr);
5504 /* Handle the actual lock release */
5505 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5506 goto Bad_ReleaseLock;
5508 /* if no more locks left, a callback would be triggered here */
5509 if (targetptr->disk.lock.lockCount <= 0) {
5510 /* convert the write lock to a read lock before breaking callbacks */
5511 VVnodeWriteToRead(&errorCode, targetptr);
5512 osi_Assert(!errorCode || errorCode == VSALVAGE);
5513 BreakCallBack(client->host, Fid, 0);
5517 /* Put back file's vnode and volume */
5518 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5521 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5522 errorCode = 0; /* under our generous policy re RO vols */
5524 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5527 } /*SAFSS_ReleaseLock */
5531 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5532 struct AFSVolSync * Sync)
5534 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5535 } /*SRXAFS_OldReleaseLock */
5539 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5540 struct AFSVolSync * Sync)
5543 struct rx_connection *tcon;
5545 struct client *t_client = NULL; /* tmp ptr to client data */
5546 #if FS_STATS_DETAILED
5547 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5548 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5549 struct timeval elapsedTime; /* Transfer time */
5552 * Set our stats pointer, remember when the RPC operation started, and
5553 * tally the operation.
5555 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5559 FT_GetTimeOfDay(&opStartTime, 0);
5560 #endif /* FS_STATS_DETAILED */
5562 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5563 goto Bad_ReleaseLock;
5565 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5568 code = CallPostamble(tcon, code, thost);
5570 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5572 #if FS_STATS_DETAILED
5573 FT_GetTimeOfDay(&opStopTime, 0);
5576 (opP->numSuccesses)++;
5577 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5578 fs_stats_AddTo((opP->sumTime), elapsedTime);
5579 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5580 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5581 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5583 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5584 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5588 #endif /* FS_STATS_DETAILED */
5590 osi_auditU(acall, ReleaseLockEvent, code,
5591 AUD_ID, t_client ? t_client->ViceId : 0,
5592 AUD_FID, Fid, AUD_END);
5595 } /*SRXAFS_ReleaseLock */
5599 SetSystemStats(struct AFSStatistics *stats)
5601 /* Fix this sometime soon.. */
5602 /* Because hey, it's not like we have a network monitoring protocol... */
5603 struct timeval time;
5605 /* this works on all system types */
5606 FT_GetTimeOfDay(&time, 0);
5607 stats->CurrentTime = time.tv_sec;
5608 } /*SetSystemStats */
5611 SetAFSStats(struct AFSStatistics *stats)
5613 extern afs_int32 StartTime, CurrentConnections;
5617 stats->CurrentMsgNumber = 0;
5618 stats->OldestMsgNumber = 0;
5619 stats->StartTime = StartTime;
5620 stats->CurrentConnections = CurrentConnections;
5621 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5622 stats->TotalFetchs =
5623 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5624 AFSCallStats.FetchStatus;
5625 stats->FetchDatas = AFSCallStats.FetchData;
5626 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5627 seconds = AFSCallStats.AccumFetchTime / 1000;
5630 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5631 stats->TotalStores =
5632 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5633 AFSCallStats.StoreStatus;
5634 stats->StoreDatas = AFSCallStats.StoreData;
5635 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5636 seconds = AFSCallStats.AccumStoreTime / 1000;
5639 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5641 stats->ProcessSize = -1; /* TODO: */
5643 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5646 h_GetWorkStats((int *)&(stats->WorkStations),
5647 (int *)&(stats->ActiveWorkStations), (int *)0,
5648 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5652 /* Get disk related information from all AFS partitions. */
5655 SetVolumeStats(struct AFSStatistics *stats)
5657 struct DiskPartition64 *part;
5660 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5661 part = part->next) {
5662 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5663 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5664 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5665 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5668 while (i < AFS_MSTATDISKS) {
5669 stats->Disks[i].TotalBlocks = -1;
5672 } /*SetVolumeStats */
5675 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5678 struct rx_connection *tcon = rx_ConnectionOf(acall);
5680 struct client *t_client = NULL; /* tmp ptr to client data */
5681 #if FS_STATS_DETAILED
5682 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5683 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5684 struct timeval elapsedTime; /* Transfer time */
5687 * Set our stats pointer, remember when the RPC operation started, and
5688 * tally the operation.
5690 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5694 FT_GetTimeOfDay(&opStartTime, 0);
5695 #endif /* FS_STATS_DETAILED */
5697 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5698 goto Bad_GetStatistics;
5700 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5702 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5704 memset(Statistics, 0, sizeof(*Statistics));
5705 SetAFSStats((struct AFSStatistics *)Statistics);
5706 SetVolumeStats((struct AFSStatistics *)Statistics);
5707 SetSystemStats((struct AFSStatistics *)Statistics);
5710 code = CallPostamble(tcon, code, thost);
5712 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5714 #if FS_STATS_DETAILED
5715 FT_GetTimeOfDay(&opStopTime, 0);
5718 (opP->numSuccesses)++;
5719 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5720 fs_stats_AddTo((opP->sumTime), elapsedTime);
5721 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5722 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5723 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5725 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5726 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5730 #endif /* FS_STATS_DETAILED */
5732 osi_auditU(acall, GetStatisticsEvent, code,
5733 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5735 } /*SRXAFS_GetStatistics */
5739 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5741 extern afs_int32 StartTime, CurrentConnections;
5744 struct rx_connection *tcon = rx_ConnectionOf(acall);
5746 struct client *t_client = NULL; /* tmp ptr to client data */
5747 struct timeval time;
5748 #if FS_STATS_DETAILED
5749 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5750 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5751 struct timeval elapsedTime; /* Transfer time */
5754 * Set our stats pointer, remember when the RPC operation started, and
5755 * tally the operation.
5757 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5761 FT_GetTimeOfDay(&opStartTime, 0);
5762 #endif /* FS_STATS_DETAILED */
5764 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5765 goto Bad_GetStatistics64;
5767 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5768 Statistics->ViceStatistics64_val =
5769 malloc(statsVersion*sizeof(afs_int64));
5770 Statistics->ViceStatistics64_len = statsVersion;
5772 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5773 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5774 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5776 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5777 AFSCallStats.TotalCalls;
5778 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5779 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5780 AFSCallStats.FetchStatus;
5781 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5782 AFSCallStats.FetchData;
5783 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5784 AFSCallStats.TotalFetchedBytes;
5785 seconds = AFSCallStats.AccumFetchTime / 1000;
5788 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5789 AFSCallStats.TotalFetchedBytes / seconds;
5790 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5791 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5792 AFSCallStats.StoreStatus;
5793 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5794 AFSCallStats.StoreData;
5795 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5796 AFSCallStats.TotalStoredBytes;
5797 seconds = AFSCallStats.AccumStoreTime / 1000;
5800 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5801 AFSCallStats.TotalStoredBytes / seconds;
5803 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5805 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5806 (afs_int32) ((long)sbrk(0) >> 10);
5809 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5810 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5812 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5816 /* this works on all system types */
5817 FT_GetTimeOfDay(&time, 0);
5818 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5820 Bad_GetStatistics64:
5821 code = CallPostamble(tcon, code, thost);
5823 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5825 #if FS_STATS_DETAILED
5826 FT_GetTimeOfDay(&opStopTime, 0);
5829 (opP->numSuccesses)++;
5830 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5831 fs_stats_AddTo((opP->sumTime), elapsedTime);
5832 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5833 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5834 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5836 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5837 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5841 #endif /* FS_STATS_DETAILED */
5843 osi_auditU(acall, GetStatisticsEvent, code,
5844 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5846 } /*SRXAFS_GetStatistics */
5849 /*------------------------------------------------------------------------
5850 * EXPORTED SRXAFS_XStatsVersion
5853 * Routine called by the server-side RPC interface to implement
5854 * pulling out the xstat version number for the File Server.
5857 * a_versionP : Ptr to the version number variable to set.
5863 * Nothing interesting.
5867 *------------------------------------------------------------------------*/
5870 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5871 { /*SRXAFS_XStatsVersion */
5873 struct client *t_client = NULL; /* tmp ptr to client data */
5874 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5875 #if FS_STATS_DETAILED
5876 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5877 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5878 struct timeval elapsedTime; /* Transfer time */
5881 * Set our stats pointer, remember when the RPC operation started, and
5882 * tally the operation.
5884 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5888 FT_GetTimeOfDay(&opStartTime, 0);
5889 #endif /* FS_STATS_DETAILED */
5891 *a_versionP = AFS_XSTAT_VERSION;
5893 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5895 #if FS_STATS_DETAILED
5896 FT_GetTimeOfDay(&opStopTime, 0);
5897 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5898 fs_stats_AddTo((opP->sumTime), elapsedTime);
5899 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5900 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5901 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5903 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5904 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5907 (opP->numSuccesses)++;
5909 #endif /* FS_STATS_DETAILED */
5911 osi_auditU(a_call, XStatsVersionEvent, 0,
5912 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5914 } /*SRXAFS_XStatsVersion */
5917 /*------------------------------------------------------------------------
5918 * PRIVATE FillPerfValues
5921 * Routine called to fill a regular performance data structure.
5924 * a_perfP : Ptr to perf structure to fill
5930 * Various collections need this info, so the guts were put in
5931 * this separate routine.
5935 *------------------------------------------------------------------------*/
5938 FillPerfValues(struct afs_PerfStats *a_perfP)
5939 { /*FillPerfValues */
5941 int dir_Buffers; /*# buffers in use by dir package */
5942 int dir_Calls; /*# read calls in dir package */
5943 int dir_IOs; /*# I/O ops in dir package */
5944 struct rx_statistics *stats;
5947 * Vnode cache section.
5949 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5950 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5951 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5952 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5953 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5954 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5955 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5956 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5957 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5958 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5959 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5960 SplitInt64(VStats.hdr_gets, hi, lo);
5961 a_perfP->vcache_H_Gets = lo;
5962 SplitInt64(VStats.hdr_loads, hi, lo);
5963 a_perfP->vcache_H_Replacements = lo;
5966 * Directory section.
5968 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5969 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5970 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5971 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5976 stats = rx_GetStatistics();
5978 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5979 a_perfP->rx_noPackets_RcvClass =
5980 (afs_int32) stats->receivePktAllocFailures;
5981 a_perfP->rx_noPackets_SendClass =
5982 (afs_int32) stats->sendPktAllocFailures;
5983 a_perfP->rx_noPackets_SpecialClass =
5984 (afs_int32) stats->specialPktAllocFailures;
5985 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5986 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5987 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5988 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5989 a_perfP->rx_noPacketBuffersOnRead =
5990 (afs_int32) stats->noPacketBuffersOnRead;
5991 a_perfP->rx_selects = (afs_int32) stats->selects;
5992 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5993 a_perfP->rx_packetsRead_RcvClass =
5994 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5995 a_perfP->rx_packetsRead_SendClass =
5996 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5997 a_perfP->rx_packetsRead_SpecialClass =
5998 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5999 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
6000 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
6001 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
6002 a_perfP->rx_spuriousPacketsRead =
6003 (afs_int32) stats->spuriousPacketsRead;
6004 a_perfP->rx_packetsSent_RcvClass =
6005 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
6006 a_perfP->rx_packetsSent_SendClass =
6007 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
6008 a_perfP->rx_packetsSent_SpecialClass =
6009 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
6010 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
6011 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
6012 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
6013 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
6014 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
6015 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
6016 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
6017 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
6018 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
6019 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
6020 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
6021 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
6022 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
6023 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
6024 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
6025 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
6026 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
6027 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
6028 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
6029 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
6031 a_perfP->host_NumHostEntries = HTs;
6032 a_perfP->host_HostBlocks = HTBlocks;
6033 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
6034 &(a_perfP->host_HostsInSameNetOrSubnet),
6035 &(a_perfP->host_HostsInDiffSubnet),
6036 &(a_perfP->host_HostsInDiffNetwork));
6037 a_perfP->host_NumClients = CEs;
6038 a_perfP->host_ClientBlocks = CEBlocks;
6040 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
6041 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
6042 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
6043 rx_FreeStatistics(&stats);
6044 } /*FillPerfValues */
6047 /*------------------------------------------------------------------------
6048 * EXPORTED SRXAFS_GetXStats
6051 * Routine called by the server-side callback RPC interface to
6052 * implement getting the given data collection from the extended
6053 * File Server statistics.
6056 * a_call : Ptr to Rx call on which this request came in.
6057 * a_clientVersionNum : Client version number.
6058 * a_opCode : Desired operation.
6059 * a_serverVersionNumP : Ptr to version number to set.
6060 * a_timeP : Ptr to time value (seconds) to set.
6061 * a_dataP : Ptr to variable array structure to return
6068 * Nothing interesting.
6072 *------------------------------------------------------------------------*/
6075 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
6076 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
6077 afs_int32 * a_timeP, AFS_CollData * a_dataP)
6078 { /*SRXAFS_GetXStats */
6080 int code; /*Return value */
6081 afs_int32 *dataBuffP; /*Ptr to data to be returned */
6082 afs_int32 dataBytes; /*Bytes in data buffer */
6083 #if FS_STATS_DETAILED
6084 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6085 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6086 struct timeval elapsedTime; /* Transfer time */
6089 * Set our stats pointer, remember when the RPC operation started, and
6090 * tally the operation.
6092 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
6096 FT_GetTimeOfDay(&opStartTime, 0);
6097 #endif /* FS_STATS_DETAILED */
6100 * Record the time of day and the server version number.
6102 *a_srvVersionNumP = AFS_XSTAT_VERSION;
6103 *a_timeP = FT_ApproxTime();
6106 * Stuff the appropriate data in there (assume victory)
6111 ("Received GetXStats call for collection %d\n",
6112 a_collectionNumber));
6116 * We're not keeping stats, so just return successfully with
6119 a_dataP->AFS_CollData_len = 0;
6120 a_dataP->AFS_CollData_val = NULL;
6123 switch (a_collectionNumber) {
6124 case AFS_XSTATSCOLL_CALL_INFO:
6126 * Pass back all the call-count-related data.
6128 * >>> We are forced to allocate a separate area in which to
6129 * >>> put this stuff in by the RPC stub generator, since it
6130 * >>> will be freed at the tail end of the server stub code.
6134 * I don't think call-level stats are being collected yet
6135 * for the File Server.
6137 dataBytes = sizeof(struct afs_Stats);
6138 dataBuffP = (afs_int32 *) malloc(dataBytes);
6139 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6140 a_dataP->AFS_CollData_len = dataBytes >> 2;
6141 a_dataP->AFS_CollData_val = dataBuffP;
6143 a_dataP->AFS_CollData_len = 0;
6144 a_dataP->AFS_CollData_val = NULL;
6148 case AFS_XSTATSCOLL_PERF_INFO:
6150 * Pass back all the regular performance-related data.
6152 * >>> We are forced to allocate a separate area in which to
6153 * >>> put this stuff in by the RPC stub generator, since it
6154 * >>> will be freed at the tail end of the server stub code.
6157 afs_perfstats.numPerfCalls++;
6158 FillPerfValues(&afs_perfstats);
6161 * Don't overwrite the spares at the end.
6164 dataBytes = sizeof(struct afs_PerfStats);
6165 dataBuffP = (afs_int32 *) malloc(dataBytes);
6166 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6167 a_dataP->AFS_CollData_len = dataBytes >> 2;
6168 a_dataP->AFS_CollData_val = dataBuffP;
6171 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6173 * Pass back the full collection of performance-related data.
6174 * We have to stuff the basic, overall numbers in, but the
6175 * detailed numbers are kept in the structure already.
6177 * >>> We are forced to allocate a separate area in which to
6178 * >>> put this stuff in by the RPC stub generator, since it
6179 * >>> will be freed at the tail end of the server stub code.
6182 afs_perfstats.numPerfCalls++;
6183 #if FS_STATS_DETAILED
6184 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6185 FillPerfValues(&afs_FullPerfStats.overall);
6188 * Don't overwrite the spares at the end.
6191 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6192 dataBuffP = (afs_int32 *) malloc(dataBytes);
6193 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6194 a_dataP->AFS_CollData_len = dataBytes >> 2;
6195 a_dataP->AFS_CollData_val = dataBuffP;
6199 case AFS_XSTATSCOLL_CBSTATS:
6200 afs_perfstats.numPerfCalls++;
6202 dataBytes = sizeof(struct cbcounters);
6203 dataBuffP = (afs_int32 *) malloc(dataBytes);
6205 extern struct cbcounters cbstuff;
6206 dataBuffP[0]=cbstuff.DeleteFiles;
6207 dataBuffP[1]=cbstuff.DeleteCallBacks;
6208 dataBuffP[2]=cbstuff.BreakCallBacks;
6209 dataBuffP[3]=cbstuff.AddCallBacks;
6210 dataBuffP[4]=cbstuff.GotSomeSpaces;
6211 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6212 dataBuffP[6]=cbstuff.nFEs;
6213 dataBuffP[7]=cbstuff.nCBs;
6214 dataBuffP[8]=cbstuff.nblks;
6215 dataBuffP[9]=cbstuff.CBsTimedOut;
6216 dataBuffP[10]=cbstuff.nbreakers;
6217 dataBuffP[11]=cbstuff.GSS1;
6218 dataBuffP[12]=cbstuff.GSS2;
6219 dataBuffP[13]=cbstuff.GSS3;
6220 dataBuffP[14]=cbstuff.GSS4;
6221 dataBuffP[15]=cbstuff.GSS5;
6224 a_dataP->AFS_CollData_len = dataBytes >> 2;
6225 a_dataP->AFS_CollData_val = dataBuffP;
6231 * Illegal collection number.
6233 a_dataP->AFS_CollData_len = 0;
6234 a_dataP->AFS_CollData_val = NULL;
6236 } /*Switch on collection number */
6238 #if FS_STATS_DETAILED
6239 FT_GetTimeOfDay(&opStopTime, 0);
6242 (opP->numSuccesses)++;
6243 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6244 fs_stats_AddTo((opP->sumTime), elapsedTime);
6245 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6246 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6247 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6249 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6250 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6254 #endif /* FS_STATS_DETAILED */
6258 } /*SRXAFS_GetXStats */
6262 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6263 struct AFSCBs *CallBackArray)
6265 afs_int32 errorCode = 0;
6267 struct client *client = 0;
6268 struct rx_connection *tcon;
6270 #if FS_STATS_DETAILED
6271 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6272 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6273 struct timeval elapsedTime; /* Transfer time */
6276 * Set our stats pointer, remember when the RPC operation started, and
6277 * tally the operation.
6280 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6284 FT_GetTimeOfDay(&opStartTime, 0);
6285 #endif /* FS_STATS_DETAILED */
6289 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6290 FidArray->AFSCBFids_len));
6293 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6295 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6296 goto Bad_GiveUpCallBacks;
6298 if (!FidArray && !CallBackArray) {
6300 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6301 (tcon->peer ? tcon->peer->host : 0)));
6302 errorCode = GetClient(tcon, &client);
6305 DeleteAllCallBacks_r(client->host, 1);
6310 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6312 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6313 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6314 (tcon->peer ? tcon->peer->host : 0)));
6316 goto Bad_GiveUpCallBacks;
6319 errorCode = GetClient(tcon, &client);
6321 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6322 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6323 DeleteCallBack(client->host, fid);
6329 Bad_GiveUpCallBacks:
6330 errorCode = CallPostamble(tcon, errorCode, thost);
6332 #if FS_STATS_DETAILED
6333 FT_GetTimeOfDay(&opStopTime, 0);
6334 if (errorCode == 0) {
6336 (opP->numSuccesses)++;
6337 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6338 fs_stats_AddTo((opP->sumTime), elapsedTime);
6339 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6340 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6341 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6343 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6344 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6348 #endif /* FS_STATS_DETAILED */
6351 } /*common_GiveUpCallBacks */
6355 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6356 struct AFSCBs * CallBackArray)
6358 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6359 } /*SRXAFS_GiveUpCallBacks */
6362 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6364 return common_GiveUpCallBacks(acall, 0, 0);
6365 } /*SRXAFS_GiveUpAllCallBacks */
6369 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6370 struct AFSVolumeInfo * avolinfo)
6372 return (VNOVOL); /* XXX Obsolete routine XXX */
6374 } /*SRXAFS_NGetVolumeInfo */
6378 * Dummy routine. Should never be called (the cache manager should only
6379 * invoke this interface when communicating with a AFS/DFS Protocol
6383 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6384 char *afs_name_p, struct AFSFid * afs_fid_p,
6385 struct AFSFetchStatus * afs_status_p,
6386 struct AFSFetchStatus * afs_dir_status_p,
6387 struct AFSCallBack * afs_callback_p,
6388 struct AFSVolSync * afs_sync_p)
6395 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6398 struct rx_connection *tcon;
6400 afs_uint32 *dataBuffP;
6401 afs_int32 dataBytes;
6404 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6405 afs_FullPerfStats.overall.fs_nGetCaps++;
6407 ViceLog(2, ("SAFS_GetCapabilties\n"));
6409 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6412 dataBytes = 1 * sizeof(afs_int32);
6413 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6414 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6415 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6417 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6419 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6420 capabilities->Capabilities_val = dataBuffP;
6423 code = CallPostamble(tcon, code, thost);
6430 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6431 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6435 afs_int32 nids, naddrs;
6436 afs_int32 *vd, *addr;
6437 Error errorCode = 0; /* return code to caller */
6438 struct client *client = 0;
6440 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6442 AFSCallStats.TotalCalls++;
6444 nids = vids->ViceIds_len; /* # of users in here */
6445 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6446 if (nids < 0 || naddrs < 0) {
6451 vd = vids->ViceIds_val;
6452 for (i = 0; i < nids; i++, vd++) {
6455 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6459 client->prfail = 2; /* Means re-eval client's cps */
6462 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6465 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6466 free(client->CPS.prlist_val);
6467 client->CPS.prlist_val = NULL;
6468 client->CPS.prlist_len = 0;
6470 ReleaseWriteLock(&client->lock);
6474 addr = addrs->IPAddrs_val;
6475 for (i = 0; i < naddrs; i++, addr++) {
6477 h_flushhostcps(*addr, htons(7001));
6481 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6483 } /*SRXAFS_FlushCPS */
6485 /* worthless hack to let CS keep running ancient software */
6487 afs_vtoi(char *aname)
6493 while ((tc = *aname++)) {
6494 if (tc > '9' || tc < '0')
6495 return 0; /* invalid name */
6503 * may get name or #, but must handle all weird cases (recognize readonly
6504 * or backup volumes by name or #
6507 CopyVolumeEntry(char *aname, struct vldbentry *ave,
6508 struct VolumeInfo *av)
6511 afs_int32 mask, whichType;
6512 afs_uint32 *serverHost, *typePtr;
6514 /* figure out what type we want if by name */
6516 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6517 whichType = BACKVOL;
6518 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6523 vol = afs_vtoi(aname);
6525 vol = ave->volumeId[whichType];
6528 * Now vol has volume # we're interested in. Next, figure out the type
6529 * of the volume by looking finding it in the vldb entry
6531 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6534 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6537 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6538 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6539 whichType = BACKVOL;
6541 return EINVAL; /* error: can't find volume in vldb entry */
6543 typePtr = &av->Type0;
6544 serverHost = &av->Server0;
6546 av->Type = whichType;
6547 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6548 if (ave->flags & VLF_RWEXISTS)
6549 typePtr[RWVOL] = ave->volumeId[RWVOL];
6550 if (ave->flags & VLF_ROEXISTS)
6551 typePtr[ROVOL] = ave->volumeId[ROVOL];
6552 if (ave->flags & VLF_BACKEXISTS)
6553 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6555 for (i = 0, j = 0; i < ave->nServers; i++) {
6556 if ((ave->serverFlags[i] & mask) == 0)
6557 continue; /* wrong volume */
6558 serverHost[j] = ave->serverNumber[i];
6561 av->ServerCount = j;
6563 serverHost[j++] = 0; /* bogus 8, but compat only now */
6568 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6570 static struct rx_connection *vlConn = 0;
6571 static int down = 0;
6572 static afs_int32 lastDownTime = 0;
6573 struct vldbentry tve;
6574 struct rx_securityClass *vlSec;
6578 vlSec = rxnull_NewClientSecurityObject();
6580 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6581 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6583 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6584 return 1; /* failure */
6587 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6589 down = 0; /* call worked */
6592 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6598 /* otherwise convert to old format vldb entry */
6599 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6609 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6610 struct VolumeInfo * avolinfo)
6613 struct rx_connection *tcon;
6615 #if FS_STATS_DETAILED
6616 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6617 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6618 struct timeval elapsedTime; /* Transfer time */
6621 * Set our stats pointer, remember when the RPC operation started, and
6622 * tally the operation.
6624 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6628 FT_GetTimeOfDay(&opStartTime, 0);
6629 #endif /* FS_STATS_DETAILED */
6630 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6631 goto Bad_GetVolumeInfo;
6634 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6636 code = TryLocalVLServer(avolid, avolinfo);
6638 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6639 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6640 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6641 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6644 code = CallPostamble(tcon, code, thost);
6646 #if FS_STATS_DETAILED
6647 FT_GetTimeOfDay(&opStopTime, 0);
6650 (opP->numSuccesses)++;
6651 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6652 fs_stats_AddTo((opP->sumTime), elapsedTime);
6653 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6654 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6655 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6657 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6658 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6662 #endif /* FS_STATS_DETAILED */
6666 } /*SRXAFS_GetVolumeInfo */
6670 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6671 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6672 char **OfflineMsg, char **Motd)
6674 Vnode *targetptr = 0; /* vnode of the new file */
6675 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6676 Error errorCode = 0; /* error code */
6677 Volume *volptr = 0; /* pointer to the volume header */
6678 struct client *client = 0; /* pointer to client entry */
6679 afs_int32 rights, anyrights; /* rights for this and any user */
6681 struct rx_connection *tcon;
6683 struct client *t_client = NULL; /* tmp ptr to client data */
6684 #if FS_STATS_DETAILED
6685 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6686 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6687 struct timeval elapsedTime; /* Transfer time */
6690 * Set our stats pointer, remember when the RPC operation started, and
6691 * tally the operation.
6694 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6698 FT_GetTimeOfDay(&opStartTime, 0);
6699 #endif /* FS_STATS_DETAILED */
6701 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6702 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6703 goto Bad_GetVolumeStatus;
6706 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6710 goto Bad_GetVolumeStatus;
6712 dummyFid.Volume = avolid, dummyFid.Vnode =
6713 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6716 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6717 &parentwhentargetnotdir, &client, READ_LOCK,
6718 &rights, &anyrights)))
6719 goto Bad_GetVolumeStatus;
6721 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6723 goto Bad_GetVolumeStatus;
6725 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6727 Bad_GetVolumeStatus:
6728 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6730 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6731 /* next is to guarantee out strings exist for stub */
6733 *Name = (char *)malloc(1);
6737 *Motd = (char *)malloc(1);
6740 if (*OfflineMsg == 0) {
6741 *OfflineMsg = (char *)malloc(1);
6744 errorCode = CallPostamble(tcon, errorCode, thost);
6746 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6748 #if FS_STATS_DETAILED
6749 FT_GetTimeOfDay(&opStopTime, 0);
6750 if (errorCode == 0) {
6752 (opP->numSuccesses)++;
6753 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6754 fs_stats_AddTo((opP->sumTime), elapsedTime);
6755 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6756 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6757 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6759 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6760 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6764 #endif /* FS_STATS_DETAILED */
6766 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6767 AUD_ID, t_client ? t_client->ViceId : 0,
6768 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6771 } /*SRXAFS_GetVolumeStatus */
6775 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6776 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6777 char *OfflineMsg, char *Motd)
6779 Vnode *targetptr = 0; /* vnode of the new file */
6780 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6781 Error errorCode = 0; /* error code */
6782 Volume *volptr = 0; /* pointer to the volume header */
6783 struct client *client = 0; /* pointer to client entry */
6784 afs_int32 rights, anyrights; /* rights for this and any user */
6786 struct rx_connection *tcon = rx_ConnectionOf(acall);
6788 struct client *t_client = NULL; /* tmp ptr to client data */
6789 #if FS_STATS_DETAILED
6790 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6791 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6792 struct timeval elapsedTime; /* Transfer time */
6795 * Set our stats pointer, remember when the RPC operation started, and
6796 * tally the operation.
6799 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6803 FT_GetTimeOfDay(&opStartTime, 0);
6804 #endif /* FS_STATS_DETAILED */
6806 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6807 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6808 goto Bad_SetVolumeStatus;
6811 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6815 goto Bad_SetVolumeStatus;
6817 dummyFid.Volume = avolid, dummyFid.Vnode =
6818 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6821 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6822 &parentwhentargetnotdir, &client, READ_LOCK,
6823 &rights, &anyrights)))
6824 goto Bad_SetVolumeStatus;
6826 if (readonlyServer) {
6827 errorCode = VREADONLY;
6828 goto Bad_SetVolumeStatus;
6830 if (VanillaUser(client)) {
6832 goto Bad_SetVolumeStatus;
6836 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6838 Bad_SetVolumeStatus:
6839 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6841 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6842 errorCode = CallPostamble(tcon, errorCode, thost);
6844 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6846 #if FS_STATS_DETAILED
6847 FT_GetTimeOfDay(&opStopTime, 0);
6848 if (errorCode == 0) {
6850 (opP->numSuccesses)++;
6851 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6852 fs_stats_AddTo((opP->sumTime), elapsedTime);
6853 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6854 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6855 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6857 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6858 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6862 #endif /* FS_STATS_DETAILED */
6864 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6865 AUD_ID, t_client ? t_client->ViceId : 0,
6866 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6868 } /*SRXAFS_SetVolumeStatus */
6870 #define DEFAULTVOLUME "root.afs"
6873 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6879 struct rx_connection *tcon;
6881 Error errorCode = 0;
6883 #if FS_STATS_DETAILED
6884 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6885 struct timeval opStartTime; /* Start time for RPC op */
6887 struct timeval opStopTime;
6888 struct timeval elapsedTime; /* Transfer time */
6892 * Set our stats pointer, remember when the RPC operation started, and
6893 * tally the operation.
6895 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6899 FT_GetTimeOfDay(&opStartTime, 0);
6900 #endif /* FS_STATS_DETAILED */
6902 return FSERR_EOPNOTSUPP;
6905 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6906 goto Bad_GetRootVolume;
6908 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6911 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6913 strcpy(temp, DEFAULTVOLUME);
6915 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6916 lockf(fd, F_LOCK, 0);
6920 len = read(fd, temp, 256);
6921 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6922 lockf(fd, F_ULOCK, 0);
6927 if (temp[len - 1] == '\n')
6931 *VolumeName = temp; /* freed by rx server-side stub */
6934 errorCode = CallPostamble(tcon, errorCode, thost);
6936 #if FS_STATS_DETAILED
6937 FT_GetTimeOfDay(&opStopTime, 0);
6938 if (errorCode == 0) {
6940 (opP->numSuccesses)++;
6941 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6942 fs_stats_AddTo((opP->sumTime), elapsedTime);
6943 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6944 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6945 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6947 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6948 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6952 #endif /* FS_STATS_DETAILED */
6957 } /*SRXAFS_GetRootVolume */
6960 /* still works because a struct CBS is the same as a struct AFSOpaque */
6962 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6963 struct AFSOpaque * Token)
6966 struct rx_connection *tcon;
6968 #if FS_STATS_DETAILED
6969 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6970 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6971 struct timeval elapsedTime; /* Transfer time */
6974 * Set our stats pointer, remember when the RPC operation started, and
6975 * tally the operation.
6977 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6981 FT_GetTimeOfDay(&opStartTime, 0);
6982 #endif /* FS_STATS_DETAILED */
6984 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6985 goto Bad_CheckToken;
6987 code = FSERR_ECONNREFUSED;
6990 code = CallPostamble(tcon, code, thost);
6992 #if FS_STATS_DETAILED
6993 FT_GetTimeOfDay(&opStopTime, 0);
6996 (opP->numSuccesses)++;
6997 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6998 fs_stats_AddTo((opP->sumTime), elapsedTime);
6999 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
7000 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
7001 fs_stats_TimeAssign((opP->minTime), elapsedTime);
7003 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
7004 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
7008 #endif /* FS_STATS_DETAILED */
7012 } /*SRXAFS_CheckToken */
7015 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
7016 afs_uint32 * USeconds)
7019 struct rx_connection *tcon;
7022 #if FS_STATS_DETAILED
7023 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
7024 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
7025 struct timeval elapsedTime; /* Transfer time */
7028 * Set our stats pointer, remember when the RPC operation started, and
7029 * tally the operation.
7031 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
7035 FT_GetTimeOfDay(&opStartTime, 0);
7036 #endif /* FS_STATS_DETAILED */
7038 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
7042 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
7044 FT_GetTimeOfDay(&tpl, 0);
7045 *Seconds = tpl.tv_sec;
7046 *USeconds = tpl.tv_usec;
7048 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
7051 code = CallPostamble(tcon, code, thost);
7053 #if FS_STATS_DETAILED
7054 FT_GetTimeOfDay(&opStopTime, 0);
7055 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
7058 (opP->numSuccesses)++;
7059 fs_stats_AddTo((opP->sumTime), elapsedTime);
7060 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
7061 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
7062 fs_stats_TimeAssign((opP->minTime), elapsedTime);
7064 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
7065 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
7069 #endif /* FS_STATS_DETAILED */
7073 } /*SRXAFS_GetTime */
7080 * Implement a client's data fetch using Rx.
7083 * volptr : Ptr to the given volume's info.
7084 * targetptr : Pointer to the vnode involved.
7085 * Call : Ptr to the Rx call involved.
7086 * Pos : Offset within the file.
7087 * Len : Length in bytes to read; this value is bogus!
7088 * if FS_STATS_DETAILED
7089 * a_bytesToFetchP : Set to the number of bytes to be fetched from
7091 * a_bytesFetchedP : Set to the actual number of bytes fetched from
7097 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
7098 struct rx_call * Call, afs_sfsize_t Pos,
7099 afs_sfsize_t Len, afs_int32 Int64Mode,
7100 #if FS_STATS_DETAILED
7101 afs_sfsize_t * a_bytesToFetchP,
7102 afs_sfsize_t * a_bytesFetchedP
7103 #endif /* FS_STATS_DETAILED */
7106 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
7111 #else /* HAVE_PIOV */
7112 struct iovec tiov[RX_MAXIOVECS];
7114 #endif /* HAVE_PIOV */
7118 #if FS_STATS_DETAILED
7120 * Initialize the byte count arguments.
7122 (*a_bytesToFetchP) = 0;
7123 (*a_bytesFetchedP) = 0;
7124 #endif /* FS_STATS_DETAILED */
7128 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
7129 (afs_uintmax_t) Len));
7131 if (!VN_GET_INO(targetptr)) {
7132 afs_int32 zero = htonl(0);
7134 * This is used for newly created files; we simply send 0 bytes
7135 * back to make the cache manager happy...
7138 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7139 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7142 FT_GetTimeOfDay(&StartTime, 0);
7143 ihP = targetptr->handle;
7146 VTakeOffline(volptr);
7147 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7151 optSize = sendBufSize;
7152 tlen = FDH_SIZE(fdP);
7154 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7157 VTakeOffline(volptr);
7158 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7162 if (CheckLength(volptr, targetptr, tlen)) {
7164 VTakeOffline(volptr);
7171 if (Pos + Len > tlen) /* get length we should send */
7172 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7175 afs_int32 high, low;
7176 SplitOffsetOrSize(Len, high, low);
7177 osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7180 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7183 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7185 #if FS_STATS_DETAILED
7186 (*a_bytesToFetchP) = Len;
7187 #endif /* FS_STATS_DETAILED */
7189 tbuffer = AllocSendBuffer();
7190 #endif /* HAVE_PIOV */
7199 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
7200 if (nBytes != wlen) {
7202 FreeSendBuffer((struct afs_buffer *)tbuffer);
7203 VTakeOffline(volptr);
7204 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7208 nBytes = rx_Write(Call, tbuffer, wlen);
7209 #else /* HAVE_PIOV */
7210 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7216 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
7217 if (nBytes != wlen) {
7219 VTakeOffline(volptr);
7220 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7224 nBytes = rx_Writev(Call, tiov, tnio, wlen);
7225 #endif /* HAVE_PIOV */
7227 #if FS_STATS_DETAILED
7229 * Bump the number of bytes actually sent by the number from this
7232 (*a_bytesFetchedP) += nBytes;
7233 #endif /* FS_STATS_DETAILED */
7234 if (nBytes != wlen) {
7238 FreeSendBuffer((struct afs_buffer *)tbuffer);
7239 #endif /* HAVE_PIOV */
7240 err = VIsGoingOffline(volptr);
7249 FreeSendBuffer((struct afs_buffer *)tbuffer);
7250 #endif /* HAVE_PIOV */
7252 FT_GetTimeOfDay(&StopTime, 0);
7254 /* Adjust all Fetch Data related stats */
7256 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7257 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7258 AFSCallStats.AccumFetchTime +=
7259 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7260 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7262 afs_fsize_t targLen;
7263 VN_GET_LEN(targLen, targetptr);
7264 AFSCallStats.TotalFetchedBytes += targLen;
7265 AFSCallStats.FetchSize1++;
7266 if (targLen < SIZE2)
7267 AFSCallStats.FetchSize2++;
7268 else if (targLen < SIZE3)
7269 AFSCallStats.FetchSize3++;
7270 else if (targLen < SIZE4)
7271 AFSCallStats.FetchSize4++;
7273 AFSCallStats.FetchSize5++;
7278 } /*FetchData_RXStyle */
7281 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7282 afs_sfsize_t * size)
7284 #ifdef AFS_NAMEI_ENV
7286 lhp = IH_OPEN(V_linkHandle(vp));
7289 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
7293 *size = OS_SIZE(fdP->fd_fd);
7294 return (*size == -1) ? -1 : 0;
7296 struct afs_stat status;
7298 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7302 *lc = GetLinkCount(vp, &status);
7303 *size = status.st_size;
7312 * Implement a client's data store using Rx.
7315 * volptr : Ptr to the given volume's info.
7316 * targetptr : Pointer to the vnode involved.
7317 * Call : Ptr to the Rx call involved.
7318 * Pos : Offset within the file.
7319 * Len : Length in bytes to store; this value is bogus!
7320 * if FS_STATS_DETAILED
7321 * a_bytesToStoreP : Set to the number of bytes to be stored to
7323 * a_bytesStoredP : Set to the actual number of bytes stored to
7328 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7329 struct client * client, struct rx_call * Call,
7330 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7332 #if FS_STATS_DETAILED
7333 afs_sfsize_t * a_bytesToStoreP,
7334 afs_sfsize_t * a_bytesStoredP
7335 #endif /* FS_STATS_DETAILED */
7338 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7339 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7340 Error errorCode = 0; /* Returned error code to caller */
7342 char *tbuffer; /* data copying buffer */
7343 #else /* HAVE_PIOV */
7344 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7345 int tnio; /* temp for iovec size */
7346 #endif /* HAVE_PIOV */
7347 afs_sfsize_t tlen; /* temp for xfr length */
7348 Inode tinode; /* inode for I/O */
7349 afs_int32 optSize; /* optimal transfer size */
7350 afs_sfsize_t DataLength = 0; /* size of inode */
7351 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7352 afs_fsize_t NewLength; /* size after this store completes */
7353 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7354 int linkCount = 0; /* link count on inode */
7355 afs_fsize_t CoW_off, CoW_len;
7357 FdHandle_t *fdP, *origfdP = NULL;
7358 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7361 #if FS_STATS_DETAILED
7363 * Initialize the byte count arguments.
7365 (*a_bytesToStoreP) = 0;
7366 (*a_bytesStoredP) = 0;
7367 #endif /* FS_STATS_DETAILED */
7370 * We break the callbacks here so that the following signal will not
7373 BreakCallBack(client->host, Fid, 0);
7375 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7376 /* the inode should have been created in Alloc_NewVnode */
7377 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7379 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7380 Fid->Volume, Fid->Vnode, Fid->Unique,
7381 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7382 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7383 return ENOENT; /* is this proper error code? */
7386 * See if the file has several links (from other volumes). If it
7387 * does, then we have to make a copy before changing it to avoid
7388 *changing read-only clones of this dude
7391 ("StoreData_RXStyle : Opening inode %s\n",
7392 PrintInode(stmp, VN_GET_INO(targetptr))));
7393 fdP = IH_OPEN(targetptr->handle);
7396 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7398 VTakeOffline(volptr);
7399 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7403 if (CheckLength(volptr, targetptr, DataLength)) {
7405 VTakeOffline(volptr);
7409 if (linkCount != 1) {
7412 ("StoreData_RXStyle : inode %s has more than onelink\n",
7413 PrintInode(stmp, VN_GET_INO(targetptr))));
7414 /* other volumes share this data, better copy it first */
7416 /* Adjust the disk block count by the creation of the new inode.
7417 * We call the special VDiskUsage so we don't adjust the volume's
7418 * quota since we don't want to penalyze the user for afs's internal
7419 * mechanisms (i.e. copy on write overhead.) Also the right size
7420 * of the disk will be recorded...
7423 VN_GET_LEN(size, targetptr);
7424 volptr->partition->flags &= ~PART_DONTUPDATE;
7425 VSetPartitionDiskUsage(volptr->partition);
7426 volptr->partition->flags |= PART_DONTUPDATE;
7427 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7428 volptr->partition->flags &= ~PART_DONTUPDATE;
7433 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7434 CopyOnWrite_calls++;
7435 if (CoW_len == 0) CopyOnWrite_size0++;
7436 if (Pos == 0) CopyOnWrite_off0++;
7437 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7439 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7440 "off 0x0 size 0x%llx\n",
7441 afs_printable_VolumeId_u(V_id(volptr)),
7442 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7443 V_name(volptr), Pos));
7444 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7445 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7446 volptr->partition->flags &= ~PART_DONTUPDATE;
7450 volptr->partition->flags &= ~PART_DONTUPDATE;
7451 VSetPartitionDiskUsage(volptr->partition);
7452 fdP = IH_OPEN(targetptr->handle);
7455 ("StoreData : Reopen after CopyOnWrite failed\n"));
7456 FDH_REALLYCLOSE(origfdP);
7460 tinode = VN_GET_INO(targetptr);
7462 if (!VALID_INO(tinode)) {
7463 VTakeOffline(volptr);
7464 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7469 /* compute new file length */
7470 NewLength = DataLength;
7471 if (FileLength < NewLength)
7472 /* simulate truncate */
7473 NewLength = FileLength;
7474 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7475 if (Pos + Length > NewLength)
7476 NewLength = Pos + Length; /* and write */
7478 /* adjust the disk block count by the difference in the files */
7480 afs_fsize_t targSize;
7481 VN_GET_LEN(targSize, targetptr);
7482 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7485 AdjustDiskUsage(volptr, adjustSize,
7486 adjustSize - SpareComp(volptr)))) {
7488 if (origfdP) FDH_REALLYCLOSE(origfdP);
7492 /* can signal cache manager to proceed from close now */
7493 /* this bit means that the locks are set and protections are OK */
7494 rx_SetLocalStatus(Call, 1);
7496 FT_GetTimeOfDay(&StartTime, 0);
7498 optSize = sendBufSize;
7500 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7501 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7502 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7504 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7505 if (FileLength < DataLength)
7506 FDH_TRUNC(fdP, FileLength);
7507 bytesTransfered = 0;
7509 tbuffer = AllocSendBuffer();
7510 #endif /* HAVE_PIOV */
7511 /* if length == 0, the loop below isn't going to do anything, including
7512 * extend the length of the inode, which it must do, since the file system
7513 * assumes that the inode length == vnode's file length. So, we extend
7514 * the file length manually if need be. Note that if file is bigger than
7515 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7516 * do what we're going to do below.
7518 if (Length == 0 && Pos > TruncatedLength) {
7519 /* Set the file's length; we've already done an lseek to the right
7522 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
7527 errorCode = FDH_TRUNC(fdP, Pos);
7529 /* have some data to copy */
7530 #if FS_STATS_DETAILED
7531 (*a_bytesToStoreP) = Length;
7532 #endif /* FS_STATS_DETAILED */
7535 if (bytesTransfered >= Length) {
7539 tlen = Length - bytesTransfered; /* how much more to do */
7541 rlen = optSize; /* bound by buffer size */
7545 errorCode = rx_Read(Call, tbuffer, rlen);
7546 #else /* HAVE_PIOV */
7547 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7548 #endif /* HAVE_PIOV */
7549 if (errorCode <= 0) {
7553 #if FS_STATS_DETAILED
7554 (*a_bytesStoredP) += errorCode;
7555 #endif /* FS_STATS_DETAILED */
7558 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
7559 #else /* HAVE_PIOV */
7560 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
7561 #endif /* HAVE_PIOV */
7562 if (nBytes != rlen) {
7563 errorCode = VDISKFULL;
7566 bytesTransfered += rlen;
7572 FreeSendBuffer((struct afs_buffer *)tbuffer);
7573 #endif /* HAVE_PIOV */
7578 afs_sfsize_t nfSize = FDH_SIZE(fdP);
7579 osi_Assert(nfSize >= 0);
7580 /* something went wrong: adjust size and return */
7581 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7582 /* changed_newTime is tested in StoreData to detemine if we
7583 * need to update the target vnode.
7585 targetptr->changed_newTime = 1;
7586 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7587 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7588 if (origfdP) FDH_REALLYCLOSE(origfdP);
7590 /* set disk usage to be correct */
7591 VAdjustDiskUsage(&errorCode, volptr,
7592 (afs_sfsize_t) (nBlocks(nfSize) -
7593 nBlocks(NewLength)), 0);
7596 if (origfdP) { /* finish CopyOnWrite */
7597 if ( (CoW_off = Pos + Length) < NewLength) {
7598 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7599 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7600 "off 0x%llx size 0x%llx returns %d\n",
7601 afs_printable_VolumeId_u(V_id(volptr)),
7602 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7603 V_name(volptr), CoW_off, CoW_len, errorCode));
7605 FDH_REALLYCLOSE(origfdP);
7609 FT_GetTimeOfDay(&StopTime, 0);
7611 VN_SET_LEN(targetptr, NewLength);
7613 /* Update all StoreData related stats */
7615 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7616 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7617 AFSCallStats.StoreSize1++; /* Piggybacked data */
7619 afs_fsize_t targLen;
7620 VN_GET_LEN(targLen, targetptr);
7621 if (targLen < SIZE2)
7622 AFSCallStats.StoreSize2++;
7623 else if (targLen < SIZE3)
7624 AFSCallStats.StoreSize3++;
7625 else if (targLen < SIZE4)
7626 AFSCallStats.StoreSize4++;
7628 AFSCallStats.StoreSize5++;
7633 } /*StoreData_RXStyle */
7635 static int sys2et[512];
7638 init_sys_error_to_et(void)
7640 memset(&sys2et, 0, sizeof(sys2et));
7641 sys2et[EPERM] = UAEPERM;
7642 sys2et[ENOENT] = UAENOENT;
7643 sys2et[ESRCH] = UAESRCH;
7644 sys2et[EINTR] = UAEINTR;
7645 sys2et[EIO] = UAEIO;
7646 sys2et[ENXIO] = UAENXIO;
7647 sys2et[E2BIG] = UAE2BIG;
7648 sys2et[ENOEXEC] = UAENOEXEC;
7649 sys2et[EBADF] = UAEBADF;
7650 sys2et[ECHILD] = UAECHILD;
7651 sys2et[EAGAIN] = UAEAGAIN;
7652 sys2et[ENOMEM] = UAENOMEM;
7653 sys2et[EACCES] = UAEACCES;
7654 sys2et[EFAULT] = UAEFAULT;
7655 sys2et[ENOTBLK] = UAENOTBLK;
7656 sys2et[EBUSY] = UAEBUSY;
7657 sys2et[EEXIST] = UAEEXIST;
7658 sys2et[EXDEV] = UAEXDEV;
7659 sys2et[ENODEV] = UAENODEV;
7660 sys2et[ENOTDIR] = UAENOTDIR;
7661 sys2et[EISDIR] = UAEISDIR;
7662 sys2et[EINVAL] = UAEINVAL;
7663 sys2et[ENFILE] = UAENFILE;
7664 sys2et[EMFILE] = UAEMFILE;
7665 sys2et[ENOTTY] = UAENOTTY;
7666 sys2et[ETXTBSY] = UAETXTBSY;
7667 sys2et[EFBIG] = UAEFBIG;
7668 sys2et[ENOSPC] = UAENOSPC;
7669 sys2et[ESPIPE] = UAESPIPE;
7670 sys2et[EROFS] = UAEROFS;
7671 sys2et[EMLINK] = UAEMLINK;
7672 sys2et[EPIPE] = UAEPIPE;
7673 sys2et[EDOM] = UAEDOM;
7674 sys2et[ERANGE] = UAERANGE;
7675 sys2et[EDEADLK] = UAEDEADLK;
7676 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7677 sys2et[ENOLCK] = UAENOLCK;
7678 sys2et[ENOSYS] = UAENOSYS;
7679 #if (ENOTEMPTY != EEXIST)
7680 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7682 sys2et[ELOOP] = UAELOOP;
7683 #if (EWOULDBLOCK != EAGAIN)
7684 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7686 sys2et[ENOMSG] = UAENOMSG;
7687 sys2et[EIDRM] = UAEIDRM;
7688 sys2et[ECHRNG] = UAECHRNG;
7689 sys2et[EL2NSYNC] = UAEL2NSYNC;
7690 sys2et[EL3HLT] = UAEL3HLT;
7691 sys2et[EL3RST] = UAEL3RST;
7692 sys2et[ELNRNG] = UAELNRNG;
7693 sys2et[EUNATCH] = UAEUNATCH;
7694 sys2et[ENOCSI] = UAENOCSI;
7695 sys2et[EL2HLT] = UAEL2HLT;
7696 sys2et[EBADE] = UAEBADE;
7697 sys2et[EBADR] = UAEBADR;
7698 sys2et[EXFULL] = UAEXFULL;
7699 sys2et[ENOANO] = UAENOANO;
7700 sys2et[EBADRQC] = UAEBADRQC;
7701 sys2et[EBADSLT] = UAEBADSLT;
7702 sys2et[EDEADLK] = UAEDEADLK;
7703 sys2et[EBFONT] = UAEBFONT;
7704 sys2et[ENOSTR] = UAENOSTR;
7705 sys2et[ENODATA] = UAENODATA;
7706 sys2et[ETIME] = UAETIME;
7707 sys2et[ENOSR] = UAENOSR;
7708 sys2et[ENONET] = UAENONET;
7709 sys2et[ENOPKG] = UAENOPKG;
7710 sys2et[EREMOTE] = UAEREMOTE;
7711 sys2et[ENOLINK] = UAENOLINK;
7712 sys2et[EADV] = UAEADV;
7713 sys2et[ESRMNT] = UAESRMNT;
7714 sys2et[ECOMM] = UAECOMM;
7715 sys2et[EPROTO] = UAEPROTO;
7716 sys2et[EMULTIHOP] = UAEMULTIHOP;
7717 sys2et[EDOTDOT] = UAEDOTDOT;
7718 sys2et[EBADMSG] = UAEBADMSG;
7719 sys2et[EOVERFLOW] = UAEOVERFLOW;
7720 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7721 sys2et[EBADFD] = UAEBADFD;
7722 sys2et[EREMCHG] = UAEREMCHG;
7723 sys2et[ELIBACC] = UAELIBACC;
7724 sys2et[ELIBBAD] = UAELIBBAD;
7725 sys2et[ELIBSCN] = UAELIBSCN;
7726 sys2et[ELIBMAX] = UAELIBMAX;
7727 sys2et[ELIBEXEC] = UAELIBEXEC;
7728 sys2et[EILSEQ] = UAEILSEQ;
7729 sys2et[ERESTART] = UAERESTART;
7730 sys2et[ESTRPIPE] = UAESTRPIPE;
7731 sys2et[EUSERS] = UAEUSERS;
7732 sys2et[ENOTSOCK] = UAENOTSOCK;
7733 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7734 sys2et[EMSGSIZE] = UAEMSGSIZE;
7735 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7736 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7737 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7738 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7739 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7740 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7741 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7742 sys2et[EADDRINUSE] = UAEADDRINUSE;
7743 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7744 sys2et[ENETDOWN] = UAENETDOWN;
7745 sys2et[ENETUNREACH] = UAENETUNREACH;
7746 sys2et[ENETRESET] = UAENETRESET;
7747 sys2et[ECONNABORTED] = UAECONNABORTED;
7748 sys2et[ECONNRESET] = UAECONNRESET;
7749 sys2et[ENOBUFS] = UAENOBUFS;
7750 sys2et[EISCONN] = UAEISCONN;
7751 sys2et[ENOTCONN] = UAENOTCONN;
7752 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7753 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7754 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7755 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7756 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7757 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7758 sys2et[EALREADY] = UAEALREADY;
7759 sys2et[EINPROGRESS] = UAEINPROGRESS;
7760 sys2et[ESTALE] = UAESTALE;
7761 sys2et[EUCLEAN] = UAEUCLEAN;
7762 sys2et[ENOTNAM] = UAENOTNAM;
7763 sys2et[ENAVAIL] = UAENAVAIL;
7764 sys2et[EISNAM] = UAEISNAM;
7765 sys2et[EREMOTEIO] = UAEREMOTEIO;
7766 sys2et[EDQUOT] = UAEDQUOT;
7767 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7768 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7770 sys2et[EIO] = UAEIO;
7774 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7775 * - pass back the connection, client, and host from CallPreamble
7776 * - keep a ref on the client, which we don't now
7777 * - keep a hold on the host, which we already do
7778 * - pass the connection, client, and host down into SAFSS_*, and use
7779 * them instead of independently discovering them via rx_ConnectionOf
7780 * (safe) and rx_GetSpecific (not so safe)
7781 * The idea being that we decide what client and host we're going to use
7782 * when CallPreamble is called, and stay consistent throughout the call.
7783 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7787 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7789 Error errorCode = 0;
7790 struct rx_connection *tcon;
7791 struct host *tcallhost;
7792 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7794 struct client *tclient;
7795 static struct rx_securityClass *sc = 0;
7797 struct rx_connection *conn;
7800 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7801 goto Bad_CallBackRxConnAddr1;
7803 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7807 tclient = h_FindClient_r(tcon);
7810 goto Bad_CallBackRxConnAddr;
7812 thost = tclient->host;
7814 /* nothing more can be done */
7815 if ( !thost->interface )
7816 goto Bad_CallBackRxConnAddr;
7818 /* the only address is the primary interface */
7819 /* can't change when there's only 1 address, anyway */
7820 if ( thost->interface->numberOfInterfaces <= 1 )
7821 goto Bad_CallBackRxConnAddr;
7823 /* initialise a security object only once */
7825 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7827 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7829 if ( *addr == thost->interface->addr[i] ) {
7834 if ( *addr != thost->interface->addr[i] )
7835 goto Bad_CallBackRxConnAddr;
7837 conn = rx_NewConnection (thost->interface->addr[i],
7838 thost->port, 1, sc, 0);
7839 rx_SetConnDeadTime(conn, 2);
7840 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7842 errorCode = RXAFSCB_Probe(conn);
7845 if ( thost->callback_rxcon )
7846 rx_DestroyConnection(thost->callback_rxcon);
7847 thost->callback_rxcon = conn;
7849 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7850 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7851 h_ReleaseClient_r(tclient);
7852 /* The hold on thost will be released by CallPostamble */
7854 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7857 rx_DestroyConnection(conn);
7859 Bad_CallBackRxConnAddr:
7860 h_ReleaseClient_r(tclient);
7861 /* The hold on thost will be released by CallPostamble */
7865 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7866 Bad_CallBackRxConnAddr1:
7867 return errorCode; /* failure */
7871 sys_error_to_et(afs_int32 in)
7875 if (in < 0 || in > 511)
7877 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7879 if (sys2et[in] != 0)