2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
37 #undef SHARED /* XXX */
42 #include <sys/param.h>
44 #include <netinet/in.h>
46 #include <sys/ioctl.h>
47 #include <sys/socket.h>
57 #ifndef AFS_LINUX20_ENV
59 #include <netinet/if_ether.h>
63 /* included early because of name conflict on IOPEN */
64 #include <sys/inode.h>
68 #endif /* AFS_HPUX_ENV */
72 #include <afs/assert.h>
75 #include <afs/afsint.h>
76 #include <afs/vldbint.h>
77 #include <afs/errors.h>
78 #include <afs/ihandle.h>
79 #include <afs/vnode.h>
80 #include <afs/volume.h>
82 #include <afs/ptclient.h>
83 #include <afs/prs_fs.h>
85 #include <rx/rx_globals.h>
87 #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)
90 #if !defined(AFS_NT40_ENV)
93 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
95 #include <sys/statfs.h>
96 #include <sys/lockf.h>
98 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
103 #include <afs/cellconfig.h>
104 #include <afs/keys.h>
106 #include <afs/auth.h>
108 #include <afs/partition.h>
109 #include "viced_prototypes.h"
112 #include <afs/audit.h>
113 #include <afs/afsutil.h>
115 #ifdef AFS_PTHREAD_ENV
116 pthread_mutex_t fileproc_glock_mutex;
117 #endif /* AFS_PTHREAD_ENV */
120 /* Useful local defines used by this module */
123 #define MustNOTBeDIR 1
127 #define TVS_SSTATUS 2
130 #define TVS_MKDIR 0x10
132 #define CHK_FETCH 0x10
133 #define CHK_FETCHDATA 0x10
134 #define CHK_FETCHACL 0x11
135 #define CHK_FETCHSTATUS 0x12
136 #define CHK_STOREDATA 0x00
137 #define CHK_STOREACL 0x01
138 #define CHK_STORESTATUS 0x02
140 #define OWNERREAD 0400
141 #define OWNERWRITE 0200
142 #define OWNEREXEC 0100
143 #ifdef USE_GROUP_PERMS
144 #define GROUPREAD 0040
145 #define GROUPWRITE 0020
146 #define GROUPREXEC 0010
149 /* The following errors were not defined in NT. They are given unique
150 * names here to avoid any potential collision.
152 #define FSERR_ELOOP 90
153 #define FSERR_EOPNOTSUPP 122
154 #define FSERR_ECONNREFUSED 130
156 #define NOTACTIVECALL 0
159 #define CREATE_SGUID_ADMIN_ONLY 1
161 extern struct afsconf_dir *confDir;
162 extern afs_int32 dataVersionHigh;
165 static struct AFSCallStatistics AFSCallStats;
166 #if FS_STATS_DETAILED
167 struct fs_stats_FullPerfStats afs_FullPerfStats;
168 extern int AnonymousID;
169 #endif /* FS_STATS_DETAILED */
170 #if TRANSARC_VOL_STATS
171 static const char nullString[] = "";
172 #endif /* TRANSARC_VOL_STATS */
175 afs_int32 NothingYet;
178 struct afs_FSStats afs_fsstats;
180 void ResetDebug(), SetDebug(), Terminate();
185 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
187 extern afs_int32 implicitAdminRights;
188 extern afs_int32 readonlyServer;
191 * Externals used by the xstat code.
193 extern int VolumeCacheSize, VolumeGets, VolumeReplacements;
194 extern int CEs, CEBlocks;
196 extern int HTs, HTBlocks;
199 FetchData_RXStyle(Volume *volptr,
201 register struct rx_call *Call,
205 #if FS_STATS_DETAILED
206 afs_size_t *a_bytesToFetchP,
207 afs_size_t *a_bytesFetchedP
208 #endif /* FS_STATS_DETAILED */
212 StoreData_RXStyle(Volume *volptr,
215 struct client *client,
216 register struct rx_call *Call,
219 afs_offs_t FileLength,
221 #if FS_STATS_DETAILED
222 afs_size_t *a_bytesToStoreP,
223 afs_size_t *a_bytesStoredP
224 #endif /* FS_STATS_DETAILED */
227 #ifdef AFS_SGI_XFS_IOPS_ENV
228 #include <afs/xfsattrs.h>
229 static int GetLinkCount(Volume *avp, struct stat *astat)
231 if (!strcmp("xfs", astat->st_fstype)) {
232 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
235 return astat->st_nlink;
238 #define GetLinkCount(V, S) (S)->st_nlink
241 afs_int32 SpareComp(Volume *avolp)
243 register afs_int32 temp;
247 temp = V_maxquota(avolp);
249 /* no matter; doesn't check in this case */
253 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.
269 static void SetVolumeSync(register struct AFSVolSync *async,
270 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
293 static int CallPreamble(register struct rx_call *acall, int activecall,
294 struct rx_connection **tconn)
297 struct client *tclient;
302 ViceLog (0, ("CallPreamble: unexpected null tconn!\n"));
305 *tconn = rx_ConnectionOf(acall);
309 tclient = h_FindClient_r(*tconn);
310 if (tclient->prfail == 1) { /* couldn't get the CPS */
312 h_ReleaseClient_r(tclient);
313 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
317 retry_flag=0; /* Retry once */
319 /* Take down the old connection and re-read the key file */
320 ViceLog(0, ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
322 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
325 h_ReleaseClient_r(tclient);
327 ViceLog(0,("CallPreamble: couldn't reconnect to ptserver\n"));
331 tclient->prfail = 2; /* Means re-eval client's cps */
332 h_ReleaseClient_r(tclient);
336 thost = tclient->host;
337 tclient->LastCall = thost->LastCall = FT_ApproxTime();
338 if (activecall) /* For all but "GetTime" calls */
339 thost->ActiveCall = thost->LastCall;
342 if (thost->hostFlags & HOSTDELETED) {
343 ViceLog(3,("Discarded a packet for deleted host %s\n",afs_inet_ntoa_r(thost->host,hoststr)));
344 code = VBUSY; /* raced, so retry */
346 else if ((thost->hostFlags & VENUSDOWN) || (thost->hostFlags & HFE_LATER)){
347 if (BreakDelayedCallBacks_r(thost)) {
348 ViceLog(0,("BreakDelayedCallbacks FAILED for host %s which IS UP. Possible network or routing failure.\n",
349 afs_inet_ntoa_r(thost->host, hoststr)));
350 if ( MultiProbeAlternateAddress_r (thost) ) {
351 ViceLog(0, ("MultiProbe failed to find new address for host %s:%d\n",
352 afs_inet_ntoa_r(thost->host, hoststr),
353 ntohs(thost->port)));
356 ViceLog(0, ("MultiProbe found new address for host %s:%d\n",
357 afs_inet_ntoa_r(thost->host, hoststr),
358 ntohs(thost->port)));
359 if (BreakDelayedCallBacks_r(thost)) {
360 ViceLog(0,("BreakDelayedCallbacks FAILED AGAIN for host %s which IS UP. Possible network or routing failure.\n",
361 afs_inet_ntoa_r(thost->host, hoststr)));
370 h_ReleaseClient_r(tclient);
378 static void CallPostamble(register struct rx_connection *aconn)
381 struct client *tclient;
384 tclient = h_FindClient_r(aconn);
385 thost = tclient->host;
386 h_ReleaseClient_r(tclient);
393 * Returns the volume and vnode pointers associated with file Fid; the lock
394 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
395 * are incremented and they must be eventualy released.
398 CheckVnode(AFSFid *fid, Volume **volptr, Vnode **vptr, int lock)
402 static struct timeval restartedat = {0,0};
404 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
406 if ((*volptr) == 0) {
411 *volptr = VGetVolume(&errorCode, (afs_int32)fid->Volume);
416 if ((errorCode == VOFFLINE) && (VInit < 2)) {
417 /* The volume we want may not be attached yet because
418 * the volume initialization is not yet complete.
419 * We can do several things:
420 * 1. return -1, which will cause users to see
421 * "connection timed out". This is more or
422 * less the same as always, except that the servers
423 * may appear to bounce up and down while they
424 * are actually restarting.
425 * 2. return VBUSY which will cause clients to
426 * sleep and retry for 6.5 - 15 minutes, depending
427 * on what version of the CM they are running. If
428 * the file server takes longer than that interval
429 * to attach the desired volume, then the application
430 * will see an ENODEV or EIO. This approach has
431 * the advantage that volumes which have been attached
432 * are immediately available, it keeps the server's
433 * immediate backlog low, and the call is interruptible
434 * by the user. Users see "waiting for busy volume."
435 * 3. sleep here and retry. Some people like this approach
436 * because there is no danger of seeing errors. However,
437 * this approach only works with a bounded number of
438 * clients, since the pending queues will grow without
439 * stopping. It might be better to find a way to take
440 * this call and stick it back on a queue in order to
441 * recycle this thread for a different request.
442 * 4. Return a new error code, which new cache managers will
443 * know enough to interpret as "sleep and retry", without
444 * the upper bound of 6-15 minutes that is imposed by the
445 * VBUSY handling. Users will see "waiting for
446 * busy volume," so they know that something is
447 * happening. Old cache managers must be able to do
448 * something reasonable with this, for instance, mark the
449 * server down. Fortunately, any error code < 0
450 * will elicit that behavior. See #1.
451 * 5. Some combination of the above. I like doing #2 for 10
452 * minutes, followed by #4. 3.1b and 3.2 cache managers
453 * will be fine as long as the restart period is
454 * not longer than 6.5 minutes, otherwise they may
455 * return ENODEV to users. 3.3 cache managers will be
456 * fine for 10 minutes, then will return
457 * ETIMEDOUT. 3.4 cache managers will just wait
458 * until the call works or fails definitively.
459 * NB. The problem with 2,3,4,5 is that old clients won't
460 * fail over to an alternate read-only replica while this
461 * server is restarting. 3.4 clients will fail over right away.
463 if (restartedat.tv_sec == 0) {
464 /* I'm not really worried about when we restarted, I'm */
465 /* just worried about when the first VBUSY was returned. */
466 TM_GetTimeOfDay(&restartedat, 0);
467 return(busyonrst?VBUSY:VRESTARTING);
471 TM_GetTimeOfDay(&now, 0);
472 if ((now.tv_sec - restartedat.tv_sec) < (11*60)) {
473 return(busyonrst?VBUSY:VRESTARTING);
476 return (VRESTARTING);
480 /* allow read operations on busy volume */
481 else if(errorCode==VBUSY && lock==READ_LOCK) {
492 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
495 if ((*vptr)->disk.uniquifier != fid->Unique) {
496 VPutVnode(&fileCode, *vptr);
497 assert(fileCode == 0);
499 return(VNOVNODE); /* return the right error code, at least */
505 * This routine returns the ACL associated with the targetptr. If the
506 * targetptr isn't a directory, we access its parent dir and get the ACL
507 * thru the parent; in such case the parent's vnode is returned in
511 SetAccessList(Vnode **targetptr,
513 struct acl_accessList **ACL,
519 if ((*targetptr)->disk.type == vDirectory) {
521 *ACL = VVnodeACL(*targetptr);
522 *ACLSize = VAclSize(*targetptr);
531 parentvnode = (*targetptr)->disk.parent;
532 VPutVnode(&errorCode,*targetptr);
534 if (errorCode) return(errorCode);
535 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
536 if (errorCode) return(errorCode);
537 *ACL = VVnodeACL(*parent);
538 *ACLSize = VAclSize(*parent);
539 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
541 if ((*targetptr)->disk.parent != parentvnode) {
542 VPutVnode(&errorCode, *parent);
544 if (errorCode) return(errorCode);
553 * Compare the directory's ACL with the user's access rights in the client
554 * connection and return the user's and everybody else's access permissions
555 * in rights and anyrights, respectively
558 GetRights (struct client *client,
559 struct acl_accessList *ACL,
561 afs_int32 *anyrights)
563 extern prlist SystemAnyUserCPS;
564 afs_int32 hrights = 0;
567 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
569 ViceLog(0,("CheckRights failed\n"));
573 acl_CheckRights(ACL, &client->CPS, rights);
575 /* wait if somebody else is already doing the getCPS call */
577 while ( client->host->hostFlags & HCPS_INPROGRESS )
579 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
580 #ifdef AFS_PTHREAD_ENV
581 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
582 #else /* AFS_PTHREAD_ENV */
583 if ((code=LWP_WaitProcess( &(client->host->hostFlags))) !=LWP_SUCCESS)
584 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
585 #endif /* AFS_PTHREAD_ENV */
588 if (client->host->hcps.prlist_len && !client->host->hcps.prlist_val) {
589 ViceLog(0,("CheckRights: len=%d, for host=0x%x\n", client->host->hcps.prlist_len, client->host->host));
591 acl_CheckRights(ACL, &client->host->hcps, &hrights);
593 /* Allow system:admin the rights given with the -implicit option */
594 if (acl_IsAMember(SystemId, &client->CPS))
595 *rights |= implicitAdminRights;
597 *anyrights |= hrights;
604 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
605 * a System:Administrator)
608 VanillaUser(struct client *client)
610 if (acl_IsAMember(SystemId, &client->CPS))
611 return(0); /* not a system administrator, then you're "vanilla" */
618 * This unusual afs_int32-parameter routine encapsulates all volume package related
619 * operations together in a single function; it's called by almost all AFS
623 GetVolumePackage(struct rx_connection *tcon,
629 struct client **client,
632 afs_int32 *anyrights)
634 struct acl_accessList * aCL; /* Internal access List */
635 int aCLSize; /* size of the access list */
636 int errorCode = 0; /* return code to caller */
638 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
641 if (chkforDir == MustNOTBeDIR && ((*targetptr)->disk.type == vDirectory))
643 else if (chkforDir == MustBeDIR && ((*targetptr)->disk.type != vDirectory))
646 if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent, (chkforDir == MustBeDIR ? (AFSFid *)0 : Fid), (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
648 if (chkforDir == MustBeDIR) assert((*parent) == 0);
649 if ((errorCode = GetClient(tcon, client)) != 0)
653 assert(GetRights(*client, aCL, rights, anyrights) == 0);
654 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
655 if ((*targetptr)->disk.type != vDirectory) {
656 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
657 if ((*targetptr)->disk.owner == (*client)->ViceId)
658 (*rights) |= PRSFS_ADMINISTER;
660 (*rights) &= ~PRSFS_ADMINISTER;
662 #ifdef ADMIN_IMPLICIT_LOOKUP
663 /* admins get automatic lookup on everything */
664 if (!VanillaUser(*client)) (*rights) |= PRSFS_LOOKUP;
665 #endif /* ADMIN_IMPLICIT_LOOKUP */
668 } /*GetVolumePackage*/
672 * This is the opposite of GetVolumePackage(), and is always used at the end of
673 * AFS calls to put back all used vnodes and the volume in the proper order!
676 PutVolumePackage(Vnode *parentwhentargetnotdir,
681 int fileCode = 0; /* Error code returned by the volume package */
683 if (parentwhentargetnotdir) {
684 VPutVnode(&fileCode, parentwhentargetnotdir);
685 assert(!fileCode || (fileCode == VSALVAGE));
688 VPutVnode(&fileCode, targetptr);
689 assert(!fileCode || (fileCode == VSALVAGE));
692 VPutVnode(&fileCode, parentptr);
693 assert(!fileCode || (fileCode == VSALVAGE));
698 } /*PutVolumePackage*/
700 static int VolumeOwner (register struct client *client,
701 register Vnode *targetptr)
703 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
706 return (client->ViceId == owner);
709 * We don't have to check for host's cps since only regular
710 * viceid are volume owners.
712 return (acl_IsAMember(owner, &client->CPS));
717 static int VolumeRootVnode (Vnode *targetptr)
719 return ((targetptr->vnodeNumber == ROOTVNODE) &&
720 (targetptr->disk.uniquifier == 1));
722 } /*VolumeRootVnode*/
725 * Check if target file has the proper access permissions for the Fetch
726 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
727 * StoreStatus) related calls
729 /* this code should probably just set a "priv" flag where all the audit events
730 * are now, and only generate the audit event once at the end of the routine,
731 * thus only generating the event if all the checks succeed, but only because
732 * of the privilege XXX
735 Check_PermissionRights(Vnode *targetptr,
736 struct client *client,
739 AFSStoreStatus *InStatus)
742 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
743 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
744 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
746 if (CallingRoutine & CHK_FETCH) {
747 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client))
749 if (targetptr->disk.type == vDirectory || targetptr->disk.type == vSymlink) {
750 if ( !(rights & PRSFS_LOOKUP)
751 #ifdef ADMIN_IMPLICIT_LOOKUP
752 /* grant admins fetch on all directories */
753 && VanillaUser(client)
754 #endif /* ADMIN_IMPLICIT_LOOKUP */
755 && !VolumeOwner(client, targetptr))
758 /* must have read access, or be owner and have insert access */
759 if (!(rights & PRSFS_READ) &&
760 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
763 if (CallingRoutine == CHK_FETCHDATA && targetptr->disk.type == vFile)
764 #ifdef USE_GROUP_PERMS
765 if (!OWNSp(client, targetptr) &&
766 !acl_IsAMember(targetptr->disk.owner, &client->CPS)) {
767 errorCode = (((GROUPREAD|GROUPEXEC) & targetptr->disk.modeBits)
770 errorCode =(((OWNERREAD|OWNEREXEC) & targetptr->disk.modeBits)
775 * The check with the ownership below is a kludge to allow
776 * reading of files created with no read permission. The owner
777 * of the file is always allowed to read it.
779 if ((client->ViceId != targetptr->disk.owner) && VanillaUser(client))
780 errorCode =(((OWNERREAD|OWNEREXEC) & targetptr->disk.modeBits) ? 0: EACCES);
783 else /* !VanillaUser(client) && !FetchData */ {
784 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
785 AUD_INT, CallingRoutine, AUD_END);
788 else { /* a store operation */
789 if ( (rights & PRSFS_INSERT) && OWNSp(client, targetptr)
790 && (CallingRoutine != CHK_STOREACL)
791 && (targetptr->disk.type == vFile))
793 /* bypass protection checks on first store after a create
794 * for the creator; also prevent chowns during this time
795 * unless you are a system administrator */
796 /****** InStatus->Owner && UnixModeBits better be SET!! */
797 if ( CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
800 else if (VanillaUser (client))
801 return(EPERM); /* Was EACCES */
803 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
804 AUD_INT, CallingRoutine, AUD_END);
807 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
808 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
809 AUD_INT, CallingRoutine, AUD_END);
812 if (readonlyServer) {
815 if (CallingRoutine == CHK_STOREACL) {
816 if (!(rights & PRSFS_ADMINISTER) &&
817 !VolumeOwner(client, targetptr)) return(EACCES);
819 else { /* store data or status */
820 /* watch for chowns and chgrps */
821 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
824 else if (VanillaUser (client))
825 return(EPERM); /* Was EACCES */
827 osi_audit(PrivilegeEvent, 0,
828 AUD_INT, (client ? client->ViceId : 0),
829 AUD_INT, CallingRoutine, AUD_END);
831 /* must be sysadmin to set suid/sgid bits */
832 if ((InStatus->Mask & AFS_SETMODE) &&
834 (InStatus->UnixModeBits & 0xc00) != 0) {
836 (InStatus->UnixModeBits & (S_ISUID|S_ISGID)) != 0) {
840 if (VanillaUser(client))
842 else osi_audit( PrivSetID, 0, AUD_INT, (client ? client->ViceId : 0),
843 AUD_INT, CallingRoutine, AUD_END);
845 if (CallingRoutine == CHK_STOREDATA) {
848 if (!(rights & PRSFS_WRITE))
850 /* Next thing is tricky. We want to prevent people
851 * from writing files sans 0200 bit, but we want
852 * creating new files with 0444 mode to work. We
853 * don't check the 0200 bit in the "you are the owner"
854 * path above, but here we check the bit. However, if
855 * you're a system administrator, we ignore the 0200
856 * bit anyway, since you may have fchowned the file,
858 #ifdef USE_GROUP_PERMS
859 if ((targetptr->disk.type == vFile)
860 && VanillaUser(client)) {
861 if (!OWNSp(client, targetptr) &&
862 !acl_IsAMember(targetptr->disk.owner,
864 errorCode = ((GROUPWRITE & targetptr->disk.modeBits)
867 errorCode = ((OWNERWRITE & targetptr->disk.modeBits)
872 if ((targetptr->disk.type != vDirectory)
873 && (!(targetptr->disk.modeBits & OWNERWRITE)))
876 if (VanillaUser(client))
878 else osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
879 AUD_INT, CallingRoutine, AUD_END);
881 else { /* a status store */
884 if (targetptr->disk.type == vDirectory) {
885 if (!(rights & PRSFS_DELETE) && !(rights & PRSFS_INSERT))
888 else { /* a file or symlink */
889 if (!(rights & PRSFS_WRITE)) return(EACCES);
898 } /*Check_PermissionRights*/
902 * The Access List information is converted from its internal form in the
903 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
904 * external form and returned back to the caller, via the AccessList
908 RXFetch_AccessList(Vnode *targetptr,
909 Vnode *parentwhentargetnotdir,
910 struct AFSOpaque *AccessList)
912 char * eACL; /* External access list placeholder */
914 if (acl_Externalize((targetptr->disk.type == vDirectory ?
915 VVnodeACL(targetptr) :
916 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
919 if ((strlen(eACL)+1) > AFSOPAQUEMAX) {
920 acl_FreeExternalACL(&eACL);
923 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
924 AccessList->AFSOpaque_len = strlen(eACL) +1;
926 acl_FreeExternalACL(&eACL);
929 } /*RXFetch_AccessList*/
933 * The Access List information is converted from its external form in the
934 * input AccessList structure to the internal representation and copied into
935 * the target dir's vnode storage.
938 RXStore_AccessList(Vnode *targetptr, struct AFSOpaque *AccessList)
940 struct acl_accessList * newACL; /* PlaceHolder for new access list */
942 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
944 if ((newACL->size + 4) > VAclSize(targetptr))
946 memcpy((char *) VVnodeACL(targetptr), (char *) newACL, (int)(newACL->size));
947 acl_FreeACL(&newACL);
950 } /*RXStore_AccessList*/
954 Fetch_AccessList(Vnode *targetptr, Vnode *parentwhentargetnotdir,
955 struct AFSAccessList *AccessList)
957 char * eACL; /* External access list placeholder */
959 assert(acl_Externalize((targetptr->disk.type == vDirectory ?
960 VVnodeACL(targetptr) :
961 VVnodeACL(parentwhentargetnotdir)), &eACL) == 0);
962 if ((strlen(eACL)+1) > AccessList->MaxSeqLen) {
963 acl_FreeExternalACL(&eACL);
966 strcpy((char *)(AccessList->SeqBody), (char *)eACL);
967 AccessList->SeqLen = strlen(eACL) +1;
969 acl_FreeExternalACL(&eACL);
972 } /*Fetch_AccessList*/
975 * The Access List information is converted from its external form in the
976 * input AccessList structure to the internal representation and copied into
977 * the target dir's vnode storage.
980 Store_AccessList(Vnode *targetptr, struct AFSAccessList *AccessList)
982 struct acl_accessList * newACL; /* PlaceHolder for new access list */
984 if (acl_Internalize(AccessList->SeqBody, &newACL) != 0)
986 if ((newACL->size + 4) > VAclSize(targetptr))
988 memcpy((char *) VVnodeACL(targetptr), (char *) newACL, (int)(newACL->size));
989 acl_FreeACL(&newACL);
992 } /*Store_AccessList*/
995 /* In our current implementation, each successive data store (new file
996 * data version) creates a new inode. This function creates the new
997 * inode, copies the old inode's contents to the new one, remove the old
998 * inode (i.e. decrement inode count -- if it's currently used the delete
999 * will be delayed), and modify some fields (i.e. vnode's
1000 * disk.inodeNumber and cloned)
1002 #define COPYBUFFSIZE 8192
1003 static int CopyOnWrite(Vnode *targetptr, Volume *volptr)
1005 Inode ino, nearInode;
1008 register afs_size_t size;
1009 register int length;
1012 int rc; /* return code */
1013 IHandle_t *newH; /* Use until finished copying, then cp to vnode.*/
1014 FdHandle_t *targFdP; /* Source Inode file handle */
1015 FdHandle_t *newFdP; /* Dest Inode file handle */
1017 if (targetptr->disk.type == vDirectory) DFlush(); /* just in case? */
1019 VN_GET_LEN(size, targetptr);
1020 buff = (char *)malloc(COPYBUFFSIZE);
1025 ino = VN_GET_INO(targetptr);
1026 assert(VALID_INO(ino));
1027 targFdP = IH_OPEN(targetptr->handle);
1028 if (targFdP == NULL) {
1030 ViceLog(0, ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n", targetptr->vnodeNumber, V_id(volptr), rc));
1032 VTakeOffline (volptr);
1036 nearInode = VN_GET_INO(targetptr);
1037 ino = IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1038 VPartitionPath(V_partition(volptr)),nearInode, V_id(volptr),
1039 targetptr->vnodeNumber, targetptr->disk.uniquifier,
1040 (int)targetptr->disk.dataVersion);
1041 if (!VALID_INO(ino))
1043 ViceLog(0,("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n", volptr->partition->name, V_id(volptr), errno));
1048 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1049 newFdP = IH_OPEN(newH);
1050 assert(newFdP != NULL);
1053 if (size > COPYBUFFSIZE) { /* more than a buffer */
1054 length = COPYBUFFSIZE;
1055 size -= COPYBUFFSIZE;
1060 rdlen = FDH_READ(targFdP, buff, length);
1061 if (rdlen == length)
1062 wrlen = FDH_WRITE(newFdP, buff, length);
1065 /* Callers of this function are not prepared to recover
1066 * from error that put the filesystem in an inconsistent
1067 * state. Make sure that we force the volume off-line if
1068 * we some error other than ENOSPC - 4.29.99)
1070 * In case we are unable to write the required bytes, and the
1071 * error code indicates that the disk is full, we roll-back to
1072 * the initial state.
1074 if((rdlen != length) || (wrlen != length))
1075 if ( (wrlen < 0) && (errno == ENOSPC) ) /* disk full */
1077 ViceLog(0,("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1078 volptr->partition->name, V_id(volptr)));
1079 /* remove destination inode which was partially copied till now*/
1080 FDH_REALLYCLOSE(newFdP);
1082 FDH_REALLYCLOSE(targFdP);
1083 rc = IH_DEC(V_linkHandle(volptr), ino,
1084 V_parentId(volptr));
1086 ViceLog(0,("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1088 volptr->partition->name));
1089 VTakeOffline (volptr);
1095 ViceLog(0,("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1096 V_id(volptr), volptr->partition->name, length,
1097 rdlen, wrlen, errno));
1098 #ifdef FAST_RESTART /* if running in no-salvage, don't core the server */
1099 ViceLog(0,("CopyOnWrite failed: taking volume offline\n"));
1100 #else /* Avoid further corruption and try to get a core. */
1103 /* Decrement this inode so salvager doesn't find it. */
1104 FDH_REALLYCLOSE(newFdP);
1106 FDH_REALLYCLOSE(targFdP);
1107 rc = IH_DEC(V_linkHandle(volptr), ino,
1108 V_parentId(volptr));
1110 VTakeOffline (volptr);
1113 #ifndef AFS_PTHREAD_ENV
1115 #endif /* !AFS_PTHREAD_ENV */
1117 FDH_REALLYCLOSE(targFdP);
1118 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1119 V_parentId(volptr)) ;
1121 IH_RELEASE(targetptr->handle);
1123 rc = FDH_SYNC(newFdP);
1126 targetptr->handle = newH;
1127 VN_SET_INO(targetptr, ino);
1128 targetptr->disk.cloned = 0;
1129 /* Internal change to vnode, no user level change to volume - def 5445 */
1130 targetptr->changed_oldTime = 1;
1132 return 0; /* success */
1137 * Common code to handle with removing the Name (file when it's called from
1138 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1139 * given directory, parentptr.
1143 DeleteTarget(Vnode *parentptr,
1151 DirHandle childdir; /* Handle for dir package I/O */
1155 /* watch for invalid names */
1156 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1158 if (parentptr->disk.cloned)
1160 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1161 if ((errorCode = CopyOnWrite(parentptr, volptr)))
1163 ViceLog(20, ("DeleteTarget %s: CopyOnWrite failed %d\n",Name,errorCode));
1168 /* check that the file is in the directory */
1169 SetDirHandle(dir, parentptr);
1170 if (Lookup(dir, Name, fileFid))
1172 fileFid->Volume = V_id(volptr);
1174 /* just-in-case check for something causing deadlock */
1175 if (fileFid->Vnode == parentptr->vnodeNumber)
1178 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1182 if (ChkForDir == MustBeDIR) {
1183 if ((*targetptr)->disk.type != vDirectory)
1185 } else if ((*targetptr)->disk.type == vDirectory)
1188 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique);*/
1190 * If the uniquifiers dont match then instead of asserting
1191 * take the volume offline and return VSALVAGE
1193 if ( (*targetptr)->disk.uniquifier != fileFid->Unique ) {
1194 VTakeOffline(volptr);
1195 errorCode = VSALVAGE;
1199 if (ChkForDir == MustBeDIR) {
1200 SetDirHandle(&childdir, *targetptr);
1201 if (IsEmpty(&childdir) != 0)
1204 (*targetptr)->delete = 1;
1205 } else if ((--(*targetptr)->disk.linkCount) == 0)
1206 (*targetptr)->delete = 1;
1207 if ((*targetptr)->delete) {
1208 if (VN_GET_INO(*targetptr)) {
1210 IH_REALLYCLOSE((*targetptr)->handle);
1211 errorCode = IH_DEC(V_linkHandle(volptr),
1212 VN_GET_INO(*targetptr),
1213 V_parentId(volptr));
1214 IH_RELEASE((*targetptr)->handle);
1215 if (errorCode == -1) {
1216 ViceLog(0, ("DT: inode=%s, name=%s, errno=%d\n",
1217 PrintInode(NULL, VN_GET_INO(*targetptr)),
1220 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
1222 if (errno != ENOENT)
1225 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1227 VTakeOffline(volptr);
1234 VN_SET_INO(*targetptr, (Inode)0);
1236 afs_size_t adjLength;
1237 VN_GET_LEN(adjLength, *targetptr);
1238 VAdjustDiskUsage(&errorCode, volptr,
1239 -nBlocks(adjLength),
1244 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1246 code = Delete(dir,(char *) Name);
1248 ViceLog(0, ("Error %d deleting %s\n", code,
1249 (((*targetptr)->disk.type== Directory)?"directory":"file")));
1250 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1252 VTakeOffline(volptr);
1253 if (!errorCode) errorCode = code;
1263 * This routine updates the parent directory's status block after the
1264 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1265 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1269 Update_ParentVnodeStatus(Vnode *parentptr,
1274 #if FS_STATS_DETAILED
1275 char a_inSameNetwork
1276 #endif /* FS_STATS_DETAILED */
1279 afs_offs_t newlength; /* Holds new directory length */
1280 afs_offs_t parentLength;
1282 #if FS_STATS_DETAILED
1283 Date currDate; /*Current date*/
1284 int writeIdx; /*Write index to bump*/
1285 int timeIdx; /*Authorship time index to bump*/
1286 #endif /* FS_STATS_DETAILED */
1288 parentptr->disk.dataVersion++;
1289 newlength = Length(dir);
1291 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1292 * (create, symlink, link, makedir) so we need to check if we have enough space
1293 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1294 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1296 VN_GET_LEN(parentLength, parentptr);
1297 if (nBlocks(newlength) != nBlocks(parentLength)) {
1298 VAdjustDiskUsage(&errorCode, volptr,
1299 (nBlocks(newlength) - nBlocks(parentLength)),
1300 (nBlocks(newlength) - nBlocks(parentLength)));
1302 VN_SET_LEN(parentptr, newlength);
1304 #if FS_STATS_DETAILED
1306 * Update directory write stats for this volume. Note that the auth
1307 * counter is located immediately after its associated ``distance''
1310 if (a_inSameNetwork)
1311 writeIdx = VOL_STATS_SAME_NET;
1313 writeIdx = VOL_STATS_DIFF_NET;
1314 V_stat_writes(volptr, writeIdx)++;
1315 if (author != AnonymousID) {
1316 V_stat_writes(volptr, writeIdx+1)++;
1320 * Update the volume's authorship information in response to this
1321 * directory operation. Get the current time, decide to which time
1322 * slot this operation belongs, and bump the appropriate slot.
1324 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1325 timeIdx = (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 :
1326 currDate < VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 :
1327 currDate < VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 :
1328 currDate < VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 :
1329 currDate < VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1330 VOL_STATS_TIME_IDX_5);
1331 if (parentptr->disk.author == author) {
1332 V_stat_dirSameAuthor(volptr, timeIdx)++;
1335 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1337 #endif /* FS_STATS_DETAILED */
1339 parentptr->disk.author = author;
1340 parentptr->disk.linkCount = linkcount;
1341 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1342 parentptr->disk.serverModifyTime = FT_ApproxTime();
1343 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1348 * Update the target file's (or dir's) status block after the specified
1349 * operation is complete. Note that some other fields maybe updated by
1350 * the individual module.
1353 /* XXX INCOMPLETE - More attention is needed here! */
1355 Update_TargetVnodeStatus(Vnode *targetptr,
1357 struct client *client,
1358 AFSStoreStatus *InStatus,
1363 #if FS_STATS_DETAILED
1364 Date currDate; /*Current date*/
1365 int writeIdx; /*Write index to bump*/
1366 int timeIdx; /*Authorship time index to bump*/
1367 #endif /* FS_STATS_DETAILED */
1369 if (Caller & (TVS_CFILE|TVS_SLINK|TVS_MKDIR)) { /* initialize new file */
1370 targetptr->disk.parent = parentptr->vnodeNumber;
1371 VN_SET_LEN(targetptr, length);
1372 /* targetptr->disk.group = 0; save some cycles */
1373 targetptr->disk.modeBits = 0777;
1374 targetptr->disk.owner = client->ViceId;
1375 targetptr->disk.dataVersion = 0 ; /* consistent with the client */
1376 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1377 /* the inode was created in Alloc_NewVnode() */
1380 #if FS_STATS_DETAILED
1382 * Update file write stats for this volume. Note that the auth
1383 * counter is located immediately after its associated ``distance''
1386 if (client->InSameNetwork)
1387 writeIdx = VOL_STATS_SAME_NET;
1389 writeIdx = VOL_STATS_DIFF_NET;
1390 V_stat_writes(volptr, writeIdx)++;
1391 if (client->ViceId != AnonymousID) {
1392 V_stat_writes(volptr, writeIdx+1)++;
1396 * We only count operations that DON'T involve creating new objects
1397 * (files, symlinks, directories) or simply setting status as
1398 * authorship-change operations.
1400 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1402 * Update the volume's authorship information in response to this
1403 * file operation. Get the current time, decide to which time
1404 * slot this operation belongs, and bump the appropriate slot.
1406 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1407 timeIdx = (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 :
1408 currDate < VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 :
1409 currDate < VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 :
1410 currDate < VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 :
1411 currDate < VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1412 VOL_STATS_TIME_IDX_5);
1413 if (targetptr->disk.author == client->ViceId) {
1414 V_stat_fileSameAuthor(volptr, timeIdx)++;
1416 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1419 #endif /* FS_STATS_DETAILED */
1421 if (!(Caller & TVS_SSTATUS))
1422 targetptr->disk.author = client->ViceId;
1423 if (Caller & TVS_SDATA) {
1424 targetptr->disk.dataVersion++;
1425 if (VanillaUser(client))
1427 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1428 #ifdef CREATE_SGUID_ADMIN_ONLY
1429 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1433 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1434 /* store status, must explicitly request to change the date */
1435 if (InStatus->Mask & AFS_SETMODTIME)
1436 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1438 else {/* other: date always changes, but perhaps to what is specified by caller */
1439 targetptr->disk.unixModifyTime = (InStatus->Mask & AFS_SETMODTIME ? InStatus->ClientModTime : FT_ApproxTime());
1441 if (InStatus->Mask & AFS_SETOWNER) {
1442 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1443 if (VanillaUser(client))
1445 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1446 #ifdef CREATE_SGUID_ADMIN_ONLY
1447 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1450 targetptr->disk.owner = InStatus->Owner;
1451 if (VolumeRootVnode (targetptr)) {
1452 Error errorCode = 0; /* what should be done with this? */
1454 V_owner(targetptr->volumePtr) = InStatus->Owner;
1455 VUpdateVolume(&errorCode, targetptr->volumePtr);
1458 if (InStatus->Mask & AFS_SETMODE) {
1459 int modebits = InStatus->UnixModeBits;
1460 #define CREATE_SGUID_ADMIN_ONLY 1
1461 #ifdef CREATE_SGUID_ADMIN_ONLY
1462 if (VanillaUser(client))
1463 modebits = modebits & 0777;
1465 if (VanillaUser(client)) {
1466 targetptr->disk.modeBits = modebits;
1469 targetptr->disk.modeBits = modebits;
1471 case TVS_SDATA: osi_audit( PrivSetID, 0, AUD_INT, client->ViceId,
1472 AUD_INT, CHK_STOREDATA, AUD_END); break;
1474 case TVS_SSTATUS: osi_audit( PrivSetID, 0, AUD_INT, client->ViceId,
1475 AUD_INT, CHK_STORESTATUS, AUD_END); break;
1480 targetptr->disk.serverModifyTime = FT_ApproxTime();
1481 if (InStatus->Mask & AFS_SETGROUP)
1482 targetptr->disk.group = InStatus->Group;
1483 /* vnode changed : to be written back by VPutVnode */
1484 targetptr->changed_newTime = 1;
1486 } /*Update_TargetVnodeStatus*/
1490 * Fills the CallBack structure with the expiration time and type of callback
1491 * structure. Warning: this function is currently incomplete.
1494 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1496 /* CallBackTime could not be 0 */
1497 if (CallBackTime == 0) {
1498 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1499 CallBack->ExpirationTime = 0;
1501 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1502 CallBack->CallBackVersion = CALLBACK_VERSION;
1503 CallBack->CallBackType = CB_SHARED; /* The default for now */
1505 } /*SetCallBackStruct*/
1509 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1510 * allocation; if some error occured (exceeded volume quota or partition
1511 * was full, or whatever), it frees the space back and returns the code.
1512 * We usually pre-adjust the volume space to make sure that there's
1513 * enough space before consuming some.
1516 AdjustDiskUsage(Volume *volptr, afs_size_t length, afs_size_t checkLength)
1521 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1523 VAdjustDiskUsage(&nc, volptr, -length, (afs_size_t) 0);
1524 if (rc == VOVERQUOTA) {
1525 ViceLog(2,("Volume %u (%s) is full\n",
1526 V_id(volptr), V_name(volptr)));
1529 if (rc == VDISKFULL) {
1530 ViceLog(0,("Partition %s that contains volume %u is full\n",
1531 volptr->partition->name, V_id(volptr)));
1534 ViceLog(0,("Got error return %d from VAdjustDiskUsage\n",rc));
1539 } /*AdjustDiskUsage*/
1542 * Common code that handles the creation of a new file (SAFS_CreateFile and
1543 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1546 Alloc_NewVnode(Vnode *parentptr,
1551 struct AFSFid *OutFid,
1553 afs_size_t BlocksPreallocatedForVnode)
1555 int errorCode = 0; /* Error code returned back */
1558 Inode nearInode; /* hint for inode allocation in solaris */
1560 if ((errorCode = AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1561 BlocksPreallocatedForVnode))) {
1562 ViceLog(25, ("Insufficient space to allocate %d blocks\n",
1563 BlocksPreallocatedForVnode));
1567 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1568 if (errorCode != 0) {
1569 VAdjustDiskUsage(&temp, volptr, - BlocksPreallocatedForVnode,
1573 OutFid->Volume = V_id(volptr);
1574 OutFid->Vnode = (*targetptr)->vnodeNumber;
1575 OutFid->Unique = (*targetptr)->disk.uniquifier;
1577 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1579 /* create the inode now itself */
1580 inode = IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1581 VPartitionPath(V_partition(volptr)), nearInode,
1582 V_id(volptr), (*targetptr)->vnodeNumber,
1583 (*targetptr)->disk.uniquifier, 1);
1585 /* error in creating inode */
1586 if (!VALID_INO(inode))
1588 ViceLog(0, ("Volume : %d vnode = %d Failed to create inode: errno = %d\n",
1589 (*targetptr)->volumePtr->header->diskstuff.id,
1590 (*targetptr)->vnodeNumber,
1592 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode,
1594 (*targetptr)->delete = 1; /* delete vnode */
1597 VN_SET_INO(*targetptr, inode);
1598 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1600 /* copy group from parent dir */
1601 (*targetptr)->disk.group = parentptr->disk.group;
1603 if (parentptr->disk.cloned)
1605 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1606 if ((errorCode = CopyOnWrite(parentptr, volptr))) /* disk full */
1608 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1609 /* delete the vnode previously allocated */
1610 (*targetptr)->delete = 1;
1611 VAdjustDiskUsage(&temp, volptr,
1612 -BlocksPreallocatedForVnode, (afs_size_t) 0);
1613 IH_REALLYCLOSE((*targetptr)->handle);
1614 if ( IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)) )
1615 ViceLog(0,("Alloc_NewVnode: partition %s idec %s failed\n",
1616 volptr->partition->name,
1617 PrintInode(NULL, inode)));
1618 IH_RELEASE((*targetptr)->handle);
1624 /* add the name to the directory */
1625 SetDirHandle(dir, parentptr);
1626 if ((errorCode = Create(dir,(char *)Name, OutFid))) {
1627 (*targetptr)->delete = 1;
1628 VAdjustDiskUsage(&temp, volptr, - BlocksPreallocatedForVnode,
1630 IH_REALLYCLOSE((*targetptr)->handle);
1631 if ( IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1632 ViceLog(0,("Alloc_NewVnode: partition %s idec %s failed\n",
1633 volptr->partition->name,
1634 PrintInode(NULL, inode)));
1635 IH_RELEASE((*targetptr)->handle);
1641 } /*Alloc_NewVnode*/
1645 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1649 HandleLocking(Vnode *targetptr, afs_int32 rights, ViceLockType LockingType)
1651 int Time; /* Used for time */
1652 int writeVnode = targetptr->changed_oldTime; /* save original status */
1654 /* Does the caller has Lock priviledges; root extends locks, however */
1655 if (LockingType != LockExtend && !(rights & PRSFS_LOCK))
1657 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1658 Time = FT_ApproxTime();
1659 switch (LockingType) {
1662 if (Time > targetptr->disk.lock.lockTime)
1663 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount = 0;
1664 Time += AFS_LOCKWAIT;
1665 if (LockingType == LockRead) {
1666 if (targetptr->disk.lock.lockCount >= 0) {
1667 ++(targetptr->disk.lock.lockCount);
1668 targetptr->disk.lock.lockTime = Time;
1669 } else return(EAGAIN);
1671 if (targetptr->disk.lock.lockCount == 0) {
1672 targetptr->disk.lock.lockCount = -1;
1673 targetptr->disk.lock.lockTime = Time;
1674 } else return(EAGAIN);
1678 Time += AFS_LOCKWAIT;
1679 if (targetptr->disk.lock.lockCount != 0)
1680 targetptr->disk.lock.lockTime = Time;
1681 else return(EINVAL);
1684 if ((--targetptr->disk.lock.lockCount) <= 0)
1685 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime = 0;
1688 targetptr->changed_oldTime = writeVnode; /* restore old status */
1689 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1694 /* 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. */
1697 CheckWriteMode(Vnode *targetptr, afs_int32 rights, int Prfs_Mode)
1701 if (!(rights & Prfs_Mode))
1703 if ((targetptr->disk.type != vDirectory) && (!(targetptr->disk.modeBits & OWNERWRITE)))
1709 * If some flags (i.e. min or max quota) are set, the volume's in disk
1710 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1711 * update, if applicable.
1714 RXUpdate_VolumeStatus(Volume *volptr, AFSStoreVolumeStatus* StoreVolStatus,
1715 char *Name, char *OfflineMsg, char *Motd)
1717 Error errorCode = 0;
1719 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1720 V_minquota(volptr) = StoreVolStatus->MinQuota;
1721 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1722 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1723 if (strlen(OfflineMsg) > 0) {
1724 strcpy(V_offlineMessage(volptr), OfflineMsg);
1726 if (strlen(Name) > 0) {
1727 strcpy(V_name(volptr), Name);
1729 #if TRANSARC_VOL_STATS
1731 * We don't overwrite the motd field, since it's now being used
1735 if (strlen(Motd) > 0) {
1736 strcpy(V_motd(volptr), Motd);
1738 #endif /* FS_STATS_DETAILED */
1739 VUpdateVolume(&errorCode, volptr);
1742 } /*RXUpdate_VolumeStatus*/
1747 Update_VolumeStatus(Volume *volptr, VolumeStatus *StoreVolStatus,
1748 struct BBS *Name, struct BBS *OfflineMsg,
1751 Error errorCode = 0;
1753 if (StoreVolStatus->MinQuota > -1)
1754 V_minquota(volptr) = StoreVolStatus->MinQuota;
1755 if (StoreVolStatus->MaxQuota > -1)
1756 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1757 if (OfflineMsg->SeqLen > 1)
1758 strcpy(V_offlineMessage(volptr), OfflineMsg->SeqBody);
1759 if (Name->SeqLen > 1)
1760 strcpy(V_name(volptr), Name->SeqBody);
1761 #if TRANSARC_VOL_STATS
1763 * We don't overwrite the motd field, since it's now being used
1767 if (Motd->SeqLen > 1)
1768 strcpy(V_motd(volptr), Motd->SeqBody);
1769 #endif /* FS_STATS_DETAILED */
1770 VUpdateVolume(&errorCode, volptr);
1773 } /*Update_VolumeStatus*/
1777 * Get internal volume-related statistics from the Volume disk label
1778 * structure and put it into the VolumeStatus structure, status; it's
1779 * used by both SAFS_GetVolumeStatus and SAFS_SetVolumeStatus to return
1780 * the volume status to the caller.
1783 GetVolumeStatus(VolumeStatus *status, struct BBS *name, struct BBS *offMsg,
1784 struct BBS *motd, Volume *volptr)
1786 status->Vid = V_id(volptr);
1787 status->ParentId = V_parentId(volptr);
1788 status->Online = V_inUse(volptr);
1789 status->InService = V_inService(volptr);
1790 status->Blessed = V_blessed(volptr);
1791 status->NeedsSalvage = V_needsSalvaged(volptr);
1792 if (VolumeWriteable(volptr))
1793 status->Type = ReadWrite;
1795 status->Type = ReadOnly;
1796 status->MinQuota = V_minquota(volptr);
1797 status->MaxQuota = V_maxquota(volptr);
1798 status->BlocksInUse = V_diskused(volptr);
1799 status->PartBlocksAvail = volptr->partition->free;
1800 status->PartMaxBlocks = volptr->partition->totalUsable;
1801 strncpy(name->SeqBody, V_name(volptr), (int)name->MaxSeqLen);
1802 name->SeqLen = strlen(V_name(volptr)) + 1;
1803 if (name->SeqLen > name->MaxSeqLen) name->SeqLen = name -> MaxSeqLen;
1804 strncpy(offMsg->SeqBody, V_offlineMessage(volptr), (int)name->MaxSeqLen);
1805 offMsg->SeqLen = strlen(V_offlineMessage(volptr)) + 1;
1806 if (offMsg->SeqLen > offMsg->MaxSeqLen)
1807 offMsg->SeqLen = offMsg -> MaxSeqLen;
1809 /*Don't do anything with the motd field*/
1810 strncpy(motd->SeqBody, nullString, (int)offMsg->MaxSeqLen);
1811 motd->SeqLen = strlen(nullString) + 1;
1813 if (motd->SeqLen > motd->MaxSeqLen)
1814 motd->SeqLen = motd -> MaxSeqLen;
1816 } /*GetVolumeStatus*/
1819 RXGetVolumeStatus(AFSFetchVolumeStatus *status, char **name, char **offMsg,
1820 char **motd, Volume *volptr)
1824 status->Vid = V_id(volptr);
1825 status->ParentId = V_parentId(volptr);
1826 status->Online = V_inUse(volptr);
1827 status->InService = V_inService(volptr);
1828 status->Blessed = V_blessed(volptr);
1829 status->NeedsSalvage = V_needsSalvaged(volptr);
1830 if (VolumeWriteable(volptr))
1831 status->Type = ReadWrite;
1833 status->Type = ReadOnly;
1834 status->MinQuota = V_minquota(volptr);
1835 status->MaxQuota = V_maxquota(volptr);
1836 status->BlocksInUse = V_diskused(volptr);
1837 status->PartBlocksAvail = volptr->partition->free;
1838 status->PartMaxBlocks = volptr->partition->totalUsable;
1840 /* now allocate and copy these things; they're freed by the RXGEN stub */
1841 temp = strlen(V_name(volptr)) + 1;
1842 *name = malloc(temp);
1844 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1847 strcpy(*name, V_name(volptr));
1848 temp = strlen(V_offlineMessage(volptr)) + 1;
1849 *offMsg = malloc(temp);
1851 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1854 strcpy(*offMsg, V_offlineMessage(volptr));
1855 #if TRANSARC_VOL_STATS
1858 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1861 strcpy(*motd, nullString);
1863 temp = strlen(V_motd(volptr)) + 1;
1864 *motd = malloc(temp);
1866 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1869 strcpy(*motd, V_motd(volptr));
1870 #endif /* FS_STATS_DETAILED */
1872 } /*RXGetVolumeStatus*/
1876 FileNameOK(register char *aname)
1878 register afs_int32 i, tc;
1881 /* watch for @sys on the right */
1882 if (strcmp(aname+i-4, "@sys") == 0) return 0;
1884 while ((tc = *aname++)) {
1885 if (tc == '/') return 0; /* very bad character to encounter */
1887 return 1; /* file name is ok */
1892 /* Debugging tool to print Volume Statu's contents */
1894 PrintVolumeStatus(VolumeStatus *status)
1896 ViceLog(5,("Volume header contains:\n"));
1897 ViceLog(5,("Vid = %u, Parent = %u, Online = %d, InService = %d, Blessed = %d, NeedsSalvage = %d\n",
1898 status->Vid, status->ParentId, status->Online, status->InService,
1899 status->Blessed, status->NeedsSalvage));
1900 ViceLog(5,("MinQuota = %d, MaxQuota = %d\n", status->MinQuota, status->MaxQuota));
1901 ViceLog(5,("Type = %d, BlocksInUse = %d, PartBlocksAvail = %d, PartMaxBlocks = %d\n",
1902 status->Type, status->BlocksInUse, status->PartBlocksAvail, status->PartMaxBlocks));
1904 } /*PrintVolumeStatus*/
1908 * This variant of symlink is expressly to support the AFS/DFS translator
1909 * and is not supported by the AFS fileserver. We just return EINVAL.
1910 * The cache manager should not generate this call to an AFS cache manager.
1912 afs_int32 SRXAFS_DFSSymlink (struct rx_call *acall,
1913 struct AFSFid *DirFid,
1916 struct AFSStoreStatus *InStatus,
1917 struct AFSFid *OutFid,
1918 struct AFSFetchStatus *OutFidStatus,
1919 struct AFSFetchStatus *OutDirStatus,
1920 struct AFSCallBack *CallBack,
1921 struct AFSVolSync *Sync)
1926 afs_int32 SRXAFS_ResidencyCmd (struct rx_call *acall, struct AFSFid *Fid,
1927 struct ResidencyCmdInputs *Inputs,
1928 struct ResidencyCmdOutputs *Outputs)
1933 static struct afs_buffer {
1934 struct afs_buffer *next;
1935 } *freeBufferList = 0;
1936 static int afs_buffersAlloced = 0;
1938 static FreeSendBuffer(register struct afs_buffer *adata)
1941 afs_buffersAlloced--;
1942 adata->next = freeBufferList;
1943 freeBufferList = adata;
1947 } /*FreeSendBuffer*/
1949 /* allocate space for sender */
1950 static char *AllocSendBuffer()
1952 register struct afs_buffer *tp;
1955 afs_buffersAlloced++;
1956 if (!freeBufferList) {
1960 tmp = malloc(sendBufSize);
1962 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
1967 tp = freeBufferList;
1968 freeBufferList = tp->next;
1972 } /*AllocSendBuffer*/
1975 * This routine returns the status info associated with the targetptr vnode
1976 * in the AFSFetchStatus structure. Some of the newer fields, such as
1977 * SegSize and Group are not yet implemented
1980 void GetStatus(Vnode *targetptr,
1981 AFSFetchStatus *status,
1983 afs_int32 anyrights,
1986 /* initialize return status from a vnode */
1987 status->InterfaceVersion = 1;
1988 status->SyncCounter = status->dataVersionHigh = status->lockCount =
1989 status->errorCode = 0;
1990 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
1991 if (targetptr->disk.type == vFile)
1992 status->FileType = File;
1993 else if (targetptr->disk.type == vDirectory)
1994 status->FileType = Directory;
1995 else if (targetptr->disk.type == vSymlink)
1996 status->FileType = SymbolicLink;
1998 status->FileType = Invalid; /*invalid type field */
1999 status->LinkCount = targetptr->disk.linkCount;
2000 SET_STATUS_LEN(status, targetptr);
2001 status->DataVersion = targetptr->disk.dataVersion;
2002 status->Author = targetptr->disk.author;
2003 status->Owner = targetptr->disk.owner;
2004 status->CallerAccess = rights;
2005 status->AnonymousAccess = anyrights;
2006 status->UnixModeBits = targetptr->disk.modeBits;
2007 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2008 status->ParentVnode = (status->FileType == Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2009 status->ParentUnique = (status->FileType == Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2010 status->ServerModTime = targetptr->disk.serverModifyTime;
2011 status->Group = targetptr->disk.group;
2012 status->lockCount = targetptr->disk.lock.lockCount;
2013 status->errorCode = 0;
2018 afs_int32 common_FetchData64 (struct rx_call *acall,
2022 struct AFSFetchStatus *OutStatus,
2023 struct AFSCallBack *CallBack,
2024 struct AFSVolSync *Sync,
2027 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2028 Vnode * parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2029 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2030 int errorCode = 0; /* return code to caller */
2031 int fileCode = 0; /* return code from vol package */
2032 Volume * volptr = 0; /* pointer to the volume */
2033 struct client *client; /* pointer to the client data */
2034 struct rx_connection *tcon; /* the connection we're part of */
2035 afs_int32 rights, anyrights; /* rights for this and any user */
2036 struct client *t_client; /* tmp ptr to client data */
2037 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2038 #if FS_STATS_DETAILED
2039 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2040 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2041 struct timeval opStartTime,
2042 opStopTime; /* Start/stop times for RPC op*/
2043 struct timeval xferStartTime,
2044 xferStopTime; /* Start/stop times for xfer portion*/
2045 struct timeval elapsedTime; /* Transfer time */
2046 afs_size_t bytesToXfer; /* # bytes to xfer*/
2047 afs_size_t bytesXferred; /* # bytes actually xferred*/
2048 int readIdx; /* Index of read stats array to bump*/
2049 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2052 * Set our stats pointers, remember when the RPC operation started, and
2053 * tally the operation.
2055 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2056 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2060 TM_GetTimeOfDay(&opStartTime, 0);
2061 #endif /* FS_STATS_DETAILED */
2063 ViceLog(1,("SRXAFS_FetchData, Fid = %u.%d.%d\n",
2064 Fid->Volume, Fid->Vnode, Fid->Unique));
2066 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2069 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
2072 /* Get ptr to client data for user Id for logging */
2073 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2074 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2075 ViceLog(5,("SRXAFS_FetchData, Fid = %u.%d.%d, Host %s, Id %d\n",
2076 Fid->Volume, Fid->Vnode, Fid->Unique,
2077 inet_ntoa(logHostAddr), t_client->ViceId));
2079 * Get volume/vnode for the fetched file; caller's access rights to
2080 * it are also returned
2082 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2083 DONTCHECK, &parentwhentargetnotdir,
2084 &client, READ_LOCK, &rights, &anyrights)))
2087 SetVolumeSync(Sync, volptr);
2089 #if FS_STATS_DETAILED
2091 * Remember that another read operation was performed.
2094 if (client->InSameNetwork)
2095 readIdx = VOL_STATS_SAME_NET;
2097 readIdx = VOL_STATS_DIFF_NET;
2098 V_stat_reads(volptr, readIdx)++;
2099 if (client->ViceId != AnonymousID) {
2100 V_stat_reads(volptr, readIdx+1)++;
2103 #endif /* FS_STATS_DETAILED */
2105 /* Check whether the caller has permission access to fetch the data */
2106 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2111 * Drop the read lock on the parent directory after saving the parent
2112 * vnode information we need to pass to GetStatus
2114 if (parentwhentargetnotdir != NULL) {
2115 tparentwhentargetnotdir = *parentwhentargetnotdir;
2116 VPutVnode(&fileCode, parentwhentargetnotdir);
2117 assert(!fileCode || (fileCode == VSALVAGE));
2118 parentwhentargetnotdir = NULL;
2121 #if FS_STATS_DETAILED
2123 * Remember when the data transfer started.
2125 TM_GetTimeOfDay(&xferStartTime, 0);
2126 #endif /* FS_STATS_DETAILED */
2128 /* actually do the data transfer */
2129 #if FS_STATS_DETAILED
2130 errorCode = FetchData_RXStyle(volptr, targetptr, acall,
2131 (afs_size_t) Pos, (afs_size_t) Len, type,
2132 &bytesToXfer, &bytesXferred);
2134 if ((errorCode = FetchData_RXStyle(volptr, targetptr, acall,
2135 (afs_size_t) Pos, (afs_size_t) Len,
2138 #endif /* FS_STATS_DETAILED */
2140 #if FS_STATS_DETAILED
2142 * At this point, the data transfer is done, for good or ill. Remember
2143 * when the transfer ended, bump the number of successes/failures, and
2144 * integrate the transfer size and elapsed time into the stats. If the
2145 * operation failed, we jump to the appropriate point.
2147 TM_GetTimeOfDay(&xferStopTime, 0);
2149 (xferP->numXfers)++;
2151 (xferP->numSuccesses)++;
2154 * Bump the xfer sum by the number of bytes actually sent, NOT the
2157 tot_bytesXferred += bytesXferred;
2158 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2159 tot_bytesXferred &= 0x3FF;
2160 if (bytesXferred < xferP->minBytes)
2161 xferP->minBytes = bytesXferred;
2162 if (bytesXferred > xferP->maxBytes)
2163 xferP->maxBytes = bytesXferred;
2166 * Tally the size of the object. Note: we tally the actual size,
2167 * NOT the number of bytes that made it out over the wire.
2169 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2170 (xferP->count[0])++;
2172 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2173 (xferP->count[1])++;
2175 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2176 (xferP->count[2])++;
2178 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2179 (xferP->count[3])++;
2181 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2182 (xferP->count[4])++;
2184 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2185 (xferP->count[5])++;
2187 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2188 (xferP->count[6])++;
2190 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2191 (xferP->count[7])++;
2193 (xferP->count[8])++;
2195 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2196 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2197 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2198 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2199 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2201 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2202 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2207 * Finally, go off to tell our caller the bad news in case the
2212 #endif /* FS_STATS_DETAILED */
2214 /* write back the OutStatus from the target vnode */
2215 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
2217 /* if a r/w volume, promise a callback to the caller */
2218 if (VolumeWriteable(volptr))
2219 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2221 struct AFSFid myFid;
2222 memset(&myFid, 0, sizeof(struct AFSFid));
2223 myFid.Volume = Fid->Volume;
2224 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2228 /* Update and store volume/vnode and parent vnodes back */
2229 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2230 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2231 CallPostamble(tcon);
2233 #if FS_STATS_DETAILED
2234 TM_GetTimeOfDay(&opStopTime, 0);
2235 if (errorCode == 0) {
2237 (opP->numSuccesses)++;
2238 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2239 fs_stats_AddTo((opP->sumTime), elapsedTime);
2240 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2241 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2242 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2244 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2245 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2250 #endif /* FS_STATS_DETAILED */
2252 osi_auditU (acall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
2255 } /*common_FetchData64*/
2257 afs_int32 SRXAFS_FetchData (struct rx_call *acall,
2261 struct AFSFetchStatus *OutStatus,
2262 struct AFSCallBack *CallBack,
2263 struct AFSVolSync *Sync)
2268 code = common_FetchData64 (acall, Fid,
2269 (afs_size_t) Pos, (afs_size_t) Len,
2275 afs_int32 SRXAFS_FetchData64 (struct rx_call *acall,
2279 struct AFSFetchStatus *OutStatus,
2280 struct AFSCallBack *CallBack,
2281 struct AFSVolSync *Sync)
2284 afs_size_t tPos, tLen;
2286 #ifdef AFS_64BIT_ENV
2287 #ifndef AFS_LARGEFILE_ENV
2288 if (Pos + Len > 0x7fffffff)
2290 #endif /* !AFS_LARGEFILE_ENV */
2293 #else /* AFS_64BIT_ENV */
2294 if (Pos.high || Len.high)
2298 #endif /* AFS_64BIT_ENV */
2300 code = common_FetchData64 (acall, Fid, tPos, tLen, OutStatus,
2305 afs_int32 SRXAFS_FetchACL (struct rx_call *acall,
2307 struct AFSOpaque *AccessList,
2308 struct AFSFetchStatus *OutStatus,
2309 struct AFSVolSync *Sync)
2311 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2312 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2313 int errorCode = 0; /* return error code to caller */
2314 Volume * volptr = 0; /* pointer to the volume */
2315 struct client *client; /* pointer to the client data */
2316 afs_int32 rights, anyrights; /* rights for this and any user */
2317 struct rx_connection *tcon = rx_ConnectionOf(acall);
2318 struct client *t_client; /* tmp ptr to client data */
2319 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2320 #if FS_STATS_DETAILED
2321 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2322 struct timeval opStartTime,
2323 opStopTime; /* Start/stop times for RPC op*/
2324 struct timeval elapsedTime; /* Transfer time */
2327 * Set our stats pointer, remember when the RPC operation started, and
2328 * tally the operation.
2330 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2334 TM_GetTimeOfDay(&opStartTime, 0);
2335 #endif /* FS_STATS_DETAILED */
2337 ViceLog(1, ("SAFS_FetchACL, Fid = %u.%d.%d\n",
2338 Fid->Volume, Fid->Vnode, Fid->Unique));
2340 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2342 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2345 /* Get ptr to client data for user Id for logging */
2346 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2347 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2348 ViceLog(5, ("SAFS_FetchACL, Fid = %u.%d.%d, Host %s, Id %d\n",
2349 Fid->Volume, Fid->Vnode, Fid->Unique,
2350 inet_ntoa(logHostAddr), t_client->ViceId));
2352 AccessList->AFSOpaque_len = 0;
2353 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2354 if (!AccessList->AFSOpaque_val) {
2355 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2360 * Get volume/vnode for the fetched file; caller's access rights to it
2363 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2364 DONTCHECK, &parentwhentargetnotdir,
2365 &client, READ_LOCK, &rights, &anyrights)))
2368 SetVolumeSync(Sync, volptr);
2370 /* Check whether we have permission to fetch the ACL */
2371 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2375 /* Get the Access List from the dir's vnode */
2376 if ((errorCode = RXFetch_AccessList(targetptr, parentwhentargetnotdir,
2380 /* Get OutStatus back From the target Vnode */
2381 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
2384 /* Update and store volume/vnode and parent vnodes back */
2385 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2386 ViceLog(2, ("SAFS_FetchACL returns %d (ACL=%s)\n",
2387 errorCode, AccessList->AFSOpaque_val));
2388 CallPostamble(tcon);
2390 #if FS_STATS_DETAILED
2391 TM_GetTimeOfDay(&opStopTime, 0);
2392 if (errorCode == 0) {
2394 (opP->numSuccesses)++;
2395 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2396 fs_stats_AddTo((opP->sumTime), elapsedTime);
2397 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2398 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2399 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2401 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2402 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2407 #endif /* FS_STATS_DETAILED */
2409 osi_auditU (acall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
2411 } /*SRXAFS_FetchACL*/
2415 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2416 * merged into it when possible.
2419 afs_int32 SAFSS_FetchStatus (struct rx_call *acall,
2421 struct AFSFetchStatus *OutStatus,
2422 struct AFSCallBack *CallBack,
2423 struct AFSVolSync *Sync)
2425 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2426 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2427 int errorCode = 0; /* return code to caller */
2428 Volume * volptr = 0; /* pointer to the volume */
2429 struct client *client; /* pointer to the client data */
2430 afs_int32 rights, anyrights; /* rights for this and any user */
2431 struct client *t_client; /* tmp ptr to client data */
2432 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2433 struct rx_connection *tcon = rx_ConnectionOf(acall);
2435 /* Get ptr to client data for user Id for logging */
2436 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2437 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2438 ViceLog(1, ("SAFS_FetchStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
2439 Fid->Volume, Fid->Vnode, Fid->Unique,
2440 inet_ntoa(logHostAddr), t_client->ViceId));
2442 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2445 * Get volume/vnode for the fetched file; caller's rights to it are
2448 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2449 DONTCHECK, &parentwhentargetnotdir,
2450 &client, READ_LOCK, &rights, &anyrights)))
2451 goto Bad_FetchStatus;
2453 /* set volume synchronization information */
2454 SetVolumeSync(Sync, volptr);
2456 /* Are we allowed to fetch Fid's status? */
2457 if (targetptr->disk.type != vDirectory) {
2458 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2459 CHK_FETCHSTATUS, 0))) {
2460 if (rx_GetCallAbortCode(acall) == errorCode)
2461 rx_SetCallAbortCode(acall, 0);
2462 goto Bad_FetchStatus;
2466 /* set OutStatus From the Fid */
2467 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
2469 /* If a r/w volume, also set the CallBack state */
2470 if (VolumeWriteable(volptr))
2471 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2473 struct AFSFid myFid;
2474 memset(&myFid, 0, sizeof(struct AFSFid));
2475 myFid.Volume = Fid->Volume;
2476 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2480 /* Update and store volume/vnode and parent vnodes back */
2481 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2482 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2485 } /*SAFSS_FetchStatus*/
2488 afs_int32 SRXAFS_BulkStatus(struct rx_call *acall,
2489 struct AFSCBFids *Fids,
2490 struct AFSBulkStats *OutStats,
2491 struct AFSCBs *CallBacks,
2492 struct AFSVolSync *Sync)
2496 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2497 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2498 int errorCode = 0; /* return code to caller */
2499 Volume * volptr = 0; /* pointer to the volume */
2500 struct client *client; /* pointer to the client data */
2501 afs_int32 rights, anyrights; /* rights for this and any user */
2502 register struct AFSFid *tfid; /* file id we're dealing with now */
2503 struct rx_connection *tcon = rx_ConnectionOf(acall);
2504 #if FS_STATS_DETAILED
2505 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2506 struct timeval opStartTime,
2507 opStopTime; /* Start/stop times for RPC op*/
2508 struct timeval elapsedTime; /* Transfer time */
2511 * Set our stats pointer, remember when the RPC operation started, and
2512 * tally the operation.
2514 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2518 TM_GetTimeOfDay(&opStartTime, 0);
2519 #endif /* FS_STATS_DETAILED */
2521 ViceLog(1, ("SAFS_BulkStatus\n"));
2523 AFSCallStats.TotalCalls++;
2526 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2527 if (nfiles <= 0) { /* Sanity check */
2529 goto Audit_and_Return;
2532 /* allocate space for return output parameters */
2533 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2534 malloc(nfiles * sizeof(struct AFSFetchStatus));
2535 if (!OutStats->AFSBulkStats_val) {
2536 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2539 OutStats->AFSBulkStats_len = nfiles;
2540 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2541 malloc(nfiles * sizeof(struct AFSCallBack));
2542 if (!CallBacks->AFSCBs_val) {
2543 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2546 CallBacks->AFSCBs_len = nfiles;
2548 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2549 goto Bad_BulkStatus;
2551 tfid = Fids->AFSCBFids_val;
2552 for (i=0; i<nfiles; i++, tfid++) {
2554 * Get volume/vnode for the fetched file; caller's rights to it
2558 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
2559 DONTCHECK, &parentwhentargetnotdir, &client,
2560 READ_LOCK, &rights, &anyrights)))
2561 goto Bad_BulkStatus;
2562 /* set volume synchronization information, but only once per call */
2564 SetVolumeSync(Sync, volptr);
2566 /* Are we allowed to fetch Fid's status? */
2567 if (targetptr->disk.type != vDirectory) {
2568 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2569 CHK_FETCHSTATUS, 0))) {
2570 if (rx_GetCallAbortCode(acall) == errorCode)
2571 rx_SetCallAbortCode(acall, 0);
2572 goto Bad_BulkStatus;
2576 /* set OutStatus From the Fid */
2577 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i],
2578 rights, anyrights, parentwhentargetnotdir);
2580 /* If a r/w volume, also set the CallBack state */
2581 if (VolumeWriteable(volptr))
2582 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2583 &CallBacks->AFSCBs_val[i]);
2585 struct AFSFid myFid;
2586 memset(&myFid, 0, sizeof(struct AFSFid));
2587 myFid.Volume = tfid->Volume;
2588 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2589 &CallBacks->AFSCBs_val[i]);
2592 /* put back the file ID and volume */
2593 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2594 parentwhentargetnotdir = (Vnode *) 0;
2595 targetptr = (Vnode *) 0;
2596 volptr = (Volume *) 0;
2600 /* Update and store volume/vnode and parent vnodes back */
2601 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2602 CallPostamble(tcon);
2604 #if FS_STATS_DETAILED
2605 TM_GetTimeOfDay(&opStopTime, 0);
2606 if (errorCode == 0) {
2608 (opP->numSuccesses)++;
2609 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2610 fs_stats_AddTo((opP->sumTime), elapsedTime);
2611 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2612 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2613 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2615 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2616 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2621 #endif /* FS_STATS_DETAILED */
2624 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2625 osi_auditU (acall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
2628 } /*SRXAFS_BulkStatus*/
2631 afs_int32 SRXAFS_InlineBulkStatus(struct rx_call *acall,
2632 struct AFSCBFids *Fids,
2633 struct AFSBulkStats *OutStats,
2634 struct AFSCBs *CallBacks,
2635 struct AFSVolSync *Sync)
2639 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2640 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2641 int errorCode = 0; /* return code to caller */
2642 Volume * volptr = 0; /* pointer to the volume */
2643 struct client *client; /* pointer to the client data */
2644 afs_int32 rights, anyrights; /* rights for this and any user */
2645 register struct AFSFid *tfid; /* file id we're dealing with now */
2646 struct rx_connection *tcon;
2647 AFSFetchStatus *tstatus;
2648 #if FS_STATS_DETAILED
2649 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2650 struct timeval opStartTime,
2651 opStopTime; /* Start/stop times for RPC op*/
2652 struct timeval elapsedTime; /* Transfer time */
2655 * Set our stats pointer, remember when the RPC operation started, and
2656 * tally the operation.
2658 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2662 TM_GetTimeOfDay(&opStartTime, 0);
2663 #endif /* FS_STATS_DETAILED */
2665 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2667 AFSCallStats.TotalCalls++;
2670 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2671 if (nfiles <= 0) { /* Sanity check */
2673 goto Audit_and_Return;
2676 /* allocate space for return output parameters */
2677 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2678 malloc(nfiles * sizeof(struct AFSFetchStatus));
2679 if (!OutStats->AFSBulkStats_val) {
2680 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2683 OutStats->AFSBulkStats_len = nfiles;
2684 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2685 malloc(nfiles * sizeof(struct AFSCallBack));
2686 if (!CallBacks->AFSCBs_val) {
2687 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2690 CallBacks->AFSCBs_len = nfiles;
2692 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) {
2693 goto Bad_InlineBulkStatus;
2696 tfid = Fids->AFSCBFids_val;
2697 for (i=0; i<nfiles; i++, tfid++) {
2699 * Get volume/vnode for the fetched file; caller's rights to it
2703 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
2704 DONTCHECK, &parentwhentargetnotdir, &client,
2705 READ_LOCK, &rights, &anyrights))) {
2706 tstatus = &OutStats->AFSBulkStats_val[i];
2707 tstatus->errorCode = errorCode;
2708 parentwhentargetnotdir = (Vnode *) 0;
2709 targetptr = (Vnode *) 0;
2710 volptr = (Volume *) 0;
2714 /* set volume synchronization information, but only once per call */
2716 SetVolumeSync(Sync, volptr);
2718 /* Are we allowed to fetch Fid's status? */
2719 if (targetptr->disk.type != vDirectory) {
2720 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2721 CHK_FETCHSTATUS, 0))) {
2722 tstatus = &OutStats->AFSBulkStats_val[i];
2723 tstatus->errorCode = errorCode;
2724 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2725 parentwhentargetnotdir = (Vnode *) 0;
2726 targetptr = (Vnode *) 0;
2727 volptr = (Volume *) 0;
2732 /* set OutStatus From the Fid */
2733 GetStatus(targetptr, (struct AFSFetchStatus *) &OutStats->AFSBulkStats_val[i],
2734 rights, anyrights, parentwhentargetnotdir);
2736 /* If a r/w volume, also set the CallBack state */
2737 if (VolumeWriteable(volptr))
2738 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2739 &CallBacks->AFSCBs_val[i]);
2741 struct AFSFid myFid;
2742 memset(&myFid, 0, sizeof(struct AFSFid));
2743 myFid.Volume = tfid->Volume;
2744 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2745 &CallBacks->AFSCBs_val[i]);
2748 /* put back the file ID and volume */
2749 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2750 parentwhentargetnotdir = (Vnode *) 0;
2751 targetptr = (Vnode *) 0;
2752 volptr = (Volume *) 0;
2755 Bad_InlineBulkStatus:
2756 /* Update and store volume/vnode and parent vnodes back */
2757 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2758 CallPostamble(tcon);
2760 #if FS_STATS_DETAILED
2761 TM_GetTimeOfDay(&opStopTime, 0);
2762 if (errorCode == 0) {
2764 (opP->numSuccesses)++;
2765 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2766 fs_stats_AddTo((opP->sumTime), elapsedTime);
2767 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2768 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2769 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2771 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2772 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2777 #endif /* FS_STATS_DETAILED */
2780 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2781 osi_auditU (acall, InlineBulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
2784 } /*SRXAFS_InlineBulkStatus*/
2787 afs_int32 SRXAFS_FetchStatus (struct rx_call *acall,
2789 struct AFSFetchStatus *OutStatus,
2790 struct AFSCallBack *CallBack,
2791 struct AFSVolSync *Sync)
2794 struct rx_connection *tcon;
2795 #if FS_STATS_DETAILED
2796 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2797 struct timeval opStartTime,
2798 opStopTime; /* Start/stop times for RPC op*/
2799 struct timeval elapsedTime; /* Transfer time */
2802 * Set our stats pointer, remember when the RPC operation started, and
2803 * tally the operation.
2805 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2809 TM_GetTimeOfDay(&opStartTime, 0);
2810 #endif /* FS_STATS_DETAILED */
2812 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
2813 goto Bad_FetchStatus;
2815 code = SAFSS_FetchStatus (acall, Fid, OutStatus, CallBack, Sync);
2818 CallPostamble(tcon);
2820 #if FS_STATS_DETAILED
2821 TM_GetTimeOfDay(&opStopTime, 0);
2824 (opP->numSuccesses)++;
2825 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2826 fs_stats_AddTo((opP->sumTime), elapsedTime);
2827 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2828 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2829 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2831 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2832 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2837 #endif /* FS_STATS_DETAILED */
2839 osi_auditU (acall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
2842 } /*SRXAFS_FetchStatus*/
2845 afs_int32 common_StoreData64 (struct rx_call *acall,
2847 struct AFSStoreStatus *InStatus,
2850 afs_offs_t FileLength,
2851 struct AFSFetchStatus *OutStatus,
2852 struct AFSVolSync *Sync)
2854 Vnode * targetptr = 0; /* pointer to input fid */
2855 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2856 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2857 int errorCode = 0; /* return code for caller */
2858 int fileCode = 0; /* return code from vol package */
2859 Volume * volptr = 0; /* pointer to the volume header */
2860 struct client * client; /* pointer to client structure */
2861 afs_int32 rights, anyrights; /* rights for this and any user */
2862 struct client *t_client; /* tmp ptr to client data */
2863 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2864 struct rx_connection *tcon;
2865 #if FS_STATS_DETAILED
2866 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2867 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2868 struct timeval opStartTime,
2869 opStopTime; /* Start/stop times for RPC op*/
2870 struct timeval xferStartTime,
2871 xferStopTime; /* Start/stop times for xfer portion*/
2872 struct timeval elapsedTime; /* Transfer time */
2873 afs_size_t bytesToXfer; /* # bytes to xfer */
2874 afs_size_t bytesXferred; /* # bytes actually xfer */
2875 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2878 * Set our stats pointers, remember when the RPC operation started, and
2879 * tally the operation.
2881 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2882 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2887 ViceLog(1, ("StoreData: Fid = %u.%d.%d\n",
2888 Fid->Volume, Fid->Vnode, Fid->Unique));
2889 TM_GetTimeOfDay(&opStartTime, 0);
2890 #endif /* FS_STATS_DETAILED */
2893 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2896 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2899 /* Get ptr to client data for user Id for logging */
2900 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2901 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2902 ViceLog(5, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d\n",
2903 Fid->Volume, Fid->Vnode, Fid->Unique,
2904 inet_ntoa(logHostAddr), t_client->ViceId));
2905 #ifdef AFS_LARGEFILE_ENV
2906 ViceLog(25, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d, Pos (0X%x,0X%x), Len (0X%x,0X%x), FileLen (0X%x,0X%x)\n",
2907 Fid->Volume, Fid->Vnode, Fid->Unique,
2908 inet_ntoa(logHostAddr), t_client->ViceId,
2909 (unsigned) (Pos >> 32), (unsigned) (Pos & 0xffffffff),
2910 (unsigned) (Length >> 32), (unsigned) (Length & 0xffffffff),
2911 (unsigned) (FileLength >> 32), (unsigned) (FileLength & 0xffffffff)));
2912 #else /* !AFS_LARGEFILE_ENV */
2913 ViceLog(25, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d, Pos 0X%x, Len 0X%x, FileLen 0X%x\n",
2914 Fid->Volume, Fid->Vnode, Fid->Unique,
2915 inet_ntoa(logHostAddr), t_client->ViceId,
2919 #endif /* !AFS_LARGEFILE_ENV */
2923 * Get associated volume/vnode for the stored file; caller's rights
2926 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2927 MustNOTBeDIR, &parentwhentargetnotdir,
2928 &client, WRITE_LOCK, &rights, &anyrights))) {
2932 /* set volume synchronization information */
2933 SetVolumeSync(Sync, volptr);
2935 if ((targetptr->disk.type == vSymlink)) {
2936 /* Should we return a better error code here??? */
2941 /* Check if we're allowed to store the data */
2942 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2943 CHK_STOREDATA, InStatus))) {
2948 * Drop the read lock on the parent directory after saving the parent
2949 * vnode information we need to pass to GetStatus
2951 if (parentwhentargetnotdir != NULL) {
2952 tparentwhentargetnotdir = *parentwhentargetnotdir;
2953 VPutVnode(&fileCode, parentwhentargetnotdir);
2954 assert(!fileCode || (fileCode == VSALVAGE));
2955 parentwhentargetnotdir = NULL;
2960 #if FS_STATS_DETAILED
2962 * Remember when the data transfer started.
2964 TM_GetTimeOfDay(&xferStartTime, 0);
2965 #endif /* FS_STATS_DETAILED */
2967 /* Do the actual storing of the data */
2968 #if FS_STATS_DETAILED
2969 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client, acall,
2970 (afs_size_t) Pos, (afs_size_t) Length,
2971 (afs_size_t) FileLength,
2972 (InStatus->Mask & AFS_FSYNC),
2973 &bytesToXfer, &bytesXferred);
2975 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client,
2977 (afs_size_t) Pos, (afs_size_t) Length,
2978 (afs_size_t) FileLength,
2979 (InStatus->Mask & AFS_FSYNC));
2980 if (errorCode && (!targetptr->changed_newTime))
2982 #endif /* FS_STATS_DETAILED */
2983 #if FS_STATS_DETAILED
2985 * At this point, the data transfer is done, for good or ill. Remember
2986 * when the transfer ended, bump the number of successes/failures, and
2987 * integrate the transfer size and elapsed time into the stats. If the
2988 * operation failed, we jump to the appropriate point.
2990 TM_GetTimeOfDay(&xferStopTime, 0);
2992 (xferP->numXfers)++;
2994 (xferP->numSuccesses)++;
2997 * Bump the xfer sum by the number of bytes actually sent, NOT the
3000 tot_bytesXferred += bytesXferred;
3001 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3002 tot_bytesXferred &= 0x3FF;
3003 if (bytesXferred < xferP->minBytes)
3004 xferP->minBytes = bytesXferred;
3005 if (bytesXferred > xferP->maxBytes)
3006 xferP->maxBytes = bytesXferred;
3009 * Tally the size of the object. Note: we tally the actual size,
3010 * NOT the number of bytes that made it out over the wire.
3012 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3013 (xferP->count[0])++;
3015 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3016 (xferP->count[1])++;
3018 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3019 (xferP->count[2])++;
3021 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3022 (xferP->count[3])++;
3024 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3025 (xferP->count[4])++;
3027 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3028 (xferP->count[5])++;
3030 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3031 (xferP->count[6])++;
3033 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3034 (xferP->count[7])++;
3036 (xferP->count[8])++;
3038 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3039 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3040 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3041 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3042 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3044 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3045 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3051 * Finally, go off to tell our caller the bad news in case the
3054 if (errorCode && (!targetptr->changed_newTime))
3056 #endif /* FS_STATS_DETAILED */
3058 /* Update the status of the target's vnode */
3059 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus, targetptr,
3060 volptr, (afs_size_t) 0);
3062 /* Get the updated File's status back to the caller */
3063 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
3066 /* Update and store volume/vnode and parent vnodes back */
3067 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3068 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3070 CallPostamble(tcon);
3072 #if FS_STATS_DETAILED
3073 TM_GetTimeOfDay(&opStopTime, 0);
3074 if (errorCode == 0) {
3076 (opP->numSuccesses)++;
3077 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3078 fs_stats_AddTo((opP->sumTime), elapsedTime);
3079 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3080 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3081 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3083 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3084 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3088 #endif /* FS_STATS_DETAILED */
3090 osi_auditU (acall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
3093 } /*common_StoreData64*/
3095 afs_int32 SRXAFS_StoreData (struct rx_call *acall,
3097 struct AFSStoreStatus *InStatus,
3100 afs_uint32 FileLength,
3101 struct AFSFetchStatus *OutStatus,
3102 struct AFSVolSync *Sync)
3106 code = common_StoreData64 (acall, Fid, InStatus, Pos, Length, FileLength,
3110 } /*SRXAFS_StoreData*/
3112 afs_int32 SRXAFS_StoreData64 (struct rx_call *acall,
3114 struct AFSStoreStatus *InStatus,
3117 afs_uint64 FileLength,
3118 struct AFSFetchStatus *OutStatus,
3119 struct AFSVolSync *Sync)
3124 afs_offs_t tFileLength;
3126 #ifdef AFS_64BIT_ENV
3127 #ifndef AFS_LARGEFILE_ENV
3128 if (FileLength > 0x7fffffff)
3130 #endif /* !AFS_LARGEFILE_ENV */
3133 tFileLength = FileLength;
3134 #else /* AFS_64BIT_ENV */
3135 if (FileLength.high)
3138 tLength = Length.low;
3139 tFileLength = FileLength.low;
3140 #endif /* AFS_64BIT_ENV */
3142 code = common_StoreData64 (acall, Fid, InStatus, tPos, tLength, tFileLength,
3147 afs_int32 SRXAFS_StoreACL (struct rx_call *acall,
3149 struct AFSOpaque *AccessList,
3150 struct AFSFetchStatus *OutStatus,
3151 struct AFSVolSync *Sync)
3153 Vnode * targetptr = 0; /* pointer to input fid */
3154 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3155 int errorCode = 0; /* return code for caller */
3156 struct AFSStoreStatus InStatus; /* Input status for fid */
3157 Volume * volptr = 0; /* pointer to the volume header */
3158 struct client * client; /* pointer to client structure */
3159 afs_int32 rights, anyrights; /* rights for this and any user */
3160 struct rx_connection *tcon;
3161 struct client *t_client; /* tmp ptr to client data */
3162 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3163 #if FS_STATS_DETAILED
3164 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3165 struct timeval opStartTime,
3166 opStopTime; /* Start/stop times for RPC op*/
3167 struct timeval elapsedTime; /* Transfer time */
3170 * Set our stats pointer, remember when the RPC operation started, and
3171 * tally the operation.
3173 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3177 TM_GetTimeOfDay(&opStartTime, 0);
3178 #endif /* FS_STATS_DETAILED */
3179 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
3182 /* Get ptr to client data for user Id for logging */
3183 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3184 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3185 ViceLog(1, ("SAFS_StoreACL, Fid = %u.%d.%d, ACL=%s, Host %s, Id %d\n",
3186 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3187 inet_ntoa(logHostAddr), t_client->ViceId));
3189 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3192 InStatus.Mask = 0; /* not storing any status */
3195 * Get associated volume/vnode for the target dir; caller's rights
3196 * are also returned.
3198 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3199 MustBeDIR, &parentwhentargetnotdir,
3200 &client, WRITE_LOCK, &rights, &anyrights))) {
3204 /* set volume synchronization information */
3205 SetVolumeSync(Sync, volptr);
3207 /* Check if we have permission to change the dir's ACL */
3208 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
3209 CHK_STOREACL, &InStatus))) {
3213 /* Build and store the new Access List for the dir */
3214 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3218 targetptr->changed_newTime = 1; /* status change of directory */
3220 /* convert the write lock to a read lock before breaking callbacks */
3221 VVnodeWriteToRead(&errorCode, targetptr);
3222 assert(!errorCode || errorCode == VSALVAGE);
3224 /* break call backs on the directory */
3225 BreakCallBack(client->host, Fid, 0);
3227 /* Get the updated dir's status back to the caller */
3228 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3231 /* Update and store volume/vnode and parent vnodes back */
3232 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3233 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3234 CallPostamble(tcon);
3236 #if FS_STATS_DETAILED
3237 TM_GetTimeOfDay(&opStopTime, 0);
3238 if (errorCode == 0) {
3240 (opP->numSuccesses)++;
3241 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3242 fs_stats_AddTo((opP->sumTime), elapsedTime);
3243 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3244 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3245 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3247 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3248 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3252 #endif /* FS_STATS_DETAILED */
3254 osi_auditU (acall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
3257 } /*SRXAFS_StoreACL*/
3261 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3262 * should be merged when possible.
3265 SAFSS_StoreStatus (struct rx_call *acall,
3267 struct AFSStoreStatus *InStatus,
3268 struct AFSFetchStatus *OutStatus,
3269 struct AFSVolSync *Sync)
3272 Vnode * targetptr = 0; /* pointer to input fid */
3273 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3274 int errorCode = 0; /* return code for caller */
3275 Volume * volptr = 0; /* pointer to the volume header */
3276 struct client * client; /* pointer to client structure */
3277 afs_int32 rights, anyrights; /* rights for this and any user */
3278 struct client *t_client; /* tmp ptr to client data */
3279 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3280 struct rx_connection *tcon = rx_ConnectionOf(acall);
3282 /* Get ptr to client data for user Id for logging */
3283 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3284 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3285 ViceLog(1, ("SAFS_StoreStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
3286 Fid->Volume, Fid->Vnode, Fid->Unique,
3287 inet_ntoa(logHostAddr), t_client->ViceId));
3289 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3292 * Get volume/vnode for the target file; caller's rights to it are
3295 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3296 DONTCHECK, &parentwhentargetnotdir,
3297 &client, WRITE_LOCK, &rights, &anyrights))) {
3298 goto Bad_StoreStatus;
3301 /* set volume synchronization information */
3302 SetVolumeSync(Sync, volptr);
3304 /* Check if the caller has proper permissions to store status to Fid */
3305 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
3306 CHK_STORESTATUS, InStatus))) {
3307 goto Bad_StoreStatus;
3310 * Check for a symbolic link; we can't chmod these (otherwise could
3311 * change a symlink to a mt pt or vice versa)
3313 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3315 goto Bad_StoreStatus;
3318 /* Update the status of the target's vnode */
3319 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3320 (parentwhentargetnotdir ?
3321 parentwhentargetnotdir : targetptr), volptr,
3324 /* convert the write lock to a read lock before breaking callbacks */
3325 VVnodeWriteToRead(&errorCode, targetptr);
3326 assert(!errorCode || errorCode == VSALVAGE);
3328 /* Break call backs on Fid */
3329 BreakCallBack(client->host, Fid, 0);
3331 /* Return the updated status back to caller */
3332 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
3335 /* Update and store volume/vnode and parent vnodes back */
3336 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3337 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3340 } /*SAFSS_StoreStatus*/
3343 afs_int32 SRXAFS_StoreStatus (struct rx_call *acall,
3345 struct AFSStoreStatus *InStatus,
3346 struct AFSFetchStatus *OutStatus,
3347 struct AFSVolSync *Sync)
3350 struct rx_connection *tcon;
3351 #if FS_STATS_DETAILED
3352 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3353 struct timeval opStartTime,
3354 opStopTime; /* Start/stop times for RPC op*/
3355 struct timeval elapsedTime; /* Transfer time */
3358 * Set our stats pointer, remember when the RPC operation started, and
3359 * tally the operation.
3361 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3365 TM_GetTimeOfDay(&opStartTime, 0);
3366 #endif /* FS_STATS_DETAILED */
3368 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3369 goto Bad_StoreStatus;
3371 code = SAFSS_StoreStatus (acall, Fid, InStatus, OutStatus, Sync);
3374 CallPostamble(tcon);
3376 #if FS_STATS_DETAILED
3377 TM_GetTimeOfDay(&opStopTime, 0);
3380 (opP->numSuccesses)++;
3381 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3382 fs_stats_AddTo((opP->sumTime), elapsedTime);
3383 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3384 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3385 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3387 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3388 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3393 #endif /* FS_STATS_DETAILED */
3395 osi_auditU (acall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
3398 } /*SRXAFS_StoreStatus*/
3402 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3403 * merged in when possible.
3406 SAFSS_RemoveFile (struct rx_call *acall,
3407 struct AFSFid *DirFid,
3409 struct AFSFetchStatus *OutDirStatus,
3410 struct AFSVolSync *Sync)
3412 Vnode * parentptr = 0; /* vnode of input Directory */
3413 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3414 Vnode * targetptr = 0; /* file to be deleted */
3415 Volume * volptr = 0; /* pointer to the volume header */
3416 AFSFid fileFid; /* area for Fid from the directory */
3417 int errorCode = 0; /* error code */
3418 DirHandle dir; /* Handle for dir package I/O */
3419 struct client * client; /* pointer to client structure */
3420 afs_int32 rights, anyrights; /* rights for this and any user */
3421 struct client *t_client; /* tmp ptr to client data */
3422 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3423 struct rx_connection *tcon = rx_ConnectionOf(acall);
3426 /* Get ptr to client data for user Id for logging */
3427 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3428 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3429 ViceLog(1, ("SAFS_RemoveFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
3430 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3431 inet_ntoa(logHostAddr), t_client->ViceId));
3433 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3436 * Get volume/vnode for the parent dir; caller's access rights are
3439 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
3440 MustBeDIR, &parentwhentargetnotdir,
3441 &client, WRITE_LOCK, &rights, &anyrights))) {
3442 goto Bad_RemoveFile;
3444 /* set volume synchronization information */
3445 SetVolumeSync(Sync, volptr);
3447 /* Does the caller has delete (& write) access to the parent directory? */
3448 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3449 goto Bad_RemoveFile;
3452 /* Actually delete the desired file */
3453 if ((errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir,
3454 &fileFid, Name, MustNOTBeDIR))) {
3455 goto Bad_RemoveFile;
3458 /* Update the vnode status of the parent dir */
3459 #if FS_STATS_DETAILED
3460 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3461 parentptr->disk.linkCount, client->InSameNetwork);
3463 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3464 parentptr->disk.linkCount);
3465 #endif /* FS_STATS_DETAILED */
3467 /* Return the updated parent dir's status back to caller */
3468 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3470 /* Handle internal callback state for the parent and the deleted file */
3471 if (targetptr->disk.linkCount == 0) {
3472 /* no references left, discard entry */
3473 DeleteFileCallBacks(&fileFid);
3474 /* convert the parent lock to a read lock before breaking callbacks */
3475 VVnodeWriteToRead(&errorCode, parentptr);
3476 assert(!errorCode || errorCode == VSALVAGE);
3478 /* convert the parent lock to a read lock before breaking callbacks */
3479 VVnodeWriteToRead(&errorCode, parentptr);
3480 assert(!errorCode || errorCode == VSALVAGE);
3481 /* convert the target lock to a read lock before breaking callbacks */
3482 VVnodeWriteToRead(&errorCode, targetptr);
3483 assert(!errorCode || errorCode == VSALVAGE);
3484 /* tell all the file has changed */
3485 BreakCallBack(client->host, &fileFid, 1);
3488 /* break call back on the directory */
3489 BreakCallBack(client->host, DirFid, 0);
3492 /* Update and store volume/vnode and parent vnodes back */
3493 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3495 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3498 } /*SAFSS_RemoveFile*/
3501 afs_int32 SRXAFS_RemoveFile (struct rx_call *acall,
3502 struct AFSFid *DirFid,
3504 struct AFSFetchStatus *OutDirStatus,
3505 struct AFSVolSync *Sync)
3508 struct rx_connection *tcon;
3509 #if FS_STATS_DETAILED
3510 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3511 struct timeval opStartTime,
3512 opStopTime; /* Start/stop times for RPC op*/
3513 struct timeval elapsedTime; /* Transfer time */
3516 * Set our stats pointer, remember when the RPC operation started, and
3517 * tally the operation.
3519 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3523 TM_GetTimeOfDay(&opStartTime, 0);
3524 #endif /* FS_STATS_DETAILED */
3526 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3527 goto Bad_RemoveFile;
3529 code = SAFSS_RemoveFile (acall, DirFid, Name, OutDirStatus, Sync);
3532 CallPostamble(tcon);
3534 #if FS_STATS_DETAILED
3535 TM_GetTimeOfDay(&opStopTime, 0);
3538 (opP->numSuccesses)++;
3539 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3540 fs_stats_AddTo((opP->sumTime), elapsedTime);
3541 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3542 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3543 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3545 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3546 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3551 #endif /* FS_STATS_DETAILED */
3553 osi_auditU (acall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3556 } /*SRXAFS_RemoveFile*/
3560 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3561 * be merged in when possible.
3564 SAFSS_CreateFile (struct rx_call *acall,
3565 struct AFSFid *DirFid,
3567 struct AFSStoreStatus *InStatus,
3568 struct AFSFid *OutFid,
3569 struct AFSFetchStatus *OutFidStatus,
3570 struct AFSFetchStatus *OutDirStatus,
3571 struct AFSCallBack *CallBack,
3572 struct AFSVolSync *Sync)
3574 Vnode * parentptr = 0; /* vnode of input Directory */
3575 Vnode * targetptr = 0; /* vnode of the new file */
3576 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3577 Volume * volptr = 0; /* pointer to the volume header */
3578 int errorCode = 0; /* error code */
3579 DirHandle dir; /* Handle for dir package I/O */
3580 struct client * client; /* pointer to client structure */
3581 afs_int32 rights, anyrights; /* rights for this and any user */
3582 struct client *t_client; /* tmp ptr to client data */
3583 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3584 struct rx_connection *tcon = rx_ConnectionOf(acall);
3588 /* Get ptr to client data for user Id for logging */
3589 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3590 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3591 ViceLog(1, ("SAFS_CreateFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
3592 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3593 inet_ntoa(logHostAddr), t_client->ViceId));
3595 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3597 if (!FileNameOK(Name)) {
3599 goto Bad_CreateFile;
3603 * Get associated volume/vnode for the parent dir; caller long are
3606 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
3607 MustBeDIR, &parentwhentargetnotdir,
3608 &client, WRITE_LOCK, &rights, &anyrights))) {
3609 goto Bad_CreateFile;
3612 /* set volume synchronization information */
3613 SetVolumeSync(Sync, volptr);
3615 /* Can we write (and insert) onto the parent directory? */
3616 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3617 goto Bad_CreateFile;
3619 /* get a new vnode for the file to be created and set it up */
3620 if ((errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
3621 Name, OutFid, vFile, nBlocks(0)))) {
3622 goto Bad_CreateFile;
3625 /* update the status of the parent vnode */
3626 #if FS_STATS_DETAILED
3627 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3628 parentptr->disk.linkCount, client->InSameNetwork);
3630 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3631 parentptr->disk.linkCount);
3632 #endif /* FS_STATS_DETAILED */
3634 /* update the status of the new file's vnode */
3635 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3636 parentptr, volptr, (afs_size_t)0);
3638 /* set up the return status for the parent dir and the newly created file */
3639 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
3640 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3642 /* convert the write lock to a read lock before breaking callbacks */
3643 VVnodeWriteToRead(&errorCode, parentptr);
3644 assert(!errorCode || errorCode == VSALVAGE);
3646 /* break call back on parent dir */
3647 BreakCallBack(client->host, DirFid, 0);
3649 /* Return a callback promise for the newly created file to the caller */
3650 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3653 /* Update and store volume/vnode and parent vnodes back */
3654 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3656 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3659 } /*SAFSS_CreateFile*/
3662 afs_int32 SRXAFS_CreateFile (struct rx_call *acall,
3663 struct AFSFid *DirFid,
3665 struct AFSStoreStatus *InStatus,
3666 struct AFSFid *OutFid,
3667 struct AFSFetchStatus *OutFidStatus,
3668 struct AFSFetchStatus *OutDirStatus,
3669 struct AFSCallBack *CallBack,
3670 struct AFSVolSync *Sync)
3673 struct rx_connection *tcon;
3674 #if FS_STATS_DETAILED
3675 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3676 struct timeval opStartTime,
3677 opStopTime; /* Start/stop times for RPC op*/
3678 struct timeval elapsedTime; /* Transfer time */
3681 * Set our stats pointer, remember when the RPC operation started, and
3682 * tally the operation.
3684 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3688 TM_GetTimeOfDay(&opStartTime, 0);
3689 #endif /* FS_STATS_DETAILED */
3691 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3692 goto Bad_CreateFile;
3694 code = SAFSS_CreateFile (acall, DirFid, Name, InStatus, OutFid,
3695 OutFidStatus, OutDirStatus, CallBack, Sync);
3698 CallPostamble(tcon);
3700 #if FS_STATS_DETAILED
3701 TM_GetTimeOfDay(&opStopTime, 0);
3704 (opP->numSuccesses)++;
3705 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3706 fs_stats_AddTo((opP->sumTime), elapsedTime);
3707 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3708 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3709 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3711 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3712 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3716 #endif /* FS_STATS_DETAILED */
3718 osi_auditU (acall, CreateFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3721 } /*SRXAFS_CreateFile*/
3725 * This routine is called exclusively from SRXAFS_Rename(), and should be
3726 * merged in when possible.
3729 SAFSS_Rename (struct rx_call *acall,
3730 struct AFSFid *OldDirFid,
3732 struct AFSFid *NewDirFid,
3734 struct AFSFetchStatus *OutOldDirStatus,
3735 struct AFSFetchStatus *OutNewDirStatus,
3736 struct AFSVolSync *Sync)
3738 Vnode * oldvptr = 0; /* vnode of the old Directory */
3739 Vnode * newvptr = 0; /* vnode of the new Directory */
3740 Vnode * fileptr = 0; /* vnode of the file to move */
3741 Vnode * newfileptr = 0; /* vnode of the file to delete */
3742 Vnode * testvptr = 0; /* used in directory tree walk */
3743 Vnode * parent = 0; /* parent for use in SetAccessList */
3744 int errorCode = 0; /* error code */
3745 int fileCode = 0; /* used when writing Vnodes */
3746 VnodeId testnode; /* used in directory tree walk */
3747 AFSFid fileFid; /* Fid of file to move */
3748 AFSFid newFileFid; /* Fid of new file */
3749 DirHandle olddir; /* Handle for dir package I/O */
3750 DirHandle newdir; /* Handle for dir package I/O */
3751 DirHandle filedir; /* Handle for dir package I/O */
3752 DirHandle newfiledir; /* Handle for dir package I/O */
3753 Volume * volptr = 0; /* pointer to the volume header */
3754 struct client * client; /* pointer to client structure */
3755 afs_int32 rights, anyrights; /* rights for this and any user */
3756 afs_int32 newrights; /* rights for this user */
3757 afs_int32 newanyrights; /* rights for any user */
3758 int doDelete; /* deleted the rename target (ref count now 0) */
3760 struct client *t_client; /* tmp ptr to client data */
3761 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3762 struct rx_connection *tcon = rx_ConnectionOf(acall);
3767 FidZero(&newfiledir);
3769 /* Get ptr to client data for user Id for logging */
3770 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3771 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3772 ViceLog(1, ("SAFS_Rename %s to %s, Fid = %u.%d.%d to %u.%d.%d, Host %s, Id %d\n",
3773 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3774 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3776 inet_ntoa(logHostAddr), t_client->ViceId));
3778 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3780 if (!FileNameOK(NewName)) {
3784 if (OldDirFid->Volume != NewDirFid->Volume) {
3789 if ( (strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0) ||
3790 (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0) ||
3791 (strlen(NewName) == 0) || (strlen(OldName) == 0) ) {
3797 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3798 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr,
3799 &oldvptr, MustBeDIR, &parent,
3800 &client, WRITE_LOCK, &rights,
3805 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3807 newrights = rights, newanyrights = anyrights;
3810 if ((errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
3811 &newvptr, MustBeDIR, &parent,
3812 &client, WRITE_LOCK, &newrights,
3819 if ((errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
3820 &newvptr, MustBeDIR, &parent,
3821 &client, WRITE_LOCK, &newrights,
3826 if ((errorCode = GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr,
3827 MustBeDIR, &parent, &client, WRITE_LOCK,
3828 &rights, &anyrights))) {
3834 /* set volume synchronization information */
3835 SetVolumeSync(Sync, volptr);
3837 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3840 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3844 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3845 * call to CopyOnWrite returns error, it is not necessary to revert back
3846 * the effects of the first call because the contents of the volume is
3847 * not modified, it is only replicated.
3849 if (oldvptr->disk.cloned)
3851 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3852 if ( ( errorCode = CopyOnWrite(oldvptr, volptr) ) )
3855 SetDirHandle(&olddir, oldvptr);
3856 if (newvptr->disk.cloned)
3858 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3859 if ( ( errorCode = CopyOnWrite(newvptr, volptr) ) )
3863 SetDirHandle(&newdir, newvptr);
3865 /* Lookup the file to delete its vnode */
3866 if (Lookup(&olddir, OldName, &fileFid)) {
3870 if (fileFid.Vnode == oldvptr->vnodeNumber ||
3871 fileFid.Vnode == newvptr->vnodeNumber) {
3872 errorCode = FSERR_ELOOP;
3875 fileFid.Volume = V_id(volptr);
3876 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3877 if (errorCode != 0) {
3878 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n", OldName, errorCode));
3879 VTakeOffline (volptr);
3882 if (fileptr->disk.uniquifier != fileFid.Unique) {
3883 ViceLog (0, ("SAFSS_Rename(): Old file %s uniquifier mismatch\n", OldName));
3884 VTakeOffline (volptr);
3889 if (fileptr->disk.type != vDirectory &&
3890 oldvptr != newvptr &&
3891 fileptr->disk.linkCount != 1) {
3893 * Hard links exist to this file - cannot move one of the links to
3894 * a new directory because of AFS restrictions (this is the same
3895 * reason that links cannot be made across directories, i.e.
3902 /* Lookup the new file */
3903 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3904 if (readonlyServer) {
3905 errorCode = VREADONLY;
3908 if (!(newrights & PRSFS_DELETE)) {
3912 if (newFileFid.Vnode == oldvptr->vnodeNumber ||
3913 newFileFid.Vnode == newvptr->vnodeNumber ||
3914 newFileFid.Vnode == fileFid.Vnode) {
3918 newFileFid.Volume = V_id(volptr);
3919 newfileptr = VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3920 if (errorCode != 0) {
3921 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n", NewName, errorCode));
3922 VTakeOffline (volptr);
3925 if (fileptr->disk.uniquifier != fileFid.Unique) {
3926 ViceLog (0, ("SAFSS_Rename(): New file %s uniquifier mismatch\n", NewName));
3927 VTakeOffline (volptr);
3931 SetDirHandle(&newfiledir, newfileptr);
3932 /* Now check that we're moving directories over directories properly, etc.
3933 * return proper POSIX error codes:
3934 * if fileptr is a file and new is a dir: EISDIR.
3935 * if fileptr is a dir and new is a file: ENOTDIR.
3936 * Also, dir to be removed must be empty, of course.
3938 if (newfileptr->disk.type == vDirectory) {
3939 if (fileptr->disk.type != vDirectory) {
3943 if ((IsEmpty(&newfiledir))) {
3949 if (fileptr->disk.type == vDirectory) {
3950 errorCode = ENOTDIR;
3957 * ok - now we check that the old name is not above new name in the
3958 * directory structure. This is to prevent removing a subtree alltogether
3960 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3961 for (testnode = newvptr->disk.parent; testnode != 0;) {
3962 if (testnode == oldvptr->vnodeNumber) {
3963 testnode = oldvptr->disk.parent;
3966 if ((testnode == fileptr->vnodeNumber) ||
3967 (testnode == newvptr->vnodeNumber)) {
3968 errorCode = FSERR_ELOOP;
3971 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3972 errorCode = FSERR_ELOOP;
3975 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3976 assert(errorCode == 0);
3977 testnode = testvptr->disk.parent;
3978 VPutVnode(&errorCode, testvptr);
3979 assert(errorCode == 0);
3982 /* Do the CopyonWrite first before modifying anything else. Copying is
3983 * required because we may have to change entries for ..
3985 if ((fileptr->disk.type == vDirectory ) && (fileptr->disk.cloned) )
3987 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3988 if ( ( errorCode = CopyOnWrite(fileptr, volptr) ) )
3992 /* If the new name exists already, delete it and the file it points to */
3995 /* Delete NewName from its directory */
3996 code = Delete(&newdir, NewName);
3999 /* Drop the link count */
4000 newfileptr->disk.linkCount--;
4001 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4003 VN_GET_LEN(newSize, newfileptr);
4004 VAdjustDiskUsage(&errorCode, volptr,
4005 -nBlocks(newSize), (afs_size_t) 0);
4006 if (VN_GET_INO(newfileptr)) {
4007 IH_REALLYCLOSE(newfileptr->handle);
4008 errorCode = IH_DEC(V_linkHandle(volptr),
4009 VN_GET_INO(newfileptr),
4010 V_parentId(volptr));
4011 IH_RELEASE(newfileptr->handle);
4012 if (errorCode == -1) {
4013 ViceLog(0, ("Del: inode=%s, name=%s, errno=%d\n",
4014 PrintInode(NULL, VN_GET_INO(newfileptr)),
4016 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
4017 ViceLog(0, ("Do we need to fsck?"));
4020 VN_SET_INO(newfileptr, (Inode)0);
4021 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4024 /* Link count did not drop to zero.
4025 * Mark NewName vnode as changed - updates stime.
4027 newfileptr->changed_newTime = 1;
4032 * If the create below fails, and the delete above worked, we have
4033 * removed the new name and not replaced it. This is not very likely,
4034 * but possible. We could try to put the old file back, but it is
4035 * highly unlikely that it would work since it would involve issuing