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)
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)
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));
323 h_ReleaseClient_r(tclient);
331 static CallPostamble(aconn)
332 register struct rx_connection *aconn;
336 struct client *tclient;
339 tclient = h_FindClient_r(aconn);
340 thost = tclient->host;
341 h_ReleaseClient_r(tclient);
348 #define AFSV_BUFFERSIZE 16384
350 static struct afs_buffer {
351 struct afs_buffer *next;
352 } *freeBufferList = 0;
353 static int afs_buffersAlloced = 0;
356 static FreeSendBuffer(adata)
357 register struct afs_buffer *adata;
361 afs_buffersAlloced--;
362 adata->next = freeBufferList;
363 freeBufferList = adata;
370 /* allocate space for sender */
371 static char *AllocSendBuffer()
374 register struct afs_buffer *tp;
377 afs_buffersAlloced++;
378 if (!freeBufferList) {
380 return malloc(AFSV_BUFFERSIZE);
383 freeBufferList = tp->next;
387 } /*AllocSendBuffer*/
390 static int VolumeOwner (client, targetptr)
391 register struct client *client;
392 register Vnode *targetptr;
395 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
398 return (client->ViceId == owner);
401 * We don't have to check for host's cps since only regular
402 * viceid are volume owners.
404 return (acl_IsAMember(owner, &client->CPS));
410 static int VolumeRootVnode (targetptr)
414 return ((targetptr->vnodeNumber == ROOTVNODE) &&
415 (targetptr->disk.uniquifier == 1));
417 } /*VolumeRootVnode*/
420 SRXAFS_FetchData (tcon, Fid, Pos, Len, OutStatus, CallBack, Sync)
421 struct rx_connection *tcon; /* Rx connection handle */
422 struct AFSFid *Fid; /* Fid of file to fetch */
423 afs_int32 Pos, Len; /* Not implemented yet */
424 struct AFSFetchStatus *OutStatus; /* Returned status for Fid */
425 struct AFSCallBack *CallBack; /* If r/w return CB for Fid */
426 struct AFSVolSync *Sync; /* synchronization info */
429 Vnode * targetptr = 0; /* pointer to vnode to fetch */
430 Vnode * parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
431 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
432 int errorCode = 0; /* return code to caller */
433 int fileCode = 0; /* return code from vol package */
434 Volume * volptr = 0; /* pointer to the volume */
435 struct client *client; /* pointer to the client data */
436 struct rx_call *tcall; /* the call we're a part of */
437 afs_int32 rights, anyrights; /* rights for this and any user */
438 struct client *t_client; /* tmp ptr to client data */
439 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
440 #if FS_STATS_DETAILED
441 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
442 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
443 struct timeval opStartTime,
444 opStopTime; /* Start/stop times for RPC op*/
445 struct timeval xferStartTime,
446 xferStopTime; /* Start/stop times for xfer portion*/
447 struct timeval elapsedTime; /* Transfer time */
448 afs_int32 bytesToXfer; /* # bytes to xfer*/
449 afs_int32 bytesXferred; /* # bytes actually xferred*/
450 int readIdx; /* Index of read stats array to bump*/
451 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
454 * Set our stats pointers, remember when the RPC operation started, and
455 * tally the operation.
457 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
458 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
462 TM_GetTimeOfDay(&opStartTime, 0);
463 #endif /* FS_STATS_DETAILED */
465 ViceLog(1,("SRXAFS_FetchData, Fid = %u.%d.%d\n",
466 Fid->Volume, Fid->Vnode, Fid->Unique));
468 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
471 /* CallPreamble changes tcon from a call to a conn */
472 tcall = (struct rx_call *) tcon;
473 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
476 /* Get ptr to client data for user Id for logging */
477 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
478 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
479 ViceLog(5,("SRXAFS_FetchData, Fid = %u.%d.%d, Host %s, Id %d\n",
480 Fid->Volume, Fid->Vnode, Fid->Unique,
481 inet_ntoa(logHostAddr), t_client->ViceId));
483 * Get volume/vnode for the fetched file; caller's access rights to
484 * it are also returned
486 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
487 DONTCHECK, &parentwhentargetnotdir,
488 &client, READ_LOCK, &rights, &anyrights))
491 SetVolumeSync(Sync, volptr);
493 #if FS_STATS_DETAILED
495 * Remember that another read operation was performed.
498 if (client->InSameNetwork)
499 readIdx = VOL_STATS_SAME_NET;
501 readIdx = VOL_STATS_DIFF_NET;
502 V_stat_reads(volptr, readIdx)++;
503 if (client->ViceId != AnonymousID) {
504 V_stat_reads(volptr, readIdx+1)++;
507 #endif /* FS_STATS_DETAILED */
509 /* Check whether the caller has permission access to fetch the data */
510 if (errorCode = Check_PermissionRights(targetptr, client, rights,
515 * Drop the read lock on the parent directory after saving the parent
516 * vnode information we need to pass to GetStatus
518 if (parentwhentargetnotdir != NULL) {
519 tparentwhentargetnotdir = *parentwhentargetnotdir;
520 VPutVnode(&fileCode, parentwhentargetnotdir);
521 assert(!fileCode || (fileCode == VSALVAGE));
522 parentwhentargetnotdir = NULL;
525 #if FS_STATS_DETAILED
527 * Remember when the data transfer started.
529 TM_GetTimeOfDay(&xferStartTime, 0);
530 #endif /* FS_STATS_DETAILED */
532 /* actually do the data transfer */
533 #if FS_STATS_DETAILED
534 errorCode = FetchData_RXStyle(volptr, targetptr, tcall, Pos, Len,
535 &bytesToXfer, &bytesXferred);
537 if (errorCode = FetchData_RXStyle(volptr, targetptr, tcall, Pos, Len))
539 #endif /* FS_STATS_DETAILED */
541 #if FS_STATS_DETAILED
543 * At this point, the data transfer is done, for good or ill. Remember
544 * when the transfer ended, bump the number of successes/failures, and
545 * integrate the transfer size and elapsed time into the stats. If the
546 * operation failed, we jump to the appropriate point.
548 TM_GetTimeOfDay(&xferStopTime, 0);
552 (xferP->numSuccesses)++;
555 * Bump the xfer sum by the number of bytes actually sent, NOT the
558 tot_bytesXferred += bytesXferred;
559 (xferP->sumBytes) += (tot_bytesXferred >> 10);
560 tot_bytesXferred &= 0x3FF;
561 if (bytesXferred < xferP->minBytes)
562 xferP->minBytes = bytesXferred;
563 if (bytesXferred > xferP->maxBytes)
564 xferP->maxBytes = bytesXferred;
567 * Tally the size of the object. Note: we tally the actual size,
568 * NOT the number of bytes that made it out over the wire.
570 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
573 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
576 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
579 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
582 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
585 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
588 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
591 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
596 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
597 fs_stats_AddTo((xferP->sumTime), elapsedTime);
598 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
599 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
600 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
602 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
603 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
608 * Finally, go off to tell our caller the bad news in case the
613 #endif /* FS_STATS_DETAILED */
615 /* write back the OutStatus from the target vnode */
616 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
618 /* if a r/w volume, promise a callback to the caller */
619 if (VolumeWriteable(volptr))
620 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
623 bzero(&myFid, sizeof(struct AFSFid));
624 myFid.Volume = Fid->Volume;
625 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
629 /* Update and store volume/vnode and parent vnodes back */
630 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
631 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
634 #if FS_STATS_DETAILED
635 TM_GetTimeOfDay(&opStopTime, 0);
636 if (errorCode == 0) {
638 (opP->numSuccesses)++;
639 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
640 fs_stats_AddTo((opP->sumTime), elapsedTime);
641 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
642 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
643 fs_stats_TimeAssign((opP->minTime), elapsedTime);
645 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
646 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
651 #endif /* FS_STATS_DETAILED */
653 osi_auditU (tcall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
656 } /*SRXAFS_FetchData*/
659 SRXAFS_FetchACL (tcon, Fid, AccessList, OutStatus, Sync)
660 struct AFSVolSync *Sync;
661 struct rx_connection *tcon; /* Rx connection handle */
662 struct AFSFid *Fid; /* Fid of target dir */
663 struct AFSOpaque *AccessList; /* Returned contents of dir's ACL */
664 struct AFSFetchStatus *OutStatus; /* Returned status for the dir */
667 Vnode * targetptr = 0; /* pointer to vnode to fetch */
668 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
669 int errorCode = 0; /* return error code to caller */
670 Volume * volptr = 0; /* pointer to the volume */
671 struct client *client; /* pointer to the client data */
672 afs_int32 rights, anyrights; /* rights for this and any user */
673 struct rx_call *tcall = (struct rx_call *) tcon;
674 struct client *t_client; /* tmp ptr to client data */
675 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
676 #if FS_STATS_DETAILED
677 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
678 struct timeval opStartTime,
679 opStopTime; /* Start/stop times for RPC op*/
680 struct timeval elapsedTime; /* Transfer time */
683 * Set our stats pointer, remember when the RPC operation started, and
684 * tally the operation.
686 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
690 TM_GetTimeOfDay(&opStartTime, 0);
691 #endif /* FS_STATS_DETAILED */
693 ViceLog(1, ("SAFS_FetchACL, Fid = %u.%d.%d\n",
694 Fid->Volume, Fid->Vnode, Fid->Unique));
696 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
698 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
701 /* Get ptr to client data for user Id for logging */
702 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
703 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
704 ViceLog(5, ("SAFS_FetchACL, Fid = %u.%d.%d, Host %s, Id %d\n",
705 Fid->Volume, Fid->Vnode, Fid->Unique,
706 inet_ntoa(logHostAddr), t_client->ViceId));
708 AccessList->AFSOpaque_len = 0;
709 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
712 * Get volume/vnode for the fetched file; caller's access rights to it
715 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
716 DONTCHECK, &parentwhentargetnotdir,
717 &client, READ_LOCK, &rights, &anyrights))
720 SetVolumeSync(Sync, volptr);
722 /* Check whether we have permission to fetch the ACL */
723 if (errorCode = Check_PermissionRights(targetptr, client, rights,
727 /* Get the Access List from the dir's vnode */
728 if (errorCode = RXFetch_AccessList(targetptr, parentwhentargetnotdir,
732 /* Get OutStatus back From the target Vnode */
733 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
736 /* Update and store volume/vnode and parent vnodes back */
737 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
738 ViceLog(2, ("SAFS_FetchACL returns %d (ACL=%s)\n",
739 errorCode, AccessList->AFSOpaque_val));
742 #if FS_STATS_DETAILED
743 TM_GetTimeOfDay(&opStopTime, 0);
744 if (errorCode == 0) {
746 (opP->numSuccesses)++;
747 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
748 fs_stats_AddTo((opP->sumTime), elapsedTime);
749 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
750 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
751 fs_stats_TimeAssign((opP->minTime), elapsedTime);
753 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
754 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
759 #endif /* FS_STATS_DETAILED */
761 osi_auditU (tcall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
764 } /*SRXAFS_FetchACL*/
768 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
769 * merged into it when possible.
771 SAFSS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync)
772 struct rx_connection *tcon; /* Rx connection handle */
773 struct AFSFid *Fid; /* Fid of target file */
774 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
775 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
776 struct AFSVolSync *Sync; /* volume synchronization parm */
779 Vnode * targetptr = 0; /* pointer to vnode to fetch */
780 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
781 int errorCode = 0; /* return code to caller */
782 Volume * volptr = 0; /* pointer to the volume */
783 struct client *client; /* pointer to the client data */
784 afs_int32 rights, anyrights; /* rights for this and any user */
785 struct client *t_client; /* tmp ptr to client data */
786 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
788 /* Get ptr to client data for user Id for logging */
789 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
790 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
791 ViceLog(1, ("SAFS_FetchStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
792 Fid->Volume, Fid->Vnode, Fid->Unique,
793 inet_ntoa(logHostAddr), t_client->ViceId));
795 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
798 * Get volume/vnode for the fetched file; caller's rights to it are
801 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
802 DONTCHECK, &parentwhentargetnotdir,
803 &client, READ_LOCK, &rights, &anyrights))
804 goto Bad_FetchStatus;
806 /* set volume synchronization information */
807 SetVolumeSync(Sync, volptr);
809 /* Are we allowed to fetch Fid's status? */
810 if (targetptr->disk.type != vDirectory) {
811 if (errorCode = Check_PermissionRights(targetptr, client, rights,
813 goto Bad_FetchStatus;
816 /* set OutStatus From the Fid */
817 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
819 /* If a r/w volume, also set the CallBack state */
820 if (VolumeWriteable(volptr))
821 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
824 bzero(&myFid, sizeof(struct AFSFid));
825 myFid.Volume = Fid->Volume;
826 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
830 /* Update and store volume/vnode and parent vnodes back */
831 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
832 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
835 } /*SAFSS_FetchStatus*/
838 SRXAFS_BulkStatus(tcon, Fids, OutStats, CallBacks, Sync)
839 struct rx_connection *tcon;
840 struct AFSCBFids *Fids;
841 struct AFSBulkStats *OutStats;
842 struct AFSCBs *CallBacks;
843 struct AFSVolSync *Sync;
848 Vnode * targetptr = 0; /* pointer to vnode to fetch */
849 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
850 int errorCode = 0; /* return code to caller */
851 Volume * volptr = 0; /* pointer to the volume */
852 struct client *client; /* pointer to the client data */
853 afs_int32 rights, anyrights; /* rights for this and any user */
854 register struct AFSFid *tfid; /* file id we're dealing with now */
855 struct rx_call *tcall = (struct rx_call *) tcon;
856 #if FS_STATS_DETAILED
857 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
858 struct timeval opStartTime,
859 opStopTime; /* Start/stop times for RPC op*/
860 struct timeval elapsedTime; /* Transfer time */
863 * Set our stats pointer, remember when the RPC operation started, and
864 * tally the operation.
866 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
870 TM_GetTimeOfDay(&opStartTime, 0);
871 #endif /* FS_STATS_DETAILED */
873 ViceLog(1, ("SAFS_BulkStatus\n"));
875 AFSCallStats.TotalCalls++;
878 nfiles = Fids->AFSCBFids_len; /* # of files in here */
879 if (nfiles <= 0) { /* Sanity check */
881 goto Audit_and_Return;
884 /* allocate space for return output parameters */
885 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
886 malloc(nfiles * sizeof(struct AFSFetchStatus));
887 OutStats->AFSBulkStats_len = nfiles;
888 CallBacks->AFSCBs_val = (struct AFSCallBack *)
889 malloc(nfiles * sizeof(struct AFSCallBack));
890 CallBacks->AFSCBs_len = nfiles;
892 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
895 tfid = Fids->AFSCBFids_val;
896 for (i=0; i<nfiles; i++, tfid++) {
898 * Get volume/vnode for the fetched file; caller's rights to it
902 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
903 DONTCHECK, &parentwhentargetnotdir, &client,
904 READ_LOCK, &rights, &anyrights))
906 /* set volume synchronization information, but only once per call */
908 SetVolumeSync(Sync, volptr);
910 /* Are we allowed to fetch Fid's status? */
911 if (targetptr->disk.type != vDirectory) {
912 if (errorCode = Check_PermissionRights(targetptr, client, rights,
917 /* set OutStatus From the Fid */
918 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i],
919 rights, anyrights, parentwhentargetnotdir);
921 /* If a r/w volume, also set the CallBack state */
922 if (VolumeWriteable(volptr))
923 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
924 &CallBacks->AFSCBs_val[i]);
927 bzero(&myFid, sizeof(struct AFSFid));
928 myFid.Volume = tfid->Volume;
929 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
930 &CallBacks->AFSCBs_val[i]);
933 /* put back the file ID and volume */
934 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
935 parentwhentargetnotdir = (Vnode *) 0;
936 targetptr = (Vnode *) 0;
937 volptr = (Volume *) 0;
941 /* Update and store volume/vnode and parent vnodes back */
942 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
945 #if FS_STATS_DETAILED
946 TM_GetTimeOfDay(&opStopTime, 0);
947 if (errorCode == 0) {
949 (opP->numSuccesses)++;
950 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
951 fs_stats_AddTo((opP->sumTime), elapsedTime);
952 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
953 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
954 fs_stats_TimeAssign((opP->minTime), elapsedTime);
956 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
957 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
962 #endif /* FS_STATS_DETAILED */
965 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
966 osi_auditU (tcall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
969 } /*SRXAFS_BulkStatus*/
972 SRXAFS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync)
973 struct AFSVolSync *Sync;
974 struct rx_connection *tcon; /* Rx connection handle */
975 struct AFSFid *Fid; /* Fid of target file */
976 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
977 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
981 struct rx_call *tcall = (struct rx_call *) tcon;
982 #if FS_STATS_DETAILED
983 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
984 struct timeval opStartTime,
985 opStopTime; /* Start/stop times for RPC op*/
986 struct timeval elapsedTime; /* Transfer time */
989 * Set our stats pointer, remember when the RPC operation started, and
990 * tally the operation.
992 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
996 TM_GetTimeOfDay(&opStartTime, 0);
997 #endif /* FS_STATS_DETAILED */
999 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1000 goto Bad_FetchStatus;
1002 code = SAFSS_FetchStatus (tcon, Fid, OutStatus, CallBack, Sync);
1005 CallPostamble(tcon);
1007 #if FS_STATS_DETAILED
1008 TM_GetTimeOfDay(&opStopTime, 0);
1011 (opP->numSuccesses)++;
1012 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1013 fs_stats_AddTo((opP->sumTime), elapsedTime);
1014 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1015 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1016 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1018 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1019 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1024 #endif /* FS_STATS_DETAILED */
1026 osi_auditU (tcall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
1029 } /*SRXAFS_FetchStatus*/
1032 SRXAFS_StoreData (tcon, Fid, InStatus, Pos, Length, FileLength, OutStatus, Sync)
1033 struct AFSVolSync *Sync;
1034 struct rx_connection *tcon; /* Rx connection Handle */
1035 struct AFSFid *Fid; /* Fid of taret file */
1036 struct AFSStoreStatus *InStatus; /* Input Status for Fid */
1037 afs_int32 Pos; /* Not implemented yet */
1038 afs_int32 Length; /* Length of data to store */
1039 afs_int32 FileLength; /* Length of file after store */
1040 struct AFSFetchStatus *OutStatus; /* Returned status for target fid */
1043 Vnode * targetptr = 0; /* pointer to input fid */
1044 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1045 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
1046 int errorCode = 0; /* return code for caller */
1047 int fileCode = 0; /* return code from vol package */
1048 Volume * volptr = 0; /* pointer to the volume header */
1049 struct client * client; /* pointer to client structure */
1050 struct rx_call *tcall; /* remember the call structure for ftp */
1051 afs_int32 rights, anyrights; /* rights for this and any user */
1052 struct client *t_client; /* tmp ptr to client data */
1053 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1054 #if FS_STATS_DETAILED
1055 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1056 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
1057 struct timeval opStartTime,
1058 opStopTime; /* Start/stop times for RPC op*/
1059 struct timeval xferStartTime,
1060 xferStopTime; /* Start/stop times for xfer portion*/
1061 struct timeval elapsedTime; /* Transfer time */
1062 afs_int32 bytesToXfer; /* # bytes to xfer */
1063 afs_int32 bytesXferred; /* # bytes actually xfer */
1064 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
1067 * Set our stats pointers, remember when the RPC operation started, and
1068 * tally the operation.
1070 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
1071 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
1076 ViceLog(1, ("StoreData: Fid = %u.%d.%d\n",
1077 Fid->Volume, Fid->Vnode, Fid->Unique));
1078 TM_GetTimeOfDay(&opStartTime, 0);
1079 #endif /* FS_STATS_DETAILED */
1082 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
1084 /* CallPreamble changes tcon from a call to a conn */
1085 tcall = (struct rx_call *) tcon;
1086 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1089 /* Get ptr to client data for user Id for logging */
1090 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1091 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1092 ViceLog(5, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d\n",
1093 Fid->Volume, Fid->Vnode, Fid->Unique,
1094 inet_ntoa(logHostAddr), t_client->ViceId));
1097 * Get associated volume/vnode for the stored file; caller's rights
1100 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1101 MustNOTBeDIR, &parentwhentargetnotdir,
1102 &client, WRITE_LOCK, &rights, &anyrights)) {
1106 /* set volume synchronization information */
1107 SetVolumeSync(Sync, volptr);
1109 if ((targetptr->disk.type == vSymlink)) {
1110 /* Should we return a better error code here??? */
1115 /* Check if we're allowed to store the data */
1116 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1117 CHK_STOREDATA, InStatus)) {
1122 * Drop the read lock on the parent directory after saving the parent
1123 * vnode information we need to pass to GetStatus
1125 if (parentwhentargetnotdir != NULL) {
1126 tparentwhentargetnotdir = *parentwhentargetnotdir;
1127 VPutVnode(&fileCode, parentwhentargetnotdir);
1128 assert(!fileCode || (fileCode == VSALVAGE));
1129 parentwhentargetnotdir = NULL;
1134 #if FS_STATS_DETAILED
1136 * Remember when the data transfer started.
1138 TM_GetTimeOfDay(&xferStartTime, 0);
1139 #endif /* FS_STATS_DETAILED */
1141 /* Do the actual storing of the data */
1142 #if FS_STATS_DETAILED
1143 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client, tcall,
1144 Pos, Length, FileLength,
1145 (InStatus->Mask & AFS_FSYNC),
1146 &bytesToXfer, &bytesXferred);
1148 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client,
1149 tcall, Pos, Length, FileLength,
1150 (InStatus->Mask & AFS_FSYNC));
1151 if (errorCode && (!targetptr->changed_newTime))
1153 #endif /* FS_STATS_DETAILED */
1154 #if FS_STATS_DETAILED
1156 * At this point, the data transfer is done, for good or ill. Remember
1157 * when the transfer ended, bump the number of successes/failures, and
1158 * integrate the transfer size and elapsed time into the stats. If the
1159 * operation failed, we jump to the appropriate point.
1161 TM_GetTimeOfDay(&xferStopTime, 0);
1163 (xferP->numXfers)++;
1165 (xferP->numSuccesses)++;
1168 * Bump the xfer sum by the number of bytes actually sent, NOT the
1171 tot_bytesXferred += bytesXferred;
1172 (xferP->sumBytes) += (tot_bytesXferred >> 10);
1173 tot_bytesXferred &= 0x3FF;
1174 if (bytesXferred < xferP->minBytes)
1175 xferP->minBytes = bytesXferred;
1176 if (bytesXferred > xferP->maxBytes)
1177 xferP->maxBytes = bytesXferred;
1180 * Tally the size of the object. Note: we tally the actual size,
1181 * NOT the number of bytes that made it out over the wire.
1183 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
1184 (xferP->count[0])++;
1186 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
1187 (xferP->count[1])++;
1189 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
1190 (xferP->count[2])++;
1192 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
1193 (xferP->count[3])++;
1195 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
1196 (xferP->count[4])++;
1198 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
1199 (xferP->count[5])++;
1201 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
1202 (xferP->count[6])++;
1204 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
1205 (xferP->count[7])++;
1207 (xferP->count[8])++;
1209 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
1210 fs_stats_AddTo((xferP->sumTime), elapsedTime);
1211 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
1212 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
1213 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
1215 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
1216 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
1222 * Finally, go off to tell our caller the bad news in case the
1225 if (errorCode && (!targetptr->changed_newTime))
1227 #endif /* FS_STATS_DETAILED */
1229 /* Update the status of the target's vnode */
1230 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus, targetptr,
1233 /* Get the updated File's status back to the caller */
1234 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
1237 /* Update and store volume/vnode and parent vnodes back */
1238 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1239 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
1241 CallPostamble(tcon);
1243 #if FS_STATS_DETAILED
1244 TM_GetTimeOfDay(&opStopTime, 0);
1245 if (errorCode == 0) {
1247 (opP->numSuccesses)++;
1248 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1249 fs_stats_AddTo((opP->sumTime), elapsedTime);
1250 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1251 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1252 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1254 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1255 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1259 #endif /* FS_STATS_DETAILED */
1261 osi_auditU (tcall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
1264 } /*SRXAFS_StoreData*/
1267 SRXAFS_StoreACL (tcon, Fid, AccessList, OutStatus, Sync)
1268 struct AFSVolSync *Sync;
1269 struct rx_connection *tcon; /* Rx connection handle */
1270 struct AFSFid *Fid; /* Target dir's fid */
1271 struct AFSOpaque *AccessList; /* Access List's contents */
1272 struct AFSFetchStatus *OutStatus; /* Returned status of fid */
1275 Vnode * targetptr = 0; /* pointer to input fid */
1276 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1277 int errorCode = 0; /* return code for caller */
1278 struct AFSStoreStatus InStatus; /* Input status for fid */
1279 Volume * volptr = 0; /* pointer to the volume header */
1280 struct client * client; /* pointer to client structure */
1281 afs_int32 rights, anyrights; /* rights for this and any user */
1282 struct rx_call *tcall = (struct rx_call *) tcon;
1283 struct client *t_client; /* tmp ptr to client data */
1284 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1285 #if FS_STATS_DETAILED
1286 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1287 struct timeval opStartTime,
1288 opStopTime; /* Start/stop times for RPC op*/
1289 struct timeval elapsedTime; /* Transfer time */
1292 * Set our stats pointer, remember when the RPC operation started, and
1293 * tally the operation.
1295 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
1299 TM_GetTimeOfDay(&opStartTime, 0);
1300 #endif /* FS_STATS_DETAILED */
1301 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1304 /* Get ptr to client data for user Id for logging */
1305 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1306 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1307 ViceLog(1, ("SAFS_StoreACL, Fid = %u.%d.%d, ACL=%s, Host %s, Id %d\n",
1308 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
1309 inet_ntoa(logHostAddr), t_client->ViceId));
1311 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
1314 InStatus.Mask = 0; /* not storing any status */
1317 * Get associated volume/vnode for the target dir; caller's rights
1318 * are also returned.
1320 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1321 MustBeDIR, &parentwhentargetnotdir,
1322 &client, WRITE_LOCK, &rights, &anyrights)) {
1326 /* set volume synchronization information */
1327 SetVolumeSync(Sync, volptr);
1329 /* Check if we have permission to change the dir's ACL */
1330 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1331 CHK_STOREACL, &InStatus)) {
1335 /* Build and store the new Access List for the dir */
1336 if (errorCode = RXStore_AccessList(targetptr, AccessList)) {
1340 targetptr->changed_newTime = 1; /* status change of directory */
1342 /* convert the write lock to a read lock before breaking callbacks */
1343 VVnodeWriteToRead(&errorCode, targetptr);
1344 assert(!errorCode || errorCode == VSALVAGE);
1346 /* break call backs on the directory */
1347 BreakCallBack(client->host, Fid, 0);
1349 /* Get the updated dir's status back to the caller */
1350 GetStatus(targetptr, OutStatus, rights, anyrights, (struct vnode *)0);
1353 /* Update and store volume/vnode and parent vnodes back */
1354 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1355 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
1356 CallPostamble(tcon);
1358 #if FS_STATS_DETAILED
1359 TM_GetTimeOfDay(&opStopTime, 0);
1360 if (errorCode == 0) {
1362 (opP->numSuccesses)++;
1363 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1364 fs_stats_AddTo((opP->sumTime), elapsedTime);
1365 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1366 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1367 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1369 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1370 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1374 #endif /* FS_STATS_DETAILED */
1376 osi_auditU (tcall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
1379 } /*SRXAFS_StoreACL*/
1383 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
1384 * should be merged when possible.
1386 SAFSS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync)
1387 struct rx_connection *tcon; /* Rx connection Handle */
1388 struct AFSFid *Fid; /* Target file's fid */
1389 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1390 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1391 struct AFSVolSync *Sync;
1394 Vnode * targetptr = 0; /* pointer to input fid */
1395 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1396 int errorCode = 0; /* return code for caller */
1397 Volume * volptr = 0; /* pointer to the volume header */
1398 struct client * client; /* pointer to client structure */
1399 afs_int32 rights, anyrights; /* rights for this and any user */
1400 struct client *t_client; /* tmp ptr to client data */
1401 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1403 /* Get ptr to client data for user Id for logging */
1404 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1405 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1406 ViceLog(1, ("SAFS_StoreStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
1407 Fid->Volume, Fid->Vnode, Fid->Unique,
1408 inet_ntoa(logHostAddr), t_client->ViceId));
1410 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
1413 * Get volume/vnode for the target file; caller's rights to it are
1416 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1417 DONTCHECK, &parentwhentargetnotdir,
1418 &client, WRITE_LOCK, &rights, &anyrights)) {
1419 goto Bad_StoreStatus;
1422 /* set volume synchronization information */
1423 SetVolumeSync(Sync, volptr);
1425 /* Check if the caller has proper permissions to store status to Fid */
1426 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1427 CHK_STORESTATUS, InStatus)) {
1428 goto Bad_StoreStatus;
1431 * Check for a symbolic link; we can't chmod these (otherwise could
1432 * change a symlink to a mt pt or vice versa)
1434 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
1436 goto Bad_StoreStatus;
1439 /* Update the status of the target's vnode */
1440 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
1441 (parentwhentargetnotdir ?
1442 parentwhentargetnotdir : targetptr), volptr, 0);
1444 /* convert the write lock to a read lock before breaking callbacks */
1445 VVnodeWriteToRead(&errorCode, targetptr);
1446 assert(!errorCode || errorCode == VSALVAGE);
1448 /* Break call backs on Fid */
1449 BreakCallBack(client->host, Fid, 0);
1451 /* Return the updated status back to caller */
1452 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
1455 /* Update and store volume/vnode and parent vnodes back */
1456 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1457 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
1460 } /*SAFSS_StoreStatus*/
1463 SRXAFS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync)
1464 struct AFSVolSync *Sync;
1465 struct rx_connection *tcon; /* Rx connection Handle */
1466 struct AFSFid *Fid; /* Target file's fid */
1467 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1468 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1472 struct rx_call *tcall = (struct rx_call *) tcon;
1473 #if FS_STATS_DETAILED
1474 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1475 struct timeval opStartTime,
1476 opStopTime; /* Start/stop times for RPC op*/
1477 struct timeval elapsedTime; /* Transfer time */
1480 * Set our stats pointer, remember when the RPC operation started, and
1481 * tally the operation.
1483 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
1487 TM_GetTimeOfDay(&opStartTime, 0);
1488 #endif /* FS_STATS_DETAILED */
1490 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1491 goto Bad_StoreStatus;
1493 code = SAFSS_StoreStatus (tcon, Fid, InStatus, OutStatus, Sync);
1496 CallPostamble(tcon);
1498 #if FS_STATS_DETAILED
1499 TM_GetTimeOfDay(&opStopTime, 0);
1502 (opP->numSuccesses)++;
1503 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1504 fs_stats_AddTo((opP->sumTime), elapsedTime);
1505 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1506 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1507 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1509 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1510 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1515 #endif /* FS_STATS_DETAILED */
1517 osi_auditU (tcall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
1520 } /*SRXAFS_StoreStatus*/
1524 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
1525 * merged in when possible.
1527 SAFSS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync)
1528 struct rx_connection *tcon; /* Rx connection handle */
1529 struct AFSFid *DirFid; /* Dir fid for file to remove */
1530 char *Name; /* File name to remove */
1531 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1532 struct AFSVolSync *Sync;
1535 Vnode * parentptr = 0; /* vnode of input Directory */
1536 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1537 Vnode * targetptr = 0; /* file to be deleted */
1538 Volume * volptr = 0; /* pointer to the volume header */
1539 AFSFid fileFid; /* area for Fid from the directory */
1540 int errorCode = 0; /* error code */
1541 DirHandle dir; /* Handle for dir package I/O */
1542 struct client * client; /* pointer to client structure */
1543 afs_int32 rights, anyrights; /* rights for this and any user */
1544 struct client *t_client; /* tmp ptr to client data */
1545 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1547 /* Get ptr to client data for user Id for logging */
1548 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1549 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1550 ViceLog(1, ("SAFS_RemoveFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1551 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1552 inet_ntoa(logHostAddr), t_client->ViceId));
1554 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
1557 * Get volume/vnode for the parent dir; caller's access rights are
1560 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1561 MustBeDIR, &parentwhentargetnotdir,
1562 &client, WRITE_LOCK, &rights, &anyrights)) {
1563 goto Bad_RemoveFile;
1565 /* set volume synchronization information */
1566 SetVolumeSync(Sync, volptr);
1568 /* Does the caller has delete (& write) access to the parent directory? */
1569 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
1570 goto Bad_RemoveFile;
1573 /* Actually delete the desired file */
1574 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir,
1575 &fileFid, Name, MustNOTBeDIR)) {
1576 goto Bad_RemoveFile;
1579 /* Update the vnode status of the parent dir */
1580 #if FS_STATS_DETAILED
1581 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1582 parentptr->disk.linkCount, client->InSameNetwork);
1584 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1585 parentptr->disk.linkCount);
1586 #endif /* FS_STATS_DETAILED */
1588 /* Return the updated parent dir's status back to caller */
1589 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
1591 /* Handle internal callback state for the parent and the deleted file */
1592 if (targetptr->disk.linkCount == 0) {
1593 /* no references left, discard entry */
1594 DeleteFileCallBacks(&fileFid);
1595 /* convert the parent lock to a read lock before breaking callbacks */
1596 VVnodeWriteToRead(&errorCode, parentptr);
1597 assert(!errorCode || errorCode == VSALVAGE);
1599 /* convert the parent lock to a read lock before breaking callbacks */
1600 VVnodeWriteToRead(&errorCode, parentptr);
1601 assert(!errorCode || errorCode == VSALVAGE);
1602 /* convert the target lock to a read lock before breaking callbacks */
1603 VVnodeWriteToRead(&errorCode, targetptr);
1604 assert(!errorCode || errorCode == VSALVAGE);
1605 /* tell all the file has changed */
1606 BreakCallBack(client->host, &fileFid, 1);
1609 /* break call back on the directory */
1610 BreakCallBack(client->host, DirFid, 0);
1613 /* Update and store volume/vnode and parent vnodes back */
1614 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
1615 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
1618 } /*SAFSS_RemoveFile*/
1621 SRXAFS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync)
1622 struct AFSVolSync *Sync;
1623 struct rx_connection *tcon; /* Rx connection handle */
1624 struct AFSFid *DirFid; /* Dir fid for file to remove */
1625 char *Name; /* File name to remove */
1626 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1630 struct rx_call *tcall = (struct rx_call *) tcon;
1631 #if FS_STATS_DETAILED
1632 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1633 struct timeval opStartTime,
1634 opStopTime; /* Start/stop times for RPC op*/
1635 struct timeval elapsedTime; /* Transfer time */
1638 * Set our stats pointer, remember when the RPC operation started, and
1639 * tally the operation.
1641 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
1645 TM_GetTimeOfDay(&opStartTime, 0);
1646 #endif /* FS_STATS_DETAILED */
1648 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1649 goto Bad_RemoveFile;
1651 code = SAFSS_RemoveFile (tcon, DirFid, Name, OutDirStatus, Sync);
1654 CallPostamble(tcon);
1656 #if FS_STATS_DETAILED
1657 TM_GetTimeOfDay(&opStopTime, 0);
1660 (opP->numSuccesses)++;
1661 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1662 fs_stats_AddTo((opP->sumTime), elapsedTime);
1663 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1664 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1665 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1667 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1668 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1673 #endif /* FS_STATS_DETAILED */
1675 osi_auditU (tcall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
1678 } /*SRXAFS_RemoveFile*/
1682 * This routine is called exclusively from SRXAFS_CreateFile(), and should
1683 * be merged in when possible.
1685 SAFSS_CreateFile (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus,
1686 OutDirStatus, CallBack, Sync)
1687 struct rx_connection *tcon; /* Rx connection handle */
1688 struct AFSFid *DirFid; /* Parent Dir fid */
1689 char *Name; /* File name to be created */
1690 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
1691 struct AFSFid *OutFid; /* Fid for newly created file */
1692 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
1693 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
1694 struct AFSCallBack *CallBack; /* Return callback promise for new file */
1695 struct AFSVolSync *Sync;
1698 Vnode * parentptr = 0; /* vnode of input Directory */
1699 Vnode * targetptr = 0; /* vnode of the new file */
1700 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1701 Volume * volptr = 0; /* pointer to the volume header */
1702 int errorCode = 0; /* error code */
1703 DirHandle dir; /* Handle for dir package I/O */
1704 struct client * client; /* pointer to client structure */
1705 afs_int32 rights, anyrights; /* rights for this and any user */
1706 struct client *t_client; /* tmp ptr to client data */
1707 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1709 /* Get ptr to client data for user Id for logging */
1710 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1711 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1712 ViceLog(1, ("SAFS_CreateFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1713 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1714 inet_ntoa(logHostAddr), t_client->ViceId));
1716 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
1718 if (!FileNameOK(Name)) {
1720 goto Bad_CreateFile;
1724 * Get associated volume/vnode for the parent dir; caller long are
1727 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1728 MustBeDIR, &parentwhentargetnotdir,
1729 &client, WRITE_LOCK, &rights, &anyrights)) {
1730 goto Bad_CreateFile;
1733 /* set volume synchronization information */
1734 SetVolumeSync(Sync, volptr);
1736 /* Can we write (and insert) onto the parent directory? */
1737 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
1738 goto Bad_CreateFile;
1740 /* get a new vnode for the file to be created and set it up */
1741 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
1742 Name, OutFid, vFile, nBlocks(0))) {
1743 goto Bad_CreateFile;
1746 /* update the status of the parent vnode */
1747 #if FS_STATS_DETAILED
1748 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1749 parentptr->disk.linkCount, client->InSameNetwork);
1751 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1752 parentptr->disk.linkCount);
1753 #endif /* FS_STATS_DETAILED */
1755 /* update the status of the new file's vnode */
1756 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
1757 parentptr, volptr, 0);
1759 /* set up the return status for the parent dir and the newly created file */
1760 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
1761 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
1763 /* convert the write lock to a read lock before breaking callbacks */
1764 VVnodeWriteToRead(&errorCode, parentptr);
1765 assert(!errorCode || errorCode == VSALVAGE);
1767 /* break call back on parent dir */
1768 BreakCallBack(client->host, DirFid, 0);
1770 /* Return a callback promise for the newly created file to the caller */
1771 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
1774 /* Update and store volume/vnode and parent vnodes back */
1775 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
1776 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
1779 } /*SAFSS_CreateFile*/
1782 SRXAFS_CreateFile (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
1783 struct AFSVolSync *Sync;
1784 struct rx_connection *tcon; /* Rx connection handle */
1785 struct AFSFid *DirFid; /* Parent Dir fid */
1786 char *Name; /* File name to be created */
1787 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
1788 struct AFSFid *OutFid; /* Fid for newly created file */
1789 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
1790 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
1791 struct AFSCallBack *CallBack; /* Return callback promise for new file */
1795 struct rx_call *tcall = (struct rx_call *) tcon;
1796 #if FS_STATS_DETAILED
1797 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1798 struct timeval opStartTime,
1799 opStopTime; /* Start/stop times for RPC op*/
1800 struct timeval elapsedTime; /* Transfer time */
1803 * Set our stats pointer, remember when the RPC operation started, and
1804 * tally the operation.
1806 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
1810 TM_GetTimeOfDay(&opStartTime, 0);
1811 #endif /* FS_STATS_DETAILED */
1813 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
1814 goto Bad_CreateFile;
1816 code = SAFSS_CreateFile (tcon, DirFid, Name, InStatus, OutFid,
1817 OutFidStatus, OutDirStatus, CallBack, Sync);
1820 CallPostamble(tcon);
1822 #if FS_STATS_DETAILED
1823 TM_GetTimeOfDay(&opStopTime, 0);
1826 (opP->numSuccesses)++;
1827 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1828 fs_stats_AddTo((opP->sumTime), elapsedTime);
1829 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1830 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1831 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1833 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1834 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1838 #endif /* FS_STATS_DETAILED */
1840 osi_auditU (tcall, CreateFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
1843 } /*SRXAFS_CreateFile*/
1847 * This routine is called exclusively from SRXAFS_Rename(), and should be
1848 * merged in when possible.
1850 SAFSS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus,
1851 OutNewDirStatus, Sync)
1852 struct rx_connection *tcon; /* Rx connection handle */
1853 struct AFSFid *OldDirFid; /* From parent dir's fid */
1854 char *OldName; /* From file name */
1855 struct AFSFid *NewDirFid; /* To parent dir's fid */
1856 char *NewName; /* To new file name */
1857 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
1858 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
1859 struct AFSVolSync *Sync;
1862 Vnode * oldvptr = 0; /* vnode of the old Directory */
1863 Vnode * newvptr = 0; /* vnode of the new Directory */
1864 Vnode * fileptr = 0; /* vnode of the file to move */
1865 Vnode * newfileptr = 0; /* vnode of the file to delete */
1866 Vnode * testvptr = 0; /* used in directory tree walk */
1867 Vnode * parent = 0; /* parent for use in SetAccessList */
1868 int errorCode = 0; /* error code */
1869 int fileCode = 0; /* used when writing Vnodes */
1870 VnodeId testnode; /* used in directory tree walk */
1871 AFSFid fileFid; /* Fid of file to move */
1872 AFSFid newFileFid; /* Fid of new file */
1873 DirHandle olddir; /* Handle for dir package I/O */
1874 DirHandle newdir; /* Handle for dir package I/O */
1875 DirHandle filedir; /* Handle for dir package I/O */
1876 DirHandle newfiledir; /* Handle for dir package I/O */
1877 Volume * volptr = 0; /* pointer to the volume header */
1878 struct client * client; /* pointer to client structure */
1879 afs_int32 rights, anyrights; /* rights for this and any user */
1880 afs_int32 newrights; /* rights for this user */
1881 afs_int32 newanyrights; /* rights for any user */
1882 int doDelete; /* deleted the rename target (ref count now 0) */
1884 struct client *t_client; /* tmp ptr to client data */
1885 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1887 /* Get ptr to client data for user Id for logging */
1888 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1889 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1890 ViceLog(1, ("SAFS_Rename %s to %s, Fid = %u.%d.%d to %u.%d.%d, Host %s, Id %d\n",
1891 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
1892 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
1894 inet_ntoa(logHostAddr), t_client->ViceId));
1896 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
1898 if (!FileNameOK(NewName)) {
1902 if (OldDirFid->Volume != NewDirFid->Volume) {
1907 if ( (strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0) ||
1908 (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0) ||
1909 (strlen(NewName) == 0) || (strlen(OldName) == 0) ) {
1915 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
1916 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr,
1917 &oldvptr, MustBeDIR, &parent,
1918 &client, WRITE_LOCK, &rights,
1923 if (OldDirFid->Vnode == NewDirFid->Vnode) {
1925 newrights = rights, newanyrights = anyrights;
1928 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
1929 &newvptr, MustBeDIR, &parent,
1930 &client, WRITE_LOCK, &newrights,
1937 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
1938 &newvptr, MustBeDIR, &parent,
1939 &client, WRITE_LOCK, &newrights,
1944 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr,
1945 MustBeDIR, &parent, &client, WRITE_LOCK,
1946 &rights, &anyrights)) {
1952 /* set volume synchronization information */
1953 SetVolumeSync(Sync, volptr);
1955 if (errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE)) {
1958 if (errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT)) {
1962 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
1963 * call to CopyOnWrite returns error, it is not necessary to revert back
1964 * the effects of the first call because the contents of the volume is
1965 * not modified, it is only replicated.
1967 if (oldvptr->disk.cloned)
1969 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
1970 if ( errorCode = CopyOnWrite(oldvptr, volptr) )
1973 SetDirHandle(&olddir, oldvptr);
1974 if (newvptr->disk.cloned)
1976 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
1977 if ( errorCode = CopyOnWrite(newvptr, volptr) )
1981 SetDirHandle(&newdir, newvptr);
1983 /* Lookup the file to delete its vnode */
1984 if (Lookup(&olddir, OldName, &fileFid)) {
1988 if (fileFid.Vnode == oldvptr->vnodeNumber ||
1989 fileFid.Vnode == newvptr->vnodeNumber) {
1990 errorCode = FSERR_ELOOP;
1993 fileFid.Volume = V_id(volptr);
1994 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
1995 if (errorCode != 0) {
1996 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n", OldName, errorCode));
1997 VTakeOffline (volptr);
2000 if (fileptr->disk.uniquifier != fileFid.Unique) {
2001 ViceLog (0, ("SAFSS_Rename(): Old file %s uniquifier mismatch\n", OldName));
2002 VTakeOffline (volptr);
2007 if (fileptr->disk.type != vDirectory &&
2008 oldvptr != newvptr &&
2009 fileptr->disk.linkCount != 1) {
2011 * Hard links exist to this file - cannot move one of the links to
2012 * a new directory because of AFS restrictions (this is the same
2013 * reason that links cannot be made across directories, i.e.
2020 /* Lookup the new file */
2021 if (!(Lookup(&newdir, NewName, &newFileFid))) {
2022 if (!(newrights & PRSFS_DELETE)) {
2026 if (newFileFid.Vnode == oldvptr->vnodeNumber ||
2027 newFileFid.Vnode == newvptr->vnodeNumber ||
2028 newFileFid.Vnode == fileFid.Vnode) {
2032 newFileFid.Volume = V_id(volptr);
2033 newfileptr = VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
2034 if (errorCode != 0) {
2035 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n", NewName, errorCode));
2036 VTakeOffline (volptr);
2039 if (fileptr->disk.uniquifier != fileFid.Unique) {
2040 ViceLog (0, ("SAFSS_Rename(): New file %s uniquifier mismatch\n", NewName));
2041 VTakeOffline (volptr);
2045 SetDirHandle(&newfiledir, newfileptr);
2046 /* Now check that we're moving directories over directories properly, etc.
2047 * return proper POSIX error codes:
2048 * if fileptr is a file and new is a dir: EISDIR.
2049 * if fileptr is a dir and new is a file: ENOTDIR.
2050 * Also, dir to be removed must be empty, of course.
2052 if (newfileptr->disk.type == vDirectory) {
2053 if (fileptr->disk.type != vDirectory) {
2057 if ((IsEmpty(&newfiledir))) {
2063 if (fileptr->disk.type == vDirectory) {
2064 errorCode = ENOTDIR;
2071 * ok - now we check that the old name is not above new name in the
2072 * directory structure. This is to prevent removing a subtree alltogether
2074 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
2075 for (testnode = newvptr->disk.parent; testnode != 0;) {
2076 if (testnode == oldvptr->vnodeNumber) {
2077 testnode = oldvptr->disk.parent;
2080 if ((testnode == fileptr->vnodeNumber) ||
2081 (testnode == newvptr->vnodeNumber)) {
2082 errorCode = FSERR_ELOOP;
2085 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
2086 errorCode = FSERR_ELOOP;
2089 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
2090 assert(errorCode == 0);
2091 testnode = testvptr->disk.parent;
2092 VPutVnode(&errorCode, testvptr);
2093 assert(errorCode == 0);
2096 /* Do the CopyonWrite first before modifying anything else. Copying is
2097 * required because we may have to change entries for ..
2099 if ((fileptr->disk.type == vDirectory ) && (fileptr->disk.cloned) )
2101 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
2102 if ( errorCode = CopyOnWrite(fileptr, volptr) )
2106 /* If the new name exists already, delete it and the file it points to */
2109 /* Delete NewName from its directory */
2110 code = Delete(&newdir, NewName);
2113 /* Drop the link count */
2114 newfileptr->disk.linkCount--;
2115 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
2116 VAdjustDiskUsage(&errorCode, volptr,
2117 -(int)nBlocks(newfileptr->disk.length), 0);
2118 if (VN_GET_INO(newfileptr)) {
2119 IH_REALLYCLOSE(newfileptr->handle);
2120 errorCode = IH_DEC(V_linkHandle(volptr),
2121 VN_GET_INO(newfileptr),
2122 V_parentId(volptr));
2123 IH_RELEASE(newfileptr->handle);
2124 if (errorCode == -1) {
2125 ViceLog(0, ("Del: inode=%d, name=%s, errno=%d\n",
2126 PrintInode(NULL, VN_GET_INO(newfileptr)),
2128 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
2129 ViceLog(0, ("Do we need to fsck?"));
2132 VN_SET_INO(newfileptr, (Inode)0);
2133 newfileptr->delete = 1; /* Mark NewName vnode to delete */
2136 /* Link count did not drop to zero.
2137 * Mark NewName vnode as changed - updates stime.
2139 newfileptr->changed_newTime = 1;
2144 * If the create below fails, and the delete above worked, we have
2145 * removed the new name and not replaced it. This is not very likely,
2146 * but possible. We could try to put the old file back, but it is
2147 * highly unlikely that it would work since it would involve issuing
2150 if (errorCode = Create(&newdir,(char *) NewName, &fileFid))
2153 /* Delete the old name */
2154 assert(Delete(&olddir,(char *) OldName) == 0);
2156 /* if the directory length changes, reflect it in the statistics */
2157 #if FS_STATS_DETAILED
2158 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2159 oldvptr->disk.linkCount, client->InSameNetwork);
2160 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2161 newvptr->disk.linkCount, client->InSameNetwork);
2163 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2164 oldvptr->disk.linkCount);
2165 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2166 newvptr->disk.linkCount);
2167 #endif /* FS_STATS_DETAILED */
2169 if (oldvptr == newvptr)
2170 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
2172 fileptr->disk.parent = newvptr->vnodeNumber;
2173 fileptr->changed_newTime = 1; /* status change of moved file */
2175 /* if we are dealing with a rename of a directory */
2176 if (fileptr->disk.type == vDirectory) {
2177 assert(!fileptr->disk.cloned);
2178 SetDirHandle(&filedir, fileptr);
2179 /* fix .. to point to the correct place */
2180 Delete(&filedir, ".."); /* No assert--some directories may be bad */
2181 assert(Create(&filedir, "..", NewDirFid) == 0);
2182 fileptr->disk.dataVersion++;
2183 /* if the parent directories are different the link counts have to be */
2184 /* changed due to .. in the renamed directory */
2185 if (oldvptr != newvptr) {
2186 oldvptr->disk.linkCount--;
2187 newvptr->disk.linkCount++;
2191 /* set up return status */
2192 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, (struct vnode *)0);
2193 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, (struct vnode *)0);
2194 if (newfileptr && doDelete) {
2195 DeleteFileCallBacks(&newFileFid); /* no other references */
2200 /* convert the write locks to a read locks before breaking callbacks */
2201 VVnodeWriteToRead(&errorCode, newvptr);
2202 assert(!errorCode || errorCode == VSALVAGE);
2203 if (oldvptr != newvptr) {
2204 VVnodeWriteToRead(&errorCode, oldvptr);
2205 assert(!errorCode || errorCode == VSALVAGE);
2207 if (newfileptr && !doDelete) {
2208 /* convert the write lock to a read lock before breaking callbacks */
2209 VVnodeWriteToRead(&errorCode, newfileptr);
2210 assert(!errorCode || errorCode == VSALVAGE);
2213 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
2214 BreakCallBack(client->host, NewDirFid, 0);
2215 if (oldvptr != newvptr) {
2216 BreakCallBack(client->host, OldDirFid, 0);
2217 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
2218 BreakCallBack(client->host, &fileFid, 0);
2221 /* Note: it is not necessary to break the callback */
2223 DeleteFileCallBacks(&newFileFid); /* no other references */
2225 /* other's still exist (with wrong link count) */
2226 BreakCallBack(client->host, &newFileFid, 1);
2231 VPutVnode(&fileCode, newfileptr);
2232 assert(fileCode == 0);
2234 PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr? newvptr : 0),
2236 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
2242 SRXAFS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus, OutNewDirStatus, Sync)
2243 struct AFSVolSync *Sync;
2244 struct rx_connection *tcon; /* Rx connection handle */
2245 struct AFSFid *OldDirFid; /* From parent dir's fid */
2246 char *OldName; /* From file name */
2247 struct AFSFid *NewDirFid; /* To parent dir's fid */
2248 char *NewName; /* To new file name */
2249 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
2250 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
2254 struct rx_call *tcall = (struct rx_call *) tcon;
2255 #if FS_STATS_DETAILED
2256 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2257 struct timeval opStartTime,
2258 opStopTime; /* Start/stop times for RPC op*/
2259 struct timeval elapsedTime; /* Transfer time */
2262 * Set our stats pointer, remember when the RPC operation started, and
2263 * tally the operation.
2265 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
2269 TM_GetTimeOfDay(&opStartTime, 0);
2270 #endif /* FS_STATS_DETAILED */
2272 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2275 code = SAFSS_Rename (tcon, OldDirFid, OldName, NewDirFid, NewName,
2276 OutOldDirStatus, OutNewDirStatus, Sync);
2279 CallPostamble(tcon);
2281 #if FS_STATS_DETAILED
2282 TM_GetTimeOfDay(&opStopTime, 0);
2285 (opP->numSuccesses)++;
2286 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2287 fs_stats_AddTo((opP->sumTime), elapsedTime);
2288 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2289 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2290 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2292 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2293 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2298 #endif /* FS_STATS_DETAILED */
2300 osi_auditU (tcall, RenameFileEvent, code, AUD_FID, OldDirFid, AUD_STR, OldName, AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
2307 * This routine is called exclusively by SRXAFS_Symlink(), and should be
2308 * merged into it when possible.
2310 SAFSS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2311 struct rx_connection *tcon; /* Rx connection handle */
2312 struct AFSFid *DirFid; /* Parent dir's fid */
2313 char *Name; /* File name to create */
2314 char *LinkContents; /* Contents of the new created file */
2315 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2316 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2317 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2318 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2319 struct AFSVolSync *Sync; /* volume synchronization information */
2322 Vnode * parentptr = 0; /* vnode of input Directory */
2323 Vnode * targetptr = 0; /* vnode of the new link */
2324 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2325 int errorCode = 0; /* error code */
2327 DirHandle dir; /* Handle for dir package I/O */
2328 Volume * volptr = 0; /* pointer to the volume header */
2329 struct client * client; /* pointer to client structure */
2330 afs_int32 rights, anyrights, fd; /* rights for this and any user */
2331 struct client *t_client; /* tmp ptr to client data */
2332 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2335 /* Get ptr to client data for user Id for logging */
2336 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2337 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2338 ViceLog(1, ("SAFS_Symlink %s to %s, Did = %u.%d.%d, Host %s, Id %d\n", Name,
2339 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2340 inet_ntoa(logHostAddr), t_client->ViceId));
2342 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
2344 if (!FileNameOK(Name)) {
2350 * Get the vnode and volume for the parent dir along with the caller's
2353 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2354 MustBeDIR, &parentwhentargetnotdir,
2355 &client, WRITE_LOCK, &rights, &anyrights)) {
2359 /* set volume synchronization information */
2360 SetVolumeSync(Sync, volptr);
2362 /* Does the caller has insert (and write) access to the parent directory? */
2363 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2368 * If we're creating a mount point (owner mode bits sans x bit), we must
2369 * have administer access to the directory, too. Always allow sysadmins
2372 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0100)) {
2374 * We have a symlink, 'cause we're trying to set the Unix mode bits
2375 * to something without the owner x bits (default mode bits if
2376 * AFS_SETMODE is false is 0777)
2378 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
2384 /* get a new vnode for the symlink and set it up */
2385 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
2386 Name, OutFid, vSymlink,
2387 nBlocks(strlen((char *) LinkContents)))) {
2391 /* update the status of the parent vnode */
2392 #if FS_STATS_DETAILED
2393 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2394 parentptr->disk.linkCount, client->InSameNetwork);
2396 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2397 parentptr->disk.linkCount);
2398 #endif /* FS_STATS_DETAILED */
2400 /* update the status of the new symbolic link file vnode */
2401 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus, parentptr,
2402 volptr, strlen((char *)LinkContents));
2404 /* Write the contents of the symbolic link name into the target inode */
2405 fdP = IH_OPEN(targetptr->handle);
2406 assert(fdP != NULL);
2407 assert(FDH_WRITE(fdP, (char *) LinkContents, strlen((char *) LinkContents)) == strlen((char *) LinkContents));
2410 * Set up and return modified status for the parent dir and new symlink
2413 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2414 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
2416 /* convert the write lock to a read lock before breaking callbacks */
2417 VVnodeWriteToRead(&errorCode, parentptr);
2418 assert(!errorCode || errorCode == VSALVAGE);
2420 /* break call back on the parent dir */
2421 BreakCallBack(client->host, DirFid, 0);
2424 /* Write the all modified vnodes (parent, new files) and volume back */
2425 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2426 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
2432 SRXAFS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2433 struct AFSVolSync *Sync;
2434 struct rx_connection *tcon; /* Rx connection handle */
2435 struct AFSFid *DirFid; /* Parent dir's fid */
2436 char *Name; /* File name to create */
2437 char *LinkContents; /* Contents of the new created file */
2438 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2439 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2440 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2441 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2445 struct rx_call *tcall = (struct rx_call *) tcon;
2446 #if FS_STATS_DETAILED
2447 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2448 struct timeval opStartTime,
2449 opStopTime; /* Start/stop times for RPC op*/
2450 struct timeval elapsedTime; /* Transfer time */
2453 * Set our stats pointer, remember when the RPC operation started, and
2454 * tally the operation.
2456 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
2460 TM_GetTimeOfDay(&opStartTime, 0);
2461 #endif /* FS_STATS_DETAILED */
2463 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2466 code = SAFSS_Symlink (tcon, DirFid, Name, LinkContents, InStatus, OutFid,
2467 OutFidStatus, OutDirStatus, Sync);
2470 CallPostamble(tcon);
2472 #if FS_STATS_DETAILED
2473 TM_GetTimeOfDay(&opStopTime, 0);
2476 (opP->numSuccesses)++;
2477 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2478 fs_stats_AddTo((opP->sumTime), elapsedTime);
2479 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2480 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2481 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2483 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2484 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2489 #endif /* FS_STATS_DETAILED */
2491 osi_auditU (tcall, SymlinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2494 } /*SRXAFS_Symlink*/
2498 * This routine is called exclusively by SRXAFS_Link(), and should be
2499 * merged into it when possible.
2501 SAFSS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2502 struct rx_connection *tcon; /* Rx connection handle */
2503 struct AFSFid *DirFid; /* Parent dir's fid */
2504 char *Name; /* File name to create */
2505 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2506 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2507 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2508 struct AFSVolSync *Sync;
2511 Vnode * parentptr = 0; /* vnode of input Directory */
2512 Vnode * targetptr = 0; /* vnode of the new file */
2513 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2514 Volume * volptr = 0; /* pointer to the volume header */
2515 int errorCode = 0; /* error code */
2516 DirHandle dir; /* Handle for dir package I/O */
2517 struct client * client; /* pointer to client structure */
2518 afs_int32 rights, anyrights; /* rights for this and any user */
2519 struct client *t_client; /* tmp ptr to client data */
2520 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2522 /* Get ptr to client data for user Id for logging */
2523 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2524 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2525 ViceLog(1, ("SAFS_Link %s, Did = %u.%d.%d, Fid = %u.%d.%d, Host %s, Id %d\n",
2526 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2527 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
2528 inet_ntoa(logHostAddr), t_client->ViceId));
2530 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
2532 if (DirFid->Volume != ExistingFid->Volume) {
2536 if (!FileNameOK(Name)) {
2542 * Get the vnode and volume for the parent dir along with the caller's
2545 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2546 MustBeDIR, &parentwhentargetnotdir,
2547 &client, WRITE_LOCK, &rights, &anyrights)) {
2551 /* set volume synchronization information */
2552 SetVolumeSync(Sync, volptr);
2554 /* Can the caller insert into the parent directory? */
2555 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2559 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) ||
2560 (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
2561 /* AFS fileservers always have directory vnodes that are odd. */
2566 /* get the file vnode */
2567 if (errorCode = CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK)) {
2570 if (targetptr->disk.type != vFile) {
2574 if (targetptr->disk.parent != DirFid->Vnode) {
2578 if (parentptr->disk.cloned)
2580 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
2581 if ( errorCode = CopyOnWrite(parentptr, volptr))
2582 goto Bad_Link; /* disk full error */
2585 /* add the name to the directory */
2586 SetDirHandle(&dir, parentptr);
2587 if (errorCode = Create(&dir, (char *)Name, ExistingFid))
2591 /* update the status in the parent vnode */
2592 /**WARNING** --> disk.author SHOULDN'T be modified???? */
2593 #if FS_STATS_DETAILED
2594 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2595 parentptr->disk.linkCount, client->InSameNetwork);
2597 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2598 parentptr->disk.linkCount);
2599 #endif /* FS_STATS_DETAILED */
2601 targetptr->disk.linkCount++;
2602 targetptr->disk.author = client->ViceId;
2603 targetptr->changed_newTime = 1; /* Status change of linked-to file */
2605 /* set up return status */
2606 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2607 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct vnode *)0);
2609 /* convert the write locks to read locks before breaking callbacks */
2610 VVnodeWriteToRead(&errorCode, targetptr);
2611 assert(!errorCode || errorCode == VSALVAGE);
2612 VVnodeWriteToRead(&errorCode, parentptr);
2613 assert(!errorCode || errorCode == VSALVAGE);
2615 /* break call back on DirFid */
2616 BreakCallBack(client->host, DirFid, 0);
2618 * We also need to break the callback for the file that is hard-linked since part
2619 * of its status (like linkcount) is changed
2621 BreakCallBack(client->host, ExistingFid, 0);
2624 /* Write the all modified vnodes (parent, new files) and volume back */
2625 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2626 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
2632 SRXAFS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2633 struct AFSVolSync *Sync;
2634 struct rx_connection *tcon; /* Rx connection handle */
2635 struct AFSFid *DirFid; /* Parent dir's fid */
2636 char *Name; /* File name to create */
2637 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2638 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2639 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2643 struct rx_call *tcall = (struct rx_call *) tcon;
2644 #if FS_STATS_DETAILED
2645 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2646 struct timeval opStartTime,
2647 opStopTime; /* Start/stop times for RPC op*/
2648 struct timeval elapsedTime; /* Transfer time */
2651 * Set our stats pointer, remember when the RPC operation started, and
2652 * tally the operation.
2654 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
2658 TM_GetTimeOfDay(&opStartTime, 0);
2659 #endif /* FS_STATS_DETAILED */
2661 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2664 code = SAFSS_Link (tcon, DirFid, Name, ExistingFid, OutFidStatus,
2665 OutDirStatus, Sync);
2668 CallPostamble(tcon);
2670 #if FS_STATS_DETAILED
2671 TM_GetTimeOfDay(&opStopTime, 0);
2674 (opP->numSuccesses)++;
2675 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2676 fs_stats_AddTo((opP->sumTime), elapsedTime);
2677 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2678 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2679 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2681 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2682 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2687 #endif /* FS_STATS_DETAILED */
2689 osi_auditU (tcall, LinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_FID, ExistingFid, AUD_END);
2696 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
2697 * merged into it when possible.
2699 SAFSS_MakeDir (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus,
2700 OutDirStatus, CallBack, Sync)
2701 struct rx_connection *tcon; /* Rx connection handle */
2702 struct AFSFid *DirFid; /* Parent dir's fid */
2703 char *Name; /* Name of dir to be created */
2704 struct AFSStoreStatus *InStatus; /* Input status for new dir */
2705 struct AFSFid *OutFid; /* Fid of new dir */
2706 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
2707 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2708 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
2709 struct AFSVolSync *Sync;
2712 Vnode * parentptr = 0; /* vnode of input Directory */
2713 Vnode * targetptr = 0; /* vnode of the new file */
2714 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2715 Volume * volptr = 0; /* pointer to the volume header */
2716 int errorCode = 0; /* error code */
2717 struct acl_accessList * newACL; /* Access list */
2718 int newACLSize; /* Size of access list */
2719 DirHandle dir; /* Handle for dir package I/O */
2720 DirHandle parentdir; /* Handle for dir package I/O */
2721 struct client * client; /* pointer to client structure */
2722 afs_int32 rights, anyrights; /* rights for this and any user */
2723 struct client *t_client; /* tmp ptr to client data */
2724 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2726 /* Get ptr to client data for user Id for logging */
2727 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2728 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2729 ViceLog(1, ("SAFS_MakeDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
2730 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2731 inet_ntoa(logHostAddr), t_client->ViceId));
2733 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
2735 if (!FileNameOK(Name)) {
2741 * Get the vnode and volume for the parent dir along with the caller's
2744 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2745 MustBeDIR, &parentwhentargetnotdir,
2746 &client, WRITE_LOCK, &rights, &anyrights)) {
2750 /* set volume synchronization information */
2751 SetVolumeSync(Sync, volptr);
2753 /* Write access to the parent directory? */
2754 #ifdef DIRCREATE_NEED_WRITE
2756 * requires w access for the user to create a directory. this
2757 * closes a loophole in the current security arrangement, since a
2758 * user with i access only can create a directory and get the
2759 * implcit a access that goes with dir ownership, and proceed to
2760 * subvert quota in the volume.
2762 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) ||
2763 (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
2765 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2766 #endif /* DIRCREATE_NEED_WRITE */
2770 #define EMPTYDIRBLOCKS 2
2771 /* get a new vnode and set it up */
2772 if (errorCode = Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr,
2773 Name, OutFid, vDirectory, EMPTYDIRBLOCKS)) {
2777 /* Update the status for the parent dir */
2778 #if FS_STATS_DETAILED
2779 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
2780 parentptr->disk.linkCount+1, client->InSameNetwork);
2782 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
2783 parentptr->disk.linkCount+1);
2784 #endif /* FS_STATS_DETAILED */
2786 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
2787 assert((SetAccessList(&targetptr, &volptr, &newACL, &newACLSize,
2788 &parentwhentargetnotdir, (AFSFid *)0, 0)) == 0);
2789 assert(parentwhentargetnotdir == 0);
2790 bcopy((char *)VVnodeACL(parentptr), (char *)newACL, VAclSize(parentptr));
2792 /* update the status for the target vnode */
2793 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
2794 parentptr, volptr, 0);
2796 /* Actually create the New directory in the directory package */
2797 SetDirHandle(&dir, targetptr);
2798 assert(!(MakeDir(&dir, OutFid, DirFid)));
2800 targetptr->disk.length = Length(&dir);
2802 /* set up return status */
2803 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2804 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
2806 /* convert the write lock to a read lock before breaking callbacks */
2807 VVnodeWriteToRead(&errorCode, parentptr);
2808 assert(!errorCode || errorCode == VSALVAGE);
2810 /* break call back on DirFid */
2811 BreakCallBack(client->host, DirFid, 0);
2813 /* Return a callback promise to caller */
2814 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
2817 /* Write the all modified vnodes (parent, new files) and volume back */
2818 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2819 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
2825 SRXAFS_MakeDir (tcon, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
2826 struct AFSVolSync *Sync;
2827 struct rx_connection *tcon; /* Rx connection handle */
2828 struct AFSFid *DirFid; /* Parent dir's fid */
2829 char *Name; /* Name of dir to be created */
2830 struct AFSStoreStatus *InStatus; /* Input status for new dir */
2831 struct AFSFid *OutFid; /* Fid of new dir */
2832 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
2833 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2834 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
2838 struct rx_call *tcall = (struct rx_call *) tcon;
2839 #if FS_STATS_DETAILED
2840 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2841 struct timeval opStartTime,
2842 opStopTime; /* Start/stop times for RPC op*/
2843 struct timeval elapsedTime; /* Transfer time */
2846 * Set our stats pointer, remember when the RPC operation started, and
2847 * tally the operation.
2849 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
2853 TM_GetTimeOfDay(&opStartTime, 0);
2854 #endif /* FS_STATS_DETAILED */
2855 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
2858 code = SAFSS_MakeDir (tcon, DirFid, Name, InStatus, OutFid,
2859 OutFidStatus, OutDirStatus, CallBack, Sync);
2862 CallPostamble(tcon);
2864 #if FS_STATS_DETAILED
2865 TM_GetTimeOfDay(&opStopTime, 0);
2868 (opP->numSuccesses)++;
2869 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2870 fs_stats_AddTo((opP->sumTime), elapsedTime);
2871 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2872 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2873 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2875 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2876 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2881 #endif /* FS_STATS_DETAILED */
2883 osi_auditU (tcall, MakeDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2886 } /*SRXAFS_MakeDir*/
2890 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
2891 * merged into it when possible.
2893 SAFSS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync)
2894 struct rx_connection *tcon; /* Rx connection handle */
2895 struct AFSFid *DirFid; /* Parent dir's fid */
2896 char *Name; /* (Empty) dir's name to be removed */
2897 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
2898 struct AFSVolSync *Sync;
2901 Vnode * parentptr = 0; /* vnode of input Directory */
2902 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2903 Vnode * targetptr = 0; /* file to be deleted */
2904 AFSFid fileFid; /* area for Fid from the directory */
2905 int errorCode = 0; /* error code */
2906 DirHandle dir; /* Handle for dir package I/O */
2907 Volume * volptr = 0; /* pointer to the volume header */
2908 struct client * client; /* pointer to client structure */
2909 afs_int32 rights, anyrights; /* rights for this and any user */
2910 Vnode debugvnode1, debugvnode2;
2911 struct client *t_client; /* tmp ptr to client data */
2912 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2914 /* Get ptr to client data for user Id for logging */
2915 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2916 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2917 ViceLog(1, ("SAFS_RemoveDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
2918 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2919 inet_ntoa(logHostAddr), t_client->ViceId));
2921 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
2924 * Get the vnode and volume for the parent dir along with the caller's
2927 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2928 MustBeDIR, &parentwhentargetnotdir,
2929 &client, WRITE_LOCK, &rights, &anyrights)) {
2932 debugvnode1 = *parentptr;
2934 /* set volume synchronization information */
2935 SetVolumeSync(Sync, volptr);
2937 /* Does the caller has delete (&write) access to the parent dir? */
2938 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
2942 debugvnode2 = *parentptr;
2943 /* Do the actual delete of the desired (empty) directory, Name */
2944 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid,
2949 /* Update the status for the parent dir; link count is also adjusted */
2950 #if FS_STATS_DETAILED
2951 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2952 parentptr->disk.linkCount-1, client->InSameNetwork);
2954 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2955 parentptr->disk.linkCount-1);
2956 #endif /* FS_STATS_DETAILED */
2958 /* Return to the caller the updated parent dir status */
2959 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
2962 * Note: it is not necessary to break the callback on fileFid, since
2963 * refcount is now 0, so no one should be able to refer to the dir
2966 DeleteFileCallBacks(&fileFid);
2968 /* convert the write lock to a read lock before breaking callbacks */
2969 VVnodeWriteToRead(&errorCode, parentptr);
2970 assert(!errorCode || errorCode == VSALVAGE);
2972 /* break call back on DirFid and fileFid */
2973 BreakCallBack(client->host, DirFid, 0);
2976 /* Write the all modified vnodes (parent, new files) and volume back */
2977 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2978 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
2981 } /*SAFSS_RemoveDir*/
2984 SRXAFS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync)
2985 struct AFSVolSync *Sync;
2986 struct rx_connection *tcon; /* Rx connection handle */
2987 struct AFSFid *DirFid; /* Parent dir's fid */
2988 char *Name; /* (Empty) dir's name to be removed */
2989 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
2993 struct rx_call *tcall = (struct rx_call *) tcon;
2994 #if FS_STATS_DETAILED
2995 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2996 struct timeval opStartTime,
2997 opStopTime; /* Start/stop times for RPC op*/
2998 struct timeval elapsedTime; /* Transfer time */
3001 * Set our stats pointer, remember when the RPC operation started, and
3002 * tally the operation.
3004 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
3008 TM_GetTimeOfDay(&opStartTime, 0);
3009 #endif /* FS_STATS_DETAILED */
3011 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3014 code = SAFSS_RemoveDir (tcon, DirFid, Name, OutDirStatus, Sync);
3017 CallPostamble(tcon);
3019 #if FS_STATS_DETAILED
3020 TM_GetTimeOfDay(&opStopTime, 0);
3023 (opP->numSuccesses)++;
3024 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3025 fs_stats_AddTo((opP->sumTime), elapsedTime);
3026 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3027 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3028 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3030 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3031 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3036 #endif /* FS_STATS_DETAILED */
3038 osi_auditU (tcall, RemoveDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3041 } /*SRXAFS_RemoveDir*/
3045 * This routine is called exclusively by SRXAFS_SetLock(), and should be
3046 * merged into it when possible.
3048 SAFSS_SetLock (tcon, Fid, type, Sync)
3049 struct rx_connection *tcon; /* Rx connection handle */
3050 struct AFSFid *Fid; /* Fid of file to lock */
3051 ViceLockType type; /* Type of lock (Read or write) */
3052 struct AFSVolSync *Sync;
3055 Vnode * targetptr = 0; /* vnode of input file */
3056 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3057 int errorCode = 0; /* error code */
3058 Volume * volptr = 0; /* pointer to the volume header */
3059 struct client * client; /* pointer to client structure */
3060 afs_int32 rights, anyrights; /* rights for this and any user */
3061 struct client *t_client; /* tmp ptr to client data */
3062 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3063 static char * locktype[2] = {"LockRead","LockWrite"};
3065 if (type != LockRead && type != LockWrite) {
3069 /* Get ptr to client data for user Id for logging */
3070 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3071 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3072 ViceLog(1,("SAFS_SetLock type = %s Fid = %u.%d.%d, Host %s, Id %d\n",
3073 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
3074 inet_ntoa(logHostAddr), t_client->ViceId));
3076 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
3080 * Get the vnode and volume for the desired file along with the caller's
3083 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3084 DONTCHECK, &parentwhentargetnotdir,
3085 &client, WRITE_LOCK, &rights, &anyrights)) {
3089 /* set volume synchronization information */
3090 SetVolumeSync(Sync, volptr);
3092 /* Handle the particular type of set locking, type */
3093 errorCode = HandleLocking(targetptr, rights, type);
3096 /* Write the all modified vnodes (parent, new files) and volume back */
3097 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3099 if ((errorCode == VREADONLY) && (type == LockRead))
3100 errorCode = 0; /* allow read locks on RO volumes without saving state */
3102 ViceLog(2,("SAFS_SetLock returns %d\n", errorCode));
3108 SRXAFS_OldSetLock(tcon, Fid, type, Sync)
3109 struct AFSVolSync *Sync;
3110 struct rx_connection *tcon; /* Rx connection handle */
3111 struct AFSFid *Fid; /* Fid of file to lock */
3112 ViceLockType type; /* Type of lock (Read or write) */
3115 return SRXAFS_SetLock(tcon, Fid, type, Sync);
3117 } /*SRXAFS_OldSetLock*/
3120 SRXAFS_SetLock (tcon, Fid, type, Sync)
3121 struct AFSVolSync *Sync;
3122 struct rx_connection *tcon; /* Rx connection handle */
3123 struct AFSFid *Fid; /* Fid of file to lock */
3124 ViceLockType type; /* Type of lock (Read or write) */
3128 struct rx_call *tcall = (struct rx_call *) tcon;
3129 #if FS_STATS_DETAILED
3130 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3131 struct timeval opStartTime,
3132 opStopTime; /* Start/stop times for RPC op*/
3133 struct timeval elapsedTime; /* Transfer time */
3136 * Set our stats pointer, remember when the RPC operation started, and
3137 * tally the operation.
3139 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
3143 TM_GetTimeOfDay(&opStartTime, 0);
3144 #endif /* FS_STATS_DETAILED */
3146 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3149 code = SAFSS_SetLock (tcon, Fid, type, Sync);
3152 CallPostamble(tcon);
3154 #if FS_STATS_DETAILED
3155 TM_GetTimeOfDay(&opStopTime, 0);
3158 (opP->numSuccesses)++;
3159 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3160 fs_stats_AddTo((opP->sumTime), elapsedTime);
3161 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3162 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3163 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3165 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3166 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3170 #endif /* FS_STATS_DETAILED */
3172 osi_auditU (tcall, SetLockEvent, code, AUD_FID, Fid, AUD_LONG, type, AUD_END);
3175 } /*SRXAFS_SetLock*/
3179 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
3180 * merged into it when possible.
3182 SAFSS_ExtendLock (tcon, Fid, Sync)
3183 struct rx_connection *tcon; /* Rx connection handle */
3184 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3185 struct AFSVolSync *Sync;
3188 Vnode * targetptr = 0; /* vnode of input file */
3189 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3190 int errorCode = 0; /* error code */
3191 Volume * volptr = 0; /* pointer to the volume header */
3192 struct client * client; /* pointer to client structure */
3193 afs_int32 rights, anyrights; /* rights for this and any user */
3194 struct client *t_client; /* tmp ptr to client data */
3195 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3197 /* Get ptr to client data for user Id for logging */
3198 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3199 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3200 ViceLog(1,("SAFS_ExtendLock Fid = %u.%d.%d, Host %s, Id %d\n",
3201 Fid->Volume, Fid->Vnode, Fid->Unique,
3202 inet_ntoa(logHostAddr), t_client->ViceId));
3204 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
3207 * Get the vnode and volume for the desired file along with the caller's
3210 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3211 DONTCHECK, &parentwhentargetnotdir,
3212 &client, WRITE_LOCK, &rights, &anyrights)) {
3213 goto Bad_ExtendLock;
3216 /* set volume synchronization information */
3217 SetVolumeSync(Sync, volptr);
3219 /* Handle the actual lock extension */
3220 errorCode = HandleLocking(targetptr, rights, LockExtend);
3223 /* Put back file's vnode and volume */
3224 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3226 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3227 errorCode = 0; /* under our generous policy re RO vols */
3229 ViceLog(2,("SAFS_ExtendLock returns %d\n", errorCode));
3232 } /*SAFSS_ExtendLock*/
3235 SRXAFS_OldExtendLock (tcon, Fid, Sync)
3236 struct AFSVolSync *Sync;
3237 struct rx_connection *tcon; /* Rx connection handle */
3238 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3241 return SRXAFS_ExtendLock(tcon, Fid, Sync);
3243 } /*SRXAFS_OldExtendLock*/
3246 SRXAFS_ExtendLock (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 */
3253 struct rx_call *tcall = (struct rx_call *) tcon;
3254 #if FS_STATS_DETAILED
3255 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3256 struct timeval opStartTime,
3257 opStopTime; /* Start/stop times for RPC op*/
3258 struct timeval elapsedTime; /* Transfer time */
3261 * Set our stats pointer, remember when the RPC operation started, and
3262 * tally the operation.
3264 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
3268 TM_GetTimeOfDay(&opStartTime, 0);
3269 #endif /* FS_STATS_DETAILED */
3271 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3272 goto Bad_ExtendLock;
3274 code = SAFSS_ExtendLock (tcon, Fid, Sync);
3277 CallPostamble(tcon);
3279 #if FS_STATS_DETAILED
3280 TM_GetTimeOfDay(&opStopTime, 0);
3283 (opP->numSuccesses)++;
3284 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3285 fs_stats_AddTo((opP->sumTime), elapsedTime);
3286 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3287 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3288 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3290 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3291 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3296 #endif /* FS_STATS_DETAILED */
3298 osi_auditU (tcall, ExtendLockEvent, code, AUD_FID, Fid , AUD_END);
3301 } /*SRXAFS_ExtendLock*/
3305 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
3306 * merged into it when possible.
3308 SAFSS_ReleaseLock (tcon, Fid, Sync)
3309 struct rx_connection *tcon; /* Rx connection handle */
3310 struct AFSFid *Fid; /* Fid of file to release lock */
3311 struct AFSVolSync *Sync;
3314 Vnode * targetptr = 0; /* vnode of input file */
3315 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3316 int errorCode = 0; /* error code */
3317 Volume * volptr = 0; /* pointer to the volume header */
3318 struct client * client; /* pointer to client structure */
3319 afs_int32 rights, anyrights; /* rights for this and any user */
3320 struct client *t_client; /* tmp ptr to client data */
3321 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3323 /* Get ptr to client data for user Id for logging */
3324 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3325 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3326 ViceLog(1,("SAFS_ReleaseLock Fid = %u.%d.%d, Host %s, Id %d\n",
3327 Fid->Volume, Fid->Vnode, Fid->Unique,
3328 inet_ntoa(logHostAddr), t_client->ViceId));
3330 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
3333 * Get the vnode and volume for the desired file along with the caller's
3336 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3337 DONTCHECK, &parentwhentargetnotdir,
3338 &client, WRITE_LOCK, &rights, &anyrights)) {
3339 goto Bad_ReleaseLock;
3342 /* set volume synchronization information */
3343 SetVolumeSync(Sync, volptr);
3345 /* Handle the actual lock release */
3346 if (errorCode = HandleLocking(targetptr, rights, LockRelease))
3347 goto Bad_ReleaseLock;
3349 /* if no more locks left, a callback would be triggered here */
3350 if (targetptr->disk.lock.lockCount <= 0) {
3351 /* convert the write lock to a read lock before breaking callbacks */
3352 VVnodeWriteToRead(&errorCode, targetptr);
3353 assert(!errorCode || errorCode == VSALVAGE);
3354 BreakCallBack(client->host, Fid, 0);
3358 /* Put back file's vnode and volume */
3359 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3361 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3362 errorCode = 0; /* under our generous policy re RO vols */
3364 ViceLog(2,("SAFS_ReleaseLock returns %d\n", errorCode));
3367 } /*SAFSS_ReleaseLock*/
3370 SRXAFS_OldReleaseLock (tcon, Fid, Sync)
3371 struct AFSVolSync *Sync;
3372 struct rx_connection *tcon; /* Rx connection handle */
3373 struct AFSFid *Fid; /* Fid of file to release lock */
3376 return SRXAFS_ReleaseLock(tcon, Fid, Sync);
3378 } /*SRXAFS_OldReleaseLock*/
3381 SRXAFS_ReleaseLock (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 */
3388 struct rx_call *tcall = (struct rx_call *) tcon;
3389 #if FS_STATS_DETAILED
3390 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3391 struct timeval opStartTime,
3392 opStopTime; /* Start/stop times for RPC op*/
3393 struct timeval elapsedTime; /* Transfer time */
3396 * Set our stats pointer, remember when the RPC operation started, and
3397 * tally the operation.
3399 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
3403 TM_GetTimeOfDay(&opStartTime, 0);
3404 #endif /* FS_STATS_DETAILED */
3406 if (code = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3407 goto Bad_ReleaseLock;
3409 code = SAFSS_ReleaseLock (tcon, Fid, Sync);
3412 CallPostamble(tcon);
3414 #if FS_STATS_DETAILED
3415 TM_GetTimeOfDay(&opStopTime, 0);
3418 (opP->numSuccesses)++;
3419 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3420 fs_stats_AddTo((opP->sumTime), elapsedTime);
3421 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3422 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3423 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3425 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3426 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3431 #endif /* FS_STATS_DETAILED */
3433 osi_auditU (tcall, ReleaseLockEvent, code, AUD_FID, Fid , AUD_END);
3436 } /*SRXAFS_ReleaseLock*/
3440 * This routine is called exclusively by SRXAFS_GetStatistics(), and should be
3441 * merged into it when possible.
3443 static GetStatistics (tcon, Statistics)
3444 struct rx_connection *tcon; /* Rx connection handle */
3445 struct AFSStatistics *Statistics; /* Placeholder for returned AFS statistics */
3447 ViceLog(1, ("SAFS_GetStatistics Received\n"));
3449 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
3451 bzero(Statistics, sizeof(*Statistics));
3452 SetAFSStats(Statistics);
3453 SetVolumeStats(Statistics);
3454 SetSystemStats(Statistics);
3461 SRXAFS_GetStatistics (tcon, Statistics)
3462 struct rx_connection *tcon; /* Rx connection handle */
3463 struct AFSStatistics *Statistics; /* Placeholder for returned AFS statistics */
3467 #if FS_STATS_DETAILED
3468 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3469 struct timeval opStartTime,
3470 opStopTime; /* Start/stop times for RPC op*/
3471 struct timeval elapsedTime; /* Transfer time */
3474 * Set our stats pointer, remember when the RPC operation started, and
3475 * tally the operation.
3477 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
3481 TM_GetTimeOfDay(&opStartTime, 0);
3482 #endif /* FS_STATS_DETAILED */
3484 if (code = CallPreamble((struct rx_call **) &tcon, NOTACTIVECALL))
3485 goto Bad_GetStatistics;
3487 code = GetStatistics (tcon, Statistics);
3490 CallPostamble(tcon);
3492 #if FS_STATS_DETAILED
3493 TM_GetTimeOfDay(&opStopTime, 0);
3496 (opP->numSuccesses)++;
3497 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3498 fs_stats_AddTo((opP->sumTime), elapsedTime);
3499 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3500 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3501 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3503 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3504 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3508 #endif /* FS_STATS_DETAILED */
3512 } /*SRXAFS_GetStatistics*/
3515 /*------------------------------------------------------------------------
3516 * EXPORTED SRXAFS_XStatsVersion
3519 * Routine called by the server-side RPC interface to implement
3520 * pulling out the xstat version number for the File Server.
3523 * a_versionP : Ptr to the version number variable to set.
3529 * Nothing interesting.
3533 *------------------------------------------------------------------------*/
3535 int SRXAFS_XStatsVersion(a_call, a_versionP)
3536 struct rx_call *a_call;
3537 afs_int32 *a_versionP;
3539 { /*SRXAFS_XStatsVersion*/
3541 #if FS_STATS_DETAILED
3542 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3543 struct timeval opStartTime,
3544 opStopTime; /* Start/stop times for RPC op*/
3545 struct timeval elapsedTime; /* Transfer time */
3548 * Set our stats pointer, remember when the RPC operation started, and
3549 * tally the operation.
3551 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
3555 TM_GetTimeOfDay(&opStartTime, 0);
3556 #endif /* FS_STATS_DETAILED */
3558 *a_versionP = AFS_XSTAT_VERSION;
3560 #if FS_STATS_DETAILED
3561 TM_GetTimeOfDay(&opStopTime, 0);
3562 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3563 fs_stats_AddTo((opP->sumTime), elapsedTime);
3564 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3565 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3566 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3568 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3569 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3572 (opP->numSuccesses)++;
3574 #endif /* FS_STATS_DETAILED */
3578 } /*SRXAFS_XStatsVersion*/
3581 /*------------------------------------------------------------------------
3582 * PRIVATE FillPerfValues
3585 * Routine called to fill a regular performance data structure.
3588 * a_perfP : Ptr to perf structure to fill
3594 * Various collections need this info, so the guts were put in
3595 * this separate routine.
3599 *------------------------------------------------------------------------*/
3601 static void FillPerfValues(a_perfP)
3602 struct afs_PerfStats *a_perfP;
3604 { /*FillPerfValues*/
3606 int dir_Buffers; /*# buffers in use by dir package*/
3607 int dir_Calls; /*# read calls in dir package*/
3608 int dir_IOs; /*# I/O ops in dir package*/
3611 * Vnode cache section.
3613 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
3614 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
3615 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
3616 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
3617 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
3618 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
3619 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
3620 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
3621 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
3622 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
3623 a_perfP->vcache_H_Entries = VolumeCacheSize;
3624 a_perfP->vcache_H_Gets = VolumeGets;
3625 a_perfP->vcache_H_Replacements = VolumeReplacements;
3628 * Directory section.
3630 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
3631 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
3632 a_perfP->dir_Calls = (afs_int32 )dir_Calls;
3633 a_perfP->dir_IOs = (afs_int32) dir_IOs;
3638 a_perfP->rx_packetRequests =
3639 (afs_int32) rx_stats.packetRequests;
3640 a_perfP->rx_noPackets_RcvClass =
3641 (afs_int32) rx_stats.receivePktAllocFailures;
3642 a_perfP->rx_noPackets_SendClass =
3643 (afs_int32) rx_stats.sendPktAllocFailures;
3644 a_perfP->rx_noPackets_SpecialClass =
3645 (afs_int32) rx_stats.specialPktAllocFailures;
3646 a_perfP->rx_socketGreedy =
3647 (afs_int32) rx_stats.socketGreedy;
3648 a_perfP->rx_bogusPacketOnRead =
3649 (afs_int32) rx_stats.bogusPacketOnRead;
3650 a_perfP->rx_bogusHost =
3651 (afs_int32) rx_stats.bogusHost;
3652 a_perfP->rx_noPacketOnRead =
3653 (afs_int32) rx_stats.noPacketOnRead;
3654 a_perfP->rx_noPacketBuffersOnRead =
3655 (afs_int32) rx_stats.noPacketBuffersOnRead;
3656 a_perfP->rx_selects =
3657 (afs_int32) rx_stats.selects;
3658 a_perfP->rx_sendSelects =
3659 (afs_int32) rx_stats.sendSelects;
3660 a_perfP->rx_packetsRead_RcvClass =
3661 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
3662 a_perfP->rx_packetsRead_SendClass =
3663 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
3664 a_perfP->rx_packetsRead_SpecialClass =
3665 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
3666 a_perfP->rx_dataPacketsRead =
3667 (afs_int32) rx_stats.dataPacketsRead;
3668 a_perfP->rx_ackPacketsRead =
3669 (afs_int32) rx_stats.ackPacketsRead;
3670 a_perfP->rx_dupPacketsRead =
3671 (afs_int32) rx_stats.dupPacketsRead;
3672 a_perfP->rx_spuriousPacketsRead =
3673 (afs_int32) rx_stats.spuriousPacketsRead;
3674 a_perfP->rx_packetsSent_RcvClass =
3675 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
3676 a_perfP->rx_packetsSent_SendClass =
3677 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
3678 a_perfP->rx_packetsSent_SpecialClass =
3679 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
3680 a_perfP->rx_ackPacketsSent =
3681 (afs_int32) rx_stats.ackPacketsSent;
3682 a_perfP->rx_pingPacketsSent =
3683 (afs_int32) rx_stats.pingPacketsSent;
3684 a_perfP->rx_abortPacketsSent =
3685 (afs_int32) rx_stats.abortPacketsSent;
3686 a_perfP->rx_busyPacketsSent =
3687 (afs_int32) rx_stats.busyPacketsSent;
3688 a_perfP->rx_dataPacketsSent =
3689 (afs_int32) rx_stats.dataPacketsSent;
3690 a_perfP->rx_dataPacketsReSent =
3691 (afs_int32) rx_stats.dataPacketsReSent;
3692 a_perfP->rx_dataPacketsPushed =
3693 (afs_int32) rx_stats.dataPacketsPushed;
3694 a_perfP->rx_ignoreAckedPacket =
3695 (afs_int32) rx_stats.ignoreAckedPacket;
3696 a_perfP->rx_totalRtt_Sec =
3697 (afs_int32) rx_stats.totalRtt.sec;
3698 a_perfP->rx_totalRtt_Usec =
3699 (afs_int32) rx_stats.totalRtt.usec;
3700 a_perfP->rx_minRtt_Sec =
3701 (afs_int32) rx_stats.minRtt.sec;
3702 a_perfP->rx_minRtt_Usec =
3703 (afs_int32) rx_stats.minRtt.usec;
3704 a_perfP->rx_maxRtt_Sec =
3705 (afs_int32) rx_stats.maxRtt.sec;
3706 a_perfP->rx_maxRtt_Usec =
3707 (afs_int32) rx_stats.maxRtt.usec;
3708 a_perfP->rx_nRttSamples =
3709 (afs_int32) rx_stats.nRttSamples;
3710 a_perfP->rx_nServerConns =
3711 (afs_int32) rx_stats.nServerConns;
3712 a_perfP->rx_nClientConns =
3713 (afs_int32) rx_stats.nClientConns;
3714 a_perfP->rx_nPeerStructs =
3715 (afs_int32) rx_stats.nPeerStructs;
3716 a_perfP->rx_nCallStructs =
3717 (afs_int32) rx_stats.nCallStructs;
3718 a_perfP->rx_nFreeCallStructs =
3719 (afs_int32) rx_stats.nFreeCallStructs;
3721 a_perfP->host_NumHostEntries = HTs;
3722 a_perfP->host_HostBlocks = HTBlocks;
3723 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
3724 &(a_perfP->host_HostsInSameNetOrSubnet),
3725 &(a_perfP->host_HostsInDiffSubnet),
3726 &(a_perfP->host_HostsInDiffNetwork));
3727 a_perfP->host_NumClients = CEs;
3728 a_perfP->host_ClientBlocks = CEBlocks;
3730 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
3732 } /*FillPerfValues*/
3735 /*------------------------------------------------------------------------
3736 * EXPORTED SRXAFS_GetXStats
3739 * Routine called by the server-side callback RPC interface to
3740 * implement getting the given data collection from the extended
3741 * File Server statistics.
3744 * a_call : Ptr to Rx call on which this request came in.
3745 * a_clientVersionNum : Client version number.
3746 * a_opCode : Desired operation.
3747 * a_serverVersionNumP : Ptr to version number to set.
3748 * a_timeP : Ptr to time value (seconds) to set.
3749 * a_dataP : Ptr to variable array structure to return
3756 * Nothing interesting.
3760 *------------------------------------------------------------------------*/
3762 int SRXAFS_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVersionNumP, a_timeP, a_dataP)
3763 struct rx_call *a_call;
3764 afs_int32 a_clientVersionNum;
3765 afs_int32 a_collectionNumber;
3766 afs_int32 *a_srvVersionNumP;
3768 AFS_CollData *a_dataP;
3770 { /*SRXAFS_GetXStats*/
3772 register int code; /*Return value*/
3773 afs_int32 *dataBuffP; /*Ptr to data to be returned*/
3774 afs_int32 dataBytes; /*Bytes in data buffer*/
3775 #if FS_STATS_DETAILED
3776 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3777 struct timeval opStartTime,
3778 opStopTime; /* Start/stop times for RPC op*/
3779 struct timeval elapsedTime; /* Transfer time */
3782 * Set our stats pointer, remember when the RPC operation started, and
3783 * tally the operation.
3785 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
3789 TM_GetTimeOfDay(&opStartTime, 0);
3790 #endif /* FS_STATS_DETAILED */
3793 * Record the time of day and the server version number.
3795 *a_srvVersionNumP = AFS_XSTAT_VERSION;
3796 *a_timeP = FT_ApproxTime();
3799 * Stuff the appropriate data in there (assume victory)
3803 ViceLog(1, ("Received GetXStats call for collection %d\n", a_collectionNumber));
3807 * We're not keeping stats, so just return successfully with
3810 a_dataP->AFS_CollData_len = 0;
3811 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3814 switch(a_collectionNumber) {
3815 case AFS_XSTATSCOLL_CALL_INFO:
3817 * Pass back all the call-count-related data.
3819 * >>> We are forced to allocate a separate area in which to
3820 * >>> put this stuff in by the RPC stub generator, since it
3821 * >>> will be freed at the tail end of the server stub code.
3825 * I don't think call-level stats are being collected yet
3826 * for the File Server.
3828 dataBytes = sizeof(struct afs_Stats);
3829 dataBuffP = (afs_int32 *)malloc(dataBytes);
3830 bcopy(&afs_cmstats, dataBuffP, dataBytes);
3831 a_dataP->AFS_CollData_len = dataBytes>>2;
3832 a_dataP->AFS_CollData_val = dataBuffP;
3834 a_dataP->AFS_CollData_len = 0;
3835 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3839 case AFS_XSTATSCOLL_PERF_INFO:
3841 * Pass back all the regular performance-related data.
3843 * >>> We are forced to allocate a separate area in which to
3844 * >>> put this stuff in by the RPC stub generator, since it
3845 * >>> will be freed at the tail end of the server stub code.
3848 afs_perfstats.numPerfCalls++;
3849 FillPerfValues(&afs_perfstats);
3852 * Don't overwrite the spares at the end.
3855 dataBytes = sizeof(struct afs_PerfStats);
3856 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
3857 bcopy(&afs_perfstats, dataBuffP, dataBytes);
3858 a_dataP->AFS_CollData_len = dataBytes>>2;
3859 a_dataP->AFS_CollData_val = dataBuffP;
3862 case AFS_XSTATSCOLL_FULL_PERF_INFO:
3864 * Pass back the full collection of performance-related data.
3865 * We have to stuff the basic, overall numbers in, but the
3866 * detailed numbers are kept in the structure already.
3868 * >>> We are forced to allocate a separate area in which to
3869 * >>> put this stuff in by the RPC stub generator, since it
3870 * >>> will be freed at the tail end of the server stub code.
3873 afs_perfstats.numPerfCalls++;
3874 #if FS_STATS_DETAILED
3875 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
3876 FillPerfValues(&afs_FullPerfStats.overall);
3879 * Don't overwrite the spares at the end.
3882 dataBytes = sizeof(struct fs_stats_FullPerfStats);
3883 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
3884 bcopy(&afs_FullPerfStats, dataBuffP, dataBytes);
3885 a_dataP->AFS_CollData_len = dataBytes>>2;
3886 a_dataP->AFS_CollData_val = dataBuffP;
3892 * Illegal collection number.
3894 a_dataP->AFS_CollData_len = 0;
3895 a_dataP->AFS_CollData_val = (afs_int32 *)0;
3897 } /*Switch on collection number*/
3899 #if FS_STATS_DETAILED
3900 TM_GetTimeOfDay(&opStopTime, 0);
3903 (opP->numSuccesses)++;
3904 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3905 fs_stats_AddTo((opP->sumTime), elapsedTime);
3906 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3907 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3908 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3910 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3911 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3916 #endif /* FS_STATS_DETAILED */
3920 } /*SRXAFS_GetXStats*/
3923 SRXAFS_GiveUpCallBacks (tcon, FidArray, CallBackArray)
3924 struct rx_connection *tcon; /* Rx connection handle */
3925 struct AFSCBFids *FidArray; /* Array of Fids entries */
3926 struct AFSCBs *CallBackArray; /* array of callbacks */
3929 afs_int32 errorCode;
3931 struct client *client;
3932 #if FS_STATS_DETAILED
3933 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3934 struct timeval opStartTime,
3935 opStopTime; /* Start/stop times for RPC op*/
3936 struct timeval elapsedTime; /* Transfer time */
3939 * Set our stats pointer, remember when the RPC operation started, and
3940 * tally the operation.
3942 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
3946 TM_GetTimeOfDay(&opStartTime, 0);
3947 #endif /* FS_STATS_DETAILED */
3949 ViceLog(1, ("SAFS_GiveUpCallBacks (Noffids=%d)\n", FidArray->AFSCBFids_len));
3951 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
3953 if (errorCode = CallPreamble((struct rx_call **) &tcon, ACTIVECALL))
3954 goto Bad_GiveUpCallBacks;
3956 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
3957 ViceLog(0, ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
3958 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
3959 (tcon->peer ? tcon->peer->host : 0)));
3961 goto Bad_GiveUpCallBacks;
3964 errorCode = GetClient(tcon, &client);
3966 for (i=0; i < FidArray->AFSCBFids_len; i++) {
3967 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
3968 DeleteCallBack(client->host, fid);
3972 Bad_GiveUpCallBacks:
3973 CallPostamble(tcon);
3975 #if FS_STATS_DETAILED
3976 TM_GetTimeOfDay(&opStopTime, 0);
3977 if (errorCode == 0) {
3979 (opP->numSuccesses)++;
3980 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3981 fs_stats_AddTo((opP->sumTime), elapsedTime);
3982 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3983 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3984 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3986 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3987 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3991 #endif /* FS_STATS_DETAILED */
3995 } /*SRXAFS_GiveUpCallBacks*/
3998 SRXAFS_NGetVolumeInfo (tcon, avolid, avolinfo)
3999 struct rx_connection *tcon; /* Rx connection handle */
4000 char *avolid; /* Volume name/id */
4001 struct AFSVolumeInfo *avolinfo; /* Returned volume's specific info */
4004 return(VNOVOL); /* XXX Obsolete routine XXX */
4006 } /*SRXAFS_NGetVolumeInfo*/
4010 * Dummy routine. Should never be called (the cache manager should only
4011 * invoke this interface when communicating with a AFS/DFS Protocol
4014 SRXAFS_Lookup(call_p, afs_dfid_p, afs_name_p, afs_fid_p,
4015 afs_status_p, afs_dir_status_p, afs_callback_p, afs_sync_p)
4016 struct rx_call *call_p; /* Rx call handle */
4017 struct AFSFid *afs_dfid_p; /* Directory */
4018 char *afs_name_p; /* Name of file to lookup */
4019 struct AFSFid *afs_fid_p; /* Place to return fid of file */
4020 struct AFSFetchStatus *afs_status_p; /* Place to return file status */
4021 struct AFSFetchStatus *afs_dir_status_p;/* Place to return file status */
4022 struct AFSCallBack *afs_callback_p; /* If r/w, callback promise for Fid */
4023 struct AFSVolSync *afs_sync_p; /* Volume sync info */
4029 SRXAFS_FlushCPS(tcon, vids, addrs, spare1, spare2, spare3)
4030 struct rx_connection *tcon;
4031 struct ViceIds *vids;
4032 struct IPAddrs *addrs;
4033 afs_int32 spare1, *spare2, *spare3;
4036 afs_int32 nids, naddrs;
4037 afs_int32 *vd, *addr;
4038 int errorCode = 0; /* return code to caller */
4039 struct client *client;
4040 struct rx_call *tcall = (struct rx_call *) tcon;
4042 ViceLog(1, ("SRXAFS_FlushCPS\n"));
4044 AFSCallStats.TotalCalls++;
4046 nids = vids->ViceIds_len; /* # of users in here */
4047 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
4048 if (nids < 0 || naddrs < 0) {
4053 vd = vids->ViceIds_val;
4054 for (i=0; i<nids; i++, vd++) {
4057 client = h_ID2Client(*vd); /* returns client locked, or NULL */
4061 BoostSharedLock(&client->lock);
4062 client->prfail = 2; /* Means re-eval client's cps */
4065 rx_SetRock(((struct rx_connection *) client->tcon), 0);
4068 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
4069 free(client->CPS.prlist_val);
4070 client->CPS.prlist_val = (afs_int32 *)0;
4072 ReleaseWriteLock(&client->lock);
4075 addr = addrs->IPAddrs_val;
4076 for (i=0; i<naddrs; i++, addr++) {
4078 h_flushhostcps(*addr, 7001);
4082 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
4084 } /*SRXAFS_FlushCPS */
4088 static GetVolumeInfo (tcon, avolid, avolinfo)
4089 struct rx_connection *tcon; /* Rx Connection handle */
4090 char *avolid; /* Volume name/id */
4091 struct VolumeInfo *avolinfo; /* Returned volume's specific info */
4094 int errorCode = 0; /* error code */
4097 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
4100 errorCode = TryLocalVLServer(avolid, avolinfo);
4101 ViceLog(1, ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
4102 errorCode, avolinfo->Vid, avolinfo->Type,
4103 avolinfo->Server0, avolinfo->Server1, avolinfo->Server2,
4104 avolinfo->Server3));
4109 /* worthless hack to let CS keep running ancient software */
4110 static afs_vtoi(aname)
4111 register char *aname;
4114 register afs_int32 temp;
4118 while(tc = *aname++) {
4119 if (tc > '9' || tc < '0') return 0; /* invalid name */
4127 * may get name or #, but must handle all weird cases (recognize readonly
4128 * or backup volumes by name or #
4130 static CopyVolumeEntry(aname, ave, av)
4132 register struct VolumeInfo *av;
4133 register struct vldbentry *ave;
4136 register int i, j, vol;
4137 afs_int32 mask, whichType;
4138 afs_uint32 *serverHost, *typePtr;
4140 /* figure out what type we want if by name */
4142 if (i >= 8 && strcmp(aname+i-7, ".backup") == 0)
4143 whichType = BACKVOL;
4144 else if (i >= 10 && strcmp(aname+i-9, ".readonly")==0)
4146 else whichType = RWVOL;
4148 vol = afs_vtoi(aname);
4149 if (vol == 0) vol = ave->volumeId[whichType];
4152 * Now vol has volume # we're interested in. Next, figure out the type
4153 * of the volume by looking finding it in the vldb entry
4155 if ((ave->flags&VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
4159 else if ((ave->flags&VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
4163 else if ((ave->flags&VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
4164 mask = VLSF_RWVOL; /* backup always is on the same volume as p