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;
425 tclient = h_FindClient_r(aconn);
428 thost = tclient->host;
429 if (thost->hostFlags & HERRORTRANS)
431 h_ReleaseClient_r(tclient);
433 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
434 * does not decrement refcount on client->host */
438 if (ahost != thost) {
439 /* host/client recycle */
440 char hoststr[16], hoststr2[16];
441 ViceLog(0, ("CallPostamble: ahost %s:%d (%x) != thost "
443 afs_inet_ntoa_r(ahost->host, hoststr),
446 afs_inet_ntoa_r(thost->host, hoststr2),
450 /* return the reference taken in CallPreamble */
454 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%x)\n",
455 afs_inet_ntoa_r(thost->host, hoststr),
462 return (translate ? sys_error_to_et(ret) : ret);
466 * Returns the volume and vnode pointers associated with file Fid; the lock
467 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
468 * are incremented and they must be eventualy released.
471 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
474 Error local_errorCode, errorCode = -1;
475 static struct timeval restartedat = { 0, 0 };
477 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
479 if ((*volptr) == 0) {
484 #ifdef AFS_DEMAND_ATTACH_FS
492 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
497 if ((errorCode == VOFFLINE) && (VInit < 2)) {
498 /* The volume we want may not be attached yet because
499 * the volume initialization is not yet complete.
500 * We can do several things:
501 * 1. return -1, which will cause users to see
502 * "connection timed out". This is more or
503 * less the same as always, except that the servers
504 * may appear to bounce up and down while they
505 * are actually restarting.
506 * 2. return VBUSY which will cause clients to
507 * sleep and retry for 6.5 - 15 minutes, depending
508 * on what version of the CM they are running. If
509 * the file server takes longer than that interval
510 * to attach the desired volume, then the application
511 * will see an ENODEV or EIO. This approach has
512 * the advantage that volumes which have been attached
513 * are immediately available, it keeps the server's
514 * immediate backlog low, and the call is interruptible
515 * by the user. Users see "waiting for busy volume."
516 * 3. sleep here and retry. Some people like this approach
517 * because there is no danger of seeing errors. However,
518 * this approach only works with a bounded number of
519 * clients, since the pending queues will grow without
520 * stopping. It might be better to find a way to take
521 * this call and stick it back on a queue in order to
522 * recycle this thread for a different request.
523 * 4. Return a new error code, which new cache managers will
524 * know enough to interpret as "sleep and retry", without
525 * the upper bound of 6-15 minutes that is imposed by the
526 * VBUSY handling. Users will see "waiting for
527 * busy volume," so they know that something is
528 * happening. Old cache managers must be able to do
529 * something reasonable with this, for instance, mark the
530 * server down. Fortunately, any error code < 0
531 * will elicit that behavior. See #1.
532 * 5. Some combination of the above. I like doing #2 for 10
533 * minutes, followed by #4. 3.1b and 3.2 cache managers
534 * will be fine as long as the restart period is
535 * not longer than 6.5 minutes, otherwise they may
536 * return ENODEV to users. 3.3 cache managers will be
537 * fine for 10 minutes, then will return
538 * ETIMEDOUT. 3.4 cache managers will just wait
539 * until the call works or fails definitively.
540 * NB. The problem with 2,3,4,5 is that old clients won't
541 * fail over to an alternate read-only replica while this
542 * server is restarting. 3.4 clients will fail over right away.
544 if (restartedat.tv_sec == 0) {
545 /* I'm not really worried about when we restarted, I'm */
546 /* just worried about when the first VBUSY was returned. */
547 FT_GetTimeOfDay(&restartedat, 0);
550 afs_perfstats.fs_nBusies++;
553 return (busyonrst ? VBUSY : restarting);
556 FT_GetTimeOfDay(&now, 0);
557 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
560 afs_perfstats.fs_nBusies++;
563 return (busyonrst ? VBUSY : restarting);
569 /* allow read operations on busy volume.
570 * must check local_errorCode because demand attach fs
571 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
572 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
573 #ifdef AFS_DEMAND_ATTACH_FS
574 /* DAFS case is complicated by the fact that local_errorCode can
575 * be VBUSY in cases where the volume is truly offline */
577 /* volume is in VOL_STATE_UNATTACHED */
580 #endif /* AFS_DEMAND_ATTACH_FS */
583 } else if (errorCode)
590 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
593 if ((*vptr)->disk.uniquifier != fid->Unique) {
594 VPutVnode(&fileCode, *vptr);
595 assert(fileCode == 0);
597 return (VNOVNODE); /* return the right error code, at least */
603 * This routine returns the ACL associated with the targetptr. If the
604 * targetptr isn't a directory, we access its parent dir and get the ACL
605 * thru the parent; in such case the parent's vnode is returned in
609 SetAccessList(Vnode ** targetptr, Volume ** volume,
610 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
611 AFSFid * Fid, int Lock)
613 if ((*targetptr)->disk.type == vDirectory) {
615 *ACL = VVnodeACL(*targetptr);
616 *ACLSize = VAclSize(*targetptr);
624 parentvnode = (*targetptr)->disk.parent;
625 VPutVnode(&errorCode, *targetptr);
629 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
632 *ACL = VVnodeACL(*parent);
633 *ACLSize = VAclSize(*parent);
634 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
636 if ((*targetptr)->disk.parent != parentvnode) {
637 VPutVnode(&errorCode, *parent);
648 /* Must not be called with H_LOCK held */
650 client_CheckRights(struct client *client, struct acl_accessList *ACL,
654 ObtainReadLock(&client->lock);
655 if (client->CPS.prlist_len > 0 && !client->deleted &&
656 client->host && !(client->host->hostFlags & HOSTDELETED))
657 acl_CheckRights(ACL, &client->CPS, rights);
658 ReleaseReadLock(&client->lock);
661 /* Must not be called with H_LOCK held */
663 client_HasAsMember(struct client *client, afs_int32 id)
667 ObtainReadLock(&client->lock);
668 if (client->CPS.prlist_len > 0 && !client->deleted &&
669 client->host && !(client->host->hostFlags & HOSTDELETED))
670 code = acl_IsAMember(id, &client->CPS);
671 ReleaseReadLock(&client->lock);
676 * Compare the directory's ACL with the user's access rights in the client
677 * connection and return the user's and everybody else's access permissions
678 * in rights and anyrights, respectively
681 GetRights(struct client *client, struct acl_accessList *ACL,
682 afs_int32 * rights, afs_int32 * anyrights)
684 extern prlist SystemAnyUserCPS;
685 afs_int32 hrights = 0;
686 #ifndef AFS_PTHREAD_ENV
690 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
691 ViceLog(0, ("CheckRights failed\n"));
696 client_CheckRights(client, ACL, rights);
698 /* wait if somebody else is already doing the getCPS call */
700 while (client->host->hostFlags & HCPS_INPROGRESS) {
701 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
702 #ifdef AFS_PTHREAD_ENV
703 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
704 #else /* AFS_PTHREAD_ENV */
706 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
707 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
708 #endif /* AFS_PTHREAD_ENV */
711 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
714 ("CheckRights: len=%u, for host=%s:%d\n",
715 client->host->hcps.prlist_len,
716 afs_inet_ntoa_r(client->host->host, hoststr),
717 ntohs(client->host->port)));
719 acl_CheckRights(ACL, &client->host->hcps, &hrights);
721 /* Allow system:admin the rights given with the -implicit option */
722 if (client_HasAsMember(client, SystemId))
723 *rights |= implicitAdminRights;
726 *anyrights |= hrights;
733 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
734 * a System:Administrator)
737 VanillaUser(struct client *client)
739 if (client_HasAsMember(client, SystemId))
740 return (0); /* not a system administrator, then you're "vanilla" */
747 * This unusual afs_int32-parameter routine encapsulates all volume package related
748 * operations together in a single function; it's called by almost all AFS
752 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
753 Vnode ** targetptr, int chkforDir, Vnode ** parent,
754 struct client **client, int locktype, afs_int32 * rights,
755 afs_int32 * anyrights)
757 struct acl_accessList *aCL; /* Internal access List */
758 int aCLSize; /* size of the access list */
759 Error errorCode = 0; /* return code to caller */
761 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
764 if (chkforDir == MustNOTBeDIR
765 && ((*targetptr)->disk.type == vDirectory))
767 else if (chkforDir == MustBeDIR
768 && ((*targetptr)->disk.type != vDirectory))
772 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
773 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
774 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
776 if (chkforDir == MustBeDIR)
777 assert((*parent) == 0);
779 if ((errorCode = GetClient(tcon, client)) != 0)
784 GetRights(*client, aCL, rights, anyrights);
785 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
786 if ((*targetptr)->disk.type != vDirectory) {
787 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
788 if ((*targetptr)->disk.owner == (*client)->ViceId)
789 (*rights) |= PRSFS_ADMINISTER;
791 (*rights) &= ~PRSFS_ADMINISTER;
793 #ifdef ADMIN_IMPLICIT_LOOKUP
794 /* admins get automatic lookup on everything */
795 if (!VanillaUser(*client))
796 (*rights) |= PRSFS_LOOKUP;
797 #endif /* ADMIN_IMPLICIT_LOOKUP */
800 } /*GetVolumePackage */
804 * This is the opposite of GetVolumePackage(), and is always used at the end of
805 * AFS calls to put back all used vnodes and the volume in the proper order!
808 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
809 Vnode * parentptr, Volume * volptr, struct client **client)
811 Error fileCode = 0; /* Error code returned by the volume package */
813 if (parentwhentargetnotdir) {
814 VPutVnode(&fileCode, parentwhentargetnotdir);
815 assert(!fileCode || (fileCode == VSALVAGE));
818 VPutVnode(&fileCode, targetptr);
819 assert(!fileCode || (fileCode == VSALVAGE));
822 VPutVnode(&fileCode, parentptr);
823 assert(!fileCode || (fileCode == VSALVAGE));
831 } /*PutVolumePackage */
834 VolumeOwner(register struct client *client, register Vnode * targetptr)
836 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
839 return (client->ViceId == owner);
842 * We don't have to check for host's cps since only regular
843 * viceid are volume owners.
845 return (client_HasAsMember(client, owner));
851 VolumeRootVnode(Vnode * targetptr)
853 return ((targetptr->vnodeNumber == ROOTVNODE)
854 && (targetptr->disk.uniquifier == 1));
856 } /*VolumeRootVnode */
859 * Check if target file has the proper access permissions for the Fetch
860 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
861 * StoreStatus) related calls
863 /* this code should probably just set a "priv" flag where all the audit events
864 * are now, and only generate the audit event once at the end of the routine,
865 * thus only generating the event if all the checks succeed, but only because
866 * of the privilege XXX
869 Check_PermissionRights(Vnode * targetptr, struct client *client,
870 afs_int32 rights, int CallingRoutine,
871 AFSStoreStatus * InStatus)
874 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
875 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
876 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
878 if (CallingRoutine & CHK_FETCH) {
879 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
880 if (targetptr->disk.type == vDirectory
881 || targetptr->disk.type == vSymlink) {
882 if (!(rights & PRSFS_LOOKUP)
883 #ifdef ADMIN_IMPLICIT_LOOKUP
884 /* grant admins fetch on all directories */
885 && VanillaUser(client)
886 #endif /* ADMIN_IMPLICIT_LOOKUP */
887 && !VolumeOwner(client, targetptr))
890 /* must have read access, or be owner and have insert access */
891 if (!(rights & PRSFS_READ)
892 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
895 if (CallingRoutine == CHK_FETCHDATA
896 && targetptr->disk.type == vFile)
897 #ifdef USE_GROUP_PERMS
898 if (!OWNSp(client, targetptr)
899 && !client_HasAsMember(client, targetptr->disk.owner)) {
901 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
905 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
910 * The check with the ownership below is a kludge to allow
911 * reading of files created with no read permission. The owner
912 * of the file is always allowed to read it.
914 if ((client->ViceId != targetptr->disk.owner)
915 && VanillaUser(client))
917 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
918 modeBits) ? 0 : EACCES);
920 } else { /* !VanillaUser(client) && !FetchData */
922 osi_audit(PrivilegeEvent, 0, AUD_ID,
923 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
926 } else { /* a store operation */
927 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
928 && (CallingRoutine != CHK_STOREACL)
929 && (targetptr->disk.type == vFile)) {
930 /* bypass protection checks on first store after a create
931 * for the creator; also prevent chowns during this time
932 * unless you are a system administrator */
933 /****** InStatus->Owner && UnixModeBits better be SET!! */
934 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
937 else if (VanillaUser(client))
938 return (EPERM); /* Was EACCES */
940 osi_audit(PrivilegeEvent, 0, AUD_ID,
941 (client ? client->ViceId : 0), AUD_INT,
942 CallingRoutine, AUD_END);
945 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
946 osi_audit(PrivilegeEvent, 0, AUD_ID,
947 (client ? client->ViceId : 0), AUD_INT,
948 CallingRoutine, AUD_END);
950 if (readonlyServer) {
953 if (CallingRoutine == CHK_STOREACL) {
954 if (!(rights & PRSFS_ADMINISTER)
955 && !VolumeOwner(client, targetptr))
957 } else { /* store data or status */
958 /* watch for chowns and chgrps */
959 if (CHOWN(InStatus, targetptr)
960 || CHGRP(InStatus, targetptr)) {
963 else if (VanillaUser(client))
964 return (EPERM); /* Was EACCES */
966 osi_audit(PrivilegeEvent, 0, AUD_ID,
967 (client ? client->ViceId : 0), AUD_INT,
968 CallingRoutine, AUD_END);
970 /* must be sysadmin to set suid/sgid bits */
971 if ((InStatus->Mask & AFS_SETMODE) &&
973 (InStatus->UnixModeBits & 0xc00) != 0) {
975 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
979 if (VanillaUser(client))
982 osi_audit(PrivSetID, 0, AUD_ID,
983 (client ? client->ViceId : 0), AUD_INT,
984 CallingRoutine, AUD_END);
986 if (CallingRoutine == CHK_STOREDATA) {
989 if (!(rights & PRSFS_WRITE))
991 /* Next thing is tricky. We want to prevent people
992 * from writing files sans 0200 bit, but we want
993 * creating new files with 0444 mode to work. We
994 * don't check the 0200 bit in the "you are the owner"
995 * path above, but here we check the bit. However, if
996 * you're a system administrator, we ignore the 0200
997 * bit anyway, since you may have fchowned the file,
999 #ifdef USE_GROUP_PERMS
1000 if ((targetptr->disk.type == vFile)
1001 && VanillaUser(client)) {
1002 if (!OWNSp(client, targetptr)
1003 && !client_HasAsMember(client, targetptr->disk.owner)) {
1005 ((GROUPWRITE & targetptr->disk.modeBits)
1009 ((OWNERWRITE & targetptr->disk.modeBits)
1014 if ((targetptr->disk.type != vDirectory)
1015 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1018 if (VanillaUser(client))
1021 osi_audit(PrivilegeEvent, 0, AUD_ID,
1022 (client ? client->ViceId : 0),
1023 AUD_INT, CallingRoutine, AUD_END);
1025 } else { /* a status store */
1028 if (targetptr->disk.type == vDirectory) {
1029 if (!(rights & PRSFS_DELETE)
1030 && !(rights & PRSFS_INSERT))
1032 } else { /* a file or symlink */
1033 if (!(rights & PRSFS_WRITE))
1043 } /*Check_PermissionRights */
1047 * The Access List information is converted from its internal form in the
1048 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1049 * external form and returned back to the caller, via the AccessList
1053 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1054 struct AFSOpaque *AccessList)
1056 char *eACL; /* External access list placeholder */
1059 ((targetptr->disk.type ==
1060 vDirectory ? VVnodeACL(targetptr) :
1061 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1064 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1065 acl_FreeExternalACL(&eACL);
1068 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1069 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1071 acl_FreeExternalACL(&eACL);
1074 } /*RXFetch_AccessList */
1078 * The Access List information is converted from its external form in the
1079 * input AccessList structure to the internal representation and copied into
1080 * the target dir's vnode storage.
1083 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1085 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1087 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
1089 if ((newACL->size + 4) > VAclSize(targetptr))
1091 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1092 acl_FreeACL(&newACL);
1095 } /*RXStore_AccessList */
1098 /* In our current implementation, each successive data store (new file
1099 * data version) creates a new inode. This function creates the new
1100 * inode, copies the old inode's contents to the new one, remove the old
1101 * inode (i.e. decrement inode count -- if it's currently used the delete
1102 * will be delayed), and modify some fields (i.e. vnode's
1103 * disk.inodeNumber and cloned)
1105 #define COPYBUFFSIZE 8192
1106 #define MAXFSIZE (~(afs_fsize_t) 0)
1108 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_fsize_t off, afs_fsize_t len)
1110 Inode ino, nearInode;
1113 register afs_fsize_t size;
1114 register int length;
1116 int rc; /* return code */
1117 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1118 FdHandle_t *targFdP; /* Source Inode file handle */
1119 FdHandle_t *newFdP; /* Dest Inode file handle */
1121 if (targetptr->disk.type == vDirectory)
1122 DFlush(); /* just in case? */
1124 VN_GET_LEN(size, targetptr);
1132 buff = (char *)malloc(COPYBUFFSIZE);
1137 ino = VN_GET_INO(targetptr);
1138 if (!VALID_INO(ino)) {
1140 VTakeOffline(volptr);
1141 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1145 targFdP = IH_OPEN(targetptr->handle);
1146 if (targFdP == NULL) {
1149 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1150 targetptr->vnodeNumber, V_id(volptr), rc));
1152 VTakeOffline(volptr);
1156 nearInode = VN_GET_INO(targetptr);
1158 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1159 VPartitionPath(V_partition(volptr)), nearInode,
1160 V_id(volptr), targetptr->vnodeNumber,
1161 targetptr->disk.uniquifier,
1162 (int)targetptr->disk.dataVersion);
1163 if (!VALID_INO(ino)) {
1165 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1166 volptr->partition->name, V_id(volptr), errno));
1171 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1172 newFdP = IH_OPEN(newH);
1173 assert(newFdP != NULL);
1175 FDH_SEEK(targFdP, off, SEEK_SET);
1176 FDH_SEEK(newFdP, off, SEEK_SET);
1178 if (size > COPYBUFFSIZE) { /* more than a buffer */
1179 length = COPYBUFFSIZE;
1180 size -= COPYBUFFSIZE;
1185 rdlen = FDH_READ(targFdP, buff, length);
1186 if (rdlen == length)
1187 wrlen = FDH_WRITE(newFdP, buff, length);
1190 /* Callers of this function are not prepared to recover
1191 * from error that put the filesystem in an inconsistent
1192 * state. Make sure that we force the volume off-line if
1193 * we some error other than ENOSPC - 4.29.99)
1195 * In case we are unable to write the required bytes, and the
1196 * error code indicates that the disk is full, we roll-back to
1197 * the initial state.
1199 if ((rdlen != length) || (wrlen != length)) {
1200 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1202 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1203 volptr->partition->name, V_id(volptr)));
1204 /* remove destination inode which was partially copied till now */
1205 FDH_REALLYCLOSE(newFdP);
1207 FDH_REALLYCLOSE(targFdP);
1208 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1211 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1212 rc, V_id(volptr), volptr->partition->name));
1213 VTakeOffline(volptr);
1219 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1220 V_id(volptr), volptr->partition->name, length, rdlen,
1222 #if defined(AFS_DEMAND_ATTACH_FS)
1223 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1225 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1227 /* Decrement this inode so salvager doesn't find it. */
1228 FDH_REALLYCLOSE(newFdP);
1230 FDH_REALLYCLOSE(targFdP);
1231 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1233 VTakeOffline(volptr);
1237 #ifndef AFS_PTHREAD_ENV
1239 #endif /* !AFS_PTHREAD_ENV */
1241 FDH_REALLYCLOSE(targFdP);
1242 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1243 V_parentId(volptr));
1245 IH_RELEASE(targetptr->handle);
1247 rc = FDH_SYNC(newFdP);
1250 targetptr->handle = newH;
1251 VN_SET_INO(targetptr, ino);
1252 targetptr->disk.cloned = 0;
1253 /* Internal change to vnode, no user level change to volume - def 5445 */
1254 targetptr->changed_oldTime = 1;
1256 return 0; /* success */
1260 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_fsize_t off, afs_fsize_t size) {
1261 char *buff = (char *)malloc(COPYBUFFSIZE);
1262 register int length;
1267 FDH_SEEK(targFdP, off, SEEK_SET);
1268 FDH_SEEK(newFdP, off, SEEK_SET);
1270 if (size > FDH_SIZE(targFdP) - off) size = FDH_SIZE(targFdP) - off;
1272 if (size > COPYBUFFSIZE) { /* more than a buffer */
1273 length = COPYBUFFSIZE;
1274 size -= COPYBUFFSIZE;
1279 rdlen = FDH_READ(targFdP, buff, length);
1280 if (rdlen == length)
1281 wrlen = FDH_WRITE(newFdP, buff, length);
1285 if ((rdlen != length) || (wrlen != length)) {
1286 /* no error recovery, at the worst we'll have a "hole" in the file */
1297 * Common code to handle with removing the Name (file when it's called from
1298 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1299 * given directory, parentptr.
1301 int DT1 = 0, DT0 = 0;
1303 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1304 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1306 DirHandle childdir; /* Handle for dir package I/O */
1307 Error errorCode = 0;
1310 /* watch for invalid names */
1311 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1313 if (parentptr->disk.cloned) {
1314 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1315 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1317 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1323 /* check that the file is in the directory */
1324 SetDirHandle(dir, parentptr);
1325 if (Lookup(dir, Name, fileFid))
1327 fileFid->Volume = V_id(volptr);
1329 /* just-in-case check for something causing deadlock */
1330 if (fileFid->Vnode == parentptr->vnodeNumber)
1333 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1337 if (ChkForDir == MustBeDIR) {
1338 if ((*targetptr)->disk.type != vDirectory)
1340 } else if ((*targetptr)->disk.type == vDirectory)
1343 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1345 * If the uniquifiers dont match then instead of asserting
1346 * take the volume offline and return VSALVAGE
1348 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1349 VTakeOffline(volptr);
1351 ("Volume %u now offline, must be salvaged.\n",
1353 errorCode = VSALVAGE;
1357 if (ChkForDir == MustBeDIR) {
1358 SetDirHandle(&childdir, *targetptr);
1359 if (IsEmpty(&childdir) != 0)
1361 DZap((afs_int32 *) &childdir);
1363 (*targetptr)->delete = 1;
1364 } else if ((--(*targetptr)->disk.linkCount) == 0)
1365 (*targetptr)->delete = 1;
1366 if ((*targetptr)->delete) {
1367 if (VN_GET_INO(*targetptr)) {
1369 IH_REALLYCLOSE((*targetptr)->handle);
1371 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1372 V_parentId(volptr));
1373 IH_RELEASE((*targetptr)->handle);
1374 if (errorCode == -1) {
1376 ("DT: inode=%s, name=%s, errno=%d\n",
1377 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1379 if (errno != ENOENT)
1381 VTakeOffline(volptr);
1383 ("Volume %u now offline, must be salvaged.\n",
1391 VN_SET_INO(*targetptr, (Inode) 0);
1393 afs_fsize_t adjLength;
1394 VN_GET_LEN(adjLength, *targetptr);
1395 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1399 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1401 code = Delete(dir, (char *)Name);
1404 ("Error %d deleting %s\n", code,
1405 (((*targetptr)->disk.type ==
1406 Directory) ? "directory" : "file")));
1407 VTakeOffline(volptr);
1409 ("Volume %u now offline, must be salvaged.\n",
1422 * This routine updates the parent directory's status block after the
1423 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1424 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1428 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1429 int author, int linkcount,
1430 #if FS_STATS_DETAILED
1431 char a_inSameNetwork
1432 #endif /* FS_STATS_DETAILED */
1435 afs_fsize_t newlength; /* Holds new directory length */
1436 afs_fsize_t parentLength;
1438 #if FS_STATS_DETAILED
1439 Date currDate; /*Current date */
1440 int writeIdx; /*Write index to bump */
1441 int timeIdx; /*Authorship time index to bump */
1442 #endif /* FS_STATS_DETAILED */
1444 parentptr->disk.dataVersion++;
1445 newlength = (afs_fsize_t) Length(dir);
1447 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1448 * (create, symlink, link, makedir) so we need to check if we have enough space
1449 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1450 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1452 VN_GET_LEN(parentLength, parentptr);
1453 if (nBlocks(newlength) != nBlocks(parentLength)) {
1454 VAdjustDiskUsage(&errorCode, volptr,
1455 (nBlocks(newlength) - nBlocks(parentLength)),
1456 (nBlocks(newlength) - nBlocks(parentLength)));
1458 VN_SET_LEN(parentptr, newlength);
1460 #if FS_STATS_DETAILED
1462 * Update directory write stats for this volume. Note that the auth
1463 * counter is located immediately after its associated ``distance''
1466 if (a_inSameNetwork)
1467 writeIdx = VOL_STATS_SAME_NET;
1469 writeIdx = VOL_STATS_DIFF_NET;
1470 V_stat_writes(volptr, writeIdx)++;
1471 if (author != AnonymousID) {
1472 V_stat_writes(volptr, writeIdx + 1)++;
1476 * Update the volume's authorship information in response to this
1477 * directory operation. Get the current time, decide to which time
1478 * slot this operation belongs, and bump the appropriate slot.
1480 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1482 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1483 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1484 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1485 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1486 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1487 if (parentptr->disk.author == author) {
1488 V_stat_dirSameAuthor(volptr, timeIdx)++;
1490 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1492 #endif /* FS_STATS_DETAILED */
1494 parentptr->disk.author = author;
1495 parentptr->disk.linkCount = linkcount;
1496 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1497 parentptr->disk.serverModifyTime = FT_ApproxTime();
1498 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1503 * Update the target file's (or dir's) status block after the specified
1504 * operation is complete. Note that some other fields maybe updated by
1505 * the individual module.
1508 /* XXX INCOMPLETE - More attention is needed here! */
1510 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1511 struct client *client, AFSStoreStatus * InStatus,
1512 Vnode * parentptr, Volume * volptr,
1515 #if FS_STATS_DETAILED
1516 Date currDate; /*Current date */
1517 int writeIdx; /*Write index to bump */
1518 int timeIdx; /*Authorship time index to bump */
1519 #endif /* FS_STATS_DETAILED */
1521 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1522 targetptr->disk.parent = parentptr->vnodeNumber;
1523 VN_SET_LEN(targetptr, length);
1524 /* targetptr->disk.group = 0; save some cycles */
1525 targetptr->disk.modeBits = 0777;
1526 targetptr->disk.owner = client->ViceId;
1527 targetptr->disk.dataVersion = 0; /* consistent with the client */
1528 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1529 /* the inode was created in Alloc_NewVnode() */
1531 #if FS_STATS_DETAILED
1533 * Update file write stats for this volume. Note that the auth
1534 * counter is located immediately after its associated ``distance''
1537 if (client->InSameNetwork)
1538 writeIdx = VOL_STATS_SAME_NET;
1540 writeIdx = VOL_STATS_DIFF_NET;
1541 V_stat_writes(volptr, writeIdx)++;
1542 if (client->ViceId != AnonymousID) {
1543 V_stat_writes(volptr, writeIdx + 1)++;
1547 * We only count operations that DON'T involve creating new objects
1548 * (files, symlinks, directories) or simply setting status as
1549 * authorship-change operations.
1551 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1553 * Update the volume's authorship information in response to this
1554 * file operation. Get the current time, decide to which time
1555 * slot this operation belongs, and bump the appropriate slot.
1557 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1560 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1561 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1562 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1563 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1564 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1565 VOL_STATS_TIME_IDX_5);
1566 if (targetptr->disk.author == client->ViceId) {
1567 V_stat_fileSameAuthor(volptr, timeIdx)++;
1569 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1572 #endif /* FS_STATS_DETAILED */
1574 if (!(Caller & TVS_SSTATUS))
1575 targetptr->disk.author = client->ViceId;
1576 if (Caller & TVS_SDATA) {
1577 targetptr->disk.dataVersion++;
1578 if (VanillaUser(client)) {
1579 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1580 #ifdef CREATE_SGUID_ADMIN_ONLY
1581 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1585 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1586 /* store status, must explicitly request to change the date */
1587 if (InStatus->Mask & AFS_SETMODTIME)
1588 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1589 } else { /* other: date always changes, but perhaps to what is specified by caller */
1590 targetptr->disk.unixModifyTime =
1591 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1592 ClientModTime : FT_ApproxTime());
1594 if (InStatus->Mask & AFS_SETOWNER) {
1595 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1596 if (VanillaUser(client)) {
1597 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1598 #ifdef CREATE_SGUID_ADMIN_ONLY
1599 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1602 targetptr->disk.owner = InStatus->Owner;
1603 if (VolumeRootVnode(targetptr)) {
1604 Error errorCode = 0; /* what should be done with this? */
1606 V_owner(targetptr->volumePtr) = InStatus->Owner;
1607 VUpdateVolume(&errorCode, targetptr->volumePtr);
1610 if (InStatus->Mask & AFS_SETMODE) {
1611 int modebits = InStatus->UnixModeBits;
1612 #define CREATE_SGUID_ADMIN_ONLY 1
1613 #ifdef CREATE_SGUID_ADMIN_ONLY
1614 if (VanillaUser(client))
1615 modebits = modebits & 0777;
1617 if (VanillaUser(client)) {
1618 targetptr->disk.modeBits = modebits;
1620 targetptr->disk.modeBits = modebits;
1623 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1624 CHK_STOREDATA, AUD_END);
1628 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1629 CHK_STORESTATUS, AUD_END);
1636 targetptr->disk.serverModifyTime = FT_ApproxTime();
1637 if (InStatus->Mask & AFS_SETGROUP)
1638 targetptr->disk.group = InStatus->Group;
1639 /* vnode changed : to be written back by VPutVnode */
1640 targetptr->changed_newTime = 1;
1642 } /*Update_TargetVnodeStatus */
1646 * Fills the CallBack structure with the expiration time and type of callback
1647 * structure. Warning: this function is currently incomplete.
1650 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1652 /* CallBackTime could not be 0 */
1653 if (CallBackTime == 0) {
1654 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1655 CallBack->ExpirationTime = 0;
1657 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1658 CallBack->CallBackVersion = CALLBACK_VERSION;
1659 CallBack->CallBackType = CB_SHARED; /* The default for now */
1661 } /*SetCallBackStruct */
1665 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1666 * allocation; if some error occured (exceeded volume quota or partition
1667 * was full, or whatever), it frees the space back and returns the code.
1668 * We usually pre-adjust the volume space to make sure that there's
1669 * enough space before consuming some.
1672 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1673 afs_sfsize_t checkLength)
1678 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1680 VAdjustDiskUsage(&nc, volptr, -length, 0);
1681 if (rc == VOVERQUOTA) {
1683 ("Volume %u (%s) is full\n", V_id(volptr),
1687 if (rc == VDISKFULL) {
1689 ("Partition %s that contains volume %u is full\n",
1690 volptr->partition->name, V_id(volptr)));
1693 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1698 } /*AdjustDiskUsage */
1701 * Common code that handles the creation of a new file (SAFS_CreateFile and
1702 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1705 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1706 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1707 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1709 Error errorCode = 0; /* Error code returned back */
1712 Inode nearInode; /* hint for inode allocation in solaris */
1715 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1716 BlocksPreallocatedForVnode))) {
1718 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1719 (afs_intmax_t) BlocksPreallocatedForVnode));
1723 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1724 if (errorCode != 0) {
1725 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1728 OutFid->Volume = V_id(volptr);
1729 OutFid->Vnode = (*targetptr)->vnodeNumber;
1730 OutFid->Unique = (*targetptr)->disk.uniquifier;
1732 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1734 /* create the inode now itself */
1736 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1737 VPartitionPath(V_partition(volptr)), nearInode,
1738 V_id(volptr), (*targetptr)->vnodeNumber,
1739 (*targetptr)->disk.uniquifier, 1);
1741 /* error in creating inode */
1742 if (!VALID_INO(inode)) {
1744 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1745 (*targetptr)->volumePtr->header->diskstuff.id,
1746 (*targetptr)->vnodeNumber, errno));
1747 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1748 (*targetptr)->delete = 1; /* delete vnode */
1751 VN_SET_INO(*targetptr, inode);
1752 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1754 /* copy group from parent dir */
1755 (*targetptr)->disk.group = parentptr->disk.group;
1757 if (parentptr->disk.cloned) {
1758 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1759 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1760 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1761 /* delete the vnode previously allocated */
1762 (*targetptr)->delete = 1;
1763 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1764 IH_REALLYCLOSE((*targetptr)->handle);
1765 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1767 ("Alloc_NewVnode: partition %s idec %s failed\n",
1768 volptr->partition->name, PrintInode(NULL, inode)));
1769 IH_RELEASE((*targetptr)->handle);
1775 /* add the name to the directory */
1776 SetDirHandle(dir, parentptr);
1777 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1778 (*targetptr)->delete = 1;
1779 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1780 IH_REALLYCLOSE((*targetptr)->handle);
1781 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1783 ("Alloc_NewVnode: partition %s idec %s failed\n",
1784 volptr->partition->name, PrintInode(NULL, inode)));
1785 IH_RELEASE((*targetptr)->handle);
1791 } /*Alloc_NewVnode */
1795 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1799 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1801 int Time; /* Used for time */
1802 int writeVnode = targetptr->changed_oldTime; /* save original status */
1804 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1805 Time = FT_ApproxTime();
1806 switch (LockingType) {
1809 if (Time > targetptr->disk.lock.lockTime)
1810 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1812 Time += AFS_LOCKWAIT;
1813 if (LockingType == LockRead) {
1814 if ( !(rights & PRSFS_LOCK) &&
1815 !(rights & PRSFS_WRITE) &&
1816 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1819 if (targetptr->disk.lock.lockCount >= 0) {
1820 ++(targetptr->disk.lock.lockCount);
1821 targetptr->disk.lock.lockTime = Time;
1824 } else if (LockingType == LockWrite) {
1825 if ( !(rights & PRSFS_WRITE) &&
1826 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1829 if (targetptr->disk.lock.lockCount == 0) {
1830 targetptr->disk.lock.lockCount = -1;
1831 targetptr->disk.lock.lockTime = Time;
1837 Time += AFS_LOCKWAIT;
1838 if (targetptr->disk.lock.lockCount != 0)
1839 targetptr->disk.lock.lockTime = Time;
1844 if ((--targetptr->disk.lock.lockCount) <= 0)
1845 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1849 targetptr->changed_oldTime = writeVnode; /* restore old status */
1850 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1853 } /*HandleLocking */
1855 /* 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. */
1858 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1862 if (!(rights & Prfs_Mode))
1864 if ((targetptr->disk.type != vDirectory)
1865 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1871 * If some flags (i.e. min or max quota) are set, the volume's in disk
1872 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1873 * update, if applicable.
1876 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1877 char *Name, char *OfflineMsg, char *Motd)
1879 Error errorCode = 0;
1881 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1882 V_minquota(volptr) = StoreVolStatus->MinQuota;
1883 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1884 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1885 if (strlen(OfflineMsg) > 0) {
1886 strcpy(V_offlineMessage(volptr), OfflineMsg);
1888 if (strlen(Name) > 0) {
1889 strcpy(V_name(volptr), Name);
1891 #if OPENAFS_VOL_STATS
1893 * We don't overwrite the motd field, since it's now being used
1897 if (strlen(Motd) > 0) {
1898 strcpy(V_motd(volptr), Motd);
1900 #endif /* FS_STATS_DETAILED */
1901 VUpdateVolume(&errorCode, volptr);
1904 } /*RXUpdate_VolumeStatus */
1908 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1909 char **motd, Volume * volptr)
1913 status->Vid = V_id(volptr);
1914 status->ParentId = V_parentId(volptr);
1915 status->Online = V_inUse(volptr);
1916 status->InService = V_inService(volptr);
1917 status->Blessed = V_blessed(volptr);
1918 status->NeedsSalvage = V_needsSalvaged(volptr);
1919 if (VolumeWriteable(volptr))
1920 status->Type = ReadWrite;
1922 status->Type = ReadOnly;
1923 status->MinQuota = V_minquota(volptr);
1924 status->MaxQuota = V_maxquota(volptr);
1925 status->BlocksInUse = V_diskused(volptr);
1926 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1927 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1929 /* now allocate and copy these things; they're freed by the RXGEN stub */
1930 temp = strlen(V_name(volptr)) + 1;
1931 *name = malloc(temp);
1933 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1936 strcpy(*name, V_name(volptr));
1937 temp = strlen(V_offlineMessage(volptr)) + 1;
1938 *offMsg = malloc(temp);
1940 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1943 strcpy(*offMsg, V_offlineMessage(volptr));
1944 #if OPENAFS_VOL_STATS
1947 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1950 strcpy(*motd, nullString);
1952 temp = strlen(V_motd(volptr)) + 1;
1953 *motd = malloc(temp);
1955 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1958 strcpy(*motd, V_motd(volptr));
1959 #endif /* FS_STATS_DETAILED */
1961 } /*RXGetVolumeStatus */
1965 FileNameOK(register char *aname)
1967 register afs_int32 i, tc;
1970 /* watch for @sys on the right */
1971 if (strcmp(aname + i - 4, "@sys") == 0)
1974 while ((tc = *aname++)) {
1976 return 0; /* very bad character to encounter */
1978 return 1; /* file name is ok */
1984 * This variant of symlink is expressly to support the AFS/DFS translator
1985 * and is not supported by the AFS fileserver. We just return EINVAL.
1986 * The cache manager should not generate this call to an AFS cache manager.
1989 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1990 char *LinkContents, struct AFSStoreStatus *InStatus,
1991 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1992 struct AFSFetchStatus *OutDirStatus,
1993 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1999 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2000 struct FsCmdInputs * Inputs,
2001 struct FsCmdOutputs * Outputs)
2005 switch (Inputs->command) {
2009 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2010 Inputs->command, Outputs->code));
2015 static struct afs_buffer {
2016 struct afs_buffer *next;
2017 } *freeBufferList = 0;
2018 static int afs_buffersAlloced = 0;
2021 FreeSendBuffer(register struct afs_buffer *adata)
2024 afs_buffersAlloced--;
2025 adata->next = freeBufferList;
2026 freeBufferList = adata;
2030 } /*FreeSendBuffer */
2032 /* allocate space for sender */
2036 register struct afs_buffer *tp;
2039 afs_buffersAlloced++;
2040 if (!freeBufferList) {
2043 tmp = malloc(sendBufSize);
2045 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2050 tp = freeBufferList;
2051 freeBufferList = tp->next;
2055 } /*AllocSendBuffer */
2056 #endif /* AFS_NT40_ENV */
2059 * This routine returns the status info associated with the targetptr vnode
2060 * in the AFSFetchStatus structure. Some of the newer fields, such as
2061 * SegSize and Group are not yet implemented
2065 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2066 afs_int32 anyrights, Vnode * parentptr)
2068 /* initialize return status from a vnode */
2069 status->InterfaceVersion = 1;
2070 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2071 status->errorCode = 0;
2072 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2073 if (targetptr->disk.type == vFile)
2074 status->FileType = File;
2075 else if (targetptr->disk.type == vDirectory)
2076 status->FileType = Directory;
2077 else if (targetptr->disk.type == vSymlink)
2078 status->FileType = SymbolicLink;
2080 status->FileType = Invalid; /*invalid type field */
2081 status->LinkCount = targetptr->disk.linkCount;
2083 afs_fsize_t targetLen;
2084 VN_GET_LEN(targetLen, targetptr);
2085 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2087 status->DataVersion = targetptr->disk.dataVersion;
2088 status->Author = targetptr->disk.author;
2089 status->Owner = targetptr->disk.owner;
2090 status->CallerAccess = rights;
2091 status->AnonymousAccess = anyrights;
2092 status->UnixModeBits = targetptr->disk.modeBits;
2093 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2094 status->ParentVnode =
2095 (status->FileType ==
2096 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2097 status->ParentUnique =
2098 (status->FileType ==
2099 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2100 status->ServerModTime = targetptr->disk.serverModifyTime;
2101 status->Group = targetptr->disk.group;
2102 status->lockCount = targetptr->disk.lock.lockCount;
2103 status->errorCode = 0;
2109 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2110 afs_sfsize_t Pos, afs_sfsize_t Len,
2111 struct AFSFetchStatus *OutStatus,
2112 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2115 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2116 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2117 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2118 Error errorCode = 0; /* return code to caller */
2119 Error fileCode = 0; /* return code from vol package */
2120 Volume *volptr = 0; /* pointer to the volume */
2121 struct client *client = 0; /* pointer to the client data */
2122 struct rx_connection *tcon; /* the connection we're part of */
2124 afs_int32 rights, anyrights; /* rights for this and any user */
2125 struct client *t_client = NULL; /* tmp ptr to client data */
2126 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2127 #if FS_STATS_DETAILED
2128 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2129 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2130 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2131 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2132 struct timeval elapsedTime; /* Transfer time */
2133 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2134 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2135 int readIdx; /* Index of read stats array to bump */
2136 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2139 * Set our stats pointers, remember when the RPC operation started, and
2140 * tally the operation.
2142 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2143 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2147 FT_GetTimeOfDay(&opStartTime, 0);
2148 #endif /* FS_STATS_DETAILED */
2151 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2154 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2156 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2159 /* Get ptr to client data for user Id for logging */
2160 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2161 logHostAddr.s_addr = rxr_HostOf(tcon);
2163 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2164 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2165 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2167 * Get volume/vnode for the fetched file; caller's access rights to
2168 * it are also returned
2171 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2172 &parentwhentargetnotdir, &client, READ_LOCK,
2173 &rights, &anyrights)))
2176 SetVolumeSync(Sync, volptr);
2178 #if FS_STATS_DETAILED
2180 * Remember that another read operation was performed.
2183 if (client->InSameNetwork)
2184 readIdx = VOL_STATS_SAME_NET;
2186 readIdx = VOL_STATS_DIFF_NET;
2187 V_stat_reads(volptr, readIdx)++;
2188 if (client->ViceId != AnonymousID) {
2189 V_stat_reads(volptr, readIdx + 1)++;
2192 #endif /* FS_STATS_DETAILED */
2193 /* Check whether the caller has permission access to fetch the data */
2195 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2199 * Drop the read lock on the parent directory after saving the parent
2200 * vnode information we need to pass to GetStatus
2202 if (parentwhentargetnotdir != NULL) {
2203 tparentwhentargetnotdir = *parentwhentargetnotdir;
2204 VPutVnode(&fileCode, parentwhentargetnotdir);
2205 assert(!fileCode || (fileCode == VSALVAGE));
2206 parentwhentargetnotdir = NULL;
2208 #if FS_STATS_DETAILED
2210 * Remember when the data transfer started.
2212 FT_GetTimeOfDay(&xferStartTime, 0);
2213 #endif /* FS_STATS_DETAILED */
2215 /* actually do the data transfer */
2216 #if FS_STATS_DETAILED
2218 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2219 &bytesToXfer, &bytesXferred);
2222 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2224 #endif /* FS_STATS_DETAILED */
2226 #if FS_STATS_DETAILED
2228 * At this point, the data transfer is done, for good or ill. Remember
2229 * when the transfer ended, bump the number of successes/failures, and
2230 * integrate the transfer size and elapsed time into the stats. If the
2231 * operation failed, we jump to the appropriate point.
2233 FT_GetTimeOfDay(&xferStopTime, 0);
2235 (xferP->numXfers)++;
2237 (xferP->numSuccesses)++;
2240 * Bump the xfer sum by the number of bytes actually sent, NOT the
2243 tot_bytesXferred += bytesXferred;
2244 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2245 tot_bytesXferred &= 0x3FF;
2246 if (bytesXferred < xferP->minBytes)
2247 xferP->minBytes = bytesXferred;
2248 if (bytesXferred > xferP->maxBytes)
2249 xferP->maxBytes = bytesXferred;
2252 * Tally the size of the object. Note: we tally the actual size,
2253 * NOT the number of bytes that made it out over the wire.
2255 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2256 (xferP->count[0])++;
2257 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2258 (xferP->count[1])++;
2259 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2260 (xferP->count[2])++;
2261 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2262 (xferP->count[3])++;
2263 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2264 (xferP->count[4])++;
2265 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2266 (xferP->count[5])++;
2267 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2268 (xferP->count[6])++;
2269 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2270 (xferP->count[7])++;
2272 (xferP->count[8])++;
2274 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2275 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2276 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2277 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2278 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2280 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2281 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2286 * Finally, go off to tell our caller the bad news in case the
2291 #endif /* FS_STATS_DETAILED */
2293 /* write back the OutStatus from the target vnode */
2294 GetStatus(targetptr, OutStatus, rights, anyrights,
2295 &tparentwhentargetnotdir);
2297 /* if a r/w volume, promise a callback to the caller */
2298 if (VolumeWriteable(volptr))
2299 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2301 struct AFSFid myFid;
2302 memset(&myFid, 0, sizeof(struct AFSFid));
2303 myFid.Volume = Fid->Volume;
2304 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2308 /* Update and store volume/vnode and parent vnodes back */
2309 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2311 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2312 errorCode = CallPostamble(tcon, errorCode, thost);
2314 #if FS_STATS_DETAILED
2315 FT_GetTimeOfDay(&opStopTime, 0);
2316 if (errorCode == 0) {
2318 (opP->numSuccesses)++;
2319 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2320 fs_stats_AddTo((opP->sumTime), elapsedTime);
2321 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2322 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2323 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2325 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2326 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2330 #endif /* FS_STATS_DETAILED */
2332 osi_auditU(acall, FetchDataEvent, errorCode,
2333 AUD_ID, t_client ? t_client->ViceId : 0,
2334 AUD_FID, Fid, AUD_END);
2337 } /*SRXAFS_FetchData */
2340 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2341 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2342 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2344 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2349 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2350 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2351 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2354 afs_sfsize_t tPos, tLen;
2356 #ifdef AFS_64BIT_ENV
2357 #ifndef AFS_LARGEFILE_ENV
2358 if (Pos + Len > 0x7fffffff)
2360 #endif /* !AFS_LARGEFILE_ENV */
2361 tPos = (afs_sfsize_t) Pos;
2362 tLen = (afs_sfsize_t) Len;
2363 #else /* AFS_64BIT_ENV */
2364 if (Pos.high || Len.high)
2368 #endif /* AFS_64BIT_ENV */
2371 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2377 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2378 struct AFSOpaque * AccessList,
2379 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2381 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2382 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2383 Error errorCode = 0; /* return error code to caller */
2384 Volume *volptr = 0; /* pointer to the volume */
2385 struct client *client = 0; /* pointer to the client data */
2386 afs_int32 rights, anyrights; /* rights for this and any user */
2387 struct rx_connection *tcon = rx_ConnectionOf(acall);
2389 struct client *t_client = NULL; /* tmp ptr to client data */
2390 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2391 #if FS_STATS_DETAILED
2392 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2393 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2394 struct timeval elapsedTime; /* Transfer time */
2397 * Set our stats pointer, remember when the RPC operation started, and
2398 * tally the operation.
2400 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2404 FT_GetTimeOfDay(&opStartTime, 0);
2405 #endif /* FS_STATS_DETAILED */
2408 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2411 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2413 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2416 /* Get ptr to client data for user Id for logging */
2417 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2418 logHostAddr.s_addr = rxr_HostOf(tcon);
2420 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2421 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2422 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2424 AccessList->AFSOpaque_len = 0;
2425 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2426 if (!AccessList->AFSOpaque_val) {
2427 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2432 * Get volume/vnode for the fetched file; caller's access rights to it
2436 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2437 &parentwhentargetnotdir, &client, READ_LOCK,
2438 &rights, &anyrights)))
2441 SetVolumeSync(Sync, volptr);
2443 /* Check whether we have permission to fetch the ACL */
2445 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2448 /* Get the Access List from the dir's vnode */
2450 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2453 /* Get OutStatus back From the target Vnode */
2454 GetStatus(targetptr, OutStatus, rights, anyrights,
2455 parentwhentargetnotdir);
2458 /* Update and store volume/vnode and parent vnodes back */
2459 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2462 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2463 AccessList->AFSOpaque_val));
2464 errorCode = CallPostamble(tcon, errorCode, thost);
2466 #if FS_STATS_DETAILED
2467 FT_GetTimeOfDay(&opStopTime, 0);
2468 if (errorCode == 0) {
2470 (opP->numSuccesses)++;
2471 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2472 fs_stats_AddTo((opP->sumTime), elapsedTime);
2473 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2474 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2475 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2477 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2478 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2482 #endif /* FS_STATS_DETAILED */
2484 osi_auditU(acall, FetchACLEvent, errorCode,
2485 AUD_ID, t_client ? t_client->ViceId : 0,
2487 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2489 } /*SRXAFS_FetchACL */
2493 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2494 * merged into it when possible.
2498 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2499 struct AFSFetchStatus *OutStatus,
2500 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2502 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2503 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2504 Error errorCode = 0; /* return code to caller */
2505 Volume *volptr = 0; /* pointer to the volume */
2506 struct client *client = 0; /* pointer to the client data */
2507 afs_int32 rights, anyrights; /* rights for this and any user */
2508 struct client *t_client = NULL; /* tmp ptr to client data */
2509 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2510 struct rx_connection *tcon = rx_ConnectionOf(acall);
2512 /* Get ptr to client data for user Id for logging */
2513 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2514 logHostAddr.s_addr = rxr_HostOf(tcon);
2516 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2517 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2518 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2520 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2523 * Get volume/vnode for the fetched file; caller's rights to it are
2527 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2528 &parentwhentargetnotdir, &client, READ_LOCK,
2529 &rights, &anyrights)))
2530 goto Bad_FetchStatus;
2532 /* set volume synchronization information */
2533 SetVolumeSync(Sync, volptr);
2535 /* Are we allowed to fetch Fid's status? */
2536 if (targetptr->disk.type != vDirectory) {
2538 Check_PermissionRights(targetptr, client, rights,
2539 CHK_FETCHSTATUS, 0))) {
2540 if (rx_GetCallAbortCode(acall) == errorCode)
2541 rx_SetCallAbortCode(acall, 0);
2542 goto Bad_FetchStatus;
2546 /* set OutStatus From the Fid */
2547 GetStatus(targetptr, OutStatus, rights, anyrights,
2548 parentwhentargetnotdir);
2550 /* If a r/w volume, also set the CallBack state */
2551 if (VolumeWriteable(volptr))
2552 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2554 struct AFSFid myFid;
2555 memset(&myFid, 0, sizeof(struct AFSFid));
2556 myFid.Volume = Fid->Volume;
2557 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2561 /* Update and store volume/vnode and parent vnodes back */
2562 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2564 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2567 } /*SAFSS_FetchStatus */
2571 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2572 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2573 struct AFSVolSync * Sync)
2577 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2578 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2579 Error errorCode = 0; /* return code to caller */
2580 Volume *volptr = 0; /* pointer to the volume */
2581 struct client *client = 0; /* pointer to the client data */
2582 afs_int32 rights, anyrights; /* rights for this and any user */
2583 register struct AFSFid *tfid; /* file id we're dealing with now */
2584 struct rx_connection *tcon = rx_ConnectionOf(acall);
2586 struct client *t_client = NULL; /* tmp pointer to the client data */
2587 #if FS_STATS_DETAILED
2588 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2589 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2590 struct timeval elapsedTime; /* Transfer time */
2593 * Set our stats pointer, remember when the RPC operation started, and
2594 * tally the operation.
2596 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2600 FT_GetTimeOfDay(&opStartTime, 0);
2601 #endif /* FS_STATS_DETAILED */
2603 ViceLog(1, ("SAFS_BulkStatus\n"));
2605 AFSCallStats.TotalCalls++;
2607 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2608 if (nfiles <= 0) { /* Sanity check */
2610 goto Audit_and_Return;
2613 /* allocate space for return output parameters */
2614 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2615 malloc(nfiles * sizeof(struct AFSFetchStatus));
2616 if (!OutStats->AFSBulkStats_val) {
2617 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2620 OutStats->AFSBulkStats_len = nfiles;
2621 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2622 malloc(nfiles * sizeof(struct AFSCallBack));
2623 if (!CallBacks->AFSCBs_val) {
2624 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2627 CallBacks->AFSCBs_len = nfiles;
2629 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2630 goto Bad_BulkStatus;
2632 tfid = Fids->AFSCBFids_val;
2633 for (i = 0; i < nfiles; i++, tfid++) {
2635 * Get volume/vnode for the fetched file; caller's rights to it
2639 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2640 &parentwhentargetnotdir, &client, READ_LOCK,
2641 &rights, &anyrights)))
2642 goto Bad_BulkStatus;
2643 /* set volume synchronization information, but only once per call */
2645 SetVolumeSync(Sync, volptr);
2647 /* Are we allowed to fetch Fid's status? */
2648 if (targetptr->disk.type != vDirectory) {
2650 Check_PermissionRights(targetptr, client, rights,
2651 CHK_FETCHSTATUS, 0))) {
2652 if (rx_GetCallAbortCode(acall) == errorCode)
2653 rx_SetCallAbortCode(acall, 0);
2654 goto Bad_BulkStatus;
2658 /* set OutStatus From the Fid */
2659 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2660 anyrights, parentwhentargetnotdir);
2662 /* If a r/w volume, also set the CallBack state */
2663 if (VolumeWriteable(volptr))
2664 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2665 &CallBacks->AFSCBs_val[i]);
2667 struct AFSFid myFid;
2668 memset(&myFid, 0, sizeof(struct AFSFid));
2669 myFid.Volume = tfid->Volume;
2670 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2671 &CallBacks->AFSCBs_val[i]);
2674 /* put back the file ID and volume */
2675 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2677 parentwhentargetnotdir = (Vnode *) 0;
2678 targetptr = (Vnode *) 0;
2679 volptr = (Volume *) 0;
2680 client = (struct client *)0;
2684 /* Update and store volume/vnode and parent vnodes back */
2685 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2687 errorCode = CallPostamble(tcon, errorCode, thost);
2689 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2691 #if FS_STATS_DETAILED
2692 FT_GetTimeOfDay(&opStopTime, 0);
2693 if (errorCode == 0) {
2695 (opP->numSuccesses)++;
2696 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2697 fs_stats_AddTo((opP->sumTime), elapsedTime);
2698 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2699 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2700 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2702 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2703 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2707 #endif /* FS_STATS_DETAILED */
2710 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2711 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2712 AUD_ID, t_client ? t_client->ViceId : 0,
2713 AUD_FIDS, Fids, AUD_END);
2716 } /*SRXAFS_BulkStatus */
2720 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2721 struct AFSBulkStats * OutStats,
2722 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2726 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2727 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2728 Error errorCode = 0; /* return code to caller */
2729 Volume *volptr = 0; /* pointer to the volume */
2730 struct client *client = 0; /* pointer to the client data */
2731 afs_int32 rights, anyrights; /* rights for this and any user */
2732 register struct AFSFid *tfid; /* file id we're dealing with now */
2733 struct rx_connection *tcon;
2735 struct client *t_client = NULL; /* tmp ptr to client data */
2736 AFSFetchStatus *tstatus;
2737 #if FS_STATS_DETAILED
2738 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2739 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2740 struct timeval elapsedTime; /* Transfer time */
2743 * Set our stats pointer, remember when the RPC operation started, and
2744 * tally the operation.
2746 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2750 FT_GetTimeOfDay(&opStartTime, 0);
2751 #endif /* FS_STATS_DETAILED */
2753 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2755 AFSCallStats.TotalCalls++;
2757 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2758 if (nfiles <= 0) { /* Sanity check */
2760 goto Audit_and_Return;
2763 /* allocate space for return output parameters */
2764 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2765 malloc(nfiles * sizeof(struct AFSFetchStatus));
2766 if (!OutStats->AFSBulkStats_val) {
2767 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2770 OutStats->AFSBulkStats_len = nfiles;
2771 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2772 malloc(nfiles * sizeof(struct AFSCallBack));
2773 if (!CallBacks->AFSCBs_val) {
2774 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2777 CallBacks->AFSCBs_len = nfiles;
2779 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2780 goto Bad_InlineBulkStatus;
2783 tfid = Fids->AFSCBFids_val;
2784 for (i = 0; i < nfiles; i++, tfid++) {
2786 * Get volume/vnode for the fetched file; caller's rights to it
2790 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2791 &parentwhentargetnotdir, &client, READ_LOCK,
2792 &rights, &anyrights))) {
2793 tstatus = &OutStats->AFSBulkStats_val[i];
2794 tstatus->errorCode = errorCode;
2795 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2797 parentwhentargetnotdir = (Vnode *) 0;
2798 targetptr = (Vnode *) 0;
2799 volptr = (Volume *) 0;
2800 client = (struct client *)0;
2804 /* set volume synchronization information, but only once per call */
2806 SetVolumeSync(Sync, volptr);
2808 /* Are we allowed to fetch Fid's status? */
2809 if (targetptr->disk.type != vDirectory) {
2811 Check_PermissionRights(targetptr, client, rights,
2812 CHK_FETCHSTATUS, 0))) {
2813 tstatus = &OutStats->AFSBulkStats_val[i];
2814 tstatus->errorCode = errorCode;
2815 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2816 (Vnode *) 0, volptr, &client);
2817 parentwhentargetnotdir = (Vnode *) 0;
2818 targetptr = (Vnode *) 0;
2819 volptr = (Volume *) 0;
2820 client = (struct client *)0;
2825 /* set OutStatus From the Fid */
2826 GetStatus(targetptr,
2827 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2828 rights, anyrights, parentwhentargetnotdir);
2830 /* If a r/w volume, also set the CallBack state */
2831 if (VolumeWriteable(volptr))
2832 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2833 &CallBacks->AFSCBs_val[i]);
2835 struct AFSFid myFid;
2836 memset(&myFid, 0, sizeof(struct AFSFid));
2837 myFid.Volume = tfid->Volume;
2838 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2839 &CallBacks->AFSCBs_val[i]);
2842 /* put back the file ID and volume */
2843 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2845 parentwhentargetnotdir = (Vnode *) 0;
2846 targetptr = (Vnode *) 0;
2847 volptr = (Volume *) 0;
2848 client = (struct client *)0;
2851 Bad_InlineBulkStatus:
2852 /* Update and store volume/vnode and parent vnodes back */
2853 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2855 errorCode = CallPostamble(tcon, errorCode, thost);
2857 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2859 #if FS_STATS_DETAILED
2860 FT_GetTimeOfDay(&opStopTime, 0);
2861 if (errorCode == 0) {
2863 (opP->numSuccesses)++;
2864 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2865 fs_stats_AddTo((opP->sumTime), elapsedTime);
2866 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2867 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2868 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2870 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2871 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2875 #endif /* FS_STATS_DETAILED */
2878 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2879 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2880 AUD_ID, t_client ? t_client->ViceId : 0,
2881 AUD_FIDS, Fids, AUD_END);
2884 } /*SRXAFS_InlineBulkStatus */
2888 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2889 struct AFSFetchStatus * OutStatus,
2890 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2893 struct rx_connection *tcon;
2895 struct client *t_client = NULL; /* tmp ptr to client data */
2896 #if FS_STATS_DETAILED
2897 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2898 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2899 struct timeval elapsedTime; /* Transfer time */
2902 * Set our stats pointer, remember when the RPC operation started, and
2903 * tally the operation.
2905 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2909 FT_GetTimeOfDay(&opStartTime, 0);
2910 #endif /* FS_STATS_DETAILED */
2912 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2913 goto Bad_FetchStatus;
2915 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2918 code = CallPostamble(tcon, code, thost);
2920 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2922 #if FS_STATS_DETAILED
2923 FT_GetTimeOfDay(&opStopTime, 0);
2926 (opP->numSuccesses)++;
2927 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2928 fs_stats_AddTo((opP->sumTime), elapsedTime);
2929 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2930 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2931 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2933 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2934 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2938 #endif /* FS_STATS_DETAILED */
2940 osi_auditU(acall, FetchStatusEvent, code,
2941 AUD_ID, t_client ? t_client->ViceId : 0,
2942 AUD_FID, Fid, AUD_END);
2945 } /*SRXAFS_FetchStatus */
2949 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2950 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2951 afs_fsize_t Length, afs_fsize_t FileLength,
2952 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2954 Vnode *targetptr = 0; /* pointer to input fid */
2955 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2956 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2957 Error errorCode = 0; /* return code for caller */
2958 Error fileCode = 0; /* return code from vol package */
2959 Volume *volptr = 0; /* pointer to the volume header */
2960 struct client *client = 0; /* pointer to client structure */
2961 afs_int32 rights, anyrights; /* rights for this and any user */
2962 struct client *t_client = NULL; /* tmp ptr to client data */
2963 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2964 struct rx_connection *tcon;
2966 #if FS_STATS_DETAILED
2967 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2968 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2969 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2970 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2971 struct timeval elapsedTime; /* Transfer time */
2972 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2973 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2974 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2977 * Set our stats pointers, remember when the RPC operation started, and
2978 * tally the operation.
2980 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2981 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2986 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2988 FT_GetTimeOfDay(&opStartTime, 0);
2989 #endif /* FS_STATS_DETAILED */
2992 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2994 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2997 /* Get ptr to client data for user Id for logging */
2998 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2999 logHostAddr.s_addr = rxr_HostOf(tcon);
3001 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3002 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3003 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3006 * Get associated volume/vnode for the stored file; caller's rights
3010 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3011 &parentwhentargetnotdir, &client, WRITE_LOCK,
3012 &rights, &anyrights))) {
3016 /* set volume synchronization information */
3017 SetVolumeSync(Sync, volptr);
3019 if ((targetptr->disk.type == vSymlink)) {
3020 /* Should we return a better error code here??? */
3025 /* Check if we're allowed to store the data */
3027 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3033 * Drop the read lock on the parent directory after saving the parent
3034 * vnode information we need to pass to GetStatus
3036 if (parentwhentargetnotdir != NULL) {
3037 tparentwhentargetnotdir = *parentwhentargetnotdir;
3038 VPutVnode(&fileCode, parentwhentargetnotdir);
3039 assert(!fileCode || (fileCode == VSALVAGE));
3040 parentwhentargetnotdir = NULL;
3042 #if FS_STATS_DETAILED
3044 * Remember when the data transfer started.
3046 FT_GetTimeOfDay(&xferStartTime, 0);
3047 #endif /* FS_STATS_DETAILED */
3049 /* Do the actual storing of the data */
3050 #if FS_STATS_DETAILED
3052 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3053 FileLength, (InStatus->Mask & AFS_FSYNC),
3054 &bytesToXfer, &bytesXferred);
3057 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3058 FileLength, (InStatus->Mask & AFS_FSYNC));
3059 if (errorCode && (!targetptr->changed_newTime))
3061 #endif /* FS_STATS_DETAILED */
3062 #if FS_STATS_DETAILED
3064 * At this point, the data transfer is done, for good or ill. Remember
3065 * when the transfer ended, bump the number of successes/failures, and
3066 * integrate the transfer size and elapsed time into the stats. If the
3067 * operation failed, we jump to the appropriate point.
3069 FT_GetTimeOfDay(&xferStopTime, 0);
3071 (xferP->numXfers)++;
3073 (xferP->numSuccesses)++;
3076 * Bump the xfer sum by the number of bytes actually sent, NOT the
3079 tot_bytesXferred += bytesXferred;
3080 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3081 tot_bytesXferred &= 0x3FF;
3082 if (bytesXferred < xferP->minBytes)
3083 xferP->minBytes = bytesXferred;
3084 if (bytesXferred > xferP->maxBytes)
3085 xferP->maxBytes = bytesXferred;
3088 * Tally the size of the object. Note: we tally the actual size,
3089 * NOT the number of bytes that made it out over the wire.
3091 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3092 (xferP->count[0])++;
3093 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3094 (xferP->count[1])++;
3095 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3096 (xferP->count[2])++;
3097 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3098 (xferP->count[3])++;
3099 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3100 (xferP->count[4])++;
3101 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3102 (xferP->count[5])++;
3103 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3104 (xferP->count[6])++;
3105 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3106 (xferP->count[7])++;
3108 (xferP->count[8])++;
3110 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3111 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3112 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3113 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3114 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3116 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3117 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3122 * Finally, go off to tell our caller the bad news in case the
3125 if (errorCode && (!targetptr->changed_newTime))
3127 #endif /* FS_STATS_DETAILED */
3129 /* Update the status of the target's vnode */
3130 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3131 targetptr, volptr, 0);
3133 /* Get the updated File's status back to the caller */
3134 GetStatus(targetptr, OutStatus, rights, anyrights,
3135 &tparentwhentargetnotdir);
3138 /* Update and store volume/vnode and parent vnodes back */
3139 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3141 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3143 errorCode = CallPostamble(tcon, errorCode, thost);
3145 #if FS_STATS_DETAILED
3146 FT_GetTimeOfDay(&opStopTime, 0);
3147 if (errorCode == 0) {
3149 (opP->numSuccesses)++;
3150 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3151 fs_stats_AddTo((opP->sumTime), elapsedTime);
3152 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3153 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3154 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3156 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3157 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3161 #endif /* FS_STATS_DETAILED */
3162 osi_auditU(acall, StoreDataEvent, errorCode,
3163 AUD_ID, t_client ? t_client->ViceId : 0,
3164 AUD_FID, Fid, AUD_END);
3166 } /*common_StoreData64 */
3169 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3170 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3171 afs_uint32 Length, afs_uint32 FileLength,
3172 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3174 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3175 (0x7fffffff - Pos) < Length)
3178 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3180 } /*SRXAFS_StoreData */
3183 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3184 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3185 afs_uint64 Length, afs_uint64 FileLength,
3186 struct AFSFetchStatus * OutStatus,
3187 struct AFSVolSync * Sync)
3191 afs_fsize_t tLength;
3192 afs_fsize_t tFileLength;
3194 #ifdef AFS_64BIT_ENV
3195 #ifndef AFS_LARGEFILE_ENV
3196 if (FileLength > 0x7fffffff)
3198 #endif /* !AFS_LARGEFILE_ENV */
3199 tPos = (afs_fsize_t) Pos;
3200 tLength = (afs_fsize_t) Length;
3201 tFileLength = (afs_fsize_t) FileLength;
3202 #else /* AFS_64BIT_ENV */
3203 if (FileLength.high)
3206 tLength = Length.low;
3207 tFileLength = FileLength.low;
3208 #endif /* AFS_64BIT_ENV */
3211 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3217 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3218 struct AFSOpaque * AccessList,
3219 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3221 Vnode *targetptr = 0; /* pointer to input fid */
3222 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3223 Error errorCode = 0; /* return code for caller */
3224 struct AFSStoreStatus InStatus; /* Input status for fid */
3225 Volume *volptr = 0; /* pointer to the volume header */
3226 struct client *client = 0; /* pointer to client structure */
3227 afs_int32 rights, anyrights; /* rights for this and any user */
3228 struct rx_connection *tcon;
3230 struct client *t_client = NULL; /* tmp ptr to client data */
3231 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3232 #if FS_STATS_DETAILED
3233 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3234 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3235 struct timeval elapsedTime; /* Transfer time */
3238 * Set our stats pointer, remember when the RPC operation started, and
3239 * tally the operation.
3241 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3245 FT_GetTimeOfDay(&opStartTime, 0);
3246 #endif /* FS_STATS_DETAILED */
3247 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3250 /* Get ptr to client data for user Id for logging */
3251 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3252 logHostAddr.s_addr = rxr_HostOf(tcon);
3254 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3255 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3256 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3258 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3260 InStatus.Mask = 0; /* not storing any status */
3263 * Get associated volume/vnode for the target dir; caller's rights
3264 * are also returned.
3267 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3268 &parentwhentargetnotdir, &client, WRITE_LOCK,
3269 &rights, &anyrights))) {
3273 /* set volume synchronization information */
3274 SetVolumeSync(Sync, volptr);
3276 /* Check if we have permission to change the dir's ACL */
3278 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3283 /* Build and store the new Access List for the dir */
3284 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3288 targetptr->changed_newTime = 1; /* status change of directory */
3290 /* convert the write lock to a read lock before breaking callbacks */
3291 VVnodeWriteToRead(&errorCode, targetptr);
3292 assert(!errorCode || errorCode == VSALVAGE);
3294 /* break call backs on the directory */
3295 BreakCallBack(client->host, Fid, 0);
3297 /* Get the updated dir's status back to the caller */
3298 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3301 /* Update and store volume/vnode and parent vnodes back */
3302 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3304 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3305 errorCode = CallPostamble(tcon, errorCode, thost);
3307 #if FS_STATS_DETAILED
3308 FT_GetTimeOfDay(&opStopTime, 0);
3309 if (errorCode == 0) {
3311 (opP->numSuccesses)++;
3312 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3313 fs_stats_AddTo((opP->sumTime), elapsedTime);
3314 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3315 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3316 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3318 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3319 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3323 #endif /* FS_STATS_DETAILED */
3325 osi_auditU(acall, StoreACLEvent, errorCode,
3326 AUD_ID, t_client ? t_client->ViceId : 0,
3327 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3330 } /*SRXAFS_StoreACL */
3334 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3335 * should be merged when possible.
3338 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3339 struct AFSStoreStatus *InStatus,
3340 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3342 Vnode *targetptr = 0; /* pointer to input fid */
3343 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3344 Error errorCode = 0; /* return code for caller */
3345 Volume *volptr = 0; /* pointer to the volume header */
3346 struct client *client = 0; /* pointer to client structure */
3347 afs_int32 rights, anyrights; /* rights for this and any user */
3348 struct client *t_client = NULL; /* tmp ptr to client data */
3349 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3350 struct rx_connection *tcon = rx_ConnectionOf(acall);
3352 /* Get ptr to client data for user Id for logging */
3353 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3354 logHostAddr.s_addr = rxr_HostOf(tcon);
3356 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3357 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3358 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3360 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3363 * Get volume/vnode for the target file; caller's rights to it are
3367 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3368 &parentwhentargetnotdir, &client, WRITE_LOCK,
3369 &rights, &anyrights))) {
3370 goto Bad_StoreStatus;
3373 /* set volume synchronization information */
3374 SetVolumeSync(Sync, volptr);
3376 /* Check if the caller has proper permissions to store status to Fid */
3378 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3380 goto Bad_StoreStatus;
3383 * Check for a symbolic link; we can't chmod these (otherwise could
3384 * change a symlink to a mt pt or vice versa)
3386 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3388 goto Bad_StoreStatus;
3391 /* Update the status of the target's vnode */
3392 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3393 (parentwhentargetnotdir ? parentwhentargetnotdir
3394 : targetptr), volptr, 0);
3396 /* convert the write lock to a read lock before breaking callbacks */
3397 VVnodeWriteToRead(&errorCode, targetptr);
3398 assert(!errorCode || errorCode == VSALVAGE);
3400 /* Break call backs on Fid */
3401 BreakCallBack(client->host, Fid, 0);
3403 /* Return the updated status back to caller */
3404 GetStatus(targetptr, OutStatus, rights, anyrights,
3405 parentwhentargetnotdir);
3408 /* Update and store volume/vnode and parent vnodes back */
3409 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3411 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3414 } /*SAFSS_StoreStatus */
3418 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3419 struct AFSStoreStatus * InStatus,
3420 struct AFSFetchStatus * OutStatus,
3421 struct AFSVolSync * Sync)
3424 struct rx_connection *tcon;
3426 struct client *t_client = NULL; /* tmp ptr to client data */
3427 #if FS_STATS_DETAILED
3428 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3429 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3430 struct timeval elapsedTime; /* Transfer time */
3433 * Set our stats pointer, remember when the RPC operation started, and
3434 * tally the operation.
3436 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3440 FT_GetTimeOfDay(&opStartTime, 0);
3441 #endif /* FS_STATS_DETAILED */
3443 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3444 goto Bad_StoreStatus;
3446 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3449 code = CallPostamble(tcon, code, thost);
3451 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3453 #if FS_STATS_DETAILED
3454 FT_GetTimeOfDay(&opStopTime, 0);
3457 (opP->numSuccesses)++;
3458 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3459 fs_stats_AddTo((opP->sumTime), elapsedTime);
3460 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3461 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3462 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3464 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3465 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3469 #endif /* FS_STATS_DETAILED */
3471 osi_auditU(acall, StoreStatusEvent, code,
3472 AUD_ID, t_client ? t_client->ViceId : 0,
3473 AUD_FID, Fid, AUD_END);
3476 } /*SRXAFS_StoreStatus */
3480 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3481 * merged in when possible.
3484 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3485 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3487 Vnode *parentptr = 0; /* vnode of input Directory */
3488 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3489 Vnode *targetptr = 0; /* file to be deleted */
3490 Volume *volptr = 0; /* pointer to the volume header */
3491 AFSFid fileFid; /* area for Fid from the directory */
3492 Error errorCode = 0; /* error code */
3493 DirHandle dir; /* Handle for dir package I/O */
3494 struct client *client = 0; /* pointer to client structure */
3495 afs_int32 rights, anyrights; /* rights for this and any user */
3496 struct client *t_client; /* tmp ptr to client data */
3497 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3498 struct rx_connection *tcon = rx_ConnectionOf(acall);
3501 /* Get ptr to client data for user Id for logging */
3502 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3503 logHostAddr.s_addr = rxr_HostOf(tcon);
3505 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3506 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3507 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3509 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3512 * Get volume/vnode for the parent dir; caller's access rights are
3516 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3517 &parentwhentargetnotdir, &client, WRITE_LOCK,
3518 &rights, &anyrights))) {
3519 goto Bad_RemoveFile;
3521 /* set volume synchronization information */
3522 SetVolumeSync(Sync, volptr);
3524 /* Does the caller has delete (& write) access to the parent directory? */
3525 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3526 goto Bad_RemoveFile;
3529 /* Actually delete the desired file */
3531 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3533 goto Bad_RemoveFile;
3536 /* Update the vnode status of the parent dir */
3537 #if FS_STATS_DETAILED
3538 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3539 parentptr->disk.linkCount,
3540 client->InSameNetwork);
3542 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3543 parentptr->disk.linkCount);
3544 #endif /* FS_STATS_DETAILED */
3546 /* Return the updated parent dir's status back to caller */
3547 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3549 /* Handle internal callback state for the parent and the deleted file */
3550 if (targetptr->disk.linkCount == 0) {
3551 /* no references left, discard entry */
3552 DeleteFileCallBacks(&fileFid);
3553 /* convert the parent lock to a read lock before breaking callbacks */
3554 VVnodeWriteToRead(&errorCode, parentptr);
3555 assert(!errorCode || errorCode == VSALVAGE);
3557 /* convert the parent lock to a read lock before breaking callbacks */
3558 VVnodeWriteToRead(&errorCode, parentptr);
3559 assert(!errorCode || errorCode == VSALVAGE);
3560 /* convert the target lock to a read lock before breaking callbacks */
3561 VVnodeWriteToRead(&errorCode, targetptr);
3562 assert(!errorCode || errorCode == VSALVAGE);
3563 /* tell all the file has changed */
3564 BreakCallBack(client->host, &fileFid, 1);
3567 /* break call back on the directory */
3568 BreakCallBack(client->host, DirFid, 0);
3571 /* Update and store volume/vnode and parent vnodes back */
3572 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3575 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3578 } /*SAFSS_RemoveFile */
3582 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3583 struct AFSFetchStatus * OutDirStatus,
3584 struct AFSVolSync * Sync)
3587 struct rx_connection *tcon;
3589 struct client *t_client = NULL; /* tmp ptr to client data */
3590 #if FS_STATS_DETAILED
3591 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3592 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3593 struct timeval elapsedTime; /* Transfer time */
3596 * Set our stats pointer, remember when the RPC operation started, and
3597 * tally the operation.
3599 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3603 FT_GetTimeOfDay(&opStartTime, 0);
3604 #endif /* FS_STATS_DETAILED */
3606 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3607 goto Bad_RemoveFile;
3609 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3612 code = CallPostamble(tcon, code, thost);
3614 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3616 #if FS_STATS_DETAILED
3617 FT_GetTimeOfDay(&opStopTime, 0);
3620 (opP->numSuccesses)++;
3621 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3622 fs_stats_AddTo((opP->sumTime), elapsedTime);
3623 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3624 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3625 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3627 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3628 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3632 #endif /* FS_STATS_DETAILED */
3634 osi_auditU(acall, RemoveFileEvent, code,
3635 AUD_ID, t_client ? t_client->ViceId : 0,
3636 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3639 } /*SRXAFS_RemoveFile */
3643 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3644 * be merged in when possible.
3647 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3648 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3649 struct AFSFetchStatus *OutFidStatus,
3650 struct AFSFetchStatus *OutDirStatus,
3651 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3653 Vnode *parentptr = 0; /* vnode of input Directory */
3654 Vnode *targetptr = 0; /* vnode of the new file */
3655 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3656 Volume *volptr = 0; /* pointer to the volume header */
3657 Error errorCode = 0; /* error code */
3658 DirHandle dir; /* Handle for dir package I/O */
3659 struct client *client = 0; /* pointer to client structure */
3660 afs_int32 rights, anyrights; /* rights for this and any user */
3661 struct client *t_client; /* tmp ptr to client data */
3662 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3663 struct rx_connection *tcon = rx_ConnectionOf(acall);
3667 /* Get ptr to client data for user Id for logging */
3668 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3669 logHostAddr.s_addr = rxr_HostOf(tcon);
3671 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3672 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3673 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3675 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3677 if (!FileNameOK(Name)) {
3679 goto Bad_CreateFile;
3683 * Get associated volume/vnode for the parent dir; caller long are
3687 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3688 &parentwhentargetnotdir, &client, WRITE_LOCK,
3689 &rights, &anyrights))) {
3690 goto Bad_CreateFile;
3693 /* set volume synchronization information */
3694 SetVolumeSync(Sync, volptr);
3696 /* Can we write (and insert) onto the parent directory? */
3697 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3698 goto Bad_CreateFile;
3700 /* get a new vnode for the file to be created and set it up */
3702 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3703 vFile, nBlocks(0)))) {
3704 goto Bad_CreateFile;
3707 /* update the status of the parent vnode */
3708 #if FS_STATS_DETAILED
3709 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3710 parentptr->disk.linkCount,
3711 client->InSameNetwork);
3713 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3714 parentptr->disk.linkCount);
3715 #endif /* FS_STATS_DETAILED */
3717 /* update the status of the new file's vnode */
3718 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3719 parentptr, volptr, 0);
3721 /* set up the return status for the parent dir and the newly created file, and since the newly created file is owned by the creator, give it PRSFS_ADMINISTER to tell the client its the owner of the file */
3722 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3723 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3725 /* convert the write lock to a read lock before breaking callbacks */
3726 VVnodeWriteToRead(&errorCode, parentptr);
3727 assert(!errorCode || errorCode == VSALVAGE);
3729 /* break call back on parent dir */
3730 BreakCallBack(client->host, DirFid, 0);
3732 /* Return a callback promise for the newly created file to the caller */
3733 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3736 /* Update and store volume/vnode and parent vnodes back */
3737 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3740 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3743 } /*SAFSS_CreateFile */
3747 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3748 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3749 struct AFSFetchStatus * OutFidStatus,
3750 struct AFSFetchStatus * OutDirStatus,
3751 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3754 struct rx_connection *tcon;
3756 struct client *t_client = NULL; /* tmp ptr to client data */
3757 #if FS_STATS_DETAILED
3758 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3759 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3760 struct timeval elapsedTime; /* Transfer time */
3763 * Set our stats pointer, remember when the RPC operation started, and
3764 * tally the operation.
3766 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3770 FT_GetTimeOfDay(&opStartTime, 0);
3771 #endif /* FS_STATS_DETAILED */
3773 memset(OutFid, 0, sizeof(struct AFSFid));
3775 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3776 goto Bad_CreateFile;
3779 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3780 OutDirStatus, CallBack, Sync);
3783 code = CallPostamble(tcon, code, thost);
3785 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3787 #if FS_STATS_DETAILED
3788 FT_GetTimeOfDay(&opStopTime, 0);
3791 (opP->numSuccesses)++;
3792 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3793 fs_stats_AddTo((opP->sumTime), elapsedTime);
3794 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3795 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3796 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3798 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3799 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3803 #endif /* FS_STATS_DETAILED */
3805 osi_auditU(acall, CreateFileEvent, code,
3806 AUD_ID, t_client ? t_client->ViceId : 0,
3807 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3810 } /*SRXAFS_CreateFile */
3814 * This routine is called exclusively from SRXAFS_Rename(), and should be
3815 * merged in when possible.
3818 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3819 struct AFSFid *NewDirFid, char *NewName,
3820 struct AFSFetchStatus *OutOldDirStatus,
3821 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3823 Vnode *oldvptr = 0; /* vnode of the old Directory */
3824 Vnode *newvptr = 0; /* vnode of the new Directory */
3825 Vnode *fileptr = 0; /* vnode of the file to move */
3826 Vnode *newfileptr = 0; /* vnode of the file to delete */
3827 Vnode *testvptr = 0; /* used in directory tree walk */
3828 Vnode *parent = 0; /* parent for use in SetAccessList */
3829 Error errorCode = 0; /* error code */
3830 Error fileCode = 0; /* used when writing Vnodes */
3831 VnodeId testnode; /* used in directory tree walk */
3832 AFSFid fileFid; /* Fid of file to move */
3833 AFSFid newFileFid; /* Fid of new file */
3834 DirHandle olddir; /* Handle for dir package I/O */
3835 DirHandle newdir; /* Handle for dir package I/O */
3836 DirHandle filedir; /* Handle for dir package I/O */
3837 DirHandle newfiledir; /* Handle for dir package I/O */
3838 Volume *volptr = 0; /* pointer to the volume header */
3839 struct client *client = 0; /* pointer to client structure */
3840 afs_int32 rights, anyrights; /* rights for this and any user */
3841 afs_int32 newrights; /* rights for this user */
3842 afs_int32 newanyrights; /* rights for any user */
3843 int doDelete; /* deleted the rename target (ref count now 0) */
3845 struct client *t_client; /* tmp ptr to client data */
3846 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3847 struct rx_connection *tcon = rx_ConnectionOf(acall);
3852 FidZero(&newfiledir);
3854 /* Get ptr to client data for user Id for logging */
3855 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3856 logHostAddr.s_addr = rxr_HostOf(tcon);
3858 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3859 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3860 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3861 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3863 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3865 if (!FileNameOK(NewName)) {
3869 if (OldDirFid->Volume != NewDirFid->Volume) {
3874 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3875 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3876 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3882 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3884 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3885 &parent, &client, WRITE_LOCK, &rights,
3890 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3892 newrights = rights, newanyrights = anyrights;
3895 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3896 MustBeDIR, &parent, &client, WRITE_LOCK,
3897 &newrights, &newanyrights))) {
3903 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3904 &parent, &client, WRITE_LOCK, &newrights,
3910 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3911 &parent, &client, WRITE_LOCK, &rights,
3918 /* set volume synchronization information */
3919 SetVolumeSync(Sync, volptr);
3921 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3924 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3928 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3929 * call to CopyOnWrite returns error, it is not necessary to revert back
3930 * the effects of the first call because the contents of the volume is
3931 * not modified, it is only replicated.
3933 if (oldvptr->disk.cloned) {
3934 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3935 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3938 SetDirHandle(&olddir, oldvptr);
3939 if (newvptr->disk.cloned) {
3940 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3941 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3945 SetDirHandle(&newdir, newvptr);
3947 /* Lookup the file to delete its vnode */
3948 if (Lookup(&olddir, OldName, &fileFid)) {
3952 if (fileFid.Vnode == oldvptr->vnodeNumber
3953 || fileFid.Vnode == newvptr->vnodeNumber) {
3954 errorCode = FSERR_ELOOP;
3957 fileFid.Volume = V_id(volptr);
3958 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3959 if (errorCode != 0) {
3961 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3962 OldName, errorCode));
3963 VTakeOffline(volptr);
3966 if (fileptr->disk.uniquifier != fileFid.Unique) {
3968 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3970 VTakeOffline(volptr);
3975 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3976 && fileptr->disk.linkCount != 1) {
3978 * Hard links exist to this file - cannot move one of the links to
3979 * a new directory because of AFS restrictions (this is the same
3980 * reason that links cannot be made across directories, i.e.
3987 /* Lookup the new file */
3988 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3989 if (readonlyServer) {
3990 errorCode = VREADONLY;
3993 if (!(newrights & PRSFS_DELETE)) {
3997 if (newFileFid.Vnode == oldvptr->vnodeNumber
3998 || newFileFid.Vnode == newvptr->vnodeNumber
3999 || newFileFid.Vnode == fileFid.Vnode) {
4003 newFileFid.Volume = V_id(volptr);
4005 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4006 if (errorCode != 0) {
4008 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4009 NewName, errorCode));
4010 VTakeOffline(volptr);
4013 if (fileptr->disk.uniquifier != fileFid.Unique) {
4015 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4017 VTakeOffline(volptr);
4021 SetDirHandle(&newfiledir, newfileptr);
4022 /* Now check that we're moving directories over directories properly, etc.
4023 * return proper POSIX error codes:
4024 * if fileptr is a file and new is a dir: EISDIR.
4025 * if fileptr is a dir and new is a file: ENOTDIR.
4026 * Also, dir to be removed must be empty, of course.
4028 if (newfileptr->disk.type == vDirectory) {
4029 if (fileptr->disk.type != vDirectory) {
4033 if ((IsEmpty(&newfiledir))) {
4038 if (fileptr->disk.type == vDirectory) {
4039 errorCode = ENOTDIR;
4046 * ok - now we check that the old name is not above new name in the
4047 * directory structure. This is to prevent removing a subtree alltogether
4049 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4050 afs_int32 forpass = 0, vnum = 0, top = 0;
4051 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4052 if (testnode > vnum) vnum = testnode;
4053 if (forpass > vnum) {
4054 errorCode = FSERR_ELOOP;