2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
37 #undef SHARED /* XXX */
42 #include <sys/param.h>
44 #include <sys/ioctl.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
51 #ifndef AFS_LINUX20_ENV
53 #ifndef AFS_ARM_DARWIN_ENV
54 #include <netinet/if_ether.h>
59 /* included early because of name conflict on IOPEN */
60 #include <sys/inode.h>
64 #endif /* AFS_HPUX_ENV */
68 #include <afs/afs_assert.h>
71 #include <afs/afsint.h>
72 #include <afs/vldbint.h>
73 #include <afs/errors.h>
74 #include <afs/ihandle.h>
75 #include <afs/vnode.h>
76 #include <afs/volume.h>
77 #include <afs/ptclient.h>
78 #include <afs/ptuser.h>
79 #include <afs/prs_fs.h>
82 #include <rx/rx_globals.h>
84 #if ! defined(AFS_SGI_ENV) && ! defined(AFS_AIX32_ENV) && ! defined(AFS_NT40_ENV) && ! defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
87 #if !defined(AFS_NT40_ENV)
90 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
92 #include <sys/statfs.h>
93 #include <sys/lockf.h>
95 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
100 #include <afs/cellconfig.h>
101 #include <afs/keys.h>
104 #include <afs/partition.h>
105 #include "viced_prototypes.h"
108 #include "callback.h"
109 #include <afs/unified_afs.h>
110 #include <afs/audit.h>
111 #include <afs/afsutil.h>
114 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
115 extern void FidZap(DirHandle * file);
116 extern void FidZero(DirHandle * file);
118 #ifdef AFS_PTHREAD_ENV
119 pthread_mutex_t fileproc_glock_mutex;
120 #endif /* AFS_PTHREAD_ENV */
122 /* Useful local defines used by this module */
125 #define MustNOTBeDIR 1
129 #define TVS_SSTATUS 2
132 #define TVS_MKDIR 0x10
134 #define CHK_FETCH 0x10
135 #define CHK_FETCHDATA 0x10
136 #define CHK_FETCHACL 0x11
137 #define CHK_FETCHSTATUS 0x12
138 #define CHK_STOREDATA 0x00
139 #define CHK_STOREACL 0x01
140 #define CHK_STORESTATUS 0x02
142 #define OWNERREAD 0400
143 #define OWNERWRITE 0200
144 #define OWNEREXEC 0100
145 #ifdef USE_GROUP_PERMS
146 #define GROUPREAD 0040
147 #define GROUPWRITE 0020
148 #define GROUPREXEC 0010
151 /* The following errors were not defined in NT. They are given unique
152 * names here to avoid any potential collision.
154 #define FSERR_ELOOP 90
155 #define FSERR_EOPNOTSUPP 122
156 #define FSERR_ECONNREFUSED 130
158 #define NOTACTIVECALL 0
161 #define CREATE_SGUID_ADMIN_ONLY 1
163 extern struct afsconf_dir *confDir;
164 extern afs_int32 dataVersionHigh;
167 static struct AFSCallStatistics AFSCallStats;
168 #if FS_STATS_DETAILED
169 struct fs_stats_FullPerfStats afs_FullPerfStats;
170 extern int AnonymousID;
171 #endif /* FS_STATS_DETAILED */
172 #if OPENAFS_VOL_STATS
173 static const char nullString[] = "";
174 #endif /* OPENAFS_VOL_STATS */
177 afs_int32 NothingYet;
180 struct afs_FSStats afs_fsstats;
185 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
187 extern afs_int32 implicitAdminRights;
188 extern afs_int32 readonlyServer;
189 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
190 extern afs_fsize_t CopyOnWrite_maxsize;
193 * Externals used by the xstat code.
195 extern VolPkgStats VStats;
196 extern int CEs, CEBlocks;
198 extern int HTs, HTBlocks;
200 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
201 struct rx_call *Call, afs_sfsize_t Pos,
202 afs_sfsize_t Len, afs_int32 Int64Mode,
203 #if FS_STATS_DETAILED
204 afs_sfsize_t * a_bytesToFetchP,
205 afs_sfsize_t * a_bytesFetchedP
206 #endif /* FS_STATS_DETAILED */
209 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
210 struct AFSFid *Fid, struct client *client,
211 struct rx_call *Call, afs_fsize_t Pos,
212 afs_fsize_t Length, afs_fsize_t FileLength,
214 #if FS_STATS_DETAILED
215 afs_sfsize_t * a_bytesToStoreP,
216 afs_sfsize_t * a_bytesStoredP
217 #endif /* FS_STATS_DETAILED */
220 #ifdef AFS_SGI_XFS_IOPS_ENV
221 #include <afs/xfsattrs.h>
223 GetLinkCount(Volume * avp, struct stat *astat)
225 if (!strcmp("xfs", astat->st_fstype)) {
226 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
228 return astat->st_nlink;
231 #define GetLinkCount(V, S) (S)->st_nlink
235 SpareComp(Volume * avolp)
241 temp = V_maxquota(avolp);
243 /* no matter; doesn't check in this case */
247 temp = (temp * PctSpare) / 100;
258 * Set the volume synchronization parameter for this volume. If it changes,
259 * the Cache Manager knows that the volume must be purged from the stat cache.
262 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
265 /* date volume instance was created */
268 async->spare1 = avol->header->diskstuff.creationDate;
281 * Verify that the on-disk size for a vnode matches the length in the vnode
284 * @param[in] vp Volume pointer
285 * @param[in] vnp Vnode pointer
286 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
287 * and CheckLength itself will determine the on-disk size.
289 * @return operation status
290 * @retval 0 lengths match
291 * @retval nonzero Error; either the lengths do not match or there was an
292 * error determining the on-disk size. The volume should be
293 * taken offline and salvaged.
296 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
299 VN_GET_LEN(vlen, vnp);
304 fdP = IH_OPEN(vnp->handle);
306 ViceLog(0, ("CheckLength: cannot open inode for fid %lu.%lu.%lu\n",
307 afs_printable_uint32_lu(vp->hashid),
308 afs_printable_uint32_lu(Vn_id(vnp)),
309 afs_printable_uint32_lu(vnp->disk.uniquifier)));
312 alen = FDH_SIZE(fdP);
315 afs_int64 alen64 = alen;
316 ViceLog(0, ("CheckLength: cannot get size for inode for fid "
317 "%lu.%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
318 afs_printable_uint32_lu(vp->hashid),
319 afs_printable_uint32_lu(Vn_id(vnp)),
320 afs_printable_uint32_lu(vnp->disk.uniquifier),
327 afs_int64 alen64 = alen, vlen64 = vlen;
328 ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index "
329 "%" AFS_INT64_FMT ", inode %" AFS_INT64_FMT "); volume "
330 "must be salvaged\n",
331 afs_printable_uint32_lu(vp->hashid),
332 afs_printable_uint32_lu(Vn_id(vnp)),
333 afs_printable_uint32_lu(vnp->disk.uniquifier),
341 * Note that this function always returns a held host, so
342 * that CallPostamble can block without the host's disappearing.
343 * Call returns rx connection in passed in *tconn
346 CallPreamble(struct rx_call *acall, int activecall,
347 struct rx_connection **tconn, struct host **ahostp)
350 struct client *tclient;
353 char hoststr[16], hoststr2[16];
354 #ifdef AFS_PTHREAD_ENV
355 struct ubik_client *uclient;
360 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
363 *tconn = rx_ConnectionOf(acall);
367 tclient = h_FindClient_r(*tconn);
369 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
373 thost = tclient->host;
374 if (tclient->prfail == 1) { /* couldn't get the CPS */
376 h_ReleaseClient_r(tclient);
378 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
382 retry_flag = 0; /* Retry once */
384 /* Take down the old connection and re-read the key file */
386 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
387 #ifdef AFS_PTHREAD_ENV
388 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
390 /* Is it still necessary to drop this? We hit the net, we should... */
396 code = hpr_Initialize(&uclient);
399 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
402 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
405 h_ReleaseClient_r(tclient);
408 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
412 tclient->prfail = 2; /* Means re-eval client's cps */
413 h_ReleaseClient_r(tclient);
418 tclient->LastCall = thost->LastCall = FT_ApproxTime();
419 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
420 thost->ActiveCall = thost->LastCall;
423 if (thost->hostFlags & HOSTDELETED) {
425 ("Discarded a packet for deleted host %s:%d\n",
426 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
427 code = VBUSY; /* raced, so retry */
428 } else if ((thost->hostFlags & VENUSDOWN)
429 || (thost->hostFlags & HFE_LATER)) {
430 if (BreakDelayedCallBacks_r(thost)) {
432 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
433 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
434 ntohs(rxr_PortOf(*tconn))));
435 if (MultiProbeAlternateAddress_r(thost)) {
437 ("MultiProbe failed to find new address for host %s:%d\n",
438 afs_inet_ntoa_r(thost->host, hoststr),
439 ntohs(thost->port)));
443 ("MultiProbe found new address for host %s:%d\n",
444 afs_inet_ntoa_r(thost->host, hoststr),
445 ntohs(thost->port)));
446 if (BreakDelayedCallBacks_r(thost)) {
448 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
449 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
450 ntohs(rxr_PortOf(*tconn))));
459 h_ReleaseClient_r(tclient);
469 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
473 struct client *tclient;
477 tclient = h_FindClient_r(aconn);
480 thost = tclient->host;
481 if (thost->hostFlags & HERRORTRANS)
483 h_ReleaseClient_r(tclient);
486 if (ahost != thost) {
487 /* host/client recycle */
488 char hoststr[16], hoststr2[16];
489 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
491 afs_inet_ntoa_r(ahost->host, hoststr),
494 afs_inet_ntoa_r(thost->host, hoststr2),
498 /* return the reference taken in CallPreamble */
502 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
503 afs_inet_ntoa_r(thost->host, hoststr),
508 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
509 * does not decrement refcount on client->host */
514 return (translate ? sys_error_to_et(ret) : ret);
518 * Returns the volume and vnode pointers associated with file Fid; the lock
519 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
520 * are incremented and they must be eventualy released.
523 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
524 Vnode ** vptr, int lock)
527 Error local_errorCode, errorCode = -1;
528 static struct timeval restartedat = { 0, 0 };
530 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
532 if ((*volptr) == 0) {
537 #ifdef AFS_DEMAND_ATTACH_FS
543 #ifdef AFS_PTHREAD_ENV
544 static const struct timespec timeout_ts = { 0, 0 };
545 static const struct timespec * const ts = &timeout_ts;
547 static const struct timespec * const ts = NULL;
551 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
552 fid->Volume, ts, cbv);
557 if ((errorCode == VOFFLINE) && (VInit < 2)) {
558 /* The volume we want may not be attached yet because
559 * the volume initialization is not yet complete.
560 * We can do several things:
561 * 1. return -1, which will cause users to see
562 * "connection timed out". This is more or
563 * less the same as always, except that the servers
564 * may appear to bounce up and down while they
565 * are actually restarting.
566 * 2. return VBUSY which will cause clients to
567 * sleep and retry for 6.5 - 15 minutes, depending
568 * on what version of the CM they are running. If
569 * the file server takes longer than that interval
570 * to attach the desired volume, then the application
571 * will see an ENODEV or EIO. This approach has
572 * the advantage that volumes which have been attached
573 * are immediately available, it keeps the server's
574 * immediate backlog low, and the call is interruptible
575 * by the user. Users see "waiting for busy volume."
576 * 3. sleep here and retry. Some people like this approach
577 * because there is no danger of seeing errors. However,
578 * this approach only works with a bounded number of
579 * clients, since the pending queues will grow without
580 * stopping. It might be better to find a way to take
581 * this call and stick it back on a queue in order to
582 * recycle this thread for a different request.
583 * 4. Return a new error code, which new cache managers will
584 * know enough to interpret as "sleep and retry", without
585 * the upper bound of 6-15 minutes that is imposed by the
586 * VBUSY handling. Users will see "waiting for
587 * busy volume," so they know that something is
588 * happening. Old cache managers must be able to do
589 * something reasonable with this, for instance, mark the
590 * server down. Fortunately, any error code < 0
591 * will elicit that behavior. See #1.
592 * 5. Some combination of the above. I like doing #2 for 10
593 * minutes, followed by #4. 3.1b and 3.2 cache managers
594 * will be fine as long as the restart period is
595 * not longer than 6.5 minutes, otherwise they may
596 * return ENODEV to users. 3.3 cache managers will be
597 * fine for 10 minutes, then will return
598 * ETIMEDOUT. 3.4 cache managers will just wait
599 * until the call works or fails definitively.
600 * NB. The problem with 2,3,4,5 is that old clients won't
601 * fail over to an alternate read-only replica while this
602 * server is restarting. 3.4 clients will fail over right away.
604 if (restartedat.tv_sec == 0) {
605 /* I'm not really worried about when we restarted, I'm */
606 /* just worried about when the first VBUSY was returned. */
607 FT_GetTimeOfDay(&restartedat, 0);
610 afs_perfstats.fs_nBusies++;
613 return (busyonrst ? VBUSY : restarting);
616 FT_GetTimeOfDay(&now, 0);
617 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
620 afs_perfstats.fs_nBusies++;
623 return (busyonrst ? VBUSY : restarting);
629 /* allow read operations on busy volume.
630 * must check local_errorCode because demand attach fs
631 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
632 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
633 #ifdef AFS_DEMAND_ATTACH_FS
634 /* DAFS case is complicated by the fact that local_errorCode can
635 * be VBUSY in cases where the volume is truly offline */
637 /* volume is in VOL_STATE_UNATTACHED */
640 #endif /* AFS_DEMAND_ATTACH_FS */
643 } else if (errorCode)
650 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
653 if ((*vptr)->disk.uniquifier != fid->Unique) {
654 VPutVnode(&fileCode, *vptr);
655 osi_Assert(fileCode == 0);
657 return (VNOVNODE); /* return the right error code, at least */
662 static_inline afs_int32
663 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
665 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
669 * This routine returns the ACL associated with the targetptr. If the
670 * targetptr isn't a directory, we access its parent dir and get the ACL
671 * thru the parent; in such case the parent's vnode is returned in
675 SetAccessList(Vnode ** targetptr, Volume ** volume,
676 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
677 AFSFid * Fid, int Lock)
679 if ((*targetptr)->disk.type == vDirectory) {
681 *ACL = VVnodeACL(*targetptr);
682 *ACLSize = VAclSize(*targetptr);
685 osi_Assert(Fid != 0);
690 parentvnode = (*targetptr)->disk.parent;
691 VPutVnode(&errorCode, *targetptr);
695 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
698 *ACL = VVnodeACL(*parent);
699 *ACLSize = VAclSize(*parent);
700 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
702 if ((*targetptr)->disk.parent != parentvnode) {
703 VPutVnode(&errorCode, *parent);
714 /* Must not be called with H_LOCK held */
716 client_CheckRights(struct client *client, struct acl_accessList *ACL,
720 ObtainReadLock(&client->lock);
721 if (client->CPS.prlist_len > 0 && !client->deleted &&
722 client->host && !(client->host->hostFlags & HOSTDELETED))
723 acl_CheckRights(ACL, &client->CPS, rights);
724 ReleaseReadLock(&client->lock);
727 /* Must not be called with H_LOCK held */
729 client_HasAsMember(struct client *client, afs_int32 id)
733 ObtainReadLock(&client->lock);
734 if (client->CPS.prlist_len > 0 && !client->deleted &&
735 client->host && !(client->host->hostFlags & HOSTDELETED))
736 code = acl_IsAMember(id, &client->CPS);
737 ReleaseReadLock(&client->lock);
742 * Compare the directory's ACL with the user's access rights in the client
743 * connection and return the user's and everybody else's access permissions
744 * in rights and anyrights, respectively
747 GetRights(struct client *client, struct acl_accessList *ACL,
748 afs_int32 * rights, afs_int32 * anyrights)
750 extern prlist SystemAnyUserCPS;
751 afs_int32 hrights = 0;
752 #ifndef AFS_PTHREAD_ENV
756 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
757 ViceLog(0, ("CheckRights failed\n"));
762 client_CheckRights(client, ACL, rights);
764 /* wait if somebody else is already doing the getCPS call */
766 while (client->host->hostFlags & HCPS_INPROGRESS) {
767 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
768 #ifdef AFS_PTHREAD_ENV
769 CV_WAIT(&client->host->cond, &host_glock_mutex);
770 #else /* AFS_PTHREAD_ENV */
772 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
773 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
774 #endif /* AFS_PTHREAD_ENV */
777 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
780 ("CheckRights: len=%u, for host=%s:%d\n",
781 client->host->hcps.prlist_len,
782 afs_inet_ntoa_r(client->host->host, hoststr),
783 ntohs(client->host->port)));
785 acl_CheckRights(ACL, &client->host->hcps, &hrights);
787 /* Allow system:admin the rights given with the -implicit option */
788 if (client_HasAsMember(client, SystemId))
789 *rights |= implicitAdminRights;
792 *anyrights |= hrights;
799 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
800 * a System:Administrator)
803 VanillaUser(struct client *client)
805 if (client_HasAsMember(client, SystemId))
806 return (0); /* not a system administrator, then you're "vanilla" */
813 * This unusual afs_int32-parameter routine encapsulates all volume package related
814 * operations together in a single function; it's called by almost all AFS
818 GetVolumePackageWithCall(struct rx_connection *tcon, struct VCallByVol *cbv,
819 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
820 int chkforDir, Vnode ** parent, struct client **client,
821 int locktype, afs_int32 * rights, afs_int32 * anyrights)
823 struct acl_accessList *aCL; /* Internal access List */
824 int aCLSize; /* size of the access list */
825 Error errorCode = 0; /* return code to caller */
827 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
830 if (chkforDir == MustNOTBeDIR
831 && ((*targetptr)->disk.type == vDirectory))
833 else if (chkforDir == MustBeDIR
834 && ((*targetptr)->disk.type != vDirectory))
838 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
839 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
840 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
842 if (chkforDir == MustBeDIR)
843 osi_Assert((*parent) == 0);
845 if ((errorCode = GetClient(tcon, client)) != 0)
850 GetRights(*client, aCL, rights, anyrights);
851 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
852 if ((*targetptr)->disk.type != vDirectory) {
853 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
854 if ((*targetptr)->disk.owner == (*client)->ViceId)
855 (*rights) |= PRSFS_ADMINISTER;
857 (*rights) &= ~PRSFS_ADMINISTER;
859 #ifdef ADMIN_IMPLICIT_LOOKUP
860 /* admins get automatic lookup on everything */
861 if (!VanillaUser(*client))
862 (*rights) |= PRSFS_LOOKUP;
863 #endif /* ADMIN_IMPLICIT_LOOKUP */
866 } /*GetVolumePackage */
868 static_inline afs_int32
869 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
870 Vnode ** targetptr, int chkforDir, Vnode ** parent,
871 struct client **client, int locktype, afs_int32 * rights,
872 afs_int32 * anyrights)
874 return GetVolumePackageWithCall(tcon, NULL, Fid, volptr, targetptr,
875 chkforDir, parent, client, locktype,
881 * This is the opposite of GetVolumePackage(), and is always used at the end of
882 * AFS calls to put back all used vnodes and the volume in the proper order!
885 PutVolumePackageWithCall(Vnode * parentwhentargetnotdir, Vnode * targetptr,
886 Vnode * parentptr, Volume * volptr,
887 struct client **client, struct VCallByVol *cbv)
889 Error fileCode = 0; /* Error code returned by the volume package */
891 if (parentwhentargetnotdir) {
892 VPutVnode(&fileCode, parentwhentargetnotdir);
893 osi_Assert(!fileCode || (fileCode == VSALVAGE));
896 VPutVnode(&fileCode, targetptr);
897 osi_Assert(!fileCode || (fileCode == VSALVAGE));
900 VPutVnode(&fileCode, parentptr);
901 osi_Assert(!fileCode || (fileCode == VSALVAGE));
904 VPutVolumeWithCall(volptr, cbv);
909 } /*PutVolumePackage */
912 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
913 Vnode * parentptr, Volume * volptr, struct client **client)
915 PutVolumePackageWithCall(parentwhentargetnotdir, targetptr, parentptr,
916 volptr, client, NULL);
920 VolumeOwner(struct client *client, Vnode * targetptr)
922 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
925 return (client->ViceId == owner);
928 * We don't have to check for host's cps since only regular
929 * viceid are volume owners.
931 return (client_HasAsMember(client, owner));
937 VolumeRootVnode(Vnode * targetptr)
939 return ((targetptr->vnodeNumber == ROOTVNODE)
940 && (targetptr->disk.uniquifier == 1));
942 } /*VolumeRootVnode */
945 * Check if target file has the proper access permissions for the Fetch
946 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
947 * StoreStatus) related calls
949 /* this code should probably just set a "priv" flag where all the audit events
950 * are now, and only generate the audit event once at the end of the routine,
951 * thus only generating the event if all the checks succeed, but only because
952 * of the privilege XXX
955 Check_PermissionRights(Vnode * targetptr, struct client *client,
956 afs_int32 rights, int CallingRoutine,
957 AFSStoreStatus * InStatus)
960 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
961 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
962 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
964 if (CallingRoutine & CHK_FETCH) {
965 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
966 if (targetptr->disk.type == vDirectory
967 || targetptr->disk.type == vSymlink) {
968 if (!(rights & PRSFS_LOOKUP)
969 #ifdef ADMIN_IMPLICIT_LOOKUP
970 /* grant admins fetch on all directories */
971 && VanillaUser(client)
972 #endif /* ADMIN_IMPLICIT_LOOKUP */
973 && !VolumeOwner(client, targetptr))
976 /* must have read access, or be owner and have insert access */
977 if (!(rights & PRSFS_READ)
978 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
979 && (client->ViceId != AnonymousID))))
982 if (CallingRoutine == CHK_FETCHDATA
983 && targetptr->disk.type == vFile)
984 #ifdef USE_GROUP_PERMS
985 if (!OWNSp(client, targetptr)
986 && !client_HasAsMember(client, targetptr->disk.owner)) {
988 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
992 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
997 * The check with the ownership below is a kludge to allow
998 * reading of files created with no read permission. The owner
999 * of the file is always allowed to read it.
1001 if ((client->ViceId != targetptr->disk.owner)
1002 && VanillaUser(client))
1004 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
1005 modeBits) ? 0 : EACCES);
1007 } else { /* !VanillaUser(client) && !FetchData */
1009 osi_audit(PrivilegeEvent, 0, AUD_ID,
1010 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
1013 } else { /* a store operation */
1014 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1015 && (CallingRoutine != CHK_STOREACL)
1016 && (targetptr->disk.type == vFile)) {
1017 /* bypass protection checks on first store after a create
1018 * for the creator; also prevent chowns during this time
1019 * unless you are a system administrator */
1020 /****** InStatus->Owner && UnixModeBits better be SET!! */
1021 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1024 else if (VanillaUser(client))
1025 return (EPERM); /* Was EACCES */
1027 osi_audit(PrivilegeEvent, 0, AUD_ID,
1028 (client ? client->ViceId : 0), AUD_INT,
1029 CallingRoutine, AUD_END);
1032 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1033 osi_audit(PrivilegeEvent, 0, AUD_ID,
1034 (client ? client->ViceId : 0), AUD_INT,
1035 CallingRoutine, AUD_END);
1037 if (readonlyServer) {
1040 if (CallingRoutine == CHK_STOREACL) {
1041 if (!(rights & PRSFS_ADMINISTER)
1042 && !VolumeOwner(client, targetptr))
1044 } else { /* store data or status */
1045 /* watch for chowns and chgrps */
1046 if (CHOWN(InStatus, targetptr)
1047 || CHGRP(InStatus, targetptr)) {
1050 else if (VanillaUser(client))
1051 return (EPERM); /* Was EACCES */
1053 osi_audit(PrivilegeEvent, 0, AUD_ID,
1054 (client ? client->ViceId : 0), AUD_INT,
1055 CallingRoutine, AUD_END);
1057 /* must be sysadmin to set suid/sgid bits */
1058 if ((InStatus->Mask & AFS_SETMODE) &&
1060 (InStatus->UnixModeBits & 0xc00) != 0) {
1062 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1066 if (VanillaUser(client))
1069 osi_audit(PrivSetID, 0, AUD_ID,
1070 (client ? client->ViceId : 0), AUD_INT,
1071 CallingRoutine, AUD_END);
1073 if (CallingRoutine == CHK_STOREDATA) {
1076 if (!(rights & PRSFS_WRITE))
1078 /* Next thing is tricky. We want to prevent people
1079 * from writing files sans 0200 bit, but we want
1080 * creating new files with 0444 mode to work. We
1081 * don't check the 0200 bit in the "you are the owner"
1082 * path above, but here we check the bit. However, if
1083 * you're a system administrator, we ignore the 0200
1084 * bit anyway, since you may have fchowned the file,
1086 #ifdef USE_GROUP_PERMS
1087 if ((targetptr->disk.type == vFile)
1088 && VanillaUser(client)) {
1089 if (!OWNSp(client, targetptr)
1090 && !client_HasAsMember(client, targetptr->disk.owner)) {
1092 ((GROUPWRITE & targetptr->disk.modeBits)
1096 ((OWNERWRITE & targetptr->disk.modeBits)
1101 if ((targetptr->disk.type != vDirectory)
1102 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1105 if (VanillaUser(client))
1108 osi_audit(PrivilegeEvent, 0, AUD_ID,
1109 (client ? client->ViceId : 0),
1110 AUD_INT, CallingRoutine, AUD_END);
1112 } else { /* a status store */
1115 if (targetptr->disk.type == vDirectory) {
1116 if (!(rights & PRSFS_DELETE)
1117 && !(rights & PRSFS_INSERT))
1119 } else { /* a file or symlink */
1120 if (!(rights & PRSFS_WRITE))
1130 } /*Check_PermissionRights */
1134 * The Access List information is converted from its internal form in the
1135 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1136 * external form and returned back to the caller, via the AccessList
1140 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1141 struct AFSOpaque *AccessList)
1143 char *eACL; /* External access list placeholder */
1145 if (acl_Externalize_pr
1146 (hpr_IdToName, (targetptr->disk.type ==
1147 vDirectory ? VVnodeACL(targetptr) :
1148 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1151 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1152 acl_FreeExternalACL(&eACL);
1155 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1156 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1158 acl_FreeExternalACL(&eACL);
1161 } /*RXFetch_AccessList */
1165 * The Access List information is converted from its external form in the
1166 * input AccessList structure to the internal representation and copied into
1167 * the target dir's vnode storage.
1170 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1172 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1174 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1177 if ((newACL->size + 4) > VAclSize(targetptr))
1179 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1180 acl_FreeACL(&newACL);
1183 } /*RXStore_AccessList */
1186 /* In our current implementation, each successive data store (new file
1187 * data version) creates a new inode. This function creates the new
1188 * inode, copies the old inode's contents to the new one, remove the old
1189 * inode (i.e. decrement inode count -- if it's currently used the delete
1190 * will be delayed), and modify some fields (i.e. vnode's
1191 * disk.inodeNumber and cloned)
1193 #define COPYBUFFSIZE 8192
1194 #define MAXFSIZE (~(afs_fsize_t) 0)
1196 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1198 Inode ino, nearInode;
1205 int rc; /* return code */
1206 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1207 FdHandle_t *targFdP; /* Source Inode file handle */
1208 FdHandle_t *newFdP; /* Dest Inode file handle */
1210 if (targetptr->disk.type == vDirectory)
1211 DFlush(); /* just in case? */
1213 VN_GET_LEN(size, targetptr);
1221 buff = (char *)malloc(COPYBUFFSIZE);
1226 ino = VN_GET_INO(targetptr);
1227 if (!VALID_INO(ino)) {
1229 VTakeOffline(volptr);
1230 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1234 targFdP = IH_OPEN(targetptr->handle);
1235 if (targFdP == NULL) {
1238 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1239 targetptr->vnodeNumber, V_id(volptr), rc));
1241 VTakeOffline(volptr);
1245 nearInode = VN_GET_INO(targetptr);
1247 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1248 VPartitionPath(V_partition(volptr)), nearInode,
1249 V_id(volptr), targetptr->vnodeNumber,
1250 targetptr->disk.uniquifier,
1251 (int)targetptr->disk.dataVersion);
1252 if (!VALID_INO(ino)) {
1254 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1255 volptr->partition->name, V_id(volptr), errno));
1260 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1261 newFdP = IH_OPEN(newH);
1262 osi_Assert(newFdP != NULL);
1266 if (size > COPYBUFFSIZE) { /* more than a buffer */
1267 length = COPYBUFFSIZE;
1268 size -= COPYBUFFSIZE;
1273 rdlen = FDH_PREAD(targFdP, buff, length, done);
1274 if (rdlen == length) {
1275 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1279 /* Callers of this function are not prepared to recover
1280 * from error that put the filesystem in an inconsistent
1281 * state. Make sure that we force the volume off-line if
1282 * we some error other than ENOSPC - 4.29.99)
1284 * In case we are unable to write the required bytes, and the
1285 * error code indicates that the disk is full, we roll-back to
1286 * the initial state.
1288 if ((rdlen != length) || (wrlen != length)) {
1289 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1291 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1292 volptr->partition->name, V_id(volptr)));
1293 /* remove destination inode which was partially copied till now */
1294 FDH_REALLYCLOSE(newFdP);
1296 FDH_REALLYCLOSE(targFdP);
1297 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1300 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1301 rc, V_id(volptr), volptr->partition->name));
1302 VTakeOffline(volptr);
1307 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1308 * since we never do any I/O anywhere near 2^32 bytes at a
1309 * time, just case to an unsigned int for printing */
1312 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1313 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1314 (unsigned)wrlen, errno));
1315 #if defined(AFS_DEMAND_ATTACH_FS)
1316 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1318 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1320 /* Decrement this inode so salvager doesn't find it. */
1321 FDH_REALLYCLOSE(newFdP);
1323 FDH_REALLYCLOSE(targFdP);
1324 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1326 VTakeOffline(volptr);
1330 #ifndef AFS_PTHREAD_ENV
1332 #endif /* !AFS_PTHREAD_ENV */
1334 FDH_REALLYCLOSE(targFdP);
1335 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1336 V_parentId(volptr));
1338 IH_RELEASE(targetptr->handle);
1340 rc = FDH_SYNC(newFdP);
1341 osi_Assert(rc == 0);
1343 targetptr->handle = newH;
1344 VN_SET_INO(targetptr, ino);
1345 targetptr->disk.cloned = 0;
1346 /* Internal change to vnode, no user level change to volume - def 5445 */
1347 targetptr->changed_oldTime = 1;
1349 return 0; /* success */
1353 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1356 char *buff = malloc(COPYBUFFSIZE);
1361 afs_foff_t done = off;
1363 if (size > FDH_SIZE(targFdP) - off)
1364 size = FDH_SIZE(targFdP) - off;
1367 if (size > COPYBUFFSIZE) { /* more than a buffer */
1368 length = COPYBUFFSIZE;
1369 size -= COPYBUFFSIZE;
1374 rdlen = FDH_PREAD(targFdP, buff, length, done);
1375 if (rdlen == length) {
1376 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1382 if ((rdlen != length) || (wrlen != length)) {
1383 /* no error recovery, at the worst we'll have a "hole"
1395 * Common code to handle with removing the Name (file when it's called from
1396 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1397 * given directory, parentptr.
1399 int DT1 = 0, DT0 = 0;
1401 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1402 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1404 DirHandle childdir; /* Handle for dir package I/O */
1405 Error errorCode = 0;
1409 /* watch for invalid names */
1410 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1413 if (CheckLength(volptr, parentptr, -1)) {
1414 VTakeOffline_r(volptr);
1418 if (parentptr->disk.cloned) {
1419 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1420 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1422 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1428 /* check that the file is in the directory */
1429 SetDirHandle(dir, parentptr);
1430 if (Lookup(dir, Name, fileFid))
1432 fileFid->Volume = V_id(volptr);
1434 /* just-in-case check for something causing deadlock */
1435 if (fileFid->Vnode == parentptr->vnodeNumber)
1438 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1442 if (ChkForDir == MustBeDIR) {
1443 if ((*targetptr)->disk.type != vDirectory)
1445 } else if ((*targetptr)->disk.type == vDirectory)
1448 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1450 * If the uniquifiers dont match then instead of asserting
1451 * take the volume offline and return VSALVAGE
1453 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1454 VTakeOffline(volptr);
1456 ("Volume %u now offline, must be salvaged.\n",
1458 errorCode = VSALVAGE;
1462 if (ChkForDir == MustBeDIR) {
1463 SetDirHandle(&childdir, *targetptr);
1464 if (IsEmpty(&childdir) != 0)
1466 DZap((afs_int32 *) &childdir);
1468 (*targetptr)->delete = 1;
1469 } else if ((--(*targetptr)->disk.linkCount) == 0)
1470 (*targetptr)->delete = 1;
1471 if ((*targetptr)->delete) {
1472 if (VN_GET_INO(*targetptr)) {
1474 IH_REALLYCLOSE((*targetptr)->handle);
1476 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1477 V_parentId(volptr));
1478 IH_RELEASE((*targetptr)->handle);
1479 if (errorCode == -1) {
1481 ("DT: inode=%s, name=%s, errno=%d\n",
1482 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1484 if (errno != ENOENT)
1486 VTakeOffline(volptr);
1488 ("Volume %u now offline, must be salvaged.\n",
1496 VN_SET_INO(*targetptr, (Inode) 0);
1498 afs_fsize_t adjLength;
1499 VN_GET_LEN(adjLength, *targetptr);
1500 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1504 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1506 code = Delete(dir, (char *)Name);
1509 ("Error %d deleting %s\n", code,
1510 (((*targetptr)->disk.type ==
1511 Directory) ? "directory" : "file")));
1512 VTakeOffline(volptr);
1514 ("Volume %u now offline, must be salvaged.\n",
1527 * This routine updates the parent directory's status block after the
1528 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1529 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1533 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1534 int author, int linkcount,
1535 #if FS_STATS_DETAILED
1536 char a_inSameNetwork
1537 #endif /* FS_STATS_DETAILED */
1540 afs_fsize_t newlength; /* Holds new directory length */
1541 afs_fsize_t parentLength;
1543 #if FS_STATS_DETAILED
1544 Date currDate; /*Current date */
1545 int writeIdx; /*Write index to bump */
1546 int timeIdx; /*Authorship time index to bump */
1547 #endif /* FS_STATS_DETAILED */
1549 parentptr->disk.dataVersion++;
1550 newlength = (afs_fsize_t) Length(dir);
1552 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1553 * (create, symlink, link, makedir) so we need to check if we have enough space
1554 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1555 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1557 VN_GET_LEN(parentLength, parentptr);
1558 if (nBlocks(newlength) != nBlocks(parentLength)) {
1559 VAdjustDiskUsage(&errorCode, volptr,
1560 (nBlocks(newlength) - nBlocks(parentLength)),
1561 (nBlocks(newlength) - nBlocks(parentLength)));
1563 VN_SET_LEN(parentptr, newlength);
1565 #if FS_STATS_DETAILED
1567 * Update directory write stats for this volume. Note that the auth
1568 * counter is located immediately after its associated ``distance''
1571 if (a_inSameNetwork)
1572 writeIdx = VOL_STATS_SAME_NET;
1574 writeIdx = VOL_STATS_DIFF_NET;
1575 V_stat_writes(volptr, writeIdx)++;
1576 if (author != AnonymousID) {
1577 V_stat_writes(volptr, writeIdx + 1)++;
1581 * Update the volume's authorship information in response to this
1582 * directory operation. Get the current time, decide to which time
1583 * slot this operation belongs, and bump the appropriate slot.
1585 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1587 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1588 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1589 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1590 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1591 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1592 if (parentptr->disk.author == author) {
1593 V_stat_dirSameAuthor(volptr, timeIdx)++;
1595 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1597 #endif /* FS_STATS_DETAILED */
1599 parentptr->disk.author = author;
1600 parentptr->disk.linkCount = linkcount;
1601 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1602 parentptr->disk.serverModifyTime = FT_ApproxTime();
1603 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1608 * Update the target file's (or dir's) status block after the specified
1609 * operation is complete. Note that some other fields maybe updated by
1610 * the individual module.
1613 /* XXX INCOMPLETE - More attention is needed here! */
1615 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1616 struct client *client, AFSStoreStatus * InStatus,
1617 Vnode * parentptr, Volume * volptr,
1620 #if FS_STATS_DETAILED
1621 Date currDate; /*Current date */
1622 int writeIdx; /*Write index to bump */
1623 int timeIdx; /*Authorship time index to bump */
1624 #endif /* FS_STATS_DETAILED */
1626 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1627 targetptr->disk.parent = parentptr->vnodeNumber;
1628 VN_SET_LEN(targetptr, length);
1629 /* targetptr->disk.group = 0; save some cycles */
1630 targetptr->disk.modeBits = 0777;
1631 targetptr->disk.owner = client->ViceId;
1632 targetptr->disk.dataVersion = 0; /* consistent with the client */
1633 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1634 /* the inode was created in Alloc_NewVnode() */
1636 #if FS_STATS_DETAILED
1638 * Update file write stats for this volume. Note that the auth
1639 * counter is located immediately after its associated ``distance''
1642 if (client->InSameNetwork)
1643 writeIdx = VOL_STATS_SAME_NET;
1645 writeIdx = VOL_STATS_DIFF_NET;
1646 V_stat_writes(volptr, writeIdx)++;
1647 if (client->ViceId != AnonymousID) {
1648 V_stat_writes(volptr, writeIdx + 1)++;
1652 * We only count operations that DON'T involve creating new objects
1653 * (files, symlinks, directories) or simply setting status as
1654 * authorship-change operations.
1656 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1658 * Update the volume's authorship information in response to this
1659 * file operation. Get the current time, decide to which time
1660 * slot this operation belongs, and bump the appropriate slot.
1662 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1665 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1666 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1667 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1668 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1669 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1670 VOL_STATS_TIME_IDX_5);
1671 if (targetptr->disk.author == client->ViceId) {
1672 V_stat_fileSameAuthor(volptr, timeIdx)++;
1674 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1677 #endif /* FS_STATS_DETAILED */
1679 if (!(Caller & TVS_SSTATUS))
1680 targetptr->disk.author = client->ViceId;
1681 if (Caller & TVS_SDATA) {
1682 targetptr->disk.dataVersion++;
1683 if (VanillaUser(client)) {
1684 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1685 #ifdef CREATE_SGUID_ADMIN_ONLY
1686 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1690 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1691 /* store status, must explicitly request to change the date */
1692 if (InStatus->Mask & AFS_SETMODTIME)
1693 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1694 } else { /* other: date always changes, but perhaps to what is specified by caller */
1695 targetptr->disk.unixModifyTime =
1696 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1697 ClientModTime : FT_ApproxTime());
1699 if (InStatus->Mask & AFS_SETOWNER) {
1700 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1701 if (VanillaUser(client)) {
1702 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1703 #ifdef CREATE_SGUID_ADMIN_ONLY
1704 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1707 targetptr->disk.owner = InStatus->Owner;
1708 if (VolumeRootVnode(targetptr)) {
1709 Error errorCode = 0; /* what should be done with this? */
1711 V_owner(targetptr->volumePtr) = InStatus->Owner;
1712 VUpdateVolume(&errorCode, targetptr->volumePtr);
1715 if (InStatus->Mask & AFS_SETMODE) {
1716 int modebits = InStatus->UnixModeBits;
1717 #define CREATE_SGUID_ADMIN_ONLY 1
1718 #ifdef CREATE_SGUID_ADMIN_ONLY
1719 if (VanillaUser(client))
1720 modebits = modebits & 0777;
1722 if (VanillaUser(client)) {
1723 targetptr->disk.modeBits = modebits;
1725 targetptr->disk.modeBits = modebits;
1728 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1729 CHK_STOREDATA, AUD_END);
1733 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1734 CHK_STORESTATUS, AUD_END);
1741 targetptr->disk.serverModifyTime = FT_ApproxTime();
1742 if (InStatus->Mask & AFS_SETGROUP)
1743 targetptr->disk.group = InStatus->Group;
1744 /* vnode changed : to be written back by VPutVnode */
1745 targetptr->changed_newTime = 1;
1747 } /*Update_TargetVnodeStatus */
1751 * Fills the CallBack structure with the expiration time and type of callback
1752 * structure. Warning: this function is currently incomplete.
1755 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1757 /* CallBackTime could not be 0 */
1758 if (CallBackTime == 0) {
1759 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1760 CallBack->ExpirationTime = 0;
1762 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1763 CallBack->CallBackVersion = CALLBACK_VERSION;
1764 CallBack->CallBackType = CB_SHARED; /* The default for now */
1766 } /*SetCallBackStruct */
1770 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1771 * allocation; if some error occured (exceeded volume quota or partition
1772 * was full, or whatever), it frees the space back and returns the code.
1773 * We usually pre-adjust the volume space to make sure that there's
1774 * enough space before consuming some.
1777 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1778 afs_sfsize_t checkLength)
1783 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1785 VAdjustDiskUsage(&nc, volptr, -length, 0);
1786 if (rc == VOVERQUOTA) {
1788 ("Volume %u (%s) is full\n", V_id(volptr),
1792 if (rc == VDISKFULL) {
1794 ("Partition %s that contains volume %u is full\n",
1795 volptr->partition->name, V_id(volptr)));
1798 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1803 } /*AdjustDiskUsage */
1806 * Common code that handles the creation of a new file (SAFS_CreateFile and
1807 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1810 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1811 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1812 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1814 Error errorCode = 0; /* Error code returned back */
1817 Inode nearInode; /* hint for inode allocation in solaris */
1821 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1822 BlocksPreallocatedForVnode))) {
1824 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1825 (afs_intmax_t) BlocksPreallocatedForVnode));
1829 if (CheckLength(volptr, parentptr, -1)) {
1830 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1831 VTakeOffline_r(volptr);
1835 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1836 if (errorCode != 0) {
1837 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1840 OutFid->Volume = V_id(volptr);
1841 OutFid->Vnode = (*targetptr)->vnodeNumber;
1842 OutFid->Unique = (*targetptr)->disk.uniquifier;
1844 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1846 /* create the inode now itself */
1848 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1849 VPartitionPath(V_partition(volptr)), nearInode,
1850 V_id(volptr), (*targetptr)->vnodeNumber,
1851 (*targetptr)->disk.uniquifier, 1);
1853 /* error in creating inode */
1854 if (!VALID_INO(inode)) {
1856 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1857 (*targetptr)->volumePtr->header->diskstuff.id,
1858 (*targetptr)->vnodeNumber, errno));
1859 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1860 (*targetptr)->delete = 1; /* delete vnode */
1863 VN_SET_INO(*targetptr, inode);
1864 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1866 /* copy group from parent dir */
1867 (*targetptr)->disk.group = parentptr->disk.group;
1869 if (parentptr->disk.cloned) {
1870 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1871 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1872 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1873 /* delete the vnode previously allocated */
1874 (*targetptr)->delete = 1;
1875 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1876 IH_REALLYCLOSE((*targetptr)->handle);
1877 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1879 ("Alloc_NewVnode: partition %s idec %s failed\n",
1880 volptr->partition->name, PrintInode(stmp, inode)));
1881 IH_RELEASE((*targetptr)->handle);
1887 /* add the name to the directory */
1888 SetDirHandle(dir, parentptr);
1889 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1890 (*targetptr)->delete = 1;
1891 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1892 IH_REALLYCLOSE((*targetptr)->handle);
1893 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1895 ("Alloc_NewVnode: partition %s idec %s failed\n",
1896 volptr->partition->name, PrintInode(stmp, inode)));
1897 IH_RELEASE((*targetptr)->handle);
1903 } /*Alloc_NewVnode */
1907 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1911 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1913 int Time; /* Used for time */
1914 int writeVnode = targetptr->changed_oldTime; /* save original status */
1916 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1917 Time = FT_ApproxTime();
1918 switch (LockingType) {
1921 if (Time > targetptr->disk.lock.lockTime)
1922 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1924 Time += AFS_LOCKWAIT;
1925 if (LockingType == LockRead) {
1926 if ( !(rights & PRSFS_LOCK) &&
1927 !(rights & PRSFS_WRITE) &&
1928 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1931 if (targetptr->disk.lock.lockCount >= 0) {
1932 ++(targetptr->disk.lock.lockCount);
1933 targetptr->disk.lock.lockTime = Time;
1936 } else if (LockingType == LockWrite) {
1937 if ( !(rights & PRSFS_WRITE) &&
1938 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1941 if (targetptr->disk.lock.lockCount == 0) {
1942 targetptr->disk.lock.lockCount = -1;
1943 targetptr->disk.lock.lockTime = Time;
1949 Time += AFS_LOCKWAIT;
1950 if (targetptr->disk.lock.lockCount != 0)
1951 targetptr->disk.lock.lockTime = Time;
1956 if ((--targetptr->disk.lock.lockCount) <= 0)
1957 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1961 targetptr->changed_oldTime = writeVnode; /* restore old status */
1962 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1965 } /*HandleLocking */
1967 /* 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. */
1970 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1974 if (!(rights & Prfs_Mode))
1976 if ((targetptr->disk.type != vDirectory)
1977 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1983 * If some flags (i.e. min or max quota) are set, the volume's in disk
1984 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1985 * update, if applicable.
1988 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1989 char *Name, char *OfflineMsg, char *Motd)
1991 Error errorCode = 0;
1993 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1994 V_minquota(volptr) = StoreVolStatus->MinQuota;
1995 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1996 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1997 if (strlen(OfflineMsg) > 0) {
1998 strcpy(V_offlineMessage(volptr), OfflineMsg);
2000 if (strlen(Name) > 0) {
2001 strcpy(V_name(volptr), Name);
2003 #if OPENAFS_VOL_STATS
2005 * We don't overwrite the motd field, since it's now being used
2009 if (strlen(Motd) > 0) {
2010 strcpy(V_motd(volptr), Motd);
2012 #endif /* FS_STATS_DETAILED */
2013 VUpdateVolume(&errorCode, volptr);
2016 } /*RXUpdate_VolumeStatus */
2020 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2021 char **motd, Volume * volptr)
2025 status->Vid = V_id(volptr);
2026 status->ParentId = V_parentId(volptr);
2027 status->Online = V_inUse(volptr);
2028 status->InService = V_inService(volptr);
2029 status->Blessed = V_blessed(volptr);
2030 status->NeedsSalvage = V_needsSalvaged(volptr);
2031 if (VolumeWriteable(volptr))
2032 status->Type = ReadWrite;
2034 status->Type = ReadOnly;
2035 status->MinQuota = V_minquota(volptr);
2036 status->MaxQuota = V_maxquota(volptr);
2037 status->BlocksInUse = V_diskused(volptr);
2038 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
2039 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
2041 /* now allocate and copy these things; they're freed by the RXGEN stub */
2042 temp = strlen(V_name(volptr)) + 1;
2043 *name = malloc(temp);
2045 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2046 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2048 strcpy(*name, V_name(volptr));
2049 temp = strlen(V_offlineMessage(volptr)) + 1;
2050 *offMsg = malloc(temp);
2052 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2053 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2055 strcpy(*offMsg, V_offlineMessage(volptr));
2056 #if OPENAFS_VOL_STATS
2059 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2060 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2062 strcpy(*motd, nullString);
2064 temp = strlen(V_motd(volptr)) + 1;
2065 *motd = malloc(temp);
2067 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
2068 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
2070 strcpy(*motd, V_motd(volptr));
2071 #endif /* FS_STATS_DETAILED */
2073 } /*RXGetVolumeStatus */
2077 FileNameOK(char *aname)
2082 /* watch for @sys on the right */
2083 if (strcmp(aname + i - 4, "@sys") == 0)
2086 while ((tc = *aname++)) {
2088 return 0; /* very bad character to encounter */
2090 return 1; /* file name is ok */
2096 * This variant of symlink is expressly to support the AFS/DFS translator
2097 * and is not supported by the AFS fileserver. We just return EINVAL.
2098 * The cache manager should not generate this call to an AFS cache manager.
2101 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2102 char *LinkContents, struct AFSStoreStatus *InStatus,
2103 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2104 struct AFSFetchStatus *OutDirStatus,
2105 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2111 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2112 struct FsCmdInputs * Inputs,
2113 struct FsCmdOutputs * Outputs)
2117 switch (Inputs->command) {
2121 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2122 Inputs->command, Outputs->code));
2127 static struct afs_buffer {
2128 struct afs_buffer *next;
2129 } *freeBufferList = 0;
2130 static int afs_buffersAlloced = 0;
2133 FreeSendBuffer(struct afs_buffer *adata)
2136 afs_buffersAlloced--;
2137 adata->next = freeBufferList;
2138 freeBufferList = adata;
2142 } /*FreeSendBuffer */
2144 /* allocate space for sender */
2146 AllocSendBuffer(void)
2148 struct afs_buffer *tp;
2151 afs_buffersAlloced++;
2152 if (!freeBufferList) {
2155 tmp = malloc(sendBufSize);
2157 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2158 osi_Panic("Failed malloc in AllocSendBuffer\n");
2162 tp = freeBufferList;
2163 freeBufferList = tp->next;
2167 } /*AllocSendBuffer */
2168 #endif /* HAVE_PIOV */
2171 * This routine returns the status info associated with the targetptr vnode
2172 * in the AFSFetchStatus structure. Some of the newer fields, such as
2173 * SegSize and Group are not yet implemented
2177 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2178 afs_int32 anyrights, Vnode * parentptr)
2180 /* initialize return status from a vnode */
2181 status->InterfaceVersion = 1;
2182 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2183 status->errorCode = 0;
2184 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2185 if (targetptr->disk.type == vFile)
2186 status->FileType = File;
2187 else if (targetptr->disk.type == vDirectory)
2188 status->FileType = Directory;
2189 else if (targetptr->disk.type == vSymlink)
2190 status->FileType = SymbolicLink;
2192 status->FileType = Invalid; /*invalid type field */
2193 status->LinkCount = targetptr->disk.linkCount;
2195 afs_fsize_t targetLen;
2196 VN_GET_LEN(targetLen, targetptr);
2197 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2199 status->DataVersion = targetptr->disk.dataVersion;
2200 status->Author = targetptr->disk.author;
2201 status->Owner = targetptr->disk.owner;
2202 status->CallerAccess = rights;
2203 status->AnonymousAccess = anyrights;
2204 status->UnixModeBits = targetptr->disk.modeBits;
2205 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2206 status->ParentVnode =
2207 (status->FileType ==
2208 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2209 status->ParentUnique =
2210 (status->FileType ==
2211 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2212 status->ServerModTime = targetptr->disk.serverModifyTime;
2213 status->Group = targetptr->disk.group;
2214 status->lockCount = targetptr->disk.lock.lockCount;
2215 status->errorCode = 0;
2221 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2222 afs_sfsize_t Pos, afs_sfsize_t Len,
2223 struct AFSFetchStatus *OutStatus,
2224 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2227 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2228 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2229 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2230 Error errorCode = 0; /* return code to caller */
2231 Error fileCode = 0; /* return code from vol package */
2232 Volume *volptr = 0; /* pointer to the volume */
2233 struct client *client = 0; /* pointer to the client data */
2234 struct rx_connection *tcon; /* the connection we're part of */
2236 afs_int32 rights, anyrights; /* rights for this and any user */
2237 struct client *t_client = NULL; /* tmp ptr to client data */
2238 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2239 struct VCallByVol tcbv, *cbv = NULL;
2240 #if FS_STATS_DETAILED
2241 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2242 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2243 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2244 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2245 struct timeval elapsedTime; /* Transfer time */
2246 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2247 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2248 int readIdx; /* Index of read stats array to bump */
2249 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2252 * Set our stats pointers, remember when the RPC operation started, and
2253 * tally the operation.
2255 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2256 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2260 FT_GetTimeOfDay(&opStartTime, 0);
2261 #endif /* FS_STATS_DETAILED */
2264 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2267 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2269 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2272 /* Get ptr to client data for user Id for logging */
2273 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2274 logHostAddr.s_addr = rxr_HostOf(tcon);
2276 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2277 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2278 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2280 queue_NodeInit(&tcbv);
2285 * Get volume/vnode for the fetched file; caller's access rights to
2286 * it are also returned
2289 GetVolumePackageWithCall(tcon, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2290 &parentwhentargetnotdir, &client, READ_LOCK,
2291 &rights, &anyrights)))
2294 SetVolumeSync(Sync, volptr);
2296 #if FS_STATS_DETAILED
2298 * Remember that another read operation was performed.
2301 if (client->InSameNetwork)
2302 readIdx = VOL_STATS_SAME_NET;
2304 readIdx = VOL_STATS_DIFF_NET;
2305 V_stat_reads(volptr, readIdx)++;
2306 if (client->ViceId != AnonymousID) {
2307 V_stat_reads(volptr, readIdx + 1)++;
2310 #endif /* FS_STATS_DETAILED */
2311 /* Check whether the caller has permission access to fetch the data */
2313 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2317 * Drop the read lock on the parent directory after saving the parent
2318 * vnode information we need to pass to GetStatus
2320 if (parentwhentargetnotdir != NULL) {
2321 tparentwhentargetnotdir = *parentwhentargetnotdir;
2322 VPutVnode(&fileCode, parentwhentargetnotdir);
2323 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2324 parentwhentargetnotdir = NULL;
2326 #if FS_STATS_DETAILED
2328 * Remember when the data transfer started.
2330 FT_GetTimeOfDay(&xferStartTime, 0);
2331 #endif /* FS_STATS_DETAILED */
2333 /* actually do the data transfer */
2334 #if FS_STATS_DETAILED
2336 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2337 &bytesToXfer, &bytesXferred);
2340 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2342 #endif /* FS_STATS_DETAILED */
2344 #if FS_STATS_DETAILED
2346 * At this point, the data transfer is done, for good or ill. Remember
2347 * when the transfer ended, bump the number of successes/failures, and
2348 * integrate the transfer size and elapsed time into the stats. If the
2349 * operation failed, we jump to the appropriate point.
2351 FT_GetTimeOfDay(&xferStopTime, 0);
2353 (xferP->numXfers)++;
2355 (xferP->numSuccesses)++;
2358 * Bump the xfer sum by the number of bytes actually sent, NOT the
2361 tot_bytesXferred += bytesXferred;
2362 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2363 tot_bytesXferred &= 0x3FF;
2364 if (bytesXferred < xferP->minBytes)
2365 xferP->minBytes = bytesXferred;
2366 if (bytesXferred > xferP->maxBytes)
2367 xferP->maxBytes = bytesXferred;
2370 * Tally the size of the object. Note: we tally the actual size,
2371 * NOT the number of bytes that made it out over the wire.
2373 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2374 (xferP->count[0])++;
2375 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2376 (xferP->count[1])++;
2377 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2378 (xferP->count[2])++;
2379 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2380 (xferP->count[3])++;
2381 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2382 (xferP->count[4])++;
2383 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2384 (xferP->count[5])++;
2385 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2386 (xferP->count[6])++;
2387 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2388 (xferP->count[7])++;
2390 (xferP->count[8])++;
2392 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2393 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2394 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2395 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2396 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2398 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2399 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2404 * Finally, go off to tell our caller the bad news in case the
2409 #endif /* FS_STATS_DETAILED */
2411 /* write back the OutStatus from the target vnode */
2412 GetStatus(targetptr, OutStatus, rights, anyrights,
2413 &tparentwhentargetnotdir);
2415 /* if a r/w volume, promise a callback to the caller */
2416 if (VolumeWriteable(volptr))
2417 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2419 struct AFSFid myFid;
2420 memset(&myFid, 0, sizeof(struct AFSFid));
2421 myFid.Volume = Fid->Volume;
2422 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2426 /* Update and store volume/vnode and parent vnodes back */
2427 (void)PutVolumePackageWithCall(parentwhentargetnotdir, targetptr,
2428 (Vnode *) 0, volptr, &client, cbv);
2429 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2430 errorCode = CallPostamble(tcon, errorCode, thost);
2432 #if FS_STATS_DETAILED
2433 FT_GetTimeOfDay(&opStopTime, 0);
2434 if (errorCode == 0) {
2436 (opP->numSuccesses)++;
2437 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2438 fs_stats_AddTo((opP->sumTime), elapsedTime);
2439 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2440 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2441 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2443 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2444 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2448 #endif /* FS_STATS_DETAILED */
2450 osi_auditU(acall, FetchDataEvent, errorCode,
2451 AUD_ID, t_client ? t_client->ViceId : 0,
2452 AUD_FID, Fid, AUD_END);
2455 } /*SRXAFS_FetchData */
2458 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2459 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2460 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2462 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2467 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2468 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2469 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2472 afs_sfsize_t tPos, tLen;
2474 tPos = (afs_sfsize_t) Pos;
2475 tLen = (afs_sfsize_t) Len;
2478 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2484 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2485 struct AFSOpaque * AccessList,
2486 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2488 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2489 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2490 Error errorCode = 0; /* return error code to caller */
2491 Volume *volptr = 0; /* pointer to the volume */
2492 struct client *client = 0; /* pointer to the client data */
2493 afs_int32 rights, anyrights; /* rights for this and any user */
2494 struct rx_connection *tcon = rx_ConnectionOf(acall);
2496 struct client *t_client = NULL; /* tmp ptr to client data */
2497 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2498 #if FS_STATS_DETAILED
2499 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2500 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2501 struct timeval elapsedTime; /* Transfer time */
2504 * Set our stats pointer, remember when the RPC operation started, and
2505 * tally the operation.
2507 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2511 FT_GetTimeOfDay(&opStartTime, 0);
2512 #endif /* FS_STATS_DETAILED */
2515 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2518 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2520 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2523 /* Get ptr to client data for user Id for logging */
2524 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2525 logHostAddr.s_addr = rxr_HostOf(tcon);
2527 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2528 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2529 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2531 AccessList->AFSOpaque_len = 0;
2532 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2533 if (!AccessList->AFSOpaque_val) {
2534 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2535 osi_Panic("Failed malloc in SRXAFS_FetchACL\n");
2539 * Get volume/vnode for the fetched file; caller's access rights to it
2543 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2544 &parentwhentargetnotdir, &client, READ_LOCK,
2545 &rights, &anyrights)))
2548 SetVolumeSync(Sync, volptr);
2550 /* Check whether we have permission to fetch the ACL */
2552 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2555 /* Get the Access List from the dir's vnode */
2557 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2560 /* Get OutStatus back From the target Vnode */
2561 GetStatus(targetptr, OutStatus, rights, anyrights,
2562 parentwhentargetnotdir);
2565 /* Update and store volume/vnode and parent vnodes back */
2566 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2569 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2570 AccessList->AFSOpaque_val));
2571 errorCode = CallPostamble(tcon, errorCode, thost);
2573 #if FS_STATS_DETAILED
2574 FT_GetTimeOfDay(&opStopTime, 0);
2575 if (errorCode == 0) {
2577 (opP->numSuccesses)++;
2578 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2579 fs_stats_AddTo((opP->sumTime), elapsedTime);
2580 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2581 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2582 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2584 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2585 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2589 #endif /* FS_STATS_DETAILED */
2591 osi_auditU(acall, FetchACLEvent, errorCode,
2592 AUD_ID, t_client ? t_client->ViceId : 0,
2594 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2596 } /*SRXAFS_FetchACL */
2600 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2601 * merged into it when possible.
2605 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2606 struct AFSFetchStatus *OutStatus,
2607 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2609 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2610 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2611 Error errorCode = 0; /* return code to caller */
2612 Volume *volptr = 0; /* pointer to the volume */
2613 struct client *client = 0; /* pointer to the client data */
2614 afs_int32 rights, anyrights; /* rights for this and any user */
2615 struct client *t_client = NULL; /* tmp ptr to client data */
2616 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2617 struct rx_connection *tcon = rx_ConnectionOf(acall);
2619 /* Get ptr to client data for user Id for logging */
2620 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2621 logHostAddr.s_addr = rxr_HostOf(tcon);
2623 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2624 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2625 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2627 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2630 * Get volume/vnode for the fetched file; caller's rights to it are
2634 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2635 &parentwhentargetnotdir, &client, READ_LOCK,
2636 &rights, &anyrights)))
2637 goto Bad_FetchStatus;
2639 /* set volume synchronization information */
2640 SetVolumeSync(Sync, volptr);
2642 /* Are we allowed to fetch Fid's status? */
2643 if (targetptr->disk.type != vDirectory) {
2645 Check_PermissionRights(targetptr, client, rights,
2646 CHK_FETCHSTATUS, 0))) {
2647 if (rx_GetCallAbortCode(acall) == errorCode)
2648 rx_SetCallAbortCode(acall, 0);
2649 goto Bad_FetchStatus;
2653 /* set OutStatus From the Fid */
2654 GetStatus(targetptr, OutStatus, rights, anyrights,
2655 parentwhentargetnotdir);
2657 /* If a r/w volume, also set the CallBack state */
2658 if (VolumeWriteable(volptr))
2659 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2661 struct AFSFid myFid;
2662 memset(&myFid, 0, sizeof(struct AFSFid));
2663 myFid.Volume = Fid->Volume;
2664 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2668 /* Update and store volume/vnode and parent vnodes back */
2669 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2671 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2674 } /*SAFSS_FetchStatus */
2678 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2679 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2680 struct AFSVolSync * Sync)
2684 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2685 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2686 Error errorCode = 0; /* return code to caller */
2687 Volume *volptr = 0; /* pointer to the volume */
2688 struct client *client = 0; /* pointer to the client data */
2689 afs_int32 rights, anyrights; /* rights for this and any user */
2690 struct AFSFid *tfid; /* file id we're dealing with now */
2691 struct rx_connection *tcon = rx_ConnectionOf(acall);
2693 struct client *t_client = NULL; /* tmp pointer to the client data */
2694 #if FS_STATS_DETAILED
2695 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2696 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2697 struct timeval elapsedTime; /* Transfer time */
2700 * Set our stats pointer, remember when the RPC operation started, and
2701 * tally the operation.
2703 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2707 FT_GetTimeOfDay(&opStartTime, 0);
2708 #endif /* FS_STATS_DETAILED */
2710 ViceLog(1, ("SAFS_BulkStatus\n"));
2712 AFSCallStats.TotalCalls++;
2714 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2715 if (nfiles <= 0) { /* Sanity check */
2717 goto Audit_and_Return;
2720 /* allocate space for return output parameters */
2721 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2722 malloc(nfiles * sizeof(struct AFSFetchStatus));
2723 if (!OutStats->AFSBulkStats_val) {
2724 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2725 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2727 OutStats->AFSBulkStats_len = nfiles;
2728 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2729 malloc(nfiles * sizeof(struct AFSCallBack));
2730 if (!CallBacks->AFSCBs_val) {
2731 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2732 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2734 CallBacks->AFSCBs_len = nfiles;
2736 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2737 goto Bad_BulkStatus;
2739 tfid = Fids->AFSCBFids_val;
2740 for (i = 0; i < nfiles; i++, tfid++) {
2742 * Get volume/vnode for the fetched file; caller's rights to it
2746 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2747 &parentwhentargetnotdir, &client, READ_LOCK,
2748 &rights, &anyrights)))
2749 goto Bad_BulkStatus;
2750 /* set volume synchronization information, but only once per call */
2752 SetVolumeSync(Sync, volptr);
2754 /* Are we allowed to fetch Fid's status? */
2755 if (targetptr->disk.type != vDirectory) {
2757 Check_PermissionRights(targetptr, client, rights,
2758 CHK_FETCHSTATUS, 0))) {
2759 if (rx_GetCallAbortCode(acall) == errorCode)
2760 rx_SetCallAbortCode(acall, 0);
2761 goto Bad_BulkStatus;
2765 /* set OutStatus From the Fid */
2766 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2767 anyrights, parentwhentargetnotdir);
2769 /* If a r/w volume, also set the CallBack state */
2770 if (VolumeWriteable(volptr))
2771 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2772 &CallBacks->AFSCBs_val[i]);
2774 struct AFSFid myFid;
2775 memset(&myFid, 0, sizeof(struct AFSFid));
2776 myFid.Volume = tfid->Volume;
2777 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2778 &CallBacks->AFSCBs_val[i]);
2781 /* put back the file ID and volume */
2782 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2784 parentwhentargetnotdir = (Vnode *) 0;
2785 targetptr = (Vnode *) 0;
2786 volptr = (Volume *) 0;
2787 client = (struct client *)0;
2791 /* Update and store volume/vnode and parent vnodes back */
2792 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2794 errorCode = CallPostamble(tcon, errorCode, thost);
2796 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2798 #if FS_STATS_DETAILED
2799 FT_GetTimeOfDay(&opStopTime, 0);
2800 if (errorCode == 0) {
2802 (opP->numSuccesses)++;
2803 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2804 fs_stats_AddTo((opP->sumTime), elapsedTime);
2805 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2806 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2807 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2809 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2810 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2814 #endif /* FS_STATS_DETAILED */
2817 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2818 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2819 AUD_ID, t_client ? t_client->ViceId : 0,
2820 AUD_FIDS, Fids, AUD_END);
2823 } /*SRXAFS_BulkStatus */
2827 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2828 struct AFSBulkStats * OutStats,
2829 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2833 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2834 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2835 Error errorCode = 0; /* return code to caller */
2836 Volume *volptr = 0; /* pointer to the volume */
2837 struct client *client = 0; /* pointer to the client data */
2838 afs_int32 rights, anyrights; /* rights for this and any user */
2839 struct AFSFid *tfid; /* file id we're dealing with now */
2840 struct rx_connection *tcon;
2842 struct client *t_client = NULL; /* tmp ptr to client data */
2843 AFSFetchStatus *tstatus;
2844 int VolSync_set = 0;
2845 #if FS_STATS_DETAILED
2846 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2847 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2848 struct timeval elapsedTime; /* Transfer time */
2851 * Set our stats pointer, remember when the RPC operation started, and
2852 * tally the operation.
2854 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2858 FT_GetTimeOfDay(&opStartTime, 0);
2859 #endif /* FS_STATS_DETAILED */
2861 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2863 AFSCallStats.TotalCalls++;
2865 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2866 if (nfiles <= 0) { /* Sanity check */
2868 goto Audit_and_Return;
2871 /* allocate space for return output parameters */
2872 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2873 malloc(nfiles * sizeof(struct AFSFetchStatus));
2874 if (!OutStats->AFSBulkStats_val) {
2875 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2876 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2878 OutStats->AFSBulkStats_len = nfiles;
2879 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2880 malloc(nfiles * sizeof(struct AFSCallBack));
2881 if (!CallBacks->AFSCBs_val) {
2882 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2883 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2885 CallBacks->AFSCBs_len = nfiles;
2887 /* Zero out return values to avoid leaking information on partial succes */
2888 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2889 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2890 memset(Sync, 0, sizeof(*Sync));
2892 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2893 goto Bad_InlineBulkStatus;
2896 tfid = Fids->AFSCBFids_val;
2897 for (i = 0; i < nfiles; i++, tfid++) {
2899 * Get volume/vnode for the fetched file; caller's rights to it
2903 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2904 &parentwhentargetnotdir, &client, READ_LOCK,
2905 &rights, &anyrights))) {
2906 tstatus = &OutStats->AFSBulkStats_val[i];
2907 tstatus->errorCode = errorCode;
2908 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2910 parentwhentargetnotdir = (Vnode *) 0;
2911 targetptr = (Vnode *) 0;
2912 volptr = (Volume *) 0;
2913 client = (struct client *)0;
2917 /* set volume synchronization information, but only once per call */
2919 SetVolumeSync(Sync, volptr);
2923 /* Are we allowed to fetch Fid's status? */
2924 if (targetptr->disk.type != vDirectory) {
2926 Check_PermissionRights(targetptr, client, rights,
2927 CHK_FETCHSTATUS, 0))) {
2928 tstatus = &OutStats->AFSBulkStats_val[i];
2929 tstatus->errorCode = errorCode;
2930 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2931 (Vnode *) 0, volptr, &client);
2932 parentwhentargetnotdir = (Vnode *) 0;
2933 targetptr = (Vnode *) 0;
2934 volptr = (Volume *) 0;
2935 client = (struct client *)0;
2940 /* set OutStatus From the Fid */
2941 GetStatus(targetptr,
2942 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2943 rights, anyrights, parentwhentargetnotdir);
2945 /* If a r/w volume, also set the CallBack state */
2946 if (VolumeWriteable(volptr))
2947 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2948 &CallBacks->AFSCBs_val[i]);
2950 struct AFSFid myFid;
2951 memset(&myFid, 0, sizeof(struct AFSFid));
2952 myFid.Volume = tfid->Volume;
2953 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2954 &CallBacks->AFSCBs_val[i]);
2957 /* put back the file ID and volume */
2958 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2960 parentwhentargetnotdir = (Vnode *) 0;
2961 targetptr = (Vnode *) 0;
2962 volptr = (Volume *) 0;
2963 client = (struct client *)0;
2966 Bad_InlineBulkStatus:
2967 /* Update and store volume/vnode and parent vnodes back */
2968 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2970 errorCode = CallPostamble(tcon, errorCode, thost);
2972 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2974 #if FS_STATS_DETAILED
2975 FT_GetTimeOfDay(&opStopTime, 0);
2976 if (errorCode == 0) {
2978 (opP->numSuccesses)++;
2979 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2980 fs_stats_AddTo((opP->sumTime), elapsedTime);
2981 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2982 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2983 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2985 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2986 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2990 #endif /* FS_STATS_DETAILED */
2993 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2994 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2995 AUD_ID, t_client ? t_client->ViceId : 0,
2996 AUD_FIDS, Fids, AUD_END);
2999 } /*SRXAFS_InlineBulkStatus */
3003 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
3004 struct AFSFetchStatus * OutStatus,
3005 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3008 struct rx_connection *tcon;
3010 struct client *t_client = NULL; /* tmp ptr to client data */
3011 #if FS_STATS_DETAILED
3012 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3013 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3014 struct timeval elapsedTime; /* Transfer time */
3017 * Set our stats pointer, remember when the RPC operation started, and
3018 * tally the operation.
3020 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
3024 FT_GetTimeOfDay(&opStartTime, 0);
3025 #endif /* FS_STATS_DETAILED */
3027 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3028 goto Bad_FetchStatus;
3030 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
3033 code = CallPostamble(tcon, code, thost);
3035 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3037 #if FS_STATS_DETAILED
3038 FT_GetTimeOfDay(&opStopTime, 0);
3041 (opP->numSuccesses)++;
3042 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3043 fs_stats_AddTo((opP->sumTime), elapsedTime);
3044 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3045 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3046 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3048 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3049 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3053 #endif /* FS_STATS_DETAILED */
3055 osi_auditU(acall, FetchStatusEvent, code,
3056 AUD_ID, t_client ? t_client->ViceId : 0,
3057 AUD_FID, Fid, AUD_END);
3060 } /*SRXAFS_FetchStatus */
3064 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
3065 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
3066 afs_fsize_t Length, afs_fsize_t FileLength,
3067 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3069 Vnode *targetptr = 0; /* pointer to input fid */
3070 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3071 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
3072 Error errorCode = 0; /* return code for caller */
3073 Error fileCode = 0; /* return code from vol package */
3074 Volume *volptr = 0; /* pointer to the volume header */
3075 struct client *client = 0; /* pointer to client structure */
3076 afs_int32 rights, anyrights; /* rights for this and any user */
3077 struct client *t_client = NULL; /* tmp ptr to client data */
3078 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3079 struct rx_connection *tcon;
3081 #if FS_STATS_DETAILED
3082 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3083 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
3084 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3085 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
3086 struct timeval elapsedTime; /* Transfer time */
3087 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
3088 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
3089 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
3092 * Set our stats pointers, remember when the RPC operation started, and
3093 * tally the operation.
3095 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
3096 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
3101 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3103 FT_GetTimeOfDay(&opStartTime, 0);
3104 #endif /* FS_STATS_DETAILED */
3107 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3109 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3112 /* Get ptr to client data for user Id for logging */
3113 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3114 logHostAddr.s_addr = rxr_HostOf(tcon);
3116 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3117 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3118 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3121 * Get associated volume/vnode for the stored file; caller's rights
3125 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3126 &parentwhentargetnotdir, &client, WRITE_LOCK,
3127 &rights, &anyrights))) {
3131 /* set volume synchronization information */
3132 SetVolumeSync(Sync, volptr);
3134 if ((targetptr->disk.type == vSymlink)) {
3135 /* Should we return a better error code here??? */
3140 /* Check if we're allowed to store the data */
3142 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3148 * Drop the read lock on the parent directory after saving the parent
3149 * vnode information we need to pass to GetStatus
3151 if (parentwhentargetnotdir != NULL) {
3152 tparentwhentargetnotdir = *parentwhentargetnotdir;
3153 VPutVnode(&fileCode, parentwhentargetnotdir);
3154 osi_Assert(!fileCode || (fileCode == VSALVAGE));
3155 parentwhentargetnotdir = NULL;
3157 #if FS_STATS_DETAILED
3159 * Remember when the data transfer started.
3161 FT_GetTimeOfDay(&xferStartTime, 0);
3162 #endif /* FS_STATS_DETAILED */
3164 /* Do the actual storing of the data */
3165 #if FS_STATS_DETAILED
3167 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3168 FileLength, (InStatus->Mask & AFS_FSYNC),
3169 &bytesToXfer, &bytesXferred);
3172 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3173 FileLength, (InStatus->Mask & AFS_FSYNC));
3174 if (errorCode && (!targetptr->changed_newTime))
3176 #endif /* FS_STATS_DETAILED */
3177 #if FS_STATS_DETAILED
3179 * At this point, the data transfer is done, for good or ill. Remember
3180 * when the transfer ended, bump the number of successes/failures, and
3181 * integrate the transfer size and elapsed time into the stats. If the
3182 * operation failed, we jump to the appropriate point.
3184 FT_GetTimeOfDay(&xferStopTime, 0);
3186 (xferP->numXfers)++;
3188 (xferP->numSuccesses)++;
3191 * Bump the xfer sum by the number of bytes actually sent, NOT the
3194 tot_bytesXferred += bytesXferred;
3195 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3196 tot_bytesXferred &= 0x3FF;
3197 if (bytesXferred < xferP->minBytes)
3198 xferP->minBytes = bytesXferred;
3199 if (bytesXferred > xferP->maxBytes)
3200 xferP->maxBytes = bytesXferred;
3203 * Tally the size of the object. Note: we tally the actual size,
3204 * NOT the number of bytes that made it out over the wire.
3206 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3207 (xferP->count[0])++;
3208 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3209 (xferP->count[1])++;
3210 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3211 (xferP->count[2])++;
3212 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3213 (xferP->count[3])++;
3214 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3215 (xferP->count[4])++;
3216 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3217 (xferP->count[5])++;
3218 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3219 (xferP->count[6])++;
3220 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3221 (xferP->count[7])++;
3223 (xferP->count[8])++;
3225 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3226 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3227 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3228 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3229 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3231 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3232 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3237 * Finally, go off to tell our caller the bad news in case the
3240 if (errorCode && (!targetptr->changed_newTime))
3242 #endif /* FS_STATS_DETAILED */
3244 /* Update the status of the target's vnode */
3245 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3246 targetptr, volptr, 0);
3248 /* Get the updated File's status back to the caller */
3249 GetStatus(targetptr, OutStatus, rights, anyrights,
3250 &tparentwhentargetnotdir);
3253 /* Update and store volume/vnode and parent vnodes back */
3254 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3256 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3258 errorCode = CallPostamble(tcon, errorCode, thost);
3260 #if FS_STATS_DETAILED
3261 FT_GetTimeOfDay(&opStopTime, 0);
3262 if (errorCode == 0) {
3264 (opP->numSuccesses)++;
3265 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3266 fs_stats_AddTo((opP->sumTime), elapsedTime);
3267 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3268 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3269 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3271 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3272 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3276 #endif /* FS_STATS_DETAILED */
3277 osi_auditU(acall, StoreDataEvent, errorCode,
3278 AUD_ID, t_client ? t_client->ViceId : 0,
3279 AUD_FID, Fid, AUD_END);
3281 } /*common_StoreData64 */
3284 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3285 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3286 afs_uint32 Length, afs_uint32 FileLength,
3287 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3289 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3290 (0x7fffffff - Pos) < Length)
3293 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3295 } /*SRXAFS_StoreData */
3298 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3299 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3300 afs_uint64 Length, afs_uint64 FileLength,
3301 struct AFSFetchStatus * OutStatus,
3302 struct AFSVolSync * Sync)
3306 afs_fsize_t tLength;
3307 afs_fsize_t tFileLength;
3309 tPos = (afs_fsize_t) Pos;
3310 tLength = (afs_fsize_t) Length;
3311 tFileLength = (afs_fsize_t) FileLength;
3314 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3320 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3321 struct AFSOpaque * AccessList,
3322 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3324 Vnode *targetptr = 0; /* pointer to input fid */
3325 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3326 Error errorCode = 0; /* return code for caller */
3327 struct AFSStoreStatus InStatus; /* Input status for fid */
3328 Volume *volptr = 0; /* pointer to the volume header */
3329 struct client *client = 0; /* pointer to client structure */
3330 afs_int32 rights, anyrights; /* rights for this and any user */
3331 struct rx_connection *tcon;
3333 struct client *t_client = NULL; /* tmp ptr to client data */
3334 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3335 #if FS_STATS_DETAILED
3336 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3337 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3338 struct timeval elapsedTime; /* Transfer time */
3341 * Set our stats pointer, remember when the RPC operation started, and
3342 * tally the operation.
3344 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3348 FT_GetTimeOfDay(&opStartTime, 0);
3349 #endif /* FS_STATS_DETAILED */
3350 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3353 /* Get ptr to client data for user Id for logging */
3354 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3355 logHostAddr.s_addr = rxr_HostOf(tcon);
3357 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3358 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3359 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3361 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3363 InStatus.Mask = 0; /* not storing any status */
3366 * Get associated volume/vnode for the target dir; caller's rights
3367 * are also returned.
3370 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3371 &parentwhentargetnotdir, &client, WRITE_LOCK,
3372 &rights, &anyrights))) {
3376 /* set volume synchronization information */
3377 SetVolumeSync(Sync, volptr);
3379 /* Check if we have permission to change the dir's ACL */
3381 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3386 /* Build and store the new Access List for the dir */
3387 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3391 targetptr->changed_newTime = 1; /* status change of directory */
3393 /* convert the write lock to a read lock before breaking callbacks */
3394 VVnodeWriteToRead(&errorCode, targetptr);
3395 osi_Assert(!errorCode || errorCode == VSALVAGE);
3397 /* break call backs on the directory */
3398 BreakCallBack(client->host, Fid, 0);
3400 /* Get the updated dir's status back to the caller */
3401 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3404 /* Update and store volume/vnode and parent vnodes back */
3405 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3407 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3408 errorCode = CallPostamble(tcon, errorCode, thost);
3410 #if FS_STATS_DETAILED
3411 FT_GetTimeOfDay(&opStopTime, 0);
3412 if (errorCode == 0) {
3414 (opP->numSuccesses)++;
3415 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3416 fs_stats_AddTo((opP->sumTime), elapsedTime);
3417 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3418 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3419 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3421 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3422 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3426 #endif /* FS_STATS_DETAILED */
3428 osi_auditU(acall, StoreACLEvent, errorCode,
3429 AUD_ID, t_client ? t_client->ViceId : 0,
3430 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3433 } /*SRXAFS_StoreACL */
3437 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3438 * should be merged when possible.
3441 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3442 struct AFSStoreStatus *InStatus,
3443 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3445 Vnode *targetptr = 0; /* pointer to input fid */
3446 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3447 Error errorCode = 0; /* return code for caller */
3448 Volume *volptr = 0; /* pointer to the volume header */
3449 struct client *client = 0; /* pointer to client structure */
3450 afs_int32 rights, anyrights; /* rights for this and any user */
3451 struct client *t_client = NULL; /* tmp ptr to client data */
3452 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3453 struct rx_connection *tcon = rx_ConnectionOf(acall);
3455 /* Get ptr to client data for user Id for logging */
3456 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3457 logHostAddr.s_addr = rxr_HostOf(tcon);
3459 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3460 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3461 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3463 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3466 * Get volume/vnode for the target file; caller's rights to it are
3470 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3471 &parentwhentargetnotdir, &client, WRITE_LOCK,
3472 &rights, &anyrights))) {
3473 goto Bad_StoreStatus;
3476 /* set volume synchronization information */
3477 SetVolumeSync(Sync, volptr);
3479 /* Check if the caller has proper permissions to store status to Fid */
3481 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3483 goto Bad_StoreStatus;
3486 * Check for a symbolic link; we can't chmod these (otherwise could
3487 * change a symlink to a mt pt or vice versa)
3489 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3491 goto Bad_StoreStatus;
3494 /* Update the status of the target's vnode */
3495 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3496 (parentwhentargetnotdir ? parentwhentargetnotdir
3497 : targetptr), volptr, 0);
3499 /* convert the write lock to a read lock before breaking callbacks */
3500 VVnodeWriteToRead(&errorCode, targetptr);
3501 osi_Assert(!errorCode || errorCode == VSALVAGE);
3503 /* Break call backs on Fid */
3504 BreakCallBack(client->host, Fid, 0);
3506 /* Return the updated status back to caller */
3507 GetStatus(targetptr, OutStatus, rights, anyrights,
3508 parentwhentargetnotdir);
3511 /* Update and store volume/vnode and parent vnodes back */
3512 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3514 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3517 } /*SAFSS_StoreStatus */
3521 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3522 struct AFSStoreStatus * InStatus,
3523 struct AFSFetchStatus * OutStatus,
3524 struct AFSVolSync * Sync)
3527 struct rx_connection *tcon;
3529 struct client *t_client = NULL; /* tmp ptr to client data */
3530 #if FS_STATS_DETAILED
3531 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3532 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3533 struct timeval elapsedTime; /* Transfer time */
3536 * Set our stats pointer, remember when the RPC operation started, and
3537 * tally the operation.
3539 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3543 FT_GetTimeOfDay(&opStartTime, 0);
3544 #endif /* FS_STATS_DETAILED */
3546 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3547 goto Bad_StoreStatus;
3549 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3552 code = CallPostamble(tcon, code, thost);
3554 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3556 #if FS_STATS_DETAILED
3557 FT_GetTimeOfDay(&opStopTime, 0);
3560 (opP->numSuccesses)++;
3561 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3562 fs_stats_AddTo((opP->sumTime), elapsedTime);
3563 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3564 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3565 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3567 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3568 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3572 #endif /* FS_STATS_DETAILED */
3574 osi_auditU(acall, StoreStatusEvent, code,
3575 AUD_ID, t_client ? t_client->ViceId : 0,
3576 AUD_FID, Fid, AUD_END);
3579 } /*SRXAFS_StoreStatus */
3583 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3584 * merged in when possible.
3587 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3588 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3590 Vnode *parentptr = 0; /* vnode of input Directory */
3591 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3592 Vnode *targetptr = 0; /* file to be deleted */
3593 Volume *volptr = 0; /* pointer to the volume header */
3594 AFSFid fileFid; /* area for Fid from the directory */
3595 Error errorCode = 0; /* error code */
3596 DirHandle dir; /* Handle for dir package I/O */
3597 struct client *client = 0; /* pointer to client structure */
3598 afs_int32 rights, anyrights; /* rights for this and any user */
3599 struct client *t_client; /* tmp ptr to client data */
3600 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3601 struct rx_connection *tcon = rx_ConnectionOf(acall);
3604 /* Get ptr to client data for user Id for logging */
3605 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3606 logHostAddr.s_addr = rxr_HostOf(tcon);
3608 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3609 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3610 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3612 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3615 * Get volume/vnode for the parent dir; caller's access rights are
3619 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3620 &parentwhentargetnotdir, &client, WRITE_LOCK,
3621 &rights, &anyrights))) {
3622 goto Bad_RemoveFile;
3624 /* set volume synchronization information */
3625 SetVolumeSync(Sync, volptr);
3627 /* Does the caller has delete (& write) access to the parent directory? */
3628 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3629 goto Bad_RemoveFile;
3632 /* Actually delete the desired file */
3634 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3636 goto Bad_RemoveFile;
3639 /* Update the vnode status of the parent dir */
3640 #if FS_STATS_DETAILED
3641 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3642 parentptr->disk.linkCount,
3643 client->InSameNetwork);
3645 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3646 parentptr->disk.linkCount);
3647 #endif /* FS_STATS_DETAILED */
3649 /* Return the updated parent dir's status back to caller */
3650 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3652 /* Handle internal callback state for the parent and the deleted file */
3653 if (targetptr->disk.linkCount == 0) {
3654 /* no references left, discard entry */
3655 DeleteFileCallBacks(&fileFid);
3656 /* convert the parent lock to a read lock before breaking callbacks */
3657 VVnodeWriteToRead(&errorCode, parentptr);
3658 osi_Assert(!errorCode || errorCode == VSALVAGE);
3660 /* convert the parent lock to a read lock before breaking callbacks */
3661 VVnodeWriteToRead(&errorCode, parentptr);
3662 osi_Assert(!errorCode || errorCode == VSALVAGE);
3663 /* convert the target lock to a read lock before breaking callbacks */
3664 VVnodeWriteToRead(&errorCode, targetptr);
3665 osi_Assert(!errorCode || errorCode == VSALVAGE);
3666 /* tell all the file has changed */
3667 BreakCallBack(client->host, &fileFid, 1);
3670 /* break call back on the directory */
3671 BreakCallBack(client->host, DirFid, 0);
3674 /* Update and store volume/vnode and parent vnodes back */
3675 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3678 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3681 } /*SAFSS_RemoveFile */
3685 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3686 struct AFSFetchStatus * OutDirStatus,
3687 struct AFSVolSync * Sync)
3690 struct rx_connection *tcon;
3692 struct client *t_client = NULL; /* tmp ptr to client data */
3693 #if FS_STATS_DETAILED
3694 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3695 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3696 struct timeval elapsedTime; /* Transfer time */
3699 * Set our stats pointer, remember when the RPC operation started, and
3700 * tally the operation.
3702 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3706 FT_GetTimeOfDay(&opStartTime, 0);
3707 #endif /* FS_STATS_DETAILED */
3709 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3710 goto Bad_RemoveFile;
3712 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3715 code = CallPostamble(tcon, code, thost);
3717 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3719 #if FS_STATS_DETAILED
3720 FT_GetTimeOfDay(&opStopTime, 0);
3723 (opP->numSuccesses)++;
3724 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3725 fs_stats_AddTo((opP->sumTime), elapsedTime);
3726 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3727 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3728 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3730 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3731 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3735 #endif /* FS_STATS_DETAILED */
3737 osi_auditU(acall, RemoveFileEvent, code,
3738 AUD_ID, t_client ? t_client->ViceId : 0,
3739 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3742 } /*SRXAFS_RemoveFile */
3746 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3747 * be merged in when possible.
3750 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3751 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3752 struct AFSFetchStatus *OutFidStatus,
3753 struct AFSFetchStatus *OutDirStatus,
3754 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3756 Vnode *parentptr = 0; /* vnode of input Directory */
3757 Vnode *targetptr = 0; /* vnode of the new file */
3758 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3759 Volume *volptr = 0; /* pointer to the volume header */
3760 Error errorCode = 0; /* error code */
3761 DirHandle dir; /* Handle for dir package I/O */
3762 struct client *client = 0; /* pointer to client structure */
3763 afs_int32 rights, anyrights; /* rights for this and any user */
3764 struct client *t_client; /* tmp ptr to client data */
3765 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3766 struct rx_connection *tcon = rx_ConnectionOf(acall);
3770 /* Get ptr to client data for user Id for logging */
3771 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3772 logHostAddr.s_addr = rxr_HostOf(tcon);
3774 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3775 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3776 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3778 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3780 if (!FileNameOK(Name)) {
3782 goto Bad_CreateFile;
3786 * Get associated volume/vnode for the parent dir; caller long are
3790 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3791 &parentwhentargetnotdir, &client, WRITE_LOCK,
3792 &rights, &anyrights))) {
3793 goto Bad_CreateFile;
3796 /* set volume synchronization information */
3797 SetVolumeSync(Sync, volptr);
3799 /* Can we write (and insert) onto the parent directory? */
3800 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3801 goto Bad_CreateFile;
3803 /* get a new vnode for the file to be created and set it up */
3805 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3806 vFile, nBlocks(0)))) {
3807 goto Bad_CreateFile;
3810 /* update the status of the parent vnode */
3811 #if FS_STATS_DETAILED
3812 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3813 parentptr->disk.linkCount,
3814 client->InSameNetwork);
3816 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3817 parentptr->disk.linkCount);
3818 #endif /* FS_STATS_DETAILED */
3820 /* update the status of the new file's vnode */
3821 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3822 parentptr, volptr, 0);
3824 /* 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 */
3825 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3826 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3828 /* convert the write lock to a read lock before breaking callbacks */
3829 VVnodeWriteToRead(&errorCode, parentptr);
3830 osi_Assert(!errorCode || errorCode == VSALVAGE);
3832 /* break call back on parent dir */
3833 BreakCallBack(client->host, DirFid, 0);
3835 /* Return a callback promise for the newly created file to the caller */
3836 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3839 /* Update and store volume/vnode and parent vnodes back */
3840 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3843 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3846 } /*SAFSS_CreateFile */
3850 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3851 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3852 struct AFSFetchStatus * OutFidStatus,
3853 struct AFSFetchStatus * OutDirStatus,
3854 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3857 struct rx_connection *tcon;
3859 struct client *t_client = NULL; /* tmp ptr to client data */
3860 #if FS_STATS_DETAILED
3861 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3862 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3863 struct timeval elapsedTime; /* Transfer time */
3866 * Set our stats pointer, remember when the RPC operation started, and
3867 * tally the operation.
3869 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3873 FT_GetTimeOfDay(&opStartTime, 0);
3874 #endif /* FS_STATS_DETAILED */
3876 memset(OutFid, 0, sizeof(struct AFSFid));
3878 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3879 goto Bad_CreateFile;
3882 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3883 OutDirStatus, CallBack, Sync);
3886 code = CallPostamble(tcon, code, thost);
3888 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3890 #if FS_STATS_DETAILED
3891 FT_GetTimeOfDay(&opStopTime, 0);
3894 (opP->numSuccesses)++;
3895 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3896 fs_stats_AddTo((opP->sumTime), elapsedTime);
3897 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3898 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3899 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3901 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3902 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3906 #endif /* FS_STATS_DETAILED */
3908 osi_auditU(acall, CreateFileEvent, code,
3909 AUD_ID, t_client ? t_client->ViceId : 0,
3910 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3913 } /*SRXAFS_CreateFile */
3917 * This routine is called exclusively from SRXAFS_Rename(), and should be
3918 * merged in when possible.
3921 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3922 struct AFSFid *NewDirFid, char *NewName,
3923 struct AFSFetchStatus *OutOldDirStatus,
3924 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3926 Vnode *oldvptr = 0; /* vnode of the old Directory */
3927 Vnode *newvptr = 0; /* vnode of the new Directory */
3928 Vnode *fileptr = 0; /* vnode of the file to move */
3929 Vnode *newfileptr = 0; /* vnode of the file to delete */
3930 Vnode *testvptr = 0; /* used in directory tree walk */
3931 Vnode *parent = 0; /* parent for use in SetAccessList */
3932 Error errorCode = 0; /* error code */
3933 Error fileCode = 0; /* used when writing Vnodes */
3934 VnodeId testnode; /* used in directory tree walk */
3935 AFSFid fileFid; /* Fid of file to move */
3936 AFSFid newFileFid; /* Fid of new file */
3937 DirHandle olddir; /* Handle for dir package I/O */
3938 DirHandle newdir; /* Handle for dir package I/O */
3939 DirHandle filedir; /* Handle for dir package I/O */
3940 DirHandle newfiledir; /* Handle for dir package I/O */
3941 Volume *volptr = 0; /* pointer to the volume header */
3942 struct client *client = 0; /* pointer to client structure */
3943 afs_int32 rights, anyrights; /* rights for this and any user */
3944 afs_int32 newrights; /* rights for this user */
3945 afs_int32 newanyrights; /* rights for any user */
3946 int doDelete; /* deleted the rename target (ref count now 0) */
3948 int updatefile = 0; /* are we changing the renamed file? (we do this
3949 * if we need to update .. on a renamed dir) */
3950 struct client *t_client; /* tmp ptr to client data */
3951 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3952 struct rx_connection *tcon = rx_ConnectionOf(acall);
3958 FidZero(&newfiledir);
3960 /* Get ptr to client data for user Id for logging */
3961 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3962 logHostAddr.s_addr = rxr_HostOf(tcon);
3964 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3965 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3966 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3967 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3969 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3971 if (!FileNameOK(NewName)) {
3975 if (OldDirFid->Volume != NewDirFid->Volume) {
3980 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3981 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3982 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3988 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3990 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3991 &parent, &client, WRITE_LOCK, &rights,
3996 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3998 newrights = rights, newanyrights = anyrights;
4001 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
4002 MustBeDIR, &parent, &client, WRITE_LOCK,
4003 &newrights, &newanyrights))) {
4009 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
4010 &parent, &client, WRITE_LOCK, &newrights,
4016 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
4017 &parent, &client, WRITE_LOCK, &rights,
4024 /* set volume synchronization information */
4025 SetVolumeSync(Sync, volptr);
4027 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
4030 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
4034 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
4035 * call to CopyOnWrite returns error, it is not necessary to revert back
4036 * the effects of the first call because the contents of the volume is
4037 * not modified, it is only replicated.
4039 if (oldvptr->disk.cloned) {
4040 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
4041 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
4044 SetDirHandle(&olddir, oldvptr);
4045 if (newvptr->disk.cloned) {
4046 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
4047 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))