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>
33 #undef SHARED /* XXX */
38 #include <sys/param.h>
40 #include <netinet/in.h>
42 #include <sys/ioctl.h>
43 #include <sys/socket.h>
44 #ifndef AFS_LINUX20_ENV
46 #include <netinet/if_ether.h>
53 /* included early because of name conflict on IOPEN */
54 #include <sys/inode.h>
58 #endif /* AFS_HPUX_ENV */
62 #include <afs/assert.h>
65 #include <afs/afsint.h>
66 #include <afs/vldbint.h>
67 #include <afs/errors.h>
68 #include <afs/ihandle.h>
69 #include <afs/vnode.h>
70 #include <afs/volume.h>
72 #include <afs/ptclient.h>
73 #include <afs/prs_fs.h>
75 #include <rx/rx_globals.h>
77 #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)
80 #if !defined(AFS_NT40_ENV)
83 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
85 #include <sys/statfs.h>
86 #include <sys/lockf.h>
88 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
93 #include <afs/cellconfig.h>
98 #include <afs/partition.h>
101 #include <afs/audit.h>
102 #include <afs/afsutil.h>
104 #ifdef AFS_PTHREAD_ENV
105 pthread_mutex_t fileproc_glock_mutex;
106 #endif /* AFS_PTHREAD_ENV */
109 /* Useful local defines used by this module */
112 #define MustNOTBeDIR 1
116 #define TVS_SSTATUS 2
119 #define TVS_MKDIR 0x10
121 #define CHK_FETCH 0x10
122 #define CHK_FETCHDATA 0x10
123 #define CHK_FETCHACL 0x11
124 #define CHK_FETCHSTATUS 0x12
125 #define CHK_STOREDATA 0x00
126 #define CHK_STOREACL 0x01
127 #define CHK_STORESTATUS 0x02
129 #define OWNERREAD 0400
130 #define OWNERWRITE 0200
131 #define OWNEREXEC 0100
132 #ifdef USE_GROUP_PERMS
133 #define GROUPREAD 0040
134 #define GROUPWRITE 0020
135 #define GROUPREXEC 0010
138 /* The following errors were not defined in NT. They are given unique
139 * names here to avoid any potential collision.
141 #define FSERR_ELOOP 90
142 #define FSERR_EOPNOTSUPP 122
143 #define FSERR_ECONNREFUSED 130
145 #define NOTACTIVECALL 0
148 extern struct afsconf_dir *confDir;
149 extern afs_int32 dataVersionHigh;
152 extern struct AFSCallStatistics AFSCallStats;
153 struct AFSCallStatistics AFSCallStats;
154 #if FS_STATS_DETAILED
155 struct fs_stats_FullPerfStats afs_FullPerfStats;
156 extern int AnonymousID;
157 #endif /* FS_STATS_DETAILED */
158 #if TRANSARC_VOL_STATS
159 static const char nullString[] = "";
160 #endif /* TRANSARC_VOL_STATS */
163 afs_int32 NothingYet;
166 struct afs_FSStats afs_fsstats;
168 void ResetDebug(), SetDebug(), GetStatus(), Terminate();
169 int CopyOnWrite(); /* returns 0 on success */
172 void SetSystemStats(), SetAFSStats(), SetVolumeStats();
176 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
178 extern afs_int32 implicitAdminRights;
180 static TryLocalVLServer();
183 * Externals used by the xstat code.
185 extern int VolumeCacheSize, VolumeGets, VolumeReplacements;
186 extern int CEs, CEBlocks;
188 extern int HTs, HTBlocks;
190 #ifdef AFS_SGI_XFS_IOPS_ENV
191 #include <afs/xfsattrs.h>
192 static int GetLinkCount(avp, astat)
196 if (!strcmp("xfs", astat->st_fstype)) {
197 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
200 return astat->st_nlink;
203 #define GetLinkCount(V, S) (S)->st_nlink
206 afs_int32 SpareComp(avolp)
210 register afs_int32 temp;
214 temp = V_maxquota(avolp);
216 /* no matter; doesn't check in this case */
220 temp = (temp * PctSpare) / 100;
233 * Set the volume synchronization parameter for this volume. If it changes,
234 * the Cache Manager knows that the volume must be purged from the stat cache.
236 static SetVolumeSync(async, avol)
237 register struct AFSVolSync *async;
238 register Volume *avol;
242 /* date volume instance was created */
245 async->spare1 = avol->header->diskstuff.creationDate;
258 * This call overwrites the pointed-to rx_call with an rx_connection. This
259 * is really bogus. Note that this function always returns a held host, so
260 * that CallPostamble can block without the host's disappearing.
262 static CallPreamble(acall, activecall)
263 register struct rx_call **acall;
268 struct rx_connection *tconn;
269 struct client *tclient;
272 tconn = rx_ConnectionOf(*acall);
273 *acall = (struct rx_call *)tconn; /* change it! */
277 tclient = h_FindClient_r(tconn);
278 if (tclient->prfail == 1) { /* couldn't get the CPS */
280 h_ReleaseClient_r(tclient);
281 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
285 retry_flag=0; /* Retry once */
287 /* Take down the old connection and re-read the key file */
288 ViceLog(0, ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
290 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
293 h_ReleaseClient_r(tclient);
295 ViceLog(0,("CallPreamble: couldn't reconnect to ptserver\n"));
299 tclient->prfail = 2; /* Means re-eval client's cps */
300 h_ReleaseClient_r(tclient);
304 thost = tclient->host;
305 tclient->LastCall = thost->LastCall = FT_ApproxTime();
306 if (activecall) /* For all but "GetTime" calls */
307 thost->ActiveCall = thost->LastCall;
310 if (thost->hostFlags & HOSTDELETED) {
311 ViceLog(3,("Discarded a packet for deleted host %08x\n",thost->host));
312 code = VBUSY; /* raced, so retry */
314 else if (thost->hostFlags & VENUSDOWN) {
315 if (BreakDelayedCallBacks_r(thost)) {
316 ViceLog(0,("BreakDelayedCallbacks FAILED for host %08x which IS UP. Possible network or routing failure.\n",thost->host));
317 if ( MultiProbeAlternateAddress_r (thost) ) {
318 ViceLog(0, ("MultiProbe failed to find new address for host %x.%d\n",
319 thost->host, thost->port));
322 ViceLog(0, ("MultiProbe found new address for host %x.%d\n",
323 thost->host, thost->port));
324 if (BreakDelayedCallBacks_r(thost)) {
325 ViceLog(0,("BreakDelayedCallbacks FAILED AGAIN for host %08x which IS UP. Possible network or routing failure.\n",thost->host));
334 h_ReleaseClient_r(tclient);
342 static CallPostamble(aconn)
343 register struct rx_connection *aconn;
347 struct client *tclient;
350 tclient = h_FindClient_r(aconn);
351 thost = tclient->host;
352 h_ReleaseClient_r(tclient);
359 #define AFSV_BUFFERSIZE 16384
361 static struct afs_buffer {
362 struct afs_buffer *next;
363 } *freeBufferList = 0;
364 static int afs_buffersAlloced = 0;
367 static FreeSendBuffer(adata)
368 register struct afs_buffer *adata;
372 afs_buffersAlloced--;
373 adata->next = freeBufferList;
374 freeBufferList = adata;
381 /* allocate space for sender */
382 static char *AllocSendBuffer()
385 register struct afs_buffer *tp;
388 afs_buffersAlloced++;
389 if (!freeBufferList) {
391 return malloc(AFSV_BUFFERSIZE);
394 freeBufferList = tp->next;
398 } /*AllocSendBuffer*/
401 static int VolumeOwner (client, targetptr)
402 register struct client *client;
403 register Vnode *targetptr;
406 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
409 return (client->ViceId == owner);
412 * We don't have to check for host's cps since only regular
413 * viceid are volume owners.
415 return (acl_IsAMember(owner, &client->CPS));
421 static int VolumeRootVnode (targetptr)
425 return ((targetptr->vnodeNumber == ROOTVNODE) &&
426 (targetptr->disk.uniquifier == 1));
428 } /*VolumeRootVnode*/
431 SRXAFS_FetchData (tcon, Fid, Pos, Len, OutStatus, CallBack, Sync)
432 struct rx_connection *tcon; /* Rx connection handle */
433 struct AFSFid *Fid; /* Fid of file to fetch */
434 afs_int32 Pos, Len; /* Not implemented yet */
435 struct AFSFetchStatus *OutStatus; /* Returned status for Fid */
436 struct AFSCallBack *CallBack; /* If r/w return CB for Fid */
437 struct AFSVolSync *Sync; /* synchronization info */
440 Vnode * targetptr = 0; /* pointer to vnode to fetch */
441 Vnode * parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
442 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
443 int errorCode = 0; /* return code to caller */
444 int fileCode = 0; /* return code from vol package */
445 Volume * volptr = 0; /* pointer to the volume */
446 struct client *client; /* pointer to the client data */
447 struct rx_call *tcall; /* the call we're a part of */
448 afs_int32 rights, anyrights; /* rights for this and any user */
449 struct client *t_client; /* tmp ptr to client data */
450 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
451 #if FS_STATS_DETAILED
452 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
453 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
454 struct timeval opStartTime,
455 opStopTime; /* Start/stop times for RPC op*/
456 struct timeval xferStartTime,
457 xferStopTime; /* Start/stop times for xfer portion*/
458 struct timeval elapsedTime; /* Transfer time */
459 afs_int32 bytesToXfer; /* # bytes to xfer*/
460 afs_int32 bytesXferred; /* # bytes actually xferred*/
461 int readIdx; /* Index of read stats array to bump*/
462 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
465 * Set our stats pointers, remember when the RPC operation started, and
466 * tally the operation.
468 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
469 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
473 TM_GetTimeOfDay(&opStartTime, 0);
474 #endif /* FS_STATS_DETAILED */
476 ViceLog(1,("SRXAFS_FetchData, Fid = %u.%d.%d\n",
477 Fid->Volume, Fid->Vnode, Fid->Unique));
479 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
482 /* CallPreamble changes tcon from a call to a conn */
483 tcall = (struct rx_call *) tcon;
484 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
487 /* Get ptr to client data for user Id for logging */
488 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
489 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
490 ViceLog(5,("SRXAFS_FetchData, Fid = %u.%d.%d, Host %s, Id %d\n",
491 Fid->Volume, Fid->Vnode, Fid->Unique,
492 inet_ntoa(logHostAddr), t_client->ViceId));
494 * Get volume/vnode for the fetched file; caller's access rights to
495 * it are also returned
497 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
498 DONTCHECK, &parentwhentargetnotdir,
499 &client, READ_LOCK, &rights, &anyrights))
502 SetVolumeSync(Sync, volptr);
504 #if FS_STATS_DETAILED
506 * Remember that another read operation was performed.
509 if (client->InSameNetwork)
510 readIdx = VOL_STATS_SAME_NET;
512 readIdx = VOL_STATS_DIFF_NET;
513 V_stat_reads(volptr, readIdx)++;
514 if (client->ViceId != AnonymousID) {
515 V_stat_reads(volptr, readIdx+1)++;
518 #endif /* FS_STATS_DETAILED */
520 /* Check whether the caller has permission access to fetch the data */
521 if (errorCode = Check_PermissionRights(targetptr, client, rights,
526 * Drop the read lock on the parent directory after saving the parent
527 * vnode information we need to pass to GetStatus
529 if (parentwhentargetnotdir != NULL) {
530 tparentwhentargetnotdir = *parentwhentargetnotdir;
531 VPutVnode(&fileCode, parentwhentargetnotdir);
532 assert(!fileCode || (fileCode == VSALVAGE));
533 parentwhentargetnotdir = NULL;
536 #if FS_STATS_DETAILED
538 * Remember when the data transfer started.
540 TM_GetTimeOfDay(&xferStartTime, 0);
541 #endif /* FS_STATS_DETAILED */
543 /* actually do the data transfer */
544 #if FS_STATS_DETAILED
545 errorCode = FetchData_RXStyle(volptr, targetptr, tcall, Pos, Len,
546 &bytesToXfer, &bytesXferred);
548 if (errorCode = FetchData_RXStyle(volptr, targetptr, tcall, Pos, Len))
550 #endif /* FS_STATS_DETAILED */
552 #if FS_STATS_DETAILED
554 * At this point, the data transfer is done, for good or ill. Remember
555 * when the transfer ended, bump the number of successes/failures, and
556 * integrate the transfer size and elapsed time into the stats. If the
557 * operation failed, we jump to the appropriate point.
559 TM_GetTimeOfDay(&xferStopTime, 0);
563 (xferP->numSuccesses)++;
566 * Bump the xfer sum by the number of bytes actually sent, NOT the
569 tot_bytesXferred += bytesXferred;
570 (xferP->sumBytes) += (tot_bytesXferred >> 10);
571 tot_bytesXferred &= 0x3FF;
572 if (bytesXferred < xferP->minBytes)
573 xferP->minBytes = bytesXferred;
574 if (bytesXferred > xferP->maxBytes)
575 xferP->maxBytes = bytesXferred;
578 * Tally the size of the object. Note: we tally the actual size,
579 * NOT the number of bytes that made it out over the wire.
581 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
584 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
587 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
590 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
593 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
596 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
599 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
602 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
607 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
608 fs_stats_AddTo((xferP->sumTime), elapsedTime);
609 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
610 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
611 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
613 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
614 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
619 * Finally, go off to tell our caller the bad news in case the
624 #endif /* FS_STATS_DETAILED */
626 /* write back the OutStatus from the target vnode */
627 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
629 /* if a r/w volume, promise a callback to the caller */
630 if (VolumeWriteable(volptr))
631 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
634 bzero(&myFid, sizeof(struct AFSFid));
635 myFid.Volume = Fid->Volume;
636 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
640 /* Update and store volume/vnode and parent vnodes back */
641 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
642 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
645 #if FS_STATS_DETAILED
646 TM_GetTimeOfDay(&opStopTime, 0);
647 if (errorCode == 0) {
649 (opP->numSuccesses)++;
650 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
651 fs_stats_AddTo((opP->sumTime), elapsedTime);
652 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
653 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
654 fs_stats_TimeAssign((opP->minTime), elapsedTime);
656 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
657 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
662 #endif /* FS_STATS_DETAILED */
664 osi_auditU (tcall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
667 } /*SRXAFS_FetchData*/
670 SRXAFS_FetchACL (tcon, Fid, AccessList, OutStatus, Sync)
671 struct AFSVolSync *Sync;
672 struct rx_connection *tcon; /* Rx connection handle */
673 struct AFSFid *Fid; /* Fid of target dir */
674 struct AFSOpaque *AccessList; /* Returned contents of dir's ACL */
675 struct AFSFetchStatus *OutStatus; /* Returned status for the dir */
678 Vnode * targetptr = 0; /* pointer to vnode to fetch */
679 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
680 int errorCode = 0; /* return error code to caller */
681 Volume * volptr = 0; /* pointer to the volume */
682 struct client *client; /* pointer to the client data */
683 afs_int32 rights, anyrights; /* rights for this and any user */
684 struct rx_call *tcall = (struct rx_call *) tcon;
685 struct client *t_client; /* tmp ptr to client data */
686 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
687 #if FS_STATS_DETAILED
688 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
689 struct timeval opStartTime,
690 opStopTime; /* Start/stop times for RPC op*/
691 struct timeval elapsedTime; /* Transfer time */
694 * Set our stats pointer, remember when the RPC operation started, and
695 * tally the operation.
697 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
701 TM_GetTimeOfDay(&opStartTime, 0);
702 #endif /* FS_STATS_DETAILED */
704 ViceLog(1, ("SAFS_FetchACL, Fid = %u.%d.%d\n",
705 Fid->Volume, Fid->Vnode, Fid->Unique));
707 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
709 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
712 /* Get ptr to client data for user Id for logging */
713 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
714 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
715 ViceLog(5, ("SAFS_FetchACL, Fid = %u.%d.%d, Host %s, Id %d\n",
716 Fid->Volume, Fid->Vnode, Fid->Unique,
717 inet_ntoa(logHostAddr), t_client->ViceId));
719 AccessList->AFSOpaque_len = 0;
720 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
723 * Get volume/vnode for the fetched file; caller's access rights to it
726 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
727 DONTCHECK, &parentwhentargetnotdir,
728 &client, READ_LOCK, &rights, &anyrights))
731 SetVolumeSync(Sync, volptr);
733 /* Check whether we have permission to fetch the ACL */
734 if (errorCode = Check_PermissionRights(targetptr, client, rights,
738 /* Get the Access List from the dir's vnode */
739 if (errorCode = RXFetch_AccessList(targetptr, parentwhentargetnotdir,
743 /* Get OutStatus back From the target Vnode */
744 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
747 /* Update and store volume/vnode and parent vnodes back */
748 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
749 ViceLog(2, ("SAFS_FetchACL returns %d (ACL=%s)\n",
750 errorCode, AccessList->AFSOpaque_val));
753 #if FS_STATS_DETAILED
754 TM_GetTimeOfDay(&opStopTime, 0);
755 if (errorCode == 0) {
757 (opP->numSuccesses)++;
758 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
759 fs_stats_AddTo((opP->sumTime), elapsedTime);
760 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
761 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
762 fs_stats_TimeAssign((opP->minTime), elapsedTime);
764 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
765 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
770 #endif /* FS_STATS_DETAILED */
772 osi_auditU (tcall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
775 } /*SRXAFS_FetchACL*/
779 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
780 * merged into it when possible.
782 SAFSS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync)
783 struct rx_connection *tcon; /* Rx connection handle */
784 struct AFSFid *Fid; /* Fid of target file */
785 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
786 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
787 struct AFSVolSync *Sync; /* volume synchronization parm */
790 Vnode * targetptr = 0; /* pointer to vnode to fetch */
791 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
792 int errorCode = 0; /* return code to caller */
793 Volume * volptr = 0; /* pointer to the volume */
794 struct client *client; /* pointer to the client data */
795 afs_int32 rights, anyrights; /* rights for this and any user */
796 struct client *t_client; /* tmp ptr to client data */
797 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
799 /* Get ptr to client data for user Id for logging */
800 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
801 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
802 ViceLog(1, ("SAFS_FetchStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
803 Fid->Volume, Fid->Vnode, Fid->Unique,
804 inet_ntoa(logHostAddr), t_client->ViceId));
806 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
809 * Get volume/vnode for the fetched file; caller's rights to it are
812 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
813 DONTCHECK, &parentwhentargetnotdir,
814 &client, READ_LOCK, &rights, &anyrights))
815 goto Bad_FetchStatus;
817 /* set volume synchronization information */
818 SetVolumeSync(Sync, volptr);
820 /* Are we allowed to fetch Fid's status? */
821 if (targetptr->disk.type != vDirectory) {
822 if (errorCode = Check_PermissionRights(targetptr, client, rights,
824 goto Bad_FetchStatus;
827 /* set OutStatus From the Fid */
828 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
830 /* If a r/w volume, also set the CallBack state */
831 if (VolumeWriteable(volptr))
832 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
835 bzero(&myFid, sizeof(struct AFSFid));
836 myFid.Volume = Fid->Volume;
837 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
841 /* Update and store volume/vnode and parent vnodes back */
842 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
843 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
846 } /*SAFSS_FetchStatus*/
849 SRXAFS_BulkStatus(tcon, Fids, OutStats, CallBacks, Sync)
850 struct rx_connection *tcon;
851 struct AFSCBFids *Fids;
852 struct AFSBulkStats *OutStats;
853 struct AFSCBs *CallBacks;
854 struct AFSVolSync *Sync;
859 Vnode * targetptr = 0; /* pointer to vnode to fetch */
860 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
861 int errorCode = 0; /* return code to caller */
862 Volume * volptr = 0; /* pointer to the volume */
863 struct client *client; /* pointer to the client data */
864 afs_int32 rights, anyrights; /* rights for this and any user */
865 register struct AFSFid *tfid; /* file id we're dealing with now */
866 struct rx_call *tcall = (struct rx_call *) tcon;
867 #if FS_STATS_DETAILED
868 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
869 struct timeval opStartTime,
870 opStopTime; /* Start/stop times for RPC op*/
871 struct timeval elapsedTime; /* Transfer time */
874 * Set our stats pointer, remember when the RPC operation started, and
875 * tally the operation.
877 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
881 TM_GetTimeOfDay(&opStartTime, 0);
882 #endif /* FS_STATS_DETAILED */
884 ViceLog(1, ("SAFS_BulkStatus\n"));
886 AFSCallStats.TotalCalls++;
889 nfiles = Fids->AFSCBFids_len; /* # of files in here */
890 if (nfiles <= 0) { /* Sanity check */
892 goto Audit_and_Return;
895 /* allocate space for return output parameters */
896 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
897 malloc(nfiles * sizeof(struct AFSFetchStatus));
898 OutStats->AFSBulkStats_len = nfiles;
899 CallBacks->AFSCBs_val = (struct AFSCallBack *)
900 malloc(nfiles * sizeof(struct AFSCallBack));
901 CallBacks->AFSCBs_len = nfiles;
903 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
906 tfid = Fids->AFSCBFids_val;
907 for (i=0; i<nfiles; i++, tfid++) {
909 * Get volume/vnode for the fetched file; caller's rights to it
913 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
914 DONTCHECK, &parentwhentargetnotdir, &client,
915 READ_LOCK, &rights, &anyrights))
917 /* set volume synchronization information, but only once per call */
919 SetVolumeSync(Sync, volptr);
921 /* Are we allowed to fetch Fid's status? */
922 if (targetptr->disk.type != vDirectory) {
923 if (errorCode = Check_PermissionRights(targetptr, client, rights,
928 /* set OutStatus From the Fid */
929 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i],
930 rights, anyrights, parentwhentargetnotdir);
932 /* If a r/w volume, also set the CallBack state */
933 if (VolumeWriteable(volptr))
934 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
935 &CallBacks->AFSCBs_val[i]);
938 bzero(&myFid, sizeof(struct AFSFid));
939 myFid.Volume = tfid->Volume;
940 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
941 &CallBacks->AFSCBs_val[i]);
944 /* put back the file ID and volume */
945 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
946 parentwhentargetnotdir = (Vnode *) 0;
947 targetptr = (Vnode *) 0;
948 volptr = (Volume *) 0;
952 /* Update and store volume/vnode and parent vnodes back */
953 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
956 #if FS_STATS_DETAILED
957 TM_GetTimeOfDay(&opStopTime, 0);
958 if (errorCode == 0) {
960 (opP->numSuccesses)++;
961 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
962 fs_stats_AddTo((opP->sumTime), elapsedTime);
963 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
964 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
965 fs_stats_TimeAssign((opP->minTime), elapsedTime);
967 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
968 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
973 #endif /* FS_STATS_DETAILED */
976 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
977 osi_auditU (tcall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
980 } /*SRXAFS_BulkStatus*/
983 SRXAFS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync)
984 struct AFSVolSync *Sync;
985 struct rx_connection *tcon; /* Rx connection handle */
986 struct AFSFid *Fid; /* Fid of target file */
987 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
988 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
992 struct rx_call *tcall = (struct rx_call *) tcon;
993 #if FS_STATS_DETAILED
994 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
995 struct timeval opStartTime,
996 opStopTime; /* Start/stop times for RPC op*/
997 struct timeval elapsedTime; /* Transfer time */
1000 * Set our stats pointer, remember when the RPC operation started, and
1001 * tally the operation.
1003 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
1007 TM_GetTimeOfDay(&opStartTime, 0);
1008 #endif /* FS_STATS_DETAILED */
1010 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1011 goto Bad_FetchStatus;
1013 code = SAFSS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync);
1016 CallPostamble(tcon);
1018 #if FS_STATS_DETAILED
1019 TM_GetTimeOfDay(&opStopTime, 0);
1022 (opP->numSuccesses)++;
1023 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1024 fs_stats_AddTo((opP->sumTime), elapsedTime);
1025 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1026 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1027 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1029 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1030 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1035 #endif /* FS_STATS_DETAILED */
1037 osi_auditU (tcall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
1040 } /*SRXAFS_FetchStatus*/
1043 SRXAFS_StoreData (tcon, Fid, InStatus, Pos, Length, FileLength, OutStatus, Sync)
1044 struct AFSVolSync *Sync;
1045 struct rx_connection *tcon; /* Rx connection Handle */
1046 struct AFSFid *Fid; /* Fid of taret file */
1047 struct AFSStoreStatus *InStatus; /* Input Status for Fid */
1048 afs_int32 Pos; /* Not implemented yet */
1049 afs_int32 Length; /* Length of data to store */
1050 afs_int32 FileLength; /* Length of file after store */
1051 struct AFSFetchStatus *OutStatus; /* Returned status for target fid */
1054 Vnode * targetptr = 0; /* pointer to input fid */
1055 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1056 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
1057 int errorCode = 0; /* return code for caller */
1058 int fileCode = 0; /* return code from vol package */
1059 Volume * volptr = 0; /* pointer to the volume header */
1060 struct client * client; /* pointer to client structure */
1061 struct rx_call *tcall; /* remember the call structure for ftp */
1062 afs_int32 rights, anyrights; /* rights for this and any user */
1063 struct client *t_client; /* tmp ptr to client data */
1064 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1065 #if FS_STATS_DETAILED
1066 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1067 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
1068 struct timeval opStartTime,
1069 opStopTime; /* Start/stop times for RPC op*/
1070 struct timeval xferStartTime,
1071 xferStopTime; /* Start/stop times for xfer portion*/
1072 struct timeval elapsedTime; /* Transfer time */
1073 afs_int32 bytesToXfer; /* # bytes to xfer */
1074 afs_int32 bytesXferred; /* # bytes actually xfer */
1075 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
1078 * Set our stats pointers, remember when the RPC operation started, and
1079 * tally the operation.
1081 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
1082 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
1087 ViceLog(1, ("StoreData: Fid = %u.%d.%d\n",
1088 Fid->Volume, Fid->Vnode, Fid->Unique));
1089 TM_GetTimeOfDay(&opStartTime, 0);
1090 #endif /* FS_STATS_DETAILED */
1093 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
1095 /* CallPreamble changes tcon from a call to a conn */
1096 tcall = (struct rx_call *) tcon;
1097 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1100 /* Get ptr to client data for user Id for logging */
1101 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1102 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1103 ViceLog(5, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d\n",
1104 Fid->Volume, Fid->Vnode, Fid->Unique,
1105 inet_ntoa(logHostAddr), t_client->ViceId));
1108 * Get associated volume/vnode for the stored file; caller's rights
1111 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1112 MustNOTBeDIR, &parentwhentargetnotdir,
1113 &client, WRITE_LOCK, &rights, &anyrights)) {
1117 /* set volume synchronization information */
1118 SetVolumeSync(Sync, volptr);
1120 if ((targetptr->disk.type == vSymlink)) {
1121 /* Should we return a better error code here??? */
1126 /* Check if we're allowed to store the data */
1127 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1128 CHK_STOREDATA, InStatus)) {
1133 * Drop the read lock on the parent directory after saving the parent
1134 * vnode information we need to pass to GetStatus
1136 if (parentwhentargetnotdir != NULL) {
1137 tparentwhentargetnotdir = *parentwhentargetnotdir;
1138 VPutVnode(&fileCode, parentwhentargetnotdir);
1139 assert(!fileCode || (fileCode == VSALVAGE));
1140 parentwhentargetnotdir = NULL;
1145 #if FS_STATS_DETAILED
1147 * Remember when the data transfer started.
1149 TM_GetTimeOfDay(&xferStartTime, 0);
1150 #endif /* FS_STATS_DETAILED */
1152 /* Do the actual storing of the data */
1153 #if FS_STATS_DETAILED
1154 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client, tcall,
1155 Pos, Length, FileLength,
1156 (InStatus->Mask & AFS_FSYNC),
1157 &bytesToXfer, &bytesXferred);
1159 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client,
1160 tcall, Pos, Length, FileLength,
1161 (InStatus->Mask & AFS_FSYNC));
1162 if (errorCode && (!targetptr->changed_newTime))
1164 #endif /* FS_STATS_DETAILED */
1165 #if FS_STATS_DETAILED
1167 * At this point, the data transfer is done, for good or ill. Remember
1168 * when the transfer ended, bump the number of successes/failures, and
1169 * integrate the transfer size and elapsed time into the stats. If the
1170 * operation failed, we jump to the appropriate point.
1172 TM_GetTimeOfDay(&xferStopTime, 0);
1174 (xferP->numXfers)++;
1176 (xferP->numSuccesses)++;
1179 * Bump the xfer sum by the number of bytes actually sent, NOT the
1182 tot_bytesXferred += bytesXferred;
1183 (xferP->sumBytes) += (tot_bytesXferred >> 10);
1184 tot_bytesXferred &= 0x3FF;
1185 if (bytesXferred < xferP->minBytes)
1186 xferP->minBytes = bytesXferred;
1187 if (bytesXferred > xferP->maxBytes)
1188 xferP->maxBytes = bytesXferred;
1191 * Tally the size of the object. Note: we tally the actual size,
1192 * NOT the number of bytes that made it out over the wire.
1194 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
1195 (xferP->count[0])++;
1197 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
1198 (xferP->count[1])++;
1200 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
1201 (xferP->count[2])++;
1203 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
1204 (xferP->count[3])++;
1206 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
1207 (xferP->count[4])++;
1209 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
1210 (xferP->count[5])++;
1212 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
1213 (xferP->count[6])++;
1215 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
1216 (xferP->count[7])++;
1218 (xferP->count[8])++;
1220 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
1221 fs_stats_AddTo((xferP->sumTime), elapsedTime);
1222 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
1223 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
1224 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
1226 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
1227 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
1233 * Finally, go off to tell our caller the bad news in case the
1236 if (errorCode && (!targetptr->changed_newTime))
1238 #endif /* FS_STATS_DETAILED */
1240 /* Update the status of the target's vnode */
1241 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus, targetptr,
1244 /* Get the updated File's status back to the caller */
1245 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
1248 /* Update and store volume/vnode and parent vnodes back */
1249 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1250 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
1252 CallPostamble(tcon);
1254 #if FS_STATS_DETAILED
1255 TM_GetTimeOfDay(&opStopTime, 0);
1256 if (errorCode == 0) {
1258 (opP->numSuccesses)++;
1259 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1260 fs_stats_AddTo((opP->sumTime), elapsedTime);
1261 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1262 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1263 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1265 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1266 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1270 #endif /* FS_STATS_DETAILED */
1272 osi_auditU (tcall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
1275 } /*SRXAFS_StoreData*/
1278 SRXAFS_StoreACL (tcon, Fid, AccessList, OutStatus, Sync)
1279 struct AFSVolSync *Sync;
1280 struct rx_connection *tcon; /* Rx connection handle */
1281 struct AFSFid *Fid; /* Target dir's fid */
1282 struct AFSOpaque *AccessList; /* Access List's contents */
1283 struct AFSFetchStatus *OutStatus; /* Returned status of fid */
1286 Vnode * targetptr = 0; /* pointer to input fid */
1287 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1288 int errorCode = 0; /* return code for caller */
1289 struct AFSStoreStatus InStatus; /* Input status for fid */
1290 Volume * volptr = 0; /* pointer to the volume header */
1291 struct client * client; /* pointer to client structure */
1292 afs_int32 rights, anyrights; /* rights for this and any user */
1293 struct rx_call *tcall = (struct rx_call *) tcon;
1294 struct client *t_client; /* tmp ptr to client data */
1295 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1296 #if FS_STATS_DETAILED
1297 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1298 struct timeval opStartTime,
1299 opStopTime; /* Start/stop times for RPC op*/
1300 struct timeval elapsedTime; /* Transfer time */
1303 * Set our stats pointer, remember when the RPC operation started, and
1304 * tally the operation.
1306 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
1310 TM_GetTimeOfDay(&opStartTime, 0);
1311 #endif /* FS_STATS_DETAILED */
1312 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1315 /* Get ptr to client data for user Id for logging */
1316 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1317 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1318 ViceLog(1, ("SAFS_StoreACL, Fid = %u.%d.%d, ACL=%s, Host %s, Id %d\n",
1319 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
1320 inet_ntoa(logHostAddr), t_client->ViceId));
1322 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
1325 InStatus.Mask = 0; /* not storing any status */
1328 * Get associated volume/vnode for the target dir; caller's rights
1329 * are also returned.
1331 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1332 MustBeDIR, &parentwhentargetnotdir,
1333 &client, WRITE_LOCK, &rights, &anyrights)) {
1337 /* set volume synchronization information */
1338 SetVolumeSync(Sync, volptr);
1340 /* Check if we have permission to change the dir's ACL */
1341 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1342 CHK_STOREACL, &InStatus)) {
1346 /* Build and store the new Access List for the dir */
1347 if (errorCode = RXStore_AccessList(targetptr, AccessList)) {
1351 targetptr->changed_newTime = 1; /* status change of directory */
1353 /* convert the write lock to a read lock before breaking callbacks */
1354 VVnodeWriteToRead(&errorCode, targetptr);
1355 assert(!errorCode || errorCode == VSALVAGE);
1357 /* break call backs on the directory */
1358 BreakCallBack(client->host, Fid, 0);
1360 /* Get the updated dir's status back to the caller */
1361 GetStatus(targetptr, OutStatus, rights, anyrights, (struct vnode *)0);
1364 /* Update and store volume/vnode and parent vnodes back */
1365 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1366 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
1367 CallPostamble(tcon);
1369 #if FS_STATS_DETAILED
1370 TM_GetTimeOfDay(&opStopTime, 0);
1371 if (errorCode == 0) {
1373 (opP->numSuccesses)++;
1374 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1375 fs_stats_AddTo((opP->sumTime), elapsedTime);
1376 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1377 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1378 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1380 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1381 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1385 #endif /* FS_STATS_DETAILED */
1387 osi_auditU (tcall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
1390 } /*SRXAFS_StoreACL*/
1394 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
1395 * should be merged when possible.
1397 SAFSS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync)
1398 struct rx_connection *tcon; /* Rx connection Handle */
1399 struct AFSFid *Fid; /* Target file's fid */
1400 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1401 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1402 struct AFSVolSync *Sync;
1405 Vnode * targetptr = 0; /* pointer to input fid */
1406 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1407 int errorCode = 0; /* return code for caller */
1408 Volume * volptr = 0; /* pointer to the volume header */
1409 struct client * client; /* pointer to client structure */
1410 afs_int32 rights, anyrights; /* rights for this and any user */
1411 struct client *t_client; /* tmp ptr to client data */
1412 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1414 /* Get ptr to client data for user Id for logging */
1415 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1416 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1417 ViceLog(1, ("SAFS_StoreStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
1418 Fid->Volume, Fid->Vnode, Fid->Unique,
1419 inet_ntoa(logHostAddr), t_client->ViceId));
1421 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
1424 * Get volume/vnode for the target file; caller's rights to it are
1427 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1428 DONTCHECK, &parentwhentargetnotdir,
1429 &client, WRITE_LOCK, &rights, &anyrights)) {
1430 goto Bad_StoreStatus;
1433 /* set volume synchronization information */
1434 SetVolumeSync(Sync, volptr);
1436 /* Check if the caller has proper permissions to store status to Fid */
1437 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1438 CHK_STORESTATUS, InStatus)) {
1439 goto Bad_StoreStatus;
1442 * Check for a symbolic link; we can't chmod these (otherwise could
1443 * change a symlink to a mt pt or vice versa)
1445 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
1447 goto Bad_StoreStatus;
1450 /* Update the status of the target's vnode */
1451 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
1452 (parentwhentargetnotdir ?
1453 parentwhentargetnotdir : targetptr), volptr, 0);
1455 /* convert the write lock to a read lock before breaking callbacks */
1456 VVnodeWriteToRead(&errorCode, targetptr);
1457 assert(!errorCode || errorCode == VSALVAGE);
1459 /* Break call backs on Fid */
1460 BreakCallBack(client->host, Fid, 0);
1462 /* Return the updated status back to caller */
1463 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
1466 /* Update and store volume/vnode and parent vnodes back */
1467 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1468 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
1471 } /*SAFSS_StoreStatus*/
1474 SRXAFS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync)
1475 struct AFSVolSync *Sync;
1476 struct rx_connection *tcon; /* Rx connection Handle */
1477 struct AFSFid *Fid; /* Target file's fid */
1478 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1479 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1483 struct rx_call *tcall = (struct rx_call *) tcon;
1484 #if FS_STATS_DETAILED
1485 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1486 struct timeval opStartTime,
1487 opStopTime; /* Start/stop times for RPC op*/
1488 struct timeval elapsedTime; /* Transfer time */
1491 * Set our stats pointer, remember when the RPC operation started, and
1492 * tally the operation.
1494 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
1498 TM_GetTimeOfDay(&opStartTime, 0);
1499 #endif /* FS_STATS_DETAILED */
1501 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1502 goto Bad_StoreStatus;
1504 code = SAFSS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync);
1507 CallPostamble(tcon);
1509 #if FS_STATS_DETAILED
1510 TM_GetTimeOfDay(&opStopTime, 0);
1513 (opP->numSuccesses)++;
1514 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1515 fs_stats_AddTo((opP->sumTime), elapsedTime);
1516 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1517 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1518 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1520 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1521 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1526 #endif /* FS_STATS_DETAILED */
1528 osi_auditU (tcall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
1531 } /*SRXAFS_StoreStatus*/
1535 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
1536 * merged in when possible.
1538 SAFSS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync)
1539 struct rx_connection *tcon; /* Rx connection handle */
1540 struct AFSFid *DirFid; /* Dir fid for file to remove */
1541 char *Name; /* File name to remove */
1542 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1543 struct AFSVolSync *Sync;
1546 Vnode * parentptr = 0; /* vnode of input Directory */
1547 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1548 Vnode * targetptr = 0; /* file to be deleted */
1549 Volume * volptr = 0; /* pointer to the volume header */
1550 AFSFid fileFid; /* area for Fid from the directory */
1551 int errorCode = 0; /* error code */
1552 DirHandle dir; /* Handle for dir package I/O */
1553 struct client * client; /* pointer to client structure */
1554 afs_int32 rights, anyrights; /* rights for this and any user */
1555 struct client *t_client; /* tmp ptr to client data */
1556 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1558 /* Get ptr to client data for user Id for logging */
1559 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1560 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1561 ViceLog(1, ("SAFS_RemoveFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1562 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1563 inet_ntoa(logHostAddr), t_client->ViceId));
1565 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
1568 * Get volume/vnode for the parent dir; caller's access rights are
1571 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1572 MustBeDIR, &parentwhentargetnotdir,
1573 &client, WRITE_LOCK, &rights, &anyrights)) {
1574 goto Bad_RemoveFile;
1576 /* set volume synchronization information */
1577 SetVolumeSync(Sync, volptr);
1579 /* Does the caller has delete (& write) access to the parent directory? */
1580 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
1581 goto Bad_RemoveFile;
1584 /* Actually delete the desired file */
1585 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir,
1586 &fileFid, Name, MustNOTBeDIR)) {
1587 goto Bad_RemoveFile;
1590 /* Update the vnode status of the parent dir */
1591 #if FS_STATS_DETAILED
1592 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1593 parentptr->disk.linkCount, client->InSameNetwork);
1595 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1596 parentptr->disk.linkCount);
1597 #endif /* FS_STATS_DETAILED */
1599 /* Return the updated parent dir's status back to caller */
1600 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
1602 /* Handle internal callback state for the parent and the deleted file */
1603 if (targetptr->disk.linkCount == 0) {
1604 /* no references left, discard entry */
1605 DeleteFileCallBacks(&fileFid);
1606 /* convert the parent lock to a read lock before breaking callbacks */
1607 VVnodeWriteToRead(&errorCode, parentptr);
1608 assert(!errorCode || errorCode == VSALVAGE);
1610 /* convert the parent lock to a read lock before breaking callbacks */
1611 VVnodeWriteToRead(&errorCode, parentptr);
1612 assert(!errorCode || errorCode == VSALVAGE);
1613 /* convert the target lock to a read lock before breaking callbacks */
1614 VVnodeWriteToRead(&errorCode, targetptr);
1615 assert(!errorCode || errorCode == VSALVAGE);
1616 /* tell all the file has changed */
1617 BreakCallBack(client->host, &fileFid, 1);
1620 /* break call back on the directory */
1621 BreakCallBack(client->host, DirFid, 0);
1624 /* Update and store volume/vnode and parent vnodes back */
1625 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
1626 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
1629 } /*SAFSS_RemoveFile*/
1632 SRXAFS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync)
1633 struct AFSVolSync *Sync;
1634 struct rx_connection *tcon; /* Rx connection handle */
1635 struct AFSFid *DirFid; /* Dir fid for file to remove */
1636 char *Name; /* File name to remove */
1637 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1641 struct rx_call *tcall = (struct rx_call *) tcon;
1642 #if FS_STATS_DETAILED
1643 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1644 struct timeval opStartTime,
1645 opStopTime; /* Start/stop times for RPC op*/
1646 struct timeval elapsedTime; /* Transfer time */
1649 * Set our stats pointer, remember when the RPC operation started, and
1650 * tally the operation.
1652 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
1656 TM_GetTimeOfDay(&opStartTime, 0);
1657 #endif /* FS_STATS_DETAILED */
1659 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1660 goto Bad_RemoveFile;
1662 code = SAFSS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync);
1665 CallPostamble(tcon);
1667 #if FS_STATS_DETAILED
1668 TM_GetTimeOfDay(&opStopTime, 0);
1671 (opP->numSuccesses)++;
1672 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1673 fs_stats_AddTo((opP->sumTime), elapsedTime);
1674 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1675 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1676 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1678 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1679 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1684 #endif /* FS_STATS_DETAILED */
1686 osi_auditU (tcall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
1689 } /*SRXAFS_RemoveFile*/
1693 * This routine is called exclusively from SRXAFS_CreateFile(), and should
1694 * be merged in when possible.
1696 SAFSS_CreateFile (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus,
1697 OutDirStatus, CallBack, Sync)
1698 struct rx_connection *tcon; /* Rx connection handle */
1699 struct AFSFid *DirFid; /* Parent Dir fid */
1700 char *Name; /* File name to be created */
1701 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
1702 struct AFSFid *OutFid; /* Fid for newly created file */
1703 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
1704 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
1705 struct AFSCallBack *CallBack; /* Return callback promise for new file */
1706 struct AFSVolSync *Sync;
1709 Vnode * parentptr = 0; /* vnode of input Directory */
1710 Vnode * targetptr = 0; /* vnode of the new file */
1711 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1712 Volume * volptr = 0; /* pointer to the volume header */
1713 int errorCode = 0; /* error code */
1714 DirHandle dir; /* Handle for dir package I/O */
1715 struct client * client; /* pointer to client structure */
1716 afs_int32 rights, anyrights; /* rights for this and any user */
1717 struct client *t_client; /* tmp ptr to client data */
1718 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1720 /* Get ptr to client data for user Id for logging */
1721 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1722 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1723 ViceLog(1, ("SAFS_CreateFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1724 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1725 inet_ntoa(logHostAddr), t_client->ViceId));
1727 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
1729 if (!FileNameOK(Name)) {
1731 goto Bad_CreateFile;
1735 * Get associated volume/vnode for the parent dir; caller long are
1738 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1739 MustBeDIR, &parentwhentargetnotdir,
1740 &client, WRITE_LOCK, &rights, &anyrights)) {
1741 goto Bad_CreateFile;
1744 /* set volume synchronization information */
1745 SetVolumeSync(Sync, volptr);
1747 /* Can we write (and insert) onto the parent directory? */
1748 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
1749 goto Bad_CreateFile;
1751 /* get a new vnode for the file to be created and set it up */
1752 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
1753 Name, OutFid, vFile, nBlocks(0))) {
1754 goto Bad_CreateFile;
1757 /* update the status of the parent vnode */
1758 #if FS_STATS_DETAILED
1759 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1760 parentptr->disk.linkCount, client->InSameNetwork);
1762 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1763 parentptr->disk.linkCount);
1764 #endif /* FS_STATS_DETAILED */
1766 /* update the status of the new file's vnode */
1767 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
1768 parentptr, volptr, 0);
1770 /* set up the return status for the parent dir and the newly created file */
1771 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
1772 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
1774 /* convert the write lock to a read lock before breaking callbacks */
1775 VVnodeWriteToRead(&errorCode, parentptr);
1776 assert(!errorCode || errorCode == VSALVAGE);
1778 /* break call back on parent dir */
1779 BreakCallBack(client->host, DirFid, 0);
1781 /* Return a callback promise for the newly created file to the caller */
1782 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
1785 /* Update and store volume/vnode and parent vnodes back */
1786 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
1787 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
1790 } /*SAFSS_CreateFile*/
1793 SRXAFS_CreateFile (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
1794 struct AFSVolSync *Sync;
1795 struct rx_connection *tcon; /* Rx connection handle */
1796 struct AFSFid *DirFid; /* Parent Dir fid */
1797 char *Name; /* File name to be created */
1798 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
1799 struct AFSFid *OutFid; /* Fid for newly created file */
1800 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
1801 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
1802 struct AFSCallBack *CallBack; /* Return callback promise for new file */
1806 struct rx_call *tcall = (struct rx_call *) tcon;
1807 #if FS_STATS_DETAILED
1808 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1809 struct timeval opStartTime,
1810 opStopTime; /* Start/stop times for RPC op*/
1811 struct timeval elapsedTime; /* Transfer time */
1814 * Set our stats pointer, remember when the RPC operation started, and
1815 * tally the operation.
1817 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
1821 TM_GetTimeOfDay(&opStartTime, 0);
1822 #endif /* FS_STATS_DETAILED */
1824 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1825 goto Bad_CreateFile;
1827 code = SAFSS_CreateFile (tcon, DirFid, Name, InStatus, OutFid,
1828 OutFidStatus, OutDirStatus, CallBack, Sync);
1831 CallPostamble(tcon);
1833 #if FS_STATS_DETAILED
1834 TM_GetTimeOfDay(&opStopTime, 0);
1837 (opP->numSuccesses)++;
1838 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1839 fs_stats_AddTo((opP->sumTime), elapsedTime);
1840 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1841 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1842 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1844 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1845 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1849 #endif /* FS_STATS_DETAILED */
1851 osi_auditU (tcall, CreateFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
1854 } /*SRXAFS_CreateFile*/
1858 * This routine is called exclusively from SRXAFS_Rename(), and should be
1859 * merged in when possible.
1861 SAFSS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus,
1862 OutNewDirStatus, Sync)
1863 struct rx_connection *tcon; /* Rx connection handle */
1864 struct AFSFid *OldDirFid; /* From parent dir's fid */
1865 char *OldName; /* From file name */
1866 struct AFSFid *NewDirFid; /* To parent dir's fid */
1867 char *NewName; /* To new file name */
1868 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
1869 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
1870 struct AFSVolSync *Sync;
1873 Vnode * oldvptr = 0; /* vnode of the old Directory */
1874 Vnode * newvptr = 0; /* vnode of the new Directory */
1875 Vnode * fileptr = 0; /* vnode of the file to move */
1876 Vnode * newfileptr = 0; /* vnode of the file to delete */
1877 Vnode * testvptr = 0; /* used in directory tree walk */
1878 Vnode * parent = 0; /* parent for use in SetAccessList */
1879 int errorCode = 0; /* error code */
1880 int fileCode = 0; /* used when writing Vnodes */
1881 VnodeId testnode; /* used in directory tree walk */
1882 AFSFid fileFid; /* Fid of file to move */
1883 AFSFid newFileFid; /* Fid of new file */
1884 DirHandle olddir; /* Handle for dir package I/O */
1885 DirHandle newdir; /* Handle for dir package I/O */
1886 DirHandle filedir; /* Handle for dir package I/O */
1887 DirHandle newfiledir; /* Handle for dir package I/O */
1888 Volume * volptr = 0; /* pointer to the volume header */
1889 struct client * client; /* pointer to client structure */
1890 afs_int32 rights, anyrights; /* rights for this and any user */
1891 afs_int32 newrights; /* rights for this user */
1892 afs_int32 newanyrights; /* rights for any user */
1893 int doDelete; /* deleted the rename target (ref count now 0) */
1895 struct client *t_client; /* tmp ptr to client data */
1896 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1898 /* Get ptr to client data for user Id for logging */
1899 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1900 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1901 ViceLog(1, ("SAFS_Rename %s to %s, Fid = %u.%d.%d to %u.%d.%d, Host %s, Id %d\n",
1902 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
1903 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
1905 inet_ntoa(logHostAddr), t_client->ViceId));
1907 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
1909 if (!FileNameOK(NewName)) {
1913 if (OldDirFid->Volume != NewDirFid->Volume) {
1918 if ( (strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0) ||
1919 (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0) ||
1920 (strlen(NewName) == 0) || (strlen(OldName) == 0) ) {
1926 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
1927 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr,
1928 &oldvptr, MustBeDIR, &parent,
1929 &client, WRITE_LOCK, &rights,
1934 if (OldDirFid->Vnode == NewDirFid->Vnode) {
1936 newrights = rights, newanyrights = anyrights;
1939 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
1940 &newvptr, MustBeDIR, &parent,
1941 &client, WRITE_LOCK, &newrights,
1948 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
1949 &newvptr, MustBeDIR, &parent,
1950 &client, WRITE_LOCK, &newrights,
1955 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr,
1956 MustBeDIR, &parent, &client, WRITE_LOCK,
1957 &rights, &anyrights)) {
1963 /* set volume synchronization information */
1964 SetVolumeSync(Sync, volptr);
1966 if (errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE)) {
1969 if (errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT)) {
1973 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
1974 * call to CopyOnWrite returns error, it is not necessary to revert back
1975 * the effects of the first call because the contents of the volume is
1976 * not modified, it is only replicated.
1978 if (oldvptr->disk.cloned)
1980 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
1981 if ( errorCode = CopyOnWrite(oldvptr, volptr) )
1984 SetDirHandle(&olddir, oldvptr);
1985 if (newvptr->disk.cloned)
1987 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
1988 if ( errorCode = CopyOnWrite(newvptr, volptr) )
1992 SetDirHandle(&newdir, newvptr);
1994 /* Lookup the file to delete its vnode */
1995 if (Lookup(&olddir, OldName, &fileFid)) {
1999 if (fileFid.Vnode == oldvptr->vnodeNumber ||
2000 fileFid.Vnode == newvptr->vnodeNumber) {
2001 errorCode = FSERR_ELOOP;
2004 fileFid.Volume = V_id(volptr);
2005 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
2006 if (errorCode != 0) {
2007 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n", OldName, errorCode));
2008 VTakeOffline (volptr);
2011 if (fileptr->disk.uniquifier != fileFid.Unique) {
2012 ViceLog (0, ("SAFSS_Rename(): Old file %s uniquifier mismatch\n", OldName));
2013 VTakeOffline (volptr);
2018 if (fileptr->disk.type != vDirectory &&
2019 oldvptr != newvptr &&
2020 fileptr->disk.linkCount != 1) {
2022 * Hard links exist to this file - cannot move one of the links to
2023 * a new directory because of AFS restrictions (this is the same
2024 * reason that links cannot be made across directories, i.e.
2031 /* Lookup the new file */
2032 if (!(Lookup(&newdir, NewName, &newFileFid))) {
2033 if (!(newrights & PRSFS_DELETE)) {
2037 if (newFileFid.Vnode == oldvptr->vnodeNumber ||
2038 newFileFid.Vnode == newvptr->vnodeNumber ||
2039 newFileFid.Vnode == fileFid.Vnode) {
2043 newFileFid.Volume = V_id(volptr);
2044 newfileptr = VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
2045 if (errorCode != 0) {
2046 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n", NewName, errorCode));
2047 VTakeOffline (volptr);
2050 if (fileptr->disk.uniquifier != fileFid.Unique) {
2051 ViceLog (0, ("SAFSS_Rename(): New file %s uniquifier mismatch\n", NewName));
2052 VTakeOffline (volptr);
2056 SetDirHandle(&newfiledir, newfileptr);
2057 /* Now check that we're moving directories over directories properly, etc.
2058 * return proper POSIX error codes:
2059 * if fileptr is a file and new is a dir: EISDIR.
2060 * if fileptr is a dir and new is a file: ENOTDIR.
2061 * Also, dir to be removed must be empty, of course.
2063 if (newfileptr->disk.type == vDirectory) {
2064 if (fileptr->disk.type != vDirectory) {
2068 if ((IsEmpty(&newfiledir))) {
2074 if (fileptr->disk.type == vDirectory) {
2075 errorCode = ENOTDIR;
2082 * ok - now we check that the old name is not above new name in the
2083 * directory structure. This is to prevent removing a subtree alltogether
2085 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
2086 for (testnode = newvptr->disk.parent; testnode != 0;) {
2087 if (testnode == oldvptr->vnodeNumber) {
2088 testnode = oldvptr->disk.parent;
2091 if ((testnode == fileptr->vnodeNumber) ||
2092 (testnode == newvptr->vnodeNumber)) {
2093 errorCode = FSERR_ELOOP;
2096 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
2097 errorCode = FSERR_ELOOP;
2100 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
2101 assert(errorCode == 0);
2102 testnode = testvptr->disk.parent;
2103 VPutVnode(&errorCode, testvptr);
2104 assert(errorCode == 0);
2107 /* Do the CopyonWrite first before modifying anything else. Copying is
2108 * required because we may have to change entries for ..
2110 if ((fileptr->disk.type == vDirectory ) && (fileptr->disk.cloned) )
2112 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
2113 if ( errorCode = CopyOnWrite(fileptr, volptr) )
2117 /* If the new name exists already, delete it and the file it points to */
2120 /* Delete NewName from its directory */
2121 code = Delete(&newdir, NewName);
2124 /* Drop the link count */
2125 newfileptr->disk.linkCount--;
2126 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
2127 VAdjustDiskUsage(&errorCode, volptr,
2128 -(int)nBlocks(newfileptr->disk.length), 0);
2129 if (VN_GET_INO(newfileptr)) {
2130 IH_REALLYCLOSE(newfileptr->handle);
2131 errorCode = IH_DEC(V_linkHandle(volptr),
2132 VN_GET_INO(newfileptr),
2133 V_parentId(volptr));
2134 IH_RELEASE(newfileptr->handle);
2135 if (errorCode == -1) {
2136 ViceLog(0, ("Del: inode=%d, name=%s, errno=%d\n",
2137 PrintInode(NULL, VN_GET_INO(newfileptr)),
2139 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
2140 ViceLog(0, ("Do we need to fsck?"));
2143 VN_SET_INO(newfileptr, (Inode)0);
2144 newfileptr->delete = 1; /* Mark NewName vnode to delete */
2147 /* Link count did not drop to zero.
2148 * Mark NewName vnode as changed - updates stime.
2150 newfileptr->changed_newTime = 1;
2155 * If the create below fails, and the delete above worked, we have
2156 * removed the new name and not replaced it. This is not very likely,
2157 * but possible. We could try to put the old file back, but it is
2158 * highly unlikely that it would work since it would involve issuing
2161 if (errorCode = Create(&newdir,(char *) NewName, &fileFid))
2164 /* Delete the old name */
2165 assert(Delete(&olddir,(char *) OldName) == 0);
2167 /* if the directory length changes, reflect it in the statistics */
2168 #if FS_STATS_DETAILED
2169 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2170 oldvptr->disk.linkCount, client->InSameNetwork);
2171 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2172 newvptr->disk.linkCount, client->InSameNetwork);
2174 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2175 oldvptr->disk.linkCount);
2176 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2177 newvptr->disk.linkCount);
2178 #endif /* FS_STATS_DETAILED */
2180 if (oldvptr == newvptr)
2181 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
2183 fileptr->disk.parent = newvptr->vnodeNumber;
2184 fileptr->changed_newTime = 1; /* status change of moved file */
2186 /* if we are dealing with a rename of a directory */
2187 if (fileptr->disk.type == vDirectory) {
2188 assert(!fileptr->disk.cloned);
2189 SetDirHandle(&filedir, fileptr);
2190 /* fix .. to point to the correct place */
2191 Delete(&filedir, ".."); /* No assert--some directories may be bad */
2192 assert(Create(&filedir, "..", NewDirFid) == 0);
2193 fileptr->disk.dataVersion++;
2194 /* if the parent directories are different the link counts have to be */
2195 /* changed due to .. in the renamed directory */
2196 if (oldvptr != newvptr) {
2197 oldvptr->disk.linkCount--;
2198 newvptr->disk.linkCount++;
2202 /* set up return status */
2203 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, (struct vnode *)0);
2204 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, (struct vnode *)0);
2205 if (newfileptr && doDelete) {
2206 DeleteFileCallBacks(&newFileFid); /* no other references */
2211 /* convert the write locks to a read locks before breaking callbacks */
2212 VVnodeWriteToRead(&errorCode, newvptr);
2213 assert(!errorCode || errorCode == VSALVAGE);
2214 if (oldvptr != newvptr) {
2215 VVnodeWriteToRead(&errorCode, oldvptr);
2216 assert(!errorCode || errorCode == VSALVAGE);
2218 if (newfileptr && !doDelete) {
2219 /* convert the write lock to a read lock before breaking callbacks */
2220 VVnodeWriteToRead(&errorCode, newfileptr);
2221 assert(!errorCode || errorCode == VSALVAGE);
2224 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
2225 BreakCallBack(client->host, NewDirFid, 0);
2226 if (oldvptr != newvptr) {
2227 BreakCallBack(client->host, OldDirFid, 0);
2228 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
2229 BreakCallBack(client->host, &fileFid, 0);
2232 /* Note: it is not necessary to break the callback */
2234 DeleteFileCallBacks(&newFileFid); /* no other references */
2236 /* other's still exist (with wrong link count) */
2237 BreakCallBack(client->host, &newFileFid, 1);
2242 VPutVnode(&fileCode, newfileptr);
2243 assert(fileCode == 0);
2245 PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr? newvptr : 0),
2247 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
2253 SRXAFS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus, OutNewDirStatus, Sync)
2254 struct AFSVolSync *Sync;
2255 struct rx_connection *tcon; /* Rx connection handle */
2256 struct AFSFid *OldDirFid; /* From parent dir's fid */
2257 char *OldName; /* From file name */
2258 struct AFSFid *NewDirFid; /* To parent dir's fid */
2259 char *NewName; /* To new file name */
2260 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
2261 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
2265 struct rx_call *tcall = (struct rx_call *) tcon;
2266 #if FS_STATS_DETAILED
2267 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2268 struct timeval opStartTime,
2269 opStopTime; /* Start/stop times for RPC op*/
2270 struct timeval elapsedTime; /* Transfer time */
2273 * Set our stats pointer, remember when the RPC operation started, and
2274 * tally the operation.
2276 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
2280 TM_GetTimeOfDay(&opStartTime, 0);
2281 #endif /* FS_STATS_DETAILED */
2283 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2286 code = SAFSS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName,
2287 OutOldDirStatus, OutNewDirStatus, Sync);
2290 CallPostamble(tcon);
2292 #if FS_STATS_DETAILED
2293 TM_GetTimeOfDay(&opStopTime, 0);
2296 (opP->numSuccesses)++;
2297 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2298 fs_stats_AddTo((opP->sumTime), elapsedTime);
2299 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2300 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2301 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2303 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2304 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2309 #endif /* FS_STATS_DETAILED */
2311 osi_auditU (tcall, RenameFileEvent, code, AUD_FID, OldDirFid, AUD_STR, OldName, AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
2318 * This routine is called exclusively by SRXAFS_Symlink(), and should be
2319 * merged into it when possible.
2321 SAFSS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2322 struct rx_connection *tcon; /* Rx connection handle */
2323 struct AFSFid *DirFid; /* Parent dir's fid */
2324 char *Name; /* File name to create */
2325 char *LinkContents; /* Contents of the new created file */
2326 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2327 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2328 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2329 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2330 struct AFSVolSync *Sync; /* volume synchronization information */
2333 Vnode * parentptr = 0; /* vnode of input Directory */
2334 Vnode * targetptr = 0; /* vnode of the new link */
2335 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2336 int errorCode = 0; /* error code */
2338 DirHandle dir; /* Handle for dir package I/O */
2339 Volume * volptr = 0; /* pointer to the volume header */
2340 struct client * client; /* pointer to client structure */
2341 afs_int32 rights, anyrights, fd; /* rights for this and any user */
2342 struct client *t_client; /* tmp ptr to client data */
2343 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2346 /* Get ptr to client data for user Id for logging */
2347 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2348 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2349 ViceLog(1, ("SAFS_Symlink %s to %s, Did = %u.%d.%d, Host %s, Id %d\n", Name,
2350 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2351 inet_ntoa(logHostAddr), t_client->ViceId));
2353 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
2355 if (!FileNameOK(Name)) {
2361 * Get the vnode and volume for the parent dir along with the caller's
2364 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2365 MustBeDIR, &parentwhentargetnotdir,
2366 &client, WRITE_LOCK, &rights, &anyrights)) {
2370 /* set volume synchronization information */
2371 SetVolumeSync(Sync, volptr);
2373 /* Does the caller has insert (and write) access to the parent directory? */
2374 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2379 * If we're creating a mount point (owner mode bits sans x bit), we must
2380 * have administer access to the directory, too. Always allow sysadmins
2383 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0100)) {
2385 * We have a symlink, 'cause we're trying to set the Unix mode bits
2386 * to something without the owner x bits (default mode bits if
2387 * AFS_SETMODE is false is 0777)
2389 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
2395 /* get a new vnode for the symlink and set it up */
2396 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
2397 Name, OutFid, vSymlink,
2398 nBlocks(strlen((char *) LinkContents)))) {
2402 /* update the status of the parent vnode */
2403 #if FS_STATS_DETAILED
2404 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2405 parentptr->disk.linkCount, client->InSameNetwork);
2407 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2408 parentptr->disk.linkCount);
2409 #endif /* FS_STATS_DETAILED */
2411 /* update the status of the new symbolic link file vnode */
2412 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus, parentptr,
2413 volptr, strlen((char *)LinkContents));
2415 /* Write the contents of the symbolic link name into the target inode */
2416 fdP = IH_OPEN(targetptr->handle);
2417 assert(fdP != NULL);
2418 assert(FDH_WRITE(fdP, (char *) LinkContents, strlen((char *) LinkContents)) == strlen((char *) LinkContents));
2421 * Set up and return modified status for the parent dir and new symlink
2424 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2425 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
2427 /* convert the write lock to a read lock before breaking callbacks */
2428 VVnodeWriteToRead(&errorCode, parentptr);
2429 assert(!errorCode || errorCode == VSALVAGE);
2431 /* break call back on the parent dir */
2432 BreakCallBack(client->host, DirFid, 0);
2435 /* Write the all modified vnodes (parent, new files) and volume back */
2436 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2437 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
2443 SRXAFS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2444 struct AFSVolSync *Sync;
2445 struct rx_connection *tcon; /* Rx connection handle */
2446 struct AFSFid *DirFid; /* Parent dir's fid */
2447 char *Name; /* File name to create */
2448 char *LinkContents; /* Contents of the new created file */
2449 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2450 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2451 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2452 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2456 struct rx_call *tcall = (struct rx_call *) tcon;
2457 #if FS_STATS_DETAILED
2458 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2459 struct timeval opStartTime,
2460 opStopTime; /* Start/stop times for RPC op*/
2461 struct timeval elapsedTime; /* Transfer time */
2464 * Set our stats pointer, remember when the RPC operation started, and
2465 * tally the operation.
2467 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
2471 TM_GetTimeOfDay(&opStartTime, 0);
2472 #endif /* FS_STATS_DETAILED */
2474 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2477 code = SAFSS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid,
2478 OutFidStatus, OutDirStatus, Sync);
2481 CallPostamble(tcon);
2483 #if FS_STATS_DETAILED
2484 TM_GetTimeOfDay(&opStopTime, 0);
2487 (opP->numSuccesses)++;
2488 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2489 fs_stats_AddTo((opP->sumTime), elapsedTime);
2490 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2491 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2492 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2494 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2495 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2500 #endif /* FS_STATS_DETAILED */
2502 osi_auditU (tcall, SymlinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2505 } /*SRXAFS_Symlink*/
2509 * This routine is called exclusively by SRXAFS_Link(), and should be
2510 * merged into it when possible.
2512 SAFSS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2513 struct rx_connection *tcon; /* Rx connection handle */
2514 struct AFSFid *DirFid; /* Parent dir's fid */
2515 char *Name; /* File name to create */
2516 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2517 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2518 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2519 struct AFSVolSync *Sync;
2522 Vnode * parentptr = 0; /* vnode of input Directory */
2523 Vnode * targetptr = 0; /* vnode of the new file */
2524 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2525 Volume * volptr = 0; /* pointer to the volume header */
2526 int errorCode = 0; /* error code */
2527 DirHandle dir; /* Handle for dir package I/O */
2528 struct client * client; /* pointer to client structure */
2529 afs_int32 rights, anyrights; /* rights for this and any user */
2530 struct client *t_client; /* tmp ptr to client data */
2531 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2533 /* Get ptr to client data for user Id for logging */
2534 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2535 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2536 ViceLog(1, ("SAFS_Link %s, Did = %u.%d.%d, Fid = %u.%d.%d, Host %s, Id %d\n",
2537 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2538 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
2539 inet_ntoa(logHostAddr), t_client->ViceId));
2541 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
2543 if (DirFid->Volume != ExistingFid->Volume) {
2547 if (!FileNameOK(Name)) {
2553 * Get the vnode and volume for the parent dir along with the caller's
2556 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2557 MustBeDIR, &parentwhentargetnotdir,
2558 &client, WRITE_LOCK, &rights, &anyrights)) {
2562 /* set volume synchronization information */
2563 SetVolumeSync(Sync, volptr);
2565 /* Can the caller insert into the parent directory? */
2566 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2570 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) ||
2571 (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
2572 /* AFS fileservers always have directory vnodes that are odd. */
2577 /* get the file vnode */
2578 if (errorCode = CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK)) {
2581 if (targetptr->disk.type != vFile) {
2585 if (targetptr->disk.parent != DirFid->Vnode) {
2589 if (parentptr->disk.cloned)
2591 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
2592 if ( errorCode = CopyOnWrite(parentptr, volptr))
2593 goto Bad_Link; /* disk full error */
2596 /* add the name to the directory */
2597 SetDirHandle(&dir, parentptr);
2598 if (errorCode = Create(&dir, (char *)Name, ExistingFid))
2602 /* update the status in the parent vnode */
2603 /**WARNING** --> disk.author SHOULDN'T be modified???? */
2604 #if FS_STATS_DETAILED
2605 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2606 parentptr->disk.linkCount, client->InSameNetwork);
2608 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2609 parentptr->disk.linkCount);
2610 #endif /* FS_STATS_DETAILED */
2612 targetptr->disk.linkCount++;
2613 targetptr->disk.author = client->ViceId;
2614 targetptr->changed_newTime = 1; /* Status change of linked-to file */
2616 /* set up return status */
2617 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2618 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
2620 /* convert the write locks to read locks before breaking callbacks */
2621 VVnodeWriteToRead(&errorCode, targetptr);
2622 assert(!errorCode || errorCode == VSALVAGE);
2623 VVnodeWriteToRead(&errorCode, parentptr);
2624 assert(!errorCode || errorCode == VSALVAGE);
2626 /* break call back on DirFid */
2627 BreakCallBack(client->host, DirFid, 0);
2629 * We also need to break the callback for the file that is hard-linked since part
2630 * of its status (like linkcount) is changed
2632 BreakCallBack(client->host, ExistingFid, 0);
2635 /* Write the all modified vnodes (parent, new files) and volume back */
2636 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2637 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
2643 SRXAFS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2644 struct AFSVolSync *Sync;
2645 struct rx_connection *tcon; /* Rx connection handle */
2646 struct AFSFid *DirFid; /* Parent dir's fid */
2647 char *Name; /* File name to create */
2648 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2649 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2650 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2654 struct rx_call *tcall = (struct rx_call *) tcon;
2655 #if FS_STATS_DETAILED
2656 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2657 struct timeval opStartTime,
2658 opStopTime; /* Start/stop times for RPC op*/
2659 struct timeval elapsedTime; /* Transfer time */
2662 * Set our stats pointer, remember when the RPC operation started, and
2663 * tally the operation.
2665 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
2669 TM_GetTimeOfDay(&opStartTime, 0);
2670 #endif /* FS_STATS_DETAILED */
2672 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2675 code = SAFSS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus,
2676 OutDirStatus, Sync);
2679 CallPostamble(tcon);
2681 #if FS_STATS_DETAILED
2682 TM_GetTimeOfDay(&opStopTime, 0);
2685 (opP->numSuccesses)++;
2686 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2687 fs_stats_AddTo((opP->sumTime), elapsedTime);
2688 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2689 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2690 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2692 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2693 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2698 #endif /* FS_STATS_DETAILED */
2700 osi_auditU (tcall, LinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_FID, ExistingFid, AUD_END);
2707 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
2708 * merged into it when possible.
2710 SAFSS_MakeDir (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus,
2711 OutDirStatus, CallBack, Sync)
2712 struct rx_connection *tcon; /* Rx connection handle */
2713 struct AFSFid *DirFid; /* Parent dir's fid */
2714 char *Name; /* Name of dir to be created */
2715 struct AFSStoreStatus *InStatus; /* Input status for new dir */
2716 struct AFSFid *OutFid; /* Fid of new dir */
2717 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
2718 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2719 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
2720 struct AFSVolSync *Sync;
2723 Vnode * parentptr = 0; /* vnode of input Directory */
2724 Vnode * targetptr = 0; /* vnode of the new file */
2725 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2726 Volume * volptr = 0; /* pointer to the volume header */
2727 int errorCode = 0; /* error code */
2728 struct acl_accessList * newACL; /* Access list */
2729 int newACLSize; /* Size of access list */
2730 DirHandle dir; /* Handle for dir package I/O */
2731 DirHandle parentdir; /* Handle for dir package I/O */
2732 struct client * client; /* pointer to client structure */
2733 afs_int32 rights, anyrights; /* rights for this and any user */
2734 struct client *t_client; /* tmp ptr to client data */
2735 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2737 /* Get ptr to client data for user Id for logging */
2738 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2739 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2740 ViceLog(1, ("SAFS_MakeDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
2741 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2742 inet_ntoa(logHostAddr), t_client->ViceId));
2744 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
2746 if (!FileNameOK(Name)) {
2752 * Get the vnode and volume for the parent dir along with the caller's
2755 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2756 MustBeDIR, &parentwhentargetnotdir,
2757 &client, WRITE_LOCK, &rights, &anyrights)) {
2761 /* set volume synchronization information */
2762 SetVolumeSync(Sync, volptr);
2764 /* Write access to the parent directory? */
2765 #ifdef DIRCREATE_NEED_WRITE
2767 * requires w access for the user to create a directory. this
2768 * closes a loophole in the current security arrangement, since a
2769 * user with i access only can create a directory and get the
2770 * implcit a access that goes with dir ownership, and proceed to
2771 * subvert quota in the volume.
2773 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) ||
2774 (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
2776 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2777 #endif /* DIRCREATE_NEED_WRITE */
2781 #define EMPTYDIRBLOCKS 2
2782 /* get a new vnode and set it up */
2783 if (errorCode = Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr,
2784 Name, OutFid, vDirectory, EMPTYDIRBLOCKS)) {
2788 /* Update the status for the parent dir */
2789 #if FS_STATS_DETAILED
2790 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
2791 parentptr->disk.linkCount+1, client->InSameNetwork);
2793 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
2794 parentptr->disk.linkCount+1);
2795 #endif /* FS_STATS_DETAILED */
2797 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
2798 assert((SetAccessList(&targetptr, &volptr, &newACL, &newACLSize,
2799 &parentwhentargetnotdir, (AFSFid *)0, 0)) == 0);
2800 assert(parentwhentargetnotdir == 0);
2801 bcopy((char *)VVnodeACL(parentptr), (char *)newACL, VAclSize(parentptr));
2803 /* update the status for the target vnode */
2804 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
2805 parentptr, volptr, 0);
2807 /* Actually create the New directory in the directory package */
2808 SetDirHandle(&dir, targetptr);
2809 assert(!(MakeDir(&dir, OutFid, DirFid)));
2811 targetptr->disk.length = Length(&dir);
2813 /* set up return status */
2814 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2815 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
2817 /* convert the write lock to a read lock before breaking callbacks */
2818 VVnodeWriteToRead(&errorCode, parentptr);
2819 assert(!errorCode || errorCode == VSALVAGE);
2821 /* break call back on DirFid */
2822 BreakCallBack(client->host, DirFid, 0);
2824 /* Return a callback promise to caller */
2825 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
2828 /* Write the all modified vnodes (parent, new files) and volume back */
2829 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2830 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
2836 SRXAFS_MakeDir (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
2837 struct AFSVolSync *Sync;
2838 struct rx_connection *tcon; /* Rx connection handle */
2839 struct AFSFid *DirFid; /* Parent dir's fid */
2840 char *Name; /* Name of dir to be created */
2841 struct AFSStoreStatus *InStatus; /* Input status for new dir */
2842 struct AFSFid *OutFid; /* Fid of new dir */
2843 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
2844 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2845 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
2849 struct rx_call *tcall = (struct rx_call *) tcon;
2850 #if FS_STATS_DETAILED
2851 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2852 struct timeval opStartTime,
2853 opStopTime; /* Start/stop times for RPC op*/
2854 struct timeval elapsedTime; /* Transfer time */
2857 * Set our stats pointer, remember when the RPC operation started, and
2858 * tally the operation.
2860 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
2864 TM_GetTimeOfDay(&opStartTime, 0);
2865 #endif /* FS_STATS_DETAILED */
2866 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2869 code = SAFSS_MakeDir (tcon, DirFid, Name, InStatus, OutFid,
2870 OutFidStatus, OutDirStatus, CallBack, Sync);
2873 CallPostamble(tcon);
2875 #if FS_STATS_DETAILED
2876 TM_GetTimeOfDay(&opStopTime, 0);
2879 (opP->numSuccesses)++;
2880 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2881 fs_stats_AddTo((opP->sumTime), elapsedTime);
2882 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2883 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2884 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2886 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2887 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2892 #endif /* FS_STATS_DETAILED */
2894 osi_auditU (tcall, MakeDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2897 } /*SRXAFS_MakeDir*/
2901 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
2902 * merged into it when possible.
2904 SAFSS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync)
2905 struct rx_connection *tcon; /* Rx connection handle */
2906 struct AFSFid *DirFid; /* Parent dir's fid */
2907 char *Name; /* (Empty) dir's name to be removed */
2908 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
2909 struct AFSVolSync *Sync;
2912 Vnode * parentptr = 0; /* vnode of input Directory */
2913 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2914 Vnode * targetptr = 0; /* file to be deleted */
2915 AFSFid fileFid; /* area for Fid from the directory */
2916 int errorCode = 0; /* error code */
2917 DirHandle dir; /* Handle for dir package I/O */
2918 Volume * volptr = 0; /* pointer to the volume header */
2919 struct client * client; /* pointer to client structure */
2920 afs_int32 rights, anyrights; /* rights for this and any user */
2921 Vnode debugvnode1, debugvnode2;
2922 struct client *t_client; /* tmp ptr to client data */
2923 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2925 /* Get ptr to client data for user Id for logging */
2926 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2927 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2928 ViceLog(1, ("SAFS_RemoveDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
2929 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2930 inet_ntoa(logHostAddr), t_client->ViceId));
2932 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
2935 * Get the vnode and volume for the parent dir along with the caller's
2938 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2939 MustBeDIR, &parentwhentargetnotdir,
2940 &client, WRITE_LOCK, &rights, &anyrights)) {
2943 debugvnode1 = *parentptr;
2945 /* set volume synchronization information */
2946 SetVolumeSync(Sync, volptr);
2948 /* Does the caller has delete (&write) access to the parent dir? */
2949 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
2953 debugvnode2 = *parentptr;
2954 /* Do the actual delete of the desired (empty) directory, Name */
2955 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid,
2960 /* Update the status for the parent dir; link count is also adjusted */
2961 #if FS_STATS_DETAILED
2962 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2963 parentptr->disk.linkCount-1, client->InSameNetwork);
2965 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2966 parentptr->disk.linkCount-1);
2967 #endif /* FS_STATS_DETAILED */
2969 /* Return to the caller the updated parent dir status */
2970 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
2973 * Note: it is not necessary to break the callback on fileFid, since
2974 * refcount is now 0, so no one should be able to refer to the dir
2977 DeleteFileCallBacks(&fileFid);
2979 /* convert the write lock to a read lock before breaking callbacks */
2980 VVnodeWriteToRead(&errorCode, parentptr);
2981 assert(!errorCode || errorCode == VSALVAGE);
2983 /* break call back on DirFid and fileFid */
2984 BreakCallBack(client->host, DirFid, 0);
2987 /* Write the all modified vnodes (parent, new files) and volume back */
2988 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2989 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
2992 } /*SAFSS_RemoveDir*/
2995 SRXAFS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync)
2996 struct AFSVolSync *Sync;
2997 struct rx_connection *tcon; /* Rx connection handle */
2998 struct AFSFid *DirFid; /* Parent dir's fid */
2999 char *Name; /* (Empty) dir's name to be removed */
3000 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
3004 struct rx_call *tcall = (struct rx_call *) tcon;
3005 #if FS_STATS_DETAILED
3006 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3007 struct timeval opStartTime,
3008 opStopTime; /* Start/stop times for RPC op*/
3009 struct timeval elapsedTime; /* Transfer time */
3012 * Set our stats pointer, remember when the RPC operation started, and
3013 * tally the operation.
3015 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
3019 TM_GetTimeOfDay(&opStartTime, 0);
3020 #endif /* FS_STATS_DETAILED */
3022 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3025 code = SAFSS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync);
3028 CallPostamble(tcon);
3030 #if FS_STATS_DETAILED
3031 TM_GetTimeOfDay(&opStopTime, 0);
3034 (opP->numSuccesses)++;
3035 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3036 fs_stats_AddTo((opP->sumTime), elapsedTime);
3037 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3038 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3039 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3041 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3042 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3047 #endif /* FS_STATS_DETAILED */
3049 osi_auditU (tcall, RemoveDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3052 } /*SRXAFS_RemoveDir*/
3056 * This routine is called exclusively by SRXAFS_SetLock(), and should be
3057 * merged into it when possible.
3059 SAFSS_SetLock (tcon, Fid, type, Sync)
3060 struct rx_connection *tcon; /* Rx connection handle */
3061 struct AFSFid *Fid; /* Fid of file to lock */
3062 ViceLockType type; /* Type of lock (Read or write) */
3063 struct AFSVolSync *Sync;
3066 Vnode * targetptr = 0; /* vnode of input file */
3067 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3068 int errorCode = 0; /* error code */
3069 Volume * volptr = 0; /* pointer to the volume header */
3070 struct client * client; /* pointer to client structure */
3071 afs_int32 rights, anyrights; /* rights for this and any user */
3072 struct client *t_client; /* tmp ptr to client data */
3073 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3074 static char * locktype[2] = {"LockRead","LockWrite"};
3076 if (type != LockRead && type != LockWrite) {
3080 /* Get ptr to client data for user Id for logging */
3081 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3082 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3083 ViceLog(1,("SAFS_SetLock type = %s Fid = %u.%d.%d, Host %s, Id %d\n",
3084 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
3085 inet_ntoa(logHostAddr), t_client->ViceId));
3087 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
3091 * Get the vnode and volume for the desired file along with the caller's
3094 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3095 DONTCHECK, &parentwhentargetnotdir,
3096 &client, WRITE_LOCK, &rights, &anyrights)) {
3100 /* set volume synchronization information */
3101 SetVolumeSync(Sync, volptr);
3103 /* Handle the particular type of set locking, type */
3104 errorCode = HandleLocking(targetptr, rights, type);
3107 /* Write the all modified vnodes (parent, new files) and volume back */
3108 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3110 if ((errorCode == VREADONLY) && (type == LockRead))
3111 errorCode = 0; /* allow read locks on RO volumes without saving state */
3113 ViceLog(2,("SAFS_SetLock returns %d\n", errorCode));
3119 SRXAFS_OldSetLock(tcon, Fid, type, Sync)
3120 struct AFSVolSync *Sync;
3121 struct rx_connection *tcon; /* Rx connection handle */
3122 struct AFSFid *Fid; /* Fid of file to lock */
3123 ViceLockType type; /* Type of lock (Read or write) */
3126 return SRXAFS_SetLock(tcon, Fid, type, Sync);
3128 } /*SRXAFS_OldSetLock*/
3131 SRXAFS_SetLock (tcon, Fid, type, Sync)
3132 struct AFSVolSync *Sync;
3133 struct rx_connection *tcon; /* Rx connection handle */
3134 struct AFSFid *Fid; /* Fid of file to lock */
3135 ViceLockType type; /* Type of lock (Read or write) */
3139 struct rx_call *tcall = (struct rx_call *) tcon;
3140 #if FS_STATS_DETAILED
3141 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3142 struct timeval opStartTime,
3143 opStopTime; /* Start/stop times for RPC op*/
3144 struct timeval elapsedTime; /* Transfer time */
3147 * Set our stats pointer, remember when the RPC operation started, and
3148 * tally the operation.
3150 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
3154 TM_GetTimeOfDay(&opStartTime, 0);
3155 #endif /* FS_STATS_DETAILED */
3157 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3160 code = SAFSS_SetLock (tcon, Fid, type, Sync);
3163 CallPostamble(tcon);
3165 #if FS_STATS_DETAILED
3166 TM_GetTimeOfDay(&opStopTime, 0);
3169 (opP->numSuccesses)++;
3170 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3171 fs_stats_AddTo((opP->sumTime), elapsedTime);
3172 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3173 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3174 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3176 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3177 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3181 #endif /* FS_STATS_DETAILED */
3183 osi_auditU (tcall, SetLockEvent, code, AUD_FID, Fid, AUD_LONG, type, AUD_END);
3186 } /*SRXAFS_SetLock*/
3190 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
3191 * merged into it when possible.
3193 SAFSS_ExtendLock (tcon, Fid, Sync)
3194 struct rx_connection *tcon; /* Rx connection handle */
3195 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3196 struct AFSVolSync *Sync;
3199 Vnode * targetptr = 0; /* vnode of input file */
3200 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3201 int errorCode = 0; /* error code */
3202 Volume * volptr = 0; /* pointer to the volume header */
3203 struct client * client; /* pointer to client structure */
3204 afs_int32 rights, anyrights; /* rights for this and any user */
3205 struct client *t_client; /* tmp ptr to client data */
3206 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3208 /* Get ptr to client data for user Id for logging */
3209 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3210 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3211 ViceLog(1,("SAFS_ExtendLock Fid = %u.%d.%d, Host %s, Id %d\n",
3212 Fid->Volume, Fid->Vnode, Fid->Unique,
3213 inet_ntoa(logHostAddr), t_client->ViceId));
3215 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
3218 * Get the vnode and volume for the desired file along with the caller's
3221 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3222 DONTCHECK, &parentwhentargetnotdir,
3223 &client, WRITE_LOCK, &rights, &anyrights)) {
3224 goto Bad_ExtendLock;
3227 /* set volume synchronization information */
3228 SetVolumeSync(Sync, volptr);
3230 /* Handle the actual lock extension */
3231 errorCode = HandleLocking(targetptr, rights, LockExtend);
3234 /* Put back file's vnode and volume */
3235 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3237 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3238 errorCode = 0; /* under our generous policy re RO vols */
3240 ViceLog(2,("SAFS_ExtendLock returns %d\n", errorCode));
3243 } /*SAFSS_ExtendLock*/
3246 SRXAFS_OldExtendLock (tcon, Fid, Sync)
3247 struct AFSVolSync *Sync;
3248 struct rx_connection *tcon; /* Rx connection handle */
3249 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3252 return SRXAFS_ExtendLock(tcon, Fid, Sync);
3254 } /*SRXAFS_OldExtendLock*/
3257 SRXAFS_ExtendLock (tcon, Fid, Sync)
3258 struct AFSVolSync *Sync;
3259 struct rx_connection *tcon; /* Rx connection handle */
3260 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3264 struct rx_call *tcall = (struct rx_call *) tcon;
3265 #if FS_STATS_DETAILED
3266 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3267 struct timeval opStartTime,
3268 opStopTime; /* Start/stop times for RPC op*/
3269 struct timeval elapsedTime; /* Transfer time */
3272 * Set our stats pointer, remember when the RPC operation started, and
3273 * tally the operation.
3275 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
3279 TM_GetTimeOfDay(&opStartTime, 0);
3280 #endif /* FS_STATS_DETAILED */
3282 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3283 goto Bad_ExtendLock;
3285 code = SAFSS_ExtendLock (tcon, Fid, Sync);
3288 CallPostamble(tcon);
3290 #if FS_STATS_DETAILED
3291 TM_GetTimeOfDay(&opStopTime, 0);
3294 (opP->numSuccesses)++;
3295 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3296 fs_stats_AddTo((opP->sumTime), elapsedTime);
3297 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3298 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3299 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3301 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3302 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3307 #endif /* FS_STATS_DETAILED */
3309 osi_auditU (tcall, ExtendLockEvent, code, AUD_FID, Fid , AUD_END);
3312 } /*SRXAFS_ExtendLock*/
3316 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
3317 * merged into it when possible.
3319 SAFSS_ReleaseLock (tcon, Fid, Sync)
3320 struct rx_connection *tcon; /* Rx connection handle */
3321 struct AFSFid *Fid; /* Fid of file to release lock */
3322 struct AFSVolSync *Sync;
3325 Vnode * targetptr = 0; /* vnode of input file */
3326 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3327 int errorCode = 0; /* error code */
3328 Volume * volptr = 0; /* pointer to the volume header */
3329 struct client * client; /* pointer to client structure */
3330 afs_int32 rights, anyrights; /* rights for this and any user */
3331 struct client *t_client; /* tmp ptr to client data */
3332 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3334 /* Get ptr to client data for user Id for logging */
3335 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3336 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3337 ViceLog(1,("SAFS_ReleaseLock Fid = %u.%d.%d, Host %s, Id %d\n",
3338 Fid->Volume, Fid->Vnode, Fid->Unique,
3339 inet_ntoa(logHostAddr), t_client->ViceId));
3341 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
3344 * Get the vnode and volume for the desired file along with the caller's
3347 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3348 DONTCHECK, &parentwhentargetnotdir,
3349 &client, WRITE_LOCK, &rights, &anyrights)) {
3350 goto Bad_ReleaseLock;
3353 /* set volume synchronization information */
3354 SetVolumeSync(Sync, volptr);
3356 /* Handle the actual lock release */
3357 if (errorCode = HandleLocking(targetptr, rights, LockRelease))
3358 goto Bad_ReleaseLock;
3360 /* if no more locks left, a callback would be triggered here */
3361 if (targetptr->disk.lock.lockCount <= 0) {
3362 /* convert the write lock to a read lock before breaking callbacks */
3363 VVnodeWriteToRead(&errorCode, targetptr);
3364 assert(!errorCode || errorCode == VSALVAGE);
3365 BreakCallBack(client->host, Fid, 0);
3369 /* Put back file's vnode and volume */
3370 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3372 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3373 errorCode = 0; /* under our generous policy re RO vols */
3375 ViceLog(2,("SAFS_ReleaseLock returns %d\n", errorCode));
3378 } /*SAFSS_ReleaseLock*/
3381 SRXAFS_OldReleaseLock (tcon, Fid, Sync)
3382 struct AFSVolSync *Sync;
3383 struct rx_connection *tcon; /* Rx connection handle */
3384 struct AFSFid *Fid; /* Fid of file to release lock */
3387 return SRXAFS_ReleaseLock(tcon, Fid, Sync);
3389 } /*SRXAFS_OldReleaseLock*/
3392 SRXAFS_ReleaseLock (tcon, Fid, Sync)
3393 struct AFSVolSync *Sync;
3394 struct rx_connection *tcon; /* Rx connection handle */
3395 struct AFSFid *Fid; /* Fid of file to release lock */
3399 struct rx_call *tcall = (struct rx_call *) tcon;
3400 #if FS_STATS_DETAILED
3401 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3402 struct timeval opStartTime,
3403 opStopTime; /* Start/stop times for RPC op*/
3404 struct timeval elapsedTime; /* Transfer time */
3407 * Set our stats pointer, remember when the RPC operation started, and
3408 * tally the operation.
3410 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
3414 TM_GetTimeOfDay(&opStartTime, 0);
3415 #endif /* FS_STATS_DETAILED */
3417 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3418 goto Bad_ReleaseLock;
3420 code = SAFSS_ReleaseLock (tcon, Fid, Sync);
3423 CallPostamble(tcon);
3425 #if FS_STATS_DETAILED
3426 TM_GetTimeOfDay(&opStopTime, 0);
3429 (opP->numSuccesses)++;
3430 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3431 fs_stats_AddTo((opP->sumTime), elapsedTime);
3432 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3433 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3434 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3436 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3437 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3442 #endif /* FS_STATS_DETAILED */
3444 osi_auditU (tcall, ReleaseLockEvent, code, AUD_FID, Fid , AUD_END);
3447 } /*SRXAFS_ReleaseLock*/
3451 * This routine is called exclusively by SRXAFS_GetStatistics(), and should be
3452 * merged into it when possible.
3454 static GetStatistics (tcon, Statistics)
3455 struct rx_connection *tcon; /* Rx connection handle */
3456 struct AFSStatistics *Statistics; /* Placeholder for returned AFS statistics */
3458 ViceLog(1, ("SAFS_GetStatistics Received\n"));
3460 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
3462 bzero(Statistics, sizeof(*Statistics));
3463 SetAFSStats(Statistics);
3464 SetVolumeStats(Statistics);
3465 SetSystemStats(Statistics);
3472 SRXAFS_GetStatistics (tcon, Statistics)
3473 struct rx_connection *tcon; /* Rx connection handle */
3474 struct AFSStatistics *Statistics; /* Placeholder for returned AFS statistics */
3478 #if FS_STATS_DETAILED
3479 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3480 struct timeval opStartTime,
3481 opStopTime; /* Start/stop times for RPC op*/
3482 struct timeval elapsedTime; /* Transfer time */
3485 * Set our stats pointer, remember when the RPC operation started, and
3486 * tally the operation.
3488 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
3492 TM_GetTimeOfDay(&opStartTime, 0);
3493 #endif /* FS_STATS_DETAILED */
3495 if (code = CallPreamble((struct rx_call **) &tcon, NOTACTIVECALL))
3496 goto Bad_GetStatistics;
3498 code = GetStatistics (tcon, Statistics);
3501 CallPostamble(tcon);
3503 #if FS_STATS_DETAILED
3504 TM_GetTimeOfDay(&opStopTime, 0);
3507 (opP->numSuccesses)++;
3508 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3509 fs_stats_AddTo((opP->sumTime), elapsedTime);
3510 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3511 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3512 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3514 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3515 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3519 #endif /* FS_STATS_DETAILED */
3523 } /*SRXAFS_GetStatistics*/
3526 /*------------------------------------------------------------------------
3527 * EXPORTED SRXAFS_XStatsVersion
3530 * Routine called by the server-side RPC interface to implement
3531 * pulling out the xstat version number for the File Server.
3534 * a_versionP : Ptr to the version number variable to set.
3540 * Nothing interesting.
3544 *------------------------------------------------------------------------*/
3546 int SRXAFS_XStatsVersion(a_call, a_versionP)
3547 struct rx_call *a_call;
3548 afs_int32 *a_versionP;
3550 { /*SRXAFS_XStatsVersion*/
3552 #if FS_STATS_DETAILED
3553 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3554 struct timeval opStartTime,
3555 opStopTime; /* Start/stop times for RPC op*/
3556 struct timeval elapsedTime; /* Transfer time */
3559 * Set our stats pointer, remember when the RPC operation started, and
3560 * tally the operation.
3562 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
3566 TM_GetTimeOfDay(&opStartTime, 0);
3567 #endif /* FS_STATS_DETAILED */
3569 *a_versionP = AFS_XSTAT_VERSION;
3571 #if FS_STATS_DETAILED
3572 TM_GetTimeOfDay(&opStopTime, 0);
3573 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3574 fs_stats_AddTo((opP->sumTime), elapsedTime);
3575 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3576 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3577 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3579 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3580 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3583 (opP->numSuccesses)++;
3585 #endif /* FS_STATS_DETAILED */
3589 } /*SRXAFS_XStatsVersion*/
3592 /*------------------------------------------------------------------------
3593 * PRIVATE FillPerfValues
3596 * Routine called to fill a regular performance data structure.
3599 * a_perfP : Ptr to perf structure to fill
3605 * Various collections need this info, so the guts were put in
3606 * this separate routine.
3610 *------------------------------------------------------------------------*/
3612 static void FillPerfValues(a_perfP)
3613 struct afs_PerfStats *a_perfP;
3615 { /*FillPerfValues*/
3617 int dir_Buffers; /*# buffers in use by dir package*/
3618 int dir_Calls; /*# read calls in dir package*/
3619 int dir_IOs; /*# I/O ops in dir package*/
3622 * Vnode cache section.
3624 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
3625 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
3626 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
3627 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
3628 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
3629 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
3630 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
3631 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
3632 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
3633 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
3634 a_perfP->vcache_H_Entries = VolumeCacheSize;
3635 a_perfP->vcache_H_Gets = VolumeGets;
3636 a_perfP->vcache_H_Replacements = VolumeReplacements;
3639 * Directory section.
3641 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
3642 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
3643 a_perfP->dir_Calls = (afs_int32 )dir_Calls;
3644 a_perfP->dir_IOs = (afs_int32) dir_IOs;
3649 a_perfP->rx_packetRequests =
3650 (afs_int32) rx_stats.packetRequests;
3651 a_perfP->rx_noPackets_RcvClass =
3652 (afs_int32) rx_stats.receivePktAllocFailures;
3653 a_perfP->rx_noPackets_SendClass =
3654 (afs_int32) rx_stats.sendPktAllocFailures;
3655 a_perfP->rx_noPackets_SpecialClass =
3656 (afs_int32) rx_stats.specialPktAllocFailures;
3657 a_perfP->rx_socketGreedy =
3658 (afs_int32) rx_stats.socketGreedy;
3659 a_perfP->rx_bogusPacketOnRead =
3660 (afs_int32) rx_stats.bogusPacketOnRead;
3661 a_perfP->rx_bogusHost =
3662 (afs_int32) rx_stats.bogusHost;
3663 a_perfP->rx_noPacketOnRead =
3664 (afs_int32) rx_stats.noPacketOnRead;
3665 a_perfP->rx_noPacketBuffersOnRead =
3666 (afs_int32) rx_stats.noPacketBuffersOnRead;
3667 a_perfP->rx_selects =
3668 (afs_int32) rx_stats.selects;
3669 a_perfP->rx_sendSelects =
3670 (afs_int32) rx_stats.sendSelects;
3671 a_perfP->rx_packetsRead_RcvClass =
3672 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
3673 a_perfP->rx_packetsRead_SendClass =
3674 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
3675 a_perfP->rx_packetsRead_SpecialClass =
3676 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
3677 a_perfP->rx_dataPacketsRead =
3678 (afs_int32) rx_stats.dataPacketsRead;
3679 a_perfP->rx_ackPacketsRead =
3680 (afs_int32) rx_stats.ackPacketsRead;
3681 a_perfP->rx_dupPacketsRead =
3682 (afs_int32) rx_stats.dupPacketsRead;
3683 a_perfP->rx_spuriousPacketsRead =
3684 (afs_int32) rx_stats.spuriousPacketsRead;
3685 a_perfP->rx_packetsSent_RcvClass =
3686 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
3687 a_perfP->rx_packetsSent_SendClass =
3688 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
3689 a_perfP->rx_packetsSent_SpecialClass =
3690 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
3691 a_perfP->rx_ackPacketsSent =
3692 (afs_int32) rx_stats.ackPacketsSent;
3693 a_perfP->rx_pingPacketsSent =
3694 (afs_int32) rx_stats.pingPacketsSent;
3695 a_perfP->rx_abortPacketsSent =
3696 (afs_int32) rx_stats.abortPacketsSent;
3697 a_perfP->rx_busyPacketsSent =
3698 (afs_int32) rx_stats.busyPacketsSent;
3699 a_perfP->rx_dataPacketsSent =
3700 (afs_int32) rx_stats.dataPacketsSent;
3701 a_perfP->rx_dataPacketsReSent =
3702 (afs_int32) rx_stats.dataPacketsReSent;
3703 a_perfP->rx_dataPacketsPushed =
3704 (afs_int32) rx_stats.dataPacketsPushed;
3705 a_perfP->rx_ignoreAckedPacket =
3706 (afs_int32) rx_stats.ignoreAckedPacket;
3707 a_perfP->rx_totalRtt_Sec =
3708 (afs_int32) rx_stats.totalRtt.sec;
3709 a_perfP->rx_totalRtt_Usec =
3710 (afs_int32) rx_stats.totalRtt.usec;
3711 a_perfP->rx_minRtt_Sec =
3712 (afs_int32) rx_stats.minRtt.sec;
3713 a_perfP->rx_minRtt_Usec =
3714 (afs_int32) rx_stats.minRtt.usec;
3715 a_perfP->rx_maxRtt_Sec =
3716 (afs_int32) rx_stats.maxRtt.sec;
3717 a_perfP->rx_maxRtt_Usec =
3718 (afs_int32) rx_stats.maxRtt.usec;
3719 a_perfP->rx_nRttSamples =
3720 (afs_int32) rx_stats.nRttSamples;
3721 a_perfP->rx_nServerConns =
3722 (afs_int32) rx_stats.nServerConns;
3723 a_perfP->rx_nClientConns =
3724 (afs_int32) rx_stats.nClientConns;
3725 a_perfP->rx_nPeerStructs =
3726 (afs_int32) rx_stats.nPeerStructs;
3727 a_perfP->rx_nCallStructs =
3728 (afs_int32) rx_stats.nCallStructs;
3729 a_perfP->rx_nFreeCallStructs =
3730 (afs_int32) rx_stats.nFreeCallStructs;
3732 a_perfP->host_NumHostEntries = HTs;
3733 a_perfP->host_HostBlocks = HTBlocks;
3734 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
3735 &(a_perfP->host_HostsInSameNetOrSubnet),
3736 &(a_perfP->host_HostsInDiffSubnet),
3737 &(a_perfP->host_HostsInDiffNetwork));
3738 a_perfP->host_NumClients = CEs;
3739 a_perfP->host_ClientBlocks = CEBlocks;
3741 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
3743 } /*FillPerfValues*/
3746 /*------------------------------------------------------------------------
3747 * EXPORTED SRXAFS_GetXStats
3750 * Routine called by the server-side callback RPC interface to
3751 * implement getting the given data collection from the extended
3752 * File Server statistics.
3755 * a_call : Ptr to Rx call on which this request came in.
3756 * a_clientVersionNum : Client version number.
3757 * a_opCode : Desired operation.
3758 * a_serverVersionNumP : Ptr to version number to set.
3759 * a_timeP : Ptr to time value (seconds) to set.
3760 * a_dataP : Ptr to variable array structure to return
3767 * Nothing interesting.
3771 *------------------------------------------------------------------------*/
3773 int SRXAFS_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVersionNumP, a_timeP, a_dataP)
3774 struct rx_call *a_call;
3775 afs_int32 a_clientVersionNum;
3776 afs_int32 a_collectionNumber;
3777 afs_int32 *a_srvVersionNumP;
3779 AFS_CollData *a_dataP;
3781 { /*SRXAFS_GetXStats*/
3783 register int code; /*Return value*/
3784 afs_int32 *dataBuffP; /*Ptr to data to be returned*/
3785 afs_int32 dataBytes; /*Bytes in data buffer*/
3786 #if FS_STATS_DETAILED
3787 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3788 struct timeval opStartTime,
3789 opStopTime; /* Start/stop times for RPC op*/
3790 struct timeval elapsedTime; /* Transfer time */
3793 * Set our stats pointer, remember when the RPC operation started, and
3794 * tally the operation.
3796 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
3800 TM_GetTimeOfDay(&opStartTime, 0);
3801 #endif /* FS_STATS_DETAILED */
3804 * Record the time of day and the server version number.
3806 *a_srvVersionNumP = AFS_XSTAT_VERSION;
3807 *a_timeP = FT_ApproxTime();
3810 * Stuff the appropriate data in there (assume victory)
3814 ViceLog(1, ("Received GetXStats call for collection %d\n", a_collectionNumber));
3818 * We're not keeping stats, so just return successfully with
3821 a_dataP->AFS_CollData_len = 0;
3822 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3825 switch(a_collectionNumber) {
3826 case AFS_XSTATSCOLL_CALL_INFO:
3828 * Pass back all the call-count-related data.
3830 * >>> We are forced to allocate a separate area in which to
3831 * >>> put this stuff in by the RPC stub generator, since it
3832 * >>> will be freed at the tail end of the server stub code.
3836 * I don't think call-level stats are being collected yet
3837 * for the File Server.
3839 dataBytes = sizeof(struct afs_Stats);
3840 dataBuffP = (afs_int32 *)malloc(dataBytes);
3841 bcopy(&afs_cmstats, dataBuffP, dataBytes);
3842 a_dataP->AFS_CollData_len = dataBytes>>2;
3843 a_dataP->AFS_CollData_val = dataBuffP;
3845 a_dataP->AFS_CollData_len = 0;
3846 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3850 case AFS_XSTATSCOLL_PERF_INFO:
3852 * Pass back all the regular performance-related data.
3854 * >>> We are forced to allocate a separate area in which to
3855 * >>> put this stuff in by the RPC stub generator, since it
3856 * >>> will be freed at the tail end of the server stub code.
3859 afs_perfstats.numPerfCalls++;
3860 FillPerfValues(&afs_perfstats);
3863 * Don't overwrite the spares at the end.
3866 dataBytes = sizeof(struct afs_PerfStats);
3867 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
3868 bcopy(&afs_perfstats, dataBuffP, dataBytes);
3869 a_dataP->AFS_CollData_len = dataBytes>>2;
3870 a_dataP->AFS_CollData_val = dataBuffP;
3873 case AFS_XSTATSCOLL_FULL_PERF_INFO:
3875 * Pass back the full collection of performance-related data.
3876 * We have to stuff the basic, overall numbers in, but the
3877 * detailed numbers are kept in the structure already.
3879 * >>> We are forced to allocate a separate area in which to
3880 * >>> put this stuff in by the RPC stub generator, since it
3881 * >>> will be freed at the tail end of the server stub code.
3884 afs_perfstats.numPerfCalls++;
3885 #if FS_STATS_DETAILED
3886 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
3887 FillPerfValues(&afs_FullPerfStats.overall);
3890 * Don't overwrite the spares at the end.
3893 dataBytes = sizeof(struct fs_stats_FullPerfStats);
3894 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
3895 bcopy(&afs_FullPerfStats, dataBuffP, dataBytes);
3896 a_dataP->AFS_CollData_len = dataBytes>>2;
3897 a_dataP->AFS_CollData_val = dataBuffP;
3903 * Illegal collection number.
3905 a_dataP->AFS_CollData_len = 0;
3906 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3908 } /*Switch on collection number*/
3910 #if FS_STATS_DETAILED
3911 TM_GetTimeOfDay(&opStopTime, 0);
3914 (opP->numSuccesses)++;
3915 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3916 fs_stats_AddTo((opP->sumTime), elapsedTime);
3917 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3918 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3919 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3921 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3922 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3927 #endif /* FS_STATS_DETAILED */
3931 } /*SRXAFS_GetXStats*/
3934 SRXAFS_GiveUpCallBacks (tcon, FidArray, CallBackArray)
3935 struct rx_connection *tcon; /* Rx connection handle */
3936 struct AFSCBFids *FidArray; /* Array of Fids entries */
3937 struct AFSCBs *CallBackArray; /* array of callbacks */
3940 afs_int32 errorCode;
3942 struct client *client;
3943 #if FS_STATS_DETAILED
3944 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3945 struct timeval opStartTime,
3946 opStopTime; /* Start/stop times for RPC op*/
3947 struct timeval elapsedTime; /* Transfer time */
3950 * Set our stats pointer, remember when the RPC operation started, and
3951 * tally the operation.
3953 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
3957 TM_GetTimeOfDay(&opStartTime, 0);
3958 #endif /* FS_STATS_DETAILED */
3960 ViceLog(1, ("SAFS_GiveUpCallBacks (Noffids=%d)\n", FidArray->AFSCBFids_len));
3962 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
3964 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3965 goto Bad_GiveUpCallBacks;
3967 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
3968 ViceLog(0, ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
3969 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
3970 (tcon->peer ? tcon->peer->host : 0)));
3972 goto Bad_GiveUpCallBacks;
3975 errorCode = GetClient(tcon, &client);
3977 for (i=0; i < FidArray->AFSCBFids_len; i++) {
3978 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
3979 DeleteCallBack(client->host, fid);
3983 Bad_GiveUpCallBacks:
3984 CallPostamble(tcon);
3986 #if FS_STATS_DETAILED
3987 TM_GetTimeOfDay(&opStopTime, 0);
3988 if (errorCode == 0) {
3990 (opP->numSuccesses)++;
3991 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3992 fs_stats_AddTo((opP->sumTime), elapsedTime);
3993 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3994 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3995 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3997 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3998 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4002 #endif /* FS_STATS_DETAILED */
4006 } /*SRXAFS_GiveUpCallBacks*/
4009 SRXAFS_NGetVolumeInfo (tcon, avolid, avolinfo)
4010 struct rx_connection *tcon; /* Rx connection handle */
4011 char *avolid; /* Volume name/id */
4012 struct AFSVolumeInfo *avolinfo; /* Returned volume's specific info */
4015 return(VNOVOL); /* XXX Obsolete routine XXX */
4017 } /*SRXAFS_NGetVolumeInfo*/
4021 * Dummy routine. Should never be called (the cache manager should only
4022 * invoke this interface when communicating with a AFS/DFS Protocol
4025 SRXAFS_Lookup(call_p, afs_dfid_p, afs_name_p, afs_fid_p,
4026 afs_status_p, afs_dir_status_p, afs_callback_p, afs_sync_p)
4027 struct rx_call *call_p; /* Rx call handle */
4028 struct AFSFid *afs_dfid_p; /* Directory */
4029 char *afs_name_p; /* Name of file to lookup */
4030 struct AFSFid *afs_fid_p; /* Place to return fid of file */
4031 struct AFSFetchStatus *afs_status_p; /* Place to return file status */
4032 struct AFSFetchStatus *afs_dir_status_p;/* Place to return file status */
4033 struct AFSCallBack *afs_callback_p; /* If r/w, callback promise for Fid */
4034 struct AFSVolSync *afs_sync_p; /* Volume sync info */
4040 SRXAFS_FlushCPS(tcon, vids, addrs, spare1, spare2, spare3)
4041 struct rx_connection *tcon;
4042 struct ViceIds *vids;
4043 struct IPAddrs *addrs;
4044 afs_int32 spare1, *spare2, *spare3;
4047 afs_int32 nids, naddrs;
4048 afs_int32 *vd, *addr;
4049 int errorCode = 0; /* return code to caller */
4050 struct client *client;
4051 struct rx_call *tcall = (struct rx_call *) tcon;
4053 ViceLog(1, ("SRXAFS_FlushCPS\n"));
4055 AFSCallStats.TotalCalls++;
4057 nids = vids->ViceIds_len; /* # of users in here */
4058 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
4059 if (nids < 0 || naddrs < 0) {
4064 vd = vids->ViceIds_val;
4065 for (i=0; i<nids; i++, vd++) {
4068 client = h_ID2Client(*vd); /* returns client locked, or NULL */
4072 BoostSharedLock(&client->lock);
4073 client->prfail = 2; /* Means re-eval client's cps */
4076 rx_SetRock(((struct rx_connection *) client->tcon), 0);
4079 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
4080 free(client->CPS.prlist_val);
4081 client->CPS.prlist_val = (afs_int32 *)0;
4083 ReleaseWriteLock(&client->lock);
4086 addr = addrs->IPAddrs_val;
4087 for (i=0; i<naddrs; i++, addr++) {
4089 h_flushhostcps(*addr, 7001);
4093 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
4095 } /*SRXAFS_FlushCPS */
4099 static GetVolumeInfo (tcon, avolid, avolinfo)
4100 struct rx_connection *tcon; /* Rx Connection handle */
4101 char *avolid; /* Volume name/id */
4102 struct VolumeInfo *avolinfo; /* Returned volume's specific info */
4105 int errorCode = 0; /* error code */
4108 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
4111 errorCode = TryLocalVLServer(avolid, avolinfo);
4112 ViceLog(1, ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
4113 errorCode, avolinfo->Vid, avolinfo->Type,
4114 avolinfo->Server0, avolinfo->Server1, avolinfo->Server2,
4115 avolinfo->Server3));
4120 /* worthless hack to let CS keep running ancient software */
4121 static afs_vtoi(aname)
4122 register char *aname;
4125 register afs_int32 temp;
4129 while(tc = *aname++) {
4130 if (tc > '9' || tc < '0') return 0; /* invalid name */
4138 * may get name or #, but must handle all weird cases (recognize readonly
4139 * or backup volumes by name or #
4141 static CopyVolumeEntry(aname, ave, av)
4143 register struct VolumeInfo *av;
4144 register struct vldbentry *ave;
4147 register int i, j, vol;
4148 afs_int32 mask, whichType;
4149 afs_uint32 *serverHost, *typePtr;
4151 /* figure out what type we want if by name */
4153 if (i >= 8 && strcmp(aname+i-7, ".backup") == 0)
4154 whichType = BACKVOL;
4155 else if (i >= 10 && strcmp(aname+i-9, ".readonly")==0)
4157 else whichType = RWVOL;
4159 vol = afs_vtoi(aname);
4160 if (vol == 0) vol = ave->volumeId[whichType];