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>
38 #undef SHARED /* XXX */
43 #include <sys/param.h>
45 #include <netinet/in.h>
47 #include <sys/ioctl.h>
48 #include <sys/socket.h>
58 #ifndef AFS_LINUX20_ENV
60 #include <netinet/if_ether.h>
64 /* included early because of name conflict on IOPEN */
65 #include <sys/inode.h>
69 #endif /* AFS_HPUX_ENV */
73 #include <afs/assert.h>
76 #include <afs/afsint.h>
77 #include <afs/vldbint.h>
78 #include <afs/errors.h>
79 #include <afs/ihandle.h>
80 #include <afs/vnode.h>
81 #include <afs/volume.h>
83 #include <afs/ptclient.h>
84 #include <afs/prs_fs.h>
86 #include <rx/rx_globals.h>
88 #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)
91 #if !defined(AFS_NT40_ENV)
94 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
96 #include <sys/statfs.h>
97 #include <sys/lockf.h>
99 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
104 #include <afs/cellconfig.h>
105 #include <afs/keys.h>
107 #include <afs/auth.h>
109 #include <afs/partition.h>
110 #include "viced_prototypes.h"
113 #include <afs/unified_afs.h>
114 #include <afs/audit.h>
115 #include <afs/afsutil.h>
118 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
119 extern void FidZap(DirHandle * file);
120 extern void FidZero(DirHandle * file);
122 #ifdef AFS_PTHREAD_ENV
123 pthread_mutex_t fileproc_glock_mutex;
124 #endif /* AFS_PTHREAD_ENV */
127 #define afs_stat stat64
128 #define afs_fstat fstat64
129 #define afs_open open64
130 #else /* !O_LARGEFILE */
131 #define afs_stat stat
132 #define afs_fstat fstat
133 #define afs_open open
134 #endif /* !O_LARGEFILE */
137 /* Useful local defines used by this module */
140 #define MustNOTBeDIR 1
144 #define TVS_SSTATUS 2
147 #define TVS_MKDIR 0x10
149 #define CHK_FETCH 0x10
150 #define CHK_FETCHDATA 0x10
151 #define CHK_FETCHACL 0x11
152 #define CHK_FETCHSTATUS 0x12
153 #define CHK_STOREDATA 0x00
154 #define CHK_STOREACL 0x01
155 #define CHK_STORESTATUS 0x02
157 #define OWNERREAD 0400
158 #define OWNERWRITE 0200
159 #define OWNEREXEC 0100
160 #ifdef USE_GROUP_PERMS
161 #define GROUPREAD 0040
162 #define GROUPWRITE 0020
163 #define GROUPREXEC 0010
166 /* The following errors were not defined in NT. They are given unique
167 * names here to avoid any potential collision.
169 #define FSERR_ELOOP 90
170 #define FSERR_EOPNOTSUPP 122
171 #define FSERR_ECONNREFUSED 130
173 #define NOTACTIVECALL 0
176 #define CREATE_SGUID_ADMIN_ONLY 1
178 extern struct afsconf_dir *confDir;
179 extern afs_int32 dataVersionHigh;
182 static struct AFSCallStatistics AFSCallStats;
183 #if FS_STATS_DETAILED
184 struct fs_stats_FullPerfStats afs_FullPerfStats;
185 extern int AnonymousID;
186 #endif /* FS_STATS_DETAILED */
187 #if OPENAFS_VOL_STATS
188 static const char nullString[] = "";
189 #endif /* OPENAFS_VOL_STATS */
192 afs_int32 NothingYet;
195 struct afs_FSStats afs_fsstats;
197 void ResetDebug(), SetDebug(), Terminate();
202 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
204 extern afs_int32 implicitAdminRights;
205 extern afs_int32 readonlyServer;
208 * Externals used by the xstat code.
210 extern int VolumeCacheSize, VolumeGets, VolumeReplacements;
211 extern int CEs, CEBlocks;
213 extern int HTs, HTBlocks;
215 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
216 register struct rx_call *Call, afs_sfsize_t Pos,
217 afs_sfsize_t Len, afs_int32 Int64Mode,
218 #if FS_STATS_DETAILED
219 afs_sfsize_t * a_bytesToFetchP,
220 afs_sfsize_t * a_bytesFetchedP
221 #endif /* FS_STATS_DETAILED */
224 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
225 struct AFSFid *Fid, struct client *client,
226 register struct rx_call *Call, afs_fsize_t Pos,
227 afs_fsize_t Length, afs_fsize_t FileLength,
229 #if FS_STATS_DETAILED
230 afs_sfsize_t * a_bytesToStoreP,
231 afs_sfsize_t * a_bytesStoredP
232 #endif /* FS_STATS_DETAILED */
235 #ifdef AFS_SGI_XFS_IOPS_ENV
236 #include <afs/xfsattrs.h>
238 GetLinkCount(Volume * avp, struct stat *astat)
240 if (!strcmp("xfs", astat->st_fstype)) {
241 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
243 return astat->st_nlink;
246 #define GetLinkCount(V, S) (S)->st_nlink
250 SpareComp(Volume * avolp)
252 register afs_int32 temp;
256 temp = V_maxquota(avolp);
258 /* no matter; doesn't check in this case */
262 temp = (temp * PctSpare) / 100;
273 * Set the volume synchronization parameter for this volume. If it changes,
274 * the Cache Manager knows that the volume must be purged from the stat cache.
277 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
280 /* date volume instance was created */
283 async->spare1 = avol->header->diskstuff.creationDate;
296 * Note that this function always returns a held host, so
297 * that CallPostamble can block without the host's disappearing.
298 * Call returns rx connection in passed in *tconn
301 CallPreamble(register struct rx_call *acall, int activecall,
302 struct rx_connection **tconn)
305 struct client *tclient;
310 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
313 *tconn = rx_ConnectionOf(acall);
317 tclient = h_FindClient_r(*tconn);
318 if (tclient->prfail == 1) { /* couldn't get the CPS */
320 h_ReleaseClient_r(tclient);
321 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
325 retry_flag = 0; /* Retry once */
327 /* Take down the old connection and re-read the key file */
329 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
331 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
334 h_ReleaseClient_r(tclient);
336 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
340 tclient->prfail = 2; /* Means re-eval client's cps */
341 h_ReleaseClient_r(tclient);
345 thost = tclient->host;
346 tclient->LastCall = thost->LastCall = FT_ApproxTime();
347 if (activecall) /* For all but "GetTime" calls */
348 thost->ActiveCall = thost->LastCall;
351 if (thost->hostFlags & HOSTDELETED) {
353 ("Discarded a packet for deleted host %s\n",
354 afs_inet_ntoa_r(thost->host, hoststr)));
355 code = VBUSY; /* raced, so retry */
356 } else if ((thost->hostFlags & VENUSDOWN)
357 || (thost->hostFlags & HFE_LATER)) {
358 if (BreakDelayedCallBacks_r(thost)) {
360 ("BreakDelayedCallbacks FAILED for host %s which IS UP. Possible network or routing failure.\n",
361 afs_inet_ntoa_r(thost->host, hoststr)));
362 if (MultiProbeAlternateAddress_r(thost)) {
364 ("MultiProbe failed to find new address for host %s:%d\n",
365 afs_inet_ntoa_r(thost->host, hoststr),
366 ntohs(thost->port)));
370 ("MultiProbe found new address for host %s:%d\n",
371 afs_inet_ntoa_r(thost->host, hoststr),
372 ntohs(thost->port)));
373 if (BreakDelayedCallBacks_r(thost)) {
375 ("BreakDelayedCallbacks FAILED AGAIN for host %s which IS UP. Possible network or routing failure.\n",
376 afs_inet_ntoa_r(thost->host, hoststr)));
385 h_ReleaseClient_r(tclient);
394 CallPostamble(register struct rx_connection *aconn, afs_int32 ret)
397 struct client *tclient;
401 tclient = h_FindClient_r(aconn);
402 thost = tclient->host;
403 if (thost->hostFlags & HERRORTRANS)
405 h_ReleaseClient_r(tclient);
408 return (translate ? sys_error_to_et(ret) : ret);
412 * Returns the volume and vnode pointers associated with file Fid; the lock
413 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
414 * are incremented and they must be eventualy released.
417 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
421 static struct timeval restartedat = { 0, 0 };
423 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
425 if ((*volptr) == 0) {
430 *volptr = VGetVolume(&errorCode, (afs_int32) fid->Volume);
435 if ((errorCode == VOFFLINE) && (VInit < 2)) {
436 /* The volume we want may not be attached yet because
437 * the volume initialization is not yet complete.
438 * We can do several things:
439 * 1. return -1, which will cause users to see
440 * "connection timed out". This is more or
441 * less the same as always, except that the servers
442 * may appear to bounce up and down while they
443 * are actually restarting.
444 * 2. return VBUSY which will cause clients to
445 * sleep and retry for 6.5 - 15 minutes, depending
446 * on what version of the CM they are running. If
447 * the file server takes longer than that interval
448 * to attach the desired volume, then the application
449 * will see an ENODEV or EIO. This approach has
450 * the advantage that volumes which have been attached
451 * are immediately available, it keeps the server's
452 * immediate backlog low, and the call is interruptible
453 * by the user. Users see "waiting for busy volume."
454 * 3. sleep here and retry. Some people like this approach
455 * because there is no danger of seeing errors. However,
456 * this approach only works with a bounded number of
457 * clients, since the pending queues will grow without
458 * stopping. It might be better to find a way to take
459 * this call and stick it back on a queue in order to
460 * recycle this thread for a different request.
461 * 4. Return a new error code, which new cache managers will
462 * know enough to interpret as "sleep and retry", without
463 * the upper bound of 6-15 minutes that is imposed by the
464 * VBUSY handling. Users will see "waiting for
465 * busy volume," so they know that something is
466 * happening. Old cache managers must be able to do
467 * something reasonable with this, for instance, mark the
468 * server down. Fortunately, any error code < 0
469 * will elicit that behavior. See #1.
470 * 5. Some combination of the above. I like doing #2 for 10
471 * minutes, followed by #4. 3.1b and 3.2 cache managers
472 * will be fine as long as the restart period is
473 * not longer than 6.5 minutes, otherwise they may
474 * return ENODEV to users. 3.3 cache managers will be
475 * fine for 10 minutes, then will return
476 * ETIMEDOUT. 3.4 cache managers will just wait
477 * until the call works or fails definitively.
478 * NB. The problem with 2,3,4,5 is that old clients won't
479 * fail over to an alternate read-only replica while this
480 * server is restarting. 3.4 clients will fail over right away.
482 if (restartedat.tv_sec == 0) {
483 /* I'm not really worried about when we restarted, I'm */
484 /* just worried about when the first VBUSY was returned. */
485 TM_GetTimeOfDay(&restartedat, 0);
488 afs_perfstats.fs_nBusies++;
491 return (busyonrst ? VBUSY : VRESTARTING);
494 TM_GetTimeOfDay(&now, 0);
495 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
498 afs_perfstats.fs_nBusies++;
501 return (busyonrst ? VBUSY : VRESTARTING);
503 return (VRESTARTING);
507 /* allow read operations on busy volume */
508 else if (errorCode == VBUSY && lock == READ_LOCK) {
511 } else if (errorCode)
518 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
521 if ((*vptr)->disk.uniquifier != fid->Unique) {
522 VPutVnode(&fileCode, *vptr);
523 assert(fileCode == 0);
525 return (VNOVNODE); /* return the right error code, at least */
531 * This routine returns the ACL associated with the targetptr. If the
532 * targetptr isn't a directory, we access its parent dir and get the ACL
533 * thru the parent; in such case the parent's vnode is returned in
537 SetAccessList(Vnode ** targetptr, Volume ** volume,
538 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
539 AFSFid * Fid, int Lock)
541 if ((*targetptr)->disk.type == vDirectory) {
543 *ACL = VVnodeACL(*targetptr);
544 *ACLSize = VAclSize(*targetptr);
552 parentvnode = (*targetptr)->disk.parent;
553 VPutVnode(&errorCode, *targetptr);
557 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
560 *ACL = VVnodeACL(*parent);
561 *ACLSize = VAclSize(*parent);
562 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
564 if ((*targetptr)->disk.parent != parentvnode) {
565 VPutVnode(&errorCode, *parent);
577 * Compare the directory's ACL with the user's access rights in the client
578 * connection and return the user's and everybody else's access permissions
579 * in rights and anyrights, respectively
582 GetRights(struct client *client, struct acl_accessList *ACL,
583 afs_int32 * rights, afs_int32 * anyrights)
585 extern prlist SystemAnyUserCPS;
586 afs_int32 hrights = 0;
587 #ifndef AFS_PTHREAD_ENV
591 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
593 ViceLog(0, ("CheckRights failed\n"));
598 ObtainWriteLock(&client->lock);
599 acl_CheckRights(ACL, &client->CPS, rights);
600 ReleaseWriteLock(&client->lock);
602 /* wait if somebody else is already doing the getCPS call */
604 while (client->host->hostFlags & HCPS_INPROGRESS) {
605 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
606 #ifdef AFS_PTHREAD_ENV
607 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
608 #else /* AFS_PTHREAD_ENV */
610 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
611 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
612 #endif /* AFS_PTHREAD_ENV */
615 if (client->host->hcps.prlist_len && !client->host->hcps.prlist_val) {
617 ("CheckRights: len=%u, for host=0x%x\n",
618 client->host->hcps.prlist_len, client->host->host));
620 acl_CheckRights(ACL, &client->host->hcps, &hrights);
622 /* Allow system:admin the rights given with the -implicit option */
623 if (acl_IsAMember(SystemId, &client->CPS))
624 *rights |= implicitAdminRights;
626 *anyrights |= hrights;
633 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
634 * a System:Administrator)
637 VanillaUser(struct client *client)
639 if (acl_IsAMember(SystemId, &client->CPS))
640 return (0); /* not a system administrator, then you're "vanilla" */
647 * This unusual afs_int32-parameter routine encapsulates all volume package related
648 * operations together in a single function; it's called by almost all AFS
652 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
653 Vnode ** targetptr, int chkforDir, Vnode ** parent,
654 struct client **client, int locktype, afs_int32 * rights,
655 afs_int32 * anyrights)
657 struct acl_accessList *aCL; /* Internal access List */
658 int aCLSize; /* size of the access list */
659 int errorCode = 0; /* return code to caller */
661 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
664 if (chkforDir == MustNOTBeDIR
665 && ((*targetptr)->disk.type == vDirectory))
667 else if (chkforDir == MustBeDIR
668 && ((*targetptr)->disk.type != vDirectory))
672 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
673 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
674 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
676 if (chkforDir == MustBeDIR)
677 assert((*parent) == 0);
678 if ((errorCode = GetClient(tcon, client)) != 0)
682 assert(GetRights(*client, aCL, rights, anyrights) == 0);
683 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
684 if ((*targetptr)->disk.type != vDirectory) {
685 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
686 if ((*targetptr)->disk.owner == (*client)->ViceId)
687 (*rights) |= PRSFS_ADMINISTER;
689 (*rights) &= ~PRSFS_ADMINISTER;
691 #ifdef ADMIN_IMPLICIT_LOOKUP
692 /* admins get automatic lookup on everything */
693 if (!VanillaUser(*client))
694 (*rights) |= PRSFS_LOOKUP;
695 #endif /* ADMIN_IMPLICIT_LOOKUP */
698 } /*GetVolumePackage */
702 * This is the opposite of GetVolumePackage(), and is always used at the end of
703 * AFS calls to put back all used vnodes and the volume in the proper order!
706 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
707 Vnode * parentptr, Volume * volptr)
709 int fileCode = 0; /* Error code returned by the volume package */
711 if (parentwhentargetnotdir) {
712 VPutVnode(&fileCode, parentwhentargetnotdir);
713 assert(!fileCode || (fileCode == VSALVAGE));
716 VPutVnode(&fileCode, targetptr);
717 assert(!fileCode || (fileCode == VSALVAGE));
720 VPutVnode(&fileCode, parentptr);
721 assert(!fileCode || (fileCode == VSALVAGE));
726 } /*PutVolumePackage */
729 VolumeOwner(register struct client *client, register Vnode * targetptr)
731 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
734 return (client->ViceId == owner);
737 * We don't have to check for host's cps since only regular
738 * viceid are volume owners.
740 return (acl_IsAMember(owner, &client->CPS));
746 VolumeRootVnode(Vnode * targetptr)
748 return ((targetptr->vnodeNumber == ROOTVNODE)
749 && (targetptr->disk.uniquifier == 1));
751 } /*VolumeRootVnode */
754 * Check if target file has the proper access permissions for the Fetch
755 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
756 * StoreStatus) related calls
758 /* this code should probably just set a "priv" flag where all the audit events
759 * are now, and only generate the audit event once at the end of the routine,
760 * thus only generating the event if all the checks succeed, but only because
761 * of the privilege XXX
764 Check_PermissionRights(Vnode * targetptr, struct client *client,
765 afs_int32 rights, int CallingRoutine,
766 AFSStoreStatus * InStatus)
769 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
770 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
771 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
773 if (CallingRoutine & CHK_FETCH) {
774 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
775 if (targetptr->disk.type == vDirectory
776 || targetptr->disk.type == vSymlink) {
777 if (!(rights & PRSFS_LOOKUP)
778 #ifdef ADMIN_IMPLICIT_LOOKUP
779 /* grant admins fetch on all directories */
780 && VanillaUser(client)
781 #endif /* ADMIN_IMPLICIT_LOOKUP */
782 && !VolumeOwner(client, targetptr))
785 /* must have read access, or be owner and have insert access */
786 if (!(rights & PRSFS_READ)
787 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
790 if (CallingRoutine == CHK_FETCHDATA
791 && targetptr->disk.type == vFile)
792 #ifdef USE_GROUP_PERMS
793 if (!OWNSp(client, targetptr)
794 && !acl_IsAMember(targetptr->disk.owner, &client->CPS)) {
796 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
800 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
805 * The check with the ownership below is a kludge to allow
806 * reading of files created with no read permission. The owner
807 * of the file is always allowed to read it.
809 if ((client->ViceId != targetptr->disk.owner)
810 && VanillaUser(client))
812 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
813 modeBits) ? 0 : EACCES);
815 } else { /* !VanillaUser(client) && !FetchData */
817 osi_audit(PrivilegeEvent, 0, AUD_INT,
818 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
821 } else { /* a store operation */
822 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
823 && (CallingRoutine != CHK_STOREACL)
824 && (targetptr->disk.type == vFile)) {
825 /* bypass protection checks on first store after a create
826 * for the creator; also prevent chowns during this time
827 * unless you are a system administrator */
828 /****** InStatus->Owner && UnixModeBits better be SET!! */
829 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
832 else if (VanillaUser(client))
833 return (EPERM); /* Was EACCES */
835 osi_audit(PrivilegeEvent, 0, AUD_INT,
836 (client ? client->ViceId : 0), AUD_INT,
837 CallingRoutine, AUD_END);
840 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
841 osi_audit(PrivilegeEvent, 0, AUD_INT,
842 (client ? client->ViceId : 0), AUD_INT,
843 CallingRoutine, AUD_END);
845 if (readonlyServer) {
848 if (CallingRoutine == CHK_STOREACL) {
849 if (!(rights & PRSFS_ADMINISTER)
850 && !VolumeOwner(client, targetptr))
852 } else { /* store data or status */
853 /* watch for chowns and chgrps */
854 if (CHOWN(InStatus, targetptr)
855 || CHGRP(InStatus, targetptr)) {
858 else if (VanillaUser(client))
859 return (EPERM); /* Was EACCES */
861 osi_audit(PrivilegeEvent, 0, AUD_INT,
862 (client ? client->ViceId : 0), AUD_INT,
863 CallingRoutine, AUD_END);
865 /* must be sysadmin to set suid/sgid bits */
866 if ((InStatus->Mask & AFS_SETMODE) &&
868 (InStatus->UnixModeBits & 0xc00) != 0) {
870 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
874 if (VanillaUser(client))
877 osi_audit(PrivSetID, 0, AUD_INT,
878 (client ? client->ViceId : 0), AUD_INT,
879 CallingRoutine, AUD_END);
881 if (CallingRoutine == CHK_STOREDATA) {
884 if (!(rights & PRSFS_WRITE))
886 /* Next thing is tricky. We want to prevent people
887 * from writing files sans 0200 bit, but we want
888 * creating new files with 0444 mode to work. We
889 * don't check the 0200 bit in the "you are the owner"
890 * path above, but here we check the bit. However, if
891 * you're a system administrator, we ignore the 0200
892 * bit anyway, since you may have fchowned the file,
894 #ifdef USE_GROUP_PERMS
895 if ((targetptr->disk.type == vFile)
896 && VanillaUser(client)) {
897 if (!OWNSp(client, targetptr)
898 && !acl_IsAMember(targetptr->disk.owner,
901 ((GROUPWRITE & targetptr->disk.modeBits)
905 ((OWNERWRITE & targetptr->disk.modeBits)
910 if ((targetptr->disk.type != vDirectory)
911 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
914 if (VanillaUser(client))
917 osi_audit(PrivilegeEvent, 0, AUD_INT,
918 (client ? client->ViceId : 0),
919 AUD_INT, CallingRoutine, AUD_END);
921 } else { /* a status store */
924 if (targetptr->disk.type == vDirectory) {
925 if (!(rights & PRSFS_DELETE)
926 && !(rights & PRSFS_INSERT))
928 } else { /* a file or symlink */
929 if (!(rights & PRSFS_WRITE))
939 } /*Check_PermissionRights */
943 * The Access List information is converted from its internal form in the
944 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
945 * external form and returned back to the caller, via the AccessList
949 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
950 struct AFSOpaque *AccessList)
952 char *eACL; /* External access list placeholder */
955 ((targetptr->disk.type ==
956 vDirectory ? VVnodeACL(targetptr) :
957 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
960 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
961 acl_FreeExternalACL(&eACL);
964 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
965 AccessList->AFSOpaque_len = strlen(eACL) + 1;
967 acl_FreeExternalACL(&eACL);
970 } /*RXFetch_AccessList */
974 * The Access List information is converted from its external form in the
975 * input AccessList structure to the internal representation and copied into
976 * the target dir's vnode storage.
979 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
981 struct acl_accessList *newACL; /* PlaceHolder for new access list */
983 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
985 if ((newACL->size + 4) > VAclSize(targetptr))
987 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
988 acl_FreeACL(&newACL);
991 } /*RXStore_AccessList */
995 Fetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
996 struct AFSAccessList *AccessList)
998 char *eACL; /* External access list placeholder */
1000 assert(acl_Externalize
1001 ((targetptr->disk.type ==
1002 vDirectory ? VVnodeACL(targetptr) :
1003 VVnodeACL(parentwhentargetnotdir)), &eACL) == 0);
1004 if ((strlen(eACL) + 1) > AccessList->MaxSeqLen) {
1005 acl_FreeExternalACL(&eACL);
1008 strcpy((char *)(AccessList->SeqBody), (char *)eACL);
1009 AccessList->SeqLen = strlen(eACL) + 1;
1011 acl_FreeExternalACL(&eACL);
1014 } /*Fetch_AccessList */
1017 * The Access List information is converted from its external form in the
1018 * input AccessList structure to the internal representation and copied into
1019 * the target dir's vnode storage.
1022 Store_AccessList(Vnode * targetptr, struct AFSAccessList *AccessList)
1024 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1026 if (acl_Internalize(AccessList->SeqBody, &newACL) != 0)
1028 if ((newACL->size + 4) > VAclSize(targetptr))
1030 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1031 acl_FreeACL(&newACL);
1034 } /*Store_AccessList */
1037 /* In our current implementation, each successive data store (new file
1038 * data version) creates a new inode. This function creates the new
1039 * inode, copies the old inode's contents to the new one, remove the old
1040 * inode (i.e. decrement inode count -- if it's currently used the delete
1041 * will be delayed), and modify some fields (i.e. vnode's
1042 * disk.inodeNumber and cloned)
1044 #define COPYBUFFSIZE 8192
1046 CopyOnWrite(Vnode * targetptr, Volume * volptr)
1048 Inode ino, nearInode;
1051 register afs_fsize_t size;
1052 register int length;
1054 int rc; /* return code */
1055 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1056 FdHandle_t *targFdP; /* Source Inode file handle */
1057 FdHandle_t *newFdP; /* Dest Inode file handle */
1059 if (targetptr->disk.type == vDirectory)
1060 DFlush(); /* just in case? */
1062 VN_GET_LEN(size, targetptr);
1063 buff = (char *)malloc(COPYBUFFSIZE);
1068 ino = VN_GET_INO(targetptr);
1069 assert(VALID_INO(ino));
1070 targFdP = IH_OPEN(targetptr->handle);
1071 if (targFdP == NULL) {
1074 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1075 targetptr->vnodeNumber, V_id(volptr), rc));
1077 VTakeOffline(volptr);
1081 nearInode = VN_GET_INO(targetptr);
1083 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1084 VPartitionPath(V_partition(volptr)), nearInode,
1085 V_id(volptr), targetptr->vnodeNumber,
1086 targetptr->disk.uniquifier,
1087 (int)targetptr->disk.dataVersion);
1088 if (!VALID_INO(ino)) {
1090 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1091 volptr->partition->name, V_id(volptr), errno));
1096 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1097 newFdP = IH_OPEN(newH);
1098 assert(newFdP != NULL);
1101 if (size > COPYBUFFSIZE) { /* more than a buffer */
1102 length = COPYBUFFSIZE;
1103 size -= COPYBUFFSIZE;
1108 rdlen = FDH_READ(targFdP, buff, length);
1109 if (rdlen == length)
1110 wrlen = FDH_WRITE(newFdP, buff, length);
1113 /* Callers of this function are not prepared to recover
1114 * from error that put the filesystem in an inconsistent
1115 * state. Make sure that we force the volume off-line if
1116 * we some error other than ENOSPC - 4.29.99)
1118 * In case we are unable to write the required bytes, and the
1119 * error code indicates that the disk is full, we roll-back to
1120 * the initial state.
1122 if ((rdlen != length) || (wrlen != length))
1123 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1125 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1126 volptr->partition->name, V_id(volptr)));
1127 /* remove destination inode which was partially copied till now */
1128 FDH_REALLYCLOSE(newFdP);
1130 FDH_REALLYCLOSE(targFdP);
1131 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1134 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1135 rc, V_id(volptr), volptr->partition->name));
1136 VTakeOffline(volptr);
1142 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1143 V_id(volptr), volptr->partition->name, length, rdlen,
1145 #ifdef FAST_RESTART /* if running in no-salvage, don't core the server */
1146 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1147 #else /* Avoid further corruption and try to get a core. */
1150 /* Decrement this inode so salvager doesn't find it. */
1151 FDH_REALLYCLOSE(newFdP);
1153 FDH_REALLYCLOSE(targFdP);
1154 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1156 VTakeOffline(volptr);
1159 #ifndef AFS_PTHREAD_ENV
1161 #endif /* !AFS_PTHREAD_ENV */
1163 FDH_REALLYCLOSE(targFdP);
1164 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1165 V_parentId(volptr));
1167 IH_RELEASE(targetptr->handle);
1169 rc = FDH_SYNC(newFdP);
1172 targetptr->handle = newH;
1173 VN_SET_INO(targetptr, ino);
1174 targetptr->disk.cloned = 0;
1175 /* Internal change to vnode, no user level change to volume - def 5445 */
1176 targetptr->changed_oldTime = 1;
1178 return 0; /* success */
1183 * Common code to handle with removing the Name (file when it's called from
1184 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1185 * given directory, parentptr.
1187 int DT1 = 0, DT0 = 0;
1189 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1190 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1192 DirHandle childdir; /* Handle for dir package I/O */
1196 /* watch for invalid names */
1197 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1199 if (parentptr->disk.cloned) {
1200 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1201 if ((errorCode = CopyOnWrite(parentptr, volptr))) {
1203 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1209 /* check that the file is in the directory */
1210 SetDirHandle(dir, parentptr);
1211 if (Lookup(dir, Name, fileFid))
1213 fileFid->Volume = V_id(volptr);
1215 /* just-in-case check for something causing deadlock */
1216 if (fileFid->Vnode == parentptr->vnodeNumber)
1219 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1223 if (ChkForDir == MustBeDIR) {
1224 if ((*targetptr)->disk.type != vDirectory)
1226 } else if ((*targetptr)->disk.type == vDirectory)
1229 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1231 * If the uniquifiers dont match then instead of asserting
1232 * take the volume offline and return VSALVAGE
1234 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1235 VTakeOffline(volptr);
1236 errorCode = VSALVAGE;
1240 if (ChkForDir == MustBeDIR) {
1241 SetDirHandle(&childdir, *targetptr);
1242 if (IsEmpty(&childdir) != 0)
1245 (*targetptr)->delete = 1;
1246 } else if ((--(*targetptr)->disk.linkCount) == 0)
1247 (*targetptr)->delete = 1;
1248 if ((*targetptr)->delete) {
1249 if (VN_GET_INO(*targetptr)) {
1251 IH_REALLYCLOSE((*targetptr)->handle);
1253 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1254 V_parentId(volptr));
1255 IH_RELEASE((*targetptr)->handle);
1256 if (errorCode == -1) {
1258 ("DT: inode=%s, name=%s, errno=%d\n",
1259 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1261 if (errno != ENOENT)
1264 ("Volume %u now offline, must be salvaged.\n",
1266 VTakeOffline(volptr);
1273 VN_SET_INO(*targetptr, (Inode) 0);
1275 afs_fsize_t adjLength;
1276 VN_GET_LEN(adjLength, *targetptr);
1277 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1281 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1283 code = Delete(dir, (char *)Name);
1286 ("Error %d deleting %s\n", code,
1287 (((*targetptr)->disk.type ==
1288 Directory) ? "directory" : "file")));
1290 ("Volume %u now offline, must be salvaged.\n",
1292 VTakeOffline(volptr);
1304 * This routine updates the parent directory's status block after the
1305 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1306 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1310 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1311 int author, int linkcount,
1312 #if FS_STATS_DETAILED
1313 char a_inSameNetwork
1314 #endif /* FS_STATS_DETAILED */
1317 afs_fsize_t newlength; /* Holds new directory length */
1318 afs_fsize_t parentLength;
1320 #if FS_STATS_DETAILED
1321 Date currDate; /*Current date */
1322 int writeIdx; /*Write index to bump */
1323 int timeIdx; /*Authorship time index to bump */
1324 #endif /* FS_STATS_DETAILED */
1326 parentptr->disk.dataVersion++;
1327 newlength = (afs_fsize_t) Length(dir);
1329 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1330 * (create, symlink, link, makedir) so we need to check if we have enough space
1331 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1332 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1334 VN_GET_LEN(parentLength, parentptr);
1335 if (nBlocks(newlength) != nBlocks(parentLength)) {
1336 VAdjustDiskUsage(&errorCode, volptr,
1337 (nBlocks(newlength) - nBlocks(parentLength)),
1338 (nBlocks(newlength) - nBlocks(parentLength)));
1340 VN_SET_LEN(parentptr, newlength);
1342 #if FS_STATS_DETAILED
1344 * Update directory write stats for this volume. Note that the auth
1345 * counter is located immediately after its associated ``distance''
1348 if (a_inSameNetwork)
1349 writeIdx = VOL_STATS_SAME_NET;
1351 writeIdx = VOL_STATS_DIFF_NET;
1352 V_stat_writes(volptr, writeIdx)++;
1353 if (author != AnonymousID) {
1354 V_stat_writes(volptr, writeIdx + 1)++;
1358 * Update the volume's authorship information in response to this
1359 * directory operation. Get the current time, decide to which time
1360 * slot this operation belongs, and bump the appropriate slot.
1362 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1364 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1365 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1366 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1367 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1368 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1369 if (parentptr->disk.author == author) {
1370 V_stat_dirSameAuthor(volptr, timeIdx)++;
1372 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1374 #endif /* FS_STATS_DETAILED */
1376 parentptr->disk.author = author;
1377 parentptr->disk.linkCount = linkcount;
1378 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1379 parentptr->disk.serverModifyTime = FT_ApproxTime();
1380 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1385 * Update the target file's (or dir's) status block after the specified
1386 * operation is complete. Note that some other fields maybe updated by
1387 * the individual module.
1390 /* XXX INCOMPLETE - More attention is needed here! */
1392 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1393 struct client *client, AFSStoreStatus * InStatus,
1394 Vnode * parentptr, Volume * volptr,
1397 #if FS_STATS_DETAILED
1398 Date currDate; /*Current date */
1399 int writeIdx; /*Write index to bump */
1400 int timeIdx; /*Authorship time index to bump */
1401 #endif /* FS_STATS_DETAILED */
1403 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1404 targetptr->disk.parent = parentptr->vnodeNumber;
1405 VN_SET_LEN(targetptr, length);
1406 /* targetptr->disk.group = 0; save some cycles */
1407 targetptr->disk.modeBits = 0777;
1408 targetptr->disk.owner = client->ViceId;
1409 targetptr->disk.dataVersion = 0; /* consistent with the client */
1410 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1411 /* the inode was created in Alloc_NewVnode() */
1413 #if FS_STATS_DETAILED
1415 * Update file write stats for this volume. Note that the auth
1416 * counter is located immediately after its associated ``distance''
1419 if (client->InSameNetwork)
1420 writeIdx = VOL_STATS_SAME_NET;
1422 writeIdx = VOL_STATS_DIFF_NET;
1423 V_stat_writes(volptr, writeIdx)++;
1424 if (client->ViceId != AnonymousID) {
1425 V_stat_writes(volptr, writeIdx + 1)++;
1429 * We only count operations that DON'T involve creating new objects
1430 * (files, symlinks, directories) or simply setting status as
1431 * authorship-change operations.
1433 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1435 * Update the volume's authorship information in response to this
1436 * file operation. Get the current time, decide to which time
1437 * slot this operation belongs, and bump the appropriate slot.
1439 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1442 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1443 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1444 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1445 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1446 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1447 VOL_STATS_TIME_IDX_5);
1448 if (targetptr->disk.author == client->ViceId) {
1449 V_stat_fileSameAuthor(volptr, timeIdx)++;
1451 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1454 #endif /* FS_STATS_DETAILED */
1456 if (!(Caller & TVS_SSTATUS))
1457 targetptr->disk.author = client->ViceId;
1458 if (Caller & TVS_SDATA) {
1459 targetptr->disk.dataVersion++;
1460 if (VanillaUser(client)) {
1461 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1462 #ifdef CREATE_SGUID_ADMIN_ONLY
1463 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1467 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1468 /* store status, must explicitly request to change the date */
1469 if (InStatus->Mask & AFS_SETMODTIME)
1470 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1471 } else { /* other: date always changes, but perhaps to what is specified by caller */
1472 targetptr->disk.unixModifyTime =
1473 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1474 ClientModTime : FT_ApproxTime());
1476 if (InStatus->Mask & AFS_SETOWNER) {
1477 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1478 if (VanillaUser(client)) {
1479 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1480 #ifdef CREATE_SGUID_ADMIN_ONLY
1481 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1484 targetptr->disk.owner = InStatus->Owner;
1485 if (VolumeRootVnode(targetptr)) {
1486 Error errorCode = 0; /* what should be done with this? */
1488 V_owner(targetptr->volumePtr) = InStatus->Owner;
1489 VUpdateVolume(&errorCode, targetptr->volumePtr);
1492 if (InStatus->Mask & AFS_SETMODE) {
1493 int modebits = InStatus->UnixModeBits;
1494 #define CREATE_SGUID_ADMIN_ONLY 1
1495 #ifdef CREATE_SGUID_ADMIN_ONLY
1496 if (VanillaUser(client))
1497 modebits = modebits & 0777;
1499 if (VanillaUser(client)) {
1500 targetptr->disk.modeBits = modebits;
1502 targetptr->disk.modeBits = modebits;
1505 osi_audit(PrivSetID, 0, AUD_INT, client->ViceId, AUD_INT,
1506 CHK_STOREDATA, AUD_END);
1510 osi_audit(PrivSetID, 0, AUD_INT, client->ViceId, AUD_INT,
1511 CHK_STORESTATUS, AUD_END);
1518 targetptr->disk.serverModifyTime = FT_ApproxTime();
1519 if (InStatus->Mask & AFS_SETGROUP)
1520 targetptr->disk.group = InStatus->Group;
1521 /* vnode changed : to be written back by VPutVnode */
1522 targetptr->changed_newTime = 1;
1524 } /*Update_TargetVnodeStatus */
1528 * Fills the CallBack structure with the expiration time and type of callback
1529 * structure. Warning: this function is currently incomplete.
1532 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1534 /* CallBackTime could not be 0 */
1535 if (CallBackTime == 0) {
1536 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1537 CallBack->ExpirationTime = 0;
1539 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1540 CallBack->CallBackVersion = CALLBACK_VERSION;
1541 CallBack->CallBackType = CB_SHARED; /* The default for now */
1543 } /*SetCallBackStruct */
1547 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1548 * allocation; if some error occured (exceeded volume quota or partition
1549 * was full, or whatever), it frees the space back and returns the code.
1550 * We usually pre-adjust the volume space to make sure that there's
1551 * enough space before consuming some.
1554 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1555 afs_sfsize_t checkLength)
1560 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1562 VAdjustDiskUsage(&nc, volptr, -length, 0);
1563 if (rc == VOVERQUOTA) {
1565 ("Volume %u (%s) is full\n", V_id(volptr),
1569 if (rc == VDISKFULL) {
1571 ("Partition %s that contains volume %u is full\n",
1572 volptr->partition->name, V_id(volptr)));
1575 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1580 } /*AdjustDiskUsage */
1583 * Common code that handles the creation of a new file (SAFS_CreateFile and
1584 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1587 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1588 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1589 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1591 int errorCode = 0; /* Error code returned back */
1594 Inode nearInode; /* hint for inode allocation in solaris */
1597 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1598 BlocksPreallocatedForVnode))) {
1600 ("Insufficient space to allocate %lld blocks\n",
1601 (afs_intmax_t) BlocksPreallocatedForVnode));
1605 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1606 if (errorCode != 0) {
1607 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1610 OutFid->Volume = V_id(volptr);
1611 OutFid->Vnode = (*targetptr)->vnodeNumber;
1612 OutFid->Unique = (*targetptr)->disk.uniquifier;
1614 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1616 /* create the inode now itself */
1618 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1619 VPartitionPath(V_partition(volptr)), nearInode,
1620 V_id(volptr), (*targetptr)->vnodeNumber,
1621 (*targetptr)->disk.uniquifier, 1);
1623 /* error in creating inode */
1624 if (!VALID_INO(inode)) {
1626 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1627 (*targetptr)->volumePtr->header->diskstuff.id,
1628 (*targetptr)->vnodeNumber, errno));
1629 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1630 (*targetptr)->delete = 1; /* delete vnode */
1633 VN_SET_INO(*targetptr, inode);
1634 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1636 /* copy group from parent dir */
1637 (*targetptr)->disk.group = parentptr->disk.group;
1639 if (parentptr->disk.cloned) {
1640 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1641 if ((errorCode = CopyOnWrite(parentptr, volptr))) { /* disk full */
1642 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1643 /* delete the vnode previously allocated */
1644 (*targetptr)->delete = 1;
1645 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1646 IH_REALLYCLOSE((*targetptr)->handle);
1647 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1649 ("Alloc_NewVnode: partition %s idec %s failed\n",
1650 volptr->partition->name, PrintInode(NULL, inode)));
1651 IH_RELEASE((*targetptr)->handle);
1657 /* add the name to the directory */
1658 SetDirHandle(dir, parentptr);
1659 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1660 (*targetptr)->delete = 1;
1661 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1662 IH_REALLYCLOSE((*targetptr)->handle);
1663 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1665 ("Alloc_NewVnode: partition %s idec %s failed\n",
1666 volptr->partition->name, PrintInode(NULL, inode)));
1667 IH_RELEASE((*targetptr)->handle);
1673 } /*Alloc_NewVnode */
1677 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1681 HandleLocking(Vnode * targetptr, afs_int32 rights, ViceLockType LockingType)
1683 int Time; /* Used for time */
1684 int writeVnode = targetptr->changed_oldTime; /* save original status */
1686 /* Does the caller has Lock priviledges; root extends locks, however */
1687 if (LockingType != LockExtend && !(rights & PRSFS_LOCK))
1689 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1690 Time = FT_ApproxTime();
1691 switch (LockingType) {
1694 if (Time > targetptr->disk.lock.lockTime)
1695 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1697 Time += AFS_LOCKWAIT;
1698 if (LockingType == LockRead) {
1699 if (targetptr->disk.lock.lockCount >= 0) {
1700 ++(targetptr->disk.lock.lockCount);
1701 targetptr->disk.lock.lockTime = Time;
1705 if (targetptr->disk.lock.lockCount == 0) {
1706 targetptr->disk.lock.lockCount = -1;
1707 targetptr->disk.lock.lockTime = Time;
1713 Time += AFS_LOCKWAIT;
1714 if (targetptr->disk.lock.lockCount != 0)
1715 targetptr->disk.lock.lockTime = Time;
1720 if ((--targetptr->disk.lock.lockCount) <= 0)
1721 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1725 targetptr->changed_oldTime = writeVnode; /* restore old status */
1726 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1729 } /*HandleLocking */
1731 /* 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. */
1734 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1738 if (!(rights & Prfs_Mode))
1740 if ((targetptr->disk.type != vDirectory)
1741 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1747 * If some flags (i.e. min or max quota) are set, the volume's in disk
1748 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1749 * update, if applicable.
1752 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1753 char *Name, char *OfflineMsg, char *Motd)
1755 Error errorCode = 0;
1757 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1758 V_minquota(volptr) = StoreVolStatus->MinQuota;
1759 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1760 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1761 if (strlen(OfflineMsg) > 0) {
1762 strcpy(V_offlineMessage(volptr), OfflineMsg);
1764 if (strlen(Name) > 0) {
1765 strcpy(V_name(volptr), Name);
1767 #if OPENAFS_VOL_STATS
1769 * We don't overwrite the motd field, since it's now being used
1773 if (strlen(Motd) > 0) {
1774 strcpy(V_motd(volptr), Motd);
1776 #endif /* FS_STATS_DETAILED */
1777 VUpdateVolume(&errorCode, volptr);
1780 } /*RXUpdate_VolumeStatus */
1785 Update_VolumeStatus(Volume * volptr, VolumeStatus * StoreVolStatus,
1786 struct BBS *Name, struct BBS *OfflineMsg,
1789 Error errorCode = 0;
1791 if (StoreVolStatus->MinQuota > -1)
1792 V_minquota(volptr) = StoreVolStatus->MinQuota;
1793 if (StoreVolStatus->MaxQuota > -1)
1794 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1795 if (OfflineMsg->SeqLen > 1)
1796 strcpy(V_offlineMessage(volptr), OfflineMsg->SeqBody);
1797 if (Name->SeqLen > 1)
1798 strcpy(V_name(volptr), Name->SeqBody);
1799 #if OPENAFS_VOL_STATS
1801 * We don't overwrite the motd field, since it's now being used
1805 if (Motd->SeqLen > 1)
1806 strcpy(V_motd(volptr), Motd->SeqBody);
1807 #endif /* FS_STATS_DETAILED */
1808 VUpdateVolume(&errorCode, volptr);
1811 } /*Update_VolumeStatus */
1815 * Get internal volume-related statistics from the Volume disk label
1816 * structure and put it into the VolumeStatus structure, status; it's
1817 * used by both SAFS_GetVolumeStatus and SAFS_SetVolumeStatus to return
1818 * the volume status to the caller.
1821 GetVolumeStatus(VolumeStatus * status, struct BBS *name, struct BBS *offMsg,
1822 struct BBS *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;
1839 strncpy(name->SeqBody, V_name(volptr), (int)name->MaxSeqLen);
1840 name->SeqLen = strlen(V_name(volptr)) + 1;
1841 if (name->SeqLen > name->MaxSeqLen)
1842 name->SeqLen = name->MaxSeqLen;
1843 strncpy(offMsg->SeqBody, V_offlineMessage(volptr), (int)name->MaxSeqLen);
1844 offMsg->SeqLen = strlen(V_offlineMessage(volptr)) + 1;
1845 if (offMsg->SeqLen > offMsg->MaxSeqLen)
1846 offMsg->SeqLen = offMsg->MaxSeqLen;
1848 /*Don't do anything with the motd field */
1849 strncpy(motd->SeqBody, nullString, (int)offMsg->MaxSeqLen);
1850 motd->SeqLen = strlen(nullString) + 1;
1852 if (motd->SeqLen > motd->MaxSeqLen)
1853 motd->SeqLen = motd->MaxSeqLen;
1855 } /*GetVolumeStatus */
1858 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1859 char **motd, Volume * volptr)
1863 status->Vid = V_id(volptr);
1864 status->ParentId = V_parentId(volptr);
1865 status->Online = V_inUse(volptr);
1866 status->InService = V_inService(volptr);
1867 status->Blessed = V_blessed(volptr);
1868 status->NeedsSalvage = V_needsSalvaged(volptr);
1869 if (VolumeWriteable(volptr))
1870 status->Type = ReadWrite;
1872 status->Type = ReadOnly;
1873 status->MinQuota = V_minquota(volptr);
1874 status->MaxQuota = V_maxquota(volptr);
1875 status->BlocksInUse = V_diskused(volptr);
1876 status->PartBlocksAvail = volptr->partition->free;
1877 status->PartMaxBlocks = volptr->partition->totalUsable;
1879 /* now allocate and copy these things; they're freed by the RXGEN stub */
1880 temp = strlen(V_name(volptr)) + 1;
1881 *name = malloc(temp);
1883 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1886 strcpy(*name, V_name(volptr));
1887 temp = strlen(V_offlineMessage(volptr)) + 1;
1888 *offMsg = malloc(temp);
1890 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1893 strcpy(*offMsg, V_offlineMessage(volptr));
1894 #if OPENAFS_VOL_STATS
1897 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1900 strcpy(*motd, nullString);
1902 temp = strlen(V_motd(volptr)) + 1;
1903 *motd = malloc(temp);
1905 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1908 strcpy(*motd, V_motd(volptr));
1909 #endif /* FS_STATS_DETAILED */
1911 } /*RXGetVolumeStatus */
1915 FileNameOK(register char *aname)
1917 register afs_int32 i, tc;
1920 /* watch for @sys on the right */
1921 if (strcmp(aname + i - 4, "@sys") == 0)
1924 while ((tc = *aname++)) {
1926 return 0; /* very bad character to encounter */
1928 return 1; /* file name is ok */
1933 /* Debugging tool to print Volume Statu's contents */
1935 PrintVolumeStatus(VolumeStatus * status)
1937 ViceLog(5, ("Volume header contains:\n"));
1939 ("Vid = %u, Parent = %u, Online = %d, InService = %d, Blessed = %d, NeedsSalvage = %d\n",
1940 status->Vid, status->ParentId, status->Online, status->InService,
1941 status->Blessed, status->NeedsSalvage));
1943 ("MinQuota = %d, MaxQuota = %d\n", status->MinQuota,
1946 ("Type = %d, BlocksInUse = %d, PartBlocksAvail = %d, PartMaxBlocks = %d\n",
1947 status->Type, status->BlocksInUse, status->PartBlocksAvail,
1948 status->PartMaxBlocks));
1950 } /*PrintVolumeStatus */
1954 * This variant of symlink is expressly to support the AFS/DFS translator
1955 * and is not supported by the AFS fileserver. We just return EINVAL.
1956 * The cache manager should not generate this call to an AFS cache manager.
1959 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1960 char *LinkContents, struct AFSStoreStatus *InStatus,
1961 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1962 struct AFSFetchStatus *OutDirStatus,
1963 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1969 SRXAFS_ResidencyCmd(struct rx_call * acall, struct AFSFid * Fid,
1970 struct ResidencyCmdInputs * Inputs,
1971 struct ResidencyCmdOutputs * Outputs)
1976 static struct afs_buffer {
1977 struct afs_buffer *next;
1978 } *freeBufferList = 0;
1979 static int afs_buffersAlloced = 0;
1982 FreeSendBuffer(register struct afs_buffer *adata)
1985 afs_buffersAlloced--;
1986 adata->next = freeBufferList;
1987 freeBufferList = adata;
1991 } /*FreeSendBuffer */
1993 /* allocate space for sender */
1997 register struct afs_buffer *tp;
2000 afs_buffersAlloced++;
2001 if (!freeBufferList) {
2004 tmp = malloc(sendBufSize);
2006 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2011 tp = freeBufferList;
2012 freeBufferList = tp->next;
2016 } /*AllocSendBuffer */
2019 * This routine returns the status info associated with the targetptr vnode
2020 * in the AFSFetchStatus structure. Some of the newer fields, such as
2021 * SegSize and Group are not yet implemented
2025 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2026 afs_int32 anyrights, Vnode * parentptr)
2028 /* initialize return status from a vnode */
2029 status->InterfaceVersion = 1;
2030 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2031 status->errorCode = 0;
2032 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2033 if (targetptr->disk.type == vFile)
2034 status->FileType = File;
2035 else if (targetptr->disk.type == vDirectory)
2036 status->FileType = Directory;
2037 else if (targetptr->disk.type == vSymlink)
2038 status->FileType = SymbolicLink;
2040 status->FileType = Invalid; /*invalid type field */
2041 status->LinkCount = targetptr->disk.linkCount;
2043 afs_fsize_t targetLen;
2044 VN_GET_LEN(targetLen, targetptr);
2045 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2047 status->DataVersion = targetptr->disk.dataVersion;
2048 status->Author = targetptr->disk.author;
2049 status->Owner = targetptr->disk.owner;
2050 status->CallerAccess = rights;
2051 status->AnonymousAccess = anyrights;
2052 status->UnixModeBits = targetptr->disk.modeBits;
2053 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2054 status->ParentVnode =
2055 (status->FileType ==
2056 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2057 status->ParentUnique =
2058 (status->FileType ==
2059 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2060 status->ServerModTime = targetptr->disk.serverModifyTime;
2061 status->Group = targetptr->disk.group;
2062 status->lockCount = targetptr->disk.lock.lockCount;
2063 status->errorCode = 0;
2069 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2070 afs_sfsize_t Pos, afs_sfsize_t Len,
2071 struct AFSFetchStatus *OutStatus,
2072 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2075 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2076 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2077 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2078 int errorCode = 0; /* return code to caller */
2079 int fileCode = 0; /* return code from vol package */
2080 Volume *volptr = 0; /* pointer to the volume */
2081 struct client *client; /* pointer to the client data */
2082 struct rx_connection *tcon; /* the connection we're part of */
2083 afs_int32 rights, anyrights; /* rights for this and any user */
2084 struct client *t_client; /* tmp ptr to client data */
2085 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2086 #if FS_STATS_DETAILED
2087 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2088 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2089 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2090 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2091 struct timeval elapsedTime; /* Transfer time */
2092 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2093 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2094 int readIdx; /* Index of read stats array to bump */
2095 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2098 * Set our stats pointers, remember when the RPC operation started, and
2099 * tally the operation.
2101 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2102 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2106 TM_GetTimeOfDay(&opStartTime, 0);
2107 #endif /* FS_STATS_DETAILED */
2110 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2113 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2115 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2118 /* Get ptr to client data for user Id for logging */
2119 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2120 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2122 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s, Id %d\n",
2123 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2126 * Get volume/vnode for the fetched file; caller's access rights to
2127 * it are also returned
2130 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2131 &parentwhentargetnotdir, &client, READ_LOCK,
2132 &rights, &anyrights)))
2135 SetVolumeSync(Sync, volptr);
2137 #if FS_STATS_DETAILED
2139 * Remember that another read operation was performed.
2142 if (client->InSameNetwork)
2143 readIdx = VOL_STATS_SAME_NET;
2145 readIdx = VOL_STATS_DIFF_NET;
2146 V_stat_reads(volptr, readIdx)++;
2147 if (client->ViceId != AnonymousID) {
2148 V_stat_reads(volptr, readIdx + 1)++;
2151 #endif /* FS_STATS_DETAILED */
2152 /* Check whether the caller has permission access to fetch the data */
2154 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2158 * Drop the read lock on the parent directory after saving the parent
2159 * vnode information we need to pass to GetStatus
2161 if (parentwhentargetnotdir != NULL) {
2162 tparentwhentargetnotdir = *parentwhentargetnotdir;
2163 VPutVnode(&fileCode, parentwhentargetnotdir);
2164 assert(!fileCode || (fileCode == VSALVAGE));
2165 parentwhentargetnotdir = NULL;
2167 #if FS_STATS_DETAILED
2169 * Remember when the data transfer started.
2171 TM_GetTimeOfDay(&xferStartTime, 0);
2172 #endif /* FS_STATS_DETAILED */
2174 /* actually do the data transfer */
2175 #if FS_STATS_DETAILED
2177 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2178 &bytesToXfer, &bytesXferred);
2181 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2183 #endif /* FS_STATS_DETAILED */
2185 #if FS_STATS_DETAILED
2187 * At this point, the data transfer is done, for good or ill. Remember
2188 * when the transfer ended, bump the number of successes/failures, and
2189 * integrate the transfer size and elapsed time into the stats. If the
2190 * operation failed, we jump to the appropriate point.
2192 TM_GetTimeOfDay(&xferStopTime, 0);
2194 (xferP->numXfers)++;
2196 (xferP->numSuccesses)++;
2199 * Bump the xfer sum by the number of bytes actually sent, NOT the
2202 tot_bytesXferred += bytesXferred;
2203 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2204 tot_bytesXferred &= 0x3FF;
2205 if (bytesXferred < xferP->minBytes)
2206 xferP->minBytes = bytesXferred;
2207 if (bytesXferred > xferP->maxBytes)
2208 xferP->maxBytes = bytesXferred;
2211 * Tally the size of the object. Note: we tally the actual size,
2212 * NOT the number of bytes that made it out over the wire.
2214 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2215 (xferP->count[0])++;
2216 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2217 (xferP->count[1])++;
2218 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2219 (xferP->count[2])++;
2220 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2221 (xferP->count[3])++;
2222 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2223 (xferP->count[4])++;
2224 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2225 (xferP->count[5])++;
2226 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2227 (xferP->count[6])++;
2228 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2229 (xferP->count[7])++;
2231 (xferP->count[8])++;
2233 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2234 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2235 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2236 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2237 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2239 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2240 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2245 * Finally, go off to tell our caller the bad news in case the
2250 #endif /* FS_STATS_DETAILED */
2252 /* write back the OutStatus from the target vnode */
2253 GetStatus(targetptr, OutStatus, rights, anyrights,
2254 &tparentwhentargetnotdir);
2256 /* if a r/w volume, promise a callback to the caller */
2257 if (VolumeWriteable(volptr))
2258 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2260 struct AFSFid myFid;
2261 memset(&myFid, 0, sizeof(struct AFSFid));
2262 myFid.Volume = Fid->Volume;
2263 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2267 /* Update and store volume/vnode and parent vnodes back */
2268 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2270 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2271 errorCode = CallPostamble(tcon, errorCode);
2273 #if FS_STATS_DETAILED
2274 TM_GetTimeOfDay(&opStopTime, 0);
2275 if (errorCode == 0) {
2277 (opP->numSuccesses)++;
2278 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2279 fs_stats_AddTo((opP->sumTime), elapsedTime);
2280 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2281 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2282 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2284 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2285 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2289 #endif /* FS_STATS_DETAILED */
2291 osi_auditU(acall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
2294 } /*SRXAFS_FetchData */
2297 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2298 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2299 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2304 common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack, Sync,
2310 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2311 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2312 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2315 afs_sfsize_t tPos, tLen;
2317 #ifdef AFS_64BIT_ENV
2318 #ifndef AFS_LARGEFILE_ENV
2319 if (Pos + Len > 0x7fffffff)
2321 #endif /* !AFS_LARGEFILE_ENV */
2322 tPos = (afs_sfsize_t) Pos;
2323 tLen = (afs_sfsize_t) Len;
2324 #else /* AFS_64BIT_ENV */
2325 if (Pos.high || Len.high)
2329 #endif /* AFS_64BIT_ENV */
2332 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2338 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2339 struct AFSOpaque * AccessList,
2340 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2342 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2343 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2344 int errorCode = 0; /* return error code to caller */
2345 Volume *volptr = 0; /* pointer to the volume */
2346 struct client *client; /* pointer to the client data */
2347 afs_int32 rights, anyrights; /* rights for this and any user */
2348 struct rx_connection *tcon = rx_ConnectionOf(acall);
2349 struct client *t_client; /* tmp ptr to client data */
2350 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2351 #if FS_STATS_DETAILED
2352 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2353 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2354 struct timeval elapsedTime; /* Transfer time */
2357 * Set our stats pointer, remember when the RPC operation started, and
2358 * tally the operation.
2360 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2364 TM_GetTimeOfDay(&opStartTime, 0);
2365 #endif /* FS_STATS_DETAILED */
2368 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2371 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2373 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2376 /* Get ptr to client data for user Id for logging */
2377 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2378 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2380 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s, Id %d\n", Fid->Volume,
2381 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2384 AccessList->AFSOpaque_len = 0;
2385 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2386 if (!AccessList->AFSOpaque_val) {
2387 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2392 * Get volume/vnode for the fetched file; caller's access rights to it
2396 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2397 &parentwhentargetnotdir, &client, READ_LOCK,
2398 &rights, &anyrights)))
2401 SetVolumeSync(Sync, volptr);
2403 /* Check whether we have permission to fetch the ACL */
2405 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2408 /* Get the Access List from the dir's vnode */
2410 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2413 /* Get OutStatus back From the target Vnode */
2414 GetStatus(targetptr, OutStatus, rights, anyrights,
2415 parentwhentargetnotdir);
2418 /* Update and store volume/vnode and parent vnodes back */
2419 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2422 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2423 AccessList->AFSOpaque_val));
2424 errorCode = CallPostamble(tcon, errorCode);
2426 #if FS_STATS_DETAILED
2427 TM_GetTimeOfDay(&opStopTime, 0);
2428 if (errorCode == 0) {
2430 (opP->numSuccesses)++;
2431 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2432 fs_stats_AddTo((opP->sumTime), elapsedTime);
2433 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2434 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2435 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2437 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2438 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2442 #endif /* FS_STATS_DETAILED */
2444 osi_auditU(acall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
2446 } /*SRXAFS_FetchACL */
2450 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2451 * merged into it when possible.
2455 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2456 struct AFSFetchStatus *OutStatus,
2457 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2459 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2460 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2461 int errorCode = 0; /* return code to caller */
2462 Volume *volptr = 0; /* pointer to the volume */
2463 struct client *client; /* pointer to the client data */
2464 afs_int32 rights, anyrights; /* rights for this and any user */
2465 struct client *t_client; /* tmp ptr to client data */
2466 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2467 struct rx_connection *tcon = rx_ConnectionOf(acall);
2469 /* Get ptr to client data for user Id for logging */
2470 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2471 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2473 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s, Id %d\n",
2474 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2477 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2480 * Get volume/vnode for the fetched file; caller's rights to it are
2484 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2485 &parentwhentargetnotdir, &client, READ_LOCK,
2486 &rights, &anyrights)))
2487 goto Bad_FetchStatus;
2489 /* set volume synchronization information */
2490 SetVolumeSync(Sync, volptr);
2492 /* Are we allowed to fetch Fid's status? */
2493 if (targetptr->disk.type != vDirectory) {
2495 Check_PermissionRights(targetptr, client, rights,
2496 CHK_FETCHSTATUS, 0))) {
2497 if (rx_GetCallAbortCode(acall) == errorCode)
2498 rx_SetCallAbortCode(acall, 0);
2499 goto Bad_FetchStatus;
2503 /* set OutStatus From the Fid */
2504 GetStatus(targetptr, OutStatus, rights, anyrights,
2505 parentwhentargetnotdir);
2507 /* If a r/w volume, also set the CallBack state */
2508 if (VolumeWriteable(volptr))
2509 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2511 struct AFSFid myFid;
2512 memset(&myFid, 0, sizeof(struct AFSFid));
2513 myFid.Volume = Fid->Volume;
2514 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2518 /* Update and store volume/vnode and parent vnodes back */
2519 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2521 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2524 } /*SAFSS_FetchStatus */
2528 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2529 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2530 struct AFSVolSync * Sync)
2534 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2535 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2536 int errorCode = 0; /* return code to caller */
2537 Volume *volptr = 0; /* pointer to the volume */
2538 struct client *client; /* pointer to the client data */
2539 afs_int32 rights, anyrights; /* rights for this and any user */
2540 register struct AFSFid *tfid; /* file id we're dealing with now */
2541 struct rx_connection *tcon = rx_ConnectionOf(acall);
2542 #if FS_STATS_DETAILED
2543 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2544 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2545 struct timeval elapsedTime; /* Transfer time */
2548 * Set our stats pointer, remember when the RPC operation started, and
2549 * tally the operation.
2551 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2555 TM_GetTimeOfDay(&opStartTime, 0);
2556 #endif /* FS_STATS_DETAILED */
2558 ViceLog(1, ("SAFS_BulkStatus\n"));
2560 AFSCallStats.TotalCalls++;
2562 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2563 if (nfiles <= 0) { /* Sanity check */
2565 goto Audit_and_Return;
2568 /* allocate space for return output parameters */
2569 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2570 malloc(nfiles * sizeof(struct AFSFetchStatus));
2571 if (!OutStats->AFSBulkStats_val) {
2572 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2575 OutStats->AFSBulkStats_len = nfiles;
2576 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2577 malloc(nfiles * sizeof(struct AFSCallBack));
2578 if (!CallBacks->AFSCBs_val) {
2579 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2582 CallBacks->AFSCBs_len = nfiles;
2584 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2585 goto Bad_BulkStatus;
2587 tfid = Fids->AFSCBFids_val;
2588 for (i = 0; i < nfiles; i++, tfid++) {
2590 * Get volume/vnode for the fetched file; caller's rights to it
2594 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2595 &parentwhentargetnotdir, &client, READ_LOCK,
2596 &rights, &anyrights)))
2597 goto Bad_BulkStatus;
2598 /* set volume synchronization information, but only once per call */
2600 SetVolumeSync(Sync, volptr);
2602 /* Are we allowed to fetch Fid's status? */
2603 if (targetptr->disk.type != vDirectory) {
2605 Check_PermissionRights(targetptr, client, rights,
2606 CHK_FETCHSTATUS, 0))) {
2607 if (rx_GetCallAbortCode(acall) == errorCode)
2608 rx_SetCallAbortCode(acall, 0);
2609 goto Bad_BulkStatus;
2613 /* set OutStatus From the Fid */
2614 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2615 anyrights, parentwhentargetnotdir);
2617 /* If a r/w volume, also set the CallBack state */
2618 if (VolumeWriteable(volptr))
2619 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2620 &CallBacks->AFSCBs_val[i]);
2622 struct AFSFid myFid;
2623 memset(&myFid, 0, sizeof(struct AFSFid));
2624 myFid.Volume = tfid->Volume;
2625 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2626 &CallBacks->AFSCBs_val[i]);
2629 /* put back the file ID and volume */
2630 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2632 parentwhentargetnotdir = (Vnode *) 0;
2633 targetptr = (Vnode *) 0;
2634 volptr = (Volume *) 0;
2638 /* Update and store volume/vnode and parent vnodes back */
2639 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2641 errorCode = CallPostamble(tcon, errorCode);
2643 #if FS_STATS_DETAILED
2644 TM_GetTimeOfDay(&opStopTime, 0);
2645 if (errorCode == 0) {
2647 (opP->numSuccesses)++;
2648 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2649 fs_stats_AddTo((opP->sumTime), elapsedTime);
2650 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2651 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2652 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2654 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2655 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2659 #endif /* FS_STATS_DETAILED */
2662 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2663 osi_auditU(acall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids,
2667 } /*SRXAFS_BulkStatus */
2671 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2672 struct AFSBulkStats * OutStats,
2673 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2677 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2678 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2679 int errorCode = 0; /* return code to caller */
2680 Volume *volptr = 0; /* pointer to the volume */
2681 struct client *client; /* pointer to the client data */
2682 afs_int32 rights, anyrights; /* rights for this and any user */
2683 register struct AFSFid *tfid; /* file id we're dealing with now */
2684 struct rx_connection *tcon;
2685 AFSFetchStatus *tstatus;
2686 #if FS_STATS_DETAILED
2687 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2688 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2689 struct timeval elapsedTime; /* Transfer time */
2692 * Set our stats pointer, remember when the RPC operation started, and
2693 * tally the operation.
2695 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2699 TM_GetTimeOfDay(&opStartTime, 0);
2700 #endif /* FS_STATS_DETAILED */
2702 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2704 AFSCallStats.TotalCalls++;
2706 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2707 if (nfiles <= 0) { /* Sanity check */
2709 goto Audit_and_Return;
2712 /* allocate space for return output parameters */
2713 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2714 malloc(nfiles * sizeof(struct AFSFetchStatus));
2715 if (!OutStats->AFSBulkStats_val) {
2716 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2719 OutStats->AFSBulkStats_len = nfiles;
2720 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2721 malloc(nfiles * sizeof(struct AFSCallBack));
2722 if (!CallBacks->AFSCBs_val) {
2723 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2726 CallBacks->AFSCBs_len = nfiles;
2728 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) {
2729 goto Bad_InlineBulkStatus;
2732 tfid = Fids->AFSCBFids_val;
2733 for (i = 0; i < nfiles; i++, tfid++) {
2735 * Get volume/vnode for the fetched file; caller's rights to it
2739 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2740 &parentwhentargetnotdir, &client, READ_LOCK,
2741 &rights, &anyrights))) {
2742 tstatus = &OutStats->AFSBulkStats_val[i];
2743 tstatus->errorCode = errorCode;
2744 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2745 parentwhentargetnotdir = (Vnode *) 0;
2746 targetptr = (Vnode *) 0;
2747 volptr = (Volume *) 0;
2751 /* set volume synchronization information, but only once per call */
2753 SetVolumeSync(Sync, volptr);
2755 /* Are we allowed to fetch Fid's status? */
2756 if (targetptr->disk.type != vDirectory) {
2758 Check_PermissionRights(targetptr, client, rights,
2759 CHK_FETCHSTATUS, 0))) {
2760 tstatus = &OutStats->AFSBulkStats_val[i];
2761 tstatus->errorCode = errorCode;
2762 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2763 (Vnode *) 0, volptr);
2764 parentwhentargetnotdir = (Vnode *) 0;
2765 targetptr = (Vnode *) 0;
2766 volptr = (Volume *) 0;
2771 /* set OutStatus From the Fid */
2772 GetStatus(targetptr,
2773 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2774 rights, anyrights, parentwhentargetnotdir);
2776 /* If a r/w volume, also set the CallBack state */
2777 if (VolumeWriteable(volptr))
2778 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2779 &CallBacks->AFSCBs_val[i]);
2781 struct AFSFid myFid;
2782 memset(&myFid, 0, sizeof(struct AFSFid));
2783 myFid.Volume = tfid->Volume;
2784 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2785 &CallBacks->AFSCBs_val[i]);
2788 /* put back the file ID and volume */
2789 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2791 parentwhentargetnotdir = (Vnode *) 0;
2792 targetptr = (Vnode *) 0;
2793 volptr = (Volume *) 0;
2796 Bad_InlineBulkStatus:
2797 /* Update and store volume/vnode and parent vnodes back */
2798 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2800 errorCode = CallPostamble(tcon, errorCode);
2802 #if FS_STATS_DETAILED
2803 TM_GetTimeOfDay(&opStopTime, 0);
2804 if (errorCode == 0) {
2806 (opP->numSuccesses)++;
2807 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2808 fs_stats_AddTo((opP->sumTime), elapsedTime);
2809 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2810 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2811 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2813 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2814 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2818 #endif /* FS_STATS_DETAILED */
2821 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2822 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode, AUD_FIDS, Fids,
2826 } /*SRXAFS_InlineBulkStatus */
2830 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2831 struct AFSFetchStatus * OutStatus,
2832 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2835 struct rx_connection *tcon;
2836 #if FS_STATS_DETAILED
2837 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2838 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2839 struct timeval elapsedTime; /* Transfer time */
2842 * Set our stats pointer, remember when the RPC operation started, and
2843 * tally the operation.
2845 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2849 TM_GetTimeOfDay(&opStartTime, 0);
2850 #endif /* FS_STATS_DETAILED */
2852 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
2853 goto Bad_FetchStatus;
2855 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2858 code = CallPostamble(tcon, code);
2860 #if FS_STATS_DETAILED
2861 TM_GetTimeOfDay(&opStopTime, 0);
2864 (opP->numSuccesses)++;
2865 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2866 fs_stats_AddTo((opP->sumTime), elapsedTime);
2867 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2868 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2869 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2871 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2872 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2876 #endif /* FS_STATS_DETAILED */
2878 osi_auditU(acall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
2881 } /*SRXAFS_FetchStatus */
2885 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2886 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2887 afs_fsize_t Length, afs_fsize_t FileLength,
2888 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2890 Vnode *targetptr = 0; /* pointer to input fid */
2891 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2892 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2893 int errorCode = 0; /* return code for caller */
2894 int fileCode = 0; /* return code from vol package */
2895 Volume *volptr = 0; /* pointer to the volume header */
2896 struct client *client; /* pointer to client structure */
2897 afs_int32 rights, anyrights; /* rights for this and any user */
2898 struct client *t_client; /* tmp ptr to client data */
2899 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2900 struct rx_connection *tcon;
2901 #if FS_STATS_DETAILED
2902 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2903 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2904 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2905 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2906 struct timeval elapsedTime; /* Transfer time */
2907 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2908 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2909 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2912 * Set our stats pointers, remember when the RPC operation started, and
2913 * tally the operation.
2915 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2916 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2921 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2923 TM_GetTimeOfDay(&opStartTime, 0);
2924 #endif /* FS_STATS_DETAILED */
2927 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2929 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2932 /* Get ptr to client data for user Id for logging */
2933 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2934 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2936 ("StoreData: Fid = %u.%u.%u, Host %s, Id %d\n", Fid->Volume,
2937 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2941 * Get associated volume/vnode for the stored file; caller's rights
2945 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2946 &parentwhentargetnotdir, &client, WRITE_LOCK,
2947 &rights, &anyrights))) {
2951 /* set volume synchronization information */
2952 SetVolumeSync(Sync, volptr);
2954 if ((targetptr->disk.type == vSymlink)) {
2955 /* Should we return a better error code here??? */
2960 /* Check if we're allowed to store the data */
2962 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2968 * Drop the read lock on the parent directory after saving the parent
2969 * vnode information we need to pass to GetStatus
2971 if (parentwhentargetnotdir != NULL) {
2972 tparentwhentargetnotdir = *parentwhentargetnotdir;
2973 VPutVnode(&fileCode, parentwhentargetnotdir);
2974 assert(!fileCode || (fileCode == VSALVAGE));
2975 parentwhentargetnotdir = NULL;
2977 #if FS_STATS_DETAILED
2979 * Remember when the data transfer started.
2981 TM_GetTimeOfDay(&xferStartTime, 0);
2982 #endif /* FS_STATS_DETAILED */
2984 /* Do the actual storing of the data */
2985 #if FS_STATS_DETAILED
2987 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2988 FileLength, (InStatus->Mask & AFS_FSYNC),
2989 &bytesToXfer, &bytesXferred);
2992 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2993 FileLength, (InStatus->Mask & AFS_FSYNC));
2994 if (errorCode && (!targetptr->changed_newTime))
2996 #endif /* FS_STATS_DETAILED */
2997 #if FS_STATS_DETAILED
2999 * At this point, the data transfer is done, for good or ill. Remember
3000 * when the transfer ended, bump the number of successes/failures, and
3001 * integrate the transfer size and elapsed time into the stats. If the
3002 * operation failed, we jump to the appropriate point.
3004 TM_GetTimeOfDay(&xferStopTime, 0);
3006 (xferP->numXfers)++;
3008 (xferP->numSuccesses)++;
3011 * Bump the xfer sum by the number of bytes actually sent, NOT the
3014 tot_bytesXferred += bytesXferred;
3015 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3016 tot_bytesXferred &= 0x3FF;
3017 if (bytesXferred < xferP->minBytes)
3018 xferP->minBytes = bytesXferred;
3019 if (bytesXferred > xferP->maxBytes)
3020 xferP->maxBytes = bytesXferred;
3023 * Tally the size of the object. Note: we tally the actual size,
3024 * NOT the number of bytes that made it out over the wire.
3026 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3027 (xferP->count[0])++;
3028 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3029 (xferP->count[1])++;
3030 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3031 (xferP->count[2])++;
3032 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3033 (xferP->count[3])++;
3034 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3035 (xferP->count[4])++;
3036 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3037 (xferP->count[5])++;
3038 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3039 (xferP->count[6])++;
3040 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3041 (xferP->count[7])++;
3043 (xferP->count[8])++;
3045 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3046 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3047 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3048 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3049 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3051 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3052 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3057 * Finally, go off to tell our caller the bad news in case the
3060 if (errorCode && (!targetptr->changed_newTime))
3062 #endif /* FS_STATS_DETAILED */
3064 /* Update the status of the target's vnode */
3065 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3066 targetptr, volptr, 0);
3068 /* Get the updated File's status back to the caller */
3069 GetStatus(targetptr, OutStatus, rights, anyrights,
3070 &tparentwhentargetnotdir);
3073 /* Update and store volume/vnode and parent vnodes back */
3074 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3076 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3078 errorCode = CallPostamble(tcon, errorCode);
3080 #if FS_STATS_DETAILED
3081 TM_GetTimeOfDay(&opStopTime, 0);
3082 if (errorCode == 0) {
3084 (opP->numSuccesses)++;
3085 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3086 fs_stats_AddTo((opP->sumTime), elapsedTime);
3087 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3088 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3089 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3091 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3092 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3096 #endif /* FS_STATS_DETAILED */
3098 osi_auditU(acall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
3101 } /*common_StoreData64 */
3104 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3105 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3106 afs_uint32 Length, afs_uint32 FileLength,
3107 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3112 common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3116 } /*SRXAFS_StoreData */
3119 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3120 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3121 afs_uint64 Length, afs_uint64 FileLength,
3122 struct AFSFetchStatus * OutStatus,
3123 struct AFSVolSync * Sync)
3127 afs_fsize_t tLength;
3128 afs_fsize_t tFileLength;
3130 #ifdef AFS_64BIT_ENV
3131 #ifndef AFS_LARGEFILE_ENV
3132 if (FileLength > 0x7fffffff)
3134 #endif /* !AFS_LARGEFILE_ENV */
3135 tPos = (afs_fsize_t) Pos;
3136 tLength = (afs_fsize_t) Length;
3137 tFileLength = (afs_fsize_t) FileLength;
3138 #else /* AFS_64BIT_ENV */
3139 if (FileLength.high)
3142 tLength = Length.low;
3143 tFileLength = FileLength.low;
3144 #endif /* AFS_64BIT_ENV */
3147 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3153 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3154 struct AFSOpaque * AccessList,
3155 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3157 Vnode *targetptr = 0; /* pointer to input fid */
3158 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3159 int errorCode = 0; /* return code for caller */
3160 struct AFSStoreStatus InStatus; /* Input status for fid */
3161 Volume *volptr = 0; /* pointer to the volume header */
3162 struct client *client; /* pointer to client structure */
3163 afs_int32 rights, anyrights; /* rights for this and any user */
3164 struct rx_connection *tcon;
3165 struct client *t_client; /* tmp ptr to client data */
3166 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3167 #if FS_STATS_DETAILED
3168 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3169 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3170 struct timeval elapsedTime; /* Transfer time */
3173 * Set our stats pointer, remember when the RPC operation started, and
3174 * tally the operation.
3176 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3180 TM_GetTimeOfDay(&opStartTime, 0);
3181 #endif /* FS_STATS_DETAILED */
3182 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
3185 /* Get ptr to client data for user Id for logging */
3186 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3187 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3189 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s, Id %d\n",
3190 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3191 inet_ntoa(logHostAddr), t_client->ViceId));
3193 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3195 InStatus.Mask = 0; /* not storing any status */
3198 * Get associated volume/vnode for the target dir; caller's rights
3199 * are also returned.
3202 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3203 &parentwhentargetnotdir, &client, WRITE_LOCK,
3204 &rights, &anyrights))) {
3208 /* set volume synchronization information */
3209 SetVolumeSync(Sync, volptr);
3211 /* Check if we have permission to change the dir's ACL */
3213 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3218 /* Build and store the new Access List for the dir */
3219 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3223 targetptr->changed_newTime = 1; /* status change of directory */
3225 /* convert the write lock to a read lock before breaking callbacks */
3226 VVnodeWriteToRead(&errorCode, targetptr);
3227 assert(!errorCode || errorCode == VSALVAGE);
3229 /* break call backs on the directory */
3230 BreakCallBack(client->host, Fid, 0);
3232 /* Get the updated dir's status back to the caller */
3233 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3236 /* Update and store volume/vnode and parent vnodes back */
3237 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
3238 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3239 errorCode = CallPostamble(tcon, errorCode);
3241 #if FS_STATS_DETAILED
3242 TM_GetTimeOfDay(&opStopTime, 0);
3243 if (errorCode == 0) {
3245 (opP->numSuccesses)++;
3246 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3247 fs_stats_AddTo((opP->sumTime), elapsedTime);
3248 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3249 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3250 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3252 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3253 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3257 #endif /* FS_STATS_DETAILED */
3259 osi_auditU(acall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
3262 } /*SRXAFS_StoreACL */
3266 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3267 * should be merged when possible.
3270 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3271 struct AFSStoreStatus *InStatus,
3272 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3274 Vnode *targetptr = 0; /* pointer to input fid */
3275 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3276 int errorCode = 0; /* return code for caller */
3277 Volume *volptr = 0; /* pointer to the volume header */
3278 struct client *client; /* pointer to client structure */
3279 afs_int32 rights, anyrights; /* rights for this and any user */
3280 struct client *t_client; /* tmp ptr to client data */
3281 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3282 struct rx_connection *tcon = rx_ConnectionOf(acall);
3284 /* Get ptr to client data for user Id for logging */
3285 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3286 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3288 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s, Id %d\n",
3289 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3292 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3295 * Get volume/vnode for the target file; caller's rights to it are
3299 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3300 &parentwhentargetnotdir, &client, WRITE_LOCK,
3301 &rights, &anyrights))) {
3302 goto Bad_StoreStatus;
3305 /* set volume synchronization information */
3306 SetVolumeSync(Sync, volptr);
3308 /* Check if the caller has proper permissions to store status to Fid */
3310 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3312 goto Bad_StoreStatus;
3315 * Check for a symbolic link; we can't chmod these (otherwise could
3316 * change a symlink to a mt pt or vice versa)
3318 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3320 goto Bad_StoreStatus;
3323 /* Update the status of the target's vnode */
3324 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3325 (parentwhentargetnotdir ? parentwhentargetnotdir
3326 : targetptr), volptr, 0);
3328 /* convert the write lock to a read lock before breaking callbacks */
3329 VVnodeWriteToRead(&errorCode, targetptr);
3330 assert(!errorCode || errorCode == VSALVAGE);
3332 /* Break call backs on Fid */
3333 BreakCallBack(client->host, Fid, 0);
3335 /* Return the updated status back to caller */
3336 GetStatus(targetptr, OutStatus, rights, anyrights,
3337 parentwhentargetnotdir);
3340 /* Update and store volume/vnode and parent vnodes back */
3341 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
3342 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3345 } /*SAFSS_StoreStatus */
3349 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3350 struct AFSStoreStatus * InStatus,
3351 struct AFSFetchStatus * OutStatus,
3352 struct AFSVolSync * Sync)
3355 struct rx_connection *tcon;
3356 #if FS_STATS_DETAILED
3357 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3358 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3359 struct timeval elapsedTime; /* Transfer time */
3362 * Set our stats pointer, remember when the RPC operation started, and
3363 * tally the operation.
3365 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3369 TM_GetTimeOfDay(&opStartTime, 0);
3370 #endif /* FS_STATS_DETAILED */
3372 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3373 goto Bad_StoreStatus;
3375 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3378 code = CallPostamble(tcon, code);
3380 #if FS_STATS_DETAILED
3381 TM_GetTimeOfDay(&opStopTime, 0);
3384 (opP->numSuccesses)++;
3385 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3386 fs_stats_AddTo((opP->sumTime), elapsedTime);
3387 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3388 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3389 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3391 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3392 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3396 #endif /* FS_STATS_DETAILED */
3398 osi_auditU(acall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
3401 } /*SRXAFS_StoreStatus */
3405 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3406 * merged in when possible.
3409 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3410 struct AFSFetchStatus *OutDirStatus, 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));
3430 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s, Id %d\n", Name,
3431 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3432 inet_ntoa(logHostAddr), t_client->ViceId));
3434 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3437 * Get volume/vnode for the parent dir; caller's access rights are
3441 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3442 &parentwhentargetnotdir, &client, WRITE_LOCK,
3443 &rights, &anyrights))) {
3444 goto Bad_RemoveFile;
3446 /* set volume synchronization information */
3447 SetVolumeSync(Sync, volptr);
3449 /* Does the caller has delete (& write) access to the parent directory? */
3450 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3451 goto Bad_RemoveFile;
3454 /* Actually delete the desired file */
3456 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3458 goto Bad_RemoveFile;
3461 /* Update the vnode status of the parent dir */
3462 #if FS_STATS_DETAILED
3463 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3464 parentptr->disk.linkCount,
3465 client->InSameNetwork);
3467 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3468 parentptr->disk.linkCount);
3469 #endif /* FS_STATS_DETAILED */
3471 /* Return the updated parent dir's status back to caller */
3472 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3474 /* Handle internal callback state for the parent and the deleted file */
3475 if (targetptr->disk.linkCount == 0) {
3476 /* no references left, discard entry */
3477 DeleteFileCallBacks(&fileFid);
3478 /* convert the parent lock to a read lock before breaking callbacks */
3479 VVnodeWriteToRead(&errorCode, parentptr);
3480 assert(!errorCode || errorCode == VSALVAGE);
3482 /* convert the parent lock to a read lock before breaking callbacks */
3483 VVnodeWriteToRead(&errorCode, parentptr);
3484 assert(!errorCode || errorCode == VSALVAGE);
3485 /* convert the target lock to a read lock before breaking callbacks */
3486 VVnodeWriteToRead(&errorCode, targetptr);
3487 assert(!errorCode || errorCode == VSALVAGE);
3488 /* tell all the file has changed */
3489 BreakCallBack(client->host, &fileFid, 1);
3492 /* break call back on the directory */
3493 BreakCallBack(client->host, DirFid, 0);
3496 /* Update and store volume/vnode and parent vnodes back */
3497 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3499 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3502 } /*SAFSS_RemoveFile */
3506 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3507 struct AFSFetchStatus * OutDirStatus,
3508 struct AFSVolSync * Sync)
3511 struct rx_connection *tcon;
3512 #if FS_STATS_DETAILED
3513 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3514 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3515 struct timeval elapsedTime; /* Transfer time */
3518 * Set our stats pointer, remember when the RPC operation started, and
3519 * tally the operation.
3521 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3525 TM_GetTimeOfDay(&opStartTime, 0);
3526 #endif /* FS_STATS_DETAILED */
3528 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3529 goto Bad_RemoveFile;
3531 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3534 code = CallPostamble(tcon, code);
3536 #if FS_STATS_DETAILED
3537 TM_GetTimeOfDay(&opStopTime, 0);
3540 (opP->numSuccesses)++;
3541 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3542 fs_stats_AddTo((opP->sumTime), elapsedTime);
3543 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3544 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3545 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3547 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3548 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3552 #endif /* FS_STATS_DETAILED */
3554 osi_auditU(acall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name,
3558 } /*SRXAFS_RemoveFile */
3562 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3563 * be merged in when possible.
3566 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3567 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3568 struct AFSFetchStatus *OutFidStatus,
3569 struct AFSFetchStatus *OutDirStatus,
3570 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3572 Vnode *parentptr = 0; /* vnode of input Directory */
3573 Vnode *targetptr = 0; /* vnode of the new file */
3574 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3575 Volume *volptr = 0; /* pointer to the volume header */
3576 int errorCode = 0; /* error code */
3577 DirHandle dir; /* Handle for dir package I/O */
3578 struct client *client; /* pointer to client structure */
3579 afs_int32 rights, anyrights; /* rights for this and any user */
3580 struct client *t_client; /* tmp ptr to client data */
3581 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3582 struct rx_connection *tcon = rx_ConnectionOf(acall);
3586 /* Get ptr to client data for user Id for logging */
3587 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3588 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3590 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s, Id %d\n", Name,
3591 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3592 inet_ntoa(logHostAddr), t_client->ViceId));
3594 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3596 if (!FileNameOK(Name)) {
3598 goto Bad_CreateFile;
3602 * Get associated volume/vnode for the parent dir; caller long are
3606 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3607 &parentwhentargetnotdir, &client, WRITE_LOCK,
3608 &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 */
3621 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3622 vFile, nBlocks(0)))) {
3623 goto Bad_CreateFile;
3626 /* update the status of the parent vnode */
3627 #if FS_STATS_DETAILED
3628 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3629 parentptr->disk.linkCount,
3630 client->InSameNetwork);
3632 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3633 parentptr->disk.linkCount);
3634 #endif /* FS_STATS_DETAILED */
3636 /* update the status of the new file's vnode */
3637 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3638 parentptr, volptr, 0);
3640 /* set up the return status for the parent dir and the newly created file, and since the newly created file is owned by the creator, give it PRSFS_ADMINISTER to tell the client its the owner of the file */
3641 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3642 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3644 /* convert the write lock to a read lock before breaking callbacks */
3645 VVnodeWriteToRead(&errorCode, parentptr);
3646 assert(!errorCode || errorCode == VSALVAGE);
3648 /* break call back on parent dir */
3649 BreakCallBack(client->host, DirFid, 0);
3651 /* Return a callback promise for the newly created file to the caller */
3652 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3655 /* Update and store volume/vnode and parent vnodes back */
3656 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3659 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3662 } /*SAFSS_CreateFile */
3666 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3667 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3668 struct AFSFetchStatus * OutFidStatus,
3669 struct AFSFetchStatus * OutDirStatus,
3670 struct AFSCallBack * CallBack, 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, opStopTime; /* Start/stop times for RPC op */
3677 struct timeval elapsedTime; /* Transfer time */
3680 * Set our stats pointer, remember when the RPC operation started, and
3681 * tally the operation.
3683 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3687 TM_GetTimeOfDay(&opStartTime, 0);
3688 #endif /* FS_STATS_DETAILED */
3690 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3691 goto Bad_CreateFile;
3694 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3695 OutDirStatus, CallBack, Sync);
3698 code = CallPostamble(tcon, code);
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,
3722 } /*SRXAFS_CreateFile */
3726 * This routine is called exclusively from SRXAFS_Rename(), and should be
3727 * merged in when possible.
3730 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3731 struct AFSFid *NewDirFid, char *NewName,
3732 struct AFSFetchStatus *OutOldDirStatus,
3733 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3735 Vnode *oldvptr = 0; /* vnode of the old Directory */
3736 Vnode *newvptr = 0; /* vnode of the new Directory */
3737 Vnode *fileptr = 0; /* vnode of the file to move */
3738 Vnode *newfileptr = 0; /* vnode of the file to delete */
3739 Vnode *testvptr = 0; /* used in directory tree walk */
3740 Vnode *parent = 0; /* parent for use in SetAccessList */
3741 int errorCode = 0; /* error code */
3742 int fileCode = 0; /* used when writing Vnodes */
3743 VnodeId testnode; /* used in directory tree walk */
3744 AFSFid fileFid; /* Fid of file to move */
3745 AFSFid newFileFid; /* Fid of new file */
3746 DirHandle olddir; /* Handle for dir package I/O */
3747 DirHandle newdir; /* Handle for dir package I/O */
3748 DirHandle filedir; /* Handle for dir package I/O */
3749 DirHandle newfiledir; /* Handle for dir package I/O */
3750 Volume *volptr = 0; /* pointer to the volume header */
3751 struct client *client; /* pointer to client structure */
3752 afs_int32 rights, anyrights; /* rights for this and any user */
3753 afs_int32 newrights; /* rights for this user */
3754 afs_int32 newanyrights; /* rights for any user */
3755 int doDelete; /* deleted the rename target (ref count now 0) */
3757 struct client *t_client; /* tmp ptr to client data */
3758 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3759 struct rx_connection *tcon = rx_ConnectionOf(acall);
3764 FidZero(&newfiledir);
3766 /* Get ptr to client data for user Id for logging */
3767 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3768 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3770 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s, Id %d\n",
3771 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3772 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3773 NewDirFid->Unique, inet_ntoa(logHostAddr), t_client->ViceId));
3775 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3777 if (!FileNameOK(NewName)) {
3781 if (OldDirFid->Volume != NewDirFid->Volume) {
3786 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3787 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3788 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3794 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3796 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3797 &parent, &client, WRITE_LOCK, &rights,
3802 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3804 newrights = rights, newanyrights = anyrights;
3807 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3808 MustBeDIR, &parent, &client, WRITE_LOCK,
3809 &newrights, &newanyrights))) {
3815 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3816 &parent, &client, WRITE_LOCK, &newrights,
3822 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3823 &parent, &client, WRITE_LOCK, &rights,
3830 /* set volume synchronization information */
3831 SetVolumeSync(Sync, volptr);
3833 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3836 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3840 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3841 * call to CopyOnWrite returns error, it is not necessary to revert back
3842 * the effects of the first call because the contents of the volume is
3843 * not modified, it is only replicated.
3845 if (oldvptr->disk.cloned) {
3846 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3847 if ((errorCode = CopyOnWrite(oldvptr, volptr)))
3850 SetDirHandle(&olddir, oldvptr);
3851 if (newvptr->disk.cloned) {
3852 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3853 if ((errorCode = CopyOnWrite(newvptr, volptr)))
3857 SetDirHandle(&newdir, newvptr);
3859 /* Lookup the file to delete its vnode */
3860 if (Lookup(&olddir, OldName, &fileFid)) {
3864 if (fileFid.Vnode == oldvptr->vnodeNumber
3865 || fileFid.Vnode == newvptr->vnodeNumber) {
3866 errorCode = FSERR_ELOOP;
3869 fileFid.Volume = V_id(volptr);
3870 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3871 if (errorCode != 0) {
3873 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3874 OldName, errorCode));
3875 VTakeOffline(volptr);
3878 if (fileptr->disk.uniquifier != fileFid.Unique) {
3880 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3882 VTakeOffline(volptr);
3887 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3888 && fileptr->disk.linkCount != 1) {
3890 * Hard links exist to this file - cannot move one of the links to
3891 * a new directory because of AFS restrictions (this is the same
3892 * reason that links cannot be made across directories, i.e.
3899 /* Lookup the new file */
3900 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3901 if (readonlyServer) {
3902 errorCode = VREADONLY;
3905 if (!(newrights & PRSFS_DELETE)) {
3909 if (newFileFid.Vnode == oldvptr->vnodeNumber
3910 || newFileFid.Vnode == newvptr->vnodeNumber
3911 || newFileFid.Vnode == fileFid.Vnode) {
3915 newFileFid.Volume = V_id(volptr);
3917 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3918 if (errorCode != 0) {
3920 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3921 NewName, errorCode));
3922 VTakeOffline(volptr);
3925 if (fileptr->disk.uniquifier != fileFid.Unique) {
3927 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3929 VTakeOffline(volptr);
3933 SetDirHandle(&newfiledir, newfileptr);
3934 /* Now check that we're moving directories over directories properly, etc.
3935 * return proper POSIX error codes:
3936 * if fileptr is a file and new is a dir: EISDIR.
3937 * if fileptr is a dir and new is a file: ENOTDIR.
3938 * Also, dir to be removed must be empty, of course.
3940 if (newfileptr->disk.type == vDirectory) {
3941 if (fileptr->disk.type != vDirectory) {
3945 if ((IsEmpty(&newfiledir))) {
3950 if (fileptr->disk.type == vDirectory) {
3951 errorCode = ENOTDIR;
3958 * ok - now we check that the old name is not above new name in the
3959 * directory structure. This is to prevent removing a subtree alltogether
3961 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3962 afs_int32 forpass = 0, vnum = 0, top = 0;
3963 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3964 if (testnode > vnum) vnum = testnode;
3965 if (forpass > vnum) {
3966 errorCode = FSERR_ELOOP;
3969 if (testnode == oldvptr->vnodeNumber) {
3970 testnode = oldvptr->disk.parent;
3973 if ((testnode == fileptr->vnodeNumber)
3974 || (testnode == newvptr->vnodeNumber)) {
3975 errorCode = FSERR_ELOOP;
3978 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3979 errorCode = FSERR_ELOOP;
3982 if (testnode == 1) top = 1;
3983 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3984 assert(errorCode == 0);
3985 testnode = testvptr->disk.parent;
3986 VPutVnode(&errorCode, testvptr);
3987 if ((top == 1) && (testnode != 0)) {
3988 VTakeOffline(volptr);
3992 assert(errorCode == 0);
3995 /* Do the CopyonWrite first before modifying anything else. Copying is
3996 * required because we may have to change entries for ..
3998 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
3999 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4000 if ((errorCode = CopyOnWrite(fileptr, volptr)))
4004 /* If the new name exists already, delete it and the file it points to */
4007 /* Delete NewName from its directory */
4008 code = Delete(&newdir, NewName);
4011 /* Drop the link count */
4012 newfileptr->disk.linkCount--;
4013 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4014 afs_fsize_t newSize;
4015 VN_GET_LEN(newSize, newfileptr);
4016 VAdjustDiskUsage((Error *) & errorCode, volptr,
4017 (afs_sfsize_t) - nBlocks(newSize), 0);
4018 if (VN_GET_INO(newfileptr)) {
4019 IH_REALLYCLOSE(newfileptr->handle);
4021 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4022 V_parentId(volptr));
4023 IH_RELEASE(newfileptr->handle);
4024 if (errorCode == -1) {
4026 ("Del: inode=%s, name=%s, errno=%d\n",
4027 PrintInode(NULL, VN_GET_INO(newfileptr)),
4029 if ((errno != ENOENT) && (errno != EIO)
4030 && (errno != ENXIO))
4031 ViceLog(0, ("Do we need to fsck?"));
4034 VN_SET_INO(newfileptr, (Inode) 0);
4035 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4038 /* Link count did not drop to zero.
4039 * Mark NewName vnode as changed - updates stime.
4041 newfileptr->changed_newTime = 1;
4046 * If the create below fails, and the delete above worked, we have
4047 * removed the new name and not replaced it. This is not very likely,
4048 * but possible. We could try to put the old file back, but it is
4049 * highly unlikely that it would work since it would involve issuing
4052 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4055 /* Delete the old name */
4056 assert(Delete(&olddir, (char *)OldName) == 0);
4058 /* if the directory length changes, reflect it in the statistics */
4059 #if FS_STATS_DETAILED
4060 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4061 oldvptr->disk.linkCount, client->InSameNetwork);
4062 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,