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 #include <netinet/if_ether.h>
56 /* included early because of name conflict on IOPEN */
57 #include <sys/inode.h>
61 #endif /* AFS_HPUX_ENV */
65 #include <afs/assert.h>
68 #include <afs/afsint.h>
69 #include <afs/vldbint.h>
70 #include <afs/errors.h>
71 #include <afs/ihandle.h>
72 #include <afs/vnode.h>
73 #include <afs/volume.h>
74 #include <afs/ptclient.h>
75 #include <afs/ptuser.h>
76 #include <afs/prs_fs.h>
79 #include <rx/rx_globals.h>
81 #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)
84 #if !defined(AFS_NT40_ENV)
87 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
89 #include <sys/statfs.h>
90 #include <sys/lockf.h>
92 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
97 #include <afs/cellconfig.h>
101 #include <afs/partition.h>
102 #include "viced_prototypes.h"
105 #include "callback.h"
106 #include <afs/unified_afs.h>
107 #include <afs/audit.h>
108 #include <afs/afsutil.h>
111 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
112 extern void FidZap(DirHandle * file);
113 extern void FidZero(DirHandle * file);
115 #ifdef AFS_PTHREAD_ENV
116 pthread_mutex_t fileproc_glock_mutex;
117 #endif /* AFS_PTHREAD_ENV */
120 #define afs_stat stat64
121 #define afs_fstat fstat64
122 #define afs_open open64
123 #else /* !O_LARGEFILE */
124 #define afs_stat stat
125 #define afs_fstat fstat
126 #define afs_open open
127 #endif /* !O_LARGEFILE */
130 /* Useful local defines used by this module */
133 #define MustNOTBeDIR 1
137 #define TVS_SSTATUS 2
140 #define TVS_MKDIR 0x10
142 #define CHK_FETCH 0x10
143 #define CHK_FETCHDATA 0x10
144 #define CHK_FETCHACL 0x11
145 #define CHK_FETCHSTATUS 0x12
146 #define CHK_STOREDATA 0x00
147 #define CHK_STOREACL 0x01
148 #define CHK_STORESTATUS 0x02
150 #define OWNERREAD 0400
151 #define OWNERWRITE 0200
152 #define OWNEREXEC 0100
153 #ifdef USE_GROUP_PERMS
154 #define GROUPREAD 0040
155 #define GROUPWRITE 0020
156 #define GROUPREXEC 0010
159 /* The following errors were not defined in NT. They are given unique
160 * names here to avoid any potential collision.
162 #define FSERR_ELOOP 90
163 #define FSERR_EOPNOTSUPP 122
164 #define FSERR_ECONNREFUSED 130
166 #define NOTACTIVECALL 0
169 #define CREATE_SGUID_ADMIN_ONLY 1
171 extern struct afsconf_dir *confDir;
172 extern afs_int32 dataVersionHigh;
175 static struct AFSCallStatistics AFSCallStats;
176 #if FS_STATS_DETAILED
177 struct fs_stats_FullPerfStats afs_FullPerfStats;
178 extern int AnonymousID;
179 #endif /* FS_STATS_DETAILED */
180 #if OPENAFS_VOL_STATS
181 static const char nullString[] = "";
182 #endif /* OPENAFS_VOL_STATS */
185 afs_int32 NothingYet;
188 struct afs_FSStats afs_fsstats;
193 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
195 extern afs_int32 implicitAdminRights;
196 extern afs_int32 readonlyServer;
197 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
198 extern afs_fsize_t CopyOnWrite_maxsize;
201 * Externals used by the xstat code.
203 extern VolPkgStats VStats;
204 extern int CEs, CEBlocks;
206 extern int HTs, HTBlocks;
208 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
209 register struct rx_call *Call, afs_sfsize_t Pos,
210 afs_sfsize_t Len, afs_int32 Int64Mode,
211 #if FS_STATS_DETAILED
212 afs_sfsize_t * a_bytesToFetchP,
213 afs_sfsize_t * a_bytesFetchedP
214 #endif /* FS_STATS_DETAILED */
217 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
218 struct AFSFid *Fid, struct client *client,
219 register struct rx_call *Call, afs_fsize_t Pos,
220 afs_fsize_t Length, afs_fsize_t FileLength,
222 #if FS_STATS_DETAILED
223 afs_sfsize_t * a_bytesToStoreP,
224 afs_sfsize_t * a_bytesStoredP
225 #endif /* FS_STATS_DETAILED */
228 #ifdef AFS_SGI_XFS_IOPS_ENV
229 #include <afs/xfsattrs.h>
231 GetLinkCount(Volume * avp, struct stat *astat)
233 if (!strcmp("xfs", astat->st_fstype)) {
234 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
236 return astat->st_nlink;
239 #define GetLinkCount(V, S) (S)->st_nlink
243 SpareComp(Volume * avolp)
245 register afs_int32 temp;
249 temp = V_maxquota(avolp);
251 /* no matter; doesn't check in this case */
255 temp = (temp * PctSpare) / 100;
266 * Set the volume synchronization parameter for this volume. If it changes,
267 * the Cache Manager knows that the volume must be purged from the stat cache.
270 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
273 /* date volume instance was created */
276 async->spare1 = avol->header->diskstuff.creationDate;
289 * Note that this function always returns a held host, so
290 * that CallPostamble can block without the host's disappearing.
291 * Call returns rx connection in passed in *tconn
294 CallPreamble(register struct rx_call *acall, int activecall,
295 struct rx_connection **tconn, struct host **ahostp)
298 struct client *tclient;
301 char hoststr[16], hoststr2[16];
302 #ifdef AFS_PTHREAD_ENV
303 struct ubik_client *uclient;
308 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
311 *tconn = rx_ConnectionOf(acall);
315 tclient = h_FindClient_r(*tconn);
317 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
321 thost = tclient->host;
322 if (tclient->prfail == 1) { /* couldn't get the CPS */
324 h_ReleaseClient_r(tclient);
326 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
330 retry_flag = 0; /* Retry once */
332 /* Take down the old connection and re-read the key file */
334 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
335 #ifdef AFS_PTHREAD_ENV
336 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
338 /* Is it still necessary to drop this? We hit the net, we should... */
344 code = hpr_Initialize(&uclient);
347 assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
350 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
353 h_ReleaseClient_r(tclient);
356 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
360 tclient->prfail = 2; /* Means re-eval client's cps */
361 h_ReleaseClient_r(tclient);
366 tclient->LastCall = thost->LastCall = FT_ApproxTime();
367 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
368 thost->ActiveCall = thost->LastCall;
371 if (thost->hostFlags & HOSTDELETED) {
373 ("Discarded a packet for deleted host %s:%d\n",
374 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
375 code = VBUSY; /* raced, so retry */
376 } else if ((thost->hostFlags & VENUSDOWN)
377 || (thost->hostFlags & HFE_LATER)) {
378 if (BreakDelayedCallBacks_r(thost)) {
380 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
381 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
382 ntohs(rxr_PortOf(*tconn))));
383 if (MultiProbeAlternateAddress_r(thost)) {
385 ("MultiProbe failed to find new address for host %s:%d\n",
386 afs_inet_ntoa_r(thost->host, hoststr),
387 ntohs(thost->port)));
391 ("MultiProbe found new address for host %s:%d\n",
392 afs_inet_ntoa_r(thost->host, hoststr),
393 ntohs(thost->port)));
394 if (BreakDelayedCallBacks_r(thost)) {
396 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
397 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
398 ntohs(rxr_PortOf(*tconn))));
407 h_ReleaseClient_r(tclient);
417 CallPostamble(register struct rx_connection *aconn, afs_int32 ret,
421 struct client *tclient;
426 tclient = h_FindClient_r(aconn);
429 thost = tclient->host;
430 if (thost->hostFlags & HERRORTRANS)
432 h_ReleaseClient_r(tclient);
433 held = h_Held_r(thost);
436 if (ahost && ahost != thost) {
437 char hoststr[16], hoststr2[16];
438 ViceLog(0, ("CallPostamble: ahost %s:%d (%x) != thost %s:%d (%x)\n",
439 afs_inet_ntoa_r(ahost->host, hoststr), ntohs(ahost->port),
441 afs_inet_ntoa_r(thost->host, hoststr2), ntohs(thost->port),
446 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%x)\n",
447 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port),
452 return (translate ? sys_error_to_et(ret) : ret);
456 * Returns the volume and vnode pointers associated with file Fid; the lock
457 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
458 * are incremented and they must be eventualy released.
461 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
464 Error local_errorCode, errorCode = -1;
465 static struct timeval restartedat = { 0, 0 };
467 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
469 if ((*volptr) == 0) {
474 #ifdef AFS_DEMAND_ATTACH_FS
482 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
487 if ((errorCode == VOFFLINE) && (VInit < 2)) {
488 /* The volume we want may not be attached yet because
489 * the volume initialization is not yet complete.
490 * We can do several things:
491 * 1. return -1, which will cause users to see
492 * "connection timed out". This is more or
493 * less the same as always, except that the servers
494 * may appear to bounce up and down while they
495 * are actually restarting.
496 * 2. return VBUSY which will cause clients to
497 * sleep and retry for 6.5 - 15 minutes, depending
498 * on what version of the CM they are running. If
499 * the file server takes longer than that interval
500 * to attach the desired volume, then the application
501 * will see an ENODEV or EIO. This approach has
502 * the advantage that volumes which have been attached
503 * are immediately available, it keeps the server's
504 * immediate backlog low, and the call is interruptible
505 * by the user. Users see "waiting for busy volume."
506 * 3. sleep here and retry. Some people like this approach
507 * because there is no danger of seeing errors. However,
508 * this approach only works with a bounded number of
509 * clients, since the pending queues will grow without
510 * stopping. It might be better to find a way to take
511 * this call and stick it back on a queue in order to
512 * recycle this thread for a different request.
513 * 4. Return a new error code, which new cache managers will
514 * know enough to interpret as "sleep and retry", without
515 * the upper bound of 6-15 minutes that is imposed by the
516 * VBUSY handling. Users will see "waiting for
517 * busy volume," so they know that something is
518 * happening. Old cache managers must be able to do
519 * something reasonable with this, for instance, mark the
520 * server down. Fortunately, any error code < 0
521 * will elicit that behavior. See #1.
522 * 5. Some combination of the above. I like doing #2 for 10
523 * minutes, followed by #4. 3.1b and 3.2 cache managers
524 * will be fine as long as the restart period is
525 * not longer than 6.5 minutes, otherwise they may
526 * return ENODEV to users. 3.3 cache managers will be
527 * fine for 10 minutes, then will return
528 * ETIMEDOUT. 3.4 cache managers will just wait
529 * until the call works or fails definitively.
530 * NB. The problem with 2,3,4,5 is that old clients won't
531 * fail over to an alternate read-only replica while this
532 * server is restarting. 3.4 clients will fail over right away.
534 if (restartedat.tv_sec == 0) {
535 /* I'm not really worried about when we restarted, I'm */
536 /* just worried about when the first VBUSY was returned. */
537 FT_GetTimeOfDay(&restartedat, 0);
540 afs_perfstats.fs_nBusies++;
543 return (busyonrst ? VBUSY : restarting);
546 FT_GetTimeOfDay(&now, 0);
547 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
550 afs_perfstats.fs_nBusies++;
553 return (busyonrst ? VBUSY : restarting);
559 /* allow read operations on busy volume.
560 * must check local_errorCode because demand attach fs
561 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
562 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
563 #ifdef AFS_DEMAND_ATTACH_FS
564 /* DAFS case is complicated by the fact that local_errorCode can
565 * be VBUSY in cases where the volume is truly offline */
567 /* volume is in VOL_STATE_UNATTACHED */
570 #endif /* AFS_DEMAND_ATTACH_FS */
573 } else if (errorCode)
580 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
583 if ((*vptr)->disk.uniquifier != fid->Unique) {
584 VPutVnode(&fileCode, *vptr);
585 assert(fileCode == 0);
587 return (VNOVNODE); /* return the right error code, at least */
593 * This routine returns the ACL associated with the targetptr. If the
594 * targetptr isn't a directory, we access its parent dir and get the ACL
595 * thru the parent; in such case the parent's vnode is returned in
599 SetAccessList(Vnode ** targetptr, Volume ** volume,
600 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
601 AFSFid * Fid, int Lock)
603 if ((*targetptr)->disk.type == vDirectory) {
605 *ACL = VVnodeACL(*targetptr);
606 *ACLSize = VAclSize(*targetptr);
614 parentvnode = (*targetptr)->disk.parent;
615 VPutVnode(&errorCode, *targetptr);
619 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
622 *ACL = VVnodeACL(*parent);
623 *ACLSize = VAclSize(*parent);
624 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
626 if ((*targetptr)->disk.parent != parentvnode) {
627 VPutVnode(&errorCode, *parent);
638 /* Must not be called with H_LOCK held */
640 client_CheckRights(struct client *client, struct acl_accessList *ACL,
644 ObtainReadLock(&client->lock);
645 if (client->CPS.prlist_len > 0 && !client->deleted &&
646 client->host && !(client->host->hostFlags & HOSTDELETED))
647 acl_CheckRights(ACL, &client->CPS, rights);
648 ReleaseReadLock(&client->lock);
651 /* Must not be called with H_LOCK held */
653 client_HasAsMember(struct client *client, afs_int32 id)
657 ObtainReadLock(&client->lock);
658 if (client->CPS.prlist_len > 0 && !client->deleted &&
659 client->host && !(client->host->hostFlags & HOSTDELETED))
660 code = acl_IsAMember(id, &client->CPS);
661 ReleaseReadLock(&client->lock);
666 * Compare the directory's ACL with the user's access rights in the client
667 * connection and return the user's and everybody else's access permissions
668 * in rights and anyrights, respectively
671 GetRights(struct client *client, struct acl_accessList *ACL,
672 afs_int32 * rights, afs_int32 * anyrights)
674 extern prlist SystemAnyUserCPS;
675 afs_int32 hrights = 0;
676 #ifndef AFS_PTHREAD_ENV
680 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
681 ViceLog(0, ("CheckRights failed\n"));
686 client_CheckRights(client, ACL, rights);
688 /* wait if somebody else is already doing the getCPS call */
690 while (client->host->hostFlags & HCPS_INPROGRESS) {
691 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
692 #ifdef AFS_PTHREAD_ENV
693 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
694 #else /* AFS_PTHREAD_ENV */
696 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
697 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
698 #endif /* AFS_PTHREAD_ENV */
701 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
704 ("CheckRights: len=%u, for host=%s:%d\n",
705 client->host->hcps.prlist_len,
706 afs_inet_ntoa_r(client->host->host, hoststr),
707 ntohs(client->host->port)));
709 acl_CheckRights(ACL, &client->host->hcps, &hrights);
711 /* Allow system:admin the rights given with the -implicit option */
712 if (client_HasAsMember(client, SystemId))
713 *rights |= implicitAdminRights;
716 *anyrights |= hrights;
723 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
724 * a System:Administrator)
727 VanillaUser(struct client *client)
729 if (client_HasAsMember(client, SystemId))
730 return (0); /* not a system administrator, then you're "vanilla" */
737 * This unusual afs_int32-parameter routine encapsulates all volume package related
738 * operations together in a single function; it's called by almost all AFS
742 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
743 Vnode ** targetptr, int chkforDir, Vnode ** parent,
744 struct client **client, int locktype, afs_int32 * rights,
745 afs_int32 * anyrights)
747 struct acl_accessList *aCL; /* Internal access List */
748 int aCLSize; /* size of the access list */
749 Error errorCode = 0; /* return code to caller */
751 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
754 if (chkforDir == MustNOTBeDIR
755 && ((*targetptr)->disk.type == vDirectory))
757 else if (chkforDir == MustBeDIR
758 && ((*targetptr)->disk.type != vDirectory))
762 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
763 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
764 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
766 if (chkforDir == MustBeDIR)
767 assert((*parent) == 0);
769 if ((errorCode = GetClient(tcon, client)) != 0)
774 GetRights(*client, aCL, rights, anyrights);
775 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
776 if ((*targetptr)->disk.type != vDirectory) {
777 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
778 if ((*targetptr)->disk.owner == (*client)->ViceId)
779 (*rights) |= PRSFS_ADMINISTER;
781 (*rights) &= ~PRSFS_ADMINISTER;
783 #ifdef ADMIN_IMPLICIT_LOOKUP
784 /* admins get automatic lookup on everything */
785 if (!VanillaUser(*client))
786 (*rights) |= PRSFS_LOOKUP;
787 #endif /* ADMIN_IMPLICIT_LOOKUP */
790 } /*GetVolumePackage */
794 * This is the opposite of GetVolumePackage(), and is always used at the end of
795 * AFS calls to put back all used vnodes and the volume in the proper order!
798 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
799 Vnode * parentptr, Volume * volptr, struct client **client)
801 Error fileCode = 0; /* Error code returned by the volume package */
803 if (parentwhentargetnotdir) {
804 VPutVnode(&fileCode, parentwhentargetnotdir);
805 assert(!fileCode || (fileCode == VSALVAGE));
808 VPutVnode(&fileCode, targetptr);
809 assert(!fileCode || (fileCode == VSALVAGE));
812 VPutVnode(&fileCode, parentptr);
813 assert(!fileCode || (fileCode == VSALVAGE));
821 } /*PutVolumePackage */
824 VolumeOwner(register struct client *client, register Vnode * targetptr)
826 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
829 return (client->ViceId == owner);
832 * We don't have to check for host's cps since only regular
833 * viceid are volume owners.
835 return (client_HasAsMember(client, owner));
841 VolumeRootVnode(Vnode * targetptr)
843 return ((targetptr->vnodeNumber == ROOTVNODE)
844 && (targetptr->disk.uniquifier == 1));
846 } /*VolumeRootVnode */
849 * Check if target file has the proper access permissions for the Fetch
850 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
851 * StoreStatus) related calls
853 /* this code should probably just set a "priv" flag where all the audit events
854 * are now, and only generate the audit event once at the end of the routine,
855 * thus only generating the event if all the checks succeed, but only because
856 * of the privilege XXX
859 Check_PermissionRights(Vnode * targetptr, struct client *client,
860 afs_int32 rights, int CallingRoutine,
861 AFSStoreStatus * InStatus)
864 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
865 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
866 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
868 if (CallingRoutine & CHK_FETCH) {
869 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
870 if (targetptr->disk.type == vDirectory
871 || targetptr->disk.type == vSymlink) {
872 if (!(rights & PRSFS_LOOKUP)
873 #ifdef ADMIN_IMPLICIT_LOOKUP
874 /* grant admins fetch on all directories */
875 && VanillaUser(client)
876 #endif /* ADMIN_IMPLICIT_LOOKUP */
877 && !VolumeOwner(client, targetptr))
880 /* must have read access, or be owner and have insert access */
881 if (!(rights & PRSFS_READ)
882 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
885 if (CallingRoutine == CHK_FETCHDATA
886 && targetptr->disk.type == vFile)
887 #ifdef USE_GROUP_PERMS
888 if (!OWNSp(client, targetptr)
889 && !client_HasAsMember(client, targetptr->disk.owner)) {
891 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
895 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
900 * The check with the ownership below is a kludge to allow
901 * reading of files created with no read permission. The owner
902 * of the file is always allowed to read it.
904 if ((client->ViceId != targetptr->disk.owner)
905 && VanillaUser(client))
907 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
908 modeBits) ? 0 : EACCES);
910 } else { /* !VanillaUser(client) && !FetchData */
912 osi_audit(PrivilegeEvent, 0, AUD_ID,
913 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
916 } else { /* a store operation */
917 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
918 && (CallingRoutine != CHK_STOREACL)
919 && (targetptr->disk.type == vFile)) {
920 /* bypass protection checks on first store after a create
921 * for the creator; also prevent chowns during this time
922 * unless you are a system administrator */
923 /****** InStatus->Owner && UnixModeBits better be SET!! */
924 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
927 else if (VanillaUser(client))
928 return (EPERM); /* Was EACCES */
930 osi_audit(PrivilegeEvent, 0, AUD_ID,
931 (client ? client->ViceId : 0), AUD_INT,
932 CallingRoutine, AUD_END);
935 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
936 osi_audit(PrivilegeEvent, 0, AUD_ID,
937 (client ? client->ViceId : 0), AUD_INT,
938 CallingRoutine, AUD_END);
940 if (readonlyServer) {
943 if (CallingRoutine == CHK_STOREACL) {
944 if (!(rights & PRSFS_ADMINISTER)
945 && !VolumeOwner(client, targetptr))
947 } else { /* store data or status */
948 /* watch for chowns and chgrps */
949 if (CHOWN(InStatus, targetptr)
950 || CHGRP(InStatus, targetptr)) {
953 else if (VanillaUser(client))
954 return (EPERM); /* Was EACCES */
956 osi_audit(PrivilegeEvent, 0, AUD_ID,
957 (client ? client->ViceId : 0), AUD_INT,
958 CallingRoutine, AUD_END);
960 /* must be sysadmin to set suid/sgid bits */
961 if ((InStatus->Mask & AFS_SETMODE) &&
963 (InStatus->UnixModeBits & 0xc00) != 0) {
965 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
969 if (VanillaUser(client))
972 osi_audit(PrivSetID, 0, AUD_ID,
973 (client ? client->ViceId : 0), AUD_INT,
974 CallingRoutine, AUD_END);
976 if (CallingRoutine == CHK_STOREDATA) {
979 if (!(rights & PRSFS_WRITE))
981 /* Next thing is tricky. We want to prevent people
982 * from writing files sans 0200 bit, but we want
983 * creating new files with 0444 mode to work. We
984 * don't check the 0200 bit in the "you are the owner"
985 * path above, but here we check the bit. However, if
986 * you're a system administrator, we ignore the 0200
987 * bit anyway, since you may have fchowned the file,
989 #ifdef USE_GROUP_PERMS
990 if ((targetptr->disk.type == vFile)
991 && VanillaUser(client)) {
992 if (!OWNSp(client, targetptr)
993 && !client_HasAsMember(client, targetptr->disk.owner)) {
995 ((GROUPWRITE & targetptr->disk.modeBits)
999 ((OWNERWRITE & targetptr->disk.modeBits)
1004 if ((targetptr->disk.type != vDirectory)
1005 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1008 if (VanillaUser(client))
1011 osi_audit(PrivilegeEvent, 0, AUD_ID,
1012 (client ? client->ViceId : 0),
1013 AUD_INT, CallingRoutine, AUD_END);
1015 } else { /* a status store */
1018 if (targetptr->disk.type == vDirectory) {
1019 if (!(rights & PRSFS_DELETE)
1020 && !(rights & PRSFS_INSERT))
1022 } else { /* a file or symlink */
1023 if (!(rights & PRSFS_WRITE))
1033 } /*Check_PermissionRights */
1037 * The Access List information is converted from its internal form in the
1038 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1039 * external form and returned back to the caller, via the AccessList
1043 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1044 struct AFSOpaque *AccessList)
1046 char *eACL; /* External access list placeholder */
1049 ((targetptr->disk.type ==
1050 vDirectory ? VVnodeACL(targetptr) :
1051 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1054 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1055 acl_FreeExternalACL(&eACL);
1058 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1059 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1061 acl_FreeExternalACL(&eACL);
1064 } /*RXFetch_AccessList */
1068 * The Access List information is converted from its external form in the
1069 * input AccessList structure to the internal representation and copied into
1070 * the target dir's vnode storage.
1073 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1075 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1077 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
1079 if ((newACL->size + 4) > VAclSize(targetptr))
1081 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1082 acl_FreeACL(&newACL);
1085 } /*RXStore_AccessList */
1088 /* In our current implementation, each successive data store (new file
1089 * data version) creates a new inode. This function creates the new
1090 * inode, copies the old inode's contents to the new one, remove the old
1091 * inode (i.e. decrement inode count -- if it's currently used the delete
1092 * will be delayed), and modify some fields (i.e. vnode's
1093 * disk.inodeNumber and cloned)
1095 #define COPYBUFFSIZE 8192
1096 #define MAXFSIZE (~(afs_fsize_t) 0)
1098 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_fsize_t off, afs_fsize_t len)
1100 Inode ino, nearInode;
1103 register afs_fsize_t size;
1104 register int length;
1106 int rc; /* return code */
1107 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1108 FdHandle_t *targFdP; /* Source Inode file handle */
1109 FdHandle_t *newFdP; /* Dest Inode file handle */
1111 if (targetptr->disk.type == vDirectory)
1112 DFlush(); /* just in case? */
1114 VN_GET_LEN(size, targetptr);
1122 buff = (char *)malloc(COPYBUFFSIZE);
1127 ino = VN_GET_INO(targetptr);
1128 if (!VALID_INO(ino)) {
1130 VTakeOffline(volptr);
1131 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1135 targFdP = IH_OPEN(targetptr->handle);
1136 if (targFdP == NULL) {
1139 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1140 targetptr->vnodeNumber, V_id(volptr), rc));
1142 VTakeOffline(volptr);
1146 nearInode = VN_GET_INO(targetptr);
1148 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1149 VPartitionPath(V_partition(volptr)), nearInode,
1150 V_id(volptr), targetptr->vnodeNumber,
1151 targetptr->disk.uniquifier,
1152 (int)targetptr->disk.dataVersion);
1153 if (!VALID_INO(ino)) {
1155 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1156 volptr->partition->name, V_id(volptr), errno));
1161 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1162 newFdP = IH_OPEN(newH);
1163 assert(newFdP != NULL);
1165 FDH_SEEK(targFdP, off, SEEK_SET);
1166 FDH_SEEK(newFdP, off, SEEK_SET);
1168 if (size > COPYBUFFSIZE) { /* more than a buffer */
1169 length = COPYBUFFSIZE;
1170 size -= COPYBUFFSIZE;
1175 rdlen = FDH_READ(targFdP, buff, length);
1176 if (rdlen == length)
1177 wrlen = FDH_WRITE(newFdP, buff, length);
1180 /* Callers of this function are not prepared to recover
1181 * from error that put the filesystem in an inconsistent
1182 * state. Make sure that we force the volume off-line if
1183 * we some error other than ENOSPC - 4.29.99)
1185 * In case we are unable to write the required bytes, and the
1186 * error code indicates that the disk is full, we roll-back to
1187 * the initial state.
1189 if ((rdlen != length) || (wrlen != length)) {
1190 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1192 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1193 volptr->partition->name, V_id(volptr)));
1194 /* remove destination inode which was partially copied till now */
1195 FDH_REALLYCLOSE(newFdP);
1197 FDH_REALLYCLOSE(targFdP);
1198 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1201 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1202 rc, V_id(volptr), volptr->partition->name));
1203 VTakeOffline(volptr);
1209 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1210 V_id(volptr), volptr->partition->name, length, rdlen,
1212 #if defined(AFS_DEMAND_ATTACH_FS)
1213 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1215 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1217 /* Decrement this inode so salvager doesn't find it. */
1218 FDH_REALLYCLOSE(newFdP);
1220 FDH_REALLYCLOSE(targFdP);
1221 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1223 VTakeOffline(volptr);
1227 #ifndef AFS_PTHREAD_ENV
1229 #endif /* !AFS_PTHREAD_ENV */
1231 FDH_REALLYCLOSE(targFdP);
1232 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1233 V_parentId(volptr));
1235 IH_RELEASE(targetptr->handle);
1237 rc = FDH_SYNC(newFdP);
1240 targetptr->handle = newH;
1241 VN_SET_INO(targetptr, ino);
1242 targetptr->disk.cloned = 0;
1243 /* Internal change to vnode, no user level change to volume - def 5445 */
1244 targetptr->changed_oldTime = 1;
1246 return 0; /* success */
1250 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_fsize_t off, afs_fsize_t size) {
1251 char *buff = (char *)malloc(COPYBUFFSIZE);
1252 register int length;
1257 FDH_SEEK(targFdP, off, SEEK_SET);
1258 FDH_SEEK(newFdP, off, SEEK_SET);
1260 if (size > FDH_SIZE(targFdP) - off) size = FDH_SIZE(targFdP) - off;
1262 if (size > COPYBUFFSIZE) { /* more than a buffer */
1263 length = COPYBUFFSIZE;
1264 size -= COPYBUFFSIZE;
1269 rdlen = FDH_READ(targFdP, buff, length);
1270 if (rdlen == length)
1271 wrlen = FDH_WRITE(newFdP, buff, length);
1275 if ((rdlen != length) || (wrlen != length)) {
1276 /* no error recovery, at the worst we'll have a "hole" in the file */
1287 * Common code to handle with removing the Name (file when it's called from
1288 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1289 * given directory, parentptr.
1291 int DT1 = 0, DT0 = 0;
1293 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1294 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1296 DirHandle childdir; /* Handle for dir package I/O */
1297 Error errorCode = 0;
1300 /* watch for invalid names */
1301 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1303 if (parentptr->disk.cloned) {
1304 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1305 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1307 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1313 /* check that the file is in the directory */
1314 SetDirHandle(dir, parentptr);
1315 if (Lookup(dir, Name, fileFid))
1317 fileFid->Volume = V_id(volptr);
1319 /* just-in-case check for something causing deadlock */
1320 if (fileFid->Vnode == parentptr->vnodeNumber)
1323 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1327 if (ChkForDir == MustBeDIR) {
1328 if ((*targetptr)->disk.type != vDirectory)
1330 } else if ((*targetptr)->disk.type == vDirectory)
1333 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1335 * If the uniquifiers dont match then instead of asserting
1336 * take the volume offline and return VSALVAGE
1338 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1339 VTakeOffline(volptr);
1341 ("Volume %u now offline, must be salvaged.\n",
1343 errorCode = VSALVAGE;
1347 if (ChkForDir == MustBeDIR) {
1348 SetDirHandle(&childdir, *targetptr);
1349 if (IsEmpty(&childdir) != 0)
1353 (*targetptr)->delete = 1;
1354 } else if ((--(*targetptr)->disk.linkCount) == 0)
1355 (*targetptr)->delete = 1;
1356 if ((*targetptr)->delete) {
1357 if (VN_GET_INO(*targetptr)) {
1359 IH_REALLYCLOSE((*targetptr)->handle);
1361 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1362 V_parentId(volptr));
1363 IH_RELEASE((*targetptr)->handle);
1364 if (errorCode == -1) {
1366 ("DT: inode=%s, name=%s, errno=%d\n",
1367 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1369 if (errno != ENOENT)
1371 VTakeOffline(volptr);
1373 ("Volume %u now offline, must be salvaged.\n",
1381 VN_SET_INO(*targetptr, (Inode) 0);
1383 afs_fsize_t adjLength;
1384 VN_GET_LEN(adjLength, *targetptr);
1385 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1389 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1391 code = Delete(dir, (char *)Name);
1394 ("Error %d deleting %s\n", code,
1395 (((*targetptr)->disk.type ==
1396 Directory) ? "directory" : "file")));
1397 VTakeOffline(volptr);
1399 ("Volume %u now offline, must be salvaged.\n",
1412 * This routine updates the parent directory's status block after the
1413 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1414 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1418 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1419 int author, int linkcount,
1420 #if FS_STATS_DETAILED
1421 char a_inSameNetwork
1422 #endif /* FS_STATS_DETAILED */
1425 afs_fsize_t newlength; /* Holds new directory length */
1426 afs_fsize_t parentLength;
1428 #if FS_STATS_DETAILED
1429 Date currDate; /*Current date */
1430 int writeIdx; /*Write index to bump */
1431 int timeIdx; /*Authorship time index to bump */
1432 #endif /* FS_STATS_DETAILED */
1434 parentptr->disk.dataVersion++;
1435 newlength = (afs_fsize_t) Length(dir);
1437 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1438 * (create, symlink, link, makedir) so we need to check if we have enough space
1439 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1440 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1442 VN_GET_LEN(parentLength, parentptr);
1443 if (nBlocks(newlength) != nBlocks(parentLength)) {
1444 VAdjustDiskUsage(&errorCode, volptr,
1445 (nBlocks(newlength) - nBlocks(parentLength)),
1446 (nBlocks(newlength) - nBlocks(parentLength)));
1448 VN_SET_LEN(parentptr, newlength);
1450 #if FS_STATS_DETAILED
1452 * Update directory write stats for this volume. Note that the auth
1453 * counter is located immediately after its associated ``distance''
1456 if (a_inSameNetwork)
1457 writeIdx = VOL_STATS_SAME_NET;
1459 writeIdx = VOL_STATS_DIFF_NET;
1460 V_stat_writes(volptr, writeIdx)++;
1461 if (author != AnonymousID) {
1462 V_stat_writes(volptr, writeIdx + 1)++;
1466 * Update the volume's authorship information in response to this
1467 * directory operation. Get the current time, decide to which time
1468 * slot this operation belongs, and bump the appropriate slot.
1470 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1472 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1473 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1474 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1475 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1476 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1477 if (parentptr->disk.author == author) {
1478 V_stat_dirSameAuthor(volptr, timeIdx)++;
1480 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1482 #endif /* FS_STATS_DETAILED */
1484 parentptr->disk.author = author;
1485 parentptr->disk.linkCount = linkcount;
1486 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1487 parentptr->disk.serverModifyTime = FT_ApproxTime();
1488 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1493 * Update the target file's (or dir's) status block after the specified
1494 * operation is complete. Note that some other fields maybe updated by
1495 * the individual module.
1498 /* XXX INCOMPLETE - More attention is needed here! */
1500 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1501 struct client *client, AFSStoreStatus * InStatus,
1502 Vnode * parentptr, Volume * volptr,
1505 #if FS_STATS_DETAILED
1506 Date currDate; /*Current date */
1507 int writeIdx; /*Write index to bump */
1508 int timeIdx; /*Authorship time index to bump */
1509 #endif /* FS_STATS_DETAILED */
1511 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1512 targetptr->disk.parent = parentptr->vnodeNumber;
1513 VN_SET_LEN(targetptr, length);
1514 /* targetptr->disk.group = 0; save some cycles */
1515 targetptr->disk.modeBits = 0777;
1516 targetptr->disk.owner = client->ViceId;
1517 targetptr->disk.dataVersion = 0; /* consistent with the client */
1518 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1519 /* the inode was created in Alloc_NewVnode() */
1521 #if FS_STATS_DETAILED
1523 * Update file write stats for this volume. Note that the auth
1524 * counter is located immediately after its associated ``distance''
1527 if (client->InSameNetwork)
1528 writeIdx = VOL_STATS_SAME_NET;
1530 writeIdx = VOL_STATS_DIFF_NET;
1531 V_stat_writes(volptr, writeIdx)++;
1532 if (client->ViceId != AnonymousID) {
1533 V_stat_writes(volptr, writeIdx + 1)++;
1537 * We only count operations that DON'T involve creating new objects
1538 * (files, symlinks, directories) or simply setting status as
1539 * authorship-change operations.
1541 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1543 * Update the volume's authorship information in response to this
1544 * file operation. Get the current time, decide to which time
1545 * slot this operation belongs, and bump the appropriate slot.
1547 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1550 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1551 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1552 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1553 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1554 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1555 VOL_STATS_TIME_IDX_5);
1556 if (targetptr->disk.author == client->ViceId) {
1557 V_stat_fileSameAuthor(volptr, timeIdx)++;
1559 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1562 #endif /* FS_STATS_DETAILED */
1564 if (!(Caller & TVS_SSTATUS))
1565 targetptr->disk.author = client->ViceId;
1566 if (Caller & TVS_SDATA) {
1567 targetptr->disk.dataVersion++;
1568 if (VanillaUser(client)) {
1569 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1570 #ifdef CREATE_SGUID_ADMIN_ONLY
1571 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1575 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1576 /* store status, must explicitly request to change the date */
1577 if (InStatus->Mask & AFS_SETMODTIME)
1578 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1579 } else { /* other: date always changes, but perhaps to what is specified by caller */
1580 targetptr->disk.unixModifyTime =
1581 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1582 ClientModTime : FT_ApproxTime());
1584 if (InStatus->Mask & AFS_SETOWNER) {
1585 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1586 if (VanillaUser(client)) {
1587 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1588 #ifdef CREATE_SGUID_ADMIN_ONLY
1589 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1592 targetptr->disk.owner = InStatus->Owner;
1593 if (VolumeRootVnode(targetptr)) {
1594 Error errorCode = 0; /* what should be done with this? */
1596 V_owner(targetptr->volumePtr) = InStatus->Owner;
1597 VUpdateVolume(&errorCode, targetptr->volumePtr);
1600 if (InStatus->Mask & AFS_SETMODE) {
1601 int modebits = InStatus->UnixModeBits;
1602 #define CREATE_SGUID_ADMIN_ONLY 1
1603 #ifdef CREATE_SGUID_ADMIN_ONLY
1604 if (VanillaUser(client))
1605 modebits = modebits & 0777;
1607 if (VanillaUser(client)) {
1608 targetptr->disk.modeBits = modebits;
1610 targetptr->disk.modeBits = modebits;
1613 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1614 CHK_STOREDATA, AUD_END);
1618 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1619 CHK_STORESTATUS, AUD_END);
1626 targetptr->disk.serverModifyTime = FT_ApproxTime();
1627 if (InStatus->Mask & AFS_SETGROUP)
1628 targetptr->disk.group = InStatus->Group;
1629 /* vnode changed : to be written back by VPutVnode */
1630 targetptr->changed_newTime = 1;
1632 } /*Update_TargetVnodeStatus */
1636 * Fills the CallBack structure with the expiration time and type of callback
1637 * structure. Warning: this function is currently incomplete.
1640 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1642 /* CallBackTime could not be 0 */
1643 if (CallBackTime == 0) {
1644 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1645 CallBack->ExpirationTime = 0;
1647 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1648 CallBack->CallBackVersion = CALLBACK_VERSION;
1649 CallBack->CallBackType = CB_SHARED; /* The default for now */
1651 } /*SetCallBackStruct */
1655 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1656 * allocation; if some error occured (exceeded volume quota or partition
1657 * was full, or whatever), it frees the space back and returns the code.
1658 * We usually pre-adjust the volume space to make sure that there's
1659 * enough space before consuming some.
1662 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1663 afs_sfsize_t checkLength)
1668 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1670 VAdjustDiskUsage(&nc, volptr, -length, 0);
1671 if (rc == VOVERQUOTA) {
1673 ("Volume %u (%s) is full\n", V_id(volptr),
1677 if (rc == VDISKFULL) {
1679 ("Partition %s that contains volume %u is full\n",
1680 volptr->partition->name, V_id(volptr)));
1683 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1688 } /*AdjustDiskUsage */
1691 * Common code that handles the creation of a new file (SAFS_CreateFile and
1692 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1695 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1696 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1697 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1699 Error errorCode = 0; /* Error code returned back */
1702 Inode nearInode; /* hint for inode allocation in solaris */
1705 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1706 BlocksPreallocatedForVnode))) {
1708 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1709 (afs_intmax_t) BlocksPreallocatedForVnode));
1713 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1714 if (errorCode != 0) {
1715 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1718 OutFid->Volume = V_id(volptr);
1719 OutFid->Vnode = (*targetptr)->vnodeNumber;
1720 OutFid->Unique = (*targetptr)->disk.uniquifier;
1722 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1724 /* create the inode now itself */
1726 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1727 VPartitionPath(V_partition(volptr)), nearInode,
1728 V_id(volptr), (*targetptr)->vnodeNumber,
1729 (*targetptr)->disk.uniquifier, 1);
1731 /* error in creating inode */
1732 if (!VALID_INO(inode)) {
1734 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1735 (*targetptr)->volumePtr->header->diskstuff.id,
1736 (*targetptr)->vnodeNumber, errno));
1737 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1738 (*targetptr)->delete = 1; /* delete vnode */
1741 VN_SET_INO(*targetptr, inode);
1742 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1744 /* copy group from parent dir */
1745 (*targetptr)->disk.group = parentptr->disk.group;
1747 if (parentptr->disk.cloned) {
1748 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1749 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1750 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1751 /* delete the vnode previously allocated */
1752 (*targetptr)->delete = 1;
1753 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1754 IH_REALLYCLOSE((*targetptr)->handle);
1755 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1757 ("Alloc_NewVnode: partition %s idec %s failed\n",
1758 volptr->partition->name, PrintInode(NULL, inode)));
1759 IH_RELEASE((*targetptr)->handle);
1765 /* add the name to the directory */
1766 SetDirHandle(dir, parentptr);
1767 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1768 (*targetptr)->delete = 1;
1769 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1770 IH_REALLYCLOSE((*targetptr)->handle);
1771 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1773 ("Alloc_NewVnode: partition %s idec %s failed\n",
1774 volptr->partition->name, PrintInode(NULL, inode)));
1775 IH_RELEASE((*targetptr)->handle);
1781 } /*Alloc_NewVnode */
1785 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1789 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1791 int Time; /* Used for time */
1792 int writeVnode = targetptr->changed_oldTime; /* save original status */
1794 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1795 Time = FT_ApproxTime();
1796 switch (LockingType) {
1799 if (Time > targetptr->disk.lock.lockTime)
1800 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1802 Time += AFS_LOCKWAIT;
1803 if (LockingType == LockRead) {
1804 if ( !(rights & PRSFS_LOCK) &&
1805 !(rights & PRSFS_WRITE) &&
1806 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1809 if (targetptr->disk.lock.lockCount >= 0) {
1810 ++(targetptr->disk.lock.lockCount);
1811 targetptr->disk.lock.lockTime = Time;
1814 } else if (LockingType == LockWrite) {
1815 if ( !(rights & PRSFS_WRITE) &&
1816 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1819 if (targetptr->disk.lock.lockCount == 0) {
1820 targetptr->disk.lock.lockCount = -1;
1821 targetptr->disk.lock.lockTime = Time;
1827 Time += AFS_LOCKWAIT;
1828 if (targetptr->disk.lock.lockCount != 0)
1829 targetptr->disk.lock.lockTime = Time;
1834 if ((--targetptr->disk.lock.lockCount) <= 0)
1835 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1839 targetptr->changed_oldTime = writeVnode; /* restore old status */
1840 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1843 } /*HandleLocking */
1845 /* 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. */
1848 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1852 if (!(rights & Prfs_Mode))
1854 if ((targetptr->disk.type != vDirectory)
1855 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1861 * If some flags (i.e. min or max quota) are set, the volume's in disk
1862 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1863 * update, if applicable.
1866 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1867 char *Name, char *OfflineMsg, char *Motd)
1869 Error errorCode = 0;
1871 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1872 V_minquota(volptr) = StoreVolStatus->MinQuota;
1873 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1874 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1875 if (strlen(OfflineMsg) > 0) {
1876 strcpy(V_offlineMessage(volptr), OfflineMsg);
1878 if (strlen(Name) > 0) {
1879 strcpy(V_name(volptr), Name);
1881 #if OPENAFS_VOL_STATS
1883 * We don't overwrite the motd field, since it's now being used
1887 if (strlen(Motd) > 0) {
1888 strcpy(V_motd(volptr), Motd);
1890 #endif /* FS_STATS_DETAILED */
1891 VUpdateVolume(&errorCode, volptr);
1894 } /*RXUpdate_VolumeStatus */
1898 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1899 char **motd, Volume * volptr)
1903 status->Vid = V_id(volptr);
1904 status->ParentId = V_parentId(volptr);
1905 status->Online = V_inUse(volptr);
1906 status->InService = V_inService(volptr);
1907 status->Blessed = V_blessed(volptr);
1908 status->NeedsSalvage = V_needsSalvaged(volptr);
1909 if (VolumeWriteable(volptr))
1910 status->Type = ReadWrite;
1912 status->Type = ReadOnly;
1913 status->MinQuota = V_minquota(volptr);
1914 status->MaxQuota = V_maxquota(volptr);
1915 status->BlocksInUse = V_diskused(volptr);
1916 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1917 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1919 /* now allocate and copy these things; they're freed by the RXGEN stub */
1920 temp = strlen(V_name(volptr)) + 1;
1921 *name = malloc(temp);
1923 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1926 strcpy(*name, V_name(volptr));
1927 temp = strlen(V_offlineMessage(volptr)) + 1;
1928 *offMsg = malloc(temp);
1930 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1933 strcpy(*offMsg, V_offlineMessage(volptr));
1934 #if OPENAFS_VOL_STATS
1937 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1940 strcpy(*motd, nullString);
1942 temp = strlen(V_motd(volptr)) + 1;
1943 *motd = malloc(temp);
1945 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1948 strcpy(*motd, V_motd(volptr));
1949 #endif /* FS_STATS_DETAILED */
1951 } /*RXGetVolumeStatus */
1955 FileNameOK(register char *aname)
1957 register afs_int32 i, tc;
1960 /* watch for @sys on the right */
1961 if (strcmp(aname + i - 4, "@sys") == 0)
1964 while ((tc = *aname++)) {
1966 return 0; /* very bad character to encounter */
1968 return 1; /* file name is ok */
1974 * This variant of symlink is expressly to support the AFS/DFS translator
1975 * and is not supported by the AFS fileserver. We just return EINVAL.
1976 * The cache manager should not generate this call to an AFS cache manager.
1979 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1980 char *LinkContents, struct AFSStoreStatus *InStatus,
1981 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1982 struct AFSFetchStatus *OutDirStatus,
1983 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1989 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
1990 struct FsCmdInputs * Inputs,
1991 struct FsCmdOutputs * Outputs)
1995 switch (Inputs->command) {
1999 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2000 Inputs->command, Outputs->code));
2005 static struct afs_buffer {
2006 struct afs_buffer *next;
2007 } *freeBufferList = 0;
2008 static int afs_buffersAlloced = 0;
2011 FreeSendBuffer(register struct afs_buffer *adata)
2014 afs_buffersAlloced--;
2015 adata->next = freeBufferList;
2016 freeBufferList = adata;
2020 } /*FreeSendBuffer */
2022 /* allocate space for sender */
2026 register struct afs_buffer *tp;
2029 afs_buffersAlloced++;
2030 if (!freeBufferList) {
2033 tmp = malloc(sendBufSize);
2035 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2040 tp = freeBufferList;
2041 freeBufferList = tp->next;
2045 } /*AllocSendBuffer */
2046 #endif /* AFS_NT40_ENV */
2049 * This routine returns the status info associated with the targetptr vnode
2050 * in the AFSFetchStatus structure. Some of the newer fields, such as
2051 * SegSize and Group are not yet implemented
2055 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2056 afs_int32 anyrights, Vnode * parentptr)
2058 /* initialize return status from a vnode */
2059 status->InterfaceVersion = 1;
2060 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2061 status->errorCode = 0;
2062 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2063 if (targetptr->disk.type == vFile)
2064 status->FileType = File;
2065 else if (targetptr->disk.type == vDirectory)
2066 status->FileType = Directory;
2067 else if (targetptr->disk.type == vSymlink)
2068 status->FileType = SymbolicLink;
2070 status->FileType = Invalid; /*invalid type field */
2071 status->LinkCount = targetptr->disk.linkCount;
2073 afs_fsize_t targetLen;
2074 VN_GET_LEN(targetLen, targetptr);
2075 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2077 status->DataVersion = targetptr->disk.dataVersion;
2078 status->Author = targetptr->disk.author;
2079 status->Owner = targetptr->disk.owner;
2080 status->CallerAccess = rights;
2081 status->AnonymousAccess = anyrights;
2082 status->UnixModeBits = targetptr->disk.modeBits;
2083 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2084 status->ParentVnode =
2085 (status->FileType ==
2086 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2087 status->ParentUnique =
2088 (status->FileType ==
2089 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2090 status->ServerModTime = targetptr->disk.serverModifyTime;
2091 status->Group = targetptr->disk.group;
2092 status->lockCount = targetptr->disk.lock.lockCount;
2093 status->errorCode = 0;
2099 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2100 afs_sfsize_t Pos, afs_sfsize_t Len,
2101 struct AFSFetchStatus *OutStatus,
2102 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2105 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2106 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2107 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2108 Error errorCode = 0; /* return code to caller */
2109 Error fileCode = 0; /* return code from vol package */
2110 Volume *volptr = 0; /* pointer to the volume */
2111 struct client *client = 0; /* pointer to the client data */
2112 struct rx_connection *tcon; /* the connection we're part of */
2114 afs_int32 rights, anyrights; /* rights for this and any user */
2115 struct client *t_client = NULL; /* tmp ptr to client data */
2116 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2117 #if FS_STATS_DETAILED
2118 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2119 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2120 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2121 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2122 struct timeval elapsedTime; /* Transfer time */
2123 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2124 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2125 int readIdx; /* Index of read stats array to bump */
2126 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2129 * Set our stats pointers, remember when the RPC operation started, and
2130 * tally the operation.
2132 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2133 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2137 FT_GetTimeOfDay(&opStartTime, 0);
2138 #endif /* FS_STATS_DETAILED */
2141 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2144 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2146 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2149 /* Get ptr to client data for user Id for logging */
2150 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2151 logHostAddr.s_addr = rxr_HostOf(tcon);
2153 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2154 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2155 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2157 * Get volume/vnode for the fetched file; caller's access rights to
2158 * it are also returned
2161 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2162 &parentwhentargetnotdir, &client, READ_LOCK,
2163 &rights, &anyrights)))
2166 SetVolumeSync(Sync, volptr);
2168 #if FS_STATS_DETAILED
2170 * Remember that another read operation was performed.
2173 if (client->InSameNetwork)
2174 readIdx = VOL_STATS_SAME_NET;
2176 readIdx = VOL_STATS_DIFF_NET;
2177 V_stat_reads(volptr, readIdx)++;
2178 if (client->ViceId != AnonymousID) {
2179 V_stat_reads(volptr, readIdx + 1)++;
2182 #endif /* FS_STATS_DETAILED */
2183 /* Check whether the caller has permission access to fetch the data */
2185 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2189 * Drop the read lock on the parent directory after saving the parent
2190 * vnode information we need to pass to GetStatus
2192 if (parentwhentargetnotdir != NULL) {
2193 tparentwhentargetnotdir = *parentwhentargetnotdir;
2194 VPutVnode(&fileCode, parentwhentargetnotdir);
2195 assert(!fileCode || (fileCode == VSALVAGE));
2196 parentwhentargetnotdir = NULL;
2198 #if FS_STATS_DETAILED
2200 * Remember when the data transfer started.
2202 FT_GetTimeOfDay(&xferStartTime, 0);
2203 #endif /* FS_STATS_DETAILED */
2205 /* actually do the data transfer */
2206 #if FS_STATS_DETAILED
2208 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2209 &bytesToXfer, &bytesXferred);
2212 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2214 #endif /* FS_STATS_DETAILED */
2216 #if FS_STATS_DETAILED
2218 * At this point, the data transfer is done, for good or ill. Remember
2219 * when the transfer ended, bump the number of successes/failures, and
2220 * integrate the transfer size and elapsed time into the stats. If the
2221 * operation failed, we jump to the appropriate point.
2223 FT_GetTimeOfDay(&xferStopTime, 0);
2225 (xferP->numXfers)++;
2227 (xferP->numSuccesses)++;
2230 * Bump the xfer sum by the number of bytes actually sent, NOT the
2233 tot_bytesXferred += bytesXferred;
2234 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2235 tot_bytesXferred &= 0x3FF;
2236 if (bytesXferred < xferP->minBytes)
2237 xferP->minBytes = bytesXferred;
2238 if (bytesXferred > xferP->maxBytes)
2239 xferP->maxBytes = bytesXferred;
2242 * Tally the size of the object. Note: we tally the actual size,
2243 * NOT the number of bytes that made it out over the wire.
2245 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2246 (xferP->count[0])++;
2247 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2248 (xferP->count[1])++;
2249 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2250 (xferP->count[2])++;
2251 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2252 (xferP->count[3])++;
2253 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2254 (xferP->count[4])++;
2255 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2256 (xferP->count[5])++;
2257 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2258 (xferP->count[6])++;
2259 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2260 (xferP->count[7])++;
2262 (xferP->count[8])++;
2264 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2265 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2266 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2267 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2268 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2270 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2271 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2276 * Finally, go off to tell our caller the bad news in case the
2281 #endif /* FS_STATS_DETAILED */
2283 /* write back the OutStatus from the target vnode */
2284 GetStatus(targetptr, OutStatus, rights, anyrights,
2285 &tparentwhentargetnotdir);
2287 /* if a r/w volume, promise a callback to the caller */
2288 if (VolumeWriteable(volptr))
2289 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2291 struct AFSFid myFid;
2292 memset(&myFid, 0, sizeof(struct AFSFid));
2293 myFid.Volume = Fid->Volume;
2294 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2298 /* Update and store volume/vnode and parent vnodes back */
2299 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2301 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2302 errorCode = CallPostamble(tcon, errorCode, thost);
2304 #if FS_STATS_DETAILED
2305 FT_GetTimeOfDay(&opStopTime, 0);
2306 if (errorCode == 0) {
2308 (opP->numSuccesses)++;
2309 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2310 fs_stats_AddTo((opP->sumTime), elapsedTime);
2311 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2312 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2313 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2315 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2316 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2320 #endif /* FS_STATS_DETAILED */
2322 osi_auditU(acall, FetchDataEvent, errorCode,
2323 AUD_ID, t_client ? t_client->ViceId : 0,
2324 AUD_FID, Fid, AUD_END);
2327 } /*SRXAFS_FetchData */
2330 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2331 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2332 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2334 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2339 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2340 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2341 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2344 afs_sfsize_t tPos, tLen;
2346 #ifdef AFS_64BIT_ENV
2347 #ifndef AFS_LARGEFILE_ENV
2348 if (Pos + Len > 0x7fffffff)
2350 #endif /* !AFS_LARGEFILE_ENV */
2351 tPos = (afs_sfsize_t) Pos;
2352 tLen = (afs_sfsize_t) Len;
2353 #else /* AFS_64BIT_ENV */
2354 if (Pos.high || Len.high)
2358 #endif /* AFS_64BIT_ENV */
2361 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2367 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2368 struct AFSOpaque * AccessList,
2369 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2371 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2372 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2373 Error errorCode = 0; /* return error code to caller */
2374 Volume *volptr = 0; /* pointer to the volume */
2375 struct client *client = 0; /* pointer to the client data */
2376 afs_int32 rights, anyrights; /* rights for this and any user */
2377 struct rx_connection *tcon = rx_ConnectionOf(acall);
2379 struct client *t_client = NULL; /* tmp ptr to client data */
2380 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2381 #if FS_STATS_DETAILED
2382 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2383 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2384 struct timeval elapsedTime; /* Transfer time */
2387 * Set our stats pointer, remember when the RPC operation started, and
2388 * tally the operation.
2390 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2394 FT_GetTimeOfDay(&opStartTime, 0);
2395 #endif /* FS_STATS_DETAILED */
2398 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2401 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2403 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2406 /* Get ptr to client data for user Id for logging */
2407 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2408 logHostAddr.s_addr = rxr_HostOf(tcon);
2410 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2411 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2412 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2414 AccessList->AFSOpaque_len = 0;
2415 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2416 if (!AccessList->AFSOpaque_val) {
2417 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2422 * Get volume/vnode for the fetched file; caller's access rights to it
2426 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2427 &parentwhentargetnotdir, &client, READ_LOCK,
2428 &rights, &anyrights)))
2431 SetVolumeSync(Sync, volptr);
2433 /* Check whether we have permission to fetch the ACL */
2435 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2438 /* Get the Access List from the dir's vnode */
2440 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2443 /* Get OutStatus back From the target Vnode */
2444 GetStatus(targetptr, OutStatus, rights, anyrights,
2445 parentwhentargetnotdir);
2448 /* Update and store volume/vnode and parent vnodes back */
2449 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2452 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2453 AccessList->AFSOpaque_val));
2454 errorCode = CallPostamble(tcon, errorCode, thost);
2456 #if FS_STATS_DETAILED
2457 FT_GetTimeOfDay(&opStopTime, 0);
2458 if (errorCode == 0) {
2460 (opP->numSuccesses)++;
2461 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2462 fs_stats_AddTo((opP->sumTime), elapsedTime);
2463 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2464 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2465 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2467 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2468 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2472 #endif /* FS_STATS_DETAILED */
2474 osi_auditU(acall, FetchACLEvent, errorCode,
2475 AUD_ID, t_client ? t_client->ViceId : 0,
2477 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2479 } /*SRXAFS_FetchACL */
2483 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2484 * merged into it when possible.
2488 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2489 struct AFSFetchStatus *OutStatus,
2490 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2492 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2493 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2494 Error errorCode = 0; /* return code to caller */
2495 Volume *volptr = 0; /* pointer to the volume */
2496 struct client *client = 0; /* pointer to the client data */
2497 afs_int32 rights, anyrights; /* rights for this and any user */
2498 struct client *t_client = NULL; /* tmp ptr to client data */
2499 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2500 struct rx_connection *tcon = rx_ConnectionOf(acall);
2502 /* Get ptr to client data for user Id for logging */
2503 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2504 logHostAddr.s_addr = rxr_HostOf(tcon);
2506 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2507 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2508 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2510 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2513 * Get volume/vnode for the fetched file; caller's rights to it are
2517 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2518 &parentwhentargetnotdir, &client, READ_LOCK,
2519 &rights, &anyrights)))
2520 goto Bad_FetchStatus;
2522 /* set volume synchronization information */
2523 SetVolumeSync(Sync, volptr);
2525 /* Are we allowed to fetch Fid's status? */
2526 if (targetptr->disk.type != vDirectory) {
2528 Check_PermissionRights(targetptr, client, rights,
2529 CHK_FETCHSTATUS, 0))) {
2530 if (rx_GetCallAbortCode(acall) == errorCode)
2531 rx_SetCallAbortCode(acall, 0);
2532 goto Bad_FetchStatus;
2536 /* set OutStatus From the Fid */
2537 GetStatus(targetptr, OutStatus, rights, anyrights,
2538 parentwhentargetnotdir);
2540 /* If a r/w volume, also set the CallBack state */
2541 if (VolumeWriteable(volptr))
2542 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2544 struct AFSFid myFid;
2545 memset(&myFid, 0, sizeof(struct AFSFid));
2546 myFid.Volume = Fid->Volume;
2547 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2551 /* Update and store volume/vnode and parent vnodes back */
2552 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2554 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2557 } /*SAFSS_FetchStatus */
2561 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2562 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2563 struct AFSVolSync * Sync)
2567 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2568 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2569 Error errorCode = 0; /* return code to caller */
2570 Volume *volptr = 0; /* pointer to the volume */
2571 struct client *client = 0; /* pointer to the client data */
2572 afs_int32 rights, anyrights; /* rights for this and any user */
2573 register struct AFSFid *tfid; /* file id we're dealing with now */
2574 struct rx_connection *tcon = rx_ConnectionOf(acall);
2576 struct client *t_client = NULL; /* tmp pointer to the client data */
2577 #if FS_STATS_DETAILED
2578 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2579 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2580 struct timeval elapsedTime; /* Transfer time */
2583 * Set our stats pointer, remember when the RPC operation started, and
2584 * tally the operation.
2586 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2590 FT_GetTimeOfDay(&opStartTime, 0);
2591 #endif /* FS_STATS_DETAILED */
2593 ViceLog(1, ("SAFS_BulkStatus\n"));
2595 AFSCallStats.TotalCalls++;
2597 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2598 if (nfiles <= 0) { /* Sanity check */
2600 goto Audit_and_Return;
2603 /* allocate space for return output parameters */
2604 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2605 malloc(nfiles * sizeof(struct AFSFetchStatus));
2606 if (!OutStats->AFSBulkStats_val) {
2607 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2610 OutStats->AFSBulkStats_len = nfiles;
2611 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2612 malloc(nfiles * sizeof(struct AFSCallBack));
2613 if (!CallBacks->AFSCBs_val) {
2614 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2617 CallBacks->AFSCBs_len = nfiles;
2619 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2620 goto Bad_BulkStatus;
2622 tfid = Fids->AFSCBFids_val;
2623 for (i = 0; i < nfiles; i++, tfid++) {
2625 * Get volume/vnode for the fetched file; caller's rights to it
2629 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2630 &parentwhentargetnotdir, &client, READ_LOCK,
2631 &rights, &anyrights)))
2632 goto Bad_BulkStatus;
2633 /* set volume synchronization information, but only once per call */
2635 SetVolumeSync(Sync, volptr);
2637 /* Are we allowed to fetch Fid's status? */
2638 if (targetptr->disk.type != vDirectory) {
2640 Check_PermissionRights(targetptr, client, rights,
2641 CHK_FETCHSTATUS, 0))) {
2642 if (rx_GetCallAbortCode(acall) == errorCode)
2643 rx_SetCallAbortCode(acall, 0);
2644 goto Bad_BulkStatus;
2648 /* set OutStatus From the Fid */
2649 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2650 anyrights, parentwhentargetnotdir);
2652 /* If a r/w volume, also set the CallBack state */
2653 if (VolumeWriteable(volptr))
2654 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2655 &CallBacks->AFSCBs_val[i]);
2657 struct AFSFid myFid;
2658 memset(&myFid, 0, sizeof(struct AFSFid));
2659 myFid.Volume = tfid->Volume;
2660 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2661 &CallBacks->AFSCBs_val[i]);
2664 /* put back the file ID and volume */
2665 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2667 parentwhentargetnotdir = (Vnode *) 0;
2668 targetptr = (Vnode *) 0;
2669 volptr = (Volume *) 0;
2670 client = (struct client *)0;
2674 /* Update and store volume/vnode and parent vnodes back */
2675 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2677 errorCode = CallPostamble(tcon, errorCode, thost);
2679 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2681 #if FS_STATS_DETAILED
2682 FT_GetTimeOfDay(&opStopTime, 0);
2683 if (errorCode == 0) {
2685 (opP->numSuccesses)++;
2686 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2687 fs_stats_AddTo((opP->sumTime), elapsedTime);
2688 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2689 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2690 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2692 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2693 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2697 #endif /* FS_STATS_DETAILED */
2700 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2701 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2702 AUD_ID, t_client ? t_client->ViceId : 0,
2703 AUD_FIDS, Fids, AUD_END);
2706 } /*SRXAFS_BulkStatus */
2710 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2711 struct AFSBulkStats * OutStats,
2712 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2716 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2717 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2718 Error errorCode = 0; /* return code to caller */
2719 Volume *volptr = 0; /* pointer to the volume */
2720 struct client *client = 0; /* pointer to the client data */
2721 afs_int32 rights, anyrights; /* rights for this and any user */
2722 register struct AFSFid *tfid; /* file id we're dealing with now */
2723 struct rx_connection *tcon;
2725 struct client *t_client = NULL; /* tmp ptr to client data */
2726 AFSFetchStatus *tstatus;
2727 #if FS_STATS_DETAILED
2728 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2729 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2730 struct timeval elapsedTime; /* Transfer time */
2733 * Set our stats pointer, remember when the RPC operation started, and
2734 * tally the operation.
2736 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2740 FT_GetTimeOfDay(&opStartTime, 0);
2741 #endif /* FS_STATS_DETAILED */
2743 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2745 AFSCallStats.TotalCalls++;
2747 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2748 if (nfiles <= 0) { /* Sanity check */
2750 goto Audit_and_Return;
2753 /* allocate space for return output parameters */
2754 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2755 malloc(nfiles * sizeof(struct AFSFetchStatus));
2756 if (!OutStats->AFSBulkStats_val) {
2757 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2760 OutStats->AFSBulkStats_len = nfiles;
2761 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2762 malloc(nfiles * sizeof(struct AFSCallBack));
2763 if (!CallBacks->AFSCBs_val) {
2764 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2767 CallBacks->AFSCBs_len = nfiles;
2769 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2770 goto Bad_InlineBulkStatus;
2773 tfid = Fids->AFSCBFids_val;
2774 for (i = 0; i < nfiles; i++, tfid++) {
2776 * Get volume/vnode for the fetched file; caller's rights to it
2780 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2781 &parentwhentargetnotdir, &client, READ_LOCK,
2782 &rights, &anyrights))) {
2783 tstatus = &OutStats->AFSBulkStats_val[i];
2784 tstatus->errorCode = errorCode;
2785 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2787 parentwhentargetnotdir = (Vnode *) 0;
2788 targetptr = (Vnode *) 0;
2789 volptr = (Volume *) 0;
2790 client = (struct client *)0;
2794 /* set volume synchronization information, but only once per call */
2796 SetVolumeSync(Sync, volptr);
2798 /* Are we allowed to fetch Fid's status? */
2799 if (targetptr->disk.type != vDirectory) {
2801 Check_PermissionRights(targetptr, client, rights,
2802 CHK_FETCHSTATUS, 0))) {
2803 tstatus = &OutStats->AFSBulkStats_val[i];
2804 tstatus->errorCode = errorCode;
2805 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2806 (Vnode *) 0, volptr, &client);
2807 parentwhentargetnotdir = (Vnode *) 0;
2808 targetptr = (Vnode *) 0;
2809 volptr = (Volume *) 0;
2810 client = (struct client *)0;
2815 /* set OutStatus From the Fid */
2816 GetStatus(targetptr,
2817 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2818 rights, anyrights, parentwhentargetnotdir);
2820 /* If a r/w volume, also set the CallBack state */
2821 if (VolumeWriteable(volptr))
2822 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2823 &CallBacks->AFSCBs_val[i]);
2825 struct AFSFid myFid;
2826 memset(&myFid, 0, sizeof(struct AFSFid));
2827 myFid.Volume = tfid->Volume;
2828 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2829 &CallBacks->AFSCBs_val[i]);
2832 /* put back the file ID and volume */
2833 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2835 parentwhentargetnotdir = (Vnode *) 0;
2836 targetptr = (Vnode *) 0;
2837 volptr = (Volume *) 0;
2838 client = (struct client *)0;
2841 Bad_InlineBulkStatus:
2842 /* Update and store volume/vnode and parent vnodes back */
2843 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2845 errorCode = CallPostamble(tcon, errorCode, thost);
2847 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2849 #if FS_STATS_DETAILED
2850 FT_GetTimeOfDay(&opStopTime, 0);
2851 if (errorCode == 0) {
2853 (opP->numSuccesses)++;
2854 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2855 fs_stats_AddTo((opP->sumTime), elapsedTime);
2856 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2857 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2858 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2860 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2861 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2865 #endif /* FS_STATS_DETAILED */
2868 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2869 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2870 AUD_ID, t_client ? t_client->ViceId : 0,
2871 AUD_FIDS, Fids, AUD_END);
2874 } /*SRXAFS_InlineBulkStatus */
2878 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2879 struct AFSFetchStatus * OutStatus,
2880 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2883 struct rx_connection *tcon;
2885 struct client *t_client = NULL; /* tmp ptr to client data */
2886 #if FS_STATS_DETAILED
2887 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2888 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2889 struct timeval elapsedTime; /* Transfer time */
2892 * Set our stats pointer, remember when the RPC operation started, and
2893 * tally the operation.
2895 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2899 FT_GetTimeOfDay(&opStartTime, 0);
2900 #endif /* FS_STATS_DETAILED */
2902 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2903 goto Bad_FetchStatus;
2905 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2908 code = CallPostamble(tcon, code, thost);
2910 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2912 #if FS_STATS_DETAILED
2913 FT_GetTimeOfDay(&opStopTime, 0);
2916 (opP->numSuccesses)++;
2917 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2918 fs_stats_AddTo((opP->sumTime), elapsedTime);
2919 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2920 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2921 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2923 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2924 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2928 #endif /* FS_STATS_DETAILED */
2930 osi_auditU(acall, FetchStatusEvent, code,
2931 AUD_ID, t_client ? t_client->ViceId : 0,
2932 AUD_FID, Fid, AUD_END);
2935 } /*SRXAFS_FetchStatus */
2939 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2940 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2941 afs_fsize_t Length, afs_fsize_t FileLength,
2942 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2944 Vnode *targetptr = 0; /* pointer to input fid */
2945 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2946 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2947 Error errorCode = 0; /* return code for caller */
2948 Error fileCode = 0; /* return code from vol package */
2949 Volume *volptr = 0; /* pointer to the volume header */
2950 struct client *client = 0; /* pointer to client structure */
2951 afs_int32 rights, anyrights; /* rights for this and any user */
2952 struct client *t_client = NULL; /* tmp ptr to client data */
2953 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2954 struct rx_connection *tcon;
2956 #if FS_STATS_DETAILED
2957 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2958 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2959 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2960 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2961 struct timeval elapsedTime; /* Transfer time */
2962 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2963 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2964 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2967 * Set our stats pointers, remember when the RPC operation started, and
2968 * tally the operation.
2970 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2971 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2976 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2978 FT_GetTimeOfDay(&opStartTime, 0);
2979 #endif /* FS_STATS_DETAILED */
2982 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2984 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2987 /* Get ptr to client data for user Id for logging */
2988 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2989 logHostAddr.s_addr = rxr_HostOf(tcon);
2991 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2992 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2993 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2996 * Get associated volume/vnode for the stored file; caller's rights
3000 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3001 &parentwhentargetnotdir, &client, WRITE_LOCK,
3002 &rights, &anyrights))) {
3006 /* set volume synchronization information */
3007 SetVolumeSync(Sync, volptr);
3009 if ((targetptr->disk.type == vSymlink)) {
3010 /* Should we return a better error code here??? */
3015 /* Check if we're allowed to store the data */
3017 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3023 * Drop the read lock on the parent directory after saving the parent
3024 * vnode information we need to pass to GetStatus
3026 if (parentwhentargetnotdir != NULL) {
3027 tparentwhentargetnotdir = *parentwhentargetnotdir;
3028 VPutVnode(&fileCode, parentwhentargetnotdir);
3029 assert(!fileCode || (fileCode == VSALVAGE));
3030 parentwhentargetnotdir = NULL;
3032 #if FS_STATS_DETAILED
3034 * Remember when the data transfer started.
3036 FT_GetTimeOfDay(&xferStartTime, 0);
3037 #endif /* FS_STATS_DETAILED */
3039 /* Do the actual storing of the data */
3040 #if FS_STATS_DETAILED
3042 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3043 FileLength, (InStatus->Mask & AFS_FSYNC),
3044 &bytesToXfer, &bytesXferred);
3047 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3048 FileLength, (InStatus->Mask & AFS_FSYNC));
3049 if (errorCode && (!targetptr->changed_newTime))
3051 #endif /* FS_STATS_DETAILED */
3052 #if FS_STATS_DETAILED
3054 * At this point, the data transfer is done, for good or ill. Remember
3055 * when the transfer ended, bump the number of successes/failures, and
3056 * integrate the transfer size and elapsed time into the stats. If the
3057 * operation failed, we jump to the appropriate point.
3059 FT_GetTimeOfDay(&xferStopTime, 0);
3061 (xferP->numXfers)++;
3063 (xferP->numSuccesses)++;
3066 * Bump the xfer sum by the number of bytes actually sent, NOT the
3069 tot_bytesXferred += bytesXferred;
3070 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3071 tot_bytesXferred &= 0x3FF;
3072 if (bytesXferred < xferP->minBytes)
3073 xferP->minBytes = bytesXferred;
3074 if (bytesXferred > xferP->maxBytes)
3075 xferP->maxBytes = bytesXferred;
3078 * Tally the size of the object. Note: we tally the actual size,
3079 * NOT the number of bytes that made it out over the wire.
3081 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3082 (xferP->count[0])++;
3083 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3084 (xferP->count[1])++;
3085 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3086 (xferP->count[2])++;
3087 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3088 (xferP->count[3])++;
3089 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3090 (xferP->count[4])++;
3091 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3092 (xferP->count[5])++;
3093 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3094 (xferP->count[6])++;
3095 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3096 (xferP->count[7])++;
3098 (xferP->count[8])++;
3100 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3101 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3102 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3103 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3104 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3106 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3107 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3112 * Finally, go off to tell our caller the bad news in case the
3115 if (errorCode && (!targetptr->changed_newTime))
3117 #endif /* FS_STATS_DETAILED */
3119 /* Update the status of the target's vnode */
3120 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3121 targetptr, volptr, 0);
3123 /* Get the updated File's status back to the caller */
3124 GetStatus(targetptr, OutStatus, rights, anyrights,
3125 &tparentwhentargetnotdir);
3128 /* Update and store volume/vnode and parent vnodes back */
3129 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3131 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3133 errorCode = CallPostamble(tcon, errorCode, thost);
3135 #if FS_STATS_DETAILED
3136 FT_GetTimeOfDay(&opStopTime, 0);
3137 if (errorCode == 0) {
3139 (opP->numSuccesses)++;
3140 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3141 fs_stats_AddTo((opP->sumTime), elapsedTime);
3142 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3143 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3144 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3146 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3147 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3151 #endif /* FS_STATS_DETAILED */
3152 osi_auditU(acall, StoreDataEvent, errorCode,
3153 AUD_ID, t_client ? t_client->ViceId : 0,
3154 AUD_FID, Fid, AUD_END);
3156 } /*common_StoreData64 */
3159 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3160 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3161 afs_uint32 Length, afs_uint32 FileLength,
3162 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3164 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3165 (0x7fffffff - Pos) < Length)
3168 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3170 } /*SRXAFS_StoreData */
3173 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3174 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3175 afs_uint64 Length, afs_uint64 FileLength,
3176 struct AFSFetchStatus * OutStatus,
3177 struct AFSVolSync * Sync)
3181 afs_fsize_t tLength;
3182 afs_fsize_t tFileLength;
3184 #ifdef AFS_64BIT_ENV
3185 #ifndef AFS_LARGEFILE_ENV
3186 if (FileLength > 0x7fffffff)
3188 #endif /* !AFS_LARGEFILE_ENV */
3189 tPos = (afs_fsize_t) Pos;
3190 tLength = (afs_fsize_t) Length;
3191 tFileLength = (afs_fsize_t) FileLength;
3192 #else /* AFS_64BIT_ENV */
3193 if (FileLength.high)
3196 tLength = Length.low;
3197 tFileLength = FileLength.low;
3198 #endif /* AFS_64BIT_ENV */
3201 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3207 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3208 struct AFSOpaque * AccessList,
3209 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3211 Vnode *targetptr = 0; /* pointer to input fid */
3212 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3213 Error errorCode = 0; /* return code for caller */
3214 struct AFSStoreStatus InStatus; /* Input status for fid */
3215 Volume *volptr = 0; /* pointer to the volume header */
3216 struct client *client = 0; /* pointer to client structure */
3217 afs_int32 rights, anyrights; /* rights for this and any user */
3218 struct rx_connection *tcon;
3220 struct client *t_client = NULL; /* tmp ptr to client data */
3221 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3222 #if FS_STATS_DETAILED
3223 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3224 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3225 struct timeval elapsedTime; /* Transfer time */
3228 * Set our stats pointer, remember when the RPC operation started, and
3229 * tally the operation.
3231 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3235 FT_GetTimeOfDay(&opStartTime, 0);
3236 #endif /* FS_STATS_DETAILED */
3237 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3240 /* Get ptr to client data for user Id for logging */
3241 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3242 logHostAddr.s_addr = rxr_HostOf(tcon);
3244 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3245 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3246 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3248 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3250 InStatus.Mask = 0; /* not storing any status */
3253 * Get associated volume/vnode for the target dir; caller's rights
3254 * are also returned.
3257 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3258 &parentwhentargetnotdir, &client, WRITE_LOCK,
3259 &rights, &anyrights))) {
3263 /* set volume synchronization information */
3264 SetVolumeSync(Sync, volptr);
3266 /* Check if we have permission to change the dir's ACL */
3268 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3273 /* Build and store the new Access List for the dir */
3274 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3278 targetptr->changed_newTime = 1; /* status change of directory */
3280 /* convert the write lock to a read lock before breaking callbacks */
3281 VVnodeWriteToRead(&errorCode, targetptr);
3282 assert(!errorCode || errorCode == VSALVAGE);
3284 /* break call backs on the directory */
3285 BreakCallBack(client->host, Fid, 0);
3287 /* Get the updated dir's status back to the caller */
3288 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3291 /* Update and store volume/vnode and parent vnodes back */
3292 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3294 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3295 errorCode = CallPostamble(tcon, errorCode, thost);
3297 #if FS_STATS_DETAILED
3298 FT_GetTimeOfDay(&opStopTime, 0);
3299 if (errorCode == 0) {
3301 (opP->numSuccesses)++;
3302 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3303 fs_stats_AddTo((opP->sumTime), elapsedTime);
3304 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3305 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3306 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3308 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3309 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3313 #endif /* FS_STATS_DETAILED */
3315 osi_auditU(acall, StoreACLEvent, errorCode,
3316 AUD_ID, t_client ? t_client->ViceId : 0,
3317 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3320 } /*SRXAFS_StoreACL */
3324 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3325 * should be merged when possible.
3328 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3329 struct AFSStoreStatus *InStatus,
3330 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3332 Vnode *targetptr = 0; /* pointer to input fid */
3333 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3334 Error errorCode = 0; /* return code for caller */
3335 Volume *volptr = 0; /* pointer to the volume header */
3336 struct client *client = 0; /* pointer to client structure */
3337 afs_int32 rights, anyrights; /* rights for this and any user */
3338 struct client *t_client = NULL; /* tmp ptr to client data */
3339 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3340 struct rx_connection *tcon = rx_ConnectionOf(acall);
3342 /* Get ptr to client data for user Id for logging */
3343 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3344 logHostAddr.s_addr = rxr_HostOf(tcon);
3346 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3347 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3348 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3350 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3353 * Get volume/vnode for the target file; caller's rights to it are
3357 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3358 &parentwhentargetnotdir, &client, WRITE_LOCK,
3359 &rights, &anyrights))) {
3360 goto Bad_StoreStatus;
3363 /* set volume synchronization information */
3364 SetVolumeSync(Sync, volptr);
3366 /* Check if the caller has proper permissions to store status to Fid */
3368 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3370 goto Bad_StoreStatus;
3373 * Check for a symbolic link; we can't chmod these (otherwise could
3374 * change a symlink to a mt pt or vice versa)
3376 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3378 goto Bad_StoreStatus;
3381 /* Update the status of the target's vnode */
3382 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3383 (parentwhentargetnotdir ? parentwhentargetnotdir
3384 : targetptr), volptr, 0);
3386 /* convert the write lock to a read lock before breaking callbacks */
3387 VVnodeWriteToRead(&errorCode, targetptr);
3388 assert(!errorCode || errorCode == VSALVAGE);
3390 /* Break call backs on Fid */
3391 BreakCallBack(client->host, Fid, 0);
3393 /* Return the updated status back to caller */
3394 GetStatus(targetptr, OutStatus, rights, anyrights,
3395 parentwhentargetnotdir);
3398 /* Update and store volume/vnode and parent vnodes back */
3399 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3401 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3404 } /*SAFSS_StoreStatus */
3408 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3409 struct AFSStoreStatus * InStatus,
3410 struct AFSFetchStatus * OutStatus,
3411 struct AFSVolSync * Sync)
3414 struct rx_connection *tcon;
3416 struct client *t_client = NULL; /* tmp ptr to client data */
3417 #if FS_STATS_DETAILED
3418 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3419 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3420 struct timeval elapsedTime; /* Transfer time */
3423 * Set our stats pointer, remember when the RPC operation started, and
3424 * tally the operation.
3426 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3430 FT_GetTimeOfDay(&opStartTime, 0);
3431 #endif /* FS_STATS_DETAILED */
3433 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3434 goto Bad_StoreStatus;
3436 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3439 code = CallPostamble(tcon, code, thost);
3441 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3443 #if FS_STATS_DETAILED
3444 FT_GetTimeOfDay(&opStopTime, 0);
3447 (opP->numSuccesses)++;
3448 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3449 fs_stats_AddTo((opP->sumTime), elapsedTime);
3450 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3451 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3452 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3454 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3455 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3459 #endif /* FS_STATS_DETAILED */
3461 osi_auditU(acall, StoreStatusEvent, code,
3462 AUD_ID, t_client ? t_client->ViceId : 0,
3463 AUD_FID, Fid, AUD_END);
3466 } /*SRXAFS_StoreStatus */
3470 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3471 * merged in when possible.