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 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
4011 * call to CopyOnWrite returns error, it is not necessary to revert back
4012 * the effects of the first call because the contents of the volume is
4013 * not modified, it is only replicated.
4015 if (oldvptr->disk.cloned) {
4016 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
4017 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
4020 SetDirHandle(&olddir, oldvptr);
4021 if (newvptr->disk.cloned) {
4022 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
4023 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
4027 SetDirHandle(&newdir, newvptr);
4029 /* Lookup the file to delete its vnode */
4030 if (Lookup(&olddir, OldName, &fileFid)) {
4034 if (fileFid.Vnode == oldvptr->vnodeNumber
4035 || fileFid.Vnode == newvptr->vnodeNumber) {
4036 errorCode = FSERR_ELOOP;
4039 fileFid.Volume = V_id(volptr);
4040 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
4041 if (errorCode != 0) {
4043 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
4044 OldName, errorCode));
4045 VTakeOffline(volptr);
4048 if (fileptr->disk.uniquifier != fileFid.Unique) {
4050 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
4052 VTakeOffline(volptr);
4057 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
4058 && fileptr->disk.linkCount != 1) {
4060 * Hard links exist to this file - cannot move one of the links to
4061 * a new directory because of AFS restrictions (this is the same
4062 * reason that links cannot be made across directories, i.e.
4069 /* Lookup the new file */
4070 if (!(Lookup(&newdir, NewName, &newFileFid))) {
4071 if (readonlyServer) {
4072 errorCode = VREADONLY;
4075 if (!(newrights & PRSFS_DELETE)) {
4079 if (newFileFid.Vnode == oldvptr->vnodeNumber
4080 || newFileFid.Vnode == newvptr->vnodeNumber
4081 || newFileFid.Vnode == fileFid.Vnode) {
4085 newFileFid.Volume = V_id(volptr);
4087 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4088 if (errorCode != 0) {
4090 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4091 NewName, errorCode));
4092 VTakeOffline(volptr);
4095 if (fileptr->disk.uniquifier != fileFid.Unique) {
4097 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4099 VTakeOffline(volptr);
4103 SetDirHandle(&newfiledir, newfileptr);
4104 /* Now check that we're moving directories over directories properly, etc.
4105 * return proper POSIX error codes:
4106 * if fileptr is a file and new is a dir: EISDIR.
4107 * if fileptr is a dir and new is a file: ENOTDIR.
4108 * Also, dir to be removed must be empty, of course.
4110 if (newfileptr->disk.type == vDirectory) {
4111 if (fileptr->disk.type != vDirectory) {
4115 if ((IsEmpty(&newfiledir))) {
4120 if (fileptr->disk.type == vDirectory) {
4121 errorCode = ENOTDIR;
4128 * ok - now we check that the old name is not above new name in the
4129 * directory structure. This is to prevent removing a subtree alltogether
4131 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4132 afs_int32 forpass = 0, vnum = 0, top = 0;
4133 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4134 if (testnode > vnum) vnum = testnode;
4135 if (forpass > vnum) {
4136 errorCode = FSERR_ELOOP;
4139 if (testnode == oldvptr->vnodeNumber) {
4140 testnode = oldvptr->disk.parent;
4143 if ((testnode == fileptr->vnodeNumber)
4144 || (testnode == newvptr->vnodeNumber)) {
4145 errorCode = FSERR_ELOOP;
4148 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4149 errorCode = FSERR_ELOOP;
4152 if (testnode == 1) top = 1;
4153 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4154 osi_Assert(errorCode == 0);
4155 testnode = testvptr->disk.parent;
4156 VPutVnode(&errorCode, testvptr);
4157 if ((top == 1) && (testnode != 0)) {
4158 VTakeOffline(volptr);
4160 ("Volume %u now offline, must be salvaged.\n",
4165 osi_Assert(errorCode == 0);
4169 if (fileptr->disk.type == vDirectory) {
4170 SetDirHandle(&filedir, fileptr);
4171 if (oldvptr != newvptr) {
4172 /* we always need to update .. if we've moving fileptr to a
4173 * different directory */
4176 struct AFSFid unused;
4178 code = Lookup(&filedir, "..", &unused);
4179 if (code == ENOENT) {
4180 /* only update .. if it doesn't already exist */
4186 /* Do the CopyonWrite first before modifying anything else. Copying is
4187 * required when we have to change entries for ..
4189 if (updatefile && (fileptr->disk.cloned)) {
4190 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4191 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4195 /* If the new name exists already, delete it and the file it points to */
4198 /* Delete NewName from its directory */
4199 code = Delete(&newdir, NewName);
4200 osi_Assert(code == 0);
4202 /* Drop the link count */
4203 newfileptr->disk.linkCount--;
4204 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4205 afs_fsize_t newSize;
4206 VN_GET_LEN(newSize, newfileptr);
4207 VAdjustDiskUsage((Error *) & errorCode, volptr,
4208 (afs_sfsize_t) - nBlocks(newSize), 0);
4209 if (VN_GET_INO(newfileptr)) {
4210 IH_REALLYCLOSE(newfileptr->handle);
4212 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4213 V_parentId(volptr));
4214 IH_RELEASE(newfileptr->handle);
4215 if (errorCode == -1) {
4217 ("Del: inode=%s, name=%s, errno=%d\n",
4218 PrintInode(stmp, VN_GET_INO(newfileptr)),
4220 if ((errno != ENOENT) && (errno != EIO)
4221 && (errno != ENXIO))
4222 ViceLog(0, ("Do we need to fsck?"));
4225 VN_SET_INO(newfileptr, (Inode) 0);
4226 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4229 /* Link count did not drop to zero.
4230 * Mark NewName vnode as changed - updates stime.
4232 newfileptr->changed_newTime = 1;
4237 * If the create below fails, and the delete above worked, we have
4238 * removed the new name and not replaced it. This is not very likely,
4239 * but possible. We could try to put the old file back, but it is
4240 * highly unlikely that it would work since it would involve issuing
4243 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4246 /* Delete the old name */
4247 osi_Assert(Delete(&olddir, (char *)OldName) == 0);
4249 /* if the directory length changes, reflect it in the statistics */
4250 #if FS_STATS_DETAILED
4251 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4252 oldvptr->disk.linkCount, client->InSameNetwork);
4253 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4254 newvptr->disk.linkCount, client->InSameNetwork);
4256 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4257 oldvptr->disk.linkCount);
4258 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4259 newvptr->disk.linkCount);
4260 #endif /* FS_STATS_DETAILED */
4262 if (oldvptr == newvptr)
4263 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4265 if (fileptr->disk.parent != newvptr->vnodeNumber) {
4266 fileptr->disk.parent = newvptr->vnodeNumber;
4267 fileptr->changed_newTime = 1;
4270 /* if we are dealing with a rename of a directory, and we need to
4271 * update the .. entry of that directory */
4273 osi_Assert(!fileptr->disk.cloned);
4275 fileptr->changed_newTime = 1; /* status change of moved file */
4277 /* fix .. to point to the correct place */
4278 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4279 osi_Assert(Create(&filedir, "..", NewDirFid) == 0);
4280 fileptr->disk.dataVersion++;
4282 /* if the parent directories are different the link counts have to be */
4283 /* changed due to .. in the renamed directory */
4284 if (oldvptr != newvptr) {
4285 oldvptr->disk.linkCount--;
4286 newvptr->disk.linkCount++;
4290 /* set up return status */
4291 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4292 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4293 if (newfileptr && doDelete) {
4294 DeleteFileCallBacks(&newFileFid); /* no other references */
4299 /* convert the write locks to a read locks before breaking callbacks */
4300 VVnodeWriteToRead(&errorCode, newvptr);
4301 osi_Assert(!errorCode || errorCode == VSALVAGE);
4302 if (oldvptr != newvptr) {
4303 VVnodeWriteToRead(&errorCode, oldvptr);
4304 osi_Assert(!errorCode || errorCode == VSALVAGE);
4306 if (newfileptr && !doDelete) {
4307 /* convert the write lock to a read lock before breaking callbacks */
4308 VVnodeWriteToRead(&errorCode, newfileptr);
4309 osi_Assert(!errorCode || errorCode == VSALVAGE);
4312 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4313 BreakCallBack(client->host, NewDirFid, 0);
4314 if (oldvptr != newvptr) {
4315 BreakCallBack(client->host, OldDirFid, 0);
4318 /* if a dir moved, .. changed */
4319 /* we do not give an AFSFetchStatus structure back to the
4320 * originating client, and the file's status has changed, so be
4321 * sure to send a callback break. In theory the client knows
4322 * enough to know that the callback could be broken implicitly,
4323 * but that may not be clear, and some client implementations
4324 * may not know to. */
4325 BreakCallBack(client->host, &fileFid, 1);
4328 /* Note: it is not necessary to break the callback */
4330 DeleteFileCallBacks(&newFileFid); /* no other references */
4332 /* other's still exist (with wrong link count) */
4333 BreakCallBack(client->host, &newFileFid, 1);
4338 VPutVnode(&fileCode, newfileptr);
4339 osi_Assert(fileCode == 0);
4341 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4342 newvptr : 0), oldvptr, volptr, &client);
4346 FidZap(&newfiledir);
4347 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4354 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4355 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4356 struct AFSFetchStatus * OutOldDirStatus,
4357 struct AFSFetchStatus * OutNewDirStatus,
4358 struct AFSVolSync * Sync)
4361 struct rx_connection *tcon;
4363 struct client *t_client = NULL; /* tmp ptr to client data */
4364 #if FS_STATS_DETAILED
4365 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4366 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4367 struct timeval elapsedTime; /* Transfer time */
4370 * Set our stats pointer, remember when the RPC operation started, and
4371 * tally the operation.
4373 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4377 FT_GetTimeOfDay(&opStartTime, 0);
4378 #endif /* FS_STATS_DETAILED */
4380 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4384 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4385 OutOldDirStatus, OutNewDirStatus, Sync);
4388 code = CallPostamble(tcon, code, thost);
4390 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4392 #if FS_STATS_DETAILED
4393 FT_GetTimeOfDay(&opStopTime, 0);
4396 (opP->numSuccesses)++;
4397 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4398 fs_stats_AddTo((opP->sumTime), elapsedTime);
4399 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4400 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4401 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4403 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4404 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4408 #endif /* FS_STATS_DETAILED */
4410 osi_auditU(acall, RenameFileEvent, code,
4411 AUD_ID, t_client ? t_client->ViceId : 0,
4412 AUD_FID, OldDirFid, AUD_STR, OldName,
4413 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4416 } /*SRXAFS_Rename */
4420 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4421 * merged into it when possible.
4424 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4425 char *LinkContents, struct AFSStoreStatus *InStatus,
4426 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4427 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4429 Vnode *parentptr = 0; /* vnode of input Directory */
4430 Vnode *targetptr = 0; /* vnode of the new link */
4431 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4432 Error errorCode = 0; /* error code */
4435 DirHandle dir; /* Handle for dir package I/O */
4436 Volume *volptr = 0; /* pointer to the volume header */
4437 struct client *client = 0; /* pointer to client structure */
4438 afs_int32 rights, anyrights; /* rights for this and any user */
4439 struct client *t_client; /* tmp ptr to client data */
4440 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4442 struct rx_connection *tcon = rx_ConnectionOf(acall);
4446 /* Get ptr to client data for user Id for logging */
4447 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4448 logHostAddr.s_addr = rxr_HostOf(tcon);
4450 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4451 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4452 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4454 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4456 if (!FileNameOK(Name)) {
4462 * Get the vnode and volume for the parent dir along with the caller's
4466 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4467 &parentwhentargetnotdir, &client, WRITE_LOCK,
4468 &rights, &anyrights))) {
4472 /* set volume synchronization information */
4473 SetVolumeSync(Sync, volptr);
4475 /* Does the caller has insert (and write) access to the parent directory? */
4476 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4481 * If we're creating a mount point (any x bits clear), we must have
4482 * administer access to the directory, too. Always allow sysadmins
4485 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4486 if (readonlyServer) {
4487 errorCode = VREADONLY;
4491 * We have a mountpoint, 'cause we're trying to set the Unix mode
4492 * bits to something with some x bits missing (default mode bits
4493 * if AFS_SETMODE is false is 0777)
4495 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4501 /* get a new vnode for the symlink and set it up */
4503 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4504 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4508 /* update the status of the parent vnode */
4509 #if FS_STATS_DETAILED
4510 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4511 parentptr->disk.linkCount,
4512 client->InSameNetwork);
4514 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4515 parentptr->disk.linkCount);
4516 #endif /* FS_STATS_DETAILED */
4518 /* update the status of the new symbolic link file vnode */
4519 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4520 parentptr, volptr, strlen((char *)LinkContents));
4522 /* Write the contents of the symbolic link name into the target inode */
4523 fdP = IH_OPEN(targetptr->handle);
4525 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4527 VTakeOffline(volptr);
4528 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4532 len = strlen((char *) LinkContents);
4533 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4535 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4538 * Set up and return modified status for the parent dir and new symlink
4541 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4542 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4544 /* convert the write lock to a read lock before breaking callbacks */
4545 VVnodeWriteToRead(&errorCode, parentptr);
4546 osi_Assert(!errorCode || errorCode == VSALVAGE);
4548 /* break call back on the parent dir */
4549 BreakCallBack(client->host, DirFid, 0);
4552 /* Write the all modified vnodes (parent, new files) and volume back */
4553 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4556 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4557 return ( errorCode ? errorCode : code );
4559 } /*SAFSS_Symlink */
4563 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4564 struct AFSFid *DirFid, /* Parent dir's fid */
4565 char *Name, /* File name to create */
4566 char *LinkContents, /* Contents of the new created file */
4567 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4568 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4569 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4570 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4571 struct AFSVolSync *Sync)
4574 struct rx_connection *tcon;
4576 struct client *t_client = NULL; /* tmp ptr to client data */
4577 #if FS_STATS_DETAILED
4578 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4579 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4580 struct timeval elapsedTime; /* Transfer time */
4583 * Set our stats pointer, remember when the RPC operation started, and
4584 * tally the operation.
4586 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4590 FT_GetTimeOfDay(&opStartTime, 0);
4591 #endif /* FS_STATS_DETAILED */
4593 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4597 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4598 OutFidStatus, OutDirStatus, Sync);
4601 code = CallPostamble(tcon, code, thost);
4603 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4605 #if FS_STATS_DETAILED
4606 FT_GetTimeOfDay(&opStopTime, 0);
4609 (opP->numSuccesses)++;
4610 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4611 fs_stats_AddTo((opP->sumTime), elapsedTime);
4612 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4613 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4614 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4616 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4617 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4621 #endif /* FS_STATS_DETAILED */
4623 osi_auditU(acall, SymlinkEvent, code,
4624 AUD_ID, t_client ? t_client->ViceId : 0,
4625 AUD_FID, DirFid, AUD_STR, Name,
4626 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4629 } /*SRXAFS_Symlink */
4633 * This routine is called exclusively by SRXAFS_Link(), and should be
4634 * merged into it when possible.
4637 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4638 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4639 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4641 Vnode *parentptr = 0; /* vnode of input Directory */
4642 Vnode *targetptr = 0; /* vnode of the new file */
4643 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4644 Volume *volptr = 0; /* pointer to the volume header */
4645 Error errorCode = 0; /* error code */
4646 DirHandle dir; /* Handle for dir package I/O */
4647 struct client *client = 0; /* pointer to client structure */
4648 afs_int32 rights, anyrights; /* rights for this and any user */
4649 struct client *t_client; /* tmp ptr to client data */
4650 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4651 struct rx_connection *tcon = rx_ConnectionOf(acall);
4655 /* Get ptr to client data for user Id for logging */
4656 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4657 logHostAddr.s_addr = rxr_HostOf(tcon);
4659 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4660 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4661 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4662 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4664 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4666 if (DirFid->Volume != ExistingFid->Volume) {
4670 if (!FileNameOK(Name)) {
4676 * Get the vnode and volume for the parent dir along with the caller's
4680 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4681 &parentwhentargetnotdir, &client, WRITE_LOCK,
4682 &rights, &anyrights))) {
4686 /* set volume synchronization information */
4687 SetVolumeSync(Sync, volptr);
4689 /* Can the caller insert into the parent directory? */
4690 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4694 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4695 /* AFS fileservers always have directory vnodes that are odd. */
4700 /* get the file vnode */
4702 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4705 if (targetptr->disk.type != vFile) {
4709 if (targetptr->disk.parent != DirFid->Vnode) {
4713 if (parentptr->disk.cloned) {
4714 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4715 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4716 goto Bad_Link; /* disk full error */
4719 /* add the name to the directory */
4720 SetDirHandle(&dir, parentptr);
4721 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4725 /* update the status in the parent vnode */
4726 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4727 #if FS_STATS_DETAILED
4728 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4729 parentptr->disk.linkCount,
4730 client->InSameNetwork);
4732 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4733 parentptr->disk.linkCount);
4734 #endif /* FS_STATS_DETAILED */
4736 targetptr->disk.linkCount++;
4737 targetptr->disk.author = client->ViceId;
4738 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4740 /* set up return status */
4741 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4742 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4744 /* convert the write locks to read locks before breaking callbacks */
4745 VVnodeWriteToRead(&errorCode, targetptr);
4746 osi_Assert(!errorCode || errorCode == VSALVAGE);
4747 VVnodeWriteToRead(&errorCode, parentptr);
4748 osi_Assert(!errorCode || errorCode == VSALVAGE);
4750 /* break call back on DirFid */
4751 BreakCallBack(client->host, DirFid, 0);
4753 * We also need to break the callback for the file that is hard-linked since part
4754 * of its status (like linkcount) is changed
4756 BreakCallBack(client->host, ExistingFid, 0);
4759 /* Write the all modified vnodes (parent, new files) and volume back */
4760 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4763 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4770 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4771 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4772 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4775 struct rx_connection *tcon;
4777 struct client *t_client = NULL; /* tmp ptr to client data */
4778 #if FS_STATS_DETAILED
4779 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4780 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4781 struct timeval elapsedTime; /* Transfer time */
4784 * Set our stats pointer, remember when the RPC operation started, and
4785 * tally the operation.
4787 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4791 FT_GetTimeOfDay(&opStartTime, 0);
4792 #endif /* FS_STATS_DETAILED */
4794 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4798 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4799 OutDirStatus, Sync);
4802 code = CallPostamble(tcon, code, thost);
4804 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4806 #if FS_STATS_DETAILED
4807 FT_GetTimeOfDay(&opStopTime, 0);
4810 (opP->numSuccesses)++;
4811 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4812 fs_stats_AddTo((opP->sumTime), elapsedTime);
4813 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4814 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4815 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4817 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4818 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4822 #endif /* FS_STATS_DETAILED */
4824 osi_auditU(acall, LinkEvent, code,
4825 AUD_ID, t_client ? t_client->ViceId : 0,
4826 AUD_FID, DirFid, AUD_STR, Name,
4827 AUD_FID, ExistingFid, AUD_END);
4834 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4835 * merged into it when possible.
4838 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4839 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4840 struct AFSFetchStatus *OutFidStatus,
4841 struct AFSFetchStatus *OutDirStatus,
4842 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4844 Vnode *parentptr = 0; /* vnode of input Directory */
4845 Vnode *targetptr = 0; /* vnode of the new file */
4846 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4847 Volume *volptr = 0; /* pointer to the volume header */
4848 Error errorCode = 0; /* error code */
4849 struct acl_accessList *newACL; /* Access list */
4850 int newACLSize; /* Size of access list */
4851 DirHandle dir; /* Handle for dir package I/O */
4852 DirHandle parentdir; /* Handle for dir package I/O */
4853 struct client *client = 0; /* pointer to client structure */
4854 afs_int32 rights, anyrights; /* rights for this and any user */
4855 struct client *t_client; /* tmp ptr to client data */
4856 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4857 struct rx_connection *tcon = rx_ConnectionOf(acall);
4860 FidZero(&parentdir);
4862 /* Get ptr to client data for user Id for logging */
4863 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4864 logHostAddr.s_addr = rxr_HostOf(tcon);
4866 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4867 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4868 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4870 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4872 if (!FileNameOK(Name)) {
4878 * Get the vnode and volume for the parent dir along with the caller's
4882 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4883 &parentwhentargetnotdir, &client, WRITE_LOCK,
4884 &rights, &anyrights))) {
4888 /* set volume synchronization information */
4889 SetVolumeSync(Sync, volptr);
4891 /* Write access to the parent directory? */
4892 #ifdef DIRCREATE_NEED_WRITE
4894 * requires w access for the user to create a directory. this
4895 * closes a loophole in the current security arrangement, since a
4896 * user with i access only can create a directory and get the
4897 * implcit a access that goes with dir ownership, and proceed to
4898 * subvert quota in the volume.
4900 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4901 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4903 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4904 #endif /* DIRCREATE_NEED_WRITE */
4907 #define EMPTYDIRBLOCKS 2
4908 /* get a new vnode and set it up */
4910 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4911 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4915 /* Update the status for the parent dir */
4916 #if FS_STATS_DETAILED
4917 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4918 parentptr->disk.linkCount + 1,
4919 client->InSameNetwork);
4921 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4922 parentptr->disk.linkCount + 1);
4923 #endif /* FS_STATS_DETAILED */
4925 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4926 osi_Assert((SetAccessList
4927 (&targetptr, &volptr, &newACL, &newACLSize,
4928 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4929 osi_Assert(parentwhentargetnotdir == 0);
4930 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4932 /* update the status for the target vnode */
4933 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4934 parentptr, volptr, 0);
4936 /* Actually create the New directory in the directory package */
4937 SetDirHandle(&dir, targetptr);
4938 osi_Assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4940 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4942 /* set up return status */
4943 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4944 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4946 /* convert the write lock to a read lock before breaking callbacks */
4947 VVnodeWriteToRead(&errorCode, parentptr);
4948 osi_Assert(!errorCode || errorCode == VSALVAGE);
4950 /* break call back on DirFid */
4951 BreakCallBack(client->host, DirFid, 0);
4953 /* Return a callback promise to caller */
4954 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4957 /* Write the all modified vnodes (parent, new files) and volume back */
4958 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4962 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4965 } /*SAFSS_MakeDir */
4969 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4970 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4971 struct AFSFetchStatus * OutFidStatus,
4972 struct AFSFetchStatus * OutDirStatus,
4973 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4976 struct rx_connection *tcon;
4978 struct client *t_client = NULL; /* tmp ptr to client data */
4979 #if FS_STATS_DETAILED
4980 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4981 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4982 struct timeval elapsedTime; /* Transfer time */
4985 * Set our stats pointer, remember when the RPC operation started, and
4986 * tally the operation.
4988 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4992 FT_GetTimeOfDay(&opStartTime, 0);
4993 #endif /* FS_STATS_DETAILED */
4994 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4998 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4999 OutDirStatus, CallBack, Sync);
5002 code = CallPostamble(tcon, code, thost);
5004 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5006 #if FS_STATS_DETAILED
5007 FT_GetTimeOfDay(&opStopTime, 0);
5010 (opP->numSuccesses)++;
5011 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5012 fs_stats_AddTo((opP->sumTime), elapsedTime);
5013 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5014 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5015 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5017 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5018 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5022 #endif /* FS_STATS_DETAILED */
5024 osi_auditU(acall, MakeDirEvent, code,
5025 AUD_ID, t_client ? t_client->ViceId : 0,
5026 AUD_FID, DirFid, AUD_STR, Name,
5027 AUD_FID, OutFid, AUD_END);
5030 } /*SRXAFS_MakeDir */
5034 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
5035 * merged into it when possible.
5038 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
5039 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
5041 Vnode *parentptr = 0; /* vnode of input Directory */
5042 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5043 Vnode *targetptr = 0; /* file to be deleted */
5044 AFSFid fileFid; /* area for Fid from the directory */
5045 Error errorCode = 0; /* error code */
5046 DirHandle dir; /* Handle for dir package I/O */
5047 Volume *volptr = 0; /* pointer to the volume header */
5048 struct client *client = 0; /* pointer to client structure */
5049 afs_int32 rights, anyrights; /* rights for this and any user */
5050 struct client *t_client; /* tmp ptr to client data */
5051 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5052 struct rx_connection *tcon = rx_ConnectionOf(acall);
5056 /* Get ptr to client data for user Id for logging */
5057 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5058 logHostAddr.s_addr = rxr_HostOf(tcon);
5060 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
5061 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
5062 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5064 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
5067 * Get the vnode and volume for the parent dir along with the caller's
5071 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
5072 &parentwhentargetnotdir, &client, WRITE_LOCK,
5073 &rights, &anyrights))) {
5077 /* set volume synchronization information */
5078 SetVolumeSync(Sync, volptr);
5080 /* Does the caller has delete (&write) access to the parent dir? */
5081 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
5085 /* Do the actual delete of the desired (empty) directory, Name */
5087 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
5092 /* Update the status for the parent dir; link count is also adjusted */
5093 #if FS_STATS_DETAILED
5094 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5095 parentptr->disk.linkCount - 1,
5096 client->InSameNetwork);
5098 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5099 parentptr->disk.linkCount - 1);
5100 #endif /* FS_STATS_DETAILED */
5102 /* Return to the caller the updated parent dir status */
5103 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
5106 * Note: it is not necessary to break the callback on fileFid, since
5107 * refcount is now 0, so no one should be able to refer to the dir
5110 DeleteFileCallBacks(&fileFid);
5112 /* convert the write lock to a read lock before breaking callbacks */
5113 VVnodeWriteToRead(&errorCode, parentptr);
5114 osi_Assert(!errorCode || errorCode == VSALVAGE);
5116 /* break call back on DirFid and fileFid */
5117 BreakCallBack(client->host, DirFid, 0);
5120 /* Write the all modified vnodes (parent, new files) and volume back */
5121 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5124 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5127 } /*SAFSS_RemoveDir */
5131 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5132 struct AFSFetchStatus * OutDirStatus,
5133 struct AFSVolSync * Sync)
5136 struct rx_connection *tcon;
5138 struct client *t_client = NULL; /* tmp ptr to client data */
5139 #if FS_STATS_DETAILED
5140 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5141 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5142 struct timeval elapsedTime; /* Transfer time */
5145 * Set our stats pointer, remember when the RPC operation started, and
5146 * tally the operation.
5148 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5152 FT_GetTimeOfDay(&opStartTime, 0);
5153 #endif /* FS_STATS_DETAILED */
5155 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5158 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5161 code = CallPostamble(tcon, code, thost);
5163 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5165 #if FS_STATS_DETAILED
5166 FT_GetTimeOfDay(&opStopTime, 0);
5169 (opP->numSuccesses)++;
5170 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5171 fs_stats_AddTo((opP->sumTime), elapsedTime);
5172 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5173 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5174 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5176 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5177 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5181 #endif /* FS_STATS_DETAILED */
5183 osi_auditU(acall, RemoveDirEvent, code,
5184 AUD_ID, t_client ? t_client->ViceId : 0,
5185 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5188 } /*SRXAFS_RemoveDir */
5192 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5193 * merged into it when possible.
5196 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5197 struct AFSVolSync *Sync)
5199 Vnode *targetptr = 0; /* vnode of input file */
5200 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5201 Error errorCode = 0; /* error code */
5202 Volume *volptr = 0; /* pointer to the volume header */
5203 struct client *client = 0; /* pointer to client structure */
5204 afs_int32 rights, anyrights; /* rights for this and any user */
5205 struct client *t_client; /* tmp ptr to client data */
5206 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5207 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5208 struct rx_connection *tcon = rx_ConnectionOf(acall);
5210 if (type != LockRead && type != LockWrite) {
5214 /* Get ptr to client data for user Id for logging */
5215 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5216 logHostAddr.s_addr = rxr_HostOf(tcon);
5218 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5219 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5220 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5222 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5225 * Get the vnode and volume for the desired file along with the caller's
5229 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5230 &parentwhentargetnotdir, &client, WRITE_LOCK,
5231 &rights, &anyrights))) {
5235 /* set volume synchronization information */
5236 SetVolumeSync(Sync, volptr);
5238 /* Handle the particular type of set locking, type */
5239 errorCode = HandleLocking(targetptr, client, rights, type);
5242 /* Write the all modified vnodes (parent, new files) and volume back */
5243 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5246 if ((errorCode == VREADONLY) && (type == LockRead))
5247 errorCode = 0; /* allow read locks on RO volumes without saving state */
5249 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5252 } /*SAFSS_SetLock */
5256 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5257 ViceLockType type, struct AFSVolSync * Sync)
5259 return SRXAFS_SetLock(acall, Fid, type, Sync);
5260 } /*SRXAFS_OldSetLock */
5264 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5265 struct AFSVolSync * Sync)
5268 struct rx_connection *tcon;
5270 struct client *t_client = NULL; /* tmp ptr to client data */
5271 #if FS_STATS_DETAILED
5272 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5273 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5274 struct timeval elapsedTime; /* Transfer time */
5277 * Set our stats pointer, remember when the RPC operation started, and
5278 * tally the operation.
5280 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5284 FT_GetTimeOfDay(&opStartTime, 0);
5285 #endif /* FS_STATS_DETAILED */
5287 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5290 code = SAFSS_SetLock(acall, Fid, type, Sync);
5293 code = CallPostamble(tcon, code, thost);
5295 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5297 #if FS_STATS_DETAILED
5298 FT_GetTimeOfDay(&opStopTime, 0);
5301 (opP->numSuccesses)++;
5302 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5303 fs_stats_AddTo((opP->sumTime), elapsedTime);
5304 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5305 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5306 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5308 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5309 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5313 #endif /* FS_STATS_DETAILED */
5315 osi_auditU(acall, SetLockEvent, code,
5316 AUD_ID, t_client ? t_client->ViceId : 0,
5317 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5319 } /*SRXAFS_SetLock */
5323 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5324 * merged into it when possible.
5327 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5328 struct AFSVolSync *Sync)
5330 Vnode *targetptr = 0; /* vnode of input file */
5331 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5332 Error errorCode = 0; /* error code */
5333 Volume *volptr = 0; /* pointer to the volume header */
5334 struct client *client = 0; /* pointer to client structure */
5335 afs_int32 rights, anyrights; /* rights for this and any user */
5336 struct client *t_client; /* tmp ptr to client data */
5337 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5338 struct rx_connection *tcon = rx_ConnectionOf(acall);
5340 /* Get ptr to client data for user Id for logging */
5341 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5342 logHostAddr.s_addr = rxr_HostOf(tcon);
5344 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5345 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5346 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5348 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5351 * Get the vnode and volume for the desired file along with the caller's
5355 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5356 &parentwhentargetnotdir, &client, WRITE_LOCK,
5357 &rights, &anyrights))) {
5358 goto Bad_ExtendLock;
5361 /* set volume synchronization information */
5362 SetVolumeSync(Sync, volptr);
5364 /* Handle the actual lock extension */
5365 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5368 /* Put back file's vnode and volume */
5369 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5372 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5373 errorCode = 0; /* under our generous policy re RO vols */
5375 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5378 } /*SAFSS_ExtendLock */
5382 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5383 struct AFSVolSync * Sync)
5385 return SRXAFS_ExtendLock(acall, Fid, Sync);
5386 } /*SRXAFS_OldExtendLock */
5390 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5391 struct AFSVolSync * Sync)
5394 struct rx_connection *tcon;
5396 struct client *t_client = NULL; /* tmp ptr to client data */
5397 #if FS_STATS_DETAILED
5398 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5399 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5400 struct timeval elapsedTime; /* Transfer time */
5403 * Set our stats pointer, remember when the RPC operation started, and
5404 * tally the operation.
5406 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5410 FT_GetTimeOfDay(&opStartTime, 0);
5411 #endif /* FS_STATS_DETAILED */
5413 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5414 goto Bad_ExtendLock;
5416 code = SAFSS_ExtendLock(acall, Fid, Sync);
5419 code = CallPostamble(tcon, code, thost);
5421 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5423 #if FS_STATS_DETAILED
5424 FT_GetTimeOfDay(&opStopTime, 0);
5427 (opP->numSuccesses)++;
5428 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5429 fs_stats_AddTo((opP->sumTime), elapsedTime);
5430 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5431 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5432 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5434 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5435 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5439 #endif /* FS_STATS_DETAILED */
5441 osi_auditU(acall, ExtendLockEvent, code,
5442 AUD_ID, t_client ? t_client->ViceId : 0,
5443 AUD_FID, Fid, AUD_END);
5446 } /*SRXAFS_ExtendLock */
5450 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5451 * merged into it when possible.
5454 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5455 struct AFSVolSync *Sync)
5457 Vnode *targetptr = 0; /* vnode of input file */
5458 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5459 Error errorCode = 0; /* error code */
5460 Volume *volptr = 0; /* pointer to the volume header */
5461 struct client *client = 0; /* pointer to client structure */
5462 afs_int32 rights, anyrights; /* rights for this and any user */
5463 struct client *t_client; /* tmp ptr to client data */
5464 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5465 struct rx_connection *tcon = rx_ConnectionOf(acall);
5467 /* Get ptr to client data for user Id for logging */
5468 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5469 logHostAddr.s_addr = rxr_HostOf(tcon);
5471 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5472 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5473 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5475 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5478 * Get the vnode and volume for the desired file along with the caller's
5482 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5483 &parentwhentargetnotdir, &client, WRITE_LOCK,
5484 &rights, &anyrights))) {
5485 goto Bad_ReleaseLock;
5488 /* set volume synchronization information */
5489 SetVolumeSync(Sync, volptr);
5491 /* Handle the actual lock release */
5492 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5493 goto Bad_ReleaseLock;
5495 /* if no more locks left, a callback would be triggered here */
5496 if (targetptr->disk.lock.lockCount <= 0) {
5497 /* convert the write lock to a read lock before breaking callbacks */
5498 VVnodeWriteToRead(&errorCode, targetptr);
5499 osi_Assert(!errorCode || errorCode == VSALVAGE);
5500 BreakCallBack(client->host, Fid, 0);
5504 /* Put back file's vnode and volume */
5505 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5508 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5509 errorCode = 0; /* under our generous policy re RO vols */
5511 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5514 } /*SAFSS_ReleaseLock */
5518 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5519 struct AFSVolSync * Sync)
5521 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5522 } /*SRXAFS_OldReleaseLock */
5526 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5527 struct AFSVolSync * Sync)
5530 struct rx_connection *tcon;
5532 struct client *t_client = NULL; /* tmp ptr to client data */
5533 #if FS_STATS_DETAILED
5534 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5535 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5536 struct timeval elapsedTime; /* Transfer time */
5539 * Set our stats pointer, remember when the RPC operation started, and
5540 * tally the operation.
5542 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5546 FT_GetTimeOfDay(&opStartTime, 0);
5547 #endif /* FS_STATS_DETAILED */
5549 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5550 goto Bad_ReleaseLock;
5552 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5555 code = CallPostamble(tcon, code, thost);
5557 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5559 #if FS_STATS_DETAILED
5560 FT_GetTimeOfDay(&opStopTime, 0);
5563 (opP->numSuccesses)++;
5564 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5565 fs_stats_AddTo((opP->sumTime), elapsedTime);
5566 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5567 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5568 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5570 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5571 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5575 #endif /* FS_STATS_DETAILED */
5577 osi_auditU(acall, ReleaseLockEvent, code,
5578 AUD_ID, t_client ? t_client->ViceId : 0,
5579 AUD_FID, Fid, AUD_END);
5582 } /*SRXAFS_ReleaseLock */
5586 SetSystemStats(struct AFSStatistics *stats)
5588 /* Fix this sometime soon.. */
5589 /* Because hey, it's not like we have a network monitoring protocol... */
5590 struct timeval time;
5592 /* this works on all system types */
5593 FT_GetTimeOfDay(&time, 0);
5594 stats->CurrentTime = time.tv_sec;
5595 } /*SetSystemStats */
5598 SetAFSStats(struct AFSStatistics *stats)
5600 extern afs_int32 StartTime, CurrentConnections;
5604 stats->CurrentMsgNumber = 0;
5605 stats->OldestMsgNumber = 0;
5606 stats->StartTime = StartTime;
5607 stats->CurrentConnections = CurrentConnections;
5608 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5609 stats->TotalFetchs =
5610 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5611 AFSCallStats.FetchStatus;
5612 stats->FetchDatas = AFSCallStats.FetchData;
5613 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5614 seconds = AFSCallStats.AccumFetchTime / 1000;
5617 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5618 stats->TotalStores =
5619 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5620 AFSCallStats.StoreStatus;
5621 stats->StoreDatas = AFSCallStats.StoreData;
5622 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5623 seconds = AFSCallStats.AccumStoreTime / 1000;
5626 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5628 stats->ProcessSize = -1; /* TODO: */
5630 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5633 h_GetWorkStats((int *)&(stats->WorkStations),
5634 (int *)&(stats->ActiveWorkStations), (int *)0,
5635 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5639 /* Get disk related information from all AFS partitions. */
5642 SetVolumeStats(struct AFSStatistics *stats)
5644 struct DiskPartition64 *part;
5647 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5648 part = part->next) {
5649 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5650 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5651 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5652 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5655 while (i < AFS_MSTATDISKS) {
5656 stats->Disks[i].TotalBlocks = -1;
5659 } /*SetVolumeStats */
5662 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5665 struct rx_connection *tcon = rx_ConnectionOf(acall);
5667 struct client *t_client = NULL; /* tmp ptr to client data */
5668 #if FS_STATS_DETAILED
5669 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5670 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5671 struct timeval elapsedTime; /* Transfer time */
5674 * Set our stats pointer, remember when the RPC operation started, and
5675 * tally the operation.
5677 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5681 FT_GetTimeOfDay(&opStartTime, 0);
5682 #endif /* FS_STATS_DETAILED */
5684 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5685 goto Bad_GetStatistics;
5687 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5689 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5691 memset(Statistics, 0, sizeof(*Statistics));
5692 SetAFSStats((struct AFSStatistics *)Statistics);
5693 SetVolumeStats((struct AFSStatistics *)Statistics);
5694 SetSystemStats((struct AFSStatistics *)Statistics);
5697 code = CallPostamble(tcon, code, thost);
5699 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5701 #if FS_STATS_DETAILED
5702 FT_GetTimeOfDay(&opStopTime, 0);
5705 (opP->numSuccesses)++;
5706 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5707 fs_stats_AddTo((opP->sumTime), elapsedTime);
5708 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5709 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5710 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5712 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5713 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5717 #endif /* FS_STATS_DETAILED */
5719 osi_auditU(acall, GetStatisticsEvent, code,
5720 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5722 } /*SRXAFS_GetStatistics */
5726 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5728 extern afs_int32 StartTime, CurrentConnections;
5731 struct rx_connection *tcon = rx_ConnectionOf(acall);
5733 struct client *t_client = NULL; /* tmp ptr to client data */
5734 struct timeval time;
5735 #if FS_STATS_DETAILED
5736 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5737 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5738 struct timeval elapsedTime; /* Transfer time */
5741 * Set our stats pointer, remember when the RPC operation started, and
5742 * tally the operation.
5744 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5748 FT_GetTimeOfDay(&opStartTime, 0);
5749 #endif /* FS_STATS_DETAILED */
5751 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5752 goto Bad_GetStatistics64;
5754 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5755 Statistics->ViceStatistics64_val =
5756 malloc(statsVersion*sizeof(afs_int64));
5757 Statistics->ViceStatistics64_len = statsVersion;
5759 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5760 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5761 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5763 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5764 AFSCallStats.TotalCalls;
5765 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5766 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5767 AFSCallStats.FetchStatus;
5768 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5769 AFSCallStats.FetchData;
5770 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5771 AFSCallStats.TotalFetchedBytes;
5772 seconds = AFSCallStats.AccumFetchTime / 1000;
5775 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5776 AFSCallStats.TotalFetchedBytes / seconds;
5777 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5778 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5779 AFSCallStats.StoreStatus;
5780 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5781 AFSCallStats.StoreData;
5782 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5783 AFSCallStats.TotalStoredBytes;
5784 seconds = AFSCallStats.AccumStoreTime / 1000;
5787 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5788 AFSCallStats.TotalStoredBytes / seconds;
5790 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5792 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5793 (afs_int32) ((long)sbrk(0) >> 10);
5796 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5797 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5799 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5803 /* this works on all system types */
5804 FT_GetTimeOfDay(&time, 0);
5805 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5807 Bad_GetStatistics64:
5808 code = CallPostamble(tcon, code, thost);
5810 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5812 #if FS_STATS_DETAILED
5813 FT_GetTimeOfDay(&opStopTime, 0);
5816 (opP->numSuccesses)++;
5817 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5818 fs_stats_AddTo((opP->sumTime), elapsedTime);
5819 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5820 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5821 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5823 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5824 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5828 #endif /* FS_STATS_DETAILED */
5830 osi_auditU(acall, GetStatisticsEvent, code,
5831 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5833 } /*SRXAFS_GetStatistics */
5836 /*------------------------------------------------------------------------
5837 * EXPORTED SRXAFS_XStatsVersion
5840 * Routine called by the server-side RPC interface to implement
5841 * pulling out the xstat version number for the File Server.
5844 * a_versionP : Ptr to the version number variable to set.
5850 * Nothing interesting.
5854 *------------------------------------------------------------------------*/
5857 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5858 { /*SRXAFS_XStatsVersion */
5860 struct client *t_client = NULL; /* tmp ptr to client data */
5861 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5862 #if FS_STATS_DETAILED
5863 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5864 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5865 struct timeval elapsedTime; /* Transfer time */
5868 * Set our stats pointer, remember when the RPC operation started, and
5869 * tally the operation.
5871 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5875 FT_GetTimeOfDay(&opStartTime, 0);
5876 #endif /* FS_STATS_DETAILED */
5878 *a_versionP = AFS_XSTAT_VERSION;
5880 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5882 #if FS_STATS_DETAILED
5883 FT_GetTimeOfDay(&opStopTime, 0);
5884 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5885 fs_stats_AddTo((opP->sumTime), elapsedTime);
5886 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5887 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5888 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5890 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5891 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5894 (opP->numSuccesses)++;
5896 #endif /* FS_STATS_DETAILED */
5898 osi_auditU(a_call, XStatsVersionEvent, 0,
5899 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5901 } /*SRXAFS_XStatsVersion */
5904 /*------------------------------------------------------------------------
5905 * PRIVATE FillPerfValues
5908 * Routine called to fill a regular performance data structure.
5911 * a_perfP : Ptr to perf structure to fill
5917 * Various collections need this info, so the guts were put in
5918 * this separate routine.
5922 *------------------------------------------------------------------------*/
5925 FillPerfValues(struct afs_PerfStats *a_perfP)
5926 { /*FillPerfValues */
5928 int dir_Buffers; /*# buffers in use by dir package */
5929 int dir_Calls; /*# read calls in dir package */
5930 int dir_IOs; /*# I/O ops in dir package */
5931 struct rx_statistics *stats;
5934 * Vnode cache section.
5936 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5937 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5938 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5939 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5940 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5941 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5942 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5943 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5944 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5945 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5946 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5947 SplitInt64(VStats.hdr_gets, hi, lo);
5948 a_perfP->vcache_H_Gets = lo;
5949 SplitInt64(VStats.hdr_loads, hi, lo);
5950 a_perfP->vcache_H_Replacements = lo;
5953 * Directory section.
5955 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5956 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5957 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5958 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5963 stats = rx_GetStatistics();
5965 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5966 a_perfP->rx_noPackets_RcvClass =
5967 (afs_int32) stats->receivePktAllocFailures;
5968 a_perfP->rx_noPackets_SendClass =
5969 (afs_int32) stats->sendPktAllocFailures;
5970 a_perfP->rx_noPackets_SpecialClass =
5971 (afs_int32) stats->specialPktAllocFailures;
5972 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5973 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5974 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5975 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5976 a_perfP->rx_noPacketBuffersOnRead =
5977 (afs_int32) stats->noPacketBuffersOnRead;
5978 a_perfP->rx_selects = (afs_int32) stats->selects;
5979 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5980 a_perfP->rx_packetsRead_RcvClass =
5981 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5982 a_perfP->rx_packetsRead_SendClass =
5983 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5984 a_perfP->rx_packetsRead_SpecialClass =
5985 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5986 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5987 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5988 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5989 a_perfP->rx_spuriousPacketsRead =
5990 (afs_int32) stats->spuriousPacketsRead;
5991 a_perfP->rx_packetsSent_RcvClass =
5992 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5993 a_perfP->rx_packetsSent_SendClass =
5994 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5995 a_perfP->rx_packetsSent_SpecialClass =
5996 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5997 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5998 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5999 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
6000 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
6001 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
6002 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
6003 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
6004 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
6005 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
6006 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
6007 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
6008 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
6009 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
6010 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
6011 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
6012 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
6013 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
6014 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
6015 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
6016 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
6018 a_perfP->host_NumHostEntries = HTs;
6019 a_perfP->host_HostBlocks = HTBlocks;
6020 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
6021 &(a_perfP->host_HostsInSameNetOrSubnet),
6022 &(a_perfP->host_HostsInDiffSubnet),
6023 &(a_perfP->host_HostsInDiffNetwork));
6024 a_perfP->host_NumClients = CEs;
6025 a_perfP->host_ClientBlocks = CEBlocks;
6027 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
6028 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
6029 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
6030 rx_FreeStatistics(&stats);
6031 } /*FillPerfValues */
6034 /*------------------------------------------------------------------------
6035 * EXPORTED SRXAFS_GetXStats
6038 * Routine called by the server-side callback RPC interface to
6039 * implement getting the given data collection from the extended
6040 * File Server statistics.
6043 * a_call : Ptr to Rx call on which this request came in.
6044 * a_clientVersionNum : Client version number.
6045 * a_opCode : Desired operation.
6046 * a_serverVersionNumP : Ptr to version number to set.
6047 * a_timeP : Ptr to time value (seconds) to set.
6048 * a_dataP : Ptr to variable array structure to return
6055 * Nothing interesting.
6059 *------------------------------------------------------------------------*/
6062 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
6063 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
6064 afs_int32 * a_timeP, AFS_CollData * a_dataP)
6065 { /*SRXAFS_GetXStats */
6067 int code; /*Return value */
6068 afs_int32 *dataBuffP; /*Ptr to data to be returned */
6069 afs_int32 dataBytes; /*Bytes in data buffer */
6070 #if FS_STATS_DETAILED
6071 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6072 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6073 struct timeval elapsedTime; /* Transfer time */
6076 * Set our stats pointer, remember when the RPC operation started, and
6077 * tally the operation.
6079 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
6083 FT_GetTimeOfDay(&opStartTime, 0);
6084 #endif /* FS_STATS_DETAILED */
6087 * Record the time of day and the server version number.
6089 *a_srvVersionNumP = AFS_XSTAT_VERSION;
6090 *a_timeP = FT_ApproxTime();
6093 * Stuff the appropriate data in there (assume victory)
6098 ("Received GetXStats call for collection %d\n",
6099 a_collectionNumber));
6103 * We're not keeping stats, so just return successfully with
6106 a_dataP->AFS_CollData_len = 0;
6107 a_dataP->AFS_CollData_val = NULL;
6110 switch (a_collectionNumber) {
6111 case AFS_XSTATSCOLL_CALL_INFO:
6113 * Pass back all the call-count-related data.
6115 * >>> We are forced to allocate a separate area in which to
6116 * >>> put this stuff in by the RPC stub generator, since it
6117 * >>> will be freed at the tail end of the server stub code.
6121 * I don't think call-level stats are being collected yet
6122 * for the File Server.
6124 dataBytes = sizeof(struct afs_Stats);
6125 dataBuffP = (afs_int32 *) malloc(dataBytes);
6126 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6127 a_dataP->AFS_CollData_len = dataBytes >> 2;
6128 a_dataP->AFS_CollData_val = dataBuffP;
6130 a_dataP->AFS_CollData_len = 0;
6131 a_dataP->AFS_CollData_val = NULL;
6135 case AFS_XSTATSCOLL_PERF_INFO:
6137 * Pass back all the regular performance-related data.
6139 * >>> We are forced to allocate a separate area in which to
6140 * >>> put this stuff in by the RPC stub generator, since it
6141 * >>> will be freed at the tail end of the server stub code.
6144 afs_perfstats.numPerfCalls++;
6145 FillPerfValues(&afs_perfstats);
6148 * Don't overwrite the spares at the end.
6151 dataBytes = sizeof(struct afs_PerfStats);
6152 dataBuffP = (afs_int32 *) malloc(dataBytes);
6153 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6154 a_dataP->AFS_CollData_len = dataBytes >> 2;
6155 a_dataP->AFS_CollData_val = dataBuffP;
6158 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6160 * Pass back the full collection of performance-related data.
6161 * We have to stuff the basic, overall numbers in, but the
6162 * detailed numbers are kept in the structure already.
6164 * >>> We are forced to allocate a separate area in which to
6165 * >>> put this stuff in by the RPC stub generator, since it
6166 * >>> will be freed at the tail end of the server stub code.
6169 afs_perfstats.numPerfCalls++;
6170 #if FS_STATS_DETAILED
6171 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6172 FillPerfValues(&afs_FullPerfStats.overall);
6175 * Don't overwrite the spares at the end.
6178 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6179 dataBuffP = (afs_int32 *) malloc(dataBytes);
6180 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6181 a_dataP->AFS_CollData_len = dataBytes >> 2;
6182 a_dataP->AFS_CollData_val = dataBuffP;
6186 case AFS_XSTATSCOLL_CBSTATS:
6187 afs_perfstats.numPerfCalls++;
6189 dataBytes = sizeof(struct cbcounters);
6190 dataBuffP = (afs_int32 *) malloc(dataBytes);
6192 extern struct cbcounters cbstuff;
6193 dataBuffP[0]=cbstuff.DeleteFiles;
6194 dataBuffP[1]=cbstuff.DeleteCallBacks;
6195 dataBuffP[2]=cbstuff.BreakCallBacks;
6196 dataBuffP[3]=cbstuff.AddCallBacks;
6197 dataBuffP[4]=cbstuff.GotSomeSpaces;
6198 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6199 dataBuffP[6]=cbstuff.nFEs;
6200 dataBuffP[7]=cbstuff.nCBs;
6201 dataBuffP[8]=cbstuff.nblks;
6202 dataBuffP[9]=cbstuff.CBsTimedOut;
6203 dataBuffP[10]=cbstuff.nbreakers;
6204 dataBuffP[11]=cbstuff.GSS1;
6205 dataBuffP[12]=cbstuff.GSS2;
6206 dataBuffP[13]=cbstuff.GSS3;
6207 dataBuffP[14]=cbstuff.GSS4;
6208 dataBuffP[15]=cbstuff.GSS5;
6211 a_dataP->AFS_CollData_len = dataBytes >> 2;
6212 a_dataP->AFS_CollData_val = dataBuffP;
6218 * Illegal collection number.
6220 a_dataP->AFS_CollData_len = 0;
6221 a_dataP->AFS_CollData_val = NULL;
6223 } /*Switch on collection number */
6225 #if FS_STATS_DETAILED
6226 FT_GetTimeOfDay(&opStopTime, 0);
6229 (opP->numSuccesses)++;
6230 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6231 fs_stats_AddTo((opP->sumTime), elapsedTime);
6232 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6233 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6234 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6236 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6237 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6241 #endif /* FS_STATS_DETAILED */
6245 } /*SRXAFS_GetXStats */
6249 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6250 struct AFSCBs *CallBackArray)
6252 afs_int32 errorCode = 0;
6254 struct client *client = 0;
6255 struct rx_connection *tcon;
6257 #if FS_STATS_DETAILED
6258 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6259 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6260 struct timeval elapsedTime; /* Transfer time */
6263 * Set our stats pointer, remember when the RPC operation started, and
6264 * tally the operation.
6267 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6271 FT_GetTimeOfDay(&opStartTime, 0);
6272 #endif /* FS_STATS_DETAILED */
6276 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6277 FidArray->AFSCBFids_len));
6280 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6282 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6283 goto Bad_GiveUpCallBacks;
6285 if (!FidArray && !CallBackArray) {
6287 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6288 (tcon->peer ? tcon->peer->host : 0)));
6289 errorCode = GetClient(tcon, &client);
6292 DeleteAllCallBacks_r(client->host, 1);
6297 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6299 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6300 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6301 (tcon->peer ? tcon->peer->host : 0)));
6303 goto Bad_GiveUpCallBacks;
6306 errorCode = GetClient(tcon, &client);
6308 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6309 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6310 DeleteCallBack(client->host, fid);
6316 Bad_GiveUpCallBacks:
6317 errorCode = CallPostamble(tcon, errorCode, thost);
6319 #if FS_STATS_DETAILED
6320 FT_GetTimeOfDay(&opStopTime, 0);
6321 if (errorCode == 0) {
6323 (opP->numSuccesses)++;
6324 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6325 fs_stats_AddTo((opP->sumTime), elapsedTime);
6326 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6327 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6328 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6330 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6331 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6335 #endif /* FS_STATS_DETAILED */
6338 } /*common_GiveUpCallBacks */
6342 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6343 struct AFSCBs * CallBackArray)
6345 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6346 } /*SRXAFS_GiveUpCallBacks */
6349 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6351 return common_GiveUpCallBacks(acall, 0, 0);
6352 } /*SRXAFS_GiveUpAllCallBacks */
6356 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6357 struct AFSVolumeInfo * avolinfo)
6359 return (VNOVOL); /* XXX Obsolete routine XXX */
6361 } /*SRXAFS_NGetVolumeInfo */
6365 * Dummy routine. Should never be called (the cache manager should only
6366 * invoke this interface when communicating with a AFS/DFS Protocol
6370 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6371 char *afs_name_p, struct AFSFid * afs_fid_p,
6372 struct AFSFetchStatus * afs_status_p,
6373 struct AFSFetchStatus * afs_dir_status_p,
6374 struct AFSCallBack * afs_callback_p,
6375 struct AFSVolSync * afs_sync_p)
6382 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6385 struct rx_connection *tcon;
6387 afs_uint32 *dataBuffP;
6388 afs_int32 dataBytes;
6391 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6392 afs_FullPerfStats.overall.fs_nGetCaps++;
6394 ViceLog(2, ("SAFS_GetCapabilties\n"));
6396 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6399 dataBytes = 1 * sizeof(afs_int32);
6400 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6401 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6402 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6404 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6406 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6407 capabilities->Capabilities_val = dataBuffP;
6410 code = CallPostamble(tcon, code, thost);
6417 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6418 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6422 afs_int32 nids, naddrs;
6423 afs_int32 *vd, *addr;
6424 Error errorCode = 0; /* return code to caller */
6425 struct client *client = 0;
6427 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6429 AFSCallStats.TotalCalls++;
6431 nids = vids->ViceIds_len; /* # of users in here */
6432 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6433 if (nids < 0 || naddrs < 0) {
6438 vd = vids->ViceIds_val;
6439 for (i = 0; i < nids; i++, vd++) {
6442 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6446 client->prfail = 2; /* Means re-eval client's cps */
6449 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6452 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6453 free(client->CPS.prlist_val);
6454 client->CPS.prlist_val = NULL;
6455 client->CPS.prlist_len = 0;
6457 ReleaseWriteLock(&client->lock);
6461 addr = addrs->IPAddrs_val;
6462 for (i = 0; i < naddrs; i++, addr++) {
6464 h_flushhostcps(*addr, htons(7001));
6468 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6470 } /*SRXAFS_FlushCPS */
6472 /* worthless hack to let CS keep running ancient software */
6474 afs_vtoi(char *aname)
6480 while ((tc = *aname++)) {
6481 if (tc > '9' || tc < '0')
6482 return 0; /* invalid name */
6490 * may get name or #, but must handle all weird cases (recognize readonly
6491 * or backup volumes by name or #
6494 CopyVolumeEntry(char *aname, struct vldbentry *ave,
6495 struct VolumeInfo *av)
6498 afs_int32 mask, whichType;
6499 afs_uint32 *serverHost, *typePtr;
6501 /* figure out what type we want if by name */
6503 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6504 whichType = BACKVOL;
6505 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6510 vol = afs_vtoi(aname);
6512 vol = ave->volumeId[whichType];
6515 * Now vol has volume # we're interested in. Next, figure out the type
6516 * of the volume by looking finding it in the vldb entry
6518 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6521 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6524 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6525 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6526 whichType = BACKVOL;
6528 return EINVAL; /* error: can't find volume in vldb entry */
6530 typePtr = &av->Type0;
6531 serverHost = &av->Server0;
6533 av->Type = whichType;
6534 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6535 if (ave->flags & VLF_RWEXISTS)
6536 typePtr[RWVOL] = ave->volumeId[RWVOL];
6537 if (ave->flags & VLF_ROEXISTS)
6538 typePtr[ROVOL] = ave->volumeId[ROVOL];
6539 if (ave->flags & VLF_BACKEXISTS)
6540 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6542 for (i = 0, j = 0; i < ave->nServers; i++) {
6543 if ((ave->serverFlags[i] & mask) == 0)
6544 continue; /* wrong volume */
6545 serverHost[j] = ave->serverNumber[i];
6548 av->ServerCount = j;
6550 serverHost[j++] = 0; /* bogus 8, but compat only now */
6555 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6557 static struct rx_connection *vlConn = 0;
6558 static int down = 0;
6559 static afs_int32 lastDownTime = 0;
6560 struct vldbentry tve;
6561 struct rx_securityClass *vlSec;
6565 vlSec = rxnull_NewClientSecurityObject();
6567 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6568 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6570 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6571 return 1; /* failure */
6574 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6576 down = 0; /* call worked */
6579 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6585 /* otherwise convert to old format vldb entry */
6586 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6596 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6597 struct VolumeInfo * avolinfo)
6600 struct rx_connection *tcon;
6602 #if FS_STATS_DETAILED
6603 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6604 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6605 struct timeval elapsedTime; /* Transfer time */
6608 * Set our stats pointer, remember when the RPC operation started, and
6609 * tally the operation.
6611 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6615 FT_GetTimeOfDay(&opStartTime, 0);
6616 #endif /* FS_STATS_DETAILED */
6617 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6618 goto Bad_GetVolumeInfo;
6621 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6623 code = TryLocalVLServer(avolid, avolinfo);
6625 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6626 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6627 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6628 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6631 code = CallPostamble(tcon, code, thost);
6633 #if FS_STATS_DETAILED
6634 FT_GetTimeOfDay(&opStopTime, 0);
6637 (opP->numSuccesses)++;
6638 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6639 fs_stats_AddTo((opP->sumTime), elapsedTime);
6640 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6641 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6642 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6644 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6645 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6649 #endif /* FS_STATS_DETAILED */
6653 } /*SRXAFS_GetVolumeInfo */
6657 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6658 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6659 char **OfflineMsg, char **Motd)
6661 Vnode *targetptr = 0; /* vnode of the new file */
6662 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6663 Error errorCode = 0; /* error code */
6664 Volume *volptr = 0; /* pointer to the volume header */
6665 struct client *client = 0; /* pointer to client entry */
6666 afs_int32 rights, anyrights; /* rights for this and any user */
6668 struct rx_connection *tcon;
6670 struct client *t_client = NULL; /* tmp ptr to client data */
6671 #if FS_STATS_DETAILED
6672 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6673 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6674 struct timeval elapsedTime; /* Transfer time */
6677 * Set our stats pointer, remember when the RPC operation started, and
6678 * tally the operation.
6681 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6685 FT_GetTimeOfDay(&opStartTime, 0);
6686 #endif /* FS_STATS_DETAILED */
6688 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6689 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6690 goto Bad_GetVolumeStatus;
6693 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6697 goto Bad_GetVolumeStatus;
6699 dummyFid.Volume = avolid, dummyFid.Vnode =
6700 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6703 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6704 &parentwhentargetnotdir, &client, READ_LOCK,
6705 &rights, &anyrights)))
6706 goto Bad_GetVolumeStatus;
6708 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6710 goto Bad_GetVolumeStatus;
6712 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6714 Bad_GetVolumeStatus:
6715 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6717 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6718 /* next is to guarantee out strings exist for stub */
6720 *Name = (char *)malloc(1);
6724 *Motd = (char *)malloc(1);
6727 if (*OfflineMsg == 0) {
6728 *OfflineMsg = (char *)malloc(1);
6731 errorCode = CallPostamble(tcon, errorCode, thost);
6733 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6735 #if FS_STATS_DETAILED
6736 FT_GetTimeOfDay(&opStopTime, 0);
6737 if (errorCode == 0) {
6739 (opP->numSuccesses)++;
6740 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6741 fs_stats_AddTo((opP->sumTime), elapsedTime);
6742 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6743 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6744 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6746 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6747 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6751 #endif /* FS_STATS_DETAILED */
6753 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6754 AUD_ID, t_client ? t_client->ViceId : 0,
6755 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6758 } /*SRXAFS_GetVolumeStatus */
6762 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6763 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6764 char *OfflineMsg, char *Motd)
6766 Vnode *targetptr = 0; /* vnode of the new file */
6767 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6768 Error errorCode = 0; /* error code */
6769 Volume *volptr = 0; /* pointer to the volume header */
6770 struct client *client = 0; /* pointer to client entry */
6771 afs_int32 rights, anyrights; /* rights for this and any user */
6773 struct rx_connection *tcon = rx_ConnectionOf(acall);
6775 struct client *t_client = NULL; /* tmp ptr to client data */
6776 #if FS_STATS_DETAILED
6777 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6778 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6779 struct timeval elapsedTime; /* Transfer time */
6782 * Set our stats pointer, remember when the RPC operation started, and
6783 * tally the operation.
6786 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6790 FT_GetTimeOfDay(&opStartTime, 0);
6791 #endif /* FS_STATS_DETAILED */
6793 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6794 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6795 goto Bad_SetVolumeStatus;
6798 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6802 goto Bad_SetVolumeStatus;
6804 dummyFid.Volume = avolid, dummyFid.Vnode =
6805 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6808 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6809 &parentwhentargetnotdir, &client, READ_LOCK,
6810 &rights, &anyrights)))
6811 goto Bad_SetVolumeStatus;
6813 if (readonlyServer) {
6814 errorCode = VREADONLY;
6815 goto Bad_SetVolumeStatus;
6817 if (VanillaUser(client)) {
6819 goto Bad_SetVolumeStatus;
6823 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6825 Bad_SetVolumeStatus:
6826 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6828 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6829 errorCode = CallPostamble(tcon, errorCode, thost);
6831 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6833 #if FS_STATS_DETAILED
6834 FT_GetTimeOfDay(&opStopTime, 0);
6835 if (errorCode == 0) {
6837 (opP->numSuccesses)++;
6838 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6839 fs_stats_AddTo((opP->sumTime), elapsedTime);
6840 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6841 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6842 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6844 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6845 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6849 #endif /* FS_STATS_DETAILED */
6851 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6852 AUD_ID, t_client ? t_client->ViceId : 0,
6853 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6855 } /*SRXAFS_SetVolumeStatus */
6857 #define DEFAULTVOLUME "root.afs"
6860 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6866 struct rx_connection *tcon;
6868 Error errorCode = 0;
6870 #if FS_STATS_DETAILED
6871 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6872 struct timeval opStartTime; /* Start time for RPC op */
6874 struct timeval opStopTime;
6875 struct timeval elapsedTime; /* Transfer time */
6879 * Set our stats pointer, remember when the RPC operation started, and
6880 * tally the operation.
6882 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6886 FT_GetTimeOfDay(&opStartTime, 0);
6887 #endif /* FS_STATS_DETAILED */
6889 return FSERR_EOPNOTSUPP;
6892 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6893 goto Bad_GetRootVolume;
6895 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6898 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6900 strcpy(temp, DEFAULTVOLUME);
6902 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6903 lockf(fd, F_LOCK, 0);
6907 len = read(fd, temp, 256);
6908 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6909 lockf(fd, F_ULOCK, 0);
6914 if (temp[len - 1] == '\n')
6918 *VolumeName = temp; /* freed by rx server-side stub */
6921 errorCode = CallPostamble(tcon, errorCode, thost);
6923 #if FS_STATS_DETAILED
6924 FT_GetTimeOfDay(&opStopTime, 0);
6925 if (errorCode == 0) {
6927 (opP->numSuccesses)++;
6928 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6929 fs_stats_AddTo((opP->sumTime), elapsedTime);
6930 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6931 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6932 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6934 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6935 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6939 #endif /* FS_STATS_DETAILED */
6944 } /*SRXAFS_GetRootVolume */
6947 /* still works because a struct CBS is the same as a struct AFSOpaque */
6949 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6950 struct AFSOpaque * Token)
6953 struct rx_connection *tcon;
6955 #if FS_STATS_DETAILED
6956 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6957 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6958 struct timeval elapsedTime; /* Transfer time */
6961 * Set our stats pointer, remember when the RPC operation started, and
6962 * tally the operation.
6964 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6968 FT_GetTimeOfDay(&opStartTime, 0);
6969 #endif /* FS_STATS_DETAILED */
6971 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6972 goto Bad_CheckToken;
6974 code = FSERR_ECONNREFUSED;
6977 code = CallPostamble(tcon, code, thost);
6979 #if FS_STATS_DETAILED
6980 FT_GetTimeOfDay(&opStopTime, 0);
6983 (opP->numSuccesses)++;
6984 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6985 fs_stats_AddTo((opP->sumTime), elapsedTime);
6986 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6987 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6988 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6990 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6991 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6995 #endif /* FS_STATS_DETAILED */
6999 } /*SRXAFS_CheckToken */
7002 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
7003 afs_uint32 * USeconds)
7006 struct rx_connection *tcon;
7009 #if FS_STATS_DETAILED
7010 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
7011 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
7012 struct timeval elapsedTime; /* Transfer time */
7015 * Set our stats pointer, remember when the RPC operation started, and
7016 * tally the operation.
7018 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
7022 FT_GetTimeOfDay(&opStartTime, 0);
7023 #endif /* FS_STATS_DETAILED */
7025 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
7029 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
7031 FT_GetTimeOfDay(&tpl, 0);
7032 *Seconds = tpl.tv_sec;
7033 *USeconds = tpl.tv_usec;
7035 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
7038 code = CallPostamble(tcon, code, thost);
7040 #if FS_STATS_DETAILED
7041 FT_GetTimeOfDay(&opStopTime, 0);
7042 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
7045 (opP->numSuccesses)++;
7046 fs_stats_AddTo((opP->sumTime), elapsedTime);
7047 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
7048 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
7049 fs_stats_TimeAssign((opP->minTime), elapsedTime);
7051 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
7052 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
7056 #endif /* FS_STATS_DETAILED */
7060 } /*SRXAFS_GetTime */
7067 * Implement a client's data fetch using Rx.
7070 * volptr : Ptr to the given volume's info.
7071 * targetptr : Pointer to the vnode involved.
7072 * Call : Ptr to the Rx call involved.
7073 * Pos : Offset within the file.
7074 * Len : Length in bytes to read; this value is bogus!
7075 * if FS_STATS_DETAILED
7076 * a_bytesToFetchP : Set to the number of bytes to be fetched from
7078 * a_bytesFetchedP : Set to the actual number of bytes fetched from
7084 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
7085 struct rx_call * Call, afs_sfsize_t Pos,
7086 afs_sfsize_t Len, afs_int32 Int64Mode,
7087 #if FS_STATS_DETAILED
7088 afs_sfsize_t * a_bytesToFetchP,
7089 afs_sfsize_t * a_bytesFetchedP
7090 #endif /* FS_STATS_DETAILED */
7093 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
7098 #else /* HAVE_PIOV */
7099 struct iovec tiov[RX_MAXIOVECS];
7101 #endif /* HAVE_PIOV */
7105 #if FS_STATS_DETAILED
7107 * Initialize the byte count arguments.
7109 (*a_bytesToFetchP) = 0;
7110 (*a_bytesFetchedP) = 0;
7111 #endif /* FS_STATS_DETAILED */
7115 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
7116 (afs_uintmax_t) Len));
7118 if (!VN_GET_INO(targetptr)) {
7119 afs_int32 zero = htonl(0);
7121 * This is used for newly created files; we simply send 0 bytes
7122 * back to make the cache manager happy...
7125 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7126 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7129 FT_GetTimeOfDay(&StartTime, 0);
7130 ihP = targetptr->handle;
7133 VTakeOffline(volptr);
7134 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7138 optSize = sendBufSize;
7139 tlen = FDH_SIZE(fdP);
7141 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7144 VTakeOffline(volptr);
7145 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7149 if (CheckLength(volptr, targetptr, tlen)) {
7151 VTakeOffline(volptr);
7158 if (Pos + Len > tlen) /* get length we should send */
7159 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7162 afs_int32 high, low;
7163 SplitOffsetOrSize(Len, high, low);
7164 osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7167 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7170 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7172 #if FS_STATS_DETAILED
7173 (*a_bytesToFetchP) = Len;
7174 #endif /* FS_STATS_DETAILED */
7176 tbuffer = AllocSendBuffer();
7177 #endif /* HAVE_PIOV */
7186 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
7187 if (nBytes != wlen) {
7189 FreeSendBuffer((struct afs_buffer *)tbuffer);
7190 VTakeOffline(volptr);
7191 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7195 nBytes = rx_Write(Call, tbuffer, wlen);
7196 #else /* HAVE_PIOV */
7197 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7203 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
7204 if (nBytes != wlen) {
7206 VTakeOffline(volptr);
7207 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7211 nBytes = rx_Writev(Call, tiov, tnio, wlen);
7212 #endif /* HAVE_PIOV */
7214 #if FS_STATS_DETAILED
7216 * Bump the number of bytes actually sent by the number from this
7219 (*a_bytesFetchedP) += nBytes;
7220 #endif /* FS_STATS_DETAILED */
7221 if (nBytes != wlen) {
7225 FreeSendBuffer((struct afs_buffer *)tbuffer);
7226 #endif /* HAVE_PIOV */
7227 err = VIsGoingOffline(volptr);
7236 FreeSendBuffer((struct afs_buffer *)tbuffer);
7237 #endif /* HAVE_PIOV */
7239 FT_GetTimeOfDay(&StopTime, 0);
7241 /* Adjust all Fetch Data related stats */
7243 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7244 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7245 AFSCallStats.AccumFetchTime +=
7246 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7247 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7249 afs_fsize_t targLen;
7250 VN_GET_LEN(targLen, targetptr);
7251 AFSCallStats.TotalFetchedBytes += targLen;
7252 AFSCallStats.FetchSize1++;
7253 if (targLen < SIZE2)
7254 AFSCallStats.FetchSize2++;
7255 else if (targLen < SIZE3)
7256 AFSCallStats.FetchSize3++;
7257 else if (targLen < SIZE4)
7258 AFSCallStats.FetchSize4++;
7260 AFSCallStats.FetchSize5++;
7265 } /*FetchData_RXStyle */
7268 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7269 afs_sfsize_t * size)
7271 #ifdef AFS_NAMEI_ENV
7273 lhp = IH_OPEN(V_linkHandle(vp));
7276 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
7280 *size = OS_SIZE(fdP->fd_fd);
7281 return (*size == -1) ? -1 : 0;
7283 struct afs_stat status;
7285 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7289 *lc = GetLinkCount(vp, &status);
7290 *size = status.st_size;
7299 * Implement a client's data store using Rx.
7302 * volptr : Ptr to the given volume's info.
7303 * targetptr : Pointer to the vnode involved.
7304 * Call : Ptr to the Rx call involved.
7305 * Pos : Offset within the file.
7306 * Len : Length in bytes to store; this value is bogus!
7307 * if FS_STATS_DETAILED
7308 * a_bytesToStoreP : Set to the number of bytes to be stored to
7310 * a_bytesStoredP : Set to the actual number of bytes stored to
7315 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7316 struct client * client, struct rx_call * Call,
7317 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7319 #if FS_STATS_DETAILED
7320 afs_sfsize_t * a_bytesToStoreP,
7321 afs_sfsize_t * a_bytesStoredP
7322 #endif /* FS_STATS_DETAILED */
7325 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7326 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7327 Error errorCode = 0; /* Returned error code to caller */
7329 char *tbuffer; /* data copying buffer */
7330 #else /* HAVE_PIOV */
7331 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7332 int tnio; /* temp for iovec size */
7333 #endif /* HAVE_PIOV */
7334 afs_sfsize_t tlen; /* temp for xfr length */
7335 Inode tinode; /* inode for I/O */
7336 afs_int32 optSize; /* optimal transfer size */
7337 afs_sfsize_t DataLength = 0; /* size of inode */
7338 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7339 afs_fsize_t NewLength; /* size after this store completes */
7340 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7341 int linkCount = 0; /* link count on inode */
7342 afs_fsize_t CoW_off, CoW_len;
7344 FdHandle_t *fdP, *origfdP = NULL;
7345 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7348 #if FS_STATS_DETAILED
7350 * Initialize the byte count arguments.
7352 (*a_bytesToStoreP) = 0;
7353 (*a_bytesStoredP) = 0;
7354 #endif /* FS_STATS_DETAILED */
7357 * We break the callbacks here so that the following signal will not
7360 BreakCallBack(client->host, Fid, 0);
7362 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7363 /* the inode should have been created in Alloc_NewVnode */
7364 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7366 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7367 Fid->Volume, Fid->Vnode, Fid->Unique,
7368 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7369 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7370 return ENOENT; /* is this proper error code? */
7373 * See if the file has several links (from other volumes). If it
7374 * does, then we have to make a copy before changing it to avoid
7375 *changing read-only clones of this dude
7378 ("StoreData_RXStyle : Opening inode %s\n",
7379 PrintInode(stmp, VN_GET_INO(targetptr))));
7380 fdP = IH_OPEN(targetptr->handle);
7383 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7385 VTakeOffline(volptr);
7386 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7390 if (CheckLength(volptr, targetptr, DataLength)) {
7392 VTakeOffline(volptr);
7396 if (linkCount != 1) {
7399 ("StoreData_RXStyle : inode %s has more than onelink\n",
7400 PrintInode(stmp, VN_GET_INO(targetptr))));
7401 /* other volumes share this data, better copy it first */
7403 /* Adjust the disk block count by the creation of the new inode.
7404 * We call the special VDiskUsage so we don't adjust the volume's
7405 * quota since we don't want to penalyze the user for afs's internal
7406 * mechanisms (i.e. copy on write overhead.) Also the right size
7407 * of the disk will be recorded...
7410 VN_GET_LEN(size, targetptr);
7411 volptr->partition->flags &= ~PART_DONTUPDATE;
7412 VSetPartitionDiskUsage(volptr->partition);
7413 volptr->partition->flags |= PART_DONTUPDATE;
7414 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7415 volptr->partition->flags &= ~PART_DONTUPDATE;
7420 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7421 CopyOnWrite_calls++;
7422 if (CoW_len == 0) CopyOnWrite_size0++;
7423 if (Pos == 0) CopyOnWrite_off0++;
7424 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7426 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7427 "off 0x0 size 0x%llx\n",
7428 afs_printable_VolumeId_u(V_id(volptr)),
7429 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7430 V_name(volptr), Pos));
7431 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7432 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7433 volptr->partition->flags &= ~PART_DONTUPDATE;
7437 volptr->partition->flags &= ~PART_DONTUPDATE;
7438 VSetPartitionDiskUsage(volptr->partition);
7439 fdP = IH_OPEN(targetptr->handle);
7442 ("StoreData : Reopen after CopyOnWrite failed\n"));
7443 FDH_REALLYCLOSE(origfdP);
7447 tinode = VN_GET_INO(targetptr);
7449 if (!VALID_INO(tinode)) {
7450 VTakeOffline(volptr);
7451 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7456 /* compute new file length */
7457 NewLength = DataLength;
7458 if (FileLength < NewLength)
7459 /* simulate truncate */
7460 NewLength = FileLength;
7461 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7462 if (Pos + Length > NewLength)
7463 NewLength = Pos + Length; /* and write */
7465 /* adjust the disk block count by the difference in the files */
7467 afs_fsize_t targSize;
7468 VN_GET_LEN(targSize, targetptr);
7469 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7472 AdjustDiskUsage(volptr, adjustSize,
7473 adjustSize - SpareComp(volptr)))) {
7475 if (origfdP) FDH_REALLYCLOSE(origfdP);
7479 /* can signal cache manager to proceed from close now */
7480 /* this bit means that the locks are set and protections are OK */
7481 rx_SetLocalStatus(Call, 1);
7483 FT_GetTimeOfDay(&StartTime, 0);
7485 optSize = sendBufSize;
7487 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7488 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7489 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7491 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7492 if (FileLength < DataLength)
7493 FDH_TRUNC(fdP, FileLength);
7494 bytesTransfered = 0;
7496 tbuffer = AllocSendBuffer();
7497 #endif /* HAVE_PIOV */
7498 /* if length == 0, the loop below isn't going to do anything, including
7499 * extend the length of the inode, which it must do, since the file system
7500 * assumes that the inode length == vnode's file length. So, we extend
7501 * the file length manually if need be. Note that if file is bigger than
7502 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7503 * do what we're going to do below.
7505 if (Length == 0 && Pos > TruncatedLength) {
7506 /* Set the file's length; we've already done an lseek to the right
7509 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
7514 errorCode = FDH_TRUNC(fdP, Pos);
7516 /* have some data to copy */
7517 #if FS_STATS_DETAILED
7518 (*a_bytesToStoreP) = Length;
7519 #endif /* FS_STATS_DETAILED */
7522 if (bytesTransfered >= Length) {
7526 tlen = Length - bytesTransfered; /* how much more to do */
7528 rlen = optSize; /* bound by buffer size */
7532 errorCode = rx_Read(Call, tbuffer, rlen);
7533 #else /* HAVE_PIOV */
7534 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7535 #endif /* HAVE_PIOV */
7536 if (errorCode <= 0) {
7540 #if FS_STATS_DETAILED
7541 (*a_bytesStoredP) += errorCode;
7542 #endif /* FS_STATS_DETAILED */
7545 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
7546 #else /* HAVE_PIOV */
7547 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
7548 #endif /* HAVE_PIOV */
7549 if (nBytes != rlen) {
7550 errorCode = VDISKFULL;
7553 bytesTransfered += rlen;
7559 FreeSendBuffer((struct afs_buffer *)tbuffer);
7560 #endif /* HAVE_PIOV */
7565 afs_sfsize_t nfSize = FDH_SIZE(fdP);
7566 osi_Assert(nfSize >= 0);
7567 /* something went wrong: adjust size and return */
7568 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7569 /* changed_newTime is tested in StoreData to detemine if we
7570 * need to update the target vnode.
7572 targetptr->changed_newTime = 1;
7573 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7574 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7575 if (origfdP) FDH_REALLYCLOSE(origfdP);
7577 /* set disk usage to be correct */
7578 VAdjustDiskUsage(&errorCode, volptr,
7579 (afs_sfsize_t) (nBlocks(nfSize) -
7580 nBlocks(NewLength)), 0);
7583 if (origfdP) { /* finish CopyOnWrite */
7584 if ( (CoW_off = Pos + Length) < NewLength) {
7585 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7586 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7587 "off 0x%llx size 0x%llx returns %d\n",
7588 afs_printable_VolumeId_u(V_id(volptr)),
7589 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7590 V_name(volptr), CoW_off, CoW_len, errorCode));
7592 FDH_REALLYCLOSE(origfdP);
7596 FT_GetTimeOfDay(&StopTime, 0);
7598 VN_SET_LEN(targetptr, NewLength);
7600 /* Update all StoreData related stats */
7602 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7603 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7604 AFSCallStats.StoreSize1++; /* Piggybacked data */
7606 afs_fsize_t targLen;
7607 VN_GET_LEN(targLen, targetptr);
7608 if (targLen < SIZE2)
7609 AFSCallStats.StoreSize2++;
7610 else if (targLen < SIZE3)
7611 AFSCallStats.StoreSize3++;
7612 else if (targLen < SIZE4)
7613 AFSCallStats.StoreSize4++;
7615 AFSCallStats.StoreSize5++;
7620 } /*StoreData_RXStyle */
7622 static int sys2et[512];
7625 init_sys_error_to_et(void)
7627 memset(&sys2et, 0, sizeof(sys2et));
7628 sys2et[EPERM] = UAEPERM;
7629 sys2et[ENOENT] = UAENOENT;
7630 sys2et[ESRCH] = UAESRCH;
7631 sys2et[EINTR] = UAEINTR;
7632 sys2et[EIO] = UAEIO;
7633 sys2et[ENXIO] = UAENXIO;
7634 sys2et[E2BIG] = UAE2BIG;
7635 sys2et[ENOEXEC] = UAENOEXEC;
7636 sys2et[EBADF] = UAEBADF;
7637 sys2et[ECHILD] = UAECHILD;
7638 sys2et[EAGAIN] = UAEAGAIN;
7639 sys2et[ENOMEM] = UAENOMEM;
7640 sys2et[EACCES] = UAEACCES;
7641 sys2et[EFAULT] = UAEFAULT;
7642 sys2et[ENOTBLK] = UAENOTBLK;
7643 sys2et[EBUSY] = UAEBUSY;
7644 sys2et[EEXIST] = UAEEXIST;
7645 sys2et[EXDEV] = UAEXDEV;
7646 sys2et[ENODEV] = UAENODEV;
7647 sys2et[ENOTDIR] = UAENOTDIR;
7648 sys2et[EISDIR] = UAEISDIR;
7649 sys2et[EINVAL] = UAEINVAL;
7650 sys2et[ENFILE] = UAENFILE;
7651 sys2et[EMFILE] = UAEMFILE;
7652 sys2et[ENOTTY] = UAENOTTY;
7653 sys2et[ETXTBSY] = UAETXTBSY;
7654 sys2et[EFBIG] = UAEFBIG;
7655 sys2et[ENOSPC] = UAENOSPC;
7656 sys2et[ESPIPE] = UAESPIPE;
7657 sys2et[EROFS] = UAEROFS;
7658 sys2et[EMLINK] = UAEMLINK;
7659 sys2et[EPIPE] = UAEPIPE;
7660 sys2et[EDOM] = UAEDOM;
7661 sys2et[ERANGE] = UAERANGE;
7662 sys2et[EDEADLK] = UAEDEADLK;
7663 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7664 sys2et[ENOLCK] = UAENOLCK;
7665 sys2et[ENOSYS] = UAENOSYS;
7666 #if (ENOTEMPTY != EEXIST)
7667 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7669 sys2et[ELOOP] = UAELOOP;
7670 #if (EWOULDBLOCK != EAGAIN)
7671 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7673 sys2et[ENOMSG] = UAENOMSG;
7674 sys2et[EIDRM] = UAEIDRM;
7675 sys2et[ECHRNG] = UAECHRNG;
7676 sys2et[EL2NSYNC] = UAEL2NSYNC;
7677 sys2et[EL3HLT] = UAEL3HLT;
7678 sys2et[EL3RST] = UAEL3RST;
7679 sys2et[ELNRNG] = UAELNRNG;
7680 sys2et[EUNATCH] = UAEUNATCH;
7681 sys2et[ENOCSI] = UAENOCSI;
7682 sys2et[EL2HLT] = UAEL2HLT;
7683 sys2et[EBADE] = UAEBADE;
7684 sys2et[EBADR] = UAEBADR;
7685 sys2et[EXFULL] = UAEXFULL;
7686 sys2et[ENOANO] = UAENOANO;
7687 sys2et[EBADRQC] = UAEBADRQC;
7688 sys2et[EBADSLT] = UAEBADSLT;
7689 sys2et[EDEADLK] = UAEDEADLK;
7690 sys2et[EBFONT] = UAEBFONT;
7691 sys2et[ENOSTR] = UAENOSTR;
7692 sys2et[ENODATA] = UAENODATA;
7693 sys2et[ETIME] = UAETIME;
7694 sys2et[ENOSR] = UAENOSR;
7695 sys2et[ENONET] = UAENONET;
7696 sys2et[ENOPKG] = UAENOPKG;
7697 sys2et[EREMOTE] = UAEREMOTE;
7698 sys2et[ENOLINK] = UAENOLINK;
7699 sys2et[EADV] = UAEADV;
7700 sys2et[ESRMNT] = UAESRMNT;
7701 sys2et[ECOMM] = UAECOMM;
7702 sys2et[EPROTO] = UAEPROTO;
7703 sys2et[EMULTIHOP] = UAEMULTIHOP;
7704 sys2et[EDOTDOT] = UAEDOTDOT;
7705 sys2et[EBADMSG] = UAEBADMSG;
7706 sys2et[EOVERFLOW] = UAEOVERFLOW;
7707 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7708 sys2et[EBADFD] = UAEBADFD;
7709 sys2et[EREMCHG] = UAEREMCHG;
7710 sys2et[ELIBACC] = UAELIBACC;
7711 sys2et[ELIBBAD] = UAELIBBAD;
7712 sys2et[ELIBSCN] = UAELIBSCN;
7713 sys2et[ELIBMAX] = UAELIBMAX;
7714 sys2et[ELIBEXEC] = UAELIBEXEC;
7715 sys2et[EILSEQ] = UAEILSEQ;
7716 sys2et[ERESTART] = UAERESTART;
7717 sys2et[ESTRPIPE] = UAESTRPIPE;
7718 sys2et[EUSERS] = UAEUSERS;
7719 sys2et[ENOTSOCK] = UAENOTSOCK;
7720 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7721 sys2et[EMSGSIZE] = UAEMSGSIZE;
7722 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7723 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7724 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7725 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7726 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7727 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7728 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7729 sys2et[EADDRINUSE] = UAEADDRINUSE;
7730 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7731 sys2et[ENETDOWN] = UAENETDOWN;
7732 sys2et[ENETUNREACH] = UAENETUNREACH;
7733 sys2et[ENETRESET] = UAENETRESET;
7734 sys2et[ECONNABORTED] = UAECONNABORTED;
7735 sys2et[ECONNRESET] = UAECONNRESET;
7736 sys2et[ENOBUFS] = UAENOBUFS;
7737 sys2et[EISCONN] = UAEISCONN;
7738 sys2et[ENOTCONN] = UAENOTCONN;
7739 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7740 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7741 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7742 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7743 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7744 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7745 sys2et[EALREADY] = UAEALREADY;
7746 sys2et[EINPROGRESS] = UAEINPROGRESS;
7747 sys2et[ESTALE] = UAESTALE;
7748 sys2et[EUCLEAN] = UAEUCLEAN;
7749 sys2et[ENOTNAM] = UAENOTNAM;
7750 sys2et[ENAVAIL] = UAENAVAIL;
7751 sys2et[EISNAM] = UAEISNAM;
7752 sys2et[EREMOTEIO] = UAEREMOTEIO;
7753 sys2et[EDQUOT] = UAEDQUOT;
7754 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7755 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7757 sys2et[EIO] = UAEIO;
7761 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7762 * - pass back the connection, client, and host from CallPreamble
7763 * - keep a ref on the client, which we don't now
7764 * - keep a hold on the host, which we already do
7765 * - pass the connection, client, and host down into SAFSS_*, and use
7766 * them instead of independently discovering them via rx_ConnectionOf
7767 * (safe) and rx_GetSpecific (not so safe)
7768 * The idea being that we decide what client and host we're going to use
7769 * when CallPreamble is called, and stay consistent throughout the call.
7770 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7774 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7776 Error errorCode = 0;
7777 struct rx_connection *tcon;
7778 struct host *tcallhost;
7779 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7781 struct client *tclient;
7782 static struct rx_securityClass *sc = 0;
7784 struct rx_connection *conn;
7787 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7788 goto Bad_CallBackRxConnAddr1;
7790 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7794 tclient = h_FindClient_r(tcon);
7797 goto Bad_CallBackRxConnAddr;
7799 thost = tclient->host;
7801 /* nothing more can be done */
7802 if ( !thost->interface )
7803 goto Bad_CallBackRxConnAddr;
7805 /* the only address is the primary interface */
7806 /* can't change when there's only 1 address, anyway */
7807 if ( thost->interface->numberOfInterfaces <= 1 )
7808 goto Bad_CallBackRxConnAddr;
7810 /* initialise a security object only once */
7812 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7814 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7816 if ( *addr == thost->interface->addr[i] ) {
7821 if ( *addr != thost->interface->addr[i] )
7822 goto Bad_CallBackRxConnAddr;
7824 conn = rx_NewConnection (thost->interface->addr[i],
7825 thost->port, 1, sc, 0);
7826 rx_SetConnDeadTime(conn, 2);
7827 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7829 errorCode = RXAFSCB_Probe(conn);
7832 if ( thost->callback_rxcon )
7833 rx_DestroyConnection(thost->callback_rxcon);
7834 thost->callback_rxcon = conn;
7836 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7837 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7838 h_ReleaseClient_r(tclient);
7839 /* The hold on thost will be released by CallPostamble */
7841 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7844 rx_DestroyConnection(conn);
7846 Bad_CallBackRxConnAddr:
7847 h_ReleaseClient_r(tclient);
7848 /* The hold on thost will be released by CallPostamble */
7852 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7853 Bad_CallBackRxConnAddr1:
7854 return errorCode; /* failure */
7858 sys_error_to_et(afs_int32 in)
7862 if (in < 0 || in > 511)
7864 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7866 if (sys2et[in] != 0)