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"));
597 acl_CheckRights(ACL, &client->CPS, rights);
599 /* wait if somebody else is already doing the getCPS call */
601 while (client->host->hostFlags & HCPS_INPROGRESS) {
602 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
603 #ifdef AFS_PTHREAD_ENV
604 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
605 #else /* AFS_PTHREAD_ENV */
607 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
608 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
609 #endif /* AFS_PTHREAD_ENV */
612 if (client->host->hcps.prlist_len && !client->host->hcps.prlist_val) {
614 ("CheckRights: len=%u, for host=0x%x\n",
615 client->host->hcps.prlist_len, client->host->host));
617 acl_CheckRights(ACL, &client->host->hcps, &hrights);
619 /* Allow system:admin the rights given with the -implicit option */
620 if (acl_IsAMember(SystemId, &client->CPS))
621 *rights |= implicitAdminRights;
623 *anyrights |= hrights;
630 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
631 * a System:Administrator)
634 VanillaUser(struct client *client)
636 if (acl_IsAMember(SystemId, &client->CPS))
637 return (0); /* not a system administrator, then you're "vanilla" */
644 * This unusual afs_int32-parameter routine encapsulates all volume package related
645 * operations together in a single function; it's called by almost all AFS
649 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
650 Vnode ** targetptr, int chkforDir, Vnode ** parent,
651 struct client **client, int locktype, afs_int32 * rights,
652 afs_int32 * anyrights)
654 struct acl_accessList *aCL; /* Internal access List */
655 int aCLSize; /* size of the access list */
656 int errorCode = 0; /* return code to caller */
658 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
661 if (chkforDir == MustNOTBeDIR
662 && ((*targetptr)->disk.type == vDirectory))
664 else if (chkforDir == MustBeDIR
665 && ((*targetptr)->disk.type != vDirectory))
669 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
670 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
671 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
673 if (chkforDir == MustBeDIR)
674 assert((*parent) == 0);
675 if ((errorCode = GetClient(tcon, client)) != 0)
679 assert(GetRights(*client, aCL, rights, anyrights) == 0);
680 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
681 if ((*targetptr)->disk.type != vDirectory) {
682 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
683 if ((*targetptr)->disk.owner == (*client)->ViceId)
684 (*rights) |= PRSFS_ADMINISTER;
686 (*rights) &= ~PRSFS_ADMINISTER;
688 #ifdef ADMIN_IMPLICIT_LOOKUP
689 /* admins get automatic lookup on everything */
690 if (!VanillaUser(*client))
691 (*rights) |= PRSFS_LOOKUP;
692 #endif /* ADMIN_IMPLICIT_LOOKUP */
695 } /*GetVolumePackage */
699 * This is the opposite of GetVolumePackage(), and is always used at the end of
700 * AFS calls to put back all used vnodes and the volume in the proper order!
703 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
704 Vnode * parentptr, Volume * volptr)
706 int fileCode = 0; /* Error code returned by the volume package */
708 if (parentwhentargetnotdir) {
709 VPutVnode(&fileCode, parentwhentargetnotdir);
710 assert(!fileCode || (fileCode == VSALVAGE));
713 VPutVnode(&fileCode, targetptr);
714 assert(!fileCode || (fileCode == VSALVAGE));
717 VPutVnode(&fileCode, parentptr);
718 assert(!fileCode || (fileCode == VSALVAGE));
723 } /*PutVolumePackage */
726 VolumeOwner(register struct client *client, register Vnode * targetptr)
728 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
731 return (client->ViceId == owner);
734 * We don't have to check for host's cps since only regular
735 * viceid are volume owners.
737 return (acl_IsAMember(owner, &client->CPS));
743 VolumeRootVnode(Vnode * targetptr)
745 return ((targetptr->vnodeNumber == ROOTVNODE)
746 && (targetptr->disk.uniquifier == 1));
748 } /*VolumeRootVnode */
751 * Check if target file has the proper access permissions for the Fetch
752 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
753 * StoreStatus) related calls
755 /* this code should probably just set a "priv" flag where all the audit events
756 * are now, and only generate the audit event once at the end of the routine,
757 * thus only generating the event if all the checks succeed, but only because
758 * of the privilege XXX
761 Check_PermissionRights(Vnode * targetptr, struct client *client,
762 afs_int32 rights, int CallingRoutine,
763 AFSStoreStatus * InStatus)
766 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
767 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
768 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
770 if (CallingRoutine & CHK_FETCH) {
771 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
772 if (targetptr->disk.type == vDirectory
773 || targetptr->disk.type == vSymlink) {
774 if (!(rights & PRSFS_LOOKUP)
775 #ifdef ADMIN_IMPLICIT_LOOKUP
776 /* grant admins fetch on all directories */
777 && VanillaUser(client)
778 #endif /* ADMIN_IMPLICIT_LOOKUP */
779 && !VolumeOwner(client, targetptr))
782 /* must have read access, or be owner and have insert access */
783 if (!(rights & PRSFS_READ)
784 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
787 if (CallingRoutine == CHK_FETCHDATA
788 && targetptr->disk.type == vFile)
789 #ifdef USE_GROUP_PERMS
790 if (!OWNSp(client, targetptr)
791 && !acl_IsAMember(targetptr->disk.owner, &client->CPS)) {
793 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
797 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
802 * The check with the ownership below is a kludge to allow
803 * reading of files created with no read permission. The owner
804 * of the file is always allowed to read it.
806 if ((client->ViceId != targetptr->disk.owner)
807 && VanillaUser(client))
809 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
810 modeBits) ? 0 : EACCES);
812 } else { /* !VanillaUser(client) && !FetchData */
814 osi_audit(PrivilegeEvent, 0, AUD_INT,
815 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
818 } else { /* a store operation */
819 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
820 && (CallingRoutine != CHK_STOREACL)
821 && (targetptr->disk.type == vFile)) {
822 /* bypass protection checks on first store after a create
823 * for the creator; also prevent chowns during this time
824 * unless you are a system administrator */
825 /****** InStatus->Owner && UnixModeBits better be SET!! */
826 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
829 else if (VanillaUser(client))
830 return (EPERM); /* Was EACCES */
832 osi_audit(PrivilegeEvent, 0, AUD_INT,
833 (client ? client->ViceId : 0), AUD_INT,
834 CallingRoutine, AUD_END);
837 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
838 osi_audit(PrivilegeEvent, 0, AUD_INT,
839 (client ? client->ViceId : 0), AUD_INT,
840 CallingRoutine, AUD_END);
842 if (readonlyServer) {
845 if (CallingRoutine == CHK_STOREACL) {
846 if (!(rights & PRSFS_ADMINISTER)
847 && !VolumeOwner(client, targetptr))
849 } else { /* store data or status */
850 /* watch for chowns and chgrps */
851 if (CHOWN(InStatus, targetptr)
852 || CHGRP(InStatus, targetptr)) {
855 else if (VanillaUser(client))
856 return (EPERM); /* Was EACCES */
858 osi_audit(PrivilegeEvent, 0, AUD_INT,
859 (client ? client->ViceId : 0), AUD_INT,
860 CallingRoutine, AUD_END);
862 /* must be sysadmin to set suid/sgid bits */
863 if ((InStatus->Mask & AFS_SETMODE) &&
865 (InStatus->UnixModeBits & 0xc00) != 0) {
867 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
871 if (VanillaUser(client))
874 osi_audit(PrivSetID, 0, AUD_INT,
875 (client ? client->ViceId : 0), AUD_INT,
876 CallingRoutine, AUD_END);
878 if (CallingRoutine == CHK_STOREDATA) {
881 if (!(rights & PRSFS_WRITE))
883 /* Next thing is tricky. We want to prevent people
884 * from writing files sans 0200 bit, but we want
885 * creating new files with 0444 mode to work. We
886 * don't check the 0200 bit in the "you are the owner"
887 * path above, but here we check the bit. However, if
888 * you're a system administrator, we ignore the 0200
889 * bit anyway, since you may have fchowned the file,
891 #ifdef USE_GROUP_PERMS
892 if ((targetptr->disk.type == vFile)
893 && VanillaUser(client)) {
894 if (!OWNSp(client, targetptr)
895 && !acl_IsAMember(targetptr->disk.owner,
898 ((GROUPWRITE & targetptr->disk.modeBits)
902 ((OWNERWRITE & targetptr->disk.modeBits)
907 if ((targetptr->disk.type != vDirectory)
908 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
911 if (VanillaUser(client))
914 osi_audit(PrivilegeEvent, 0, AUD_INT,
915 (client ? client->ViceId : 0),
916 AUD_INT, CallingRoutine, AUD_END);
918 } else { /* a status store */
921 if (targetptr->disk.type == vDirectory) {
922 if (!(rights & PRSFS_DELETE)
923 && !(rights & PRSFS_INSERT))
925 } else { /* a file or symlink */
926 if (!(rights & PRSFS_WRITE))
936 } /*Check_PermissionRights */
940 * The Access List information is converted from its internal form in the
941 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
942 * external form and returned back to the caller, via the AccessList
946 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
947 struct AFSOpaque *AccessList)
949 char *eACL; /* External access list placeholder */
952 ((targetptr->disk.type ==
953 vDirectory ? VVnodeACL(targetptr) :
954 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
957 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
958 acl_FreeExternalACL(&eACL);
961 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
962 AccessList->AFSOpaque_len = strlen(eACL) + 1;
964 acl_FreeExternalACL(&eACL);
967 } /*RXFetch_AccessList */
971 * The Access List information is converted from its external form in the
972 * input AccessList structure to the internal representation and copied into
973 * the target dir's vnode storage.
976 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
978 struct acl_accessList *newACL; /* PlaceHolder for new access list */
980 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
982 if ((newACL->size + 4) > VAclSize(targetptr))
984 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
985 acl_FreeACL(&newACL);
988 } /*RXStore_AccessList */
992 Fetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
993 struct AFSAccessList *AccessList)
995 char *eACL; /* External access list placeholder */
997 assert(acl_Externalize
998 ((targetptr->disk.type ==
999 vDirectory ? VVnodeACL(targetptr) :
1000 VVnodeACL(parentwhentargetnotdir)), &eACL) == 0);
1001 if ((strlen(eACL) + 1) > AccessList->MaxSeqLen) {
1002 acl_FreeExternalACL(&eACL);
1005 strcpy((char *)(AccessList->SeqBody), (char *)eACL);
1006 AccessList->SeqLen = strlen(eACL) + 1;
1008 acl_FreeExternalACL(&eACL);
1011 } /*Fetch_AccessList */
1014 * The Access List information is converted from its external form in the
1015 * input AccessList structure to the internal representation and copied into
1016 * the target dir's vnode storage.
1019 Store_AccessList(Vnode * targetptr, struct AFSAccessList *AccessList)
1021 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1023 if (acl_Internalize(AccessList->SeqBody, &newACL) != 0)
1025 if ((newACL->size + 4) > VAclSize(targetptr))
1027 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1028 acl_FreeACL(&newACL);
1031 } /*Store_AccessList */
1034 /* In our current implementation, each successive data store (new file
1035 * data version) creates a new inode. This function creates the new
1036 * inode, copies the old inode's contents to the new one, remove the old
1037 * inode (i.e. decrement inode count -- if it's currently used the delete
1038 * will be delayed), and modify some fields (i.e. vnode's
1039 * disk.inodeNumber and cloned)
1041 #define COPYBUFFSIZE 8192
1043 CopyOnWrite(Vnode * targetptr, Volume * volptr)
1045 Inode ino, nearInode;
1048 register afs_fsize_t size;
1049 register int length;
1051 int rc; /* return code */
1052 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1053 FdHandle_t *targFdP; /* Source Inode file handle */
1054 FdHandle_t *newFdP; /* Dest Inode file handle */
1056 if (targetptr->disk.type == vDirectory)
1057 DFlush(); /* just in case? */
1059 VN_GET_LEN(size, targetptr);
1060 buff = (char *)malloc(COPYBUFFSIZE);
1065 ino = VN_GET_INO(targetptr);
1066 assert(VALID_INO(ino));
1067 targFdP = IH_OPEN(targetptr->handle);
1068 if (targFdP == NULL) {
1071 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1072 targetptr->vnodeNumber, V_id(volptr), rc));
1074 VTakeOffline(volptr);
1078 nearInode = VN_GET_INO(targetptr);
1080 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1081 VPartitionPath(V_partition(volptr)), nearInode,
1082 V_id(volptr), targetptr->vnodeNumber,
1083 targetptr->disk.uniquifier,
1084 (int)targetptr->disk.dataVersion);
1085 if (!VALID_INO(ino)) {
1087 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1088 volptr->partition->name, V_id(volptr), errno));
1093 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1094 newFdP = IH_OPEN(newH);
1095 assert(newFdP != NULL);
1098 if (size > COPYBUFFSIZE) { /* more than a buffer */
1099 length = COPYBUFFSIZE;
1100 size -= COPYBUFFSIZE;
1105 rdlen = FDH_READ(targFdP, buff, length);
1106 if (rdlen == length)
1107 wrlen = FDH_WRITE(newFdP, buff, length);
1110 /* Callers of this function are not prepared to recover
1111 * from error that put the filesystem in an inconsistent
1112 * state. Make sure that we force the volume off-line if
1113 * we some error other than ENOSPC - 4.29.99)
1115 * In case we are unable to write the required bytes, and the
1116 * error code indicates that the disk is full, we roll-back to
1117 * the initial state.
1119 if ((rdlen != length) || (wrlen != length))
1120 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1122 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1123 volptr->partition->name, V_id(volptr)));
1124 /* remove destination inode which was partially copied till now */
1125 FDH_REALLYCLOSE(newFdP);
1127 FDH_REALLYCLOSE(targFdP);
1128 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1131 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1132 rc, V_id(volptr), volptr->partition->name));
1133 VTakeOffline(volptr);
1139 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1140 V_id(volptr), volptr->partition->name, length, rdlen,
1142 #ifdef FAST_RESTART /* if running in no-salvage, don't core the server */
1143 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1144 #else /* Avoid further corruption and try to get a core. */
1147 /* Decrement this inode so salvager doesn't find it. */
1148 FDH_REALLYCLOSE(newFdP);
1150 FDH_REALLYCLOSE(targFdP);
1151 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1153 VTakeOffline(volptr);
1156 #ifndef AFS_PTHREAD_ENV
1158 #endif /* !AFS_PTHREAD_ENV */
1160 FDH_REALLYCLOSE(targFdP);
1161 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1162 V_parentId(volptr));
1164 IH_RELEASE(targetptr->handle);
1166 rc = FDH_SYNC(newFdP);
1169 targetptr->handle = newH;
1170 VN_SET_INO(targetptr, ino);
1171 targetptr->disk.cloned = 0;
1172 /* Internal change to vnode, no user level change to volume - def 5445 */
1173 targetptr->changed_oldTime = 1;
1175 return 0; /* success */
1180 * Common code to handle with removing the Name (file when it's called from
1181 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1182 * given directory, parentptr.
1184 int DT1 = 0, DT0 = 0;
1186 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1187 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1189 DirHandle childdir; /* Handle for dir package I/O */
1193 /* watch for invalid names */
1194 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1196 if (parentptr->disk.cloned) {
1197 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1198 if ((errorCode = CopyOnWrite(parentptr, volptr))) {
1200 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1206 /* check that the file is in the directory */
1207 SetDirHandle(dir, parentptr);
1208 if (Lookup(dir, Name, fileFid))
1210 fileFid->Volume = V_id(volptr);
1212 /* just-in-case check for something causing deadlock */
1213 if (fileFid->Vnode == parentptr->vnodeNumber)
1216 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1220 if (ChkForDir == MustBeDIR) {
1221 if ((*targetptr)->disk.type != vDirectory)
1223 } else if ((*targetptr)->disk.type == vDirectory)
1226 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1228 * If the uniquifiers dont match then instead of asserting
1229 * take the volume offline and return VSALVAGE
1231 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1232 VTakeOffline(volptr);
1233 errorCode = VSALVAGE;
1237 if (ChkForDir == MustBeDIR) {
1238 SetDirHandle(&childdir, *targetptr);
1239 if (IsEmpty(&childdir) != 0)
1242 (*targetptr)->delete = 1;
1243 } else if ((--(*targetptr)->disk.linkCount) == 0)
1244 (*targetptr)->delete = 1;
1245 if ((*targetptr)->delete) {
1246 if (VN_GET_INO(*targetptr)) {
1248 IH_REALLYCLOSE((*targetptr)->handle);
1250 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1251 V_parentId(volptr));
1252 IH_RELEASE((*targetptr)->handle);
1253 if (errorCode == -1) {
1255 ("DT: inode=%s, name=%s, errno=%d\n",
1256 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1258 if (errno != ENOENT)
1261 ("Volume %u now offline, must be salvaged.\n",
1263 VTakeOffline(volptr);
1270 VN_SET_INO(*targetptr, (Inode) 0);
1272 afs_fsize_t adjLength;
1273 VN_GET_LEN(adjLength, *targetptr);
1274 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1278 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1280 code = Delete(dir, (char *)Name);
1283 ("Error %d deleting %s\n", code,
1284 (((*targetptr)->disk.type ==
1285 Directory) ? "directory" : "file")));
1287 ("Volume %u now offline, must be salvaged.\n",
1289 VTakeOffline(volptr);
1301 * This routine updates the parent directory's status block after the
1302 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1303 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1307 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1308 int author, int linkcount,
1309 #if FS_STATS_DETAILED
1310 char a_inSameNetwork
1311 #endif /* FS_STATS_DETAILED */
1314 afs_fsize_t newlength; /* Holds new directory length */
1315 afs_fsize_t parentLength;
1317 #if FS_STATS_DETAILED
1318 Date currDate; /*Current date */
1319 int writeIdx; /*Write index to bump */
1320 int timeIdx; /*Authorship time index to bump */
1321 #endif /* FS_STATS_DETAILED */
1323 parentptr->disk.dataVersion++;
1324 newlength = (afs_fsize_t) Length(dir);
1326 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1327 * (create, symlink, link, makedir) so we need to check if we have enough space
1328 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1329 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1331 VN_GET_LEN(parentLength, parentptr);
1332 if (nBlocks(newlength) != nBlocks(parentLength)) {
1333 VAdjustDiskUsage(&errorCode, volptr,
1334 (nBlocks(newlength) - nBlocks(parentLength)),
1335 (nBlocks(newlength) - nBlocks(parentLength)));
1337 VN_SET_LEN(parentptr, newlength);
1339 #if FS_STATS_DETAILED
1341 * Update directory write stats for this volume. Note that the auth
1342 * counter is located immediately after its associated ``distance''
1345 if (a_inSameNetwork)
1346 writeIdx = VOL_STATS_SAME_NET;
1348 writeIdx = VOL_STATS_DIFF_NET;
1349 V_stat_writes(volptr, writeIdx)++;
1350 if (author != AnonymousID) {
1351 V_stat_writes(volptr, writeIdx + 1)++;
1355 * Update the volume's authorship information in response to this
1356 * directory operation. Get the current time, decide to which time
1357 * slot this operation belongs, and bump the appropriate slot.
1359 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1361 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1362 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1363 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1364 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1365 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1366 if (parentptr->disk.author == author) {
1367 V_stat_dirSameAuthor(volptr, timeIdx)++;
1369 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1371 #endif /* FS_STATS_DETAILED */
1373 parentptr->disk.author = author;
1374 parentptr->disk.linkCount = linkcount;
1375 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1376 parentptr->disk.serverModifyTime = FT_ApproxTime();
1377 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1382 * Update the target file's (or dir's) status block after the specified
1383 * operation is complete. Note that some other fields maybe updated by
1384 * the individual module.
1387 /* XXX INCOMPLETE - More attention is needed here! */
1389 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1390 struct client *client, AFSStoreStatus * InStatus,
1391 Vnode * parentptr, Volume * volptr,
1394 #if FS_STATS_DETAILED
1395 Date currDate; /*Current date */
1396 int writeIdx; /*Write index to bump */
1397 int timeIdx; /*Authorship time index to bump */
1398 #endif /* FS_STATS_DETAILED */
1400 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1401 targetptr->disk.parent = parentptr->vnodeNumber;
1402 VN_SET_LEN(targetptr, length);
1403 /* targetptr->disk.group = 0; save some cycles */
1404 targetptr->disk.modeBits = 0777;
1405 targetptr->disk.owner = client->ViceId;
1406 targetptr->disk.dataVersion = 0; /* consistent with the client */
1407 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1408 /* the inode was created in Alloc_NewVnode() */
1410 #if FS_STATS_DETAILED
1412 * Update file write stats for this volume. Note that the auth
1413 * counter is located immediately after its associated ``distance''
1416 if (client->InSameNetwork)
1417 writeIdx = VOL_STATS_SAME_NET;
1419 writeIdx = VOL_STATS_DIFF_NET;
1420 V_stat_writes(volptr, writeIdx)++;
1421 if (client->ViceId != AnonymousID) {
1422 V_stat_writes(volptr, writeIdx + 1)++;
1426 * We only count operations that DON'T involve creating new objects
1427 * (files, symlinks, directories) or simply setting status as
1428 * authorship-change operations.
1430 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1432 * Update the volume's authorship information in response to this
1433 * file operation. Get the current time, decide to which time
1434 * slot this operation belongs, and bump the appropriate slot.
1436 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1439 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1440 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1441 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1442 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1443 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1444 VOL_STATS_TIME_IDX_5);
1445 if (targetptr->disk.author == client->ViceId) {
1446 V_stat_fileSameAuthor(volptr, timeIdx)++;
1448 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1451 #endif /* FS_STATS_DETAILED */
1453 if (!(Caller & TVS_SSTATUS))
1454 targetptr->disk.author = client->ViceId;
1455 if (Caller & TVS_SDATA) {
1456 targetptr->disk.dataVersion++;
1457 if (VanillaUser(client)) {
1458 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1459 #ifdef CREATE_SGUID_ADMIN_ONLY
1460 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1464 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1465 /* store status, must explicitly request to change the date */
1466 if (InStatus->Mask & AFS_SETMODTIME)
1467 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1468 } else { /* other: date always changes, but perhaps to what is specified by caller */
1469 targetptr->disk.unixModifyTime =
1470 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1471 ClientModTime : FT_ApproxTime());
1473 if (InStatus->Mask & AFS_SETOWNER) {
1474 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1475 if (VanillaUser(client)) {
1476 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1477 #ifdef CREATE_SGUID_ADMIN_ONLY
1478 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1481 targetptr->disk.owner = InStatus->Owner;
1482 if (VolumeRootVnode(targetptr)) {
1483 Error errorCode = 0; /* what should be done with this? */
1485 V_owner(targetptr->volumePtr) = InStatus->Owner;
1486 VUpdateVolume(&errorCode, targetptr->volumePtr);
1489 if (InStatus->Mask & AFS_SETMODE) {
1490 int modebits = InStatus->UnixModeBits;
1491 #define CREATE_SGUID_ADMIN_ONLY 1
1492 #ifdef CREATE_SGUID_ADMIN_ONLY
1493 if (VanillaUser(client))
1494 modebits = modebits & 0777;
1496 if (VanillaUser(client)) {
1497 targetptr->disk.modeBits = modebits;
1499 targetptr->disk.modeBits = modebits;
1502 osi_audit(PrivSetID, 0, AUD_INT, client->ViceId, AUD_INT,
1503 CHK_STOREDATA, AUD_END);
1507 osi_audit(PrivSetID, 0, AUD_INT, client->ViceId, AUD_INT,
1508 CHK_STORESTATUS, AUD_END);
1515 targetptr->disk.serverModifyTime = FT_ApproxTime();
1516 if (InStatus->Mask & AFS_SETGROUP)
1517 targetptr->disk.group = InStatus->Group;
1518 /* vnode changed : to be written back by VPutVnode */
1519 targetptr->changed_newTime = 1;
1521 } /*Update_TargetVnodeStatus */
1525 * Fills the CallBack structure with the expiration time and type of callback
1526 * structure. Warning: this function is currently incomplete.
1529 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1531 /* CallBackTime could not be 0 */
1532 if (CallBackTime == 0) {
1533 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1534 CallBack->ExpirationTime = 0;
1536 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1537 CallBack->CallBackVersion = CALLBACK_VERSION;
1538 CallBack->CallBackType = CB_SHARED; /* The default for now */
1540 } /*SetCallBackStruct */
1544 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1545 * allocation; if some error occured (exceeded volume quota or partition
1546 * was full, or whatever), it frees the space back and returns the code.
1547 * We usually pre-adjust the volume space to make sure that there's
1548 * enough space before consuming some.
1551 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1552 afs_sfsize_t checkLength)
1557 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1559 VAdjustDiskUsage(&nc, volptr, -length, 0);
1560 if (rc == VOVERQUOTA) {
1562 ("Volume %u (%s) is full\n", V_id(volptr),
1566 if (rc == VDISKFULL) {
1568 ("Partition %s that contains volume %u is full\n",
1569 volptr->partition->name, V_id(volptr)));
1572 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1577 } /*AdjustDiskUsage */
1580 * Common code that handles the creation of a new file (SAFS_CreateFile and
1581 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1584 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1585 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1586 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1588 int errorCode = 0; /* Error code returned back */
1591 Inode nearInode; /* hint for inode allocation in solaris */
1594 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1595 BlocksPreallocatedForVnode))) {
1597 ("Insufficient space to allocate %lld blocks\n",
1598 (afs_intmax_t) BlocksPreallocatedForVnode));
1602 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1603 if (errorCode != 0) {
1604 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1607 OutFid->Volume = V_id(volptr);
1608 OutFid->Vnode = (*targetptr)->vnodeNumber;
1609 OutFid->Unique = (*targetptr)->disk.uniquifier;
1611 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1613 /* create the inode now itself */
1615 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1616 VPartitionPath(V_partition(volptr)), nearInode,
1617 V_id(volptr), (*targetptr)->vnodeNumber,
1618 (*targetptr)->disk.uniquifier, 1);
1620 /* error in creating inode */
1621 if (!VALID_INO(inode)) {
1623 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1624 (*targetptr)->volumePtr->header->diskstuff.id,
1625 (*targetptr)->vnodeNumber, errno));
1626 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1627 (*targetptr)->delete = 1; /* delete vnode */
1630 VN_SET_INO(*targetptr, inode);
1631 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1633 /* copy group from parent dir */
1634 (*targetptr)->disk.group = parentptr->disk.group;
1636 if (parentptr->disk.cloned) {
1637 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1638 if ((errorCode = CopyOnWrite(parentptr, volptr))) { /* disk full */
1639 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1640 /* delete the vnode previously allocated */
1641 (*targetptr)->delete = 1;
1642 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1643 IH_REALLYCLOSE((*targetptr)->handle);
1644 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1646 ("Alloc_NewVnode: partition %s idec %s failed\n",
1647 volptr->partition->name, PrintInode(NULL, inode)));
1648 IH_RELEASE((*targetptr)->handle);
1654 /* add the name to the directory */
1655 SetDirHandle(dir, parentptr);
1656 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1657 (*targetptr)->delete = 1;
1658 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1659 IH_REALLYCLOSE((*targetptr)->handle);
1660 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1662 ("Alloc_NewVnode: partition %s idec %s failed\n",
1663 volptr->partition->name, PrintInode(NULL, inode)));
1664 IH_RELEASE((*targetptr)->handle);
1670 } /*Alloc_NewVnode */
1674 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1678 HandleLocking(Vnode * targetptr, afs_int32 rights, ViceLockType LockingType)
1680 int Time; /* Used for time */
1681 int writeVnode = targetptr->changed_oldTime; /* save original status */
1683 /* Does the caller has Lock priviledges; root extends locks, however */
1684 if (LockingType != LockExtend && !(rights & PRSFS_LOCK))
1686 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1687 Time = FT_ApproxTime();
1688 switch (LockingType) {
1691 if (Time > targetptr->disk.lock.lockTime)
1692 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1694 Time += AFS_LOCKWAIT;
1695 if (LockingType == LockRead) {
1696 if (targetptr->disk.lock.lockCount >= 0) {
1697 ++(targetptr->disk.lock.lockCount);
1698 targetptr->disk.lock.lockTime = Time;
1702 if (targetptr->disk.lock.lockCount == 0) {
1703 targetptr->disk.lock.lockCount = -1;
1704 targetptr->disk.lock.lockTime = Time;
1710 Time += AFS_LOCKWAIT;
1711 if (targetptr->disk.lock.lockCount != 0)
1712 targetptr->disk.lock.lockTime = Time;
1717 if ((--targetptr->disk.lock.lockCount) <= 0)
1718 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1722 targetptr->changed_oldTime = writeVnode; /* restore old status */
1723 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1726 } /*HandleLocking */
1728 /* 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. */
1731 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1735 if (!(rights & Prfs_Mode))
1737 if ((targetptr->disk.type != vDirectory)
1738 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1744 * If some flags (i.e. min or max quota) are set, the volume's in disk
1745 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1746 * update, if applicable.
1749 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1750 char *Name, char *OfflineMsg, char *Motd)
1752 Error errorCode = 0;
1754 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1755 V_minquota(volptr) = StoreVolStatus->MinQuota;
1756 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1757 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1758 if (strlen(OfflineMsg) > 0) {
1759 strcpy(V_offlineMessage(volptr), OfflineMsg);
1761 if (strlen(Name) > 0) {
1762 strcpy(V_name(volptr), Name);
1764 #if OPENAFS_VOL_STATS
1766 * We don't overwrite the motd field, since it's now being used
1770 if (strlen(Motd) > 0) {
1771 strcpy(V_motd(volptr), Motd);
1773 #endif /* FS_STATS_DETAILED */
1774 VUpdateVolume(&errorCode, volptr);
1777 } /*RXUpdate_VolumeStatus */
1782 Update_VolumeStatus(Volume * volptr, VolumeStatus * StoreVolStatus,
1783 struct BBS *Name, struct BBS *OfflineMsg,
1786 Error errorCode = 0;
1788 if (StoreVolStatus->MinQuota > -1)
1789 V_minquota(volptr) = StoreVolStatus->MinQuota;
1790 if (StoreVolStatus->MaxQuota > -1)
1791 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1792 if (OfflineMsg->SeqLen > 1)
1793 strcpy(V_offlineMessage(volptr), OfflineMsg->SeqBody);
1794 if (Name->SeqLen > 1)
1795 strcpy(V_name(volptr), Name->SeqBody);
1796 #if OPENAFS_VOL_STATS
1798 * We don't overwrite the motd field, since it's now being used
1802 if (Motd->SeqLen > 1)
1803 strcpy(V_motd(volptr), Motd->SeqBody);
1804 #endif /* FS_STATS_DETAILED */
1805 VUpdateVolume(&errorCode, volptr);
1808 } /*Update_VolumeStatus */
1812 * Get internal volume-related statistics from the Volume disk label
1813 * structure and put it into the VolumeStatus structure, status; it's
1814 * used by both SAFS_GetVolumeStatus and SAFS_SetVolumeStatus to return
1815 * the volume status to the caller.
1818 GetVolumeStatus(VolumeStatus * status, struct BBS *name, struct BBS *offMsg,
1819 struct BBS *motd, Volume * volptr)
1821 status->Vid = V_id(volptr);
1822 status->ParentId = V_parentId(volptr);
1823 status->Online = V_inUse(volptr);
1824 status->InService = V_inService(volptr);
1825 status->Blessed = V_blessed(volptr);
1826 status->NeedsSalvage = V_needsSalvaged(volptr);
1827 if (VolumeWriteable(volptr))
1828 status->Type = ReadWrite;
1830 status->Type = ReadOnly;
1831 status->MinQuota = V_minquota(volptr);
1832 status->MaxQuota = V_maxquota(volptr);
1833 status->BlocksInUse = V_diskused(volptr);
1834 status->PartBlocksAvail = volptr->partition->free;
1835 status->PartMaxBlocks = volptr->partition->totalUsable;
1836 strncpy(name->SeqBody, V_name(volptr), (int)name->MaxSeqLen);
1837 name->SeqLen = strlen(V_name(volptr)) + 1;
1838 if (name->SeqLen > name->MaxSeqLen)
1839 name->SeqLen = name->MaxSeqLen;
1840 strncpy(offMsg->SeqBody, V_offlineMessage(volptr), (int)name->MaxSeqLen);
1841 offMsg->SeqLen = strlen(V_offlineMessage(volptr)) + 1;
1842 if (offMsg->SeqLen > offMsg->MaxSeqLen)
1843 offMsg->SeqLen = offMsg->MaxSeqLen;
1845 /*Don't do anything with the motd field */
1846 strncpy(motd->SeqBody, nullString, (int)offMsg->MaxSeqLen);
1847 motd->SeqLen = strlen(nullString) + 1;
1849 if (motd->SeqLen > motd->MaxSeqLen)
1850 motd->SeqLen = motd->MaxSeqLen;
1852 } /*GetVolumeStatus */
1855 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1856 char **motd, Volume * volptr)
1860 status->Vid = V_id(volptr);
1861 status->ParentId = V_parentId(volptr);
1862 status->Online = V_inUse(volptr);
1863 status->InService = V_inService(volptr);
1864 status->Blessed = V_blessed(volptr);
1865 status->NeedsSalvage = V_needsSalvaged(volptr);
1866 if (VolumeWriteable(volptr))
1867 status->Type = ReadWrite;
1869 status->Type = ReadOnly;
1870 status->MinQuota = V_minquota(volptr);
1871 status->MaxQuota = V_maxquota(volptr);
1872 status->BlocksInUse = V_diskused(volptr);
1873 status->PartBlocksAvail = volptr->partition->free;
1874 status->PartMaxBlocks = volptr->partition->totalUsable;
1876 /* now allocate and copy these things; they're freed by the RXGEN stub */
1877 temp = strlen(V_name(volptr)) + 1;
1878 *name = malloc(temp);
1880 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1883 strcpy(*name, V_name(volptr));
1884 temp = strlen(V_offlineMessage(volptr)) + 1;
1885 *offMsg = malloc(temp);
1887 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1890 strcpy(*offMsg, V_offlineMessage(volptr));
1891 #if OPENAFS_VOL_STATS
1894 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1897 strcpy(*motd, nullString);
1899 temp = strlen(V_motd(volptr)) + 1;
1900 *motd = malloc(temp);
1902 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1905 strcpy(*motd, V_motd(volptr));
1906 #endif /* FS_STATS_DETAILED */
1908 } /*RXGetVolumeStatus */
1912 FileNameOK(register char *aname)
1914 register afs_int32 i, tc;
1917 /* watch for @sys on the right */
1918 if (strcmp(aname + i - 4, "@sys") == 0)
1921 while ((tc = *aname++)) {
1923 return 0; /* very bad character to encounter */
1925 return 1; /* file name is ok */
1930 /* Debugging tool to print Volume Statu's contents */
1932 PrintVolumeStatus(VolumeStatus * status)
1934 ViceLog(5, ("Volume header contains:\n"));
1936 ("Vid = %u, Parent = %u, Online = %d, InService = %d, Blessed = %d, NeedsSalvage = %d\n",
1937 status->Vid, status->ParentId, status->Online, status->InService,
1938 status->Blessed, status->NeedsSalvage));
1940 ("MinQuota = %d, MaxQuota = %d\n", status->MinQuota,
1943 ("Type = %d, BlocksInUse = %d, PartBlocksAvail = %d, PartMaxBlocks = %d\n",
1944 status->Type, status->BlocksInUse, status->PartBlocksAvail,
1945 status->PartMaxBlocks));
1947 } /*PrintVolumeStatus */
1951 * This variant of symlink is expressly to support the AFS/DFS translator
1952 * and is not supported by the AFS fileserver. We just return EINVAL.
1953 * The cache manager should not generate this call to an AFS cache manager.
1956 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1957 char *LinkContents, struct AFSStoreStatus *InStatus,
1958 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1959 struct AFSFetchStatus *OutDirStatus,
1960 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1966 SRXAFS_ResidencyCmd(struct rx_call * acall, struct AFSFid * Fid,
1967 struct ResidencyCmdInputs * Inputs,
1968 struct ResidencyCmdOutputs * Outputs)
1973 static struct afs_buffer {
1974 struct afs_buffer *next;
1975 } *freeBufferList = 0;
1976 static int afs_buffersAlloced = 0;
1979 FreeSendBuffer(register struct afs_buffer *adata)
1982 afs_buffersAlloced--;
1983 adata->next = freeBufferList;
1984 freeBufferList = adata;
1988 } /*FreeSendBuffer */
1990 /* allocate space for sender */
1994 register struct afs_buffer *tp;
1997 afs_buffersAlloced++;
1998 if (!freeBufferList) {
2001 tmp = malloc(sendBufSize);
2003 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2008 tp = freeBufferList;
2009 freeBufferList = tp->next;
2013 } /*AllocSendBuffer */
2016 * This routine returns the status info associated with the targetptr vnode
2017 * in the AFSFetchStatus structure. Some of the newer fields, such as
2018 * SegSize and Group are not yet implemented
2022 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2023 afs_int32 anyrights, Vnode * parentptr)
2025 /* initialize return status from a vnode */
2026 status->InterfaceVersion = 1;
2027 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2028 status->errorCode = 0;
2029 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2030 if (targetptr->disk.type == vFile)
2031 status->FileType = File;
2032 else if (targetptr->disk.type == vDirectory)
2033 status->FileType = Directory;
2034 else if (targetptr->disk.type == vSymlink)
2035 status->FileType = SymbolicLink;
2037 status->FileType = Invalid; /*invalid type field */
2038 status->LinkCount = targetptr->disk.linkCount;
2040 afs_fsize_t targetLen;
2041 VN_GET_LEN(targetLen, targetptr);
2042 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2044 status->DataVersion = targetptr->disk.dataVersion;
2045 status->Author = targetptr->disk.author;
2046 status->Owner = targetptr->disk.owner;
2047 status->CallerAccess = rights;
2048 status->AnonymousAccess = anyrights;
2049 status->UnixModeBits = targetptr->disk.modeBits;
2050 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2051 status->ParentVnode =
2052 (status->FileType ==
2053 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2054 status->ParentUnique =
2055 (status->FileType ==
2056 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2057 status->ServerModTime = targetptr->disk.serverModifyTime;
2058 status->Group = targetptr->disk.group;
2059 status->lockCount = targetptr->disk.lock.lockCount;
2060 status->errorCode = 0;
2066 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2067 afs_sfsize_t Pos, afs_sfsize_t Len,
2068 struct AFSFetchStatus *OutStatus,
2069 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2072 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2073 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2074 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2075 int errorCode = 0; /* return code to caller */
2076 int fileCode = 0; /* return code from vol package */
2077 Volume *volptr = 0; /* pointer to the volume */
2078 struct client *client; /* pointer to the client data */
2079 struct rx_connection *tcon; /* the connection we're part of */
2080 afs_int32 rights, anyrights; /* rights for this and any user */
2081 struct client *t_client; /* tmp ptr to client data */
2082 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2083 #if FS_STATS_DETAILED
2084 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2085 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2086 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2087 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2088 struct timeval elapsedTime; /* Transfer time */
2089 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2090 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2091 int readIdx; /* Index of read stats array to bump */
2092 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2095 * Set our stats pointers, remember when the RPC operation started, and
2096 * tally the operation.
2098 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2099 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2103 TM_GetTimeOfDay(&opStartTime, 0);
2104 #endif /* FS_STATS_DETAILED */
2107 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2110 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2112 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2115 /* Get ptr to client data for user Id for logging */
2116 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2117 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2119 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s, Id %d\n",
2120 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2123 * Get volume/vnode for the fetched file; caller's access rights to
2124 * it are also returned
2127 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2128 &parentwhentargetnotdir, &client, READ_LOCK,
2129 &rights, &anyrights)))
2132 SetVolumeSync(Sync, volptr);
2134 #if FS_STATS_DETAILED
2136 * Remember that another read operation was performed.
2139 if (client->InSameNetwork)
2140 readIdx = VOL_STATS_SAME_NET;
2142 readIdx = VOL_STATS_DIFF_NET;
2143 V_stat_reads(volptr, readIdx)++;
2144 if (client->ViceId != AnonymousID) {
2145 V_stat_reads(volptr, readIdx + 1)++;
2148 #endif /* FS_STATS_DETAILED */
2149 /* Check whether the caller has permission access to fetch the data */
2151 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2155 * Drop the read lock on the parent directory after saving the parent
2156 * vnode information we need to pass to GetStatus
2158 if (parentwhentargetnotdir != NULL) {
2159 tparentwhentargetnotdir = *parentwhentargetnotdir;
2160 VPutVnode(&fileCode, parentwhentargetnotdir);
2161 assert(!fileCode || (fileCode == VSALVAGE));
2162 parentwhentargetnotdir = NULL;
2164 #if FS_STATS_DETAILED
2166 * Remember when the data transfer started.
2168 TM_GetTimeOfDay(&xferStartTime, 0);
2169 #endif /* FS_STATS_DETAILED */
2171 /* actually do the data transfer */
2172 #if FS_STATS_DETAILED
2174 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2175 &bytesToXfer, &bytesXferred);
2178 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2180 #endif /* FS_STATS_DETAILED */
2182 #if FS_STATS_DETAILED
2184 * At this point, the data transfer is done, for good or ill. Remember
2185 * when the transfer ended, bump the number of successes/failures, and
2186 * integrate the transfer size and elapsed time into the stats. If the
2187 * operation failed, we jump to the appropriate point.
2189 TM_GetTimeOfDay(&xferStopTime, 0);
2191 (xferP->numXfers)++;
2193 (xferP->numSuccesses)++;
2196 * Bump the xfer sum by the number of bytes actually sent, NOT the
2199 tot_bytesXferred += bytesXferred;
2200 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2201 tot_bytesXferred &= 0x3FF;
2202 if (bytesXferred < xferP->minBytes)
2203 xferP->minBytes = bytesXferred;
2204 if (bytesXferred > xferP->maxBytes)
2205 xferP->maxBytes = bytesXferred;
2208 * Tally the size of the object. Note: we tally the actual size,
2209 * NOT the number of bytes that made it out over the wire.
2211 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2212 (xferP->count[0])++;
2213 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2214 (xferP->count[1])++;
2215 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2216 (xferP->count[2])++;
2217 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2218 (xferP->count[3])++;
2219 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2220 (xferP->count[4])++;
2221 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2222 (xferP->count[5])++;
2223 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2224 (xferP->count[6])++;
2225 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2226 (xferP->count[7])++;
2228 (xferP->count[8])++;
2230 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2231 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2232 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2233 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2234 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2236 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2237 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2242 * Finally, go off to tell our caller the bad news in case the
2247 #endif /* FS_STATS_DETAILED */
2249 /* write back the OutStatus from the target vnode */
2250 GetStatus(targetptr, OutStatus, rights, anyrights,
2251 &tparentwhentargetnotdir);
2253 /* if a r/w volume, promise a callback to the caller */
2254 if (VolumeWriteable(volptr))
2255 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2257 struct AFSFid myFid;
2258 memset(&myFid, 0, sizeof(struct AFSFid));
2259 myFid.Volume = Fid->Volume;
2260 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2264 /* Update and store volume/vnode and parent vnodes back */
2265 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2267 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2268 errorCode = CallPostamble(tcon, errorCode);
2270 #if FS_STATS_DETAILED
2271 TM_GetTimeOfDay(&opStopTime, 0);
2272 if (errorCode == 0) {
2274 (opP->numSuccesses)++;
2275 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2276 fs_stats_AddTo((opP->sumTime), elapsedTime);
2277 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2278 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2279 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2281 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2282 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2286 #endif /* FS_STATS_DETAILED */
2288 osi_auditU(acall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
2291 } /*SRXAFS_FetchData */
2294 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2295 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2296 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2301 common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack, Sync,
2307 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2308 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2309 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2312 afs_sfsize_t tPos, tLen;
2314 #ifdef AFS_64BIT_ENV
2315 #ifndef AFS_LARGEFILE_ENV
2316 if (Pos + Len > 0x7fffffff)
2318 #endif /* !AFS_LARGEFILE_ENV */
2319 tPos = (afs_sfsize_t) Pos;
2320 tLen = (afs_sfsize_t) Len;
2321 #else /* AFS_64BIT_ENV */
2322 if (Pos.high || Len.high)
2326 #endif /* AFS_64BIT_ENV */
2329 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2335 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2336 struct AFSOpaque * AccessList,
2337 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2339 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2340 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2341 int errorCode = 0; /* return error code to caller */
2342 Volume *volptr = 0; /* pointer to the volume */
2343 struct client *client; /* pointer to the client data */
2344 afs_int32 rights, anyrights; /* rights for this and any user */
2345 struct rx_connection *tcon = rx_ConnectionOf(acall);
2346 struct client *t_client; /* tmp ptr to client data */
2347 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2348 #if FS_STATS_DETAILED
2349 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2350 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2351 struct timeval elapsedTime; /* Transfer time */
2354 * Set our stats pointer, remember when the RPC operation started, and
2355 * tally the operation.
2357 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2361 TM_GetTimeOfDay(&opStartTime, 0);
2362 #endif /* FS_STATS_DETAILED */
2365 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2368 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2370 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2373 /* Get ptr to client data for user Id for logging */
2374 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2375 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2377 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s, Id %d\n", Fid->Volume,
2378 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2381 AccessList->AFSOpaque_len = 0;
2382 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2383 if (!AccessList->AFSOpaque_val) {
2384 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2389 * Get volume/vnode for the fetched file; caller's access rights to it
2393 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2394 &parentwhentargetnotdir, &client, READ_LOCK,
2395 &rights, &anyrights)))
2398 SetVolumeSync(Sync, volptr);
2400 /* Check whether we have permission to fetch the ACL */
2402 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2405 /* Get the Access List from the dir's vnode */
2407 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2410 /* Get OutStatus back From the target Vnode */
2411 GetStatus(targetptr, OutStatus, rights, anyrights,
2412 parentwhentargetnotdir);
2415 /* Update and store volume/vnode and parent vnodes back */
2416 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2419 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2420 AccessList->AFSOpaque_val));
2421 errorCode = CallPostamble(tcon, errorCode);
2423 #if FS_STATS_DETAILED
2424 TM_GetTimeOfDay(&opStopTime, 0);
2425 if (errorCode == 0) {
2427 (opP->numSuccesses)++;
2428 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2429 fs_stats_AddTo((opP->sumTime), elapsedTime);
2430 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2431 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2432 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2434 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2435 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2439 #endif /* FS_STATS_DETAILED */
2441 osi_auditU(acall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
2443 } /*SRXAFS_FetchACL */
2447 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2448 * merged into it when possible.
2452 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2453 struct AFSFetchStatus *OutStatus,
2454 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2456 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2457 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2458 int errorCode = 0; /* return code to caller */
2459 Volume *volptr = 0; /* pointer to the volume */
2460 struct client *client; /* pointer to the client data */
2461 afs_int32 rights, anyrights; /* rights for this and any user */
2462 struct client *t_client; /* tmp ptr to client data */
2463 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2464 struct rx_connection *tcon = rx_ConnectionOf(acall);
2466 /* Get ptr to client data for user Id for logging */
2467 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2468 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2470 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s, Id %d\n",
2471 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2474 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2477 * Get volume/vnode for the fetched file; caller's rights to it are
2481 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2482 &parentwhentargetnotdir, &client, READ_LOCK,
2483 &rights, &anyrights)))
2484 goto Bad_FetchStatus;
2486 /* set volume synchronization information */
2487 SetVolumeSync(Sync, volptr);
2489 /* Are we allowed to fetch Fid's status? */
2490 if (targetptr->disk.type != vDirectory) {
2492 Check_PermissionRights(targetptr, client, rights,
2493 CHK_FETCHSTATUS, 0))) {
2494 if (rx_GetCallAbortCode(acall) == errorCode)
2495 rx_SetCallAbortCode(acall, 0);
2496 goto Bad_FetchStatus;
2500 /* set OutStatus From the Fid */
2501 GetStatus(targetptr, OutStatus, rights, anyrights,
2502 parentwhentargetnotdir);
2504 /* If a r/w volume, also set the CallBack state */
2505 if (VolumeWriteable(volptr))
2506 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2508 struct AFSFid myFid;
2509 memset(&myFid, 0, sizeof(struct AFSFid));
2510 myFid.Volume = Fid->Volume;
2511 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2515 /* Update and store volume/vnode and parent vnodes back */
2516 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2518 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2521 } /*SAFSS_FetchStatus */
2525 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2526 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2527 struct AFSVolSync * Sync)
2531 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2532 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2533 int errorCode = 0; /* return code to caller */
2534 Volume *volptr = 0; /* pointer to the volume */
2535 struct client *client; /* pointer to the client data */
2536 afs_int32 rights, anyrights; /* rights for this and any user */
2537 register struct AFSFid *tfid; /* file id we're dealing with now */
2538 struct rx_connection *tcon = rx_ConnectionOf(acall);
2539 #if FS_STATS_DETAILED
2540 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2541 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2542 struct timeval elapsedTime; /* Transfer time */
2545 * Set our stats pointer, remember when the RPC operation started, and
2546 * tally the operation.
2548 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2552 TM_GetTimeOfDay(&opStartTime, 0);
2553 #endif /* FS_STATS_DETAILED */
2555 ViceLog(1, ("SAFS_BulkStatus\n"));
2557 AFSCallStats.TotalCalls++;
2559 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2560 if (nfiles <= 0) { /* Sanity check */
2562 goto Audit_and_Return;
2565 /* allocate space for return output parameters */
2566 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2567 malloc(nfiles * sizeof(struct AFSFetchStatus));
2568 if (!OutStats->AFSBulkStats_val) {
2569 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2572 OutStats->AFSBulkStats_len = nfiles;
2573 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2574 malloc(nfiles * sizeof(struct AFSCallBack));
2575 if (!CallBacks->AFSCBs_val) {
2576 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2579 CallBacks->AFSCBs_len = nfiles;
2581 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2582 goto Bad_BulkStatus;
2584 tfid = Fids->AFSCBFids_val;
2585 for (i = 0; i < nfiles; i++, tfid++) {
2587 * Get volume/vnode for the fetched file; caller's rights to it
2591 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2592 &parentwhentargetnotdir, &client, READ_LOCK,
2593 &rights, &anyrights)))
2594 goto Bad_BulkStatus;
2595 /* set volume synchronization information, but only once per call */
2597 SetVolumeSync(Sync, volptr);
2599 /* Are we allowed to fetch Fid's status? */
2600 if (targetptr->disk.type != vDirectory) {
2602 Check_PermissionRights(targetptr, client, rights,
2603 CHK_FETCHSTATUS, 0))) {
2604 if (rx_GetCallAbortCode(acall) == errorCode)
2605 rx_SetCallAbortCode(acall, 0);
2606 goto Bad_BulkStatus;
2610 /* set OutStatus From the Fid */
2611 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2612 anyrights, parentwhentargetnotdir);
2614 /* If a r/w volume, also set the CallBack state */
2615 if (VolumeWriteable(volptr))
2616 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2617 &CallBacks->AFSCBs_val[i]);
2619 struct AFSFid myFid;
2620 memset(&myFid, 0, sizeof(struct AFSFid));
2621 myFid.Volume = tfid->Volume;
2622 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2623 &CallBacks->AFSCBs_val[i]);
2626 /* put back the file ID and volume */
2627 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2629 parentwhentargetnotdir = (Vnode *) 0;
2630 targetptr = (Vnode *) 0;
2631 volptr = (Volume *) 0;
2635 /* Update and store volume/vnode and parent vnodes back */
2636 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2638 errorCode = CallPostamble(tcon, errorCode);
2640 #if FS_STATS_DETAILED
2641 TM_GetTimeOfDay(&opStopTime, 0);
2642 if (errorCode == 0) {
2644 (opP->numSuccesses)++;
2645 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2646 fs_stats_AddTo((opP->sumTime), elapsedTime);
2647 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2648 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2649 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2651 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2652 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2656 #endif /* FS_STATS_DETAILED */
2659 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2660 osi_auditU(acall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids,
2664 } /*SRXAFS_BulkStatus */
2668 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2669 struct AFSBulkStats * OutStats,
2670 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2674 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2675 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2676 int errorCode = 0; /* return code to caller */
2677 Volume *volptr = 0; /* pointer to the volume */
2678 struct client *client; /* pointer to the client data */
2679 afs_int32 rights, anyrights; /* rights for this and any user */
2680 register struct AFSFid *tfid; /* file id we're dealing with now */
2681 struct rx_connection *tcon;
2682 AFSFetchStatus *tstatus;
2683 #if FS_STATS_DETAILED
2684 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2685 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2686 struct timeval elapsedTime; /* Transfer time */
2689 * Set our stats pointer, remember when the RPC operation started, and
2690 * tally the operation.
2692 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2696 TM_GetTimeOfDay(&opStartTime, 0);
2697 #endif /* FS_STATS_DETAILED */
2699 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2701 AFSCallStats.TotalCalls++;
2703 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2704 if (nfiles <= 0) { /* Sanity check */
2706 goto Audit_and_Return;
2709 /* allocate space for return output parameters */
2710 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2711 malloc(nfiles * sizeof(struct AFSFetchStatus));
2712 if (!OutStats->AFSBulkStats_val) {
2713 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2716 OutStats->AFSBulkStats_len = nfiles;
2717 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2718 malloc(nfiles * sizeof(struct AFSCallBack));
2719 if (!CallBacks->AFSCBs_val) {
2720 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2723 CallBacks->AFSCBs_len = nfiles;
2725 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) {
2726 goto Bad_InlineBulkStatus;
2729 tfid = Fids->AFSCBFids_val;
2730 for (i = 0; i < nfiles; i++, tfid++) {
2732 * Get volume/vnode for the fetched file; caller's rights to it
2736 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2737 &parentwhentargetnotdir, &client, READ_LOCK,
2738 &rights, &anyrights))) {
2739 tstatus = &OutStats->AFSBulkStats_val[i];
2740 tstatus->errorCode = errorCode;
2741 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2742 parentwhentargetnotdir = (Vnode *) 0;
2743 targetptr = (Vnode *) 0;
2744 volptr = (Volume *) 0;
2748 /* set volume synchronization information, but only once per call */
2750 SetVolumeSync(Sync, volptr);
2752 /* Are we allowed to fetch Fid's status? */
2753 if (targetptr->disk.type != vDirectory) {
2755 Check_PermissionRights(targetptr, client, rights,
2756 CHK_FETCHSTATUS, 0))) {
2757 tstatus = &OutStats->AFSBulkStats_val[i];
2758 tstatus->errorCode = errorCode;
2759 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2760 (Vnode *) 0, volptr);
2761 parentwhentargetnotdir = (Vnode *) 0;
2762 targetptr = (Vnode *) 0;
2763 volptr = (Volume *) 0;
2768 /* set OutStatus From the Fid */
2769 GetStatus(targetptr,
2770 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2771 rights, anyrights, parentwhentargetnotdir);
2773 /* If a r/w volume, also set the CallBack state */
2774 if (VolumeWriteable(volptr))
2775 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2776 &CallBacks->AFSCBs_val[i]);
2778 struct AFSFid myFid;
2779 memset(&myFid, 0, sizeof(struct AFSFid));
2780 myFid.Volume = tfid->Volume;
2781 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2782 &CallBacks->AFSCBs_val[i]);
2785 /* put back the file ID and volume */
2786 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2788 parentwhentargetnotdir = (Vnode *) 0;
2789 targetptr = (Vnode *) 0;
2790 volptr = (Volume *) 0;
2793 Bad_InlineBulkStatus:
2794 /* Update and store volume/vnode and parent vnodes back */
2795 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2797 errorCode = CallPostamble(tcon, errorCode);
2799 #if FS_STATS_DETAILED
2800 TM_GetTimeOfDay(&opStopTime, 0);
2801 if (errorCode == 0) {
2803 (opP->numSuccesses)++;
2804 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2805 fs_stats_AddTo((opP->sumTime), elapsedTime);
2806 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2807 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2808 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2810 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2811 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2815 #endif /* FS_STATS_DETAILED */
2818 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2819 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode, AUD_FIDS, Fids,
2823 } /*SRXAFS_InlineBulkStatus */
2827 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2828 struct AFSFetchStatus * OutStatus,
2829 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2832 struct rx_connection *tcon;
2833 #if FS_STATS_DETAILED
2834 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2835 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2836 struct timeval elapsedTime; /* Transfer time */
2839 * Set our stats pointer, remember when the RPC operation started, and
2840 * tally the operation.
2842 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2846 TM_GetTimeOfDay(&opStartTime, 0);
2847 #endif /* FS_STATS_DETAILED */
2849 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
2850 goto Bad_FetchStatus;
2852 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2855 code = CallPostamble(tcon, code);
2857 #if FS_STATS_DETAILED
2858 TM_GetTimeOfDay(&opStopTime, 0);
2861 (opP->numSuccesses)++;
2862 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2863 fs_stats_AddTo((opP->sumTime), elapsedTime);
2864 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2865 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2866 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2868 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2869 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2873 #endif /* FS_STATS_DETAILED */
2875 osi_auditU(acall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
2878 } /*SRXAFS_FetchStatus */
2882 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2883 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2884 afs_fsize_t Length, afs_fsize_t FileLength,
2885 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2887 Vnode *targetptr = 0; /* pointer to input fid */
2888 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2889 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2890 int errorCode = 0; /* return code for caller */
2891 int fileCode = 0; /* return code from vol package */
2892 Volume *volptr = 0; /* pointer to the volume header */
2893 struct client *client; /* pointer to client structure */
2894 afs_int32 rights, anyrights; /* rights for this and any user */
2895 struct client *t_client; /* tmp ptr to client data */
2896 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2897 struct rx_connection *tcon;
2898 #if FS_STATS_DETAILED
2899 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2900 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2901 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2902 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2903 struct timeval elapsedTime; /* Transfer time */
2904 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2905 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2906 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2909 * Set our stats pointers, remember when the RPC operation started, and
2910 * tally the operation.
2912 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2913 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2918 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2920 TM_GetTimeOfDay(&opStartTime, 0);
2921 #endif /* FS_STATS_DETAILED */
2924 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2926 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2929 /* Get ptr to client data for user Id for logging */
2930 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2931 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2933 ("StoreData: Fid = %u.%u.%u, Host %s, Id %d\n", Fid->Volume,
2934 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2938 * Get associated volume/vnode for the stored file; caller's rights
2942 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2943 &parentwhentargetnotdir, &client, WRITE_LOCK,
2944 &rights, &anyrights))) {
2948 /* set volume synchronization information */
2949 SetVolumeSync(Sync, volptr);
2951 if ((targetptr->disk.type == vSymlink)) {
2952 /* Should we return a better error code here??? */
2957 /* Check if we're allowed to store the data */
2959 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2965 * Drop the read lock on the parent directory after saving the parent
2966 * vnode information we need to pass to GetStatus
2968 if (parentwhentargetnotdir != NULL) {
2969 tparentwhentargetnotdir = *parentwhentargetnotdir;
2970 VPutVnode(&fileCode, parentwhentargetnotdir);
2971 assert(!fileCode || (fileCode == VSALVAGE));
2972 parentwhentargetnotdir = NULL;
2974 #if FS_STATS_DETAILED
2976 * Remember when the data transfer started.
2978 TM_GetTimeOfDay(&xferStartTime, 0);
2979 #endif /* FS_STATS_DETAILED */
2981 /* Do the actual storing of the data */
2982 #if FS_STATS_DETAILED
2984 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2985 FileLength, (InStatus->Mask & AFS_FSYNC),
2986 &bytesToXfer, &bytesXferred);
2989 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2990 FileLength, (InStatus->Mask & AFS_FSYNC));
2991 if (errorCode && (!targetptr->changed_newTime))
2993 #endif /* FS_STATS_DETAILED */
2994 #if FS_STATS_DETAILED
2996 * At this point, the data transfer is done, for good or ill. Remember
2997 * when the transfer ended, bump the number of successes/failures, and
2998 * integrate the transfer size and elapsed time into the stats. If the
2999 * operation failed, we jump to the appropriate point.
3001 TM_GetTimeOfDay(&xferStopTime, 0);
3003 (xferP->numXfers)++;
3005 (xferP->numSuccesses)++;
3008 * Bump the xfer sum by the number of bytes actually sent, NOT the
3011 tot_bytesXferred += bytesXferred;
3012 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3013 tot_bytesXferred &= 0x3FF;
3014 if (bytesXferred < xferP->minBytes)
3015 xferP->minBytes = bytesXferred;
3016 if (bytesXferred > xferP->maxBytes)
3017 xferP->maxBytes = bytesXferred;
3020 * Tally the size of the object. Note: we tally the actual size,
3021 * NOT the number of bytes that made it out over the wire.
3023 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3024 (xferP->count[0])++;
3025 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3026 (xferP->count[1])++;
3027 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3028 (xferP->count[2])++;
3029 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3030 (xferP->count[3])++;
3031 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3032 (xferP->count[4])++;
3033 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3034 (xferP->count[5])++;
3035 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3036 (xferP->count[6])++;
3037 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3038 (xferP->count[7])++;
3040 (xferP->count[8])++;
3042 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3043 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3044 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3045 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3046 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3048 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3049 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3054 * Finally, go off to tell our caller the bad news in case the
3057 if (errorCode && (!targetptr->changed_newTime))
3059 #endif /* FS_STATS_DETAILED */
3061 /* Update the status of the target's vnode */
3062 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3063 targetptr, volptr, 0);
3065 /* Get the updated File's status back to the caller */
3066 GetStatus(targetptr, OutStatus, rights, anyrights,
3067 &tparentwhentargetnotdir);
3070 /* Update and store volume/vnode and parent vnodes back */
3071 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3073 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3075 errorCode = CallPostamble(tcon, errorCode);
3077 #if FS_STATS_DETAILED
3078 TM_GetTimeOfDay(&opStopTime, 0);
3079 if (errorCode == 0) {
3081 (opP->numSuccesses)++;
3082 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3083 fs_stats_AddTo((opP->sumTime), elapsedTime);
3084 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3085 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3086 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3088 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3089 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3093 #endif /* FS_STATS_DETAILED */
3095 osi_auditU(acall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
3098 } /*common_StoreData64 */
3101 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3102 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3103 afs_uint32 Length, afs_uint32 FileLength,
3104 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3109 common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3113 } /*SRXAFS_StoreData */
3116 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3117 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3118 afs_uint64 Length, afs_uint64 FileLength,
3119 struct AFSFetchStatus * OutStatus,
3120 struct AFSVolSync * Sync)
3124 afs_fsize_t tLength;
3125 afs_fsize_t tFileLength;
3127 #ifdef AFS_64BIT_ENV
3128 #ifndef AFS_LARGEFILE_ENV
3129 if (FileLength > 0x7fffffff)
3131 #endif /* !AFS_LARGEFILE_ENV */
3132 tPos = (afs_fsize_t) Pos;
3133 tLength = (afs_fsize_t) Length;
3134 tFileLength = (afs_fsize_t) FileLength;
3135 #else /* AFS_64BIT_ENV */
3136 if (FileLength.high)
3139 tLength = Length.low;
3140 tFileLength = FileLength.low;
3141 #endif /* AFS_64BIT_ENV */
3144 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3150 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3151 struct AFSOpaque * AccessList,
3152 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3154 Vnode *targetptr = 0; /* pointer to input fid */
3155 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3156 int errorCode = 0; /* return code for caller */
3157 struct AFSStoreStatus InStatus; /* Input status for fid */
3158 Volume *volptr = 0; /* pointer to the volume header */
3159 struct client *client; /* pointer to client structure */
3160 afs_int32 rights, anyrights; /* rights for this and any user */
3161 struct rx_connection *tcon;
3162 struct client *t_client; /* tmp ptr to client data */
3163 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3164 #if FS_STATS_DETAILED
3165 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3166 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3167 struct timeval elapsedTime; /* Transfer time */
3170 * Set our stats pointer, remember when the RPC operation started, and
3171 * tally the operation.
3173 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3177 TM_GetTimeOfDay(&opStartTime, 0);
3178 #endif /* FS_STATS_DETAILED */
3179 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
3182 /* Get ptr to client data for user Id for logging */
3183 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3184 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3186 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s, Id %d\n",
3187 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3188 inet_ntoa(logHostAddr), t_client->ViceId));
3190 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3192 InStatus.Mask = 0; /* not storing any status */
3195 * Get associated volume/vnode for the target dir; caller's rights
3196 * are also returned.
3199 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3200 &parentwhentargetnotdir, &client, WRITE_LOCK,
3201 &rights, &anyrights))) {
3205 /* set volume synchronization information */
3206 SetVolumeSync(Sync, volptr);
3208 /* Check if we have permission to change the dir's ACL */
3210 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3215 /* Build and store the new Access List for the dir */
3216 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3220 targetptr->changed_newTime = 1; /* status change of directory */
3222 /* convert the write lock to a read lock before breaking callbacks */
3223 VVnodeWriteToRead(&errorCode, targetptr);
3224 assert(!errorCode || errorCode == VSALVAGE);
3226 /* break call backs on the directory */
3227 BreakCallBack(client->host, Fid, 0);
3229 /* Get the updated dir's status back to the caller */
3230 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3233 /* Update and store volume/vnode and parent vnodes back */
3234 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
3235 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3236 errorCode = CallPostamble(tcon, errorCode);
3238 #if FS_STATS_DETAILED
3239 TM_GetTimeOfDay(&opStopTime, 0);
3240 if (errorCode == 0) {
3242 (opP->numSuccesses)++;
3243 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3244 fs_stats_AddTo((opP->sumTime), elapsedTime);
3245 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3246 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3247 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3249 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3250 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3254 #endif /* FS_STATS_DETAILED */
3256 osi_auditU(acall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
3259 } /*SRXAFS_StoreACL */
3263 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3264 * should be merged when possible.
3267 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3268 struct AFSStoreStatus *InStatus,
3269 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3271 Vnode *targetptr = 0; /* pointer to input fid */
3272 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3273 int errorCode = 0; /* return code for caller */
3274 Volume *volptr = 0; /* pointer to the volume header */
3275 struct client *client; /* pointer to client structure */
3276 afs_int32 rights, anyrights; /* rights for this and any user */
3277 struct client *t_client; /* tmp ptr to client data */
3278 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3279 struct rx_connection *tcon = rx_ConnectionOf(acall);
3281 /* Get ptr to client data for user Id for logging */
3282 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3283 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3285 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s, Id %d\n",
3286 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3289 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3292 * Get volume/vnode for the target file; caller's rights to it are
3296 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3297 &parentwhentargetnotdir, &client, WRITE_LOCK,
3298 &rights, &anyrights))) {
3299 goto Bad_StoreStatus;
3302 /* set volume synchronization information */
3303 SetVolumeSync(Sync, volptr);
3305 /* Check if the caller has proper permissions to store status to Fid */
3307 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3309 goto Bad_StoreStatus;
3312 * Check for a symbolic link; we can't chmod these (otherwise could
3313 * change a symlink to a mt pt or vice versa)
3315 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3317 goto Bad_StoreStatus;
3320 /* Update the status of the target's vnode */
3321 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3322 (parentwhentargetnotdir ? parentwhentargetnotdir
3323 : targetptr), volptr, 0);
3325 /* convert the write lock to a read lock before breaking callbacks */
3326 VVnodeWriteToRead(&errorCode, targetptr);
3327 assert(!errorCode || errorCode == VSALVAGE);
3329 /* Break call backs on Fid */
3330 BreakCallBack(client->host, Fid, 0);
3332 /* Return the updated status back to caller */
3333 GetStatus(targetptr, OutStatus, rights, anyrights,
3334 parentwhentargetnotdir);
3337 /* Update and store volume/vnode and parent vnodes back */
3338 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
3339 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3342 } /*SAFSS_StoreStatus */
3346 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3347 struct AFSStoreStatus * InStatus,
3348 struct AFSFetchStatus * OutStatus,
3349 struct AFSVolSync * Sync)
3352 struct rx_connection *tcon;
3353 #if FS_STATS_DETAILED
3354 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3355 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3356 struct timeval elapsedTime; /* Transfer time */
3359 * Set our stats pointer, remember when the RPC operation started, and
3360 * tally the operation.
3362 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3366 TM_GetTimeOfDay(&opStartTime, 0);
3367 #endif /* FS_STATS_DETAILED */
3369 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3370 goto Bad_StoreStatus;
3372 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3375 code = CallPostamble(tcon, code);
3377 #if FS_STATS_DETAILED
3378 TM_GetTimeOfDay(&opStopTime, 0);
3381 (opP->numSuccesses)++;
3382 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3383 fs_stats_AddTo((opP->sumTime), elapsedTime);
3384 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3385 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3386 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3388 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3389 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3393 #endif /* FS_STATS_DETAILED */
3395 osi_auditU(acall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
3398 } /*SRXAFS_StoreStatus */
3402 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3403 * merged in when possible.
3406 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3407 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3409 Vnode *parentptr = 0; /* vnode of input Directory */
3410 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3411 Vnode *targetptr = 0; /* file to be deleted */
3412 Volume *volptr = 0; /* pointer to the volume header */
3413 AFSFid fileFid; /* area for Fid from the directory */
3414 int errorCode = 0; /* error code */
3415 DirHandle dir; /* Handle for dir package I/O */
3416 struct client *client; /* pointer to client structure */
3417 afs_int32 rights, anyrights; /* rights for this and any user */
3418 struct client *t_client; /* tmp ptr to client data */
3419 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3420 struct rx_connection *tcon = rx_ConnectionOf(acall);
3423 /* Get ptr to client data for user Id for logging */
3424 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3425 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3427 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s, Id %d\n", Name,
3428 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3429 inet_ntoa(logHostAddr), t_client->ViceId));
3431 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3434 * Get volume/vnode for the parent dir; caller's access rights are
3438 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3439 &parentwhentargetnotdir, &client, WRITE_LOCK,
3440 &rights, &anyrights))) {
3441 goto Bad_RemoveFile;
3443 /* set volume synchronization information */
3444 SetVolumeSync(Sync, volptr);
3446 /* Does the caller has delete (& write) access to the parent directory? */
3447 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3448 goto Bad_RemoveFile;
3451 /* Actually delete the desired file */
3453 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3455 goto Bad_RemoveFile;
3458 /* Update the vnode status of the parent dir */
3459 #if FS_STATS_DETAILED
3460 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3461 parentptr->disk.linkCount,
3462 client->InSameNetwork);
3464 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3465 parentptr->disk.linkCount);
3466 #endif /* FS_STATS_DETAILED */
3468 /* Return the updated parent dir's status back to caller */
3469 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3471 /* Handle internal callback state for the parent and the deleted file */
3472 if (targetptr->disk.linkCount == 0) {
3473 /* no references left, discard entry */
3474 DeleteFileCallBacks(&fileFid);
3475 /* convert the parent lock to a read lock before breaking callbacks */
3476 VVnodeWriteToRead(&errorCode, parentptr);
3477 assert(!errorCode || errorCode == VSALVAGE);
3479 /* convert the parent lock to a read lock before breaking callbacks */
3480 VVnodeWriteToRead(&errorCode, parentptr);
3481 assert(!errorCode || errorCode == VSALVAGE);
3482 /* convert the target lock to a read lock before breaking callbacks */
3483 VVnodeWriteToRead(&errorCode, targetptr);
3484 assert(!errorCode || errorCode == VSALVAGE);
3485 /* tell all the file has changed */
3486 BreakCallBack(client->host, &fileFid, 1);
3489 /* break call back on the directory */
3490 BreakCallBack(client->host, DirFid, 0);
3493 /* Update and store volume/vnode and parent vnodes back */
3494 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3496 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3499 } /*SAFSS_RemoveFile */
3503 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3504 struct AFSFetchStatus * OutDirStatus,
3505 struct AFSVolSync * Sync)
3508 struct rx_connection *tcon;
3509 #if FS_STATS_DETAILED
3510 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3511 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3512 struct timeval elapsedTime; /* Transfer time */
3515 * Set our stats pointer, remember when the RPC operation started, and
3516 * tally the operation.
3518 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3522 TM_GetTimeOfDay(&opStartTime, 0);
3523 #endif /* FS_STATS_DETAILED */
3525 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3526 goto Bad_RemoveFile;
3528 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3531 code = CallPostamble(tcon, code);
3533 #if FS_STATS_DETAILED
3534 TM_GetTimeOfDay(&opStopTime, 0);
3537 (opP->numSuccesses)++;
3538 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3539 fs_stats_AddTo((opP->sumTime), elapsedTime);
3540 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3541 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3542 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3544 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3545 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3549 #endif /* FS_STATS_DETAILED */
3551 osi_auditU(acall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name,
3555 } /*SRXAFS_RemoveFile */
3559 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3560 * be merged in when possible.
3563 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3564 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3565 struct AFSFetchStatus *OutFidStatus,
3566 struct AFSFetchStatus *OutDirStatus,
3567 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3569 Vnode *parentptr = 0; /* vnode of input Directory */
3570 Vnode *targetptr = 0; /* vnode of the new file */
3571 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3572 Volume *volptr = 0; /* pointer to the volume header */
3573 int errorCode = 0; /* error code */
3574 DirHandle dir; /* Handle for dir package I/O */
3575 struct client *client; /* pointer to client structure */
3576 afs_int32 rights, anyrights; /* rights for this and any user */
3577 struct client *t_client; /* tmp ptr to client data */
3578 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3579 struct rx_connection *tcon = rx_ConnectionOf(acall);
3583 /* Get ptr to client data for user Id for logging */
3584 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3585 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3587 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s, Id %d\n", Name,
3588 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3589 inet_ntoa(logHostAddr), t_client->ViceId));
3591 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3593 if (!FileNameOK(Name)) {
3595 goto Bad_CreateFile;
3599 * Get associated volume/vnode for the parent dir; caller long are
3603 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3604 &parentwhentargetnotdir, &client, WRITE_LOCK,
3605 &rights, &anyrights))) {
3606 goto Bad_CreateFile;
3609 /* set volume synchronization information */
3610 SetVolumeSync(Sync, volptr);
3612 /* Can we write (and insert) onto the parent directory? */
3613 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3614 goto Bad_CreateFile;
3616 /* get a new vnode for the file to be created and set it up */
3618 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3619 vFile, nBlocks(0)))) {
3620 goto Bad_CreateFile;
3623 /* update the status of the parent vnode */
3624 #if FS_STATS_DETAILED
3625 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3626 parentptr->disk.linkCount,
3627 client->InSameNetwork);
3629 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3630 parentptr->disk.linkCount);
3631 #endif /* FS_STATS_DETAILED */
3633 /* update the status of the new file's vnode */
3634 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3635 parentptr, volptr, 0);
3637 /* 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 */
3638 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3639 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3641 /* convert the write lock to a read lock before breaking callbacks */
3642 VVnodeWriteToRead(&errorCode, parentptr);
3643 assert(!errorCode || errorCode == VSALVAGE);
3645 /* break call back on parent dir */
3646 BreakCallBack(client->host, DirFid, 0);
3648 /* Return a callback promise for the newly created file to the caller */
3649 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3652 /* Update and store volume/vnode and parent vnodes back */
3653 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3656 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3659 } /*SAFSS_CreateFile */
3663 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3664 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3665 struct AFSFetchStatus * OutFidStatus,
3666 struct AFSFetchStatus * OutDirStatus,
3667 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3670 struct rx_connection *tcon;
3671 #if FS_STATS_DETAILED
3672 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3673 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3674 struct timeval elapsedTime; /* Transfer time */
3677 * Set our stats pointer, remember when the RPC operation started, and
3678 * tally the operation.
3680 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3684 TM_GetTimeOfDay(&opStartTime, 0);
3685 #endif /* FS_STATS_DETAILED */
3687 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3688 goto Bad_CreateFile;
3691 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3692 OutDirStatus, CallBack, Sync);
3695 code = CallPostamble(tcon, code);
3697 #if FS_STATS_DETAILED
3698 TM_GetTimeOfDay(&opStopTime, 0);
3701 (opP->numSuccesses)++;
3702 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3703 fs_stats_AddTo((opP->sumTime), elapsedTime);
3704 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3705 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3706 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3708 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3709 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3713 #endif /* FS_STATS_DETAILED */
3715 osi_auditU(acall, CreateFileEvent, code, AUD_FID, DirFid, AUD_STR, Name,
3719 } /*SRXAFS_CreateFile */
3723 * This routine is called exclusively from SRXAFS_Rename(), and should be
3724 * merged in when possible.
3727 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3728 struct AFSFid *NewDirFid, char *NewName,
3729 struct AFSFetchStatus *OutOldDirStatus,
3730 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3732 Vnode *oldvptr = 0; /* vnode of the old Directory */
3733 Vnode *newvptr = 0; /* vnode of the new Directory */
3734 Vnode *fileptr = 0; /* vnode of the file to move */
3735 Vnode *newfileptr = 0; /* vnode of the file to delete */
3736 Vnode *testvptr = 0; /* used in directory tree walk */
3737 Vnode *parent = 0; /* parent for use in SetAccessList */
3738 int errorCode = 0; /* error code */
3739 int fileCode = 0; /* used when writing Vnodes */
3740 VnodeId testnode; /* used in directory tree walk */
3741 AFSFid fileFid; /* Fid of file to move */
3742 AFSFid newFileFid; /* Fid of new file */
3743 DirHandle olddir; /* Handle for dir package I/O */
3744 DirHandle newdir; /* Handle for dir package I/O */
3745 DirHandle filedir; /* Handle for dir package I/O */
3746 DirHandle newfiledir; /* Handle for dir package I/O */
3747 Volume *volptr = 0; /* pointer to the volume header */
3748 struct client *client; /* pointer to client structure */
3749 afs_int32 rights, anyrights; /* rights for this and any user */
3750 afs_int32 newrights; /* rights for this user */
3751 afs_int32 newanyrights; /* rights for any user */
3752 int doDelete; /* deleted the rename target (ref count now 0) */
3754 struct client *t_client; /* tmp ptr to client data */
3755 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3756 struct rx_connection *tcon = rx_ConnectionOf(acall);
3761 FidZero(&newfiledir);
3763 /* Get ptr to client data for user Id for logging */
3764 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3765 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3767 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s, Id %d\n",
3768 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3769 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3770 NewDirFid->Unique, inet_ntoa(logHostAddr), t_client->ViceId));
3772 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3774 if (!FileNameOK(NewName)) {
3778 if (OldDirFid->Volume != NewDirFid->Volume) {
3783 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3784 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3785 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3791 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3793 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3794 &parent, &client, WRITE_LOCK, &rights,
3799 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3801 newrights = rights, newanyrights = anyrights;
3804 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3805 MustBeDIR, &parent, &client, WRITE_LOCK,
3806 &newrights, &newanyrights))) {
3812 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3813 &parent, &client, WRITE_LOCK, &newrights,
3819 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3820 &parent, &client, WRITE_LOCK, &rights,
3827 /* set volume synchronization information */
3828 SetVolumeSync(Sync, volptr);
3830 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3833 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3837 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3838 * call to CopyOnWrite returns error, it is not necessary to revert back
3839 * the effects of the first call because the contents of the volume is
3840 * not modified, it is only replicated.
3842 if (oldvptr->disk.cloned) {
3843 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3844 if ((errorCode = CopyOnWrite(oldvptr, volptr)))
3847 SetDirHandle(&olddir, oldvptr);
3848 if (newvptr->disk.cloned) {
3849 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3850 if ((errorCode = CopyOnWrite(newvptr, volptr)))
3854 SetDirHandle(&newdir, newvptr);
3856 /* Lookup the file to delete its vnode */
3857 if (Lookup(&olddir, OldName, &fileFid)) {
3861 if (fileFid.Vnode == oldvptr->vnodeNumber
3862 || fileFid.Vnode == newvptr->vnodeNumber) {
3863 errorCode = FSERR_ELOOP;
3866 fileFid.Volume = V_id(volptr);
3867 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3868 if (errorCode != 0) {
3870 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3871 OldName, errorCode));
3872 VTakeOffline(volptr);
3875 if (fileptr->disk.uniquifier != fileFid.Unique) {
3877 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3879 VTakeOffline(volptr);
3884 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3885 && fileptr->disk.linkCount != 1) {
3887 * Hard links exist to this file - cannot move one of the links to
3888 * a new directory because of AFS restrictions (this is the same
3889 * reason that links cannot be made across directories, i.e.
3896 /* Lookup the new file */
3897 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3898 if (readonlyServer) {
3899 errorCode = VREADONLY;
3902 if (!(newrights & PRSFS_DELETE)) {
3906 if (newFileFid.Vnode == oldvptr->vnodeNumber
3907 || newFileFid.Vnode == newvptr->vnodeNumber
3908 || newFileFid.Vnode == fileFid.Vnode) {
3912 newFileFid.Volume = V_id(volptr);
3914 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3915 if (errorCode != 0) {
3917 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3918 NewName, errorCode));
3919 VTakeOffline(volptr);
3922 if (fileptr->disk.uniquifier != fileFid.Unique) {
3924 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3926 VTakeOffline(volptr);
3930 SetDirHandle(&newfiledir, newfileptr);
3931 /* Now check that we're moving directories over directories properly, etc.
3932 * return proper POSIX error codes:
3933 * if fileptr is a file and new is a dir: EISDIR.
3934 * if fileptr is a dir and new is a file: ENOTDIR.
3935 * Also, dir to be removed must be empty, of course.
3937 if (newfileptr->disk.type == vDirectory) {
3938 if (fileptr->disk.type != vDirectory) {
3942 if ((IsEmpty(&newfiledir))) {
3947 if (fileptr->disk.type == vDirectory) {
3948 errorCode = ENOTDIR;
3955 * ok - now we check that the old name is not above new name in the
3956 * directory structure. This is to prevent removing a subtree alltogether
3958 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3959 afs_int32 forpass = 0, vnum = 0, top = 0;
3960 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3961 if (testnode > vnum) vnum = testnode;
3962 if (forpass > vnum) {
3963 errorCode = FSERR_ELOOP;
3966 if (testnode == oldvptr->vnodeNumber) {
3967 testnode = oldvptr->disk.parent;
3970 if ((testnode == fileptr->vnodeNumber)
3971 || (testnode == newvptr->vnodeNumber)) {
3972 errorCode = FSERR_ELOOP;
3975 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3976 errorCode = FSERR_ELOOP;
3979 if (testnode == 1) top = 1;
3980 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3981 assert(errorCode == 0);
3982 testnode = testvptr->disk.parent;
3983 VPutVnode(&errorCode, testvptr);
3984 if ((top == 1) && (testnode != 0)) {
3985 VTakeOffline(volptr);
3989 assert(errorCode == 0);
3992 /* Do the CopyonWrite first before modifying anything else. Copying is
3993 * required because we may have to change entries for ..
3995 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
3996 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3997 if ((errorCode = CopyOnWrite(fileptr, volptr)))
4001 /* If the new name exists already, delete it and the file it points to */
4004 /* Delete NewName from its directory */
4005 code = Delete(&newdir, NewName);
4008 /* Drop the link count */
4009 newfileptr->disk.linkCount--;
4010 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4011 afs_fsize_t newSize;
4012 VN_GET_LEN(newSize, newfileptr);
4013 VAdjustDiskUsage((Error *) & errorCode, volptr,
4014 (afs_sfsize_t) - nBlocks(newSize), 0);
4015 if (VN_GET_INO(newfileptr)) {
4016 IH_REALLYCLOSE(newfileptr->handle);
4018 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4019 V_parentId(volptr));
4020 IH_RELEASE(newfileptr->handle);
4021 if (errorCode == -1) {
4023 ("Del: inode=%s, name=%s, errno=%d\n",
4024 PrintInode(NULL, VN_GET_INO(newfileptr)),
4026 if ((errno != ENOENT) && (errno != EIO)
4027 && (errno != ENXIO))
4028 ViceLog(0, ("Do we need to fsck?"));
4031 VN_SET_INO(newfileptr, (Inode) 0);
4032 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4035 /* Link count did not drop to zero.
4036 * Mark NewName vnode as changed - updates stime.
4038 newfileptr->changed_newTime = 1;
4043 * If the create below fails, and the delete above worked, we have
4044 * removed the new name and not replaced it. This is not very likely,
4045 * but possible. We could try to put the old file back, but it is
4046 * highly unlikely that it would work since it would involve issuing
4049 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4052 /* Delete the old name */
4053 assert(Delete(&olddir, (char *)OldName) == 0);
4055 /* if the directory length changes, reflect it in the statistics */
4056 #if FS_STATS_DETAILED
4057 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4058 oldvptr->disk.linkCount, client->InSameNetwork);
4059 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4060 newvptr->disk.linkCount, client->InSameNetwork);
4062 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4063 oldvptr->disk.linkCount);
4064 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4065 newvptr->disk.linkCount);
4066 #endif /* FS_STATS_DETAILED */
4068 if (oldvptr == newvptr)
4069 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4071 fileptr->disk.parent = newvptr->vnodeNumber;
4072 fileptr->changed_newTime = 1; /* status change of moved file */
4074 /* if we are dealing with a rename of a directory */
4075 if (fileptr->disk.type == vDirectory) {
4076 assert(!fileptr->disk.cloned);
4077 SetDirHandle(&filedir, fileptr);
4078 /* fix .. to point to the correct place */
4079 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4080 assert(Create(&filedir, "..", NewDirFid) == 0);
4081 fileptr->disk.dataVersion++;
4082 /* if the parent directories are different the link counts have to be */
4083 /* changed due to .. in the renamed directory */
4084 if (oldvptr != newvptr) {
4085 oldvptr->disk.linkCount--;
4086 newvptr->disk.linkCount++;
4090 /* set up return status */
4091 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4092 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4093 if (newfileptr && doDelete) {
4094 DeleteFileCallBacks(&newFileFid); /* no other references */
4099 /* convert the write locks to a read locks before breaking callbacks */
4100 VVnodeWriteToRead(&errorCode, newvptr);
4101 assert(!errorCode || errorCode == VSALVAGE);
4102 if (oldvptr != newvptr) {
4103 VVnodeWriteToRead(&errorCode, oldvptr);
4104 assert(!errorCode || errorCode == VSALVAGE);
4106 if (newfileptr && !doDelete) {
4107 /* convert the write lock to a read lock before breaking callbacks */
4108 VVnodeWriteToRead(&errorCode, newfileptr);
4109 assert(!errorCode || errorCode == VSALVAGE);
4112 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4113 BreakCallBack(client->host, NewDirFid, 0);
4114 if (oldvptr != newvptr) {
4115 BreakCallBack(client->host, OldDirFid, 0);
4116 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4117 BreakCallBack(client->host, &fileFid, 0);
4120 /* Note: it is not necessary to break the callback */
4122 DeleteFileCallBacks(&newFileFid); /* no other references */
4124 /* other's still exist (with wrong link count) */
4125 BreakCallBack(client->host, &newFileFid, 1);
4130 VPutVnode(&fileCode, newfileptr);
4131 assert(fileCode == 0);
4133 (void)PutVolumePackage(fileptr,
4135 && newvptr != oldvptr ? newvptr : 0), oldvptr,
4140 FidZap(&newfiledir);
4141 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4148 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4149 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4150 struct AFSFetchStatus * OutOldDirStatus,
4151 struct AFSFetchStatus * OutNewDirStatus,
4152 struct AFSVolSync * Sync)
4155 struct rx_connection *tcon;
4156 #if FS_STATS_DETAILED
4157 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4158 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4159 struct timeval elapsedTime; /* Transfer time */
4162 * Set our stats pointer, remember when the RPC operation started, and
4163 * tally the operation.
4165 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4169 TM_GetTimeOfDay(&opStartTime, 0);
4170 #endif /* FS_STATS_DETAILED */
4172 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4176 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4177 OutOldDirStatus, OutNewDirStatus, Sync);
4180 code = CallPostamble(tcon, code);
4182 #if FS_STATS_DETAILED
4183 TM_GetTimeOfDay(&opStopTime, 0);
4186 (opP->numSuccesses)++;
4187 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4188 fs_stats_AddTo((opP->sumTime), elapsedTime);
4189 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4190 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4191 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4193 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4194 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4198 #endif /* FS_STATS_DETAILED */
4200 osi_auditU(acall, RenameFileEvent, code, AUD_FID, OldDirFid, AUD_STR,
4201 OldName, AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4204 } /*SRXAFS_Rename */
4208 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4209 * merged into it when possible.
4212 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4213 char *LinkContents, struct AFSStoreStatus *InStatus,
4214 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4215 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4217 Vnode *parentptr = 0; /* vnode of input Directory */
4218 Vnode *targetptr = 0; /* vnode of the new link */
4219 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4220 int errorCode = 0; /* error code */
4222 DirHandle dir; /* Handle for dir package I/O */
4223 Volume *volptr = 0; /* pointer to the volume header */
4224 struct client *client; /* pointer to client structure */
4225 afs_int32 rights, anyrights; /* rights for this and any user */
4226 struct client *t_client; /* tmp ptr to client data */
4227 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4229 struct rx_connection *tcon = rx_ConnectionOf(acall);
4233 /* Get ptr to client data for user Id for logging */
4234 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4235 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4237 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s, Id %d\n", Name,
4238 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4239 inet_ntoa(logHostAddr), t_client->ViceId));
4241 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4243 if (!FileNameOK(Name)) {
4249 * Get the vnode and volume for the parent dir along with the caller's
4253 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4254 &parentwhentargetnotdir, &client, WRITE_LOCK,
4255 &rights, &anyrights))) {
4259 /* set volume synchronization information */
4260 SetVolumeSync(Sync, volptr);
4262 /* Does the caller has insert (and write) access to the parent directory? */
4263 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4268 * If we're creating a mount point (any x bits clear), we must have
4269 * administer access to the directory, too. Always allow sysadmins
4272 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4273 if (readonlyServer) {
4274 errorCode = VREADONLY;
4278 * We have a mountpoint, 'cause we're trying to set the Unix mode
4279 * bits to something with some x bits missing (default mode bits
4280 * if AFS_SETMODE is false is 0777)
4282 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4288 /* get a new vnode for the symlink and set it up */
4290 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4291 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4295 /* update the status of the parent vnode */
4296 #if FS_STATS_DETAILED
4297 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4298 parentptr->disk.linkCount,
4299 client->InSameNetwork);
4301 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4302 parentptr->disk.linkCount);
4303 #endif /* FS_STATS_DETAILED */
4305 /* update the status of the new symbolic link file vnode */
4306 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4307 parentptr, volptr, strlen((char *)LinkContents));
4309 /* Write the contents of the symbolic link name into the target inode */
4310 fdP = IH_OPEN(targetptr->handle);
4311 assert(fdP != NULL);
4312 assert(FDH_WRITE(fdP, (char *)LinkContents, strlen((char *)LinkContents))
4313 == strlen((char *)LinkContents));
4316 * Set up and return modified status for the parent dir and new symlink
4319 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4320 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4322 /* convert the write lock to a read lock before breaking callbacks */
4323 VVnodeWriteToRead(&errorCode, parentptr);
4324 assert(!errorCode || errorCode == VSALVAGE);
4326 /* break call back on the parent dir */
4327 BreakCallBack(client->host, DirFid, 0);
4330 /* Write the all modified vnodes (parent, new files) and volume back */
4331 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4334 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4337 } /*SAFSS_Symlink */
4341 SRXAFS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4342 OutFidStatus, OutDirStatus, Sync)
4343 struct AFSVolSync *Sync;
4344 struct rx_call *acall; /* Rx call */
4345 struct AFSFid *DirFid; /* Parent dir's fid */
4346 char *Name; /* File name to create */
4347 char *LinkContents; /* Contents of the new created file */
4348 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
4349 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
4350 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
4351 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
4355 struct rx_connection *tcon;
4356 #if FS_STATS_DETAILED
4357 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4358 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4359 struct timeval elapsedTime; /* Transfer time */
4362 * Set our stats pointer, remember when the RPC operation started, and
4363 * tally the operation.
4365 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4369 TM_GetTimeOfDay(&opStartTime, 0);
4370 #endif /* FS_STATS_DETAILED */
4372 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4376 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4377 OutFidStatus, OutDirStatus, Sync);
4380 code = CallPostamble(tcon, code);
4382 #if FS_STATS_DETAILED
4383 TM_GetTimeOfDay(&opStopTime, 0);
4386 (opP->numSuccesses)++;
4387 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4388 fs_stats_AddTo((opP->sumTime), elapsedTime);
4389 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4390 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4391 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4393 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4394 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4398 #endif /* FS_STATS_DETAILED */
4400 osi_auditU(acall, SymlinkEvent, code, AUD_FID, DirFid, AUD_STR, Name,
4404 } /*SRXAFS_Symlink */
4408 * This routine is called exclusively by SRXAFS_Link(), and should be
4409 * merged into it when possible.
4412 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4413 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4414 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4416 Vnode *parentptr = 0; /* vnode of input Directory */
4417 Vnode *targetptr = 0; /* vnode of the new file */
4418 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4419 Volume *volptr = 0; /* pointer to the volume header */
4420 int errorCode = 0; /* error code */
4421 DirHandle dir; /* Handle for dir package I/O */
4422 struct client *client; /* pointer to client structure */
4423 afs_int32 rights, anyrights; /* rights for this and any user */
4424 struct client *t_client; /* tmp ptr to client data */
4425 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4426 struct rx_connection *tcon = rx_ConnectionOf(acall);
4430 /* Get ptr to client data for user Id for logging */
4431 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4432 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4434 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s, Id %d\n",
4435 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4436 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4437 inet_ntoa(logHostAddr), t_client->ViceId));
4439 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4441 if (DirFid->Volume != ExistingFid->Volume) {
4445 if (!FileNameOK(Name)) {
4451 * Get the vnode and volume for the parent dir along with the caller's
4455 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4456 &parentwhentargetnotdir, &client, WRITE_LOCK,
4457 &rights, &anyrights))) {
4461 /* set volume synchronization information */
4462 SetVolumeSync(Sync, volptr);
4464 /* Can the caller insert into the parent directory? */
4465 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4469 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4470 /* AFS fileservers always have directory vnodes that are odd. */
4475 /* get the file vnode */
4477 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4480 if (targetptr->disk.type != vFile) {
4484 if (targetptr->disk.parent != DirFid->Vnode) {
4488 if (parentptr->disk.cloned) {
4489 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4490 if ((errorCode = CopyOnWrite(parentptr, volptr)))
4491 goto Bad_Link; /* disk full error */
4494 /* add the name to the directory */
4495 SetDirHandle(&dir, parentptr);
4496 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4500 /* update the status in the parent vnode */
4501 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4502 #if FS_STATS_DETAILED
4503 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4504 parentptr->disk.linkCount,
4505 client->InSameNetwork);
4507 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4508 parentptr->disk.linkCount);
4509 #endif /* FS_STATS_DETAILED */
4511 targetptr->disk.linkCount++;
4512 targetptr->disk.author = client->ViceId;
4513 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4515 /* set up return status */
4516 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4517 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4519 /* convert the write locks to read locks before breaking callbacks */
4520 VVnodeWriteToRead(&errorCode, targetptr);
4521 assert(!errorCode || errorCode == VSALVAGE);
4522 VVnodeWriteToRead(&errorCode, parentptr);
4523 assert(!errorCode || errorCode == VSALVAGE);
4525 /* break call back on DirFid */
4526 BreakCallBack(client->host, DirFid, 0);
4528 * We also need to break the callback for the file that is hard-linked since part
4529 * of its status (like linkcount) is changed
4531 BreakCallBack(client->host, ExistingFid, 0);
4534 /* Write the all modified vnodes (parent, new files) and volume back */
4535 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4538 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4545 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4546 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4547 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4550 struct rx_connection *tcon;
4551 #if FS_STATS_DETAILED
4552 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4553 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4554 struct timeval elapsedTime; /* Transfer time */
4557 * Set our stats pointer, remember when the RPC operation started, and
4558 * tally the operation.
4560 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4564 TM_GetTimeOfDay(&opStartTime, 0);
4565 #endif /* FS_STATS_DETAILED */
4567 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4571 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4572 OutDirStatus, Sync);
4575 code = CallPostamble(tcon, code);
4577 #if FS_STATS_DETAILED
4578 TM_GetTimeOfDay(&opStopTime, 0);
4581 (opP->numSuccesses)++;
4582 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4583 fs_stats_AddTo((opP->sumTime), elapsedTime);
4584 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4585 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4586 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4588 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4589 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4593 #endif /* FS_STATS_DETAILED */
4595 osi_auditU(acall, LinkEvent, code, AUD_FID, DirFid, AUD_STR, Name,
4596 AUD_FID, ExistingFid, AUD_END);
4603 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4604 * merged into it when possible.
4607 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4608 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4609 struct AFSFetchStatus *OutFidStatus,
4610 struct AFSFetchStatus *OutDirStatus,
4611 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4613 Vnode *parentptr = 0; /* vnode of input Directory */
4614 Vnode *targetptr = 0; /* vnode of the new file */
4615 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4616 Volume *volptr = 0; /* pointer to the volume header */
4617 int errorCode = 0; /* error code */
4618 struct acl_accessList *newACL; /* Access list */
4619 int newACLSize; /* Size of access list */
4620 DirHandle dir; /* Handle for dir package I/O */
4621 DirHandle parentdir; /* Handle for dir package I/O */
4622 struct client *client; /* pointer to client structure */
4623 afs_int32 rights, anyrights; /* rights for this and any user */
4624 struct client *t_client; /* tmp ptr to client data */
4625 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4626 struct rx_connection *tcon = rx_ConnectionOf(acall);
4629 FidZero(&parentdir);
4631 /* Get ptr to client data for user Id for logging */
4632 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4633 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4635 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s, Id %d\n", Name,
4636 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4637 inet_ntoa(logHostAddr), t_client->ViceId));
4639 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4641 if (!FileNameOK(Name)) {
4647 * Get the vnode and volume for the parent dir along with the caller's
4651 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4652 &parentwhentargetnotdir, &client, WRITE_LOCK,
4653 &rights, &anyrights))) {
4657 /* set volume synchronization information */
4658 SetVolumeSync(Sync, volptr);
4660 /* Write access to the parent directory? */
4661 #ifdef DIRCREATE_NEED_WRITE
4663 * requires w access for the user to create a directory. this
4664 * closes a loophole in the current security arrangement, since a
4665 * user with i access only can create a directory and get the
4666 * implcit a access that goes with dir ownership, and proceed to
4667 * subvert quota in the volume.
4669 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4670 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4672 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4673 #endif /* DIRCREATE_NEED_WRITE */
4676 #define EMPTYDIRBLOCKS 2
4677 /* get a new vnode and set it up */
4679 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4680 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4684 /* Update the status for the parent dir */
4685 #if FS_STATS_DETAILED
4686 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4687 parentptr->disk.linkCount + 1,
4688 client->InSameNetwork);
4690 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4691 parentptr->disk.linkCount + 1);
4692 #endif /* FS_STATS_DETAILED */
4694 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4695 assert((SetAccessList
4696 (&targetptr, &volptr, &newACL, &newACLSize,
4697 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4698 assert(parentwhentargetnotdir == 0);
4699 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4701 /* update the status for the target vnode */
4702 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4703 parentptr, volptr, 0);
4705 /* Actually create the New directory in the directory package */
4706 SetDirHandle(&dir, targetptr);
4707 assert(!(MakeDir(&dir, OutFid, DirFid)));
4709 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4711 /* set up return status */
4712 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4713 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4715 /* convert the write lock to a read lock before breaking callbacks */
4716 VVnodeWriteToRead(&errorCode, parentptr);
4717 assert(!errorCode || errorCode == VSALVAGE);
4719 /* break call back on DirFid */
4720 BreakCallBack(client->host, DirFid, 0);
4722 /* Return a callback promise to caller */
4723 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4726 /* Write the all modified vnodes (parent, new files) and volume back */
4727 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4731 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4734 } /*SAFSS_MakeDir */
4738 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4739 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4740 struct AFSFetchStatus * OutFidStatus,
4741 struct AFSFetchStatus * OutDirStatus,
4742 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4745 struct rx_connection *tcon;
4746 #if FS_STATS_DETAILED
4747 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4748 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4749 struct timeval elapsedTime; /* Transfer time */
4752 * Set our stats pointer, remember when the RPC operation started, and
4753 * tally the operation.
4755 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4759 TM_GetTimeOfDay(&opStartTime, 0);
4760 #endif /* FS_STATS_DETAILED */
4761 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4765 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4766 OutDirStatus, CallBack, Sync);
4769 code = CallPostamble(tcon, code);
4771 #if FS_STATS_DETAILED
4772 TM_GetTimeOfDay(&opStopTime, 0);
4775 (opP->numSuccesses)++;
4776 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4777 fs_stats_AddTo((opP->sumTime), elapsedTime);
4778 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4779 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4780 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4782 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4783 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4787 #endif /* FS_STATS_DETAILED */
4789 osi_auditU(acall, MakeDirEvent, code, AUD_FID, DirFid, AUD_STR, Name,
4793 } /*SRXAFS_MakeDir */
4797 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4798 * merged into it when possible.
4801 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4802 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4804 Vnode *parentptr = 0; /* vnode of input Directory */
4805 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4806 Vnode *targetptr = 0; /* file to be deleted */
4807 AFSFid fileFid; /* area for Fid from the directory */
4808 int errorCode = 0; /* error code */
4809 DirHandle dir; /* Handle for dir package I/O */
4810 Volume *volptr = 0; /* pointer to the volume header */
4811 struct client *client; /* pointer to client structure */
4812 afs_int32 rights, anyrights; /* rights for this and any user */
4813 Vnode debugvnode1, debugvnode2;
4814 struct client *t_client; /* tmp ptr to client data */
4815 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4816 struct rx_connection *tcon = rx_ConnectionOf(acall);
4820 /* Get ptr to client data for user Id for logging */
4821 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4822 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4824 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s, Id %d\n", Name,
4825 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4826 inet_ntoa(logHostAddr), t_client->ViceId));
4828 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4831 * Get the vnode and volume for the parent dir along with the caller's
4835 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4836 &parentwhentargetnotdir, &client, WRITE_LOCK,
4837 &rights, &anyrights))) {
4840 debugvnode1 = *parentptr;
4842 /* set volume synchronization information */
4843 SetVolumeSync(Sync, volptr);
4845 /* Does the caller has delete (&write) access to the parent dir? */
4846 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4850 debugvnode2 = *parentptr;
4851 /* Do the actual delete of the desired (empty) directory, Name */
4853 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4858 /* Update the status for the parent dir; link count is also adjusted */
4859 #if FS_STATS_DETAILED
4860 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4861 parentptr->disk.linkCount - 1,
4862 client->InSameNetwork);
4864 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4865 parentptr->disk.linkCount - 1);
4866 #endif /* FS_STATS_DETAILED */
4868 /* Return to the caller the updated parent dir status */
4869 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4872 * Note: it is not necessary to break the callback on fileFid, since
4873 * refcount is now 0, so no one should be able to refer to the dir
4876 DeleteFileCallBacks(&fileFid);
4878 /* convert the write lock to a read lock before breaking callbacks */
4879 VVnodeWriteToRead(&errorCode, parentptr);
4880 assert(!errorCode || errorCode == VSALVAGE);
4882 /* break call back on DirFid and fileFid */
4883 BreakCallBack(client->host, DirFid, 0);
4886 /* Write the all modified vnodes (parent, new files) and volume back */
4887 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4890 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4893 } /*SAFSS_RemoveDir */
4897 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4898 struct AFSFetchStatus * OutDirStatus,
4899 struct AFSVolSync * Sync)
4902 struct rx_connection *tcon;
4903 #if FS_STATS_DETAILED
4904 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4905 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4906 struct timeval elapsedTime; /* Transfer time */
4909 * Set our stats pointer, remember when the RPC operation started, and
4910 * tally the operation.
4912 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
4916 TM_GetTimeOfDay(&opStartTime, 0);
4917 #endif /* FS_STATS_DETAILED */
4919 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4922 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4925 code = CallPostamble(tcon, code);
4927 #if FS_STATS_DETAILED
4928 TM_GetTimeOfDay(&opStopTime, 0);
4931 (opP->numSuccesses)++;
4932 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4933 fs_stats_AddTo((opP->sumTime), elapsedTime);
4934 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4935 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4936 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4938 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4939 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4943 #endif /* FS_STATS_DETAILED */
4945 osi_auditU(acall, RemoveDirEvent, code, AUD_FID, DirFid, AUD_STR, Name,
4949 } /*SRXAFS_RemoveDir */
4953 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4954 * merged into it when possible.
4957 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4958 struct AFSVolSync *Sync)
4960 Vnode *targetptr = 0; /* vnode of input file */
4961 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4962 int errorCode = 0; /* error code */
4963 Volume *volptr = 0; /* pointer to the volume header */
4964 struct client *client; /* pointer to client structure */
4965 afs_int32 rights, anyrights; /* rights for this and any user */
4966 struct client *t_client; /* tmp ptr to client data */
4967 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4968 static char *locktype[2] = { "LockRead", "LockWrite" };
4969 struct rx_connection *tcon = rx_ConnectionOf(acall);
4971 if (type != LockRead && type != LockWrite) {
4975 /* Get ptr to client data for user Id for logging */
4976 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4977 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4979 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s, Id %d\n",
4980 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4981 inet_ntoa(logHostAddr), t_client->ViceId));
4983 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4986 * Get the vnode and volume for the desired file along with the caller's
4990 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
4991 &parentwhentargetnotdir, &client, WRITE_LOCK,
4992 &rights, &anyrights))) {
4996 /* set volume synchronization information */
4997 SetVolumeSync(Sync, volptr);
4999 /* Handle the particular type of set locking, type */
5000 errorCode = HandleLocking(targetptr, rights, type);
5003 /* Write the all modified vnodes (parent, new files) and volume back */
5004 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5007 if ((errorCode == VREADONLY) && (type == LockRead))
5008 errorCode = 0; /* allow read locks on RO volumes without saving state */
5010 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5013 } /*SAFSS_SetLock */
5017 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5018 ViceLockType type, struct AFSVolSync * Sync)
5020 return SRXAFS_SetLock(acall, Fid, type, Sync);
5022 } /*SRXAFS_OldSetLock */
5026 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5027 struct AFSVolSync * Sync)
5030 struct rx_connection *tcon;
5031 #if FS_STATS_DETAILED
5032 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5033 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5034 struct timeval elapsedTime; /* Transfer time */
5037 * Set our stats pointer, remember when the RPC operation started, and
5038 * tally the operation.
5040 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5044 TM_GetTimeOfDay(&opStartTime, 0);
5045 #endif /* FS_STATS_DETAILED */
5047 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5050 code = SAFSS_SetLock(acall, Fid, type, Sync);
5053 code = CallPostamble(tcon, code);
5055 #if FS_STATS_DETAILED
5056 TM_GetTimeOfDay(&opStopTime, 0);
5059 (opP->numSuccesses)++;
5060 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5061 fs_stats_AddTo((opP->sumTime), elapsedTime);
5062 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5063 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5064 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5066 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5067 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5071 #endif /* FS_STATS_DETAILED */
5073 osi_auditU(acall, SetLockEvent, code, AUD_FID, Fid, AUD_LONG, type,
5077 } /*SRXAFS_SetLock */
5081 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5082 * merged into it when possible.
5085 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5086 struct AFSVolSync *Sync)
5088 Vnode *targetptr = 0; /* vnode of input file */
5089 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5090 int errorCode = 0; /* error code */
5091 Volume *volptr = 0; /* pointer to the volume header */
5092 struct client *client; /* pointer to client structure */
5093 afs_int32 rights, anyrights; /* rights for this and any user */
5094 struct client *t_client; /* tmp ptr to client data */
5095 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5096 struct rx_connection *tcon = rx_ConnectionOf(acall);
5098 /* Get ptr to client data for user Id for logging */
5099 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5100 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
5102 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s, Id %d\n", Fid->Volume,
5103 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5106 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5109 * Get the vnode and volume for the desired file along with the caller's
5113 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5114 &parentwhentargetnotdir, &client, WRITE_LOCK,
5115 &rights, &anyrights))) {
5116 goto Bad_ExtendLock;
5119 /* set volume synchronization information */
5120 SetVolumeSync(Sync, volptr);
5122 /* Handle the actual lock extension */
5123 errorCode = HandleLocking(targetptr, rights, LockExtend);
5126 /* Put back file's vnode and volume */
5127 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5130 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5131 errorCode = 0; /* under our generous policy re RO vols */
5133 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5136 } /*SAFSS_ExtendLock */
5140 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5141 struct AFSVolSync * Sync)
5143 return SRXAFS_ExtendLock(acall, Fid, Sync);
5145 } /*SRXAFS_OldExtendLock */
5149 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5150 struct AFSVolSync * Sync)
5153 struct rx_connection *tcon;
5154 #if FS_STATS_DETAILED
5155 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5156 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5157 struct timeval elapsedTime; /* Transfer time */
5160 * Set our stats pointer, remember when the RPC operation started, and
5161 * tally the operation.
5163 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5167 TM_GetTimeOfDay(&opStartTime, 0);
5168 #endif /* FS_STATS_DETAILED */
5170 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5171 goto Bad_ExtendLock;
5173 code = SAFSS_ExtendLock(acall, Fid, Sync);
5176 code = CallPostamble(tcon, code);
5178 #if FS_STATS_DETAILED
5179 TM_GetTimeOfDay(&opStopTime, 0);
5182 (opP->numSuccesses)++;
5183 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5184 fs_stats_AddTo((opP->sumTime), elapsedTime);
5185 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5186 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5187 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5189 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5190 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5194 #endif /* FS_STATS_DETAILED */
5196 osi_auditU(acall, ExtendLockEvent, code, AUD_FID, Fid, AUD_END);
5199 } /*SRXAFS_ExtendLock */
5203 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5204 * merged into it when possible.
5207 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5208 struct AFSVolSync *Sync)
5210 Vnode *targetptr = 0; /* vnode of input file */
5211 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5212 int errorCode = 0; /* error code */
5213 Volume *volptr = 0; /* pointer to the volume header */
5214 struct client *client; /* pointer to client structure */
5215 afs_int32 rights, anyrights; /* rights for this and any user */
5216 struct client *t_client; /* tmp ptr to client data */
5217 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5218 struct rx_connection *tcon = rx_ConnectionOf(acall);
5220 /* Get ptr to client data for user Id for logging */
5221 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5222 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
5224 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s, Id %d\n", Fid->Volume,
5225 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5228 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5231 * Get the vnode and volume for the desired file along with the caller's
5235 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5236 &parentwhentargetnotdir, &client, WRITE_LOCK,
5237 &rights, &anyrights))) {
5238 goto Bad_ReleaseLock;
5241 /* set volume synchronization information */
5242 SetVolumeSync(Sync, volptr);
5244 /* Handle the actual lock release */
5245 if ((errorCode = HandleLocking(targetptr, rights, LockRelease)))
5246 goto Bad_ReleaseLock;
5248 /* if no more locks left, a callback would be triggered here */
5249 if (targetptr->disk.lock.lockCount <= 0) {
5250 /* convert the write lock to a read lock before breaking callbacks */
5251 VVnodeWriteToRead(&errorCode, targetptr);
5252 assert(!errorCode || errorCode == VSALVAGE);
5253 BreakCallBack(client->host, Fid, 0);
5257 /* Put back file's vnode and volume */
5258 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5261 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5262 errorCode = 0; /* under our generous policy re RO vols */
5264 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5267 } /*SAFSS_ReleaseLock */
5271 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5272 struct AFSVolSync * Sync)
5274 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5276 } /*SRXAFS_OldReleaseLock */
5280 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5281 struct AFSVolSync * Sync)
5284 struct rx_connection *tcon;
5285 #if FS_STATS_DETAILED
5286 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5287 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5288 struct timeval elapsedTime; /* Transfer time */
5291 * Set our stats pointer, remember when the RPC operation started, and
5292 * tally the operation.
5294 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5298 TM_GetTimeOfDay(&opStartTime, 0);
5299 #endif /* FS_STATS_DETAILED */
5301 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5302 goto Bad_ReleaseLock;
5304 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5307 code = CallPostamble(tcon, code);
5309 #if FS_STATS_DETAILED
5310 TM_GetTimeOfDay(&opStopTime, 0);
5313 (opP->numSuccesses)++;
5314 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5315 fs_stats_AddTo((opP->sumTime), elapsedTime);
5316 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5317 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5318 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5320 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5321 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5325 #endif /* FS_STATS_DETAILED */
5327 osi_auditU(acall, ReleaseLockEvent, code, AUD_FID, Fid, AUD_END);
5330 } /*SRXAFS_ReleaseLock */
5334 SetSystemStats(struct AFSStatistics *stats)
5336 /* Fix this sometime soon.. */
5337 /* Because hey, it's not like we have a network monitoring protocol... */
5338 struct timeval time;
5340 /* this works on all system types */
5341 TM_GetTimeOfDay(&time, 0);
5342 stats->CurrentTime = time.tv_sec;
5343 } /*SetSystemStats */
5346 SetAFSStats(struct AFSStatistics *stats)
5348 extern afs_int32 StartTime, CurrentConnections;
5352 stats->CurrentMsgNumber = 0;
5353 stats->OldestMsgNumber = 0;
5354 stats->StartTime = StartTime;
5355 stats->CurrentConnections = CurrentConnections;
5356 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5357 stats->TotalFetchs =
5358 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5359 AFSCallStats.FetchStatus;
5360 stats->FetchDatas = AFSCallStats.FetchData;
5361 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5362 seconds = AFSCallStats.AccumFetchTime / 1000;
5365 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5366 stats->TotalStores =
5367 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5368 AFSCallStats.StoreStatus;
5369 stats->StoreDatas = AFSCallStats.StoreData;
5370 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5371 seconds = AFSCallStats.AccumStoreTime / 1000;
5374 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5376 stats->ProcessSize = -1; /* TODO: */
5378 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5381 h_GetWorkStats((int *)&(stats->WorkStations),
5382 (int *)&(stats->ActiveWorkStations), (int *)0,
5383 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5387 /* Get disk related information from all AFS partitions. */
5390 SetVolumeStats(struct AFSStatistics *stats)
5392 struct DiskPartition *part;
5395 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5396 part = part->next) {
5397 stats->Disks[i].TotalBlocks = part->totalUsable;
5398 stats->Disks[i].BlocksAvailable = part->free;
5399 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5400 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5403 while (i < AFS_MSTATDISKS) {
5404 stats->Disks[i].TotalBlocks = -1;
5407 } /*SetVolumeStats */
5410 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5413 struct rx_connection *tcon;
5414 #if FS_STATS_DETAILED
5415 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5416 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5417 struct timeval elapsedTime; /* Transfer time */
5420 * Set our stats pointer, remember when the RPC operation started, and
5421 * tally the operation.
5423 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5427 TM_GetTimeOfDay(&opStartTime, 0);
5428 #endif /* FS_STATS_DETAILED */
5430 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon)))
5431 goto Bad_GetStatistics;
5433 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5435 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5437 memset(Statistics, 0, sizeof(*Statistics));
5438 SetAFSStats((struct AFSStatistics *)Statistics);
5439 SetVolumeStats((struct AFSStatistics *)Statistics);
5440 SetSystemStats((struct AFSStatistics *)Statistics);
5443 code = CallPostamble(tcon, code);
5445 #if FS_STATS_DETAILED
5446 TM_GetTimeOfDay(&opStopTime, 0);
5449 (opP->numSuccesses)++;
5450 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5451 fs_stats_AddTo((opP->sumTime), elapsedTime);
5452 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5453 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5454 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5456 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5457 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5461 #endif /* FS_STATS_DETAILED */
5465 } /*SRXAFS_GetStatistics */
5468 /*------------------------------------------------------------------------
5469 * EXPORTED SRXAFS_XStatsVersion
5472 * Routine called by the server-side RPC interface to implement
5473 * pulling out the xstat version number for the File Server.
5476 * a_versionP : Ptr to the version number variable to set.
5482 * Nothing interesting.
5486 *------------------------------------------------------------------------*/
5489 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5490 { /*SRXAFS_XStatsVersion */
5492 #if FS_STATS_DETAILED
5493 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5494 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5495 struct timeval elapsedTime; /* Transfer time */
5498 * Set our stats pointer, remember when the RPC operation started, and
5499 * tally the operation.
5501 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5505 TM_GetTimeOfDay(&opStartTime, 0);
5506 #endif /* FS_STATS_DETAILED */
5508 *a_versionP = AFS_XSTAT_VERSION;
5510 #if FS_STATS_DETAILED
5511 TM_GetTimeOfDay(&opStopTime, 0);
5512 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5513 fs_stats_AddTo((opP->sumTime), elapsedTime);
5514 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5515 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5516 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5518 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5519 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5522 (opP->numSuccesses)++;
5524 #endif /* FS_STATS_DETAILED */
5527 } /*SRXAFS_XStatsVersion */
5530 /*------------------------------------------------------------------------
5531 * PRIVATE FillPerfValues
5534 * Routine called to fill a regular performance data structure.
5537 * a_perfP : Ptr to perf structure to fill
5543 * Various collections need this info, so the guts were put in
5544 * this separate routine.
5548 *------------------------------------------------------------------------*/
5551 FillPerfValues(struct afs_PerfStats *a_perfP)
5552 { /*FillPerfValues */
5554 int dir_Buffers; /*# buffers in use by dir package */
5555 int dir_Calls; /*# read calls in dir package */
5556 int dir_IOs; /*# I/O ops in dir package */
5559 * Vnode cache section.
5561 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5562 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5563 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5564 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5565 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5566 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5567 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5568 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5569 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5570 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5571 a_perfP->vcache_H_Entries = VolumeCacheSize;
5572 a_perfP->vcache_H_Gets = VolumeGets;
5573 a_perfP->vcache_H_Replacements = VolumeReplacements;
5576 * Directory section.
5578 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5579 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5580 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5581 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5586 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5587 a_perfP->rx_noPackets_RcvClass =
5588 (afs_int32) rx_stats.receivePktAllocFailures;
5589 a_perfP->rx_noPackets_SendClass =
5590 (afs_int32) rx_stats.sendPktAllocFailures;
5591 a_perfP->rx_noPackets_SpecialClass =
5592 (afs_int32) rx_stats.specialPktAllocFailures;
5593 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5594 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5595 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5596 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5597 a_perfP->rx_noPacketBuffersOnRead =
5598 (afs_int32) rx_stats.noPacketBuffersOnRead;
5599 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5600 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5601 a_perfP->rx_packetsRead_RcvClass =
5602 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5603 a_perfP->rx_packetsRead_SendClass =
5604 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5605 a_perfP->rx_packetsRead_SpecialClass =
5606 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5607 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5608 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5609 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5610 a_perfP->rx_spuriousPacketsRead =
5611 (afs_int32) rx_stats.spuriousPacketsRead;
5612 a_perfP->rx_packetsSent_RcvClass =
5613 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5614 a_perfP->rx_packetsSent_SendClass =
5615 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5616 a_perfP->rx_packetsSent_SpecialClass =
5617 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5618 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5619 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5620 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5621 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5622 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5623 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5624 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5625 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5626 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5627 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5628 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5629 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5630 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5631 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5632 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5633 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5634 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5635 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5636 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5637 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5639 a_perfP->host_NumHostEntries = HTs;
5640 a_perfP->host_HostBlocks = HTBlocks;
5641 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5642 &(a_perfP->host_HostsInSameNetOrSubnet),
5643 &(a_perfP->host_HostsInDiffSubnet),
5644 &(a_perfP->host_HostsInDiffNetwork));
5645 a_perfP->host_NumClients = CEs;
5646 a_perfP->host_ClientBlocks = CEBlocks;
5648 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5649 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5650 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5651 } /*FillPerfValues */
5654 /*------------------------------------------------------------------------
5655 * EXPORTED SRXAFS_GetXStats
5658 * Routine called by the server-side callback RPC interface to
5659 * implement getting the given data collection from the extended
5660 * File Server statistics.
5663 * a_call : Ptr to Rx call on which this request came in.
5664 * a_clientVersionNum : Client version number.
5665 * a_opCode : Desired operation.
5666 * a_serverVersionNumP : Ptr to version number to set.
5667 * a_timeP : Ptr to time value (seconds) to set.
5668 * a_dataP : Ptr to variable array structure to return
5675 * Nothing interesting.
5679 *------------------------------------------------------------------------*/
5682 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5683 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5684 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5685 { /*SRXAFS_GetXStats */
5687 register int code; /*Return value */
5688 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5689 afs_int32 dataBytes; /*Bytes in data buffer */
5690 #if FS_STATS_DETAILED
5691 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5692 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5693 struct timeval elapsedTime; /* Transfer time */
5696 * Set our stats pointer, remember when the RPC operation started, and
5697 * tally the operation.
5699 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5703 TM_GetTimeOfDay(&opStartTime, 0);
5704 #endif /* FS_STATS_DETAILED */
5707 * Record the time of day and the server version number.
5709 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5710 *a_timeP = FT_ApproxTime();
5713 * Stuff the appropriate data in there (assume victory)
5718 ("Received GetXStats call for collection %d\n",
5719 a_collectionNumber));
5723 * We're not keeping stats, so just return successfully with
5726 a_dataP->AFS_CollData_len = 0;
5727 a_dataP->AFS_CollData_val = NULL;
5730 switch (a_collectionNumber) {
5731 case AFS_XSTATSCOLL_CALL_INFO:
5733 * Pass back all the call-count-related data.
5735 * >>> We are forced to allocate a separate area in which to
5736 * >>> put this stuff in by the RPC stub generator, since it
5737 * >>> will be freed at the tail end of the server stub code.
5741 * I don't think call-level stats are being collected yet
5742 * for the File Server.
5744 dataBytes = sizeof(struct afs_Stats);
5745 dataBuffP = (afs_int32 *) malloc(dataBytes);
5746 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5747 a_dataP->AFS_CollData_len = dataBytes >> 2;
5748 a_dataP->AFS_CollData_val = dataBuffP;
5750 a_dataP->AFS_CollData_len = 0;
5751 a_dataP->AFS_CollData_val = NULL;
5755 case AFS_XSTATSCOLL_PERF_INFO:
5757 * Pass back all the regular performance-related data.
5759 * >>> We are forced to allocate a separate area in which to
5760 * >>> put this stuff in by the RPC stub generator, since it
5761 * >>> will be freed at the tail end of the server stub code.
5764 afs_perfstats.numPerfCalls++;
5765 FillPerfValues(&afs_perfstats);
5768 * Don't overwrite the spares at the end.
5771 dataBytes = sizeof(struct afs_PerfStats);
5772 dataBuffP = (afs_int32 *) malloc(dataBytes);
5773 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5774 a_dataP->AFS_CollData_len = dataBytes >> 2;
5775 a_dataP->AFS_CollData_val = dataBuffP;
5778 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5780 * Pass back the full collection of performance-related data.
5781 * We have to stuff the basic, overall numbers in, but the
5782 * detailed numbers are kept in the structure already.
5784 * >>> We are forced to allocate a separate area in which to
5785 * >>> put this stuff in by the RPC stub generator, since it
5786 * >>> will be freed at the tail end of the server stub code.
5789 afs_perfstats.numPerfCalls++;
5790 #if FS_STATS_DETAILED
5791 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5792 FillPerfValues(&afs_FullPerfStats.overall);
5795 * Don't overwrite the spares at the end.
5798 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5799 dataBuffP = (afs_int32 *) malloc(dataBytes);
5800 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5801 a_dataP->AFS_CollData_len = dataBytes >> 2;
5802 a_dataP->AFS_CollData_val = dataBuffP;
5808 * Illegal collection number.
5810 a_dataP->AFS_CollData_len = 0;
5811 a_dataP->AFS_CollData_val = NULL;
5813 } /*Switch on collection number */
5815 #if FS_STATS_DETAILED
5816 TM_GetTimeOfDay(&opStopTime, 0);
5819 (opP->numSuccesses)++;
5820 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5821 fs_stats_AddTo((opP->sumTime), elapsedTime);
5822 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5823 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5824 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5826 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5827 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5831 #endif /* FS_STATS_DETAILED */
5835 } /*SRXAFS_GetXStats */
5839 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5840 struct AFSCBs *CallBackArray)
5842 afs_int32 errorCode = 0;
5844 struct client *client;
5845 struct rx_connection *tcon;
5846 #if FS_STATS_DETAILED
5847 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5848 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5849 struct timeval elapsedTime; /* Transfer time */
5852 * Set our stats pointer, remember when the RPC operation started, and
5853 * tally the operation.
5856 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
5860 TM_GetTimeOfDay(&opStartTime, 0);
5861 #endif /* FS_STATS_DETAILED */
5865 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5866 FidArray->AFSCBFids_len));
5869 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5871 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
5872 goto Bad_GiveUpCallBacks;
5874 if (!FidArray && !CallBackArray) {
5876 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5877 (tcon->peer ? tcon->peer->host : 0)));
5878 errorCode = GetClient(tcon, &client);
5880 DeleteAllCallBacks_r(client->host, 1);
5882 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5884 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5885 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5886 (tcon->peer ? tcon->peer->host : 0)));
5888 goto Bad_GiveUpCallBacks;
5891 errorCode = GetClient(tcon, &client);
5893 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5894 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5895 DeleteCallBack(client->host, fid);
5900 Bad_GiveUpCallBacks:
5901 errorCode = CallPostamble(tcon, errorCode);
5903 #if FS_STATS_DETAILED
5904 TM_GetTimeOfDay(&opStopTime, 0);
5905 if (errorCode == 0) {
5907 (opP->numSuccesses)++;
5908 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5909 fs_stats_AddTo((opP->sumTime), elapsedTime);
5910 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5911 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5912 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5914 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5915 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5919 #endif /* FS_STATS_DETAILED */
5922 } /*common_GiveUpCallBacks */
5926 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5927 struct AFSCBs * CallBackArray)
5929 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5930 } /*SRXAFS_GiveUpCallBacks */
5933 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
5935 return common_GiveUpCallBacks(acall, 0, 0);
5936 } /*SRXAFS_GiveUpAllCallBacks */
5940 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
5941 struct AFSVolumeInfo * avolinfo)
5943 return (VNOVOL); /* XXX Obsolete routine XXX */
5945 } /*SRXAFS_NGetVolumeInfo */
5949 * Dummy routine. Should never be called (the cache manager should only
5950 * invoke this interface when communicating with a AFS/DFS Protocol
5954 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
5955 char *afs_name_p, struct AFSFid * afs_fid_p,
5956 struct AFSFetchStatus * afs_status_p,
5957 struct AFSFetchStatus * afs_dir_status_p,
5958 struct AFSCallBack * afs_callback_p,
5959 struct AFSVolSync * afs_sync_p)
5966 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
5968 afs_int32 *dataBuffP;
5969 afs_int32 dataBytes;
5971 dataBytes = 1 * sizeof(afs_int32);
5972 dataBuffP = (afs_int32 *) malloc(dataBytes);
5973 dataBuffP[0] = CAPABILITY_ERRORTRANS;
5974 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
5975 capabilities->Capabilities_val = dataBuffP;
5981 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
5982 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
5986 afs_int32 nids, naddrs;
5987 afs_int32 *vd, *addr;
5988 int errorCode = 0; /* return code to caller */
5989 struct client *client;
5990 struct rx_connection *tcon = rx_ConnectionOf(acall);
5992 ViceLog(1, ("SRXAFS_FlushCPS\n"));
5994 AFSCallStats.TotalCalls++;
5996 nids = vids->ViceIds_len; /* # of users in here */
5997 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
5998 if (nids < 0 || naddrs < 0) {
6003 vd = vids->ViceIds_val;
6004 for (i = 0; i < nids; i++, vd++) {
6007 client = h_ID2Client(*vd); /* returns client write locked, or NULL */
6011 client->prfail = 2; /* Means re-eval client's cps */
6014 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6017 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6018 free(client->CPS.prlist_val);
6019 client->CPS.prlist_val = NULL;
6020 client->CPS.prlist_len = 0;
6022 ReleaseWriteLock(&client->lock);
6025 addr = addrs->IPAddrs_val;
6026 for (i = 0; i < naddrs; i++, addr++) {
6028 h_flushhostcps(*addr, htons(7001));
6032 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6034 } /*SRXAFS_FlushCPS */
6036 /* worthless hack to let CS keep running ancient software */
6038 afs_vtoi(register char *aname)
6040 register afs_int32 temp;
6044 while ((tc = *aname++)) {
6045 if (tc > '9' || tc < '0')
6046 return 0; /* invalid name */
6054 * may get name or #, but must handle all weird cases (recognize readonly
6055 * or backup volumes by name or #
6058 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6059 register struct VolumeInfo *av)
6061 register int i, j, vol;
6062 afs_int32 mask, whichType;
6063 afs_uint32 *serverHost, *typePtr;
6065 /* figure out what type we want if by name */
6067 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6068 whichType = BACKVOL;
6069 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6074 vol = afs_vtoi(aname);
6076 vol = ave->volumeId[whichType];
6079 * Now vol has volume # we're interested in. Next, figure out the type
6080 * of the volume by looking finding it in the vldb entry
6082 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6085 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6088 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6089 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6090 whichType = BACKVOL;
6092 return EINVAL; /* error: can't find volume in vldb entry */
6094 typePtr = &av->Type0;
6095 serverHost = &av->Server0;
6097 av->Type = whichType;
6098 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6099 if (ave->flags & VLF_RWEXISTS)
6100 typePtr[RWVOL] = ave->volumeId[RWVOL];
6101 if (ave->flags & VLF_ROEXISTS)
6102 typePtr[ROVOL] = ave->volumeId[ROVOL];
6103 if (ave->flags & VLF_BACKEXISTS)
6104 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6106 for (i = 0, j = 0; i < ave->nServers; i++) {
6107 if ((ave->serverFlags[i] & mask) == 0)
6108 continue; /* wrong volume */
6109 serverHost[j] = ave->serverNumber[i];
6112 av->ServerCount = j;
6114 serverHost[j++] = 0; /* bogus 8, but compat only now */
6119 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6121 static struct rx_connection *vlConn = 0;
6122 static int down = 0;
6123 static afs_int32 lastDownTime = 0;
6124 struct vldbentry tve;
6125 struct rx_securityClass *vlSec;
6126 register afs_int32 code;
6129 vlSec = rxnull_NewClientSecurityObject();
6131 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6132 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6134 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6135 return 1; /* failure */
6138 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6140 down = 0; /* call worked */
6143 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6149 /* otherwise convert to old format vldb entry */
6150 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6160 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6161 struct VolumeInfo * avolinfo)
6164 struct rx_connection *tcon;
6165 #if FS_STATS_DETAILED
6166 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6167 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6168 struct timeval elapsedTime; /* Transfer time */
6171 * Set our stats pointer, remember when the RPC operation started, and
6172 * tally the operation.
6174 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6178 TM_GetTimeOfDay(&opStartTime, 0);
6179 #endif /* FS_STATS_DETAILED */
6180 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
6181 goto Bad_GetVolumeInfo;
6184 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6186 code = TryLocalVLServer(avolid, avolinfo);
6188 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6189 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6190 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6191 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6194 code = CallPostamble(tcon, code);
6196 #if FS_STATS_DETAILED
6197 TM_GetTimeOfDay(&opStopTime, 0);
6200 (opP->numSuccesses)++;
6201 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6202 fs_stats_AddTo((opP->sumTime), elapsedTime);
6203 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6204 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6205 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6207 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6208 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6212 #endif /* FS_STATS_DETAILED */
6216 } /*SRXAFS_GetVolumeInfo */
6220 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6221 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6222 char **OfflineMsg, char **Motd)
6224 Vnode *targetptr = 0; /* vnode of the new file */
6225 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6226 int errorCode = 0; /* error code */
6227 Volume *volptr = 0; /* pointer to the volume header */
6228 struct client *client; /* pointer to client entry */
6229 afs_int32 rights, anyrights; /* rights for this and any user */
6231 struct rx_connection *tcon;
6232 #if FS_STATS_DETAILED
6233 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6234 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6235 struct timeval elapsedTime; /* Transfer time */
6238 * Set our stats pointer, remember when the RPC operation started, and
6239 * tally the operation.
6242 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6246 TM_GetTimeOfDay(&opStartTime, 0);
6247 #endif /* FS_STATS_DETAILED */
6249 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6250 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
6251 goto Bad_GetVolumeStatus;
6254 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6258 goto Bad_GetVolumeStatus;
6260 dummyFid.Volume = avolid, dummyFid.Vnode =
6261 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6264 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6265 &parentwhentargetnotdir, &client, READ_LOCK,
6266 &rights, &anyrights)))
6267 goto Bad_GetVolumeStatus;
6269 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6271 goto Bad_GetVolumeStatus;
6273 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6275 Bad_GetVolumeStatus:
6276 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6278 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6279 /* next is to guarantee out strings exist for stub */
6281 *Name = (char *)malloc(1);
6285 *Motd = (char *)malloc(1);
6288 if (*OfflineMsg == 0) {
6289 *OfflineMsg = (char *)malloc(1);
6292 errorCode = CallPostamble(tcon, errorCode);
6294 #if FS_STATS_DETAILED
6295 TM_GetTimeOfDay(&opStopTime, 0);
6296 if (errorCode == 0) {
6298 (opP->numSuccesses)++;
6299 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6300 fs_stats_AddTo((opP->sumTime), elapsedTime);
6301 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6302 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6303 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6305 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6306 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6310 #endif /* FS_STATS_DETAILED */
6313 } /*SRXAFS_GetVolumeStatus */
6317 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6318 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6319 char *OfflineMsg, char *Motd)
6321 Vnode *targetptr = 0; /* vnode of the new file */
6322 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6323 int errorCode = 0; /* error code */
6324 Volume *volptr = 0; /* pointer to the volume header */
6325 struct client *client; /* pointer to client entry */
6326 afs_int32 rights, anyrights; /* rights for this and any user */
6328 struct rx_connection *tcon = rx_ConnectionOf(acall);
6329 #if FS_STATS_DETAILED
6330 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6331 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6332 struct timeval elapsedTime; /* Transfer time */
6335 * Set our stats pointer, remember when the RPC operation started, and
6336 * tally the operation.
6339 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6343 TM_GetTimeOfDay(&opStartTime, 0);
6344 #endif /* FS_STATS_DETAILED */
6346 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6347 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
6348 goto Bad_SetVolumeStatus;
6351 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6355 goto Bad_SetVolumeStatus;
6357 dummyFid.Volume = avolid, dummyFid.Vnode =
6358 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6361 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6362 &parentwhentargetnotdir, &client, READ_LOCK,
6363 &rights, &anyrights)))
6364 goto Bad_SetVolumeStatus;
6366 if (readonlyServer) {
6367 errorCode = VREADONLY;
6368 goto Bad_SetVolumeStatus;
6370 if (VanillaUser(client)) {
6372 goto Bad_SetVolumeStatus;
6376 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6378 Bad_SetVolumeStatus:
6379 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
6380 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6381 errorCode = CallPostamble(tcon, errorCode);
6383 #if FS_STATS_DETAILED
6384 TM_GetTimeOfDay(&opStopTime, 0);
6385 if (errorCode == 0) {
6387 (opP->numSuccesses)++;
6388 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6389 fs_stats_AddTo((opP->sumTime), elapsedTime);
6390 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6391 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6392 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6394 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6395 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6399 #endif /* FS_STATS_DETAILED */
6401 osi_auditU(acall, SetVolumeStatusEvent, errorCode, AUD_LONG, avolid,
6402 AUD_STR, Name, AUD_END);
6405 } /*SRXAFS_SetVolumeStatus */
6407 #define DEFAULTVOLUME "root.afs"
6410 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6416 struct rx_connection *tcon;
6419 #if FS_STATS_DETAILED
6420 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6421 struct timeval opStartTime; /* Start time for RPC op */
6423 struct timeval opStopTime;
6424 struct timeval elapsedTime; /* Transfer time */
6428 * Set our stats pointer, remember when the RPC operation started, and
6429 * tally the operation.
6431 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6435 TM_GetTimeOfDay(&opStartTime, 0);
6436 #endif /* FS_STATS_DETAILED */
6438 return FSERR_EOPNOTSUPP;
6441 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
6442 goto Bad_GetRootVolume;
6444 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6447 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6449 strcpy(temp, DEFAULTVOLUME);
6451 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6452 lockf(fd, F_LOCK, 0);
6456 len = read(fd, temp, 256);
6457 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6458 lockf(fd, F_ULOCK, 0);
6463 if (temp[len - 1] == '\n')
6467 *VolumeName = temp; /* freed by rx server-side stub */
6470 errorCode = CallPostamble(tcon, errorCode);
6472 #if FS_STATS_DETAILED
6473 TM_GetTimeOfDay(&opStopTime, 0);
6474 if (errorCode == 0) {
6476 (opP->numSuccesses)++;
6477 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6478 fs_stats_AddTo((opP->sumTime), elapsedTime);
6479 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6480 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6481 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6483 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6484 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6488 #endif /* FS_STATS_DETAILED */
6493 } /*SRXAFS_GetRootVolume */
6496 /* still works because a struct CBS is the same as a struct AFSOpaque */
6498 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6499 struct AFSOpaque * Token)
6502 struct rx_connection *tcon;
6503 #if FS_STATS_DETAILED
6504 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6505 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6506 struct timeval elapsedTime; /* Transfer time */
6509 * Set our stats pointer, remember when the RPC operation started, and
6510 * tally the operation.
6512 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6516 TM_GetTimeOfDay(&opStartTime, 0);
6517 #endif /* FS_STATS_DETAILED */
6519 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
6520 goto Bad_CheckToken;
6522 code = FSERR_ECONNREFUSED;
6525 code = CallPostamble(tcon, code);
6527 #if FS_STATS_DETAILED
6528 TM_GetTimeOfDay(&opStopTime, 0);
6531 (opP->numSuccesses)++;
6532 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6533 fs_stats_AddTo((opP->sumTime), elapsedTime);
6534 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6535 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6536 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6538 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6539 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6543 #endif /* FS_STATS_DETAILED */
6547 } /*SRXAFS_CheckToken */
6550 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6551 afs_uint32 * USeconds)
6554 struct rx_connection *tcon;
6556 #if FS_STATS_DETAILED
6557 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6558 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6559 struct timeval elapsedTime; /* Transfer time */
6562 * Set our stats pointer, remember when the RPC operation started, and
6563 * tally the operation.
6565 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6569 TM_GetTimeOfDay(&opStartTime, 0);
6570 #endif /* FS_STATS_DETAILED */
6572 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon)))
6576 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6578 TM_GetTimeOfDay(&tpl, 0);
6579 *Seconds = tpl.tv_sec;
6580 *USeconds = tpl.tv_usec;
6582 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6585 code = CallPostamble(tcon, code);
6587 #if FS_STATS_DETAILED
6588 TM_GetTimeOfDay(&opStopTime, 0);
6589 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6592 (opP->numSuccesses)++;
6593 fs_stats_AddTo((opP->sumTime), elapsedTime);
6594 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6595 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6596 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6598 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6599 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6603 #endif /* FS_STATS_DETAILED */
6607 } /*SRXAFS_GetTime */
6614 * Implement a client's data fetch using Rx.
6617 * volptr : Ptr to the given volume's info.
6618 * targetptr : Pointer to the vnode involved.
6619 * Call : Ptr to the Rx call involved.
6620 * Pos : Offset within the file.
6621 * Len : Length in bytes to read; this value is bogus!
6622 * if FS_STATS_DETAILED
6623 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6625 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6631 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6632 register struct rx_call * Call, afs_sfsize_t Pos,
6633 afs_sfsize_t Len, afs_int32 Int64Mode,
6634 #if FS_STATS_DETAILED
6635 afs_sfsize_t * a_bytesToFetchP,
6636 afs_sfsize_t * a_bytesFetchedP
6637 #endif /* FS_STATS_DETAILED */
6640 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6641 int errorCode = 0; /* Returned error code to caller */
6645 register char *tbuffer;
6646 #else /* AFS_NT40_ENV */
6647 struct iovec tiov[RX_MAXIOVECS];
6649 #endif /* AFS_NT40_ENV */
6653 #if FS_STATS_DETAILED
6655 * Initialize the byte count arguments.
6657 (*a_bytesToFetchP) = 0;
6658 (*a_bytesFetchedP) = 0;
6659 #endif /* FS_STATS_DETAILED */
6663 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6664 (afs_uintmax_t) Len));
6666 if (!VN_GET_INO(targetptr)) {
6667 afs_int32 zero = htonl(0);
6669 * This is used for newly created files; we simply send 0 bytes
6670 * back to make the cache manager happy...
6673 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6674 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6677 TM_GetTimeOfDay(&StartTime, 0);
6678 ihP = targetptr->handle;
6682 optSize = sendBufSize;
6683 tlen = FDH_SIZE(fdP);
6685 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6694 if (Pos + Len > tlen)
6695 Len = tlen - Pos; /* get length we should send */
6696 (void)FDH_SEEK(fdP, Pos, 0);
6698 afs_int32 high, low;
6699 SplitOffsetOrSize(Len, high, low);
6700 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6703 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6706 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6708 #if FS_STATS_DETAILED
6709 (*a_bytesToFetchP) = Len;
6710 #endif /* FS_STATS_DETAILED */
6712 tbuffer = AllocSendBuffer();
6713 #endif /* AFS_NT40_ENV */
6721 errorCode = FDH_READ(fdP, tbuffer, wlen);
6722 if (errorCode != wlen) {
6724 FreeSendBuffer((struct afs_buffer *)tbuffer);
6727 errorCode = rx_Write(Call, tbuffer, wlen);
6728 #else /* AFS_NT40_ENV */
6729 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6730 if (errorCode <= 0) {
6735 errorCode = FDH_READV(fdP, tiov, tnio);
6736 if (errorCode != wlen) {
6740 errorCode = rx_Writev(Call, tiov, tnio, wlen);
6741 #endif /* AFS_NT40_ENV */
6742 #if FS_STATS_DETAILED
6744 * Bump the number of bytes actually sent by the number from this
6747 (*a_bytesFetchedP) += errorCode;
6748 #endif /* FS_STATS_DETAILED */
6749 if (errorCode != wlen) {
6752 FreeSendBuffer((struct afs_buffer *)tbuffer);
6753 #endif /* AFS_NT40_ENV */
6759 FreeSendBuffer((struct afs_buffer *)tbuffer);
6760 #endif /* AFS_NT40_ENV */
6762 TM_GetTimeOfDay(&StopTime, 0);
6764 /* Adjust all Fetch Data related stats */
6766 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6767 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6768 AFSCallStats.AccumFetchTime +=
6769 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6770 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6772 afs_fsize_t targLen;
6773 VN_GET_LEN(targLen, targetptr);
6774 AFSCallStats.TotalFetchedBytes += targLen;
6775 AFSCallStats.FetchSize1++;
6776 if (targLen < SIZE2)
6777 AFSCallStats.FetchSize2++;
6778 else if (targLen < SIZE3)
6779 AFSCallStats.FetchSize3++;
6780 else if (targLen < SIZE4)
6781 AFSCallStats.FetchSize4++;
6783 AFSCallStats.FetchSize5++;
6788 } /*FetchData_RXStyle */
6791 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6792 afs_sfsize_t * size)
6794 #ifdef AFS_NAMEI_ENV
6796 lhp = IH_OPEN(V_linkHandle(vp));
6800 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6802 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6807 *size = OS_SIZE(fdP->fd_fd);
6808 return (*size == -1) ? -1 : 0;
6810 struct afs_stat status;
6812 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6816 *lc = GetLinkCount(vp, &status);
6817 *size = status.st_size;
6826 * Implement a client's data store using Rx.
6829 * volptr : Ptr to the given volume's info.
6830 * targetptr : Pointer to the vnode involved.
6831 * Call : Ptr to the Rx call involved.
6832 * Pos : Offset within the file.
6833 * Len : Length in bytes to store; this value is bogus!
6834 * if FS_STATS_DETAILED
6835 * a_bytesToStoreP : Set to the number of bytes to be stored to
6837 * a_bytesStoredP : Set to the actual number of bytes stored to
6842 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6843 struct client * client, register struct rx_call * Call,
6844 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6846 #if FS_STATS_DETAILED
6847 afs_sfsize_t * a_bytesToStoreP,
6848 afs_sfsize_t * a_bytesStoredP
6849 #endif /* FS_STATS_DETAILED */
6852 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6853 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6854 int errorCode = 0; /* Returned error code to caller */
6856 register char *tbuffer; /* data copying buffer */
6857 #else /* AFS_NT40_ENV */
6858 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6859 int tnio; /* temp for iovec size */
6860 #endif /* AFS_NT40_ENV */
6861 afs_sfsize_t tlen; /* temp for xfr length */
6862 Inode tinode; /* inode for I/O */
6863 afs_int32 optSize; /* optimal transfer size */
6864 afs_sfsize_t DataLength; /* size of inode */
6865 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6866 afs_fsize_t NewLength; /* size after this store completes */
6867 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6868 int linkCount; /* link count on inode */
6870 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6872 #if FS_STATS_DETAILED
6874 * Initialize the byte count arguments.
6876 (*a_bytesToStoreP) = 0;
6877 (*a_bytesStoredP) = 0;
6878 #endif /* FS_STATS_DETAILED */
6881 * We break the callbacks here so that the following signal will not
6884 BreakCallBack(client->host, Fid, 0);
6886 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6887 /* the inode should have been created in Alloc_NewVnode */
6888 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(Call)));
6890 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s\n",
6891 Fid->Volume, Fid->Vnode, Fid->Unique,
6892 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
6893 inet_ntoa(logHostAddr)));
6894 return ENOENT; /* is this proper error code? */
6897 * See if the file has several links (from other volumes). If it
6898 * does, then we have to make a copy before changing it to avoid
6899 *changing read-only clones of this dude
6902 ("StoreData_RXStyle : Opening inode %s\n",
6903 PrintInode(NULL, VN_GET_INO(targetptr))));
6904 fdP = IH_OPEN(targetptr->handle);
6907 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
6912 if (linkCount != 1) {
6915 ("StoreData_RXStyle : inode %s has more than onelink\n",
6916 PrintInode(NULL, VN_GET_INO(targetptr))));
6917 /* other volumes share this data, better copy it first */
6919 /* Adjust the disk block count by the creation of the new inode.
6920 * We call the special VDiskUsage so we don't adjust the volume's
6921 * quota since we don't want to penalyze the user for afs's internal
6922 * mechanisms (i.e. copy on write overhead.) Also the right size
6923 * of the disk will be recorded...
6926 VN_GET_LEN(size, targetptr);
6927 volptr->partition->flags &= ~PART_DONTUPDATE;
6928 VSetPartitionDiskUsage(volptr->partition);
6929 volptr->partition->flags |= PART_DONTUPDATE;
6930 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6931 volptr->partition->flags &= ~PART_DONTUPDATE;
6935 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6936 if ((errorCode = CopyOnWrite(targetptr, volptr))) {
6937 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6938 volptr->partition->flags &= ~PART_DONTUPDATE;
6941 volptr->partition->flags &= ~PART_DONTUPDATE;
6942 VSetPartitionDiskUsage(volptr->partition);
6943 fdP = IH_OPEN(targetptr->handle);
6946 ("StoreData : Reopen after CopyOnWrite failed\n"));
6950 tinode = VN_GET_INO(targetptr);
6952 assert(VALID_INO(tinode));
6954 /* compute new file length */
6955 NewLength = DataLength;
6956 if (FileLength < NewLength)
6957 /* simulate truncate */
6958 NewLength = FileLength;
6959 TruncatedLength = NewLength; /* remember length after possible ftruncate */
6960 if (Pos + Length > NewLength)
6961 NewLength = Pos + Length; /* and write */
6963 /* adjust the disk block count by the difference in the files */
6965 afs_fsize_t targSize;
6966 VN_GET_LEN(targSize, targetptr);
6967 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
6970 AdjustDiskUsage(volptr, adjustSize,
6971 adjustSize - SpareComp(volptr)))) {
6976 /* can signal cache manager to proceed from close now */
6977 /* this bit means that the locks are set and protections are OK */
6978 rx_SetLocalStatus(Call, 1);
6980 TM_GetTimeOfDay(&StartTime, 0);
6982 optSize = sendBufSize;
6984 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
6985 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
6986 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
6988 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
6989 if (FileLength < DataLength)
6990 FDH_TRUNC(fdP, FileLength);
6992 FDH_SEEK(fdP, Pos, 0);
6993 bytesTransfered = 0;
6995 tbuffer = AllocSendBuffer();
6996 #endif /* AFS_NT40_ENV */
6997 /* if length == 0, the loop below isn't going to do anything, including
6998 * extend the length of the inode, which it must do, since the file system
6999 * assumes that the inode length == vnode's file length. So, we extend
7000 * the file length manually if need be. Note that if file is bigger than
7001 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7002 * do what we're going to do below.
7004 if (Length == 0 && Pos > TruncatedLength) {
7005 /* Set the file's length; we've already done an lseek to the right
7008 errorCode = FDH_WRITE(fdP, &tlen, 1);
7011 errorCode = FDH_TRUNC(fdP, Pos);
7013 /* have some data to copy */
7014 #if FS_STATS_DETAILED
7015 (*a_bytesToStoreP) = Length;
7016 #endif /* FS_STATS_DETAILED */
7019 if (bytesTransfered >= Length) {
7023 tlen = Length - bytesTransfered; /* how much more to do */
7025 rlen = optSize; /* bound by buffer size */
7029 errorCode = rx_Read(Call, tbuffer, rlen);
7030 #else /* AFS_NT40_ENV */
7031 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7032 #endif /* AFS_NT40_ENV */
7033 #if FS_STATS_DETAILED
7034 (*a_bytesStoredP) += errorCode;
7035 #endif /* FS_STATS_DETAILED */
7036 if (errorCode <= 0) {
7042 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7043 #else /* AFS_NT40_ENV */
7044 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7045 #endif /* AFS_NT40_ENV */
7046 if (errorCode != rlen) {
7047 errorCode = VDISKFULL;
7050 bytesTransfered += rlen;
7055 FreeSendBuffer((struct afs_buffer *)tbuffer);
7056 #endif /* AFS_NT40_ENV */
7061 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7062 /* something went wrong: adjust size and return */
7063 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7064 /* changed_newTime is tested in StoreData to detemine if we
7065 * need to update the target vnode.
7067 targetptr->changed_newTime = 1;
7069 /* set disk usage to be correct */
7070 VAdjustDiskUsage(&errorCode, volptr,
7071 (afs_sfsize_t) (nBlocks(nfSize) -
7072 nBlocks(NewLength)), 0);
7077 TM_GetTimeOfDay(&StopTime, 0);
7079 VN_SET_LEN(targetptr, NewLength);
7081 /* Update all StoreData related stats */
7083 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7084 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7085 AFSCallStats.StoreSize1++; /* Piggybacked data */
7087 afs_fsize_t targLen;
7088 VN_GET_LEN(targLen, targetptr);
7089 if (targLen < SIZE2)
7090 AFSCallStats.StoreSize2++;
7091 else if (targLen < SIZE3)
7092 AFSCallStats.StoreSize3++;
7093 else if (targLen < SIZE4)
7094 AFSCallStats.StoreSize4++;
7096 AFSCallStats.StoreSize5++;
7101 } /*StoreData_RXStyle */
7103 static int sys2et[512];
7106 init_sys_error_to_et(void)
7108 memset(&sys2et, 0, sizeof(sys2et));
7109 sys2et[EPERM] = UAEPERM;
7110 sys2et[ENOENT] = UAENOENT;
7111 sys2et[ESRCH] = UAESRCH;
7112 sys2et[EINTR] = UAEINTR;
7113 sys2et[EIO] = UAEIO;
7114 sys2et[ENXIO] = UAENXIO;
7115 sys2et[E2BIG] = UAE2BIG;
7116 sys2et[ENOEXEC] = UAENOEXEC;
7117 sys2et[EBADF] = UAEBADF;
7118 sys2et[ECHILD] = UAECHILD;
7119 sys2et[EAGAIN] = UAEAGAIN;
7120 sys2et[ENOMEM] = UAENOMEM;
7121 sys2et[EACCES] = UAEACCES;
7122 sys2et[EFAULT] = UAEFAULT;
7123 sys2et[ENOTBLK] = UAENOTBLK;
7124 sys2et[EBUSY] = UAEBUSY;
7125 sys2et[EEXIST] = UAEEXIST;
7126 sys2et[EXDEV] = UAEXDEV;
7127 sys2et[ENODEV] = UAENODEV;
7128 sys2et[ENOTDIR] = UAENOTDIR;
7129 sys2et[EISDIR] = UAEISDIR;
7130 sys2et[EINVAL] = UAEINVAL;
7131 sys2et[ENFILE] = UAENFILE;
7132 sys2et[EMFILE] = UAEMFILE;
7133 sys2et[ENOTTY] = UAENOTTY;
7134 sys2et[ETXTBSY] = UAETXTBSY;
7135 sys2et[EFBIG] = UAEFBIG;
7136 sys2et[ENOSPC] = UAENOSPC;
7137 sys2et[ESPIPE] = UAESPIPE;
7138 sys2et[EROFS] = UAEROFS;
7139 sys2et[EMLINK] = UAEMLINK;
7140 sys2et[EPIPE] = UAEPIPE;
7141 sys2et[EDOM] = UAEDOM;
7142 sys2et[ERANGE] = UAERANGE;
7143 sys2et[EDEADLK] = UAEDEADLK;
7144 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7145 sys2et[ENOLCK] = UAENOLCK;
7146 sys2et[ENOSYS] = UAENOSYS;
7147 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7148 sys2et[ELOOP] = UAELOOP;
7149 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7150 sys2et[ENOMSG] = UAENOMSG;
7151 sys2et[EIDRM] = UAEIDRM;
7152 sys2et[ECHRNG] = UAECHRNG;
7153 sys2et[EL2NSYNC] = UAEL2NSYNC;
7154 sys2et[EL3HLT] = UAEL3HLT;
7155 sys2et[EL3RST] = UAEL3RST;
7156 sys2et[ELNRNG] = UAELNRNG;
7157 sys2et[EUNATCH] = UAEUNATCH;
7158 sys2et[ENOCSI] = UAENOCSI;
7159 sys2et[EL2HLT] = UAEL2HLT;
7160 sys2et[EBADE] = UAEBADE;
7161 sys2et[EBADR] = UAEBADR;
7162 sys2et[EXFULL] = UAEXFULL;
7163 sys2et[ENOANO] = UAENOANO;
7164 sys2et[EBADRQC] = UAEBADRQC;
7165 sys2et[EBADSLT] = UAEBADSLT;
7166 sys2et[EDEADLK] = UAEDEADLK;
7167 sys2et[EBFONT] = UAEBFONT;
7168 sys2et[ENOSTR] = UAENOSTR;
7169 sys2et[ENODATA] = UAENODATA;
7170 sys2et[ETIME] = UAETIME;
7171 sys2et[ENOSR] = UAENOSR;
7172 sys2et[ENONET] = UAENONET;
7173 sys2et[ENOPKG] = UAENOPKG;
7174 sys2et[EREMOTE] = UAEREMOTE;
7175 sys2et[ENOLINK] = UAENOLINK;
7176 sys2et[EADV] = UAEADV;
7177 sys2et[ESRMNT] = UAESRMNT;
7178 sys2et[ECOMM] = UAECOMM;
7179 sys2et[EPROTO] = UAEPROTO;
7180 sys2et[EMULTIHOP] = UAEMULTIHOP;
7181 sys2et[EDOTDOT] = UAEDOTDOT;
7182 sys2et[EBADMSG] = UAEBADMSG;
7183 sys2et[EOVERFLOW] = UAEOVERFLOW;
7184 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7185 sys2et[EBADFD] = UAEBADFD;
7186 sys2et[EREMCHG] = UAEREMCHG;
7187 sys2et[ELIBACC] = UAELIBACC;
7188 sys2et[ELIBBAD] = UAELIBBAD;
7189 sys2et[ELIBSCN] = UAELIBSCN;
7190 sys2et[ELIBMAX] = UAELIBMAX;
7191 sys2et[ELIBEXEC] = UAELIBEXEC;
7192 sys2et[EILSEQ] = UAEILSEQ;
7193 sys2et[ERESTART] = UAERESTART;
7194 sys2et[ESTRPIPE] = UAESTRPIPE;
7195 sys2et[EUSERS] = UAEUSERS;
7196 sys2et[ENOTSOCK] = UAENOTSOCK;
7197 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7198 sys2et[EMSGSIZE] = UAEMSGSIZE;
7199 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7200 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7201 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7202 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7203 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7204 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7205 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7206 sys2et[EADDRINUSE] = UAEADDRINUSE;
7207 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7208 sys2et[ENETDOWN] = UAENETDOWN;
7209 sys2et[ENETUNREACH] = UAENETUNREACH;
7210 sys2et[ENETRESET] = UAENETRESET;
7211 sys2et[ECONNABORTED] = UAECONNABORTED;
7212 sys2et[ECONNRESET] = UAECONNRESET;
7213 sys2et[ENOBUFS] = UAENOBUFS;
7214 sys2et[EISCONN] = UAEISCONN;
7215 sys2et[ENOTCONN] = UAENOTCONN;
7216 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7217 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7218 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7219 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7220 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7221 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7222 sys2et[EALREADY] = UAEALREADY;
7223 sys2et[EINPROGRESS] = UAEINPROGRESS;
7224 sys2et[ESTALE] = UAESTALE;
7225 sys2et[EUCLEAN] = UAEUCLEAN;
7226 sys2et[ENOTNAM] = UAENOTNAM;
7227 sys2et[ENAVAIL] = UAENAVAIL;
7228 sys2et[EISNAM] = UAEISNAM;
7229 sys2et[EREMOTEIO] = UAEREMOTEIO;
7230 sys2et[EDQUOT] = UAEDQUOT;
7231 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7232 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7236 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7238 Error errorCode = 0;
7240 struct client *tclient;
7241 static struct rx_securityClass *sc = 0;
7243 struct rx_connection *tcon;
7244 struct rx_connection *conn;
7246 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
7247 goto Bad_CallBackRxConnAddr1;
7249 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7253 tclient = h_FindClient_r(tcon);
7254 thost = tclient->host;
7256 /* nothing more can be done */
7257 if ( !thost->interface )
7258 goto Bad_CallBackRxConnAddr;
7260 assert(thost->interface->numberOfInterfaces > 0 );
7262 /* the only address is the primary interface */
7263 /* can't change when there's only 1 address, anyway */
7264 if ( thost->interface->numberOfInterfaces == 1 )
7265 goto Bad_CallBackRxConnAddr;
7267 /* initialise a security object only once */
7269 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7271 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7273 if ( *addr == thost->interface->addr[i] ) {
7278 if ( *addr != thost->interface->addr[i] )
7279 goto Bad_CallBackRxConnAddr;
7281 conn = rx_NewConnection (thost->interface->addr[i],
7282 thost->port, 1, sc, 0);
7283 rx_SetConnDeadTime(conn, 2);
7284 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7286 errorCode = RXAFSCB_Probe(conn);
7289 if ( thost->callback_rxcon )
7290 rx_DestroyConnection(thost->callback_rxcon);
7291 thost->callback_rxcon = conn;
7293 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7294 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7296 errorCode = CallPostamble(tcon, errorCode);
7299 rx_DestroyConnection(conn);
7301 Bad_CallBackRxConnAddr:
7305 errorCode = CallPostamble(tcon, errorCode);
7306 Bad_CallBackRxConnAddr1:
7307 return errorCode; /* failure */
7311 sys_error_to_et(afs_int32 in)
7315 if (in < 0 || in > 511)
7317 if (sys2et[in] != 0)