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 <afs/param.h>
29 #include <afsconfig.h>
37 #undef SHARED /* XXX */
42 #include <sys/param.h>
44 #include <netinet/in.h>
46 #include <sys/ioctl.h>
47 #include <sys/socket.h>
48 #ifndef AFS_LINUX20_ENV
50 #include <netinet/if_ether.h>
57 /* included early because of name conflict on IOPEN */
58 #include <sys/inode.h>
62 #endif /* AFS_HPUX_ENV */
66 #include <afs/assert.h>
69 #include <afs/afsint.h>
70 #include <afs/vldbint.h>
71 #include <afs/errors.h>
72 #include <afs/ihandle.h>
73 #include <afs/vnode.h>
74 #include <afs/volume.h>
76 #include <afs/ptclient.h>
77 #include <afs/prs_fs.h>
79 #include <rx/rx_globals.h>
81 #if ! defined(AFS_SGI_ENV) && ! defined(AFS_AIX32_ENV) && ! defined(AFS_NT40_ENV) && ! defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
84 #if !defined(AFS_NT40_ENV)
87 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
89 #include <sys/statfs.h>
90 #include <sys/lockf.h>
92 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
97 #include <afs/cellconfig.h>
100 #include <afs/auth.h>
102 #include <afs/partition.h>
105 #include <afs/audit.h>
106 #include <afs/afsutil.h>
108 #ifdef AFS_PTHREAD_ENV
109 pthread_mutex_t fileproc_glock_mutex;
110 #endif /* AFS_PTHREAD_ENV */
113 /* Useful local defines used by this module */
116 #define MustNOTBeDIR 1
120 #define TVS_SSTATUS 2
123 #define TVS_MKDIR 0x10
125 #define CHK_FETCH 0x10
126 #define CHK_FETCHDATA 0x10
127 #define CHK_FETCHACL 0x11
128 #define CHK_FETCHSTATUS 0x12
129 #define CHK_STOREDATA 0x00
130 #define CHK_STOREACL 0x01
131 #define CHK_STORESTATUS 0x02
133 #define OWNERREAD 0400
134 #define OWNERWRITE 0200
135 #define OWNEREXEC 0100
136 #ifdef USE_GROUP_PERMS
137 #define GROUPREAD 0040
138 #define GROUPWRITE 0020
139 #define GROUPREXEC 0010
142 /* The following errors were not defined in NT. They are given unique
143 * names here to avoid any potential collision.
145 #define FSERR_ELOOP 90
146 #define FSERR_EOPNOTSUPP 122
147 #define FSERR_ECONNREFUSED 130
149 #define NOTACTIVECALL 0
152 extern struct afsconf_dir *confDir;
153 extern afs_int32 dataVersionHigh;
156 extern struct AFSCallStatistics AFSCallStats;
157 struct AFSCallStatistics AFSCallStats;
158 #if FS_STATS_DETAILED
159 struct fs_stats_FullPerfStats afs_FullPerfStats;
160 extern int AnonymousID;
161 #endif /* FS_STATS_DETAILED */
162 #if TRANSARC_VOL_STATS
163 static const char nullString[] = "";
164 #endif /* TRANSARC_VOL_STATS */
167 afs_int32 NothingYet;
170 struct afs_FSStats afs_fsstats;
172 void ResetDebug(), SetDebug(), GetStatus(), Terminate();
173 int CopyOnWrite(); /* returns 0 on success */
176 void SetSystemStats(), SetAFSStats(), SetVolumeStats();
180 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
182 extern afs_int32 implicitAdminRights;
184 static TryLocalVLServer();
187 * Externals used by the xstat code.
189 extern int VolumeCacheSize, VolumeGets, VolumeReplacements;
190 extern int CEs, CEBlocks;
192 extern int HTs, HTBlocks;
194 #ifdef AFS_SGI_XFS_IOPS_ENV
195 #include <afs/xfsattrs.h>
196 static int GetLinkCount(avp, astat)
200 if (!strcmp("xfs", astat->st_fstype)) {
201 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
204 return astat->st_nlink;
207 #define GetLinkCount(V, S) (S)->st_nlink
210 afs_int32 SpareComp(avolp)
214 register afs_int32 temp;
218 temp = V_maxquota(avolp);
220 /* no matter; doesn't check in this case */
224 temp = (temp * PctSpare) / 100;
237 * Set the volume synchronization parameter for this volume. If it changes,
238 * the Cache Manager knows that the volume must be purged from the stat cache.
240 static SetVolumeSync(async, avol)
241 register struct AFSVolSync *async;
242 register Volume *avol;
246 /* date volume instance was created */
249 async->spare1 = avol->header->diskstuff.creationDate;
262 * This call overwrites the pointed-to rx_call with an rx_connection. This
263 * is really bogus. Note that this function always returns a held host, so
264 * that CallPostamble can block without the host's disappearing.
266 static CallPreamble(acall, activecall)
267 register struct rx_call **acall;
272 struct rx_connection *tconn;
273 struct client *tclient;
276 tconn = rx_ConnectionOf(*acall);
277 *acall = (struct rx_call *)tconn; /* change it! */
281 tclient = h_FindClient_r(tconn);
282 if (tclient->prfail == 1) { /* couldn't get the CPS */
284 h_ReleaseClient_r(tclient);
285 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
289 retry_flag=0; /* Retry once */
291 /* Take down the old connection and re-read the key file */
292 ViceLog(0, ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
294 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
297 h_ReleaseClient_r(tclient);
299 ViceLog(0,("CallPreamble: couldn't reconnect to ptserver\n"));
303 tclient->prfail = 2; /* Means re-eval client's cps */
304 h_ReleaseClient_r(tclient);
308 thost = tclient->host;
309 tclient->LastCall = thost->LastCall = FT_ApproxTime();
310 if (activecall) /* For all but "GetTime" calls */
311 thost->ActiveCall = thost->LastCall;
314 if (thost->hostFlags & HOSTDELETED) {
315 ViceLog(3,("Discarded a packet for deleted host %08x\n",thost->host));
316 code = VBUSY; /* raced, so retry */
318 else if (thost->hostFlags & VENUSDOWN) {
319 if (BreakDelayedCallBacks_r(thost)) {
320 ViceLog(0,("BreakDelayedCallbacks FAILED for host %08x which IS UP. Possible network or routing failure.\n",thost->host));
321 if ( MultiProbeAlternateAddress_r (thost) ) {
322 ViceLog(0, ("MultiProbe failed to find new address for host %x.%d\n",
323 thost->host, thost->port));
326 ViceLog(0, ("MultiProbe found new address for host %x.%d\n",
327 thost->host, thost->port));
328 if (BreakDelayedCallBacks_r(thost)) {
329 ViceLog(0,("BreakDelayedCallbacks FAILED AGAIN for host %08x which IS UP. Possible network or routing failure.\n",thost->host));
338 h_ReleaseClient_r(tclient);
346 static CallPostamble(aconn)
347 register struct rx_connection *aconn;
351 struct client *tclient;
354 tclient = h_FindClient_r(aconn);
355 thost = tclient->host;
356 h_ReleaseClient_r(tclient);
363 #define AFSV_BUFFERSIZE 16384
365 static struct afs_buffer {
366 struct afs_buffer *next;
367 } *freeBufferList = 0;
368 static int afs_buffersAlloced = 0;
371 static FreeSendBuffer(adata)
372 register struct afs_buffer *adata;
376 afs_buffersAlloced--;
377 adata->next = freeBufferList;
378 freeBufferList = adata;
385 /* allocate space for sender */
386 static char *AllocSendBuffer()
389 register struct afs_buffer *tp;
392 afs_buffersAlloced++;
393 if (!freeBufferList) {
395 return malloc(AFSV_BUFFERSIZE);
398 freeBufferList = tp->next;
402 } /*AllocSendBuffer*/
405 static int VolumeOwner (client, targetptr)
406 register struct client *client;
407 register Vnode *targetptr;
410 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
413 return (client->ViceId == owner);
416 * We don't have to check for host's cps since only regular
417 * viceid are volume owners.
419 return (acl_IsAMember(owner, &client->CPS));
425 static int VolumeRootVnode (targetptr)
429 return ((targetptr->vnodeNumber == ROOTVNODE) &&
430 (targetptr->disk.uniquifier == 1));
432 } /*VolumeRootVnode*/
435 SRXAFS_FetchData (tcon, Fid, Pos, Len, OutStatus, CallBack, Sync)
436 struct rx_connection *tcon; /* Rx connection handle */
437 struct AFSFid *Fid; /* Fid of file to fetch */
438 afs_int32 Pos, Len; /* Not implemented yet */
439 struct AFSFetchStatus *OutStatus; /* Returned status for Fid */
440 struct AFSCallBack *CallBack; /* If r/w return CB for Fid */
441 struct AFSVolSync *Sync; /* synchronization info */
444 Vnode * targetptr = 0; /* pointer to vnode to fetch */
445 Vnode * parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
446 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
447 int errorCode = 0; /* return code to caller */
448 int fileCode = 0; /* return code from vol package */
449 Volume * volptr = 0; /* pointer to the volume */
450 struct client *client; /* pointer to the client data */
451 struct rx_call *tcall; /* the call we're a part of */
452 afs_int32 rights, anyrights; /* rights for this and any user */
453 struct client *t_client; /* tmp ptr to client data */
454 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
455 #if FS_STATS_DETAILED
456 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
457 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
458 struct timeval opStartTime,
459 opStopTime; /* Start/stop times for RPC op*/
460 struct timeval xferStartTime,
461 xferStopTime; /* Start/stop times for xfer portion*/
462 struct timeval elapsedTime; /* Transfer time */
463 afs_int32 bytesToXfer; /* # bytes to xfer*/
464 afs_int32 bytesXferred; /* # bytes actually xferred*/
465 int readIdx; /* Index of read stats array to bump*/
466 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
469 * Set our stats pointers, remember when the RPC operation started, and
470 * tally the operation.
472 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
473 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
477 TM_GetTimeOfDay(&opStartTime, 0);
478 #endif /* FS_STATS_DETAILED */
480 ViceLog(1,("SRXAFS_FetchData, Fid = %u.%d.%d\n",
481 Fid->Volume, Fid->Vnode, Fid->Unique));
483 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
486 /* CallPreamble changes tcon from a call to a conn */
487 tcall = (struct rx_call *) tcon;
488 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
491 /* Get ptr to client data for user Id for logging */
492 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
493 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
494 ViceLog(5,("SRXAFS_FetchData, Fid = %u.%d.%d, Host %s, Id %d\n",
495 Fid->Volume, Fid->Vnode, Fid->Unique,
496 inet_ntoa(logHostAddr), t_client->ViceId));
498 * Get volume/vnode for the fetched file; caller's access rights to
499 * it are also returned
501 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
502 DONTCHECK, &parentwhentargetnotdir,
503 &client, READ_LOCK, &rights, &anyrights))
506 SetVolumeSync(Sync, volptr);
508 #if FS_STATS_DETAILED
510 * Remember that another read operation was performed.
513 if (client->InSameNetwork)
514 readIdx = VOL_STATS_SAME_NET;
516 readIdx = VOL_STATS_DIFF_NET;
517 V_stat_reads(volptr, readIdx)++;
518 if (client->ViceId != AnonymousID) {
519 V_stat_reads(volptr, readIdx+1)++;
522 #endif /* FS_STATS_DETAILED */
524 /* Check whether the caller has permission access to fetch the data */
525 if (errorCode = Check_PermissionRights(targetptr, client, rights,
530 * Drop the read lock on the parent directory after saving the parent
531 * vnode information we need to pass to GetStatus
533 if (parentwhentargetnotdir != NULL) {
534 tparentwhentargetnotdir = *parentwhentargetnotdir;
535 VPutVnode(&fileCode, parentwhentargetnotdir);
536 assert(!fileCode || (fileCode == VSALVAGE));
537 parentwhentargetnotdir = NULL;
540 #if FS_STATS_DETAILED
542 * Remember when the data transfer started.
544 TM_GetTimeOfDay(&xferStartTime, 0);
545 #endif /* FS_STATS_DETAILED */
547 /* actually do the data transfer */
548 #if FS_STATS_DETAILED
549 errorCode = FetchData_RXStyle(volptr, targetptr, tcall, Pos, Len,
550 &bytesToXfer, &bytesXferred);
552 if (errorCode = FetchData_RXStyle(volptr, targetptr, tcall, Pos, Len))
554 #endif /* FS_STATS_DETAILED */
556 #if FS_STATS_DETAILED
558 * At this point, the data transfer is done, for good or ill. Remember
559 * when the transfer ended, bump the number of successes/failures, and
560 * integrate the transfer size and elapsed time into the stats. If the
561 * operation failed, we jump to the appropriate point.
563 TM_GetTimeOfDay(&xferStopTime, 0);
567 (xferP->numSuccesses)++;
570 * Bump the xfer sum by the number of bytes actually sent, NOT the
573 tot_bytesXferred += bytesXferred;
574 (xferP->sumBytes) += (tot_bytesXferred >> 10);
575 tot_bytesXferred &= 0x3FF;
576 if (bytesXferred < xferP->minBytes)
577 xferP->minBytes = bytesXferred;
578 if (bytesXferred > xferP->maxBytes)
579 xferP->maxBytes = bytesXferred;
582 * Tally the size of the object. Note: we tally the actual size,
583 * NOT the number of bytes that made it out over the wire.
585 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
588 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
591 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
594 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
597 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
600 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
603 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
606 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
611 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
612 fs_stats_AddTo((xferP->sumTime), elapsedTime);
613 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
614 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
615 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
617 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
618 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
623 * Finally, go off to tell our caller the bad news in case the
628 #endif /* FS_STATS_DETAILED */
630 /* write back the OutStatus from the target vnode */
631 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
633 /* if a r/w volume, promise a callback to the caller */
634 if (VolumeWriteable(volptr))
635 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
638 bzero(&myFid, sizeof(struct AFSFid));
639 myFid.Volume = Fid->Volume;
640 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
644 /* Update and store volume/vnode and parent vnodes back */
645 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
646 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
649 #if FS_STATS_DETAILED
650 TM_GetTimeOfDay(&opStopTime, 0);
651 if (errorCode == 0) {
653 (opP->numSuccesses)++;
654 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
655 fs_stats_AddTo((opP->sumTime), elapsedTime);
656 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
657 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
658 fs_stats_TimeAssign((opP->minTime), elapsedTime);
660 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
661 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
666 #endif /* FS_STATS_DETAILED */
668 osi_auditU (tcall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
671 } /*SRXAFS_FetchData*/
674 SRXAFS_FetchACL (tcon, Fid, AccessList, OutStatus, Sync)
675 struct AFSVolSync *Sync;
676 struct rx_connection *tcon; /* Rx connection handle */
677 struct AFSFid *Fid; /* Fid of target dir */
678 struct AFSOpaque *AccessList; /* Returned contents of dir's ACL */
679 struct AFSFetchStatus *OutStatus; /* Returned status for the dir */
682 Vnode * targetptr = 0; /* pointer to vnode to fetch */
683 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
684 int errorCode = 0; /* return error code to caller */
685 Volume * volptr = 0; /* pointer to the volume */
686 struct client *client; /* pointer to the client data */
687 afs_int32 rights, anyrights; /* rights for this and any user */
688 struct rx_call *tcall = (struct rx_call *) tcon;
689 struct client *t_client; /* tmp ptr to client data */
690 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
691 #if FS_STATS_DETAILED
692 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
693 struct timeval opStartTime,
694 opStopTime; /* Start/stop times for RPC op*/
695 struct timeval elapsedTime; /* Transfer time */
698 * Set our stats pointer, remember when the RPC operation started, and
699 * tally the operation.
701 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
705 TM_GetTimeOfDay(&opStartTime, 0);
706 #endif /* FS_STATS_DETAILED */
708 ViceLog(1, ("SAFS_FetchACL, Fid = %u.%d.%d\n",
709 Fid->Volume, Fid->Vnode, Fid->Unique));
711 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
713 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
716 /* Get ptr to client data for user Id for logging */
717 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
718 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
719 ViceLog(5, ("SAFS_FetchACL, Fid = %u.%d.%d, Host %s, Id %d\n",
720 Fid->Volume, Fid->Vnode, Fid->Unique,
721 inet_ntoa(logHostAddr), t_client->ViceId));
723 AccessList->AFSOpaque_len = 0;
724 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
727 * Get volume/vnode for the fetched file; caller's access rights to it
730 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
731 DONTCHECK, &parentwhentargetnotdir,
732 &client, READ_LOCK, &rights, &anyrights))
735 SetVolumeSync(Sync, volptr);
737 /* Check whether we have permission to fetch the ACL */
738 if (errorCode = Check_PermissionRights(targetptr, client, rights,
742 /* Get the Access List from the dir's vnode */
743 if (errorCode = RXFetch_AccessList(targetptr, parentwhentargetnotdir,
747 /* Get OutStatus back From the target Vnode */
748 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
751 /* Update and store volume/vnode and parent vnodes back */
752 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
753 ViceLog(2, ("SAFS_FetchACL returns %d (ACL=%s)\n",
754 errorCode, AccessList->AFSOpaque_val));
757 #if FS_STATS_DETAILED
758 TM_GetTimeOfDay(&opStopTime, 0);
759 if (errorCode == 0) {
761 (opP->numSuccesses)++;
762 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
763 fs_stats_AddTo((opP->sumTime), elapsedTime);
764 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
765 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
766 fs_stats_TimeAssign((opP->minTime), elapsedTime);
768 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
769 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
774 #endif /* FS_STATS_DETAILED */
776 osi_auditU (tcall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
779 } /*SRXAFS_FetchACL*/
783 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
784 * merged into it when possible.
786 SAFSS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync)
787 struct rx_connection *tcon; /* Rx connection handle */
788 struct AFSFid *Fid; /* Fid of target file */
789 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
790 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
791 struct AFSVolSync *Sync; /* volume synchronization parm */
794 Vnode * targetptr = 0; /* pointer to vnode to fetch */
795 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
796 int errorCode = 0; /* return code to caller */
797 Volume * volptr = 0; /* pointer to the volume */
798 struct client *client; /* pointer to the client data */
799 afs_int32 rights, anyrights; /* rights for this and any user */
800 struct client *t_client; /* tmp ptr to client data */
801 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
803 /* Get ptr to client data for user Id for logging */
804 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
805 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
806 ViceLog(1, ("SAFS_FetchStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
807 Fid->Volume, Fid->Vnode, Fid->Unique,
808 inet_ntoa(logHostAddr), t_client->ViceId));
810 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
813 * Get volume/vnode for the fetched file; caller's rights to it are
816 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
817 DONTCHECK, &parentwhentargetnotdir,
818 &client, READ_LOCK, &rights, &anyrights))
819 goto Bad_FetchStatus;
821 /* set volume synchronization information */
822 SetVolumeSync(Sync, volptr);
824 /* Are we allowed to fetch Fid's status? */
825 if (targetptr->disk.type != vDirectory) {
826 if (errorCode = Check_PermissionRights(targetptr, client, rights,
828 goto Bad_FetchStatus;
831 /* set OutStatus From the Fid */
832 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
834 /* If a r/w volume, also set the CallBack state */
835 if (VolumeWriteable(volptr))
836 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
839 bzero(&myFid, sizeof(struct AFSFid));
840 myFid.Volume = Fid->Volume;
841 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
845 /* Update and store volume/vnode and parent vnodes back */
846 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
847 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
850 } /*SAFSS_FetchStatus*/
853 SRXAFS_BulkStatus(tcon, Fids, OutStats, CallBacks, Sync)
854 struct rx_connection *tcon;
855 struct AFSCBFids *Fids;
856 struct AFSBulkStats *OutStats;
857 struct AFSCBs *CallBacks;
858 struct AFSVolSync *Sync;
863 Vnode * targetptr = 0; /* pointer to vnode to fetch */
864 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
865 int errorCode = 0; /* return code to caller */
866 Volume * volptr = 0; /* pointer to the volume */
867 struct client *client; /* pointer to the client data */
868 afs_int32 rights, anyrights; /* rights for this and any user */
869 register struct AFSFid *tfid; /* file id we're dealing with now */
870 struct rx_call *tcall = (struct rx_call *) tcon;
871 #if FS_STATS_DETAILED
872 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
873 struct timeval opStartTime,
874 opStopTime; /* Start/stop times for RPC op*/
875 struct timeval elapsedTime; /* Transfer time */
878 * Set our stats pointer, remember when the RPC operation started, and
879 * tally the operation.
881 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
885 TM_GetTimeOfDay(&opStartTime, 0);
886 #endif /* FS_STATS_DETAILED */
888 ViceLog(1, ("SAFS_BulkStatus\n"));
890 AFSCallStats.TotalCalls++;
893 nfiles = Fids->AFSCBFids_len; /* # of files in here */
894 if (nfiles <= 0) { /* Sanity check */
896 goto Audit_and_Return;
899 /* allocate space for return output parameters */
900 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
901 malloc(nfiles * sizeof(struct AFSFetchStatus));
902 OutStats->AFSBulkStats_len = nfiles;
903 CallBacks->AFSCBs_val = (struct AFSCallBack *)
904 malloc(nfiles * sizeof(struct AFSCallBack));
905 CallBacks->AFSCBs_len = nfiles;
907 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
910 tfid = Fids->AFSCBFids_val;
911 for (i=0; i<nfiles; i++, tfid++) {
913 * Get volume/vnode for the fetched file; caller's rights to it
917 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
918 DONTCHECK, &parentwhentargetnotdir, &client,
919 READ_LOCK, &rights, &anyrights))
921 /* set volume synchronization information, but only once per call */
923 SetVolumeSync(Sync, volptr);
925 /* Are we allowed to fetch Fid's status? */
926 if (targetptr->disk.type != vDirectory) {
927 if (errorCode = Check_PermissionRights(targetptr, client, rights,
932 /* set OutStatus From the Fid */
933 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i],
934 rights, anyrights, parentwhentargetnotdir);
936 /* If a r/w volume, also set the CallBack state */
937 if (VolumeWriteable(volptr))
938 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
939 &CallBacks->AFSCBs_val[i]);
942 bzero(&myFid, sizeof(struct AFSFid));
943 myFid.Volume = tfid->Volume;
944 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
945 &CallBacks->AFSCBs_val[i]);
948 /* put back the file ID and volume */
949 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
950 parentwhentargetnotdir = (Vnode *) 0;
951 targetptr = (Vnode *) 0;
952 volptr = (Volume *) 0;
956 /* Update and store volume/vnode and parent vnodes back */
957 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
960 #if FS_STATS_DETAILED
961 TM_GetTimeOfDay(&opStopTime, 0);
962 if (errorCode == 0) {
964 (opP->numSuccesses)++;
965 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
966 fs_stats_AddTo((opP->sumTime), elapsedTime);
967 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
968 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
969 fs_stats_TimeAssign((opP->minTime), elapsedTime);
971 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
972 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
977 #endif /* FS_STATS_DETAILED */
980 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
981 osi_auditU (tcall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
984 } /*SRXAFS_BulkStatus*/
987 SRXAFS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync)
988 struct AFSVolSync *Sync;
989 struct rx_connection *tcon; /* Rx connection handle */
990 struct AFSFid *Fid; /* Fid of target file */
991 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
992 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
996 struct rx_call *tcall = (struct rx_call *) tcon;
997 #if FS_STATS_DETAILED
998 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
999 struct timeval opStartTime,
1000 opStopTime; /* Start/stop times for RPC op*/
1001 struct timeval elapsedTime; /* Transfer time */
1004 * Set our stats pointer, remember when the RPC operation started, and
1005 * tally the operation.
1007 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
1011 TM_GetTimeOfDay(&opStartTime, 0);
1012 #endif /* FS_STATS_DETAILED */
1014 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1015 goto Bad_FetchStatus;
1017 code = SAFSS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync);
1020 CallPostamble(tcon);
1022 #if FS_STATS_DETAILED
1023 TM_GetTimeOfDay(&opStopTime, 0);
1026 (opP->numSuccesses)++;
1027 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1028 fs_stats_AddTo((opP->sumTime), elapsedTime);
1029 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1030 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1031 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1033 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1034 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1039 #endif /* FS_STATS_DETAILED */
1041 osi_auditU (tcall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
1044 } /*SRXAFS_FetchStatus*/
1047 SRXAFS_StoreData (tcon, Fid, InStatus, Pos, Length, FileLength, OutStatus, Sync)
1048 struct AFSVolSync *Sync;
1049 struct rx_connection *tcon; /* Rx connection Handle */
1050 struct AFSFid *Fid; /* Fid of taret file */
1051 struct AFSStoreStatus *InStatus; /* Input Status for Fid */
1052 afs_int32 Pos; /* Not implemented yet */
1053 afs_int32 Length; /* Length of data to store */
1054 afs_int32 FileLength; /* Length of file after store */
1055 struct AFSFetchStatus *OutStatus; /* Returned status for target fid */
1058 Vnode * targetptr = 0; /* pointer to input fid */
1059 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1060 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
1061 int errorCode = 0; /* return code for caller */
1062 int fileCode = 0; /* return code from vol package */
1063 Volume * volptr = 0; /* pointer to the volume header */
1064 struct client * client; /* pointer to client structure */
1065 struct rx_call *tcall; /* remember the call structure for ftp */
1066 afs_int32 rights, anyrights; /* rights for this and any user */
1067 struct client *t_client; /* tmp ptr to client data */
1068 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1069 #if FS_STATS_DETAILED
1070 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1071 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
1072 struct timeval opStartTime,
1073 opStopTime; /* Start/stop times for RPC op*/
1074 struct timeval xferStartTime,
1075 xferStopTime; /* Start/stop times for xfer portion*/
1076 struct timeval elapsedTime; /* Transfer time */
1077 afs_int32 bytesToXfer; /* # bytes to xfer */
1078 afs_int32 bytesXferred; /* # bytes actually xfer */
1079 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
1082 * Set our stats pointers, remember when the RPC operation started, and
1083 * tally the operation.
1085 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
1086 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
1091 ViceLog(1, ("StoreData: Fid = %u.%d.%d\n",
1092 Fid->Volume, Fid->Vnode, Fid->Unique));
1093 TM_GetTimeOfDay(&opStartTime, 0);
1094 #endif /* FS_STATS_DETAILED */
1097 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
1099 /* CallPreamble changes tcon from a call to a conn */
1100 tcall = (struct rx_call *) tcon;
1101 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1104 /* Get ptr to client data for user Id for logging */
1105 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1106 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1107 ViceLog(5, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d\n",
1108 Fid->Volume, Fid->Vnode, Fid->Unique,
1109 inet_ntoa(logHostAddr), t_client->ViceId));
1112 * Get associated volume/vnode for the stored file; caller's rights
1115 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1116 MustNOTBeDIR, &parentwhentargetnotdir,
1117 &client, WRITE_LOCK, &rights, &anyrights)) {
1121 /* set volume synchronization information */
1122 SetVolumeSync(Sync, volptr);
1124 if ((targetptr->disk.type == vSymlink)) {
1125 /* Should we return a better error code here??? */
1130 /* Check if we're allowed to store the data */
1131 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1132 CHK_STOREDATA, InStatus)) {
1137 * Drop the read lock on the parent directory after saving the parent
1138 * vnode information we need to pass to GetStatus
1140 if (parentwhentargetnotdir != NULL) {
1141 tparentwhentargetnotdir = *parentwhentargetnotdir;
1142 VPutVnode(&fileCode, parentwhentargetnotdir);
1143 assert(!fileCode || (fileCode == VSALVAGE));
1144 parentwhentargetnotdir = NULL;
1149 #if FS_STATS_DETAILED
1151 * Remember when the data transfer started.
1153 TM_GetTimeOfDay(&xferStartTime, 0);
1154 #endif /* FS_STATS_DETAILED */
1156 /* Do the actual storing of the data */
1157 #if FS_STATS_DETAILED
1158 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client, tcall,
1159 Pos, Length, FileLength,
1160 (InStatus->Mask & AFS_FSYNC),
1161 &bytesToXfer, &bytesXferred);
1163 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client,
1164 tcall, Pos, Length, FileLength,
1165 (InStatus->Mask & AFS_FSYNC));
1166 if (errorCode && (!targetptr->changed_newTime))
1168 #endif /* FS_STATS_DETAILED */
1169 #if FS_STATS_DETAILED
1171 * At this point, the data transfer is done, for good or ill. Remember
1172 * when the transfer ended, bump the number of successes/failures, and
1173 * integrate the transfer size and elapsed time into the stats. If the
1174 * operation failed, we jump to the appropriate point.
1176 TM_GetTimeOfDay(&xferStopTime, 0);
1178 (xferP->numXfers)++;
1180 (xferP->numSuccesses)++;
1183 * Bump the xfer sum by the number of bytes actually sent, NOT the
1186 tot_bytesXferred += bytesXferred;
1187 (xferP->sumBytes) += (tot_bytesXferred >> 10);
1188 tot_bytesXferred &= 0x3FF;
1189 if (bytesXferred < xferP->minBytes)
1190 xferP->minBytes = bytesXferred;
1191 if (bytesXferred > xferP->maxBytes)
1192 xferP->maxBytes = bytesXferred;
1195 * Tally the size of the object. Note: we tally the actual size,
1196 * NOT the number of bytes that made it out over the wire.
1198 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
1199 (xferP->count[0])++;
1201 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
1202 (xferP->count[1])++;
1204 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
1205 (xferP->count[2])++;
1207 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
1208 (xferP->count[3])++;
1210 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
1211 (xferP->count[4])++;
1213 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
1214 (xferP->count[5])++;
1216 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
1217 (xferP->count[6])++;
1219 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
1220 (xferP->count[7])++;
1222 (xferP->count[8])++;
1224 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
1225 fs_stats_AddTo((xferP->sumTime), elapsedTime);
1226 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
1227 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
1228 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
1230 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
1231 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
1237 * Finally, go off to tell our caller the bad news in case the
1240 if (errorCode && (!targetptr->changed_newTime))
1242 #endif /* FS_STATS_DETAILED */
1244 /* Update the status of the target's vnode */
1245 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus, targetptr,
1248 /* Get the updated File's status back to the caller */
1249 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
1252 /* Update and store volume/vnode and parent vnodes back */
1253 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1254 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
1256 CallPostamble(tcon);
1258 #if FS_STATS_DETAILED
1259 TM_GetTimeOfDay(&opStopTime, 0);
1260 if (errorCode == 0) {
1262 (opP->numSuccesses)++;
1263 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1264 fs_stats_AddTo((opP->sumTime), elapsedTime);
1265 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1266 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1267 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1269 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1270 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1274 #endif /* FS_STATS_DETAILED */
1276 osi_auditU (tcall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
1279 } /*SRXAFS_StoreData*/
1282 SRXAFS_StoreACL (tcon, Fid, AccessList, OutStatus, Sync)
1283 struct AFSVolSync *Sync;
1284 struct rx_connection *tcon; /* Rx connection handle */
1285 struct AFSFid *Fid; /* Target dir's fid */
1286 struct AFSOpaque *AccessList; /* Access List's contents */
1287 struct AFSFetchStatus *OutStatus; /* Returned status of fid */
1290 Vnode * targetptr = 0; /* pointer to input fid */
1291 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1292 int errorCode = 0; /* return code for caller */
1293 struct AFSStoreStatus InStatus; /* Input status for fid */
1294 Volume * volptr = 0; /* pointer to the volume header */
1295 struct client * client; /* pointer to client structure */
1296 afs_int32 rights, anyrights; /* rights for this and any user */
1297 struct rx_call *tcall = (struct rx_call *) tcon;
1298 struct client *t_client; /* tmp ptr to client data */
1299 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1300 #if FS_STATS_DETAILED
1301 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1302 struct timeval opStartTime,
1303 opStopTime; /* Start/stop times for RPC op*/
1304 struct timeval elapsedTime; /* Transfer time */
1307 * Set our stats pointer, remember when the RPC operation started, and
1308 * tally the operation.
1310 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
1314 TM_GetTimeOfDay(&opStartTime, 0);
1315 #endif /* FS_STATS_DETAILED */
1316 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1319 /* Get ptr to client data for user Id for logging */
1320 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1321 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1322 ViceLog(1, ("SAFS_StoreACL, Fid = %u.%d.%d, ACL=%s, Host %s, Id %d\n",
1323 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
1324 inet_ntoa(logHostAddr), t_client->ViceId));
1326 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
1329 InStatus.Mask = 0; /* not storing any status */
1332 * Get associated volume/vnode for the target dir; caller's rights
1333 * are also returned.
1335 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1336 MustBeDIR, &parentwhentargetnotdir,
1337 &client, WRITE_LOCK, &rights, &anyrights)) {
1341 /* set volume synchronization information */
1342 SetVolumeSync(Sync, volptr);
1344 /* Check if we have permission to change the dir's ACL */
1345 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1346 CHK_STOREACL, &InStatus)) {
1350 /* Build and store the new Access List for the dir */
1351 if (errorCode = RXStore_AccessList(targetptr, AccessList)) {
1355 targetptr->changed_newTime = 1; /* status change of directory */
1357 /* convert the write lock to a read lock before breaking callbacks */
1358 VVnodeWriteToRead(&errorCode, targetptr);
1359 assert(!errorCode || errorCode == VSALVAGE);
1361 /* break call backs on the directory */
1362 BreakCallBack(client->host, Fid, 0);
1364 /* Get the updated dir's status back to the caller */
1365 GetStatus(targetptr, OutStatus, rights, anyrights, (struct vnode *)0);
1368 /* Update and store volume/vnode and parent vnodes back */
1369 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1370 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
1371 CallPostamble(tcon);
1373 #if FS_STATS_DETAILED
1374 TM_GetTimeOfDay(&opStopTime, 0);
1375 if (errorCode == 0) {
1377 (opP->numSuccesses)++;
1378 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1379 fs_stats_AddTo((opP->sumTime), elapsedTime);
1380 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1381 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1382 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1384 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1385 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1389 #endif /* FS_STATS_DETAILED */
1391 osi_auditU (tcall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
1394 } /*SRXAFS_StoreACL*/
1398 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
1399 * should be merged when possible.
1401 SAFSS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync)
1402 struct rx_connection *tcon; /* Rx connection Handle */
1403 struct AFSFid *Fid; /* Target file's fid */
1404 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1405 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1406 struct AFSVolSync *Sync;
1409 Vnode * targetptr = 0; /* pointer to input fid */
1410 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1411 int errorCode = 0; /* return code for caller */
1412 Volume * volptr = 0; /* pointer to the volume header */
1413 struct client * client; /* pointer to client structure */
1414 afs_int32 rights, anyrights; /* rights for this and any user */
1415 struct client *t_client; /* tmp ptr to client data */
1416 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1418 /* Get ptr to client data for user Id for logging */
1419 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1420 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1421 ViceLog(1, ("SAFS_StoreStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
1422 Fid->Volume, Fid->Vnode, Fid->Unique,
1423 inet_ntoa(logHostAddr), t_client->ViceId));
1425 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
1428 * Get volume/vnode for the target file; caller's rights to it are
1431 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1432 DONTCHECK, &parentwhentargetnotdir,
1433 &client, WRITE_LOCK, &rights, &anyrights)) {
1434 goto Bad_StoreStatus;
1437 /* set volume synchronization information */
1438 SetVolumeSync(Sync, volptr);
1440 /* Check if the caller has proper permissions to store status to Fid */
1441 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1442 CHK_STORESTATUS, InStatus)) {
1443 goto Bad_StoreStatus;
1446 * Check for a symbolic link; we can't chmod these (otherwise could
1447 * change a symlink to a mt pt or vice versa)
1449 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
1451 goto Bad_StoreStatus;
1454 /* Update the status of the target's vnode */
1455 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
1456 (parentwhentargetnotdir ?
1457 parentwhentargetnotdir : targetptr), volptr, 0);
1459 /* convert the write lock to a read lock before breaking callbacks */
1460 VVnodeWriteToRead(&errorCode, targetptr);
1461 assert(!errorCode || errorCode == VSALVAGE);
1463 /* Break call backs on Fid */
1464 BreakCallBack(client->host, Fid, 0);
1466 /* Return the updated status back to caller */
1467 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
1470 /* Update and store volume/vnode and parent vnodes back */
1471 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1472 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
1475 } /*SAFSS_StoreStatus*/
1478 SRXAFS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync)
1479 struct AFSVolSync *Sync;
1480 struct rx_connection *tcon; /* Rx connection Handle */
1481 struct AFSFid *Fid; /* Target file's fid */
1482 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1483 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1487 struct rx_call *tcall = (struct rx_call *) tcon;
1488 #if FS_STATS_DETAILED
1489 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1490 struct timeval opStartTime,
1491 opStopTime; /* Start/stop times for RPC op*/
1492 struct timeval elapsedTime; /* Transfer time */
1495 * Set our stats pointer, remember when the RPC operation started, and
1496 * tally the operation.
1498 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
1502 TM_GetTimeOfDay(&opStartTime, 0);
1503 #endif /* FS_STATS_DETAILED */
1505 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1506 goto Bad_StoreStatus;
1508 code = SAFSS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync);
1511 CallPostamble(tcon);
1513 #if FS_STATS_DETAILED
1514 TM_GetTimeOfDay(&opStopTime, 0);
1517 (opP->numSuccesses)++;
1518 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1519 fs_stats_AddTo((opP->sumTime), elapsedTime);
1520 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1521 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1522 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1524 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1525 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1530 #endif /* FS_STATS_DETAILED */
1532 osi_auditU (tcall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
1535 } /*SRXAFS_StoreStatus*/
1539 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
1540 * merged in when possible.
1542 SAFSS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync)
1543 struct rx_connection *tcon; /* Rx connection handle */
1544 struct AFSFid *DirFid; /* Dir fid for file to remove */
1545 char *Name; /* File name to remove */
1546 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1547 struct AFSVolSync *Sync;
1550 Vnode * parentptr = 0; /* vnode of input Directory */
1551 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1552 Vnode * targetptr = 0; /* file to be deleted */
1553 Volume * volptr = 0; /* pointer to the volume header */
1554 AFSFid fileFid; /* area for Fid from the directory */
1555 int errorCode = 0; /* error code */
1556 DirHandle dir; /* Handle for dir package I/O */
1557 struct client * client; /* pointer to client structure */
1558 afs_int32 rights, anyrights; /* rights for this and any user */
1559 struct client *t_client; /* tmp ptr to client data */
1560 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1562 /* Get ptr to client data for user Id for logging */
1563 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1564 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1565 ViceLog(1, ("SAFS_RemoveFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1566 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1567 inet_ntoa(logHostAddr), t_client->ViceId));
1569 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
1572 * Get volume/vnode for the parent dir; caller's access rights are
1575 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1576 MustBeDIR, &parentwhentargetnotdir,
1577 &client, WRITE_LOCK, &rights, &anyrights)) {
1578 goto Bad_RemoveFile;
1580 /* set volume synchronization information */
1581 SetVolumeSync(Sync, volptr);
1583 /* Does the caller has delete (& write) access to the parent directory? */
1584 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
1585 goto Bad_RemoveFile;
1588 /* Actually delete the desired file */
1589 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir,
1590 &fileFid, Name, MustNOTBeDIR)) {
1591 goto Bad_RemoveFile;
1594 /* Update the vnode status of the parent dir */
1595 #if FS_STATS_DETAILED
1596 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1597 parentptr->disk.linkCount, client->InSameNetwork);
1599 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1600 parentptr->disk.linkCount);
1601 #endif /* FS_STATS_DETAILED */
1603 /* Return the updated parent dir's status back to caller */
1604 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
1606 /* Handle internal callback state for the parent and the deleted file */
1607 if (targetptr->disk.linkCount == 0) {
1608 /* no references left, discard entry */
1609 DeleteFileCallBacks(&fileFid);
1610 /* convert the parent lock to a read lock before breaking callbacks */
1611 VVnodeWriteToRead(&errorCode, parentptr);
1612 assert(!errorCode || errorCode == VSALVAGE);
1614 /* convert the parent lock to a read lock before breaking callbacks */
1615 VVnodeWriteToRead(&errorCode, parentptr);
1616 assert(!errorCode || errorCode == VSALVAGE);
1617 /* convert the target lock to a read lock before breaking callbacks */
1618 VVnodeWriteToRead(&errorCode, targetptr);
1619 assert(!errorCode || errorCode == VSALVAGE);
1620 /* tell all the file has changed */
1621 BreakCallBack(client->host, &fileFid, 1);
1624 /* break call back on the directory */
1625 BreakCallBack(client->host, DirFid, 0);
1628 /* Update and store volume/vnode and parent vnodes back */
1629 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
1630 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
1633 } /*SAFSS_RemoveFile*/
1636 SRXAFS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync)
1637 struct AFSVolSync *Sync;
1638 struct rx_connection *tcon; /* Rx connection handle */
1639 struct AFSFid *DirFid; /* Dir fid for file to remove */
1640 char *Name; /* File name to remove */
1641 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1645 struct rx_call *tcall = (struct rx_call *) tcon;
1646 #if FS_STATS_DETAILED
1647 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1648 struct timeval opStartTime,
1649 opStopTime; /* Start/stop times for RPC op*/
1650 struct timeval elapsedTime; /* Transfer time */
1653 * Set our stats pointer, remember when the RPC operation started, and
1654 * tally the operation.
1656 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
1660 TM_GetTimeOfDay(&opStartTime, 0);
1661 #endif /* FS_STATS_DETAILED */
1663 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1664 goto Bad_RemoveFile;
1666 code = SAFSS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync);
1669 CallPostamble(tcon);
1671 #if FS_STATS_DETAILED
1672 TM_GetTimeOfDay(&opStopTime, 0);
1675 (opP->numSuccesses)++;
1676 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1677 fs_stats_AddTo((opP->sumTime), elapsedTime);
1678 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1679 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1680 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1682 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1683 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1688 #endif /* FS_STATS_DETAILED */
1690 osi_auditU (tcall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
1693 } /*SRXAFS_RemoveFile*/
1697 * This routine is called exclusively from SRXAFS_CreateFile(), and should
1698 * be merged in when possible.
1700 SAFSS_CreateFile (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus,
1701 OutDirStatus, CallBack, Sync)
1702 struct rx_connection *tcon; /* Rx connection handle */
1703 struct AFSFid *DirFid; /* Parent Dir fid */
1704 char *Name; /* File name to be created */
1705 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
1706 struct AFSFid *OutFid; /* Fid for newly created file */
1707 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
1708 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
1709 struct AFSCallBack *CallBack; /* Return callback promise for new file */
1710 struct AFSVolSync *Sync;
1713 Vnode * parentptr = 0; /* vnode of input Directory */
1714 Vnode * targetptr = 0; /* vnode of the new file */
1715 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1716 Volume * volptr = 0; /* pointer to the volume header */
1717 int errorCode = 0; /* error code */
1718 DirHandle dir; /* Handle for dir package I/O */
1719 struct client * client; /* pointer to client structure */
1720 afs_int32 rights, anyrights; /* rights for this and any user */
1721 struct client *t_client; /* tmp ptr to client data */
1722 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1724 /* Get ptr to client data for user Id for logging */
1725 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1726 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1727 ViceLog(1, ("SAFS_CreateFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1728 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1729 inet_ntoa(logHostAddr), t_client->ViceId));
1731 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
1733 if (!FileNameOK(Name)) {
1735 goto Bad_CreateFile;
1739 * Get associated volume/vnode for the parent dir; caller long are
1742 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1743 MustBeDIR, &parentwhentargetnotdir,
1744 &client, WRITE_LOCK, &rights, &anyrights)) {
1745 goto Bad_CreateFile;
1748 /* set volume synchronization information */
1749 SetVolumeSync(Sync, volptr);
1751 /* Can we write (and insert) onto the parent directory? */
1752 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
1753 goto Bad_CreateFile;
1755 /* get a new vnode for the file to be created and set it up */
1756 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
1757 Name, OutFid, vFile, nBlocks(0))) {
1758 goto Bad_CreateFile;
1761 /* update the status of the parent vnode */
1762 #if FS_STATS_DETAILED
1763 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1764 parentptr->disk.linkCount, client->InSameNetwork);
1766 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1767 parentptr->disk.linkCount);
1768 #endif /* FS_STATS_DETAILED */
1770 /* update the status of the new file's vnode */
1771 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
1772 parentptr, volptr, 0);
1774 /* set up the return status for the parent dir and the newly created file */
1775 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
1776 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
1778 /* convert the write lock to a read lock before breaking callbacks */
1779 VVnodeWriteToRead(&errorCode, parentptr);
1780 assert(!errorCode || errorCode == VSALVAGE);
1782 /* break call back on parent dir */
1783 BreakCallBack(client->host, DirFid, 0);
1785 /* Return a callback promise for the newly created file to the caller */
1786 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
1789 /* Update and store volume/vnode and parent vnodes back */
1790 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
1791 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
1794 } /*SAFSS_CreateFile*/
1797 SRXAFS_CreateFile (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
1798 struct AFSVolSync *Sync;
1799 struct rx_connection *tcon; /* Rx connection handle */
1800 struct AFSFid *DirFid; /* Parent Dir fid */
1801 char *Name; /* File name to be created */
1802 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
1803 struct AFSFid *OutFid; /* Fid for newly created file */
1804 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
1805 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
1806 struct AFSCallBack *CallBack; /* Return callback promise for new file */
1810 struct rx_call *tcall = (struct rx_call *) tcon;
1811 #if FS_STATS_DETAILED
1812 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1813 struct timeval opStartTime,
1814 opStopTime; /* Start/stop times for RPC op*/
1815 struct timeval elapsedTime; /* Transfer time */
1818 * Set our stats pointer, remember when the RPC operation started, and
1819 * tally the operation.
1821 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
1825 TM_GetTimeOfDay(&opStartTime, 0);
1826 #endif /* FS_STATS_DETAILED */
1828 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1829 goto Bad_CreateFile;
1831 code = SAFSS_CreateFile (tcon, DirFid, Name, InStatus, OutFid,
1832 OutFidStatus, OutDirStatus, CallBack, Sync);
1835 CallPostamble(tcon);
1837 #if FS_STATS_DETAILED
1838 TM_GetTimeOfDay(&opStopTime, 0);
1841 (opP->numSuccesses)++;
1842 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1843 fs_stats_AddTo((opP->sumTime), elapsedTime);
1844 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1845 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1846 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1848 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1849 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1853 #endif /* FS_STATS_DETAILED */
1855 osi_auditU (tcall, CreateFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
1858 } /*SRXAFS_CreateFile*/
1862 * This routine is called exclusively from SRXAFS_Rename(), and should be
1863 * merged in when possible.
1865 SAFSS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus,
1866 OutNewDirStatus, Sync)
1867 struct rx_connection *tcon; /* Rx connection handle */
1868 struct AFSFid *OldDirFid; /* From parent dir's fid */
1869 char *OldName; /* From file name */
1870 struct AFSFid *NewDirFid; /* To parent dir's fid */
1871 char *NewName; /* To new file name */
1872 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
1873 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
1874 struct AFSVolSync *Sync;
1877 Vnode * oldvptr = 0; /* vnode of the old Directory */
1878 Vnode * newvptr = 0; /* vnode of the new Directory */
1879 Vnode * fileptr = 0; /* vnode of the file to move */
1880 Vnode * newfileptr = 0; /* vnode of the file to delete */
1881 Vnode * testvptr = 0; /* used in directory tree walk */
1882 Vnode * parent = 0; /* parent for use in SetAccessList */
1883 int errorCode = 0; /* error code */
1884 int fileCode = 0; /* used when writing Vnodes */
1885 VnodeId testnode; /* used in directory tree walk */
1886 AFSFid fileFid; /* Fid of file to move */
1887 AFSFid newFileFid; /* Fid of new file */
1888 DirHandle olddir; /* Handle for dir package I/O */
1889 DirHandle newdir; /* Handle for dir package I/O */
1890 DirHandle filedir; /* Handle for dir package I/O */
1891 DirHandle newfiledir; /* Handle for dir package I/O */
1892 Volume * volptr = 0; /* pointer to the volume header */
1893 struct client * client; /* pointer to client structure */
1894 afs_int32 rights, anyrights; /* rights for this and any user */
1895 afs_int32 newrights; /* rights for this user */
1896 afs_int32 newanyrights; /* rights for any user */
1897 int doDelete; /* deleted the rename target (ref count now 0) */
1899 struct client *t_client; /* tmp ptr to client data */
1900 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1902 /* Get ptr to client data for user Id for logging */
1903 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1904 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1905 ViceLog(1, ("SAFS_Rename %s to %s, Fid = %u.%d.%d to %u.%d.%d, Host %s, Id %d\n",
1906 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
1907 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
1909 inet_ntoa(logHostAddr), t_client->ViceId));
1911 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
1913 if (!FileNameOK(NewName)) {
1917 if (OldDirFid->Volume != NewDirFid->Volume) {
1922 if ( (strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0) ||
1923 (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0) ||
1924 (strlen(NewName) == 0) || (strlen(OldName) == 0) ) {
1930 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
1931 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr,
1932 &oldvptr, MustBeDIR, &parent,
1933 &client, WRITE_LOCK, &rights,
1938 if (OldDirFid->Vnode == NewDirFid->Vnode) {
1940 newrights = rights, newanyrights = anyrights;
1943 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
1944 &newvptr, MustBeDIR, &parent,
1945 &client, WRITE_LOCK, &newrights,
1952 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
1953 &newvptr, MustBeDIR, &parent,
1954 &client, WRITE_LOCK, &newrights,
1959 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr,
1960 MustBeDIR, &parent, &client, WRITE_LOCK,
1961 &rights, &anyrights)) {
1967 /* set volume synchronization information */
1968 SetVolumeSync(Sync, volptr);
1970 if (errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE)) {
1973 if (errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT)) {
1977 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
1978 * call to CopyOnWrite returns error, it is not necessary to revert back
1979 * the effects of the first call because the contents of the volume is
1980 * not modified, it is only replicated.
1982 if (oldvptr->disk.cloned)
1984 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
1985 if ( errorCode = CopyOnWrite(oldvptr, volptr) )
1988 SetDirHandle(&olddir, oldvptr);
1989 if (newvptr->disk.cloned)
1991 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
1992 if ( errorCode = CopyOnWrite(newvptr, volptr) )
1996 SetDirHandle(&newdir, newvptr);
1998 /* Lookup the file to delete its vnode */
1999 if (Lookup(&olddir, OldName, &fileFid)) {
2003 if (fileFid.Vnode == oldvptr->vnodeNumber ||
2004 fileFid.Vnode == newvptr->vnodeNumber) {
2005 errorCode = FSERR_ELOOP;
2008 fileFid.Volume = V_id(volptr);
2009 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
2010 if (errorCode != 0) {
2011 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n", OldName, errorCode));
2012 VTakeOffline (volptr);
2015 if (fileptr->disk.uniquifier != fileFid.Unique) {
2016 ViceLog (0, ("SAFSS_Rename(): Old file %s uniquifier mismatch\n", OldName));
2017 VTakeOffline (volptr);
2022 if (fileptr->disk.type != vDirectory &&
2023 oldvptr != newvptr &&
2024 fileptr->disk.linkCount != 1) {
2026 * Hard links exist to this file - cannot move one of the links to
2027 * a new directory because of AFS restrictions (this is the same
2028 * reason that links cannot be made across directories, i.e.
2035 /* Lookup the new file */
2036 if (!(Lookup(&newdir, NewName, &newFileFid))) {
2037 if (!(newrights & PRSFS_DELETE)) {
2041 if (newFileFid.Vnode == oldvptr->vnodeNumber ||
2042 newFileFid.Vnode == newvptr->vnodeNumber ||
2043 newFileFid.Vnode == fileFid.Vnode) {
2047 newFileFid.Volume = V_id(volptr);
2048 newfileptr = VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
2049 if (errorCode != 0) {
2050 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n", NewName, errorCode));
2051 VTakeOffline (volptr);
2054 if (fileptr->disk.uniquifier != fileFid.Unique) {
2055 ViceLog (0, ("SAFSS_Rename(): New file %s uniquifier mismatch\n", NewName));
2056 VTakeOffline (volptr);
2060 SetDirHandle(&newfiledir, newfileptr);
2061 /* Now check that we're moving directories over directories properly, etc.
2062 * return proper POSIX error codes:
2063 * if fileptr is a file and new is a dir: EISDIR.
2064 * if fileptr is a dir and new is a file: ENOTDIR.
2065 * Also, dir to be removed must be empty, of course.
2067 if (newfileptr->disk.type == vDirectory) {
2068 if (fileptr->disk.type != vDirectory) {
2072 if ((IsEmpty(&newfiledir))) {
2078 if (fileptr->disk.type == vDirectory) {
2079 errorCode = ENOTDIR;
2086 * ok - now we check that the old name is not above new name in the
2087 * directory structure. This is to prevent removing a subtree alltogether
2089 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
2090 for (testnode = newvptr->disk.parent; testnode != 0;) {
2091 if (testnode == oldvptr->vnodeNumber) {
2092 testnode = oldvptr->disk.parent;
2095 if ((testnode == fileptr->vnodeNumber) ||
2096 (testnode == newvptr->vnodeNumber)) {
2097 errorCode = FSERR_ELOOP;
2100 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
2101 errorCode = FSERR_ELOOP;
2104 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
2105 assert(errorCode == 0);
2106 testnode = testvptr->disk.parent;
2107 VPutVnode(&errorCode, testvptr);
2108 assert(errorCode == 0);
2111 /* Do the CopyonWrite first before modifying anything else. Copying is
2112 * required because we may have to change entries for ..
2114 if ((fileptr->disk.type == vDirectory ) && (fileptr->disk.cloned) )
2116 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
2117 if ( errorCode = CopyOnWrite(fileptr, volptr) )
2121 /* If the new name exists already, delete it and the file it points to */
2124 /* Delete NewName from its directory */
2125 code = Delete(&newdir, NewName);
2128 /* Drop the link count */
2129 newfileptr->disk.linkCount--;
2130 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
2131 VAdjustDiskUsage(&errorCode, volptr,
2132 -(int)nBlocks(newfileptr->disk.length), 0);
2133 if (VN_GET_INO(newfileptr)) {
2134 IH_REALLYCLOSE(newfileptr->handle);
2135 errorCode = IH_DEC(V_linkHandle(volptr),
2136 VN_GET_INO(newfileptr),
2137 V_parentId(volptr));
2138 IH_RELEASE(newfileptr->handle);
2139 if (errorCode == -1) {
2140 ViceLog(0, ("Del: inode=%d, name=%s, errno=%d\n",
2141 PrintInode(NULL, VN_GET_INO(newfileptr)),
2143 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
2144 ViceLog(0, ("Do we need to fsck?"));
2147 VN_SET_INO(newfileptr, (Inode)0);
2148 newfileptr->delete = 1; /* Mark NewName vnode to delete */
2151 /* Link count did not drop to zero.
2152 * Mark NewName vnode as changed - updates stime.
2154 newfileptr->changed_newTime = 1;
2159 * If the create below fails, and the delete above worked, we have
2160 * removed the new name and not replaced it. This is not very likely,
2161 * but possible. We could try to put the old file back, but it is
2162 * highly unlikely that it would work since it would involve issuing
2165 if (errorCode = Create(&newdir,(char *) NewName, &fileFid))
2168 /* Delete the old name */
2169 assert(Delete(&olddir,(char *) OldName) == 0);
2171 /* if the directory length changes, reflect it in the statistics */
2172 #if FS_STATS_DETAILED
2173 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2174 oldvptr->disk.linkCount, client->InSameNetwork);
2175 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2176 newvptr->disk.linkCount, client->InSameNetwork);
2178 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2179 oldvptr->disk.linkCount);
2180 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2181 newvptr->disk.linkCount);
2182 #endif /* FS_STATS_DETAILED */
2184 if (oldvptr == newvptr)
2185 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
2187 fileptr->disk.parent = newvptr->vnodeNumber;
2188 fileptr->changed_newTime = 1; /* status change of moved file */
2190 /* if we are dealing with a rename of a directory */
2191 if (fileptr->disk.type == vDirectory) {
2192 assert(!fileptr->disk.cloned);
2193 SetDirHandle(&filedir, fileptr);
2194 /* fix .. to point to the correct place */
2195 Delete(&filedir, ".."); /* No assert--some directories may be bad */
2196 assert(Create(&filedir, "..", NewDirFid) == 0);
2197 fileptr->disk.dataVersion++;
2198 /* if the parent directories are different the link counts have to be */
2199 /* changed due to .. in the renamed directory */
2200 if (oldvptr != newvptr) {
2201 oldvptr->disk.linkCount--;
2202 newvptr->disk.linkCount++;
2206 /* set up return status */
2207 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, (struct vnode *)0);
2208 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, (struct vnode *)0);
2209 if (newfileptr && doDelete) {
2210 DeleteFileCallBacks(&newFileFid); /* no other references */
2215 /* convert the write locks to a read locks before breaking callbacks */
2216 VVnodeWriteToRead(&errorCode, newvptr);
2217 assert(!errorCode || errorCode == VSALVAGE);
2218 if (oldvptr != newvptr) {
2219 VVnodeWriteToRead(&errorCode, oldvptr);
2220 assert(!errorCode || errorCode == VSALVAGE);
2222 if (newfileptr && !doDelete) {
2223 /* convert the write lock to a read lock before breaking callbacks */
2224 VVnodeWriteToRead(&errorCode, newfileptr);
2225 assert(!errorCode || errorCode == VSALVAGE);
2228 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
2229 BreakCallBack(client->host, NewDirFid, 0);
2230 if (oldvptr != newvptr) {
2231 BreakCallBack(client->host, OldDirFid, 0);
2232 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
2233 BreakCallBack(client->host, &fileFid, 0);
2236 /* Note: it is not necessary to break the callback */
2238 DeleteFileCallBacks(&newFileFid); /* no other references */
2240 /* other's still exist (with wrong link count) */
2241 BreakCallBack(client->host, &newFileFid, 1);
2246 VPutVnode(&fileCode, newfileptr);
2247 assert(fileCode == 0);
2249 PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr? newvptr : 0),
2251 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
2257 SRXAFS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus, OutNewDirStatus, Sync)
2258 struct AFSVolSync *Sync;
2259 struct rx_connection *tcon; /* Rx connection handle */
2260 struct AFSFid *OldDirFid; /* From parent dir's fid */
2261 char *OldName; /* From file name */
2262 struct AFSFid *NewDirFid; /* To parent dir's fid */
2263 char *NewName; /* To new file name */
2264 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
2265 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
2269 struct rx_call *tcall = (struct rx_call *) tcon;
2270 #if FS_STATS_DETAILED
2271 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2272 struct timeval opStartTime,
2273 opStopTime; /* Start/stop times for RPC op*/
2274 struct timeval elapsedTime; /* Transfer time */
2277 * Set our stats pointer, remember when the RPC operation started, and
2278 * tally the operation.
2280 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
2284 TM_GetTimeOfDay(&opStartTime, 0);
2285 #endif /* FS_STATS_DETAILED */
2287 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2290 code = SAFSS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName,
2291 OutOldDirStatus, OutNewDirStatus, Sync);
2294 CallPostamble(tcon);
2296 #if FS_STATS_DETAILED
2297 TM_GetTimeOfDay(&opStopTime, 0);
2300 (opP->numSuccesses)++;
2301 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2302 fs_stats_AddTo((opP->sumTime), elapsedTime);
2303 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2304 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2305 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2307 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2308 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2313 #endif /* FS_STATS_DETAILED */
2315 osi_auditU (tcall, RenameFileEvent, code, AUD_FID, OldDirFid, AUD_STR, OldName, AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
2322 * This routine is called exclusively by SRXAFS_Symlink(), and should be
2323 * merged into it when possible.
2325 SAFSS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2326 struct rx_connection *tcon; /* Rx connection handle */
2327 struct AFSFid *DirFid; /* Parent dir's fid */
2328 char *Name; /* File name to create */
2329 char *LinkContents; /* Contents of the new created file */
2330 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2331 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2332 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2333 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2334 struct AFSVolSync *Sync; /* volume synchronization information */
2337 Vnode * parentptr = 0; /* vnode of input Directory */
2338 Vnode * targetptr = 0; /* vnode of the new link */
2339 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2340 int errorCode = 0; /* error code */
2342 DirHandle dir; /* Handle for dir package I/O */
2343 Volume * volptr = 0; /* pointer to the volume header */
2344 struct client * client; /* pointer to client structure */
2345 afs_int32 rights, anyrights, fd; /* rights for this and any user */
2346 struct client *t_client; /* tmp ptr to client data */
2347 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2350 /* Get ptr to client data for user Id for logging */
2351 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2352 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2353 ViceLog(1, ("SAFS_Symlink %s to %s, Did = %u.%d.%d, Host %s, Id %d\n", Name,
2354 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2355 inet_ntoa(logHostAddr), t_client->ViceId));
2357 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
2359 if (!FileNameOK(Name)) {
2365 * Get the vnode and volume for the parent dir along with the caller's
2368 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2369 MustBeDIR, &parentwhentargetnotdir,
2370 &client, WRITE_LOCK, &rights, &anyrights)) {
2374 /* set volume synchronization information */
2375 SetVolumeSync(Sync, volptr);
2377 /* Does the caller has insert (and write) access to the parent directory? */
2378 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2383 * If we're creating a mount point (owner mode bits sans x bit), we must
2384 * have administer access to the directory, too. Always allow sysadmins
2387 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0100)) {
2389 * We have a symlink, 'cause we're trying to set the Unix mode bits
2390 * to something without the owner x bits (default mode bits if
2391 * AFS_SETMODE is false is 0777)
2393 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
2399 /* get a new vnode for the symlink and set it up */
2400 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
2401 Name, OutFid, vSymlink,
2402 nBlocks(strlen((char *) LinkContents)))) {
2406 /* update the status of the parent vnode */
2407 #if FS_STATS_DETAILED
2408 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2409 parentptr->disk.linkCount, client->InSameNetwork);
2411 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2412 parentptr->disk.linkCount);
2413 #endif /* FS_STATS_DETAILED */
2415 /* update the status of the new symbolic link file vnode */
2416 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus, parentptr,
2417 volptr, strlen((char *)LinkContents));
2419 /* Write the contents of the symbolic link name into the target inode */
2420 fdP = IH_OPEN(targetptr->handle);
2421 assert(fdP != NULL);
2422 assert(FDH_WRITE(fdP, (char *) LinkContents, strlen((char *) LinkContents)) == strlen((char *) LinkContents));
2425 * Set up and return modified status for the parent dir and new symlink
2428 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2429 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
2431 /* convert the write lock to a read lock before breaking callbacks */
2432 VVnodeWriteToRead(&errorCode, parentptr);
2433 assert(!errorCode || errorCode == VSALVAGE);
2435 /* break call back on the parent dir */
2436 BreakCallBack(client->host, DirFid, 0);
2439 /* Write the all modified vnodes (parent, new files) and volume back */
2440 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2441 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
2447 SRXAFS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2448 struct AFSVolSync *Sync;
2449 struct rx_connection *tcon; /* Rx connection handle */
2450 struct AFSFid *DirFid; /* Parent dir's fid */
2451 char *Name; /* File name to create */
2452 char *LinkContents; /* Contents of the new created file */
2453 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2454 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2455 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2456 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2460 struct rx_call *tcall = (struct rx_call *) tcon;
2461 #if FS_STATS_DETAILED
2462 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2463 struct timeval opStartTime,
2464 opStopTime; /* Start/stop times for RPC op*/
2465 struct timeval elapsedTime; /* Transfer time */
2468 * Set our stats pointer, remember when the RPC operation started, and
2469 * tally the operation.
2471 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
2475 TM_GetTimeOfDay(&opStartTime, 0);
2476 #endif /* FS_STATS_DETAILED */
2478 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2481 code = SAFSS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid,
2482 OutFidStatus, OutDirStatus, Sync);
2485 CallPostamble(tcon);
2487 #if FS_STATS_DETAILED
2488 TM_GetTimeOfDay(&opStopTime, 0);
2491 (opP->numSuccesses)++;
2492 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2493 fs_stats_AddTo((opP->sumTime), elapsedTime);
2494 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2495 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2496 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2498 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2499 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2504 #endif /* FS_STATS_DETAILED */
2506 osi_auditU (tcall, SymlinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2509 } /*SRXAFS_Symlink*/
2513 * This routine is called exclusively by SRXAFS_Link(), and should be
2514 * merged into it when possible.
2516 SAFSS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2517 struct rx_connection *tcon; /* Rx connection handle */
2518 struct AFSFid *DirFid; /* Parent dir's fid */
2519 char *Name; /* File name to create */
2520 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2521 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2522 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2523 struct AFSVolSync *Sync;
2526 Vnode * parentptr = 0; /* vnode of input Directory */
2527 Vnode * targetptr = 0; /* vnode of the new file */
2528 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2529 Volume * volptr = 0; /* pointer to the volume header */
2530 int errorCode = 0; /* error code */
2531 DirHandle dir; /* Handle for dir package I/O */
2532 struct client * client; /* pointer to client structure */
2533 afs_int32 rights, anyrights; /* rights for this and any user */
2534 struct client *t_client; /* tmp ptr to client data */
2535 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2537 /* Get ptr to client data for user Id for logging */
2538 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2539 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2540 ViceLog(1, ("SAFS_Link %s, Did = %u.%d.%d, Fid = %u.%d.%d, Host %s, Id %d\n",
2541 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2542 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
2543 inet_ntoa(logHostAddr), t_client->ViceId));
2545 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
2547 if (DirFid->Volume != ExistingFid->Volume) {
2551 if (!FileNameOK(Name)) {
2557 * Get the vnode and volume for the parent dir along with the caller's
2560 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2561 MustBeDIR, &parentwhentargetnotdir,
2562 &client, WRITE_LOCK, &rights, &anyrights)) {
2566 /* set volume synchronization information */
2567 SetVolumeSync(Sync, volptr);
2569 /* Can the caller insert into the parent directory? */
2570 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2574 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) ||
2575 (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
2576 /* AFS fileservers always have directory vnodes that are odd. */
2581 /* get the file vnode */
2582 if (errorCode = CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK)) {
2585 if (targetptr->disk.type != vFile) {
2589 if (targetptr->disk.parent != DirFid->Vnode) {
2593 if (parentptr->disk.cloned)
2595 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
2596 if ( errorCode = CopyOnWrite(parentptr, volptr))
2597 goto Bad_Link; /* disk full error */
2600 /* add the name to the directory */
2601 SetDirHandle(&dir, parentptr);
2602 if (errorCode = Create(&dir, (char *)Name, ExistingFid))
2606 /* update the status in the parent vnode */
2607 /**WARNING** --> disk.author SHOULDN'T be modified???? */
2608 #if FS_STATS_DETAILED
2609 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2610 parentptr->disk.linkCount, client->InSameNetwork);
2612 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2613 parentptr->disk.linkCount);
2614 #endif /* FS_STATS_DETAILED */
2616 targetptr->disk.linkCount++;
2617 targetptr->disk.author = client->ViceId;
2618 targetptr->changed_newTime = 1; /* Status change of linked-to file */
2620 /* set up return status */
2621 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2622 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
2624 /* convert the write locks to read locks before breaking callbacks */
2625 VVnodeWriteToRead(&errorCode, targetptr);
2626 assert(!errorCode || errorCode == VSALVAGE);
2627 VVnodeWriteToRead(&errorCode, parentptr);
2628 assert(!errorCode || errorCode == VSALVAGE);
2630 /* break call back on DirFid */
2631 BreakCallBack(client->host, DirFid, 0);
2633 * We also need to break the callback for the file that is hard-linked since part
2634 * of its status (like linkcount) is changed
2636 BreakCallBack(client->host, ExistingFid, 0);
2639 /* Write the all modified vnodes (parent, new files) and volume back */
2640 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2641 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
2647 SRXAFS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2648 struct AFSVolSync *Sync;
2649 struct rx_connection *tcon; /* Rx connection handle */
2650 struct AFSFid *DirFid; /* Parent dir's fid */
2651 char *Name; /* File name to create */
2652 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2653 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2654 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2658 struct rx_call *tcall = (struct rx_call *) tcon;
2659 #if FS_STATS_DETAILED
2660 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2661 struct timeval opStartTime,
2662 opStopTime; /* Start/stop times for RPC op*/
2663 struct timeval elapsedTime; /* Transfer time */
2666 * Set our stats pointer, remember when the RPC operation started, and
2667 * tally the operation.
2669 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
2673 TM_GetTimeOfDay(&opStartTime, 0);
2674 #endif /* FS_STATS_DETAILED */
2676 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2679 code = SAFSS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus,
2680 OutDirStatus, Sync);
2683 CallPostamble(tcon);
2685 #if FS_STATS_DETAILED
2686 TM_GetTimeOfDay(&opStopTime, 0);
2689 (opP->numSuccesses)++;
2690 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2691 fs_stats_AddTo((opP->sumTime), elapsedTime);
2692 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2693 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2694 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2696 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2697 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2702 #endif /* FS_STATS_DETAILED */
2704 osi_auditU (tcall, LinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_FID, ExistingFid, AUD_END);
2711 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
2712 * merged into it when possible.
2714 SAFSS_MakeDir (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus,
2715 OutDirStatus, CallBack, Sync)
2716 struct rx_connection *tcon; /* Rx connection handle */
2717 struct AFSFid *DirFid; /* Parent dir's fid */
2718 char *Name; /* Name of dir to be created */
2719 struct AFSStoreStatus *InStatus; /* Input status for new dir */
2720 struct AFSFid *OutFid; /* Fid of new dir */
2721 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
2722 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2723 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
2724 struct AFSVolSync *Sync;
2727 Vnode * parentptr = 0; /* vnode of input Directory */
2728 Vnode * targetptr = 0; /* vnode of the new file */
2729 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2730 Volume * volptr = 0; /* pointer to the volume header */
2731 int errorCode = 0; /* error code */
2732 struct acl_accessList * newACL; /* Access list */
2733 int newACLSize; /* Size of access list */
2734 DirHandle dir; /* Handle for dir package I/O */
2735 DirHandle parentdir; /* Handle for dir package I/O */
2736 struct client * client; /* pointer to client structure */
2737 afs_int32 rights, anyrights; /* rights for this and any user */
2738 struct client *t_client; /* tmp ptr to client data */
2739 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2741 /* Get ptr to client data for user Id for logging */
2742 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2743 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2744 ViceLog(1, ("SAFS_MakeDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
2745 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2746 inet_ntoa(logHostAddr), t_client->ViceId));
2748 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
2750 if (!FileNameOK(Name)) {
2756 * Get the vnode and volume for the parent dir along with the caller's
2759 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2760 MustBeDIR, &parentwhentargetnotdir,
2761 &client, WRITE_LOCK, &rights, &anyrights)) {
2765 /* set volume synchronization information */
2766 SetVolumeSync(Sync, volptr);
2768 /* Write access to the parent directory? */
2769 #ifdef DIRCREATE_NEED_WRITE
2771 * requires w access for the user to create a directory. this
2772 * closes a loophole in the current security arrangement, since a
2773 * user with i access only can create a directory and get the
2774 * implcit a access that goes with dir ownership, and proceed to
2775 * subvert quota in the volume.
2777 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) ||
2778 (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
2780 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2781 #endif /* DIRCREATE_NEED_WRITE */
2785 #define EMPTYDIRBLOCKS 2
2786 /* get a new vnode and set it up */
2787 if (errorCode = Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr,
2788 Name, OutFid, vDirectory, EMPTYDIRBLOCKS)) {
2792 /* Update the status for the parent dir */
2793 #if FS_STATS_DETAILED
2794 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
2795 parentptr->disk.linkCount+1, client->InSameNetwork);
2797 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
2798 parentptr->disk.linkCount+1);
2799 #endif /* FS_STATS_DETAILED */
2801 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
2802 assert((SetAccessList(&targetptr, &volptr, &newACL, &newACLSize,
2803 &parentwhentargetnotdir, (AFSFid *)0, 0)) == 0);
2804 assert(parentwhentargetnotdir == 0);
2805 bcopy((char *)VVnodeACL(parentptr), (char *)newACL, VAclSize(parentptr));
2807 /* update the status for the target vnode */
2808 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
2809 parentptr, volptr, 0);
2811 /* Actually create the New directory in the directory package */
2812 SetDirHandle(&dir, targetptr);
2813 assert(!(MakeDir(&dir, OutFid, DirFid)));
2815 targetptr->disk.length = Length(&dir);
2817 /* set up return status */
2818 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2819 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
2821 /* convert the write lock to a read lock before breaking callbacks */
2822 VVnodeWriteToRead(&errorCode, parentptr);
2823 assert(!errorCode || errorCode == VSALVAGE);
2825 /* break call back on DirFid */
2826 BreakCallBack(client->host, DirFid, 0);
2828 /* Return a callback promise to caller */
2829 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
2832 /* Write the all modified vnodes (parent, new files) and volume back */
2833 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2834 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
2840 SRXAFS_MakeDir (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
2841 struct AFSVolSync *Sync;
2842 struct rx_connection *tcon; /* Rx connection handle */
2843 struct AFSFid *DirFid; /* Parent dir's fid */
2844 char *Name; /* Name of dir to be created */
2845 struct AFSStoreStatus *InStatus; /* Input status for new dir */
2846 struct AFSFid *OutFid; /* Fid of new dir */
2847 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
2848 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2849 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
2853 struct rx_call *tcall = (struct rx_call *) tcon;
2854 #if FS_STATS_DETAILED
2855 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2856 struct timeval opStartTime,
2857 opStopTime; /* Start/stop times for RPC op*/
2858 struct timeval elapsedTime; /* Transfer time */
2861 * Set our stats pointer, remember when the RPC operation started, and
2862 * tally the operation.
2864 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
2868 TM_GetTimeOfDay(&opStartTime, 0);
2869 #endif /* FS_STATS_DETAILED */
2870 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2873 code = SAFSS_MakeDir (tcon, DirFid, Name, InStatus, OutFid,
2874 OutFidStatus, OutDirStatus, CallBack, Sync);
2877 CallPostamble(tcon);
2879 #if FS_STATS_DETAILED
2880 TM_GetTimeOfDay(&opStopTime, 0);
2883 (opP->numSuccesses)++;
2884 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2885 fs_stats_AddTo((opP->sumTime), elapsedTime);
2886 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2887 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2888 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2890 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2891 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2896 #endif /* FS_STATS_DETAILED */
2898 osi_auditU (tcall, MakeDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2901 } /*SRXAFS_MakeDir*/
2905 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
2906 * merged into it when possible.
2908 SAFSS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync)
2909 struct rx_connection *tcon; /* Rx connection handle */
2910 struct AFSFid *DirFid; /* Parent dir's fid */
2911 char *Name; /* (Empty) dir's name to be removed */
2912 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
2913 struct AFSVolSync *Sync;
2916 Vnode * parentptr = 0; /* vnode of input Directory */
2917 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2918 Vnode * targetptr = 0; /* file to be deleted */
2919 AFSFid fileFid; /* area for Fid from the directory */
2920 int errorCode = 0; /* error code */
2921 DirHandle dir; /* Handle for dir package I/O */
2922 Volume * volptr = 0; /* pointer to the volume header */
2923 struct client * client; /* pointer to client structure */
2924 afs_int32 rights, anyrights; /* rights for this and any user */
2925 Vnode debugvnode1, debugvnode2;
2926 struct client *t_client; /* tmp ptr to client data */
2927 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
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));
2932 ViceLog(1, ("SAFS_RemoveDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
2933 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2934 inet_ntoa(logHostAddr), t_client->ViceId));
2936 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
2939 * Get the vnode and volume for the parent dir along with the caller's
2942 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2943 MustBeDIR, &parentwhentargetnotdir,
2944 &client, WRITE_LOCK, &rights, &anyrights)) {
2947 debugvnode1 = *parentptr;
2949 /* set volume synchronization information */
2950 SetVolumeSync(Sync, volptr);
2952 /* Does the caller has delete (&write) access to the parent dir? */
2953 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
2957 debugvnode2 = *parentptr;
2958 /* Do the actual delete of the desired (empty) directory, Name */
2959 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid,
2964 /* Update the status for the parent dir; link count is also adjusted */
2965 #if FS_STATS_DETAILED
2966 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2967 parentptr->disk.linkCount-1, client->InSameNetwork);
2969 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2970 parentptr->disk.linkCount-1);
2971 #endif /* FS_STATS_DETAILED */
2973 /* Return to the caller the updated parent dir status */
2974 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
2977 * Note: it is not necessary to break the callback on fileFid, since
2978 * refcount is now 0, so no one should be able to refer to the dir
2981 DeleteFileCallBacks(&fileFid);
2983 /* convert the write lock to a read lock before breaking callbacks */
2984 VVnodeWriteToRead(&errorCode, parentptr);
2985 assert(!errorCode || errorCode == VSALVAGE);
2987 /* break call back on DirFid and fileFid */
2988 BreakCallBack(client->host, DirFid, 0);
2991 /* Write the all modified vnodes (parent, new files) and volume back */
2992 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2993 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
2996 } /*SAFSS_RemoveDir*/
2999 SRXAFS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync)
3000 struct AFSVolSync *Sync;
3001 struct rx_connection *tcon; /* Rx connection handle */
3002 struct AFSFid *DirFid; /* Parent dir's fid */
3003 char *Name; /* (Empty) dir's name to be removed */
3004 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
3008 struct rx_call *tcall = (struct rx_call *) tcon;
3009 #if FS_STATS_DETAILED
3010 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3011 struct timeval opStartTime,
3012 opStopTime; /* Start/stop times for RPC op*/
3013 struct timeval elapsedTime; /* Transfer time */
3016 * Set our stats pointer, remember when the RPC operation started, and
3017 * tally the operation.
3019 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
3023 TM_GetTimeOfDay(&opStartTime, 0);
3024 #endif /* FS_STATS_DETAILED */
3026 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3029 code = SAFSS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync);
3032 CallPostamble(tcon);
3034 #if FS_STATS_DETAILED
3035 TM_GetTimeOfDay(&opStopTime, 0);
3038 (opP->numSuccesses)++;
3039 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3040 fs_stats_AddTo((opP->sumTime), elapsedTime);
3041 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3042 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3043 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3045 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3046 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3051 #endif /* FS_STATS_DETAILED */
3053 osi_auditU (tcall, RemoveDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3056 } /*SRXAFS_RemoveDir*/
3060 * This routine is called exclusively by SRXAFS_SetLock(), and should be
3061 * merged into it when possible.
3063 SAFSS_SetLock (tcon, Fid, type, Sync)
3064 struct rx_connection *tcon; /* Rx connection handle */
3065 struct AFSFid *Fid; /* Fid of file to lock */
3066 ViceLockType type; /* Type of lock (Read or write) */
3067 struct AFSVolSync *Sync;
3070 Vnode * targetptr = 0; /* vnode of input file */
3071 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3072 int errorCode = 0; /* error code */
3073 Volume * volptr = 0; /* pointer to the volume header */
3074 struct client * client; /* pointer to client structure */
3075 afs_int32 rights, anyrights; /* rights for this and any user */
3076 struct client *t_client; /* tmp ptr to client data */
3077 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3078 static char * locktype[2] = {"LockRead","LockWrite"};
3080 if (type != LockRead && type != LockWrite) {
3084 /* Get ptr to client data for user Id for logging */
3085 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3086 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3087 ViceLog(1,("SAFS_SetLock type = %s Fid = %u.%d.%d, Host %s, Id %d\n",
3088 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
3089 inet_ntoa(logHostAddr), t_client->ViceId));
3091 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
3095 * Get the vnode and volume for the desired file along with the caller's
3098 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3099 DONTCHECK, &parentwhentargetnotdir,
3100 &client, WRITE_LOCK, &rights, &anyrights)) {
3104 /* set volume synchronization information */
3105 SetVolumeSync(Sync, volptr);
3107 /* Handle the particular type of set locking, type */
3108 errorCode = HandleLocking(targetptr, rights, type);
3111 /* Write the all modified vnodes (parent, new files) and volume back */
3112 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3114 if ((errorCode == VREADONLY) && (type == LockRead))
3115 errorCode = 0; /* allow read locks on RO volumes without saving state */
3117 ViceLog(2,("SAFS_SetLock returns %d\n", errorCode));
3123 SRXAFS_OldSetLock(tcon, Fid, type, Sync)
3124 struct AFSVolSync *Sync;
3125 struct rx_connection *tcon; /* Rx connection handle */
3126 struct AFSFid *Fid; /* Fid of file to lock */
3127 ViceLockType type; /* Type of lock (Read or write) */
3130 return SRXAFS_SetLock(tcon, Fid, type, Sync);
3132 } /*SRXAFS_OldSetLock*/
3135 SRXAFS_SetLock (tcon, Fid, type, Sync)
3136 struct AFSVolSync *Sync;
3137 struct rx_connection *tcon; /* Rx connection handle */
3138 struct AFSFid *Fid; /* Fid of file to lock */
3139 ViceLockType type; /* Type of lock (Read or write) */
3143 struct rx_call *tcall = (struct rx_call *) tcon;
3144 #if FS_STATS_DETAILED
3145 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3146 struct timeval opStartTime,
3147 opStopTime; /* Start/stop times for RPC op*/
3148 struct timeval elapsedTime; /* Transfer time */
3151 * Set our stats pointer, remember when the RPC operation started, and
3152 * tally the operation.
3154 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
3158 TM_GetTimeOfDay(&opStartTime, 0);
3159 #endif /* FS_STATS_DETAILED */
3161 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3164 code = SAFSS_SetLock (tcon, Fid, type, Sync);
3167 CallPostamble(tcon);
3169 #if FS_STATS_DETAILED
3170 TM_GetTimeOfDay(&opStopTime, 0);
3173 (opP->numSuccesses)++;
3174 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3175 fs_stats_AddTo((opP->sumTime), elapsedTime);
3176 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3177 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3178 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3180 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3181 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3185 #endif /* FS_STATS_DETAILED */
3187 osi_auditU (tcall, SetLockEvent, code, AUD_FID, Fid, AUD_LONG, type, AUD_END);
3190 } /*SRXAFS_SetLock*/
3194 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
3195 * merged into it when possible.
3197 SAFSS_ExtendLock (tcon, Fid, Sync)
3198 struct rx_connection *tcon; /* Rx connection handle */
3199 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3200 struct AFSVolSync *Sync;
3203 Vnode * targetptr = 0; /* vnode of input file */
3204 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3205 int errorCode = 0; /* error code */
3206 Volume * volptr = 0; /* pointer to the volume header */
3207 struct client * client; /* pointer to client structure */
3208 afs_int32 rights, anyrights; /* rights for this and any user */
3209 struct client *t_client; /* tmp ptr to client data */
3210 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3212 /* Get ptr to client data for user Id for logging */
3213 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3214 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3215 ViceLog(1,("SAFS_ExtendLock Fid = %u.%d.%d, Host %s, Id %d\n",
3216 Fid->Volume, Fid->Vnode, Fid->Unique,
3217 inet_ntoa(logHostAddr), t_client->ViceId));
3219 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
3222 * Get the vnode and volume for the desired file along with the caller's
3225 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3226 DONTCHECK, &parentwhentargetnotdir,
3227 &client, WRITE_LOCK, &rights, &anyrights)) {
3228 goto Bad_ExtendLock;
3231 /* set volume synchronization information */
3232 SetVolumeSync(Sync, volptr);
3234 /* Handle the actual lock extension */
3235 errorCode = HandleLocking(targetptr, rights, LockExtend);
3238 /* Put back file's vnode and volume */
3239 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3241 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3242 errorCode = 0; /* under our generous policy re RO vols */
3244 ViceLog(2,("SAFS_ExtendLock returns %d\n", errorCode));
3247 } /*SAFSS_ExtendLock*/
3250 SRXAFS_OldExtendLock (tcon, Fid, Sync)
3251 struct AFSVolSync *Sync;
3252 struct rx_connection *tcon; /* Rx connection handle */
3253 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3256 return SRXAFS_ExtendLock(tcon, Fid, Sync);
3258 } /*SRXAFS_OldExtendLock*/
3261 SRXAFS_ExtendLock (tcon, Fid, Sync)
3262 struct AFSVolSync *Sync;
3263 struct rx_connection *tcon; /* Rx connection handle */
3264 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3268 struct rx_call *tcall = (struct rx_call *) tcon;
3269 #if FS_STATS_DETAILED
3270 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3271 struct timeval opStartTime,
3272 opStopTime; /* Start/stop times for RPC op*/
3273 struct timeval elapsedTime; /* Transfer time */
3276 * Set our stats pointer, remember when the RPC operation started, and
3277 * tally the operation.
3279 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
3283 TM_GetTimeOfDay(&opStartTime, 0);
3284 #endif /* FS_STATS_DETAILED */
3286 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3287 goto Bad_ExtendLock;
3289 code = SAFSS_ExtendLock (tcon, Fid, Sync);
3292 CallPostamble(tcon);
3294 #if FS_STATS_DETAILED
3295 TM_GetTimeOfDay(&opStopTime, 0);
3298 (opP->numSuccesses)++;
3299 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3300 fs_stats_AddTo((opP->sumTime), elapsedTime);
3301 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3302 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3303 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3305 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3306 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3311 #endif /* FS_STATS_DETAILED */
3313 osi_auditU (tcall, ExtendLockEvent, code, AUD_FID, Fid , AUD_END);
3316 } /*SRXAFS_ExtendLock*/
3320 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
3321 * merged into it when possible.
3323 SAFSS_ReleaseLock (tcon, Fid, Sync)
3324 struct rx_connection *tcon; /* Rx connection handle */
3325 struct AFSFid *Fid; /* Fid of file to release lock */
3326 struct AFSVolSync *Sync;
3329 Vnode * targetptr = 0; /* vnode of input file */
3330 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3331 int errorCode = 0; /* error code */
3332 Volume * volptr = 0; /* pointer to the volume header */
3333 struct client * client; /* pointer to client structure */
3334 afs_int32 rights, anyrights; /* rights for this and any user */
3335 struct client *t_client; /* tmp ptr to client data */
3336 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3338 /* Get ptr to client data for user Id for logging */
3339 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3340 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3341 ViceLog(1,("SAFS_ReleaseLock Fid = %u.%d.%d, Host %s, Id %d\n",
3342 Fid->Volume, Fid->Vnode, Fid->Unique,
3343 inet_ntoa(logHostAddr), t_client->ViceId));
3345 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
3348 * Get the vnode and volume for the desired file along with the caller's
3351 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3352 DONTCHECK, &parentwhentargetnotdir,
3353 &client, WRITE_LOCK, &rights, &anyrights)) {
3354 goto Bad_ReleaseLock;
3357 /* set volume synchronization information */
3358 SetVolumeSync(Sync, volptr);
3360 /* Handle the actual lock release */
3361 if (errorCode = HandleLocking(targetptr, rights, LockRelease))
3362 goto Bad_ReleaseLock;
3364 /* if no more locks left, a callback would be triggered here */
3365 if (targetptr->disk.lock.lockCount <= 0) {
3366 /* convert the write lock to a read lock before breaking callbacks */
3367 VVnodeWriteToRead(&errorCode, targetptr);
3368 assert(!errorCode || errorCode == VSALVAGE);
3369 BreakCallBack(client->host, Fid, 0);
3373 /* Put back file's vnode and volume */
3374 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3376 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3377 errorCode = 0; /* under our generous policy re RO vols */
3379 ViceLog(2,("SAFS_ReleaseLock returns %d\n", errorCode));
3382 } /*SAFSS_ReleaseLock*/
3385 SRXAFS_OldReleaseLock (tcon, Fid, Sync)
3386 struct AFSVolSync *Sync;
3387 struct rx_connection *tcon; /* Rx connection handle */
3388 struct AFSFid *Fid; /* Fid of file to release lock */
3391 return SRXAFS_ReleaseLock(tcon, Fid, Sync);
3393 } /*SRXAFS_OldReleaseLock*/
3396 SRXAFS_ReleaseLock (tcon, Fid, Sync)
3397 struct AFSVolSync *Sync;
3398 struct rx_connection *tcon; /* Rx connection handle */
3399 struct AFSFid *Fid; /* Fid of file to release lock */
3403 struct rx_call *tcall = (struct rx_call *) tcon;
3404 #if FS_STATS_DETAILED
3405 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3406 struct timeval opStartTime,
3407 opStopTime; /* Start/stop times for RPC op*/
3408 struct timeval elapsedTime; /* Transfer time */
3411 * Set our stats pointer, remember when the RPC operation started, and
3412 * tally the operation.
3414 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
3418 TM_GetTimeOfDay(&opStartTime, 0);
3419 #endif /* FS_STATS_DETAILED */
3421 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3422 goto Bad_ReleaseLock;
3424 code = SAFSS_ReleaseLock (tcon, Fid, Sync);
3427 CallPostamble(tcon);
3429 #if FS_STATS_DETAILED
3430 TM_GetTimeOfDay(&opStopTime, 0);
3433 (opP->numSuccesses)++;
3434 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3435 fs_stats_AddTo((opP->sumTime), elapsedTime);
3436 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3437 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3438 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3440 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3441 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3446 #endif /* FS_STATS_DETAILED */
3448 osi_auditU (tcall, ReleaseLockEvent, code, AUD_FID, Fid , AUD_END);
3451 } /*SRXAFS_ReleaseLock*/
3455 * This routine is called exclusively by SRXAFS_GetStatistics(), and should be
3456 * merged into it when possible.
3458 static GetStatistics (tcon, Statistics)
3459 struct rx_connection *tcon; /* Rx connection handle */
3460 struct AFSStatistics *Statistics; /* Placeholder for returned AFS statistics */
3462 ViceLog(1, ("SAFS_GetStatistics Received\n"));
3464 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
3466 bzero(Statistics, sizeof(*Statistics));
3467 SetAFSStats(Statistics);
3468 SetVolumeStats(Statistics);
3469 SetSystemStats(Statistics);
3476 SRXAFS_GetStatistics (tcon, Statistics)
3477 struct rx_connection *tcon; /* Rx connection handle */
3478 struct AFSStatistics *Statistics; /* Placeholder for returned AFS statistics */
3482 #if FS_STATS_DETAILED
3483 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3484 struct timeval opStartTime,
3485 opStopTime; /* Start/stop times for RPC op*/
3486 struct timeval elapsedTime; /* Transfer time */
3489 * Set our stats pointer, remember when the RPC operation started, and
3490 * tally the operation.
3492 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
3496 TM_GetTimeOfDay(&opStartTime, 0);
3497 #endif /* FS_STATS_DETAILED */
3499 if (code = CallPreamble((struct rx_call **) &tcon, NOTACTIVECALL))
3500 goto Bad_GetStatistics;
3502 code = GetStatistics (tcon, Statistics);
3505 CallPostamble(tcon);
3507 #if FS_STATS_DETAILED
3508 TM_GetTimeOfDay(&opStopTime, 0);
3511 (opP->numSuccesses)++;
3512 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3513 fs_stats_AddTo((opP->sumTime), elapsedTime);
3514 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3515 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3516 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3518 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3519 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3523 #endif /* FS_STATS_DETAILED */
3527 } /*SRXAFS_GetStatistics*/
3530 /*------------------------------------------------------------------------
3531 * EXPORTED SRXAFS_XStatsVersion
3534 * Routine called by the server-side RPC interface to implement
3535 * pulling out the xstat version number for the File Server.
3538 * a_versionP : Ptr to the version number variable to set.
3544 * Nothing interesting.
3548 *------------------------------------------------------------------------*/
3550 int SRXAFS_XStatsVersion(a_call, a_versionP)
3551 struct rx_call *a_call;
3552 afs_int32 *a_versionP;
3554 { /*SRXAFS_XStatsVersion*/
3556 #if FS_STATS_DETAILED
3557 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3558 struct timeval opStartTime,
3559 opStopTime; /* Start/stop times for RPC op*/
3560 struct timeval elapsedTime; /* Transfer time */
3563 * Set our stats pointer, remember when the RPC operation started, and
3564 * tally the operation.
3566 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
3570 TM_GetTimeOfDay(&opStartTime, 0);
3571 #endif /* FS_STATS_DETAILED */
3573 *a_versionP = AFS_XSTAT_VERSION;
3575 #if FS_STATS_DETAILED
3576 TM_GetTimeOfDay(&opStopTime, 0);
3577 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3578 fs_stats_AddTo((opP->sumTime), elapsedTime);
3579 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3580 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3581 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3583 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3584 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3587 (opP->numSuccesses)++;
3589 #endif /* FS_STATS_DETAILED */
3593 } /*SRXAFS_XStatsVersion*/
3596 /*------------------------------------------------------------------------
3597 * PRIVATE FillPerfValues
3600 * Routine called to fill a regular performance data structure.
3603 * a_perfP : Ptr to perf structure to fill
3609 * Various collections need this info, so the guts were put in
3610 * this separate routine.
3614 *------------------------------------------------------------------------*/
3616 static void FillPerfValues(a_perfP)
3617 struct afs_PerfStats *a_perfP;
3619 { /*FillPerfValues*/
3621 int dir_Buffers; /*# buffers in use by dir package*/
3622 int dir_Calls; /*# read calls in dir package*/
3623 int dir_IOs; /*# I/O ops in dir package*/
3626 * Vnode cache section.
3628 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
3629 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
3630 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
3631 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
3632 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
3633 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
3634 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
3635 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
3636 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
3637 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
3638 a_perfP->vcache_H_Entries = VolumeCacheSize;
3639 a_perfP->vcache_H_Gets = VolumeGets;
3640 a_perfP->vcache_H_Replacements = VolumeReplacements;
3643 * Directory section.
3645 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
3646 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
3647 a_perfP->dir_Calls = (afs_int32 )dir_Calls;
3648 a_perfP->dir_IOs = (afs_int32) dir_IOs;
3653 a_perfP->rx_packetRequests =
3654 (afs_int32) rx_stats.packetRequests;
3655 a_perfP->rx_noPackets_RcvClass =
3656 (afs_int32) rx_stats.receivePktAllocFailures;
3657 a_perfP->rx_noPackets_SendClass =
3658 (afs_int32) rx_stats.sendPktAllocFailures;
3659 a_perfP->rx_noPackets_SpecialClass =
3660 (afs_int32) rx_stats.specialPktAllocFailures;
3661 a_perfP->rx_socketGreedy =
3662 (afs_int32) rx_stats.socketGreedy;
3663 a_perfP->rx_bogusPacketOnRead =
3664 (afs_int32) rx_stats.bogusPacketOnRead;
3665 a_perfP->rx_bogusHost =
3666 (afs_int32) rx_stats.bogusHost;
3667 a_perfP->rx_noPacketOnRead =
3668 (afs_int32) rx_stats.noPacketOnRead;
3669 a_perfP->rx_noPacketBuffersOnRead =
3670 (afs_int32) rx_stats.noPacketBuffersOnRead;
3671 a_perfP->rx_selects =
3672 (afs_int32) rx_stats.selects;
3673 a_perfP->rx_sendSelects =
3674 (afs_int32) rx_stats.sendSelects;
3675 a_perfP->rx_packetsRead_RcvClass =
3676 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
3677 a_perfP->rx_packetsRead_SendClass =
3678 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
3679 a_perfP->rx_packetsRead_SpecialClass =
3680 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
3681 a_perfP->rx_dataPacketsRead =
3682 (afs_int32) rx_stats.dataPacketsRead;
3683 a_perfP->rx_ackPacketsRead =
3684 (afs_int32) rx_stats.ackPacketsRead;
3685 a_perfP->rx_dupPacketsRead =
3686 (afs_int32) rx_stats.dupPacketsRead;
3687 a_perfP->rx_spuriousPacketsRead =
3688 (afs_int32) rx_stats.spuriousPacketsRead;
3689 a_perfP->rx_packetsSent_RcvClass =
3690 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
3691 a_perfP->rx_packetsSent_SendClass =
3692 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
3693 a_perfP->rx_packetsSent_SpecialClass =
3694 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
3695 a_perfP->rx_ackPacketsSent =
3696 (afs_int32) rx_stats.ackPacketsSent;
3697 a_perfP->rx_pingPacketsSent =
3698 (afs_int32) rx_stats.pingPacketsSent;
3699 a_perfP->rx_abortPacketsSent =
3700 (afs_int32) rx_stats.abortPacketsSent;
3701 a_perfP->rx_busyPacketsSent =
3702 (afs_int32) rx_stats.busyPacketsSent;
3703 a_perfP->rx_dataPacketsSent =
3704 (afs_int32) rx_stats.dataPacketsSent;
3705 a_perfP->rx_dataPacketsReSent =
3706 (afs_int32) rx_stats.dataPacketsReSent;
3707 a_perfP->rx_dataPacketsPushed =
3708 (afs_int32) rx_stats.dataPacketsPushed;
3709 a_perfP->rx_ignoreAckedPacket =
3710 (afs_int32) rx_stats.ignoreAckedPacket;
3711 a_perfP->rx_totalRtt_Sec =
3712 (afs_int32) rx_stats.totalRtt.sec;
3713 a_perfP->rx_totalRtt_Usec =
3714 (afs_int32) rx_stats.totalRtt.usec;
3715 a_perfP->rx_minRtt_Sec =
3716 (afs_int32) rx_stats.minRtt.sec;
3717 a_perfP->rx_minRtt_Usec =
3718 (afs_int32) rx_stats.minRtt.usec;
3719 a_perfP->rx_maxRtt_Sec =
3720 (afs_int32) rx_stats.maxRtt.sec;
3721 a_perfP->rx_maxRtt_Usec =
3722 (afs_int32) rx_stats.maxRtt.usec;
3723 a_perfP->rx_nRttSamples =
3724 (afs_int32) rx_stats.nRttSamples;
3725 a_perfP->rx_nServerConns =
3726 (afs_int32) rx_stats.nServerConns;
3727 a_perfP->rx_nClientConns =
3728 (afs_int32) rx_stats.nClientConns;
3729 a_perfP->rx_nPeerStructs =
3730 (afs_int32) rx_stats.nPeerStructs;
3731 a_perfP->rx_nCallStructs =
3732 (afs_int32) rx_stats.nCallStructs;
3733 a_perfP->rx_nFreeCallStructs =
3734 (afs_int32) rx_stats.nFreeCallStructs;
3736 a_perfP->host_NumHostEntries = HTs;
3737 a_perfP->host_HostBlocks = HTBlocks;
3738 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
3739 &(a_perfP->host_HostsInSameNetOrSubnet),
3740 &(a_perfP->host_HostsInDiffSubnet),
3741 &(a_perfP->host_HostsInDiffNetwork));
3742 a_perfP->host_NumClients = CEs;
3743 a_perfP->host_ClientBlocks = CEBlocks;
3745 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
3747 } /*FillPerfValues*/
3750 /*------------------------------------------------------------------------
3751 * EXPORTED SRXAFS_GetXStats
3754 * Routine called by the server-side callback RPC interface to
3755 * implement getting the given data collection from the extended
3756 * File Server statistics.
3759 * a_call : Ptr to Rx call on which this request came in.
3760 * a_clientVersionNum : Client version number.
3761 * a_opCode : Desired operation.
3762 * a_serverVersionNumP : Ptr to version number to set.
3763 * a_timeP : Ptr to time value (seconds) to set.
3764 * a_dataP : Ptr to variable array structure to return
3771 * Nothing interesting.
3775 *------------------------------------------------------------------------*/
3777 int SRXAFS_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVersionNumP, a_timeP, a_dataP)
3778 struct rx_call *a_call;
3779 afs_int32 a_clientVersionNum;
3780 afs_int32 a_collectionNumber;
3781 afs_int32 *a_srvVersionNumP;
3783 AFS_CollData *a_dataP;
3785 { /*SRXAFS_GetXStats*/
3787 register int code; /*Return value*/
3788 afs_int32 *dataBuffP; /*Ptr to data to be returned*/
3789 afs_int32 dataBytes; /*Bytes in data buffer*/
3790 #if FS_STATS_DETAILED
3791 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3792 struct timeval opStartTime,
3793 opStopTime; /* Start/stop times for RPC op*/
3794 struct timeval elapsedTime; /* Transfer time */
3797 * Set our stats pointer, remember when the RPC operation started, and
3798 * tally the operation.
3800 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
3804 TM_GetTimeOfDay(&opStartTime, 0);
3805 #endif /* FS_STATS_DETAILED */
3808 * Record the time of day and the server version number.
3810 *a_srvVersionNumP = AFS_XSTAT_VERSION;
3811 *a_timeP = FT_ApproxTime();
3814 * Stuff the appropriate data in there (assume victory)
3818 ViceLog(1, ("Received GetXStats call for collection %d\n", a_collectionNumber));
3822 * We're not keeping stats, so just return successfully with
3825 a_dataP->AFS_CollData_len = 0;
3826 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3829 switch(a_collectionNumber) {
3830 case AFS_XSTATSCOLL_CALL_INFO:
3832 * Pass back all the call-count-related data.
3834 * >>> We are forced to allocate a separate area in which to
3835 * >>> put this stuff in by the RPC stub generator, since it
3836 * >>> will be freed at the tail end of the server stub code.
3840 * I don't think call-level stats are being collected yet
3841 * for the File Server.
3843 dataBytes = sizeof(struct afs_Stats);
3844 dataBuffP = (afs_int32 *)malloc(dataBytes);
3845 bcopy(&afs_cmstats, dataBuffP, dataBytes);
3846 a_dataP->AFS_CollData_len = dataBytes>>2;
3847 a_dataP->AFS_CollData_val = dataBuffP;
3849 a_dataP->AFS_CollData_len = 0;
3850 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3854 case AFS_XSTATSCOLL_PERF_INFO:
3856 * Pass back all the regular performance-related data.
3858 * >>> We are forced to allocate a separate area in which to
3859 * >>> put this stuff in by the RPC stub generator, since it
3860 * >>> will be freed at the tail end of the server stub code.
3863 afs_perfstats.numPerfCalls++;
3864 FillPerfValues(&afs_perfstats);
3867 * Don't overwrite the spares at the end.
3870 dataBytes = sizeof(struct afs_PerfStats);
3871 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
3872 bcopy(&afs_perfstats, dataBuffP, dataBytes);
3873 a_dataP->AFS_CollData_len = dataBytes>>2;
3874 a_dataP->AFS_CollData_val = dataBuffP;
3877 case AFS_XSTATSCOLL_FULL_PERF_INFO:
3879 * Pass back the full collection of performance-related data.
3880 * We have to stuff the basic, overall numbers in, but the
3881 * detailed numbers are kept in the structure already.
3883 * >>> We are forced to allocate a separate area in which to
3884 * >>> put this stuff in by the RPC stub generator, since it
3885 * >>> will be freed at the tail end of the server stub code.
3888 afs_perfstats.numPerfCalls++;
3889 #if FS_STATS_DETAILED
3890 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
3891 FillPerfValues(&afs_FullPerfStats.overall);
3894 * Don't overwrite the spares at the end.
3897 dataBytes = sizeof(struct fs_stats_FullPerfStats);
3898 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
3899 bcopy(&afs_FullPerfStats, dataBuffP, dataBytes);
3900 a_dataP->AFS_CollData_len = dataBytes>>2;
3901 a_dataP->AFS_CollData_val = dataBuffP;
3907 * Illegal collection number.
3909 a_dataP->AFS_CollData_len = 0;
3910 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3912 } /*Switch on collection number*/
3914 #if FS_STATS_DETAILED
3915 TM_GetTimeOfDay(&opStopTime, 0);
3918 (opP->numSuccesses)++;
3919 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3920 fs_stats_AddTo((opP->sumTime), elapsedTime);
3921 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3922 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3923 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3925 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3926 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3931 #endif /* FS_STATS_DETAILED */
3935 } /*SRXAFS_GetXStats*/
3938 SRXAFS_GiveUpCallBacks (tcon, FidArray, CallBackArray)
3939 struct rx_connection *tcon; /* Rx connection handle */
3940 struct AFSCBFids *FidArray; /* Array of Fids entries */
3941 struct AFSCBs *CallBackArray; /* array of callbacks */
3944 afs_int32 errorCode;
3946 struct client *client;
3947 #if FS_STATS_DETAILED
3948 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3949 struct timeval opStartTime,
3950 opStopTime; /* Start/stop times for RPC op*/
3951 struct timeval elapsedTime; /* Transfer time */
3954 * Set our stats pointer, remember when the RPC operation started, and
3955 * tally the operation.
3957 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
3961 TM_GetTimeOfDay(&opStartTime, 0);
3962 #endif /* FS_STATS_DETAILED */
3964 ViceLog(1, ("SAFS_GiveUpCallBacks (Noffids=%d)\n", FidArray->AFSCBFids_len));
3966 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
3968 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3969 goto Bad_GiveUpCallBacks;
3971 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
3972 ViceLog(0, ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
3973 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
3974 (tcon->peer ? tcon->peer->host : 0)));
3976 goto Bad_GiveUpCallBacks;
3979 errorCode = GetClient(tcon, &client);
3981 for (i=0; i < FidArray->AFSCBFids_len; i++) {
3982 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
3983 DeleteCallBack(client->host, fid);
3987 Bad_GiveUpCallBacks:
3988 CallPostamble(tcon);
3990 #if FS_STATS_DETAILED
3991 TM_GetTimeOfDay(&opStopTime, 0);
3992 if (errorCode == 0) {
3994 (opP->numSuccesses)++;
3995 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3996 fs_stats_AddTo((opP->sumTime), elapsedTime);
3997 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3998 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3999 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4001 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4002 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4006 #endif /* FS_STATS_DETAILED */
4010 } /*SRXAFS_GiveUpCallBacks*/
4013 SRXAFS_NGetVolumeInfo (tcon, avolid, avolinfo)
4014 struct rx_connection *tcon; /* Rx connection handle */
4015 char *avolid; /* Volume name/id */
4016 struct AFSVolumeInfo *avolinfo; /* Returned volume's specific info */
4019 return(VNOVOL); /* XXX Obsolete routine XXX */
4021 } /*SRXAFS_NGetVolumeInfo*/
4025 * Dummy routine. Should never be called (the cache manager should only
4026 * invoke this interface when communicating with a AFS/DFS Protocol
4029 SRXAFS_Lookup(call_p, afs_dfid_p, afs_name_p, afs_fid_p,
4030 afs_status_p, afs_dir_status_p, afs_callback_p, afs_sync_p)
4031 struct rx_call *call_p; /* Rx call handle */
4032 struct AFSFid *afs_dfid_p; /* Directory */
4033 char *afs_name_p; /* Name of file to lookup */
4034 struct AFSFid *afs_fid_p; /* Place to return fid of file */
4035 struct AFSFetchStatus *afs_status_p; /* Place to return file status */
4036 struct AFSFetchStatus *afs_dir_status_p;/* Place to return file status */
4037 struct AFSCallBack *afs_callback_p; /* If r/w, callback promise for Fid */
4038 struct AFSVolSync *afs_sync_p; /* Volume sync info */
4044 SRXAFS_FlushCPS(tcon, vids, addrs, spare1, spare2, spare3)
4045 struct rx_connection *tcon;
4046 struct ViceIds *vids;
4047 struct IPAddrs *addrs;
4048 afs_int32 spare1, *spare2, *spare3;
4051 afs_int32 nids, naddrs;
4052 afs_int32 *vd, *addr;
4053 int errorCode = 0; /* return code to caller */
4054 struct client *client;
4055 struct rx_call *tcall = (struct rx_call *) tcon;
4057 ViceLog(1, ("SRXAFS_FlushCPS\n"));
4059 AFSCallStats.TotalCalls++;
4061 nids = vids->ViceIds_len; /* # of users in here */
4062 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
4063 if (nids < 0 || naddrs < 0) {
4068 vd = vids->ViceIds_val;
4069 for (i=0; i<nids; i++, vd++) {
4072 client = h_ID2Client(*vd); /* returns client locked, or NULL */
4076 BoostSharedLock(&client->lock);
4077 client->prfail = 2; /* Means re-eval client's cps */
4080 rx_SetRock(((struct rx_connection *) client->tcon), 0);
4083 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
4084 free(client->CPS.prlist_val);
4085 client->CPS.prlist_val = (afs_int32 *)0;
4087 ReleaseWriteLock(&client->lock);
4090 addr = addrs->IPAddrs_val;
4091 for (i=0; i<naddrs; i++, addr++) {
4093 h_flushhostcps(*addr, 7001);
4097 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
4099 } /*SRXAFS_FlushCPS */
4103 static GetVolumeInfo (tcon, avolid, avolinfo)
4104 struct rx_connection *tcon; /* Rx Connection handle */
4105 char *avolid; /* Volume name/id */
4106 struct VolumeInfo *avolinfo; /* Returned volume's specific info */
4109 int errorCode = 0; /* error code */
4112 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
4115 errorCode = TryLocalVLServer(avolid, avolinfo);
4116 ViceLog(1, ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
4117 errorCode, avolinfo->Vid, avolinfo->Type,
4118 avolinfo->Server0, avolinfo->Server1, avolinfo->Server2,
4119 avolinfo->Server3));
4124 /* worthless hack to let CS keep running ancient software */
4125 static afs_vtoi(aname)
4126 register char *aname;
4129 register afs_int32 temp;
4133 while(tc = *aname++) {
4134 if (tc > '9' || tc < '0') return 0; /* invalid name */
4142 * may get name or #, but must handle all weird cases (recognize readonly
4143 * or backup volumes by name or #
4145 static CopyVolumeEntry(aname, ave, av)
4147 register struct VolumeInfo *av;
4148 register struct vldbentry *ave;
4151 register int i, j, vol;
4152 afs_int32 mask, whichType;
4153 afs_uint32 *serverHost, *typePtr;
4155 /* figure out what type we want if by name */
4157 if (i >= 8 && strcmp(aname+i-7, ".backup") == 0)
4158 whichType = BACKVOL;
4159 else if (i >= 10 && strcmp(aname+i-9, ".readonly")==0)
4161 else whichType = RWVOL;