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>
36 #undef SHARED /* XXX */
41 #include <sys/param.h>
43 #include <sys/ioctl.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
50 #ifndef AFS_LINUX20_ENV
52 #ifndef AFS_ARM_DARWIN_ENV
53 #include <netinet/if_ether.h>
58 /* included early because of name conflict on IOPEN */
59 #include <sys/inode.h>
63 #endif /* AFS_HPUX_ENV */
67 #include <afs/afs_assert.h>
70 #include <afs/afsint.h>
71 #include <afs/vldbint.h>
72 #include <afs/errors.h>
73 #include <afs/ihandle.h>
74 #include <afs/vnode.h>
75 #include <afs/volume.h>
76 #include <afs/ptclient.h>
77 #include <afs/ptuser.h>
78 #include <afs/prs_fs.h>
81 #include <rx/rx_globals.h>
83 #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)
86 #if !defined(AFS_NT40_ENV)
89 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
91 #include <sys/statfs.h>
92 #include <sys/lockf.h>
94 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
99 #include <afs/cellconfig.h>
100 #include <afs/keys.h>
103 #include <afs/partition.h>
104 #include "viced_prototypes.h"
107 #include "callback.h"
108 #include <afs/unified_afs.h>
109 #include <afs/audit.h>
110 #include <afs/afsutil.h>
113 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
114 extern void FidZap(DirHandle * file);
115 extern void FidZero(DirHandle * file);
117 #ifdef AFS_PTHREAD_ENV
118 pthread_mutex_t fileproc_glock_mutex;
119 #endif /* AFS_PTHREAD_ENV */
122 #define afs_stat stat64
123 #define afs_fstat fstat64
124 #define afs_open open64
125 #else /* !O_LARGEFILE */
126 #define afs_stat stat
127 #define afs_fstat fstat
128 #define afs_open open
129 #endif /* !O_LARGEFILE */
132 /* Useful local defines used by this module */
135 #define MustNOTBeDIR 1
139 #define TVS_SSTATUS 2
142 #define TVS_MKDIR 0x10
144 #define CHK_FETCH 0x10
145 #define CHK_FETCHDATA 0x10
146 #define CHK_FETCHACL 0x11
147 #define CHK_FETCHSTATUS 0x12
148 #define CHK_STOREDATA 0x00
149 #define CHK_STOREACL 0x01
150 #define CHK_STORESTATUS 0x02
152 #define OWNERREAD 0400
153 #define OWNERWRITE 0200
154 #define OWNEREXEC 0100
155 #ifdef USE_GROUP_PERMS
156 #define GROUPREAD 0040
157 #define GROUPWRITE 0020
158 #define GROUPREXEC 0010
161 /* The following errors were not defined in NT. They are given unique
162 * names here to avoid any potential collision.
164 #define FSERR_ELOOP 90
165 #define FSERR_EOPNOTSUPP 122
166 #define FSERR_ECONNREFUSED 130
168 #define NOTACTIVECALL 0
171 #define CREATE_SGUID_ADMIN_ONLY 1
173 extern struct afsconf_dir *confDir;
174 extern afs_int32 dataVersionHigh;
177 static struct AFSCallStatistics AFSCallStats;
178 #if FS_STATS_DETAILED
179 struct fs_stats_FullPerfStats afs_FullPerfStats;
180 extern int AnonymousID;
181 #endif /* FS_STATS_DETAILED */
182 #if OPENAFS_VOL_STATS
183 static const char nullString[] = "";
184 #endif /* OPENAFS_VOL_STATS */
187 afs_int32 NothingYet;
190 struct afs_FSStats afs_fsstats;
195 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
197 extern afs_int32 implicitAdminRights;
198 extern afs_int32 readonlyServer;
199 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
200 extern afs_fsize_t CopyOnWrite_maxsize;
203 * Externals used by the xstat code.
205 extern VolPkgStats VStats;
206 extern int CEs, CEBlocks;
208 extern int HTs, HTBlocks;
210 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
211 struct rx_call *Call, afs_sfsize_t Pos,
212 afs_sfsize_t Len, afs_int32 Int64Mode,
213 #if FS_STATS_DETAILED
214 afs_sfsize_t * a_bytesToFetchP,
215 afs_sfsize_t * a_bytesFetchedP
216 #endif /* FS_STATS_DETAILED */
219 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
220 struct AFSFid *Fid, struct client *client,
221 struct rx_call *Call, afs_fsize_t Pos,
222 afs_fsize_t Length, afs_fsize_t FileLength,
224 #if FS_STATS_DETAILED
225 afs_sfsize_t * a_bytesToStoreP,
226 afs_sfsize_t * a_bytesStoredP
227 #endif /* FS_STATS_DETAILED */
230 #ifdef AFS_SGI_XFS_IOPS_ENV
231 #include <afs/xfsattrs.h>
233 GetLinkCount(Volume * avp, struct stat *astat)
235 if (!strcmp("xfs", astat->st_fstype)) {
236 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
238 return astat->st_nlink;
241 #define GetLinkCount(V, S) (S)->st_nlink
245 SpareComp(Volume * avolp)
251 temp = V_maxquota(avolp);
253 /* no matter; doesn't check in this case */
257 temp = (temp * PctSpare) / 100;
268 * Set the volume synchronization parameter for this volume. If it changes,
269 * the Cache Manager knows that the volume must be purged from the stat cache.
272 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
275 /* date volume instance was created */
278 async->spare1 = avol->header->diskstuff.creationDate;
291 * Note that this function always returns a held host, so
292 * that CallPostamble can block without the host's disappearing.
293 * Call returns rx connection in passed in *tconn
296 CallPreamble(struct rx_call *acall, int activecall,
297 struct rx_connection **tconn, struct host **ahostp)
300 struct client *tclient;
303 char hoststr[16], hoststr2[16];
304 #ifdef AFS_PTHREAD_ENV
305 struct ubik_client *uclient;
310 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
313 *tconn = rx_ConnectionOf(acall);
317 tclient = h_FindClient_r(*tconn);
319 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
323 thost = tclient->host;
324 if (tclient->prfail == 1) { /* couldn't get the CPS */
326 h_ReleaseClient_r(tclient);
328 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
332 retry_flag = 0; /* Retry once */
334 /* Take down the old connection and re-read the key file */
336 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
337 #ifdef AFS_PTHREAD_ENV
338 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
340 /* Is it still necessary to drop this? We hit the net, we should... */
346 code = hpr_Initialize(&uclient);
349 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
352 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
355 h_ReleaseClient_r(tclient);
358 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
362 tclient->prfail = 2; /* Means re-eval client's cps */
363 h_ReleaseClient_r(tclient);
368 tclient->LastCall = thost->LastCall = FT_ApproxTime();
369 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
370 thost->ActiveCall = thost->LastCall;
373 if (thost->hostFlags & HOSTDELETED) {
375 ("Discarded a packet for deleted host %s:%d\n",
376 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
377 code = VBUSY; /* raced, so retry */
378 } else if ((thost->hostFlags & VENUSDOWN)
379 || (thost->hostFlags & HFE_LATER)) {
380 if (BreakDelayedCallBacks_r(thost)) {
382 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
383 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
384 ntohs(rxr_PortOf(*tconn))));
385 if (MultiProbeAlternateAddress_r(thost)) {
387 ("MultiProbe failed to find new address for host %s:%d\n",
388 afs_inet_ntoa_r(thost->host, hoststr),
389 ntohs(thost->port)));
393 ("MultiProbe found new address for host %s:%d\n",
394 afs_inet_ntoa_r(thost->host, hoststr),
395 ntohs(thost->port)));
396 if (BreakDelayedCallBacks_r(thost)) {
398 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
399 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
400 ntohs(rxr_PortOf(*tconn))));
409 h_ReleaseClient_r(tclient);
419 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
423 struct client *tclient;
427 tclient = h_FindClient_r(aconn);
430 thost = tclient->host;
431 if (thost->hostFlags & HERRORTRANS)
433 h_ReleaseClient_r(tclient);
436 if (ahost != thost) {
437 /* host/client recycle */
438 char hoststr[16], hoststr2[16];
439 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
441 afs_inet_ntoa_r(ahost->host, hoststr),
444 afs_inet_ntoa_r(thost->host, hoststr2),
448 /* return the reference taken in CallPreamble */
452 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
453 afs_inet_ntoa_r(thost->host, hoststr),
458 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
459 * does not decrement refcount on client->host */
464 return (translate ? sys_error_to_et(ret) : ret);
468 * Returns the volume and vnode pointers associated with file Fid; the lock
469 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
470 * are incremented and they must be eventualy released.
473 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
476 Error local_errorCode, errorCode = -1;
477 static struct timeval restartedat = { 0, 0 };
479 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
481 if ((*volptr) == 0) {
486 #ifdef AFS_DEMAND_ATTACH_FS
494 *volptr = VGetVolumeNoWait(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
499 if ((errorCode == VOFFLINE) && (VInit < 2)) {
500 /* The volume we want may not be attached yet because
501 * the volume initialization is not yet complete.
502 * We can do several things:
503 * 1. return -1, which will cause users to see
504 * "connection timed out". This is more or
505 * less the same as always, except that the servers
506 * may appear to bounce up and down while they
507 * are actually restarting.
508 * 2. return VBUSY which will cause clients to
509 * sleep and retry for 6.5 - 15 minutes, depending
510 * on what version of the CM they are running. If
511 * the file server takes longer than that interval
512 * to attach the desired volume, then the application
513 * will see an ENODEV or EIO. This approach has
514 * the advantage that volumes which have been attached
515 * are immediately available, it keeps the server's
516 * immediate backlog low, and the call is interruptible
517 * by the user. Users see "waiting for busy volume."
518 * 3. sleep here and retry. Some people like this approach
519 * because there is no danger of seeing errors. However,
520 * this approach only works with a bounded number of
521 * clients, since the pending queues will grow without
522 * stopping. It might be better to find a way to take
523 * this call and stick it back on a queue in order to
524 * recycle this thread for a different request.
525 * 4. Return a new error code, which new cache managers will
526 * know enough to interpret as "sleep and retry", without
527 * the upper bound of 6-15 minutes that is imposed by the
528 * VBUSY handling. Users will see "waiting for
529 * busy volume," so they know that something is
530 * happening. Old cache managers must be able to do
531 * something reasonable with this, for instance, mark the
532 * server down. Fortunately, any error code < 0
533 * will elicit that behavior. See #1.
534 * 5. Some combination of the above. I like doing #2 for 10
535 * minutes, followed by #4. 3.1b and 3.2 cache managers
536 * will be fine as long as the restart period is
537 * not longer than 6.5 minutes, otherwise they may
538 * return ENODEV to users. 3.3 cache managers will be
539 * fine for 10 minutes, then will return
540 * ETIMEDOUT. 3.4 cache managers will just wait
541 * until the call works or fails definitively.
542 * NB. The problem with 2,3,4,5 is that old clients won't
543 * fail over to an alternate read-only replica while this
544 * server is restarting. 3.4 clients will fail over right away.
546 if (restartedat.tv_sec == 0) {
547 /* I'm not really worried about when we restarted, I'm */
548 /* just worried about when the first VBUSY was returned. */
549 FT_GetTimeOfDay(&restartedat, 0);
552 afs_perfstats.fs_nBusies++;
555 return (busyonrst ? VBUSY : restarting);
558 FT_GetTimeOfDay(&now, 0);
559 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
562 afs_perfstats.fs_nBusies++;
565 return (busyonrst ? VBUSY : restarting);
571 /* allow read operations on busy volume.
572 * must check local_errorCode because demand attach fs
573 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
574 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
575 #ifdef AFS_DEMAND_ATTACH_FS
576 /* DAFS case is complicated by the fact that local_errorCode can
577 * be VBUSY in cases where the volume is truly offline */
579 /* volume is in VOL_STATE_UNATTACHED */
582 #endif /* AFS_DEMAND_ATTACH_FS */
585 } else if (errorCode)
592 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
595 if ((*vptr)->disk.uniquifier != fid->Unique) {
596 VPutVnode(&fileCode, *vptr);
597 osi_Assert(fileCode == 0);
599 return (VNOVNODE); /* return the right error code, at least */
605 * This routine returns the ACL associated with the targetptr. If the
606 * targetptr isn't a directory, we access its parent dir and get the ACL
607 * thru the parent; in such case the parent's vnode is returned in
611 SetAccessList(Vnode ** targetptr, Volume ** volume,
612 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
613 AFSFid * Fid, int Lock)
615 if ((*targetptr)->disk.type == vDirectory) {
617 *ACL = VVnodeACL(*targetptr);
618 *ACLSize = VAclSize(*targetptr);
621 osi_Assert(Fid != 0);
626 parentvnode = (*targetptr)->disk.parent;
627 VPutVnode(&errorCode, *targetptr);
631 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
634 *ACL = VVnodeACL(*parent);
635 *ACLSize = VAclSize(*parent);
636 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
638 if ((*targetptr)->disk.parent != parentvnode) {
639 VPutVnode(&errorCode, *parent);
650 /* Must not be called with H_LOCK held */
652 client_CheckRights(struct client *client, struct acl_accessList *ACL,
656 ObtainReadLock(&client->lock);
657 if (client->CPS.prlist_len > 0 && !client->deleted &&
658 client->host && !(client->host->hostFlags & HOSTDELETED))
659 acl_CheckRights(ACL, &client->CPS, rights);
660 ReleaseReadLock(&client->lock);
663 /* Must not be called with H_LOCK held */
665 client_HasAsMember(struct client *client, afs_int32 id)
669 ObtainReadLock(&client->lock);
670 if (client->CPS.prlist_len > 0 && !client->deleted &&
671 client->host && !(client->host->hostFlags & HOSTDELETED))
672 code = acl_IsAMember(id, &client->CPS);
673 ReleaseReadLock(&client->lock);
678 * Compare the directory's ACL with the user's access rights in the client
679 * connection and return the user's and everybody else's access permissions
680 * in rights and anyrights, respectively
683 GetRights(struct client *client, struct acl_accessList *ACL,
684 afs_int32 * rights, afs_int32 * anyrights)
686 extern prlist SystemAnyUserCPS;
687 afs_int32 hrights = 0;
688 #ifndef AFS_PTHREAD_ENV
692 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
693 ViceLog(0, ("CheckRights failed\n"));
698 client_CheckRights(client, ACL, rights);
700 /* wait if somebody else is already doing the getCPS call */
702 while (client->host->hostFlags & HCPS_INPROGRESS) {
703 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
704 #ifdef AFS_PTHREAD_ENV
705 CV_WAIT(&client->host->cond, &host_glock_mutex);
706 #else /* AFS_PTHREAD_ENV */
708 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
709 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
710 #endif /* AFS_PTHREAD_ENV */
713 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
716 ("CheckRights: len=%u, for host=%s:%d\n",
717 client->host->hcps.prlist_len,
718 afs_inet_ntoa_r(client->host->host, hoststr),
719 ntohs(client->host->port)));
721 acl_CheckRights(ACL, &client->host->hcps, &hrights);
723 /* Allow system:admin the rights given with the -implicit option */
724 if (client_HasAsMember(client, SystemId))
725 *rights |= implicitAdminRights;
728 *anyrights |= hrights;
735 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
736 * a System:Administrator)
739 VanillaUser(struct client *client)
741 if (client_HasAsMember(client, SystemId))
742 return (0); /* not a system administrator, then you're "vanilla" */
749 * This unusual afs_int32-parameter routine encapsulates all volume package related
750 * operations together in a single function; it's called by almost all AFS
754 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
755 Vnode ** targetptr, int chkforDir, Vnode ** parent,
756 struct client **client, int locktype, afs_int32 * rights,
757 afs_int32 * anyrights)
759 struct acl_accessList *aCL; /* Internal access List */
760 int aCLSize; /* size of the access list */
761 Error errorCode = 0; /* return code to caller */
763 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
766 if (chkforDir == MustNOTBeDIR
767 && ((*targetptr)->disk.type == vDirectory))
769 else if (chkforDir == MustBeDIR
770 && ((*targetptr)->disk.type != vDirectory))
774 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
775 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
776 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
778 if (chkforDir == MustBeDIR)
779 osi_Assert((*parent) == 0);
781 if ((errorCode = GetClient(tcon, client)) != 0)
786 GetRights(*client, aCL, rights, anyrights);
787 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
788 if ((*targetptr)->disk.type != vDirectory) {
789 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
790 if ((*targetptr)->disk.owner == (*client)->ViceId)
791 (*rights) |= PRSFS_ADMINISTER;
793 (*rights) &= ~PRSFS_ADMINISTER;
795 #ifdef ADMIN_IMPLICIT_LOOKUP
796 /* admins get automatic lookup on everything */
797 if (!VanillaUser(*client))
798 (*rights) |= PRSFS_LOOKUP;
799 #endif /* ADMIN_IMPLICIT_LOOKUP */
802 } /*GetVolumePackage */
806 * This is the opposite of GetVolumePackage(), and is always used at the end of
807 * AFS calls to put back all used vnodes and the volume in the proper order!
810 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
811 Vnode * parentptr, Volume * volptr, struct client **client)
813 Error fileCode = 0; /* Error code returned by the volume package */
815 if (parentwhentargetnotdir) {
816 VPutVnode(&fileCode, parentwhentargetnotdir);
817 osi_Assert(!fileCode || (fileCode == VSALVAGE));
820 VPutVnode(&fileCode, targetptr);
821 osi_Assert(!fileCode || (fileCode == VSALVAGE));
824 VPutVnode(&fileCode, parentptr);
825 osi_Assert(!fileCode || (fileCode == VSALVAGE));
833 } /*PutVolumePackage */
836 VolumeOwner(struct client *client, Vnode * targetptr)
838 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
841 return (client->ViceId == owner);
844 * We don't have to check for host's cps since only regular
845 * viceid are volume owners.
847 return (client_HasAsMember(client, owner));
853 VolumeRootVnode(Vnode * targetptr)
855 return ((targetptr->vnodeNumber == ROOTVNODE)
856 && (targetptr->disk.uniquifier == 1));
858 } /*VolumeRootVnode */
861 * Check if target file has the proper access permissions for the Fetch
862 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
863 * StoreStatus) related calls
865 /* this code should probably just set a "priv" flag where all the audit events
866 * are now, and only generate the audit event once at the end of the routine,
867 * thus only generating the event if all the checks succeed, but only because
868 * of the privilege XXX
871 Check_PermissionRights(Vnode * targetptr, struct client *client,
872 afs_int32 rights, int CallingRoutine,
873 AFSStoreStatus * InStatus)
876 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
877 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
878 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
880 if (CallingRoutine & CHK_FETCH) {
881 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
882 if (targetptr->disk.type == vDirectory
883 || targetptr->disk.type == vSymlink) {
884 if (!(rights & PRSFS_LOOKUP)
885 #ifdef ADMIN_IMPLICIT_LOOKUP
886 /* grant admins fetch on all directories */
887 && VanillaUser(client)
888 #endif /* ADMIN_IMPLICIT_LOOKUP */
889 && !VolumeOwner(client, targetptr))
892 /* must have read access, or be owner and have insert access */
893 if (!(rights & PRSFS_READ)
894 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
897 if (CallingRoutine == CHK_FETCHDATA
898 && targetptr->disk.type == vFile)
899 #ifdef USE_GROUP_PERMS
900 if (!OWNSp(client, targetptr)
901 && !client_HasAsMember(client, targetptr->disk.owner)) {
903 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
907 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
912 * The check with the ownership below is a kludge to allow
913 * reading of files created with no read permission. The owner
914 * of the file is always allowed to read it.
916 if ((client->ViceId != targetptr->disk.owner)
917 && VanillaUser(client))
919 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
920 modeBits) ? 0 : EACCES);
922 } else { /* !VanillaUser(client) && !FetchData */
924 osi_audit(PrivilegeEvent, 0, AUD_ID,
925 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
928 } else { /* a store operation */
929 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
930 && (CallingRoutine != CHK_STOREACL)
931 && (targetptr->disk.type == vFile)) {
932 /* bypass protection checks on first store after a create
933 * for the creator; also prevent chowns during this time
934 * unless you are a system administrator */
935 /****** InStatus->Owner && UnixModeBits better be SET!! */
936 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
939 else if (VanillaUser(client))
940 return (EPERM); /* Was EACCES */
942 osi_audit(PrivilegeEvent, 0, AUD_ID,
943 (client ? client->ViceId : 0), AUD_INT,
944 CallingRoutine, AUD_END);
947 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
948 osi_audit(PrivilegeEvent, 0, AUD_ID,
949 (client ? client->ViceId : 0), AUD_INT,
950 CallingRoutine, AUD_END);
952 if (readonlyServer) {
955 if (CallingRoutine == CHK_STOREACL) {
956 if (!(rights & PRSFS_ADMINISTER)
957 && !VolumeOwner(client, targetptr))
959 } else { /* store data or status */
960 /* watch for chowns and chgrps */
961 if (CHOWN(InStatus, targetptr)
962 || CHGRP(InStatus, targetptr)) {
965 else if (VanillaUser(client))
966 return (EPERM); /* Was EACCES */
968 osi_audit(PrivilegeEvent, 0, AUD_ID,
969 (client ? client->ViceId : 0), AUD_INT,
970 CallingRoutine, AUD_END);
972 /* must be sysadmin to set suid/sgid bits */
973 if ((InStatus->Mask & AFS_SETMODE) &&
975 (InStatus->UnixModeBits & 0xc00) != 0) {
977 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
981 if (VanillaUser(client))
984 osi_audit(PrivSetID, 0, AUD_ID,
985 (client ? client->ViceId : 0), AUD_INT,
986 CallingRoutine, AUD_END);
988 if (CallingRoutine == CHK_STOREDATA) {
991 if (!(rights & PRSFS_WRITE))
993 /* Next thing is tricky. We want to prevent people
994 * from writing files sans 0200 bit, but we want
995 * creating new files with 0444 mode to work. We
996 * don't check the 0200 bit in the "you are the owner"
997 * path above, but here we check the bit. However, if
998 * you're a system administrator, we ignore the 0200
999 * bit anyway, since you may have fchowned the file,
1001 #ifdef USE_GROUP_PERMS
1002 if ((targetptr->disk.type == vFile)
1003 && VanillaUser(client)) {
1004 if (!OWNSp(client, targetptr)
1005 && !client_HasAsMember(client, targetptr->disk.owner)) {
1007 ((GROUPWRITE & targetptr->disk.modeBits)
1011 ((OWNERWRITE & targetptr->disk.modeBits)
1016 if ((targetptr->disk.type != vDirectory)
1017 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1020 if (VanillaUser(client))
1023 osi_audit(PrivilegeEvent, 0, AUD_ID,
1024 (client ? client->ViceId : 0),
1025 AUD_INT, CallingRoutine, AUD_END);
1027 } else { /* a status store */
1030 if (targetptr->disk.type == vDirectory) {
1031 if (!(rights & PRSFS_DELETE)
1032 && !(rights & PRSFS_INSERT))
1034 } else { /* a file or symlink */
1035 if (!(rights & PRSFS_WRITE))
1045 } /*Check_PermissionRights */
1049 * The Access List information is converted from its internal form in the
1050 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1051 * external form and returned back to the caller, via the AccessList
1055 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1056 struct AFSOpaque *AccessList)
1058 char *eACL; /* External access list placeholder */
1060 if (acl_Externalize_pr
1061 (hpr_IdToName, (targetptr->disk.type ==
1062 vDirectory ? VVnodeACL(targetptr) :
1063 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1066 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1067 acl_FreeExternalACL(&eACL);
1070 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1071 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1073 acl_FreeExternalACL(&eACL);
1076 } /*RXFetch_AccessList */
1080 * The Access List information is converted from its external form in the
1081 * input AccessList structure to the internal representation and copied into
1082 * the target dir's vnode storage.
1085 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1087 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1089 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1092 if ((newACL->size + 4) > VAclSize(targetptr))
1094 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1095 acl_FreeACL(&newACL);
1098 } /*RXStore_AccessList */
1101 /* In our current implementation, each successive data store (new file
1102 * data version) creates a new inode. This function creates the new
1103 * inode, copies the old inode's contents to the new one, remove the old
1104 * inode (i.e. decrement inode count -- if it's currently used the delete
1105 * will be delayed), and modify some fields (i.e. vnode's
1106 * disk.inodeNumber and cloned)
1108 #define COPYBUFFSIZE 8192
1109 #define MAXFSIZE (~(afs_fsize_t) 0)
1111 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1113 Inode ino, nearInode;
1120 int rc; /* return code */
1121 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1122 FdHandle_t *targFdP; /* Source Inode file handle */
1123 FdHandle_t *newFdP; /* Dest Inode file handle */
1125 if (targetptr->disk.type == vDirectory)
1126 DFlush(); /* just in case? */
1128 VN_GET_LEN(size, targetptr);
1136 buff = (char *)malloc(COPYBUFFSIZE);
1141 ino = VN_GET_INO(targetptr);
1142 if (!VALID_INO(ino)) {
1144 VTakeOffline(volptr);
1145 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1149 targFdP = IH_OPEN(targetptr->handle);
1150 if (targFdP == NULL) {
1153 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1154 targetptr->vnodeNumber, V_id(volptr), rc));
1156 VTakeOffline(volptr);
1160 nearInode = VN_GET_INO(targetptr);
1162 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1163 VPartitionPath(V_partition(volptr)), nearInode,
1164 V_id(volptr), targetptr->vnodeNumber,
1165 targetptr->disk.uniquifier,
1166 (int)targetptr->disk.dataVersion);
1167 if (!VALID_INO(ino)) {
1169 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1170 volptr->partition->name, V_id(volptr), errno));
1175 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1176 newFdP = IH_OPEN(newH);
1177 osi_Assert(newFdP != NULL);
1181 if (size > COPYBUFFSIZE) { /* more than a buffer */
1182 length = COPYBUFFSIZE;
1183 size -= COPYBUFFSIZE;
1188 rdlen = FDH_PREAD(targFdP, buff, length, done);
1189 if (rdlen == length) {
1190 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1194 /* Callers of this function are not prepared to recover
1195 * from error that put the filesystem in an inconsistent
1196 * state. Make sure that we force the volume off-line if
1197 * we some error other than ENOSPC - 4.29.99)
1199 * In case we are unable to write the required bytes, and the
1200 * error code indicates that the disk is full, we roll-back to
1201 * the initial state.
1203 if ((rdlen != length) || (wrlen != length)) {
1204 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1206 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1207 volptr->partition->name, V_id(volptr)));
1208 /* remove destination inode which was partially copied till now */
1209 FDH_REALLYCLOSE(newFdP);
1211 FDH_REALLYCLOSE(targFdP);
1212 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1215 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1216 rc, V_id(volptr), volptr->partition->name));
1217 VTakeOffline(volptr);
1222 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1223 * since we never do any I/O anywhere near 2^32 bytes at a
1224 * time, just case to an unsigned int for printing */
1227 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1228 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1229 (unsigned)wrlen, errno));
1230 #if defined(AFS_DEMAND_ATTACH_FS)
1231 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1233 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1235 /* Decrement this inode so salvager doesn't find it. */
1236 FDH_REALLYCLOSE(newFdP);
1238 FDH_REALLYCLOSE(targFdP);
1239 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1241 VTakeOffline(volptr);
1245 #ifndef AFS_PTHREAD_ENV
1247 #endif /* !AFS_PTHREAD_ENV */
1249 FDH_REALLYCLOSE(targFdP);
1250 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1251 V_parentId(volptr));
1253 IH_RELEASE(targetptr->handle);
1255 rc = FDH_SYNC(newFdP);
1256 osi_Assert(rc == 0);
1258 targetptr->handle = newH;
1259 VN_SET_INO(targetptr, ino);
1260 targetptr->disk.cloned = 0;
1261 /* Internal change to vnode, no user level change to volume - def 5445 */
1262 targetptr->changed_oldTime = 1;
1264 return 0; /* success */
1268 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1271 char *buff = malloc(COPYBUFFSIZE);
1276 afs_foff_t done = off;
1278 if (size > FDH_SIZE(targFdP) - off)
1279 size = FDH_SIZE(targFdP) - off;
1282 if (size > COPYBUFFSIZE) { /* more than a buffer */
1283 length = COPYBUFFSIZE;
1284 size -= COPYBUFFSIZE;
1289 rdlen = FDH_PREAD(targFdP, buff, length, done);
1290 if (rdlen == length) {
1291 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1297 if ((rdlen != length) || (wrlen != length)) {
1298 /* no error recovery, at the worst we'll have a "hole"
1310 * Common code to handle with removing the Name (file when it's called from
1311 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1312 * given directory, parentptr.
1314 int DT1 = 0, DT0 = 0;
1316 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1317 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1319 DirHandle childdir; /* Handle for dir package I/O */
1320 Error errorCode = 0;
1324 /* watch for invalid names */
1325 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1327 if (parentptr->disk.cloned) {
1328 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1329 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1331 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1337 /* check that the file is in the directory */
1338 SetDirHandle(dir, parentptr);
1339 if (Lookup(dir, Name, fileFid))
1341 fileFid->Volume = V_id(volptr);
1343 /* just-in-case check for something causing deadlock */
1344 if (fileFid->Vnode == parentptr->vnodeNumber)
1347 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1351 if (ChkForDir == MustBeDIR) {
1352 if ((*targetptr)->disk.type != vDirectory)
1354 } else if ((*targetptr)->disk.type == vDirectory)
1357 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1359 * If the uniquifiers dont match then instead of asserting
1360 * take the volume offline and return VSALVAGE
1362 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1363 VTakeOffline(volptr);
1365 ("Volume %u now offline, must be salvaged.\n",
1367 errorCode = VSALVAGE;
1371 if (ChkForDir == MustBeDIR) {
1372 SetDirHandle(&childdir, *targetptr);
1373 if (IsEmpty(&childdir) != 0)
1375 DZap((afs_int32 *) &childdir);
1377 (*targetptr)->delete = 1;
1378 } else if ((--(*targetptr)->disk.linkCount) == 0)
1379 (*targetptr)->delete = 1;
1380 if ((*targetptr)->delete) {
1381 if (VN_GET_INO(*targetptr)) {
1383 IH_REALLYCLOSE((*targetptr)->handle);
1385 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1386 V_parentId(volptr));
1387 IH_RELEASE((*targetptr)->handle);
1388 if (errorCode == -1) {
1390 ("DT: inode=%s, name=%s, errno=%d\n",
1391 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1393 if (errno != ENOENT)
1395 VTakeOffline(volptr);
1397 ("Volume %u now offline, must be salvaged.\n",
1405 VN_SET_INO(*targetptr, (Inode) 0);
1407 afs_fsize_t adjLength;
1408 VN_GET_LEN(adjLength, *targetptr);
1409 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1413 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1415 code = Delete(dir, (char *)Name);
1418 ("Error %d deleting %s\n", code,
1419 (((*targetptr)->disk.type ==
1420 Directory) ? "directory" : "file")));
1421 VTakeOffline(volptr);
1423 ("Volume %u now offline, must be salvaged.\n",
1436 * This routine updates the parent directory's status block after the
1437 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1438 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1442 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1443 int author, int linkcount,
1444 #if FS_STATS_DETAILED
1445 char a_inSameNetwork
1446 #endif /* FS_STATS_DETAILED */
1449 afs_fsize_t newlength; /* Holds new directory length */
1450 afs_fsize_t parentLength;
1452 #if FS_STATS_DETAILED
1453 Date currDate; /*Current date */
1454 int writeIdx; /*Write index to bump */
1455 int timeIdx; /*Authorship time index to bump */
1456 #endif /* FS_STATS_DETAILED */
1458 parentptr->disk.dataVersion++;
1459 newlength = (afs_fsize_t) Length(dir);
1461 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1462 * (create, symlink, link, makedir) so we need to check if we have enough space
1463 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1464 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1466 VN_GET_LEN(parentLength, parentptr);
1467 if (nBlocks(newlength) != nBlocks(parentLength)) {
1468 VAdjustDiskUsage(&errorCode, volptr,
1469 (nBlocks(newlength) - nBlocks(parentLength)),
1470 (nBlocks(newlength) - nBlocks(parentLength)));
1472 VN_SET_LEN(parentptr, newlength);
1474 #if FS_STATS_DETAILED
1476 * Update directory write stats for this volume. Note that the auth
1477 * counter is located immediately after its associated ``distance''
1480 if (a_inSameNetwork)
1481 writeIdx = VOL_STATS_SAME_NET;
1483 writeIdx = VOL_STATS_DIFF_NET;
1484 V_stat_writes(volptr, writeIdx)++;
1485 if (author != AnonymousID) {
1486 V_stat_writes(volptr, writeIdx + 1)++;
1490 * Update the volume's authorship information in response to this
1491 * directory operation. Get the current time, decide to which time
1492 * slot this operation belongs, and bump the appropriate slot.
1494 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1496 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1497 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1498 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1499 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1500 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1501 if (parentptr->disk.author == author) {
1502 V_stat_dirSameAuthor(volptr, timeIdx)++;
1504 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1506 #endif /* FS_STATS_DETAILED */
1508 parentptr->disk.author = author;
1509 parentptr->disk.linkCount = linkcount;
1510 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1511 parentptr->disk.serverModifyTime = FT_ApproxTime();
1512 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1517 * Update the target file's (or dir's) status block after the specified
1518 * operation is complete. Note that some other fields maybe updated by
1519 * the individual module.
1522 /* XXX INCOMPLETE - More attention is needed here! */
1524 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1525 struct client *client, AFSStoreStatus * InStatus,
1526 Vnode * parentptr, Volume * volptr,
1529 #if FS_STATS_DETAILED
1530 Date currDate; /*Current date */
1531 int writeIdx; /*Write index to bump */
1532 int timeIdx; /*Authorship time index to bump */
1533 #endif /* FS_STATS_DETAILED */
1535 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1536 targetptr->disk.parent = parentptr->vnodeNumber;
1537 VN_SET_LEN(targetptr, length);
1538 /* targetptr->disk.group = 0; save some cycles */
1539 targetptr->disk.modeBits = 0777;
1540 targetptr->disk.owner = client->ViceId;
1541 targetptr->disk.dataVersion = 0; /* consistent with the client */
1542 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1543 /* the inode was created in Alloc_NewVnode() */
1545 #if FS_STATS_DETAILED
1547 * Update file write stats for this volume. Note that the auth
1548 * counter is located immediately after its associated ``distance''
1551 if (client->InSameNetwork)
1552 writeIdx = VOL_STATS_SAME_NET;
1554 writeIdx = VOL_STATS_DIFF_NET;
1555 V_stat_writes(volptr, writeIdx)++;
1556 if (client->ViceId != AnonymousID) {
1557 V_stat_writes(volptr, writeIdx + 1)++;
1561 * We only count operations that DON'T involve creating new objects
1562 * (files, symlinks, directories) or simply setting status as
1563 * authorship-change operations.
1565 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1567 * Update the volume's authorship information in response to this
1568 * file operation. Get the current time, decide to which time
1569 * slot this operation belongs, and bump the appropriate slot.
1571 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1574 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1575 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1576 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1577 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1578 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1579 VOL_STATS_TIME_IDX_5);
1580 if (targetptr->disk.author == client->ViceId) {
1581 V_stat_fileSameAuthor(volptr, timeIdx)++;
1583 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1586 #endif /* FS_STATS_DETAILED */
1588 if (!(Caller & TVS_SSTATUS))
1589 targetptr->disk.author = client->ViceId;
1590 if (Caller & TVS_SDATA) {
1591 targetptr->disk.dataVersion++;
1592 if (VanillaUser(client)) {
1593 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1594 #ifdef CREATE_SGUID_ADMIN_ONLY
1595 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1599 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1600 /* store status, must explicitly request to change the date */
1601 if (InStatus->Mask & AFS_SETMODTIME)
1602 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1603 } else { /* other: date always changes, but perhaps to what is specified by caller */
1604 targetptr->disk.unixModifyTime =
1605 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1606 ClientModTime : FT_ApproxTime());
1608 if (InStatus->Mask & AFS_SETOWNER) {
1609 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1610 if (VanillaUser(client)) {
1611 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1612 #ifdef CREATE_SGUID_ADMIN_ONLY
1613 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1616 targetptr->disk.owner = InStatus->Owner;
1617 if (VolumeRootVnode(targetptr)) {
1618 Error errorCode = 0; /* what should be done with this? */
1620 V_owner(targetptr->volumePtr) = InStatus->Owner;
1621 VUpdateVolume(&errorCode, targetptr->volumePtr);
1624 if (InStatus->Mask & AFS_SETMODE) {
1625 int modebits = InStatus->UnixModeBits;
1626 #define CREATE_SGUID_ADMIN_ONLY 1
1627 #ifdef CREATE_SGUID_ADMIN_ONLY
1628 if (VanillaUser(client))
1629 modebits = modebits & 0777;
1631 if (VanillaUser(client)) {
1632 targetptr->disk.modeBits = modebits;
1634 targetptr->disk.modeBits = modebits;
1637 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1638 CHK_STOREDATA, AUD_END);
1642 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1643 CHK_STORESTATUS, AUD_END);
1650 targetptr->disk.serverModifyTime = FT_ApproxTime();
1651 if (InStatus->Mask & AFS_SETGROUP)
1652 targetptr->disk.group = InStatus->Group;
1653 /* vnode changed : to be written back by VPutVnode */
1654 targetptr->changed_newTime = 1;
1656 } /*Update_TargetVnodeStatus */
1660 * Fills the CallBack structure with the expiration time and type of callback
1661 * structure. Warning: this function is currently incomplete.
1664 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1666 /* CallBackTime could not be 0 */
1667 if (CallBackTime == 0) {
1668 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1669 CallBack->ExpirationTime = 0;
1671 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1672 CallBack->CallBackVersion = CALLBACK_VERSION;
1673 CallBack->CallBackType = CB_SHARED; /* The default for now */
1675 } /*SetCallBackStruct */
1679 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1680 * allocation; if some error occured (exceeded volume quota or partition
1681 * was full, or whatever), it frees the space back and returns the code.
1682 * We usually pre-adjust the volume space to make sure that there's
1683 * enough space before consuming some.
1686 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1687 afs_sfsize_t checkLength)
1692 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1694 VAdjustDiskUsage(&nc, volptr, -length, 0);
1695 if (rc == VOVERQUOTA) {
1697 ("Volume %u (%s) is full\n", V_id(volptr),
1701 if (rc == VDISKFULL) {
1703 ("Partition %s that contains volume %u is full\n",
1704 volptr->partition->name, V_id(volptr)));
1707 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1712 } /*AdjustDiskUsage */
1715 * Common code that handles the creation of a new file (SAFS_CreateFile and
1716 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1719 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1720 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1721 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1723 Error errorCode = 0; /* Error code returned back */
1726 Inode nearInode; /* hint for inode allocation in solaris */
1730 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1731 BlocksPreallocatedForVnode))) {
1733 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1734 (afs_intmax_t) BlocksPreallocatedForVnode));
1738 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1739 if (errorCode != 0) {
1740 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1743 OutFid->Volume = V_id(volptr);
1744 OutFid->Vnode = (*targetptr)->vnodeNumber;
1745 OutFid->Unique = (*targetptr)->disk.uniquifier;
1747 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1749 /* create the inode now itself */
1751 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1752 VPartitionPath(V_partition(volptr)), nearInode,
1753 V_id(volptr), (*targetptr)->vnodeNumber,
1754 (*targetptr)->disk.uniquifier, 1);
1756 /* error in creating inode */
1757 if (!VALID_INO(inode)) {
1759 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1760 (*targetptr)->volumePtr->header->diskstuff.id,
1761 (*targetptr)->vnodeNumber, errno));
1762 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1763 (*targetptr)->delete = 1; /* delete vnode */
1766 VN_SET_INO(*targetptr, inode);
1767 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1769 /* copy group from parent dir */
1770 (*targetptr)->disk.group = parentptr->disk.group;
1772 if (parentptr->disk.cloned) {
1773 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1774 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1775 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1776 /* delete the vnode previously allocated */
1777 (*targetptr)->delete = 1;
1778 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1779 IH_REALLYCLOSE((*targetptr)->handle);
1780 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1782 ("Alloc_NewVnode: partition %s idec %s failed\n",
1783 volptr->partition->name, PrintInode(stmp, inode)));
1784 IH_RELEASE((*targetptr)->handle);
1790 /* add the name to the directory */
1791 SetDirHandle(dir, parentptr);
1792 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1793 (*targetptr)->delete = 1;
1794 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1795 IH_REALLYCLOSE((*targetptr)->handle);
1796 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1798 ("Alloc_NewVnode: partition %s idec %s failed\n",
1799 volptr->partition->name, PrintInode(stmp, inode)));
1800 IH_RELEASE((*targetptr)->handle);
1806 } /*Alloc_NewVnode */
1810 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1814 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1816 int Time; /* Used for time */
1817 int writeVnode = targetptr->changed_oldTime; /* save original status */
1819 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1820 Time = FT_ApproxTime();
1821 switch (LockingType) {
1824 if (Time > targetptr->disk.lock.lockTime)
1825 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1827 Time += AFS_LOCKWAIT;
1828 if (LockingType == LockRead) {
1829 if ( !(rights & PRSFS_LOCK) &&
1830 !(rights & PRSFS_WRITE) &&
1831 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1834 if (targetptr->disk.lock.lockCount >= 0) {
1835 ++(targetptr->disk.lock.lockCount);
1836 targetptr->disk.lock.lockTime = Time;
1839 } else if (LockingType == LockWrite) {
1840 if ( !(rights & PRSFS_WRITE) &&
1841 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1844 if (targetptr->disk.lock.lockCount == 0) {
1845 targetptr->disk.lock.lockCount = -1;
1846 targetptr->disk.lock.lockTime = Time;
1852 Time += AFS_LOCKWAIT;
1853 if (targetptr->disk.lock.lockCount != 0)
1854 targetptr->disk.lock.lockTime = Time;
1859 if ((--targetptr->disk.lock.lockCount) <= 0)
1860 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1864 targetptr->changed_oldTime = writeVnode; /* restore old status */
1865 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1868 } /*HandleLocking */
1870 /* 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. */
1873 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1877 if (!(rights & Prfs_Mode))
1879 if ((targetptr->disk.type != vDirectory)
1880 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1886 * If some flags (i.e. min or max quota) are set, the volume's in disk
1887 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1888 * update, if applicable.
1891 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1892 char *Name, char *OfflineMsg, char *Motd)
1894 Error errorCode = 0;
1896 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1897 V_minquota(volptr) = StoreVolStatus->MinQuota;
1898 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1899 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1900 if (strlen(OfflineMsg) > 0) {
1901 strcpy(V_offlineMessage(volptr), OfflineMsg);
1903 if (strlen(Name) > 0) {
1904 strcpy(V_name(volptr), Name);
1906 #if OPENAFS_VOL_STATS
1908 * We don't overwrite the motd field, since it's now being used
1912 if (strlen(Motd) > 0) {
1913 strcpy(V_motd(volptr), Motd);
1915 #endif /* FS_STATS_DETAILED */
1916 VUpdateVolume(&errorCode, volptr);
1919 } /*RXUpdate_VolumeStatus */
1923 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1924 char **motd, Volume * volptr)
1928 status->Vid = V_id(volptr);
1929 status->ParentId = V_parentId(volptr);
1930 status->Online = V_inUse(volptr);
1931 status->InService = V_inService(volptr);
1932 status->Blessed = V_blessed(volptr);
1933 status->NeedsSalvage = V_needsSalvaged(volptr);
1934 if (VolumeWriteable(volptr))
1935 status->Type = ReadWrite;
1937 status->Type = ReadOnly;
1938 status->MinQuota = V_minquota(volptr);
1939 status->MaxQuota = V_maxquota(volptr);
1940 status->BlocksInUse = V_diskused(volptr);
1941 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1942 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1944 /* now allocate and copy these things; they're freed by the RXGEN stub */
1945 temp = strlen(V_name(volptr)) + 1;
1946 *name = malloc(temp);
1948 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1949 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1951 strcpy(*name, V_name(volptr));
1952 temp = strlen(V_offlineMessage(volptr)) + 1;
1953 *offMsg = malloc(temp);
1955 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1956 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1958 strcpy(*offMsg, V_offlineMessage(volptr));
1959 #if OPENAFS_VOL_STATS
1962 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1963 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1965 strcpy(*motd, nullString);
1967 temp = strlen(V_motd(volptr)) + 1;
1968 *motd = malloc(temp);
1970 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1971 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1973 strcpy(*motd, V_motd(volptr));
1974 #endif /* FS_STATS_DETAILED */
1976 } /*RXGetVolumeStatus */
1980 FileNameOK(char *aname)
1985 /* watch for @sys on the right */
1986 if (strcmp(aname + i - 4, "@sys") == 0)
1989 while ((tc = *aname++)) {
1991 return 0; /* very bad character to encounter */
1993 return 1; /* file name is ok */
1999 * This variant of symlink is expressly to support the AFS/DFS translator
2000 * and is not supported by the AFS fileserver. We just return EINVAL.
2001 * The cache manager should not generate this call to an AFS cache manager.
2004 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2005 char *LinkContents, struct AFSStoreStatus *InStatus,
2006 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2007 struct AFSFetchStatus *OutDirStatus,
2008 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2014 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2015 struct FsCmdInputs * Inputs,
2016 struct FsCmdOutputs * Outputs)
2020 switch (Inputs->command) {
2024 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2025 Inputs->command, Outputs->code));
2030 static struct afs_buffer {
2031 struct afs_buffer *next;
2032 } *freeBufferList = 0;
2033 static int afs_buffersAlloced = 0;
2036 FreeSendBuffer(struct afs_buffer *adata)
2039 afs_buffersAlloced--;
2040 adata->next = freeBufferList;
2041 freeBufferList = adata;
2045 } /*FreeSendBuffer */
2047 /* allocate space for sender */
2049 AllocSendBuffer(void)
2051 struct afs_buffer *tp;
2054 afs_buffersAlloced++;
2055 if (!freeBufferList) {
2058 tmp = malloc(sendBufSize);
2060 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2061 osi_Panic("Failed malloc in AllocSendBuffer\n");
2065 tp = freeBufferList;
2066 freeBufferList = tp->next;
2070 } /*AllocSendBuffer */
2071 #endif /* HAVE_PIOV */
2074 * This routine returns the status info associated with the targetptr vnode
2075 * in the AFSFetchStatus structure. Some of the newer fields, such as
2076 * SegSize and Group are not yet implemented
2080 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2081 afs_int32 anyrights, Vnode * parentptr)
2083 /* initialize return status from a vnode */
2084 status->InterfaceVersion = 1;
2085 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2086 status->errorCode = 0;
2087 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2088 if (targetptr->disk.type == vFile)
2089 status->FileType = File;
2090 else if (targetptr->disk.type == vDirectory)
2091 status->FileType = Directory;
2092 else if (targetptr->disk.type == vSymlink)
2093 status->FileType = SymbolicLink;
2095 status->FileType = Invalid; /*invalid type field */
2096 status->LinkCount = targetptr->disk.linkCount;
2098 afs_fsize_t targetLen;
2099 VN_GET_LEN(targetLen, targetptr);
2100 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2102 status->DataVersion = targetptr->disk.dataVersion;
2103 status->Author = targetptr->disk.author;
2104 status->Owner = targetptr->disk.owner;
2105 status->CallerAccess = rights;
2106 status->AnonymousAccess = anyrights;
2107 status->UnixModeBits = targetptr->disk.modeBits;
2108 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2109 status->ParentVnode =
2110 (status->FileType ==
2111 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2112 status->ParentUnique =
2113 (status->FileType ==
2114 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2115 status->ServerModTime = targetptr->disk.serverModifyTime;
2116 status->Group = targetptr->disk.group;
2117 status->lockCount = targetptr->disk.lock.lockCount;
2118 status->errorCode = 0;
2124 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2125 afs_sfsize_t Pos, afs_sfsize_t Len,
2126 struct AFSFetchStatus *OutStatus,
2127 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2130 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2131 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2132 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2133 Error errorCode = 0; /* return code to caller */
2134 Error fileCode = 0; /* return code from vol package */
2135 Volume *volptr = 0; /* pointer to the volume */
2136 struct client *client = 0; /* pointer to the client data */
2137 struct rx_connection *tcon; /* the connection we're part of */
2139 afs_int32 rights, anyrights; /* rights for this and any user */
2140 struct client *t_client = NULL; /* tmp ptr to client data */
2141 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2142 #if FS_STATS_DETAILED
2143 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2144 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2145 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2146 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2147 struct timeval elapsedTime; /* Transfer time */
2148 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2149 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2150 int readIdx; /* Index of read stats array to bump */
2151 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2154 * Set our stats pointers, remember when the RPC operation started, and
2155 * tally the operation.
2157 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2158 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2162 FT_GetTimeOfDay(&opStartTime, 0);
2163 #endif /* FS_STATS_DETAILED */
2166 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2169 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2171 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2174 /* Get ptr to client data for user Id for logging */
2175 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2176 logHostAddr.s_addr = rxr_HostOf(tcon);
2178 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2179 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2180 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2182 * Get volume/vnode for the fetched file; caller's access rights to
2183 * it are also returned
2186 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2187 &parentwhentargetnotdir, &client, READ_LOCK,
2188 &rights, &anyrights)))
2191 SetVolumeSync(Sync, volptr);
2193 #if FS_STATS_DETAILED
2195 * Remember that another read operation was performed.
2198 if (client->InSameNetwork)
2199 readIdx = VOL_STATS_SAME_NET;
2201 readIdx = VOL_STATS_DIFF_NET;
2202 V_stat_reads(volptr, readIdx)++;
2203 if (client->ViceId != AnonymousID) {
2204 V_stat_reads(volptr, readIdx + 1)++;
2207 #endif /* FS_STATS_DETAILED */
2208 /* Check whether the caller has permission access to fetch the data */
2210 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2214 * Drop the read lock on the parent directory after saving the parent
2215 * vnode information we need to pass to GetStatus
2217 if (parentwhentargetnotdir != NULL) {
2218 tparentwhentargetnotdir = *parentwhentargetnotdir;
2219 VPutVnode(&fileCode, parentwhentargetnotdir);
2220 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2221 parentwhentargetnotdir = NULL;
2223 #if FS_STATS_DETAILED
2225 * Remember when the data transfer started.
2227 FT_GetTimeOfDay(&xferStartTime, 0);
2228 #endif /* FS_STATS_DETAILED */
2230 /* actually do the data transfer */
2231 #if FS_STATS_DETAILED
2233 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2234 &bytesToXfer, &bytesXferred);
2237 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2239 #endif /* FS_STATS_DETAILED */
2241 #if FS_STATS_DETAILED
2243 * At this point, the data transfer is done, for good or ill. Remember
2244 * when the transfer ended, bump the number of successes/failures, and
2245 * integrate the transfer size and elapsed time into the stats. If the
2246 * operation failed, we jump to the appropriate point.
2248 FT_GetTimeOfDay(&xferStopTime, 0);
2250 (xferP->numXfers)++;
2252 (xferP->numSuccesses)++;
2255 * Bump the xfer sum by the number of bytes actually sent, NOT the
2258 tot_bytesXferred += bytesXferred;
2259 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2260 tot_bytesXferred &= 0x3FF;
2261 if (bytesXferred < xferP->minBytes)
2262 xferP->minBytes = bytesXferred;
2263 if (bytesXferred > xferP->maxBytes)
2264 xferP->maxBytes = bytesXferred;
2267 * Tally the size of the object. Note: we tally the actual size,
2268 * NOT the number of bytes that made it out over the wire.
2270 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2271 (xferP->count[0])++;
2272 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2273 (xferP->count[1])++;
2274 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2275 (xferP->count[2])++;
2276 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2277 (xferP->count[3])++;
2278 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2279 (xferP->count[4])++;
2280 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2281 (xferP->count[5])++;
2282 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2283 (xferP->count[6])++;
2284 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2285 (xferP->count[7])++;
2287 (xferP->count[8])++;
2289 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2290 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2291 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2292 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2293 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2295 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2296 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2301 * Finally, go off to tell our caller the bad news in case the
2306 #endif /* FS_STATS_DETAILED */
2308 /* write back the OutStatus from the target vnode */
2309 GetStatus(targetptr, OutStatus, rights, anyrights,
2310 &tparentwhentargetnotdir);
2312 /* if a r/w volume, promise a callback to the caller */
2313 if (VolumeWriteable(volptr))
2314 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2316 struct AFSFid myFid;
2317 memset(&myFid, 0, sizeof(struct AFSFid));
2318 myFid.Volume = Fid->Volume;
2319 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2323 /* Update and store volume/vnode and parent vnodes back */
2324 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2326 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2327 errorCode = CallPostamble(tcon, errorCode, thost);
2329 #if FS_STATS_DETAILED
2330 FT_GetTimeOfDay(&opStopTime, 0);
2331 if (errorCode == 0) {
2333 (opP->numSuccesses)++;
2334 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2335 fs_stats_AddTo((opP->sumTime), elapsedTime);
2336 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2337 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2338 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2340 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2341 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2345 #endif /* FS_STATS_DETAILED */
2347 osi_auditU(acall, FetchDataEvent, errorCode,
2348 AUD_ID, t_client ? t_client->ViceId : 0,
2349 AUD_FID, Fid, AUD_END);
2352 } /*SRXAFS_FetchData */
2355 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2356 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2357 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2359 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2364 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2365 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2366 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2369 afs_sfsize_t tPos, tLen;
2371 tPos = (afs_sfsize_t) Pos;
2372 tLen = (afs_sfsize_t) Len;
2375 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2381 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2382 struct AFSOpaque * AccessList,
2383 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2385 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2386 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2387 Error errorCode = 0; /* return error code to caller */
2388 Volume *volptr = 0; /* pointer to the volume */
2389 struct client *client = 0; /* pointer to the client data */
2390 afs_int32 rights, anyrights; /* rights for this and any user */
2391 struct rx_connection *tcon = rx_ConnectionOf(acall);
2393 struct client *t_client = NULL; /* tmp ptr to client data */
2394 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2395 #if FS_STATS_DETAILED
2396 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2397 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2398 struct timeval elapsedTime; /* Transfer time */
2401 * Set our stats pointer, remember when the RPC operation started, and
2402 * tally the operation.
2404 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2408 FT_GetTimeOfDay(&opStartTime, 0);
2409 #endif /* FS_STATS_DETAILED */
2412 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2415 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2417 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2420 /* Get ptr to client data for user Id for logging */
2421 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2422 logHostAddr.s_addr = rxr_HostOf(tcon);
2424 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2425 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2426 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2428 AccessList->AFSOpaque_len = 0;
2429 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2430 if (!AccessList->AFSOpaque_val) {
2431 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2432 osi_Panic("Failed malloc in SRXAFS_FetchACL\n");
2436 * Get volume/vnode for the fetched file; caller's access rights to it
2440 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2441 &parentwhentargetnotdir, &client, READ_LOCK,
2442 &rights, &anyrights)))
2445 SetVolumeSync(Sync, volptr);
2447 /* Check whether we have permission to fetch the ACL */
2449 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2452 /* Get the Access List from the dir's vnode */
2454 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2457 /* Get OutStatus back From the target Vnode */
2458 GetStatus(targetptr, OutStatus, rights, anyrights,
2459 parentwhentargetnotdir);
2462 /* Update and store volume/vnode and parent vnodes back */
2463 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2466 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2467 AccessList->AFSOpaque_val));
2468 errorCode = CallPostamble(tcon, errorCode, thost);
2470 #if FS_STATS_DETAILED
2471 FT_GetTimeOfDay(&opStopTime, 0);
2472 if (errorCode == 0) {
2474 (opP->numSuccesses)++;
2475 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2476 fs_stats_AddTo((opP->sumTime), elapsedTime);
2477 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2478 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2479 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2481 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2482 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2486 #endif /* FS_STATS_DETAILED */
2488 osi_auditU(acall, FetchACLEvent, errorCode,
2489 AUD_ID, t_client ? t_client->ViceId : 0,
2491 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2493 } /*SRXAFS_FetchACL */
2497 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2498 * merged into it when possible.
2502 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2503 struct AFSFetchStatus *OutStatus,
2504 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2506 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2507 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2508 Error errorCode = 0; /* return code to caller */
2509 Volume *volptr = 0; /* pointer to the volume */
2510 struct client *client = 0; /* pointer to the client data */
2511 afs_int32 rights, anyrights; /* rights for this and any user */
2512 struct client *t_client = NULL; /* tmp ptr to client data */
2513 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2514 struct rx_connection *tcon = rx_ConnectionOf(acall);
2516 /* Get ptr to client data for user Id for logging */
2517 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2518 logHostAddr.s_addr = rxr_HostOf(tcon);
2520 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2521 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2522 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2524 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2527 * Get volume/vnode for the fetched file; caller's rights to it are
2531 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2532 &parentwhentargetnotdir, &client, READ_LOCK,
2533 &rights, &anyrights)))
2534 goto Bad_FetchStatus;
2536 /* set volume synchronization information */
2537 SetVolumeSync(Sync, volptr);
2539 /* Are we allowed to fetch Fid's status? */
2540 if (targetptr->disk.type != vDirectory) {
2542 Check_PermissionRights(targetptr, client, rights,
2543 CHK_FETCHSTATUS, 0))) {
2544 if (rx_GetCallAbortCode(acall) == errorCode)
2545 rx_SetCallAbortCode(acall, 0);
2546 goto Bad_FetchStatus;
2550 /* set OutStatus From the Fid */
2551 GetStatus(targetptr, OutStatus, rights, anyrights,
2552 parentwhentargetnotdir);
2554 /* If a r/w volume, also set the CallBack state */
2555 if (VolumeWriteable(volptr))
2556 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2558 struct AFSFid myFid;
2559 memset(&myFid, 0, sizeof(struct AFSFid));
2560 myFid.Volume = Fid->Volume;
2561 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2565 /* Update and store volume/vnode and parent vnodes back */
2566 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2568 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2571 } /*SAFSS_FetchStatus */
2575 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2576 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2577 struct AFSVolSync * Sync)
2581 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2582 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2583 Error errorCode = 0; /* return code to caller */
2584 Volume *volptr = 0; /* pointer to the volume */
2585 struct client *client = 0; /* pointer to the client data */
2586 afs_int32 rights, anyrights; /* rights for this and any user */
2587 struct AFSFid *tfid; /* file id we're dealing with now */
2588 struct rx_connection *tcon = rx_ConnectionOf(acall);
2590 struct client *t_client = NULL; /* tmp pointer to the client data */
2591 #if FS_STATS_DETAILED
2592 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2593 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2594 struct timeval elapsedTime; /* Transfer time */
2597 * Set our stats pointer, remember when the RPC operation started, and
2598 * tally the operation.
2600 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2604 FT_GetTimeOfDay(&opStartTime, 0);
2605 #endif /* FS_STATS_DETAILED */
2607 ViceLog(1, ("SAFS_BulkStatus\n"));
2609 AFSCallStats.TotalCalls++;
2611 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2612 if (nfiles <= 0) { /* Sanity check */
2614 goto Audit_and_Return;
2617 /* allocate space for return output parameters */
2618 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2619 malloc(nfiles * sizeof(struct AFSFetchStatus));
2620 if (!OutStats->AFSBulkStats_val) {
2621 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2622 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2624 OutStats->AFSBulkStats_len = nfiles;
2625 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2626 malloc(nfiles * sizeof(struct AFSCallBack));
2627 if (!CallBacks->AFSCBs_val) {
2628 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2629 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2631 CallBacks->AFSCBs_len = nfiles;
2633 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2634 goto Bad_BulkStatus;
2636 tfid = Fids->AFSCBFids_val;
2637 for (i = 0; i < nfiles; i++, tfid++) {
2639 * Get volume/vnode for the fetched file; caller's rights to it
2643 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2644 &parentwhentargetnotdir, &client, READ_LOCK,
2645 &rights, &anyrights)))
2646 goto Bad_BulkStatus;
2647 /* set volume synchronization information, but only once per call */
2649 SetVolumeSync(Sync, volptr);
2651 /* Are we allowed to fetch Fid's status? */
2652 if (targetptr->disk.type != vDirectory) {
2654 Check_PermissionRights(targetptr, client, rights,
2655 CHK_FETCHSTATUS, 0))) {
2656 if (rx_GetCallAbortCode(acall) == errorCode)
2657 rx_SetCallAbortCode(acall, 0);
2658 goto Bad_BulkStatus;
2662 /* set OutStatus From the Fid */
2663 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2664 anyrights, parentwhentargetnotdir);
2666 /* If a r/w volume, also set the CallBack state */
2667 if (VolumeWriteable(volptr))
2668 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2669 &CallBacks->AFSCBs_val[i]);
2671 struct AFSFid myFid;
2672 memset(&myFid, 0, sizeof(struct AFSFid));
2673 myFid.Volume = tfid->Volume;
2674 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2675 &CallBacks->AFSCBs_val[i]);
2678 /* put back the file ID and volume */
2679 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2681 parentwhentargetnotdir = (Vnode *) 0;
2682 targetptr = (Vnode *) 0;
2683 volptr = (Volume *) 0;
2684 client = (struct client *)0;
2688 /* Update and store volume/vnode and parent vnodes back */
2689 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2691 errorCode = CallPostamble(tcon, errorCode, thost);
2693 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2695 #if FS_STATS_DETAILED
2696 FT_GetTimeOfDay(&opStopTime, 0);
2697 if (errorCode == 0) {
2699 (opP->numSuccesses)++;
2700 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2701 fs_stats_AddTo((opP->sumTime), elapsedTime);
2702 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2703 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2704 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2706 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2707 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2711 #endif /* FS_STATS_DETAILED */
2714 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2715 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2716 AUD_ID, t_client ? t_client->ViceId : 0,
2717 AUD_FIDS, Fids, AUD_END);
2720 } /*SRXAFS_BulkStatus */
2724 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2725 struct AFSBulkStats * OutStats,
2726 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2730 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2731 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2732 Error errorCode = 0; /* return code to caller */
2733 Volume *volptr = 0; /* pointer to the volume */
2734 struct client *client = 0; /* pointer to the client data */
2735 afs_int32 rights, anyrights; /* rights for this and any user */
2736 struct AFSFid *tfid; /* file id we're dealing with now */
2737 struct rx_connection *tcon;
2739 struct client *t_client = NULL; /* tmp ptr to client data */
2740 AFSFetchStatus *tstatus;
2741 int VolSync_set = 0;
2742 #if FS_STATS_DETAILED
2743 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2744 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2745 struct timeval elapsedTime; /* Transfer time */
2748 * Set our stats pointer, remember when the RPC operation started, and
2749 * tally the operation.
2751 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2755 FT_GetTimeOfDay(&opStartTime, 0);
2756 #endif /* FS_STATS_DETAILED */
2758 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2760 AFSCallStats.TotalCalls++;
2762 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2763 if (nfiles <= 0) { /* Sanity check */
2765 goto Audit_and_Return;
2768 /* allocate space for return output parameters */
2769 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2770 malloc(nfiles * sizeof(struct AFSFetchStatus));
2771 if (!OutStats->AFSBulkStats_val) {
2772 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2773 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2775 OutStats->AFSBulkStats_len = nfiles;
2776 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2777 malloc(nfiles * sizeof(struct AFSCallBack));
2778 if (!CallBacks->AFSCBs_val) {
2779 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2780 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2782 CallBacks->AFSCBs_len = nfiles;
2784 /* Zero out return values to avoid leaking information on partial succes */
2785 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2786 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2787 memset(Sync, 0, sizeof(*Sync));
2789 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2790 goto Bad_InlineBulkStatus;
2793 tfid = Fids->AFSCBFids_val;
2794 for (i = 0; i < nfiles; i++, tfid++) {
2796 * Get volume/vnode for the fetched file; caller's rights to it
2800 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2801 &parentwhentargetnotdir, &client, READ_LOCK,
2802 &rights, &anyrights))) {
2803 tstatus = &OutStats->AFSBulkStats_val[i];
2804 tstatus->errorCode = errorCode;
2805 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2807 parentwhentargetnotdir = (Vnode *) 0;
2808 targetptr = (Vnode *) 0;
2809 volptr = (Volume *) 0;
2810 client = (struct client *)0;
2814 /* set volume synchronization information, but only once per call */
2816 SetVolumeSync(Sync, volptr);
2820 /* Are we allowed to fetch Fid's status? */
2821 if (targetptr->disk.type != vDirectory) {
2823 Check_PermissionRights(targetptr, client, rights,
2824 CHK_FETCHSTATUS, 0))) {
2825 tstatus = &OutStats->AFSBulkStats_val[i];
2826 tstatus->errorCode = errorCode;
2827 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2828 (Vnode *) 0, volptr, &client);
2829 parentwhentargetnotdir = (Vnode *) 0;
2830 targetptr = (Vnode *) 0;
2831 volptr = (Volume *) 0;
2832 client = (struct client *)0;
2837 /* set OutStatus From the Fid */
2838 GetStatus(targetptr,
2839 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2840 rights, anyrights, parentwhentargetnotdir);
2842 /* If a r/w volume, also set the CallBack state */
2843 if (VolumeWriteable(volptr))
2844 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2845 &CallBacks->AFSCBs_val[i]);
2847 struct AFSFid myFid;
2848 memset(&myFid, 0, sizeof(struct AFSFid));
2849 myFid.Volume = tfid->Volume;
2850 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2851 &CallBacks->AFSCBs_val[i]);
2854 /* put back the file ID and volume */
2855 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2857 parentwhentargetnotdir = (Vnode *) 0;
2858 targetptr = (Vnode *) 0;
2859 volptr = (Volume *) 0;
2860 client = (struct client *)0;
2863 Bad_InlineBulkStatus:
2864 /* Update and store volume/vnode and parent vnodes back */
2865 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2867 errorCode = CallPostamble(tcon, errorCode, thost);
2869 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2871 #if FS_STATS_DETAILED
2872 FT_GetTimeOfDay(&opStopTime, 0);
2873 if (errorCode == 0) {
2875 (opP->numSuccesses)++;
2876 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2877 fs_stats_AddTo((opP->sumTime), elapsedTime);
2878 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2879 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2880 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2882 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2883 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2887 #endif /* FS_STATS_DETAILED */
2890 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2891 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2892 AUD_ID, t_client ? t_client->ViceId : 0,
2893 AUD_FIDS, Fids, AUD_END);
2896 } /*SRXAFS_InlineBulkStatus */
2900 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2901 struct AFSFetchStatus * OutStatus,
2902 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2905 struct rx_connection *tcon;
2907 struct client *t_client = NULL; /* tmp ptr to client data */
2908 #if FS_STATS_DETAILED
2909 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2910 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2911 struct timeval elapsedTime; /* Transfer time */
2914 * Set our stats pointer, remember when the RPC operation started, and
2915 * tally the operation.
2917 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2921 FT_GetTimeOfDay(&opStartTime, 0);
2922 #endif /* FS_STATS_DETAILED */
2924 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2925 goto Bad_FetchStatus;
2927 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2930 code = CallPostamble(tcon, code, thost);
2932 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2934 #if FS_STATS_DETAILED
2935 FT_GetTimeOfDay(&opStopTime, 0);
2938 (opP->numSuccesses)++;
2939 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2940 fs_stats_AddTo((opP->sumTime), elapsedTime);
2941 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2942 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2943 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2945 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2946 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2950 #endif /* FS_STATS_DETAILED */
2952 osi_auditU(acall, FetchStatusEvent, code,
2953 AUD_ID, t_client ? t_client->ViceId : 0,
2954 AUD_FID, Fid, AUD_END);
2957 } /*SRXAFS_FetchStatus */
2961 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2962 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2963 afs_fsize_t Length, afs_fsize_t FileLength,
2964 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2966 Vnode *targetptr = 0; /* pointer to input fid */
2967 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2968 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2969 Error errorCode = 0; /* return code for caller */
2970 Error fileCode = 0; /* return code from vol package */
2971 Volume *volptr = 0; /* pointer to the volume header */
2972 struct client *client = 0; /* pointer to client structure */
2973 afs_int32 rights, anyrights; /* rights for this and any user */
2974 struct client *t_client = NULL; /* tmp ptr to client data */
2975 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2976 struct rx_connection *tcon;
2978 #if FS_STATS_DETAILED
2979 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2980 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2981 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2982 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2983 struct timeval elapsedTime; /* Transfer time */
2984 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2985 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2986 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2989 * Set our stats pointers, remember when the RPC operation started, and
2990 * tally the operation.
2992 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2993 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2998 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3000 FT_GetTimeOfDay(&opStartTime, 0);
3001 #endif /* FS_STATS_DETAILED */
3004 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3006 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3009 /* Get ptr to client data for user Id for logging */
3010 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3011 logHostAddr.s_addr = rxr_HostOf(tcon);
3013 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3014 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3015 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3018 * Get associated volume/vnode for the stored file; caller's rights
3022 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3023 &parentwhentargetnotdir, &client, WRITE_LOCK,
3024 &rights, &anyrights))) {
3028 /* set volume synchronization information */
3029 SetVolumeSync(Sync, volptr);
3031 if ((targetptr->disk.type == vSymlink)) {
3032 /* Should we return a better error code here??? */
3037 /* Check if we're allowed to store the data */
3039 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3045 * Drop the read lock on the parent directory after saving the parent
3046 * vnode information we need to pass to GetStatus
3048 if (parentwhentargetnotdir != NULL) {
3049 tparentwhentargetnotdir = *parentwhentargetnotdir;
3050 VPutVnode(&fileCode, parentwhentargetnotdir);
3051 osi_Assert(!fileCode || (fileCode == VSALVAGE));
3052 parentwhentargetnotdir = NULL;
3054 #if FS_STATS_DETAILED
3056 * Remember when the data transfer started.
3058 FT_GetTimeOfDay(&xferStartTime, 0);
3059 #endif /* FS_STATS_DETAILED */
3061 /* Do the actual storing of the data */
3062 #if FS_STATS_DETAILED
3064 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3065 FileLength, (InStatus->Mask & AFS_FSYNC),
3066 &bytesToXfer, &bytesXferred);
3069 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3070 FileLength, (InStatus->Mask & AFS_FSYNC));
3071 if (errorCode && (!targetptr->changed_newTime))
3073 #endif /* FS_STATS_DETAILED */
3074 #if FS_STATS_DETAILED
3076 * At this point, the data transfer is done, for good or ill. Remember
3077 * when the transfer ended, bump the number of successes/failures, and
3078 * integrate the transfer size and elapsed time into the stats. If the
3079 * operation failed, we jump to the appropriate point.
3081 FT_GetTimeOfDay(&xferStopTime, 0);
3083 (xferP->numXfers)++;
3085 (xferP->numSuccesses)++;
3088 * Bump the xfer sum by the number of bytes actually sent, NOT the
3091 tot_bytesXferred += bytesXferred;
3092 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3093 tot_bytesXferred &= 0x3FF;
3094 if (bytesXferred < xferP->minBytes)
3095 xferP->minBytes = bytesXferred;
3096 if (bytesXferred > xferP->maxBytes)
3097 xferP->maxBytes = bytesXferred;
3100 * Tally the size of the object. Note: we tally the actual size,
3101 * NOT the number of bytes that made it out over the wire.
3103 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3104 (xferP->count[0])++;
3105 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3106 (xferP->count[1])++;
3107 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3108 (xferP->count[2])++;
3109 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3110 (xferP->count[3])++;
3111 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3112 (xferP->count[4])++;
3113 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3114 (xferP->count[5])++;
3115 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3116 (xferP->count[6])++;
3117 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3118 (xferP->count[7])++;
3120 (xferP->count[8])++;
3122 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3123 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3124 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3125 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3126 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3128 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3129 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3134 * Finally, go off to tell our caller the bad news in case the
3137 if (errorCode && (!targetptr->changed_newTime))
3139 #endif /* FS_STATS_DETAILED */
3141 /* Update the status of the target's vnode */
3142 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3143 targetptr, volptr, 0);
3145 /* Get the updated File's status back to the caller */
3146 GetStatus(targetptr, OutStatus, rights, anyrights,
3147 &tparentwhentargetnotdir);
3150 /* Update and store volume/vnode and parent vnodes back */
3151 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3153 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3155 errorCode = CallPostamble(tcon, errorCode, thost);
3157 #if FS_STATS_DETAILED
3158 FT_GetTimeOfDay(&opStopTime, 0);
3159 if (errorCode == 0) {
3161 (opP->numSuccesses)++;
3162 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3163 fs_stats_AddTo((opP->sumTime), elapsedTime);
3164 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3165 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3166 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3168 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3169 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3173 #endif /* FS_STATS_DETAILED */
3174 osi_auditU(acall, StoreDataEvent, errorCode,
3175 AUD_ID, t_client ? t_client->ViceId : 0,
3176 AUD_FID, Fid, AUD_END);
3178 } /*common_StoreData64 */
3181 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3182 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3183 afs_uint32 Length, afs_uint32 FileLength,
3184 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3186 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3187 (0x7fffffff - Pos) < Length)
3190 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3192 } /*SRXAFS_StoreData */
3195 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3196 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3197 afs_uint64 Length, afs_uint64 FileLength,
3198 struct AFSFetchStatus * OutStatus,
3199 struct AFSVolSync * Sync)
3203 afs_fsize_t tLength;
3204 afs_fsize_t tFileLength;
3206 tPos = (afs_fsize_t) Pos;
3207 tLength = (afs_fsize_t) Length;
3208 tFileLength = (afs_fsize_t) FileLength;
3211 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3217 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3218 struct AFSOpaque * AccessList,
3219 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3221 Vnode *targetptr = 0; /* pointer to input fid */
3222 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3223 Error errorCode = 0; /* return code for caller */
3224 struct AFSStoreStatus InStatus; /* Input status for fid */
3225 Volume *volptr = 0; /* pointer to the volume header */
3226 struct client *client = 0; /* pointer to client structure */
3227 afs_int32 rights, anyrights; /* rights for this and any user */
3228 struct rx_connection *tcon;
3230 struct client *t_client = NULL; /* tmp ptr to client data */
3231 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3232 #if FS_STATS_DETAILED
3233 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3234 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3235 struct timeval elapsedTime; /* Transfer time */
3238 * Set our stats pointer, remember when the RPC operation started, and
3239 * tally the operation.
3241 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3245 FT_GetTimeOfDay(&opStartTime, 0);
3246 #endif /* FS_STATS_DETAILED */
3247 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3250 /* Get ptr to client data for user Id for logging */
3251 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3252 logHostAddr.s_addr = rxr_HostOf(tcon);
3254 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3255 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3256 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3258 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3260 InStatus.Mask = 0; /* not storing any status */
3263 * Get associated volume/vnode for the target dir; caller's rights
3264 * are also returned.
3267 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3268 &parentwhentargetnotdir, &client, WRITE_LOCK,
3269 &rights, &anyrights))) {
3273 /* set volume synchronization information */
3274 SetVolumeSync(Sync, volptr);
3276 /* Check if we have permission to change the dir's ACL */
3278 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3283 /* Build and store the new Access List for the dir */
3284 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3288 targetptr->changed_newTime = 1; /* status change of directory */
3290 /* convert the write lock to a read lock before breaking callbacks */
3291 VVnodeWriteToRead(&errorCode, targetptr);
3292 osi_Assert(!errorCode || errorCode == VSALVAGE);
3294 /* break call backs on the directory */
3295 BreakCallBack(client->host, Fid, 0);
3297 /* Get the updated dir's status back to the caller */
3298 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3301 /* Update and store volume/vnode and parent vnodes back */
3302 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3304 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3305 errorCode = CallPostamble(tcon, errorCode, thost);
3307 #if FS_STATS_DETAILED
3308 FT_GetTimeOfDay(&opStopTime, 0);
3309 if (errorCode == 0) {
3311 (opP->numSuccesses)++;
3312 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3313 fs_stats_AddTo((opP->sumTime), elapsedTime);
3314 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3315 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3316 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3318 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3319 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3323 #endif /* FS_STATS_DETAILED */
3325 osi_auditU(acall, StoreACLEvent, errorCode,
3326 AUD_ID, t_client ? t_client->ViceId : 0,
3327 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3330 } /*SRXAFS_StoreACL */
3334 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3335 * should be merged when possible.
3338 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3339 struct AFSStoreStatus *InStatus,
3340 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3342 Vnode *targetptr = 0; /* pointer to input fid */
3343 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3344 Error errorCode = 0; /* return code for caller */
3345 Volume *volptr = 0; /* pointer to the volume header */
3346 struct client *client = 0; /* pointer to client structure */
3347 afs_int32 rights, anyrights; /* rights for this and any user */
3348 struct client *t_client = NULL; /* tmp ptr to client data */
3349 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3350 struct rx_connection *tcon = rx_ConnectionOf(acall);
3352 /* Get ptr to client data for user Id for logging */
3353 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3354 logHostAddr.s_addr = rxr_HostOf(tcon);
3356 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3357 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3358 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3360 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3363 * Get volume/vnode for the target file; caller's rights to it are
3367 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3368 &parentwhentargetnotdir, &client, WRITE_LOCK,
3369 &rights, &anyrights))) {
3370 goto Bad_StoreStatus;
3373 /* set volume synchronization information */
3374 SetVolumeSync(Sync, volptr);
3376 /* Check if the caller has proper permissions to store status to Fid */
3378 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3380 goto Bad_StoreStatus;
3383 * Check for a symbolic link; we can't chmod these (otherwise could
3384 * change a symlink to a mt pt or vice versa)
3386 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3388 goto Bad_StoreStatus;
3391 /* Update the status of the target's vnode */
3392 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3393 (parentwhentargetnotdir ? parentwhentargetnotdir
3394 : targetptr), volptr, 0);
3396 /* convert the write lock to a read lock before breaking callbacks */
3397 VVnodeWriteToRead(&errorCode, targetptr);
3398 osi_Assert(!errorCode || errorCode == VSALVAGE);
3400 /* Break call backs on Fid */
3401 BreakCallBack(client->host, Fid, 0);
3403 /* Return the updated status back to caller */
3404 GetStatus(targetptr, OutStatus, rights, anyrights,
3405 parentwhentargetnotdir);
3408 /* Update and store volume/vnode and parent vnodes back */
3409 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3411 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3414 } /*SAFSS_StoreStatus */
3418 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3419 struct AFSStoreStatus * InStatus,
3420 struct AFSFetchStatus * OutStatus,
3421 struct AFSVolSync * Sync)
3424 struct rx_connection *tcon;
3426 struct client *t_client = NULL; /* tmp ptr to client data */
3427 #if FS_STATS_DETAILED
3428 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3429 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3430 struct timeval elapsedTime; /* Transfer time */
3433 * Set our stats pointer, remember when the RPC operation started, and
3434 * tally the operation.
3436 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3440 FT_GetTimeOfDay(&opStartTime, 0);
3441 #endif /* FS_STATS_DETAILED */
3443 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3444 goto Bad_StoreStatus;
3446 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3449 code = CallPostamble(tcon, code, thost);
3451 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3453 #if FS_STATS_DETAILED
3454 FT_GetTimeOfDay(&opStopTime, 0);
3457 (opP->numSuccesses)++;
3458 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3459 fs_stats_AddTo((opP->sumTime), elapsedTime);
3460 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3461 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {<