2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
37 #undef SHARED /* XXX */
42 #include <sys/param.h>
44 #include <netinet/in.h>
46 #include <sys/ioctl.h>
47 #include <sys/socket.h>
48 #ifndef AFS_LINUX20_ENV
50 #include <netinet/if_ether.h>
57 /* included early because of name conflict on IOPEN */
58 #include <sys/inode.h>
62 #endif /* AFS_HPUX_ENV */
66 #include <afs/assert.h>
69 #include <afs/afsint.h>
70 #include <afs/vldbint.h>
71 #include <afs/errors.h>
72 #include <afs/ihandle.h>
73 #include <afs/vnode.h>
74 #include <afs/volume.h>
76 #include <afs/ptclient.h>
77 #include <afs/prs_fs.h>
79 #include <rx/rx_globals.h>
81 #if ! defined(AFS_SGI_ENV) && ! defined(AFS_AIX32_ENV) && ! defined(AFS_NT40_ENV) && ! defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
84 #if !defined(AFS_NT40_ENV)
87 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
89 #include <sys/statfs.h>
90 #include <sys/lockf.h>
92 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
97 #include <afs/cellconfig.h>
100 #include <afs/auth.h>
102 #include <afs/partition.h>
105 #include <afs/audit.h>
106 #include <afs/afsutil.h>
108 #ifdef AFS_PTHREAD_ENV
109 pthread_mutex_t fileproc_glock_mutex;
110 #endif /* AFS_PTHREAD_ENV */
113 /* Useful local defines used by this module */
116 #define MustNOTBeDIR 1
120 #define TVS_SSTATUS 2
123 #define TVS_MKDIR 0x10
125 #define CHK_FETCH 0x10
126 #define CHK_FETCHDATA 0x10
127 #define CHK_FETCHACL 0x11
128 #define CHK_FETCHSTATUS 0x12
129 #define CHK_STOREDATA 0x00
130 #define CHK_STOREACL 0x01
131 #define CHK_STORESTATUS 0x02
133 #define OWNERREAD 0400
134 #define OWNERWRITE 0200
135 #define OWNEREXEC 0100
136 #ifdef USE_GROUP_PERMS
137 #define GROUPREAD 0040
138 #define GROUPWRITE 0020
139 #define GROUPREXEC 0010
142 /* The following errors were not defined in NT. They are given unique
143 * names here to avoid any potential collision.
145 #define FSERR_ELOOP 90
146 #define FSERR_EOPNOTSUPP 122
147 #define FSERR_ECONNREFUSED 130
149 #define NOTACTIVECALL 0
152 extern struct afsconf_dir *confDir;
153 extern afs_int32 dataVersionHigh;
156 extern struct AFSCallStatistics AFSCallStats;
157 struct AFSCallStatistics AFSCallStats;
158 #if FS_STATS_DETAILED
159 struct fs_stats_FullPerfStats afs_FullPerfStats;
160 extern int AnonymousID;
161 #endif /* FS_STATS_DETAILED */
162 #if TRANSARC_VOL_STATS
163 static const char nullString[] = "";
164 #endif /* TRANSARC_VOL_STATS */
167 afs_int32 NothingYet;
170 struct afs_FSStats afs_fsstats;
172 void ResetDebug(), SetDebug(), Terminate();
173 int CopyOnWrite(); /* returns 0 on success */
176 void SetSystemStats(), SetAFSStats(), SetVolumeStats();
180 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
182 extern afs_int32 implicitAdminRights;
184 static TryLocalVLServer();
186 void GetStatus(Vnode *targetptr, AFSFetchStatus *status, afs_int32 rights, afs_int32 anyrights, Vnode *parentptr);
189 * Externals used by the xstat code.
191 extern int VolumeCacheSize, VolumeGets, VolumeReplacements;
192 extern int CEs, CEBlocks;
194 extern int HTs, HTBlocks;
196 #ifdef AFS_SGI_XFS_IOPS_ENV
197 #include <afs/xfsattrs.h>
198 static int GetLinkCount(avp, astat)
202 if (!strcmp("xfs", astat->st_fstype)) {
203 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
206 return astat->st_nlink;
209 #define GetLinkCount(V, S) (S)->st_nlink
212 afs_int32 SpareComp(avolp)
216 register afs_int32 temp;
220 temp = V_maxquota(avolp);
222 /* no matter; doesn't check in this case */
226 temp = (temp * PctSpare) / 100;
239 * Set the volume synchronization parameter for this volume. If it changes,
240 * the Cache Manager knows that the volume must be purged from the stat cache.
242 static SetVolumeSync(async, avol)
243 register struct AFSVolSync *async;
244 register Volume *avol;
248 /* date volume instance was created */
251 async->spare1 = avol->header->diskstuff.creationDate;
264 * Note that this function always returns a held host, so
265 * that CallPostamble can block without the host's disappearing.
266 * Call returns rx connection in passed in *tconn
268 static CallPreamble(acall, activecall, tconn)
269 register struct rx_call *acall;
271 struct rx_connection **tconn;
275 struct client *tclient;
280 ViceLog (0, ("CallPreamble: unexpected null tconn!\n"));
283 *tconn = rx_ConnectionOf(acall);
287 tclient = h_FindClient_r(*tconn);
288 if (tclient->prfail == 1) { /* couldn't get the CPS */
290 h_ReleaseClient_r(tclient);
291 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
295 retry_flag=0; /* Retry once */
297 /* Take down the old connection and re-read the key file */
298 ViceLog(0, ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
300 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
303 h_ReleaseClient_r(tclient);
305 ViceLog(0,("CallPreamble: couldn't reconnect to ptserver\n"));
309 tclient->prfail = 2; /* Means re-eval client's cps */
310 h_ReleaseClient_r(tclient);
314 thost = tclient->host;
315 tclient->LastCall = thost->LastCall = FT_ApproxTime();
316 if (activecall) /* For all but "GetTime" calls */
317 thost->ActiveCall = thost->LastCall;
320 if (thost->hostFlags & HOSTDELETED) {
321 ViceLog(3,("Discarded a packet for deleted host %s\n",afs_inet_ntoa_r(thost->host,hoststr)));
322 code = VBUSY; /* raced, so retry */
324 else if (thost->hostFlags & VENUSDOWN) {
325 if (BreakDelayedCallBacks_r(thost)) {
326 ViceLog(0,("BreakDelayedCallbacks FAILED for host %s which IS UP. Possible network or routing failure.\n",
327 afs_inet_ntoa_r(thost->host, hoststr)));
328 if ( MultiProbeAlternateAddress_r (thost) ) {
329 ViceLog(0, ("MultiProbe failed to find new address for host %s:%d\n",
330 afs_inet_ntoa_r(thost->host, hoststr), thost->port));
333 ViceLog(0, ("MultiProbe found new address for host %s:%d\n",
334 afs_inet_ntoa_r(thost->host, hoststr), thost->port));
335 if (BreakDelayedCallBacks_r(thost)) {
336 ViceLog(0,("BreakDelayedCallbacks FAILED AGAIN for host %s which IS UP. Possible network or routing failure.\n",
337 afs_inet_ntoa_r(thost->host, hoststr)));
346 h_ReleaseClient_r(tclient);
354 static CallPostamble(aconn)
355 register struct rx_connection *aconn;
359 struct client *tclient;
362 tclient = h_FindClient_r(aconn);
363 thost = tclient->host;
364 h_ReleaseClient_r(tclient);
371 #define AFSV_BUFFERSIZE 16384
373 static struct afs_buffer {
374 struct afs_buffer *next;
375 } *freeBufferList = 0;
376 static int afs_buffersAlloced = 0;
379 static FreeSendBuffer(adata)
380 register struct afs_buffer *adata;
384 afs_buffersAlloced--;
385 adata->next = freeBufferList;
386 freeBufferList = adata;
393 /* allocate space for sender */
394 static char *AllocSendBuffer()
397 register struct afs_buffer *tp;
400 afs_buffersAlloced++;
401 if (!freeBufferList) {
403 return malloc(AFSV_BUFFERSIZE);
406 freeBufferList = tp->next;
410 } /*AllocSendBuffer*/
413 static int VolumeOwner (client, targetptr)
414 register struct client *client;
415 register Vnode *targetptr;
418 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
421 return (client->ViceId == owner);
424 * We don't have to check for host's cps since only regular
425 * viceid are volume owners.
427 return (acl_IsAMember(owner, &client->CPS));
433 static int VolumeRootVnode (targetptr)
437 return ((targetptr->vnodeNumber == ROOTVNODE) &&
438 (targetptr->disk.uniquifier == 1));
440 } /*VolumeRootVnode*/
443 afs_int32 SRXAFS_FetchData (acall, Fid, Pos, Len, OutStatus, CallBack, Sync)
444 struct rx_call *acall; /* Rx call */
445 struct AFSFid *Fid; /* Fid of file to fetch */
446 afs_int32 Pos, Len; /* Not implemented yet */
447 struct AFSFetchStatus *OutStatus; /* Returned status for Fid */
448 struct AFSCallBack *CallBack; /* If r/w return CB for Fid */
449 struct AFSVolSync *Sync; /* synchronization info */
454 code = common_FetchData (acall, Fid, Pos, Len, OutStatus,
459 afs_int32 SRXAFS_FetchData64 (acall, Fid, Pos, Len, OutStatus, CallBack, Sync)
460 struct rx_call *acall; /* Rx call */
461 struct AFSFid *Fid; /* Fid of file to fetch */
462 afs_int64 Pos, Len; /* Not implemented yet */
463 struct AFSFetchStatus *OutStatus; /* Returned status for Fid */
464 struct AFSCallBack *CallBack; /* If r/w return CB for Fid */
465 struct AFSVolSync *Sync; /* synchronization info */
468 afs_int32 tPos, tLen;
471 if (Pos + Len > 0x7fffffff)
475 #else /* AFS_64BIT_ENV */
476 if (Pos.high || Len.high)
480 #endif /* AFS_64BIT_ENV */
482 code = common_FetchData (acall, Fid, tPos, tLen, OutStatus,
487 common_FetchData (acall, Fid, Pos, Len, OutStatus, CallBack, Sync, type)
488 struct rx_call *acall; /* Rx call */
489 struct AFSFid *Fid; /* Fid of file to fetch */
490 afs_int32 Pos, Len; /* Not implemented yet */
491 struct AFSFetchStatus *OutStatus; /* Returned status for Fid */
492 struct AFSCallBack *CallBack; /* If r/w return CB for Fid */
493 struct AFSVolSync *Sync; /* synchronization info */
494 int type; /* 32 bit or 64 bit call */
497 Vnode * targetptr = 0; /* pointer to vnode to fetch */
498 Vnode * parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
499 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
500 int errorCode = 0; /* return code to caller */
501 int fileCode = 0; /* return code from vol package */
502 Volume * volptr = 0; /* pointer to the volume */
503 struct client *client; /* pointer to the client data */
504 struct rx_connection *tcon; /* the connection we're part of */
505 afs_int32 rights, anyrights; /* rights for this and any user */
506 struct client *t_client; /* tmp ptr to client data */
507 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
508 #if FS_STATS_DETAILED
509 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
510 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
511 struct timeval opStartTime,
512 opStopTime; /* Start/stop times for RPC op*/
513 struct timeval xferStartTime,
514 xferStopTime; /* Start/stop times for xfer portion*/
515 struct timeval elapsedTime; /* Transfer time */
516 afs_int32 bytesToXfer; /* # bytes to xfer*/
517 afs_int32 bytesXferred; /* # bytes actually xferred*/
518 int readIdx; /* Index of read stats array to bump*/
519 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
522 * Set our stats pointers, remember when the RPC operation started, and
523 * tally the operation.
525 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
526 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
530 TM_GetTimeOfDay(&opStartTime, 0);
531 #endif /* FS_STATS_DETAILED */
533 ViceLog(1,("SRXAFS_FetchData, Fid = %u.%d.%d\n",
534 Fid->Volume, Fid->Vnode, Fid->Unique));
536 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
539 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
542 /* Get ptr to client data for user Id for logging */
543 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
544 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
545 ViceLog(5,("SRXAFS_FetchData, Fid = %u.%d.%d, Host %s, Id %d\n",
546 Fid->Volume, Fid->Vnode, Fid->Unique,
547 inet_ntoa(logHostAddr), t_client->ViceId));
549 * Get volume/vnode for the fetched file; caller's access rights to
550 * it are also returned
552 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
553 DONTCHECK, &parentwhentargetnotdir,
554 &client, READ_LOCK, &rights, &anyrights))
557 SetVolumeSync(Sync, volptr);
559 #if FS_STATS_DETAILED
561 * Remember that another read operation was performed.
564 if (client->InSameNetwork)
565 readIdx = VOL_STATS_SAME_NET;
567 readIdx = VOL_STATS_DIFF_NET;
568 V_stat_reads(volptr, readIdx)++;
569 if (client->ViceId != AnonymousID) {
570 V_stat_reads(volptr, readIdx+1)++;
573 #endif /* FS_STATS_DETAILED */
575 /* Check whether the caller has permission access to fetch the data */
576 if (errorCode = Check_PermissionRights(targetptr, client, rights,
581 * Drop the read lock on the parent directory after saving the parent
582 * vnode information we need to pass to GetStatus
584 if (parentwhentargetnotdir != NULL) {
585 tparentwhentargetnotdir = *parentwhentargetnotdir;
586 VPutVnode(&fileCode, parentwhentargetnotdir);
587 assert(!fileCode || (fileCode == VSALVAGE));
588 parentwhentargetnotdir = NULL;
591 #if FS_STATS_DETAILED
593 * Remember when the data transfer started.
595 TM_GetTimeOfDay(&xferStartTime, 0);
596 #endif /* FS_STATS_DETAILED */
598 /* actually do the data transfer */
599 #if FS_STATS_DETAILED
600 errorCode = FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
601 &bytesToXfer, &bytesXferred);
603 if (errorCode = FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type))
605 #endif /* FS_STATS_DETAILED */
607 #if FS_STATS_DETAILED
609 * At this point, the data transfer is done, for good or ill. Remember
610 * when the transfer ended, bump the number of successes/failures, and
611 * integrate the transfer size and elapsed time into the stats. If the
612 * operation failed, we jump to the appropriate point.
614 TM_GetTimeOfDay(&xferStopTime, 0);
618 (xferP->numSuccesses)++;
621 * Bump the xfer sum by the number of bytes actually sent, NOT the
624 tot_bytesXferred += bytesXferred;
625 (xferP->sumBytes) += (tot_bytesXferred >> 10);
626 tot_bytesXferred &= 0x3FF;
627 if (bytesXferred < xferP->minBytes)
628 xferP->minBytes = bytesXferred;
629 if (bytesXferred > xferP->maxBytes)
630 xferP->maxBytes = bytesXferred;
633 * Tally the size of the object. Note: we tally the actual size,
634 * NOT the number of bytes that made it out over the wire.
636 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
639 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
642 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
645 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
648 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
651 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
654 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
657 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
662 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
663 fs_stats_AddTo((xferP->sumTime), elapsedTime);
664 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
665 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
666 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
668 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
669 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
674 * Finally, go off to tell our caller the bad news in case the
679 #endif /* FS_STATS_DETAILED */
681 /* write back the OutStatus from the target vnode */
682 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
684 /* if a r/w volume, promise a callback to the caller */
685 if (VolumeWriteable(volptr))
686 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
689 memset(&myFid, 0, sizeof(struct AFSFid));
690 myFid.Volume = Fid->Volume;
691 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
695 /* Update and store volume/vnode and parent vnodes back */
696 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
697 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
700 #if FS_STATS_DETAILED
701 TM_GetTimeOfDay(&opStopTime, 0);
702 if (errorCode == 0) {
704 (opP->numSuccesses)++;
705 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
706 fs_stats_AddTo((opP->sumTime), elapsedTime);
707 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
708 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
709 fs_stats_TimeAssign((opP->minTime), elapsedTime);
711 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
712 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
717 #endif /* FS_STATS_DETAILED */
719 osi_auditU (acall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
722 } /*SRXAFS_FetchData*/
725 afs_int32 SRXAFS_FetchACL (acall, Fid, AccessList, OutStatus, Sync)
726 struct rx_call *acall; /* Rx call */
727 struct AFSFid *Fid; /* Fid of target dir */
728 struct AFSOpaque *AccessList; /* Returned contents of dir's ACL */
729 struct AFSFetchStatus *OutStatus; /* Returned status for the dir */
730 struct AFSVolSync *Sync;
732 Vnode * targetptr = 0; /* pointer to vnode to fetch */
733 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
734 int errorCode = 0; /* return error code to caller */
735 Volume * volptr = 0; /* pointer to the volume */
736 struct client *client; /* pointer to the client data */
737 afs_int32 rights, anyrights; /* rights for this and any user */
738 struct rx_connection *tcon = rx_ConnectionOf(acall);
739 struct client *t_client; /* tmp ptr to client data */
740 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
741 #if FS_STATS_DETAILED
742 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
743 struct timeval opStartTime,
744 opStopTime; /* Start/stop times for RPC op*/
745 struct timeval elapsedTime; /* Transfer time */
748 * Set our stats pointer, remember when the RPC operation started, and
749 * tally the operation.
751 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
755 TM_GetTimeOfDay(&opStartTime, 0);
756 #endif /* FS_STATS_DETAILED */
758 ViceLog(1, ("SAFS_FetchACL, Fid = %u.%d.%d\n",
759 Fid->Volume, Fid->Vnode, Fid->Unique));
761 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
763 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
766 /* Get ptr to client data for user Id for logging */
767 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
768 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
769 ViceLog(5, ("SAFS_FetchACL, Fid = %u.%d.%d, Host %s, Id %d\n",
770 Fid->Volume, Fid->Vnode, Fid->Unique,
771 inet_ntoa(logHostAddr), t_client->ViceId));
773 AccessList->AFSOpaque_len = 0;
774 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
777 * Get volume/vnode for the fetched file; caller's access rights to it
780 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
781 DONTCHECK, &parentwhentargetnotdir,
782 &client, READ_LOCK, &rights, &anyrights))
785 SetVolumeSync(Sync, volptr);
787 /* Check whether we have permission to fetch the ACL */
788 if (errorCode = Check_PermissionRights(targetptr, client, rights,
792 /* Get the Access List from the dir's vnode */
793 if (errorCode = RXFetch_AccessList(targetptr, parentwhentargetnotdir,
797 /* Get OutStatus back From the target Vnode */
798 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
801 /* Update and store volume/vnode and parent vnodes back */
802 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
803 ViceLog(2, ("SAFS_FetchACL returns %d (ACL=%s)\n",
804 errorCode, AccessList->AFSOpaque_val));
807 #if FS_STATS_DETAILED
808 TM_GetTimeOfDay(&opStopTime, 0);
809 if (errorCode == 0) {
811 (opP->numSuccesses)++;
812 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
813 fs_stats_AddTo((opP->sumTime), elapsedTime);
814 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
815 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
816 fs_stats_TimeAssign((opP->minTime), elapsedTime);
818 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
819 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
824 #endif /* FS_STATS_DETAILED */
826 osi_auditU (acall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
829 } /*SRXAFS_FetchACL*/
833 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
834 * merged into it when possible.
836 SAFSS_FetchStatus (acall, Fid, OutStatus, CallBack, Sync)
837 struct rx_call *acall;
838 struct AFSFid *Fid; /* Fid of target file */
839 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
840 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
841 struct AFSVolSync *Sync; /* volume synchronization parm */
844 Vnode * targetptr = 0; /* pointer to vnode to fetch */
845 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
846 int errorCode = 0; /* return code to caller */
847 Volume * volptr = 0; /* pointer to the volume */
848 struct client *client; /* pointer to the client data */
849 afs_int32 rights, anyrights; /* rights for this and any user */
850 struct client *t_client; /* tmp ptr to client data */
851 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
852 struct rx_connection *tcon = rx_ConnectionOf(acall);
854 /* Get ptr to client data for user Id for logging */
855 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
856 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
857 ViceLog(1, ("SAFS_FetchStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
858 Fid->Volume, Fid->Vnode, Fid->Unique,
859 inet_ntoa(logHostAddr), t_client->ViceId));
861 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
864 * Get volume/vnode for the fetched file; caller's rights to it are
867 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
868 DONTCHECK, &parentwhentargetnotdir,
869 &client, READ_LOCK, &rights, &anyrights))
870 goto Bad_FetchStatus;
872 /* set volume synchronization information */
873 SetVolumeSync(Sync, volptr);
875 /* Are we allowed to fetch Fid's status? */
876 if (targetptr->disk.type != vDirectory) {
877 if (errorCode = Check_PermissionRights(targetptr, client, rights,
878 CHK_FETCHSTATUS, 0)) {
879 if (rx_GetCallAbortCode(acall) == errorCode)
880 rx_SetCallAbortCode(acall, 0);
881 goto Bad_FetchStatus;
885 /* set OutStatus From the Fid */
886 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
888 /* If a r/w volume, also set the CallBack state */
889 if (VolumeWriteable(volptr))
890 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
893 memset(&myFid, 0, sizeof(struct AFSFid));
894 myFid.Volume = Fid->Volume;
895 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
899 /* Update and store volume/vnode and parent vnodes back */
900 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
901 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
904 } /*SAFSS_FetchStatus*/
907 afs_int32 SRXAFS_BulkStatus(acall, Fids, OutStats, CallBacks, Sync)
908 struct rx_call *acall;
909 struct AFSCBFids *Fids;
910 struct AFSBulkStats *OutStats;
911 struct AFSCBs *CallBacks;
912 struct AFSVolSync *Sync;
917 Vnode * targetptr = 0; /* pointer to vnode to fetch */
918 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
919 int errorCode = 0; /* return code to caller */
920 Volume * volptr = 0; /* pointer to the volume */
921 struct client *client; /* pointer to the client data */
922 afs_int32 rights, anyrights; /* rights for this and any user */
923 register struct AFSFid *tfid; /* file id we're dealing with now */
924 struct rx_connection *tcon = rx_ConnectionOf(acall);
925 #if FS_STATS_DETAILED
926 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
927 struct timeval opStartTime,
928 opStopTime; /* Start/stop times for RPC op*/
929 struct timeval elapsedTime; /* Transfer time */
932 * Set our stats pointer, remember when the RPC operation started, and
933 * tally the operation.
935 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
939 TM_GetTimeOfDay(&opStartTime, 0);
940 #endif /* FS_STATS_DETAILED */
942 ViceLog(1, ("SAFS_BulkStatus\n"));
944 AFSCallStats.TotalCalls++;
947 nfiles = Fids->AFSCBFids_len; /* # of files in here */
948 if (nfiles <= 0) { /* Sanity check */
950 goto Audit_and_Return;
953 /* allocate space for return output parameters */
954 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
955 malloc(nfiles * sizeof(struct AFSFetchStatus));
956 OutStats->AFSBulkStats_len = nfiles;
957 CallBacks->AFSCBs_val = (struct AFSCallBack *)
958 malloc(nfiles * sizeof(struct AFSCallBack));
959 CallBacks->AFSCBs_len = nfiles;
961 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
964 tfid = Fids->AFSCBFids_val;
965 for (i=0; i<nfiles; i++, tfid++) {
967 * Get volume/vnode for the fetched file; caller's rights to it
971 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
972 DONTCHECK, &parentwhentargetnotdir, &client,
973 READ_LOCK, &rights, &anyrights))
975 /* set volume synchronization information, but only once per call */
977 SetVolumeSync(Sync, volptr);
979 /* Are we allowed to fetch Fid's status? */
980 if (targetptr->disk.type != vDirectory) {
981 if (errorCode = Check_PermissionRights(targetptr, client, rights,
982 CHK_FETCHSTATUS, 0)) {
983 if (rx_GetCallAbortCode(acall) == errorCode)
984 rx_SetCallAbortCode(acall, 0);
989 /* set OutStatus From the Fid */
990 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i],
991 rights, anyrights, parentwhentargetnotdir);
993 /* If a r/w volume, also set the CallBack state */
994 if (VolumeWriteable(volptr))
995 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
996 &CallBacks->AFSCBs_val[i]);
999 memset(&myFid, 0, sizeof(struct AFSFid));
1000 myFid.Volume = tfid->Volume;
1001 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
1002 &CallBacks->AFSCBs_val[i]);
1005 /* put back the file ID and volume */
1006 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
1007 parentwhentargetnotdir = (Vnode *) 0;
1008 targetptr = (Vnode *) 0;
1009 volptr = (Volume *) 0;
1013 /* Update and store volume/vnode and parent vnodes back */
1014 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1015 CallPostamble(tcon);
1017 #if FS_STATS_DETAILED
1018 TM_GetTimeOfDay(&opStopTime, 0);
1019 if (errorCode == 0) {
1021 (opP->numSuccesses)++;
1022 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1023 fs_stats_AddTo((opP->sumTime), elapsedTime);
1024 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1025 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1026 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1028 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1029 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1034 #endif /* FS_STATS_DETAILED */
1037 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
1038 osi_auditU (acall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
1041 } /*SRXAFS_BulkStatus*/
1044 afs_int32 SRXAFS_InlineBulkStatus(acall, Fids, OutStats, CallBacks, Sync)
1045 struct rx_call *acall;
1046 struct AFSCBFids *Fids;
1047 struct AFSBulkStats *OutStats;
1048 struct AFSCBs *CallBacks;
1049 struct AFSVolSync *Sync;
1053 Vnode * targetptr = 0; /* pointer to vnode to fetch */
1054 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
1055 int errorCode = 0; /* return code to caller */
1056 Volume * volptr = 0; /* pointer to the volume */
1057 struct client *client; /* pointer to the client data */
1058 afs_int32 rights, anyrights; /* rights for this and any user */
1059 register struct AFSFid *tfid; /* file id we're dealing with now */
1060 struct rx_connection *tcon;
1061 AFSFetchStatus *tstatus;
1062 #if FS_STATS_DETAILED
1063 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1064 struct timeval opStartTime,
1065 opStopTime; /* Start/stop times for RPC op*/
1066 struct timeval elapsedTime; /* Transfer time */
1069 * Set our stats pointer, remember when the RPC operation started, and
1070 * tally the operation.
1072 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
1076 TM_GetTimeOfDay(&opStartTime, 0);
1077 #endif /* FS_STATS_DETAILED */
1079 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
1081 AFSCallStats.TotalCalls++;
1084 nfiles = Fids->AFSCBFids_len; /* # of files in here */
1085 if (nfiles <= 0) { /* Sanity check */
1087 goto Audit_and_Return;
1090 /* allocate space for return output parameters */
1091 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
1092 malloc(nfiles * sizeof(struct AFSFetchStatus));
1093 OutStats->AFSBulkStats_len = nfiles;
1094 CallBacks->AFSCBs_val = (struct AFSCallBack *)
1095 malloc(nfiles * sizeof(struct AFSCallBack));
1096 CallBacks->AFSCBs_len = nfiles;
1098 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon)) {
1099 goto Bad_InlineBulkStatus;
1102 tfid = Fids->AFSCBFids_val;
1103 for (i=0; i<nfiles; i++, tfid++) {
1105 * Get volume/vnode for the fetched file; caller's rights to it
1109 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
1110 DONTCHECK, &parentwhentargetnotdir, &client,
1111 READ_LOCK, &rights, &anyrights)) {
1112 tstatus = &OutStats->AFSBulkStats_val[i];
1113 tstatus->errorCode = errorCode;
1114 parentwhentargetnotdir = (Vnode *) 0;
1115 targetptr = (Vnode *) 0;
1116 volptr = (Volume *) 0;
1120 /* set volume synchronization information, but only once per call */
1122 SetVolumeSync(Sync, volptr);
1124 /* Are we allowed to fetch Fid's status? */
1125 if (targetptr->disk.type != vDirectory) {
1126 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1127 CHK_FETCHSTATUS, 0)) {
1128 tstatus = &OutStats->AFSBulkStats_val[i];
1129 tstatus->errorCode = errorCode;
1130 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
1131 parentwhentargetnotdir = (Vnode *) 0;
1132 targetptr = (Vnode *) 0;
1133 volptr = (Volume *) 0;
1138 /* set OutStatus From the Fid */
1139 GetStatus(targetptr, (struct AFSFetchStatus *) &OutStats->AFSBulkStats_val[i],
1140 rights, anyrights, parentwhentargetnotdir);
1142 /* If a r/w volume, also set the CallBack state */
1143 if (VolumeWriteable(volptr))
1144 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
1145 &CallBacks->AFSCBs_val[i]);
1147 struct AFSFid myFid;
1148 memset(&myFid, 0, sizeof(struct AFSFid));
1149 myFid.Volume = tfid->Volume;
1150 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
1151 &CallBacks->AFSCBs_val[i]);
1154 /* put back the file ID and volume */
1155 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
1156 parentwhentargetnotdir = (Vnode *) 0;
1157 targetptr = (Vnode *) 0;
1158 volptr = (Volume *) 0;
1161 Bad_InlineBulkStatus:
1162 /* Update and store volume/vnode and parent vnodes back */
1163 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1164 CallPostamble(tcon);
1166 #if FS_STATS_DETAILED
1167 TM_GetTimeOfDay(&opStopTime, 0);
1168 if (errorCode == 0) {
1170 (opP->numSuccesses)++;
1171 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1172 fs_stats_AddTo((opP->sumTime), elapsedTime);
1173 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1174 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1175 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1177 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1178 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1183 #endif /* FS_STATS_DETAILED */
1186 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
1187 osi_auditU (acall, InlineBulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
1190 } /*SRXAFS_InlineBulkStatus*/
1193 afs_int32 SRXAFS_FetchStatus (acall, Fid, OutStatus, CallBack, Sync)
1194 struct rx_call *acall; /* Rx call */
1195 struct AFSFid *Fid; /* Fid of target file */
1196 struct AFSFetchStatus *OutStatus; /* Returned status for the fid */
1197 struct AFSCallBack *CallBack; /* if r/w, callback promise for Fid */
1198 struct AFSVolSync *Sync;
1201 struct rx_connection *tcon;
1202 #if FS_STATS_DETAILED
1203 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1204 struct timeval opStartTime,
1205 opStopTime; /* Start/stop times for RPC op*/
1206 struct timeval elapsedTime; /* Transfer time */
1209 * Set our stats pointer, remember when the RPC operation started, and
1210 * tally the operation.
1212 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
1216 TM_GetTimeOfDay(&opStartTime, 0);
1217 #endif /* FS_STATS_DETAILED */
1219 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
1220 goto Bad_FetchStatus;
1222 code = SAFSS_FetchStatus (acall, Fid, OutStatus, CallBack, Sync);
1225 CallPostamble(tcon);
1227 #if FS_STATS_DETAILED
1228 TM_GetTimeOfDay(&opStopTime, 0);
1231 (opP->numSuccesses)++;
1232 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1233 fs_stats_AddTo((opP->sumTime), elapsedTime);
1234 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1235 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1236 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1238 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1239 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1244 #endif /* FS_STATS_DETAILED */
1246 osi_auditU (acall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
1249 } /*SRXAFS_FetchStatus*/
1252 afs_int32 SRXAFS_StoreData (acall, Fid, InStatus, Pos, Length, FileLength, OutStatus, Sync)
1253 struct rx_call *acall; /* Rx call */
1254 struct AFSFid *Fid; /* Fid of taret file */
1255 struct AFSStoreStatus *InStatus; /* Input Status for Fid */
1256 afs_uint32 Pos; /* Not implemented yet */
1257 afs_uint32 Length; /* Length of data to store */
1258 afs_uint32 FileLength; /* Length of file after store */
1259 struct AFSFetchStatus *OutStatus; /* Returned status for target fid */
1260 struct AFSVolSync *Sync;
1262 Vnode * targetptr = 0; /* pointer to input fid */
1263 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1264 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
1265 int errorCode = 0; /* return code for caller */
1266 int fileCode = 0; /* return code from vol package */
1267 Volume * volptr = 0; /* pointer to the volume header */
1268 struct client * client; /* pointer to client structure */
1269 afs_int32 rights, anyrights; /* rights for this and any user */
1270 struct client *t_client; /* tmp ptr to client data */
1271 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1272 struct rx_connection *tcon;
1273 #if FS_STATS_DETAILED
1274 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1275 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
1276 struct timeval opStartTime,
1277 opStopTime; /* Start/stop times for RPC op*/
1278 struct timeval xferStartTime,
1279 xferStopTime; /* Start/stop times for xfer portion*/
1280 struct timeval elapsedTime; /* Transfer time */
1281 afs_int32 bytesToXfer; /* # bytes to xfer */
1282 afs_int32 bytesXferred; /* # bytes actually xfer */
1283 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
1286 * Set our stats pointers, remember when the RPC operation started, and
1287 * tally the operation.
1289 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
1290 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
1295 ViceLog(1, ("StoreData: Fid = %u.%d.%d\n",
1296 Fid->Volume, Fid->Vnode, Fid->Unique));
1297 TM_GetTimeOfDay(&opStartTime, 0);
1298 #endif /* FS_STATS_DETAILED */
1301 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
1304 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
1307 /* Get ptr to client data for user Id for logging */
1308 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1309 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1310 ViceLog(5, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d\n",
1311 Fid->Volume, Fid->Vnode, Fid->Unique,
1312 inet_ntoa(logHostAddr), t_client->ViceId));
1315 * Get associated volume/vnode for the stored file; caller's rights
1318 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1319 MustNOTBeDIR, &parentwhentargetnotdir,
1320 &client, WRITE_LOCK, &rights, &anyrights)) {
1324 /* set volume synchronization information */
1325 SetVolumeSync(Sync, volptr);
1327 if ((targetptr->disk.type == vSymlink)) {
1328 /* Should we return a better error code here??? */
1333 /* Check if we're allowed to store the data */
1334 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1335 CHK_STOREDATA, InStatus)) {
1340 * Drop the read lock on the parent directory after saving the parent
1341 * vnode information we need to pass to GetStatus
1343 if (parentwhentargetnotdir != NULL) {
1344 tparentwhentargetnotdir = *parentwhentargetnotdir;
1345 VPutVnode(&fileCode, parentwhentargetnotdir);
1346 assert(!fileCode || (fileCode == VSALVAGE));
1347 parentwhentargetnotdir = NULL;
1352 #if FS_STATS_DETAILED
1354 * Remember when the data transfer started.
1356 TM_GetTimeOfDay(&xferStartTime, 0);
1357 #endif /* FS_STATS_DETAILED */
1359 /* Do the actual storing of the data */
1360 #if FS_STATS_DETAILED
1361 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client, acall,
1362 Pos, Length, FileLength,
1363 (InStatus->Mask & AFS_FSYNC),
1364 &bytesToXfer, &bytesXferred);
1366 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client,
1367 acall, Pos, Length, FileLength,
1368 (InStatus->Mask & AFS_FSYNC));
1369 if (errorCode && (!targetptr->changed_newTime))
1371 #endif /* FS_STATS_DETAILED */
1372 #if FS_STATS_DETAILED
1374 * At this point, the data transfer is done, for good or ill. Remember
1375 * when the transfer ended, bump the number of successes/failures, and
1376 * integrate the transfer size and elapsed time into the stats. If the
1377 * operation failed, we jump to the appropriate point.
1379 TM_GetTimeOfDay(&xferStopTime, 0);
1381 (xferP->numXfers)++;
1383 (xferP->numSuccesses)++;
1386 * Bump the xfer sum by the number of bytes actually sent, NOT the
1389 tot_bytesXferred += bytesXferred;
1390 (xferP->sumBytes) += (tot_bytesXferred >> 10);
1391 tot_bytesXferred &= 0x3FF;
1392 if (bytesXferred < xferP->minBytes)
1393 xferP->minBytes = bytesXferred;
1394 if (bytesXferred > xferP->maxBytes)
1395 xferP->maxBytes = bytesXferred;
1398 * Tally the size of the object. Note: we tally the actual size,
1399 * NOT the number of bytes that made it out over the wire.
1401 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
1402 (xferP->count[0])++;
1404 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
1405 (xferP->count[1])++;
1407 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
1408 (xferP->count[2])++;
1410 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
1411 (xferP->count[3])++;
1413 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
1414 (xferP->count[4])++;
1416 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
1417 (xferP->count[5])++;
1419 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
1420 (xferP->count[6])++;
1422 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
1423 (xferP->count[7])++;
1425 (xferP->count[8])++;
1427 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
1428 fs_stats_AddTo((xferP->sumTime), elapsedTime);
1429 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
1430 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
1431 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
1433 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
1434 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
1440 * Finally, go off to tell our caller the bad news in case the
1443 if (errorCode && (!targetptr->changed_newTime))
1445 #endif /* FS_STATS_DETAILED */
1447 /* Update the status of the target's vnode */
1448 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus, targetptr,
1451 /* Get the updated File's status back to the caller */
1452 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
1455 /* Update and store volume/vnode and parent vnodes back */
1456 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1457 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
1459 CallPostamble(tcon);
1461 #if FS_STATS_DETAILED
1462 TM_GetTimeOfDay(&opStopTime, 0);
1463 if (errorCode == 0) {
1465 (opP->numSuccesses)++;
1466 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1467 fs_stats_AddTo((opP->sumTime), elapsedTime);
1468 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1469 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1470 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1472 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1473 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1477 #endif /* FS_STATS_DETAILED */
1479 osi_auditU (acall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
1482 } /*SRXAFS_StoreData*/
1484 afs_int32 SRXAFS_StoreData64 (acall, Fid, InStatus, Pos, Length, FileLength, OutStatus, Sync)
1485 struct rx_call *acall; /* Rx call */
1486 struct AFSFid *Fid; /* Fid of taret file */
1487 struct AFSStoreStatus *InStatus; /* Input Status for Fid */
1488 afs_uint64 Pos; /* Not implemented yet */
1489 afs_uint64 Length; /* Length of data to store */
1490 afs_uint64 FileLength; /* Length of file after store */
1491 struct AFSFetchStatus *OutStatus; /* Returned status for target fid */
1492 struct AFSVolSync *Sync;
1497 afs_int32 tFileLength;
1499 #ifdef AFS_64BIT_ENV
1500 if (FileLength > 0x7fffffff)
1504 tFileLength = FileLength;
1505 #else /* AFS_64BIT_ENV */
1506 if (FileLength.high)
1509 tLength = Length.low;
1510 tFileLength = FileLength.low;
1511 #endif /* AFS_64BIT_ENV */
1513 code = SRXAFS_StoreData (acall, Fid, InStatus, tPos, tLength, tFileLength,
1518 afs_int32 SRXAFS_StoreACL (acall, Fid, AccessList, OutStatus, Sync)
1519 struct rx_call *acall; /* Rx call */
1520 struct AFSFid *Fid; /* Target dir's fid */
1521 struct AFSOpaque *AccessList; /* Access List's contents */
1522 struct AFSFetchStatus *OutStatus; /* Returned status of fid */
1523 struct AFSVolSync *Sync;
1525 Vnode * targetptr = 0; /* pointer to input fid */
1526 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1527 int errorCode = 0; /* return code for caller */
1528 struct AFSStoreStatus InStatus; /* Input status for fid */
1529 Volume * volptr = 0; /* pointer to the volume header */
1530 struct client * client; /* pointer to client structure */
1531 afs_int32 rights, anyrights; /* rights for this and any user */
1532 struct rx_connection *tcon;
1533 struct client *t_client; /* tmp ptr to client data */
1534 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1535 #if FS_STATS_DETAILED
1536 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1537 struct timeval opStartTime,
1538 opStopTime; /* Start/stop times for RPC op*/
1539 struct timeval elapsedTime; /* Transfer time */
1542 * Set our stats pointer, remember when the RPC operation started, and
1543 * tally the operation.
1545 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
1549 TM_GetTimeOfDay(&opStartTime, 0);
1550 #endif /* FS_STATS_DETAILED */
1551 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
1554 /* Get ptr to client data for user Id for logging */
1555 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1556 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1557 ViceLog(1, ("SAFS_StoreACL, Fid = %u.%d.%d, ACL=%s, Host %s, Id %d\n",
1558 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
1559 inet_ntoa(logHostAddr), t_client->ViceId));
1561 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
1564 InStatus.Mask = 0; /* not storing any status */
1567 * Get associated volume/vnode for the target dir; caller's rights
1568 * are also returned.
1570 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1571 MustBeDIR, &parentwhentargetnotdir,
1572 &client, WRITE_LOCK, &rights, &anyrights)) {
1576 /* set volume synchronization information */
1577 SetVolumeSync(Sync, volptr);
1579 /* Check if we have permission to change the dir's ACL */
1580 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1581 CHK_STOREACL, &InStatus)) {
1585 /* Build and store the new Access List for the dir */
1586 if (errorCode = RXStore_AccessList(targetptr, AccessList)) {
1590 targetptr->changed_newTime = 1; /* status change of directory */
1592 /* convert the write lock to a read lock before breaking callbacks */
1593 VVnodeWriteToRead(&errorCode, targetptr);
1594 assert(!errorCode || errorCode == VSALVAGE);
1596 /* break call backs on the directory */
1597 BreakCallBack(client->host, Fid, 0);
1599 /* Get the updated dir's status back to the caller */
1600 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
1603 /* Update and store volume/vnode and parent vnodes back */
1604 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1605 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
1606 CallPostamble(tcon);
1608 #if FS_STATS_DETAILED
1609 TM_GetTimeOfDay(&opStopTime, 0);
1610 if (errorCode == 0) {
1612 (opP->numSuccesses)++;
1613 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1614 fs_stats_AddTo((opP->sumTime), elapsedTime);
1615 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1616 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1617 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1619 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1620 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1624 #endif /* FS_STATS_DETAILED */
1626 osi_auditU (acall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
1629 } /*SRXAFS_StoreACL*/
1633 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
1634 * should be merged when possible.
1636 SAFSS_StoreStatus (acall, Fid, InStatus, OutStatus, Sync)
1637 struct rx_call *acall; /* Rx call */
1638 struct AFSFid *Fid; /* Target file's fid */
1639 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1640 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1641 struct AFSVolSync *Sync;
1644 Vnode * targetptr = 0; /* pointer to input fid */
1645 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
1646 int errorCode = 0; /* return code for caller */
1647 Volume * volptr = 0; /* pointer to the volume header */
1648 struct client * client; /* pointer to client structure */
1649 afs_int32 rights, anyrights; /* rights for this and any user */
1650 struct client *t_client; /* tmp ptr to client data */
1651 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1652 struct rx_connection *tcon = rx_ConnectionOf(acall);
1654 /* Get ptr to client data for user Id for logging */
1655 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1656 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1657 ViceLog(1, ("SAFS_StoreStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
1658 Fid->Volume, Fid->Vnode, Fid->Unique,
1659 inet_ntoa(logHostAddr), t_client->ViceId));
1661 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
1664 * Get volume/vnode for the target file; caller's rights to it are
1667 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
1668 DONTCHECK, &parentwhentargetnotdir,
1669 &client, WRITE_LOCK, &rights, &anyrights)) {
1670 goto Bad_StoreStatus;
1673 /* set volume synchronization information */
1674 SetVolumeSync(Sync, volptr);
1676 /* Check if the caller has proper permissions to store status to Fid */
1677 if (errorCode = Check_PermissionRights(targetptr, client, rights,
1678 CHK_STORESTATUS, InStatus)) {
1679 goto Bad_StoreStatus;
1682 * Check for a symbolic link; we can't chmod these (otherwise could
1683 * change a symlink to a mt pt or vice versa)
1685 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
1687 goto Bad_StoreStatus;
1690 /* Update the status of the target's vnode */
1691 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
1692 (parentwhentargetnotdir ?
1693 parentwhentargetnotdir : targetptr), volptr, 0);
1695 /* convert the write lock to a read lock before breaking callbacks */
1696 VVnodeWriteToRead(&errorCode, targetptr);
1697 assert(!errorCode || errorCode == VSALVAGE);
1699 /* Break call backs on Fid */
1700 BreakCallBack(client->host, Fid, 0);
1702 /* Return the updated status back to caller */
1703 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
1706 /* Update and store volume/vnode and parent vnodes back */
1707 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
1708 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
1711 } /*SAFSS_StoreStatus*/
1714 afs_int32 SRXAFS_StoreStatus (acall, Fid, InStatus, OutStatus, Sync)
1715 struct rx_call *acall; /* Rx call */
1716 struct AFSFid *Fid; /* Target file's fid */
1717 struct AFSStoreStatus *InStatus; /* Input status for Fid */
1718 struct AFSFetchStatus *OutStatus; /* Output status for fid */
1719 struct AFSVolSync *Sync;
1722 struct rx_connection *tcon;
1723 #if FS_STATS_DETAILED
1724 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1725 struct timeval opStartTime,
1726 opStopTime; /* Start/stop times for RPC op*/
1727 struct timeval elapsedTime; /* Transfer time */
1730 * Set our stats pointer, remember when the RPC operation started, and
1731 * tally the operation.
1733 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
1737 TM_GetTimeOfDay(&opStartTime, 0);
1738 #endif /* FS_STATS_DETAILED */
1740 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
1741 goto Bad_StoreStatus;
1743 code = SAFSS_StoreStatus (acall, Fid, InStatus, OutStatus, Sync);
1746 CallPostamble(tcon);
1748 #if FS_STATS_DETAILED
1749 TM_GetTimeOfDay(&opStopTime, 0);
1752 (opP->numSuccesses)++;
1753 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1754 fs_stats_AddTo((opP->sumTime), elapsedTime);
1755 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1756 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1757 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1759 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1760 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1765 #endif /* FS_STATS_DETAILED */
1767 osi_auditU (acall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
1770 } /*SRXAFS_StoreStatus*/
1774 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
1775 * merged in when possible.
1777 SAFSS_RemoveFile (acall, DirFid, Name, OutDirStatus, Sync)
1778 struct rx_call *acall; /* Rx call */
1779 struct AFSFid *DirFid; /* Dir fid for file to remove */
1780 char *Name; /* File name to remove */
1781 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1782 struct AFSVolSync *Sync;
1785 Vnode * parentptr = 0; /* vnode of input Directory */
1786 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1787 Vnode * targetptr = 0; /* file to be deleted */
1788 Volume * volptr = 0; /* pointer to the volume header */
1789 AFSFid fileFid; /* area for Fid from the directory */
1790 int errorCode = 0; /* error code */
1791 DirHandle dir; /* Handle for dir package I/O */
1792 struct client * client; /* pointer to client structure */
1793 afs_int32 rights, anyrights; /* rights for this and any user */
1794 struct client *t_client; /* tmp ptr to client data */
1795 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1796 struct rx_connection *tcon = rx_ConnectionOf(acall);
1798 /* Get ptr to client data for user Id for logging */
1799 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1800 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1801 ViceLog(1, ("SAFS_RemoveFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1802 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1803 inet_ntoa(logHostAddr), t_client->ViceId));
1805 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
1808 * Get volume/vnode for the parent dir; caller's access rights are
1811 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1812 MustBeDIR, &parentwhentargetnotdir,
1813 &client, WRITE_LOCK, &rights, &anyrights)) {
1814 goto Bad_RemoveFile;
1816 /* set volume synchronization information */
1817 SetVolumeSync(Sync, volptr);
1819 /* Does the caller has delete (& write) access to the parent directory? */
1820 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
1821 goto Bad_RemoveFile;
1824 /* Actually delete the desired file */
1825 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir,
1826 &fileFid, Name, MustNOTBeDIR)) {
1827 goto Bad_RemoveFile;
1830 /* Update the vnode status of the parent dir */
1831 #if FS_STATS_DETAILED
1832 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1833 parentptr->disk.linkCount, client->InSameNetwork);
1835 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
1836 parentptr->disk.linkCount);
1837 #endif /* FS_STATS_DETAILED */
1839 /* Return the updated parent dir's status back to caller */
1840 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
1842 /* Handle internal callback state for the parent and the deleted file */
1843 if (targetptr->disk.linkCount == 0) {
1844 /* no references left, discard entry */
1845 DeleteFileCallBacks(&fileFid);
1846 /* convert the parent lock to a read lock before breaking callbacks */
1847 VVnodeWriteToRead(&errorCode, parentptr);
1848 assert(!errorCode || errorCode == VSALVAGE);
1850 /* convert the parent lock to a read lock before breaking callbacks */
1851 VVnodeWriteToRead(&errorCode, parentptr);
1852 assert(!errorCode || errorCode == VSALVAGE);
1853 /* convert the target lock to a read lock before breaking callbacks */
1854 VVnodeWriteToRead(&errorCode, targetptr);
1855 assert(!errorCode || errorCode == VSALVAGE);
1856 /* tell all the file has changed */
1857 BreakCallBack(client->host, &fileFid, 1);
1860 /* break call back on the directory */
1861 BreakCallBack(client->host, DirFid, 0);
1864 /* Update and store volume/vnode and parent vnodes back */
1865 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
1866 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
1869 } /*SAFSS_RemoveFile*/
1872 afs_int32 SRXAFS_RemoveFile (acall, DirFid, Name, OutDirStatus, Sync)
1873 struct rx_call *acall; /* Rx call */
1874 struct AFSFid *DirFid; /* Dir fid for file to remove */
1875 char *Name; /* File name to remove */
1876 struct AFSFetchStatus *OutDirStatus; /* Output status for dir fid's */
1877 struct AFSVolSync *Sync;
1880 struct rx_connection *tcon;
1881 #if FS_STATS_DETAILED
1882 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1883 struct timeval opStartTime,
1884 opStopTime; /* Start/stop times for RPC op*/
1885 struct timeval elapsedTime; /* Transfer time */
1888 * Set our stats pointer, remember when the RPC operation started, and
1889 * tally the operation.
1891 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
1895 TM_GetTimeOfDay(&opStartTime, 0);
1896 #endif /* FS_STATS_DETAILED */
1898 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
1899 goto Bad_RemoveFile;
1901 code = SAFSS_RemoveFile (acall, DirFid, Name, OutDirStatus, Sync);
1904 CallPostamble(tcon);
1906 #if FS_STATS_DETAILED
1907 TM_GetTimeOfDay(&opStopTime, 0);
1910 (opP->numSuccesses)++;
1911 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
1912 fs_stats_AddTo((opP->sumTime), elapsedTime);
1913 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
1914 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
1915 fs_stats_TimeAssign((opP->minTime), elapsedTime);
1917 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
1918 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
1923 #endif /* FS_STATS_DETAILED */
1925 osi_auditU (acall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
1928 } /*SRXAFS_RemoveFile*/
1932 * This routine is called exclusively from SRXAFS_CreateFile(), and should
1933 * be merged in when possible.
1935 SAFSS_CreateFile (acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
1936 OutDirStatus, CallBack, Sync)
1937 struct rx_call *acall; /* Rx call */
1938 struct AFSFid *DirFid; /* Parent Dir fid */
1939 char *Name; /* File name to be created */
1940 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
1941 struct AFSFid *OutFid; /* Fid for newly created file */
1942 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
1943 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
1944 struct AFSCallBack *CallBack; /* Return callback promise for new file */
1945 struct AFSVolSync *Sync;
1948 Vnode * parentptr = 0; /* vnode of input Directory */
1949 Vnode * targetptr = 0; /* vnode of the new file */
1950 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
1951 Volume * volptr = 0; /* pointer to the volume header */
1952 int errorCode = 0; /* error code */
1953 DirHandle dir; /* Handle for dir package I/O */
1954 struct client * client; /* pointer to client structure */
1955 afs_int32 rights, anyrights; /* rights for this and any user */
1956 struct client *t_client; /* tmp ptr to client data */
1957 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1958 struct rx_connection *tcon = rx_ConnectionOf(acall);
1960 /* Get ptr to client data for user Id for logging */
1961 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
1962 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
1963 ViceLog(1, ("SAFS_CreateFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
1964 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
1965 inet_ntoa(logHostAddr), t_client->ViceId));
1967 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
1969 if (!FileNameOK(Name)) {
1971 goto Bad_CreateFile;
1975 * Get associated volume/vnode for the parent dir; caller long are
1978 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
1979 MustBeDIR, &parentwhentargetnotdir,
1980 &client, WRITE_LOCK, &rights, &anyrights)) {
1981 goto Bad_CreateFile;
1984 /* set volume synchronization information */
1985 SetVolumeSync(Sync, volptr);
1987 /* Can we write (and insert) onto the parent directory? */
1988 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
1989 goto Bad_CreateFile;
1991 /* get a new vnode for the file to be created and set it up */
1992 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
1993 Name, OutFid, vFile, nBlocks(0))) {
1994 goto Bad_CreateFile;
1997 /* update the status of the parent vnode */
1998 #if FS_STATS_DETAILED
1999 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2000 parentptr->disk.linkCount, client->InSameNetwork);
2002 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2003 parentptr->disk.linkCount);
2004 #endif /* FS_STATS_DETAILED */
2006 /* update the status of the new file's vnode */
2007 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
2008 parentptr, volptr, 0);
2010 /* set up the return status for the parent dir and the newly created file */
2011 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2012 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
2014 /* convert the write lock to a read lock before breaking callbacks */
2015 VVnodeWriteToRead(&errorCode, parentptr);
2016 assert(!errorCode || errorCode == VSALVAGE);
2018 /* break call back on parent dir */
2019 BreakCallBack(client->host, DirFid, 0);
2021 /* Return a callback promise for the newly created file to the caller */
2022 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
2025 /* Update and store volume/vnode and parent vnodes back */
2026 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2027 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
2030 } /*SAFSS_CreateFile*/
2033 afs_int32 SRXAFS_CreateFile (acall, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
2034 struct rx_call *acall; /* Rx call */
2035 struct AFSFid *DirFid; /* Parent Dir fid */
2036 char *Name; /* File name to be created */
2037 struct AFSStoreStatus *InStatus; /* Input status for newly created file */
2038 struct AFSFid *OutFid; /* Fid for newly created file */
2039 struct AFSFetchStatus *OutFidStatus; /* Output status for new file */
2040 struct AFSFetchStatus *OutDirStatus; /* Ouput status for the parent dir */
2041 struct AFSCallBack *CallBack; /* Return callback promise for new file */
2042 struct AFSVolSync *Sync;
2045 struct rx_connection *tcon;
2046 #if FS_STATS_DETAILED
2047 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2048 struct timeval opStartTime,
2049 opStopTime; /* Start/stop times for RPC op*/
2050 struct timeval elapsedTime; /* Transfer time */
2053 * Set our stats pointer, remember when the RPC operation started, and
2054 * tally the operation.
2056 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
2060 TM_GetTimeOfDay(&opStartTime, 0);
2061 #endif /* FS_STATS_DETAILED */
2063 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
2064 goto Bad_CreateFile;
2066 code = SAFSS_CreateFile (acall, DirFid, Name, InStatus, OutFid,
2067 OutFidStatus, OutDirStatus, CallBack, Sync);
2070 CallPostamble(tcon);
2072 #if FS_STATS_DETAILED
2073 TM_GetTimeOfDay(&opStopTime, 0);
2076 (opP->numSuccesses)++;
2077 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2078 fs_stats_AddTo((opP->sumTime), elapsedTime);
2079 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2080 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2081 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2083 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2084 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2088 #endif /* FS_STATS_DETAILED */
2090 osi_auditU (acall, CreateFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2093 } /*SRXAFS_CreateFile*/
2097 * This routine is called exclusively from SRXAFS_Rename(), and should be
2098 * merged in when possible.
2100 SAFSS_Rename (acall, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus,
2101 OutNewDirStatus, Sync)
2102 struct rx_call *acall; /* Rx call */
2103 struct AFSFid *OldDirFid; /* From parent dir's fid */
2104 char *OldName; /* From file name */
2105 struct AFSFid *NewDirFid; /* To parent dir's fid */
2106 char *NewName; /* To new file name */
2107 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
2108 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
2109 struct AFSVolSync *Sync;
2112 Vnode * oldvptr = 0; /* vnode of the old Directory */
2113 Vnode * newvptr = 0; /* vnode of the new Directory */
2114 Vnode * fileptr = 0; /* vnode of the file to move */
2115 Vnode * newfileptr = 0; /* vnode of the file to delete */
2116 Vnode * testvptr = 0; /* used in directory tree walk */
2117 Vnode * parent = 0; /* parent for use in SetAccessList */
2118 int errorCode = 0; /* error code */
2119 int fileCode = 0; /* used when writing Vnodes */
2120 VnodeId testnode; /* used in directory tree walk */
2121 AFSFid fileFid; /* Fid of file to move */
2122 AFSFid newFileFid; /* Fid of new file */
2123 DirHandle olddir; /* Handle for dir package I/O */
2124 DirHandle newdir; /* Handle for dir package I/O */
2125 DirHandle filedir; /* Handle for dir package I/O */
2126 DirHandle newfiledir; /* Handle for dir package I/O */
2127 Volume * volptr = 0; /* pointer to the volume header */
2128 struct client * client; /* pointer to client structure */
2129 afs_int32 rights, anyrights; /* rights for this and any user */
2130 afs_int32 newrights; /* rights for this user */
2131 afs_int32 newanyrights; /* rights for any user */
2132 int doDelete; /* deleted the rename target (ref count now 0) */
2134 struct client *t_client; /* tmp ptr to client data */
2135 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2136 struct rx_connection *tcon = rx_ConnectionOf(acall);
2138 /* Get ptr to client data for user Id for logging */
2139 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2140 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2141 ViceLog(1, ("SAFS_Rename %s to %s, Fid = %u.%d.%d to %u.%d.%d, Host %s, Id %d\n",
2142 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
2143 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
2145 inet_ntoa(logHostAddr), t_client->ViceId));
2147 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
2149 if (!FileNameOK(NewName)) {
2153 if (OldDirFid->Volume != NewDirFid->Volume) {
2158 if ( (strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0) ||
2159 (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0) ||
2160 (strlen(NewName) == 0) || (strlen(OldName) == 0) ) {
2166 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
2167 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr,
2168 &oldvptr, MustBeDIR, &parent,
2169 &client, WRITE_LOCK, &rights,
2174 if (OldDirFid->Vnode == NewDirFid->Vnode) {
2176 newrights = rights, newanyrights = anyrights;
2179 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
2180 &newvptr, MustBeDIR, &parent,
2181 &client, WRITE_LOCK, &newrights,
2188 if (errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
2189 &newvptr, MustBeDIR, &parent,
2190 &client, WRITE_LOCK, &newrights,
2195 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr,
2196 MustBeDIR, &parent, &client, WRITE_LOCK,
2197 &rights, &anyrights)) {
2203 /* set volume synchronization information */
2204 SetVolumeSync(Sync, volptr);
2206 if (errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE)) {
2209 if (errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT)) {
2213 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
2214 * call to CopyOnWrite returns error, it is not necessary to revert back
2215 * the effects of the first call because the contents of the volume is
2216 * not modified, it is only replicated.
2218 if (oldvptr->disk.cloned)
2220 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
2221 if ( errorCode = CopyOnWrite(oldvptr, volptr) )
2224 SetDirHandle(&olddir, oldvptr);
2225 if (newvptr->disk.cloned)
2227 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
2228 if ( errorCode = CopyOnWrite(newvptr, volptr) )
2232 SetDirHandle(&newdir, newvptr);
2234 /* Lookup the file to delete its vnode */
2235 if (Lookup(&olddir, OldName, &fileFid)) {
2239 if (fileFid.Vnode == oldvptr->vnodeNumber ||
2240 fileFid.Vnode == newvptr->vnodeNumber) {
2241 errorCode = FSERR_ELOOP;
2244 fileFid.Volume = V_id(volptr);
2245 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
2246 if (errorCode != 0) {
2247 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n", OldName, errorCode));
2248 VTakeOffline (volptr);
2251 if (fileptr->disk.uniquifier != fileFid.Unique) {
2252 ViceLog (0, ("SAFSS_Rename(): Old file %s uniquifier mismatch\n", OldName));
2253 VTakeOffline (volptr);
2258 if (fileptr->disk.type != vDirectory &&
2259 oldvptr != newvptr &&
2260 fileptr->disk.linkCount != 1) {
2262 * Hard links exist to this file - cannot move one of the links to
2263 * a new directory because of AFS restrictions (this is the same
2264 * reason that links cannot be made across directories, i.e.
2271 /* Lookup the new file */
2272 if (!(Lookup(&newdir, NewName, &newFileFid))) {
2273 if (!(newrights & PRSFS_DELETE)) {
2277 if (newFileFid.Vnode == oldvptr->vnodeNumber ||
2278 newFileFid.Vnode == newvptr->vnodeNumber ||
2279 newFileFid.Vnode == fileFid.Vnode) {
2283 newFileFid.Volume = V_id(volptr);
2284 newfileptr = VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
2285 if (errorCode != 0) {
2286 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n", NewName, errorCode));
2287 VTakeOffline (volptr);
2290 if (fileptr->disk.uniquifier != fileFid.Unique) {
2291 ViceLog (0, ("SAFSS_Rename(): New file %s uniquifier mismatch\n", NewName));
2292 VTakeOffline (volptr);
2296 SetDirHandle(&newfiledir, newfileptr);
2297 /* Now check that we're moving directories over directories properly, etc.
2298 * return proper POSIX error codes:
2299 * if fileptr is a file and new is a dir: EISDIR.
2300 * if fileptr is a dir and new is a file: ENOTDIR.
2301 * Also, dir to be removed must be empty, of course.
2303 if (newfileptr->disk.type == vDirectory) {
2304 if (fileptr->disk.type != vDirectory) {
2308 if ((IsEmpty(&newfiledir))) {
2314 if (fileptr->disk.type == vDirectory) {
2315 errorCode = ENOTDIR;
2322 * ok - now we check that the old name is not above new name in the
2323 * directory structure. This is to prevent removing a subtree alltogether
2325 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
2326 for (testnode = newvptr->disk.parent; testnode != 0;) {
2327 if (testnode == oldvptr->vnodeNumber) {
2328 testnode = oldvptr->disk.parent;
2331 if ((testnode == fileptr->vnodeNumber) ||
2332 (testnode == newvptr->vnodeNumber)) {
2333 errorCode = FSERR_ELOOP;
2336 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
2337 errorCode = FSERR_ELOOP;
2340 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
2341 assert(errorCode == 0);
2342 testnode = testvptr->disk.parent;
2343 VPutVnode(&errorCode, testvptr);
2344 assert(errorCode == 0);
2347 /* Do the CopyonWrite first before modifying anything else. Copying is
2348 * required because we may have to change entries for ..
2350 if ((fileptr->disk.type == vDirectory ) && (fileptr->disk.cloned) )
2352 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
2353 if ( errorCode = CopyOnWrite(fileptr, volptr) )
2357 /* If the new name exists already, delete it and the file it points to */
2360 /* Delete NewName from its directory */
2361 code = Delete(&newdir, NewName);
2364 /* Drop the link count */
2365 newfileptr->disk.linkCount--;
2366 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
2367 VAdjustDiskUsage(&errorCode, volptr,
2368 -(int)nBlocks(newfileptr->disk.length), 0);
2369 if (VN_GET_INO(newfileptr)) {
2370 IH_REALLYCLOSE(newfileptr->handle);
2371 errorCode = IH_DEC(V_linkHandle(volptr),
2372 VN_GET_INO(newfileptr),
2373 V_parentId(volptr));
2374 IH_RELEASE(newfileptr->handle);
2375 if (errorCode == -1) {
2376 ViceLog(0, ("Del: inode=%s, name=%s, errno=%d\n",
2377 PrintInode(NULL, VN_GET_INO(newfileptr)),
2379 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
2380 ViceLog(0, ("Do we need to fsck?"));
2383 VN_SET_INO(newfileptr, (Inode)0);
2384 newfileptr->delete = 1; /* Mark NewName vnode to delete */
2387 /* Link count did not drop to zero.
2388 * Mark NewName vnode as changed - updates stime.
2390 newfileptr->changed_newTime = 1;
2395 * If the create below fails, and the delete above worked, we have
2396 * removed the new name and not replaced it. This is not very likely,
2397 * but possible. We could try to put the old file back, but it is
2398 * highly unlikely that it would work since it would involve issuing
2401 if (errorCode = Create(&newdir,(char *) NewName, &fileFid))
2404 /* Delete the old name */
2405 assert(Delete(&olddir,(char *) OldName) == 0);
2407 /* if the directory length changes, reflect it in the statistics */
2408 #if FS_STATS_DETAILED
2409 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2410 oldvptr->disk.linkCount, client->InSameNetwork);
2411 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2412 newvptr->disk.linkCount, client->InSameNetwork);
2414 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
2415 oldvptr->disk.linkCount);
2416 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
2417 newvptr->disk.linkCount);
2418 #endif /* FS_STATS_DETAILED */
2420 if (oldvptr == newvptr)
2421 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
2423 fileptr->disk.parent = newvptr->vnodeNumber;
2424 fileptr->changed_newTime = 1; /* status change of moved file */
2426 /* if we are dealing with a rename of a directory */
2427 if (fileptr->disk.type == vDirectory) {
2428 assert(!fileptr->disk.cloned);
2429 SetDirHandle(&filedir, fileptr);
2430 /* fix .. to point to the correct place */
2431 Delete(&filedir, ".."); /* No assert--some directories may be bad */
2432 assert(Create(&filedir, "..", NewDirFid) == 0);
2433 fileptr->disk.dataVersion++;
2434 /* if the parent directories are different the link counts have to be */
2435 /* changed due to .. in the renamed directory */
2436 if (oldvptr != newvptr) {
2437 oldvptr->disk.linkCount--;
2438 newvptr->disk.linkCount++;
2442 /* set up return status */
2443 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
2444 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
2445 if (newfileptr && doDelete) {
2446 DeleteFileCallBacks(&newFileFid); /* no other references */
2451 /* convert the write locks to a read locks before breaking callbacks */
2452 VVnodeWriteToRead(&errorCode, newvptr);
2453 assert(!errorCode || errorCode == VSALVAGE);
2454 if (oldvptr != newvptr) {
2455 VVnodeWriteToRead(&errorCode, oldvptr);
2456 assert(!errorCode || errorCode == VSALVAGE);
2458 if (newfileptr && !doDelete) {
2459 /* convert the write lock to a read lock before breaking callbacks */
2460 VVnodeWriteToRead(&errorCode, newfileptr);
2461 assert(!errorCode || errorCode == VSALVAGE);
2464 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
2465 BreakCallBack(client->host, NewDirFid, 0);
2466 if (oldvptr != newvptr) {
2467 BreakCallBack(client->host, OldDirFid, 0);
2468 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
2469 BreakCallBack(client->host, &fileFid, 0);
2472 /* Note: it is not necessary to break the callback */
2474 DeleteFileCallBacks(&newFileFid); /* no other references */
2476 /* other's still exist (with wrong link count) */
2477 BreakCallBack(client->host, &newFileFid, 1);
2482 VPutVnode(&fileCode, newfileptr);
2483 assert(fileCode == 0);
2485 PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr? newvptr : 0),
2487 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
2493 afs_int32 SRXAFS_Rename (acall, OldDirFid, OldName, NewDirFid, NewName, OutOldDirStatus, OutNewDirStatus, Sync)
2494 struct rx_call *acall; /* Rx call */
2495 struct AFSFid *OldDirFid; /* From parent dir's fid */
2496 char *OldName; /* From file name */
2497 struct AFSFid *NewDirFid; /* To parent dir's fid */
2498 char *NewName; /* To new file name */
2499 struct AFSFetchStatus *OutOldDirStatus; /* Output status for From parent dir */
2500 struct AFSFetchStatus *OutNewDirStatus; /* Output status for To parent dir */
2501 struct AFSVolSync *Sync;
2504 struct rx_connection *tcon;
2505 #if FS_STATS_DETAILED
2506 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2507 struct timeval opStartTime,
2508 opStopTime; /* Start/stop times for RPC op*/
2509 struct timeval elapsedTime; /* Transfer time */
2512 * Set our stats pointer, remember when the RPC operation started, and
2513 * tally the operation.
2515 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
2519 TM_GetTimeOfDay(&opStartTime, 0);
2520 #endif /* FS_STATS_DETAILED */
2522 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
2525 code = SAFSS_Rename (acall, OldDirFid, OldName, NewDirFid, NewName,
2526 OutOldDirStatus, OutNewDirStatus, Sync);
2529 CallPostamble(tcon);
2531 #if FS_STATS_DETAILED
2532 TM_GetTimeOfDay(&opStopTime, 0);
2535 (opP->numSuccesses)++;
2536 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2537 fs_stats_AddTo((opP->sumTime), elapsedTime);
2538 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2539 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2540 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2542 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2543 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2548 #endif /* FS_STATS_DETAILED */
2550 osi_auditU (acall, RenameFileEvent, code, AUD_FID, OldDirFid, AUD_STR, OldName, AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
2557 * This routine is called exclusively by SRXAFS_Symlink(), and should be
2558 * merged into it when possible.
2560 SAFSS_Symlink (acall, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2561 struct rx_call *acall; /* Rx call */
2562 struct AFSFid *DirFid; /* Parent dir's fid */
2563 char *Name; /* File name to create */
2564 char *LinkContents; /* Contents of the new created file */
2565 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2566 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2567 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2568 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2569 struct AFSVolSync *Sync; /* volume synchronization information */
2572 Vnode * parentptr = 0; /* vnode of input Directory */
2573 Vnode * targetptr = 0; /* vnode of the new link */
2574 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2575 int errorCode = 0; /* error code */
2577 DirHandle dir; /* Handle for dir package I/O */
2578 Volume * volptr = 0; /* pointer to the volume header */
2579 struct client * client; /* pointer to client structure */
2580 afs_int32 rights, anyrights, fd; /* rights for this and any user */
2581 struct client *t_client; /* tmp ptr to client data */
2582 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2584 struct rx_connection *tcon = rx_ConnectionOf(acall);
2586 /* Get ptr to client data for user Id for logging */
2587 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2588 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2589 ViceLog(1, ("SAFS_Symlink %s to %s, Did = %u.%d.%d, Host %s, Id %d\n", Name,
2590 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2591 inet_ntoa(logHostAddr), t_client->ViceId));
2593 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
2595 if (!FileNameOK(Name)) {
2601 * Get the vnode and volume for the parent dir along with the caller's
2604 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2605 MustBeDIR, &parentwhentargetnotdir,
2606 &client, WRITE_LOCK, &rights, &anyrights)) {
2610 /* set volume synchronization information */
2611 SetVolumeSync(Sync, volptr);
2613 /* Does the caller has insert (and write) access to the parent directory? */
2614 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2619 * If we're creating a mount point (any x bits clear), we must have
2620 * administer access to the directory, too. Always allow sysadmins
2623 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
2625 * We have a mountpoint, 'cause we're trying to set the Unix mode
2626 * bits to something with some x bits missing (default mode bits
2627 * if AFS_SETMODE is false is 0777)
2629 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
2635 /* get a new vnode for the symlink and set it up */
2636 if (errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
2637 Name, OutFid, vSymlink,
2638 nBlocks(strlen((char *) LinkContents)))) {
2642 /* update the status of the parent vnode */
2643 #if FS_STATS_DETAILED
2644 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2645 parentptr->disk.linkCount, client->InSameNetwork);
2647 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2648 parentptr->disk.linkCount);
2649 #endif /* FS_STATS_DETAILED */
2651 /* update the status of the new symbolic link file vnode */
2652 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus, parentptr,
2653 volptr, strlen((char *)LinkContents));
2655 /* Write the contents of the symbolic link name into the target inode */
2656 fdP = IH_OPEN(targetptr->handle);
2657 assert(fdP != NULL);
2658 assert(FDH_WRITE(fdP, (char *) LinkContents, strlen((char *) LinkContents)) == strlen((char *) LinkContents));
2661 * Set up and return modified status for the parent dir and new symlink
2664 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2665 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
2667 /* convert the write lock to a read lock before breaking callbacks */
2668 VVnodeWriteToRead(&errorCode, parentptr);
2669 assert(!errorCode || errorCode == VSALVAGE);
2671 /* break call back on the parent dir */
2672 BreakCallBack(client->host, DirFid, 0);
2675 /* Write the all modified vnodes (parent, new files) and volume back */
2676 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2677 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
2683 afs_int32 SRXAFS_Symlink (acall, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
2684 struct AFSVolSync *Sync;
2685 struct rx_call *acall; /* Rx call */
2686 struct AFSFid *DirFid; /* Parent dir's fid */
2687 char *Name; /* File name to create */
2688 char *LinkContents; /* Contents of the new created file */
2689 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
2690 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
2691 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
2692 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2696 struct rx_connection *tcon;
2697 #if FS_STATS_DETAILED
2698 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2699 struct timeval opStartTime,
2700 opStopTime; /* Start/stop times for RPC op*/
2701 struct timeval elapsedTime; /* Transfer time */
2704 * Set our stats pointer, remember when the RPC operation started, and
2705 * tally the operation.
2707 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
2711 TM_GetTimeOfDay(&opStartTime, 0);
2712 #endif /* FS_STATS_DETAILED */
2714 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
2717 code = SAFSS_Symlink (acall, DirFid, Name, LinkContents, InStatus, OutFid,
2718 OutFidStatus, OutDirStatus, Sync);
2721 CallPostamble(tcon);
2723 #if FS_STATS_DETAILED
2724 TM_GetTimeOfDay(&opStopTime, 0);
2727 (opP->numSuccesses)++;
2728 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2729 fs_stats_AddTo((opP->sumTime), elapsedTime);
2730 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2731 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2732 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2734 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2735 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2740 #endif /* FS_STATS_DETAILED */
2742 osi_auditU (acall, SymlinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
2745 } /*SRXAFS_Symlink*/
2749 * This routine is called exclusively by SRXAFS_Link(), and should be
2750 * merged into it when possible.
2752 SAFSS_Link (acall, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2753 struct rx_call *acall; /* Rx call */
2754 struct AFSFid *DirFid; /* Parent dir's fid */
2755 char *Name; /* File name to create */
2756 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2757 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2758 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2759 struct AFSVolSync *Sync;
2762 Vnode * parentptr = 0; /* vnode of input Directory */
2763 Vnode * targetptr = 0; /* vnode of the new file */
2764 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2765 Volume * volptr = 0; /* pointer to the volume header */
2766 int errorCode = 0; /* error code */
2767 DirHandle dir; /* Handle for dir package I/O */
2768 struct client * client; /* pointer to client structure */
2769 afs_int32 rights, anyrights; /* rights for this and any user */
2770 struct client *t_client; /* tmp ptr to client data */
2771 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2772 struct rx_connection *tcon = rx_ConnectionOf(acall);
2774 /* Get ptr to client data for user Id for logging */
2775 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2776 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2777 ViceLog(1, ("SAFS_Link %s, Did = %u.%d.%d, Fid = %u.%d.%d, Host %s, Id %d\n",
2778 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2779 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
2780 inet_ntoa(logHostAddr), t_client->ViceId));
2782 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
2784 if (DirFid->Volume != ExistingFid->Volume) {
2788 if (!FileNameOK(Name)) {
2794 * Get the vnode and volume for the parent dir along with the caller's
2797 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2798 MustBeDIR, &parentwhentargetnotdir,
2799 &client, WRITE_LOCK, &rights, &anyrights)) {
2803 /* set volume synchronization information */
2804 SetVolumeSync(Sync, volptr);
2806 /* Can the caller insert into the parent directory? */
2807 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
2811 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) ||
2812 (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
2813 /* AFS fileservers always have directory vnodes that are odd. */
2818 /* get the file vnode */
2819 if (errorCode = CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK)) {
2822 if (targetptr->disk.type != vFile) {
2826 if (targetptr->disk.parent != DirFid->Vnode) {
2830 if (parentptr->disk.cloned)
2832 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
2833 if ( errorCode = CopyOnWrite(parentptr, volptr))
2834 goto Bad_Link; /* disk full error */
2837 /* add the name to the directory */
2838 SetDirHandle(&dir, parentptr);
2839 if (errorCode = Create(&dir, (char *)Name, ExistingFid))
2843 /* update the status in the parent vnode */
2844 /**WARNING** --> disk.author SHOULDN'T be modified???? */
2845 #if FS_STATS_DETAILED
2846 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2847 parentptr->disk.linkCount, client->InSameNetwork);
2849 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
2850 parentptr->disk.linkCount);
2851 #endif /* FS_STATS_DETAILED */
2853 targetptr->disk.linkCount++;
2854 targetptr->disk.author = client->ViceId;
2855 targetptr->changed_newTime = 1; /* Status change of linked-to file */
2857 /* set up return status */
2858 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
2859 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
2861 /* convert the write locks to read locks before breaking callbacks */
2862 VVnodeWriteToRead(&errorCode, targetptr);
2863 assert(!errorCode || errorCode == VSALVAGE);
2864 VVnodeWriteToRead(&errorCode, parentptr);
2865 assert(!errorCode || errorCode == VSALVAGE);
2867 /* break call back on DirFid */
2868 BreakCallBack(client->host, DirFid, 0);
2870 * We also need to break the callback for the file that is hard-linked since part
2871 * of its status (like linkcount) is changed
2873 BreakCallBack(client->host, ExistingFid, 0);
2876 /* Write the all modified vnodes (parent, new files) and volume back */
2877 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
2878 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
2884 afs_int32 SRXAFS_Link (acall, DirFid, Name, ExistingFid, OutFidStatus, OutDirStatus, Sync)
2885 struct rx_call *acall; /* Rx call */
2886 struct AFSFid *DirFid; /* Parent dir's fid */
2887 char *Name; /* File name to create */
2888 struct AFSFid *ExistingFid; /* Fid of existing fid we'll make link to */
2889 struct AFSFetchStatus *OutFidStatus; /* Output status for newly created file */
2890 struct AFSFetchStatus *OutDirStatus; /* Outpout status for parent dir */
2891 struct AFSVolSync *Sync;
2894 struct rx_connection *tcon;
2895 #if FS_STATS_DETAILED
2896 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2897 struct timeval opStartTime,
2898 opStopTime; /* Start/stop times for RPC op*/
2899 struct timeval elapsedTime; /* Transfer time */
2902 * Set our stats pointer, remember when the RPC operation started, and
2903 * tally the operation.
2905 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
2909 TM_GetTimeOfDay(&opStartTime, 0);
2910 #endif /* FS_STATS_DETAILED */
2912 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
2915 code = SAFSS_Link (acall, DirFid, Name, ExistingFid, OutFidStatus,
2916 OutDirStatus, Sync);
2919 CallPostamble(tcon);
2921 #if FS_STATS_DETAILED
2922 TM_GetTimeOfDay(&opStopTime, 0);
2925 (opP->numSuccesses)++;
2926 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2927 fs_stats_AddTo((opP->sumTime), elapsedTime);
2928 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2929 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2930 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2932 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2933 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2938 #endif /* FS_STATS_DETAILED */
2940 osi_auditU (acall, LinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_FID, ExistingFid, AUD_END);
2947 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
2948 * merged into it when possible.
2950 SAFSS_MakeDir (acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
2951 OutDirStatus, CallBack, Sync)
2952 struct rx_call *acall; /* Rx call */
2953 struct AFSFid *DirFid; /* Parent dir's fid */
2954 char *Name; /* Name of dir to be created */
2955 struct AFSStoreStatus *InStatus; /* Input status for new dir */
2956 struct AFSFid *OutFid; /* Fid of new dir */
2957 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
2958 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
2959 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
2960 struct AFSVolSync *Sync;
2963 Vnode * parentptr = 0; /* vnode of input Directory */
2964 Vnode * targetptr = 0; /* vnode of the new file */
2965 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
2966 Volume * volptr = 0; /* pointer to the volume header */
2967 int errorCode = 0; /* error code */
2968 struct acl_accessList * newACL; /* Access list */
2969 int newACLSize; /* Size of access list */
2970 DirHandle dir; /* Handle for dir package I/O */
2971 DirHandle parentdir; /* Handle for dir package I/O */
2972 struct client * client; /* pointer to client structure */
2973 afs_int32 rights, anyrights; /* rights for this and any user */
2974 struct client *t_client; /* tmp ptr to client data */
2975 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2976 struct rx_connection *tcon = rx_ConnectionOf(acall);
2978 /* Get ptr to client data for user Id for logging */
2979 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2980 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2981 ViceLog(1, ("SAFS_MakeDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
2982 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
2983 inet_ntoa(logHostAddr), t_client->ViceId));
2985 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
2987 if (!FileNameOK(Name)) {
2993 * Get the vnode and volume for the parent dir along with the caller's
2996 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
2997 MustBeDIR, &parentwhentargetnotdir,
2998 &client, WRITE_LOCK, &rights, &anyrights)) {
3002 /* set volume synchronization information */
3003 SetVolumeSync(Sync, volptr);
3005 /* Write access to the parent directory? */
3006 #ifdef DIRCREATE_NEED_WRITE
3008 * requires w access for the user to create a directory. this
3009 * closes a loophole in the current security arrangement, since a
3010 * user with i access only can create a directory and get the
3011 * implcit a access that goes with dir ownership, and proceed to
3012 * subvert quota in the volume.
3014 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) ||
3015 (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
3017 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) {
3018 #endif /* DIRCREATE_NEED_WRITE */
3022 #define EMPTYDIRBLOCKS 2
3023 /* get a new vnode and set it up */
3024 if (errorCode = Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr,
3025 Name, OutFid, vDirectory, EMPTYDIRBLOCKS)) {
3029 /* Update the status for the parent dir */
3030 #if FS_STATS_DETAILED
3031 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
3032 parentptr->disk.linkCount+1, client->InSameNetwork);
3034 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
3035 parentptr->disk.linkCount+1);
3036 #endif /* FS_STATS_DETAILED */
3038 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
3039 assert((SetAccessList(&targetptr, &volptr, &newACL, &newACLSize,
3040 &parentwhentargetnotdir, (AFSFid *)0, 0)) == 0);
3041 assert(parentwhentargetnotdir == 0);
3042 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
3044 /* update the status for the target vnode */
3045 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
3046 parentptr, volptr, 0);
3048 /* Actually create the New directory in the directory package */
3049 SetDirHandle(&dir, targetptr);
3050 assert(!(MakeDir(&dir, OutFid, DirFid)));
3052 targetptr->disk.length = Length(&dir);
3054 /* set up return status */
3055 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
3056 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
3058 /* convert the write lock to a read lock before breaking callbacks */
3059 VVnodeWriteToRead(&errorCode, parentptr);
3060 assert(!errorCode || errorCode == VSALVAGE);
3062 /* break call back on DirFid */
3063 BreakCallBack(client->host, DirFid, 0);
3065 /* Return a callback promise to caller */
3066 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3069 /* Write the all modified vnodes (parent, new files) and volume back */
3070 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3071 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
3077 afs_int32 SRXAFS_MakeDir (acall, DirFid, Name, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
3078 struct rx_call *acall; /* Rx call */
3079 struct AFSFid *DirFid; /* Parent dir's fid */
3080 char *Name; /* Name of dir to be created */
3081 struct AFSStoreStatus *InStatus; /* Input status for new dir */
3082 struct AFSFid *OutFid; /* Fid of new dir */
3083 struct AFSFetchStatus *OutFidStatus; /* Output status for new directory */
3084 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
3085 struct AFSCallBack *CallBack; /* Returned callback promise for new dir */
3086 struct AFSVolSync *Sync;
3089 struct rx_connection *tcon;
3090 #if FS_STATS_DETAILED
3091 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3092 struct timeval opStartTime,
3093 opStopTime; /* Start/stop times for RPC op*/
3094 struct timeval elapsedTime; /* Transfer time */
3097 * Set our stats pointer, remember when the RPC operation started, and
3098 * tally the operation.
3100 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
3104 TM_GetTimeOfDay(&opStartTime, 0);
3105 #endif /* FS_STATS_DETAILED */
3106 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
3109 code = SAFSS_MakeDir (acall, DirFid, Name, InStatus, OutFid,
3110 OutFidStatus, OutDirStatus, CallBack, Sync);
3113 CallPostamble(tcon);
3115 #if FS_STATS_DETAILED
3116 TM_GetTimeOfDay(&opStopTime, 0);
3119 (opP->numSuccesses)++;
3120 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3121 fs_stats_AddTo((opP->sumTime), elapsedTime);
3122 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3123 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3124 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3126 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3127 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3132 #endif /* FS_STATS_DETAILED */
3134 osi_auditU (acall, MakeDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3137 } /*SRXAFS_MakeDir*/
3141 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
3142 * merged into it when possible.
3144 SAFSS_RemoveDir (acall, DirFid, Name, OutDirStatus, Sync)
3145 struct rx_call *acall; /* Rx call */
3146 struct AFSFid *DirFid; /* Parent dir's fid */
3147 char *Name; /* (Empty) dir's name to be removed */
3148 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
3149 struct AFSVolSync *Sync;
3152 Vnode * parentptr = 0; /* vnode of input Directory */
3153 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3154 Vnode * targetptr = 0; /* file to be deleted */
3155 AFSFid fileFid; /* area for Fid from the directory */
3156 int errorCode = 0; /* error code */
3157 DirHandle dir; /* Handle for dir package I/O */
3158 Volume * volptr = 0; /* pointer to the volume header */
3159 struct client * client; /* pointer to client structure */
3160 afs_int32 rights, anyrights; /* rights for this and any user */
3161 Vnode debugvnode1, debugvnode2;
3162 struct client *t_client; /* tmp ptr to client data */
3163 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3164 struct rx_connection *tcon = rx_ConnectionOf(acall);
3166 /* Get ptr to client data for user Id for logging */
3167 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3168 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3169 ViceLog(1, ("SAFS_RemoveDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
3170 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3171 inet_ntoa(logHostAddr), t_client->ViceId));
3173 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
3176 * Get the vnode and volume for the parent dir along with the caller's
3179 if (errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
3180 MustBeDIR, &parentwhentargetnotdir,
3181 &client, WRITE_LOCK, &rights, &anyrights)) {
3184 debugvnode1 = *parentptr;
3186 /* set volume synchronization information */
3187 SetVolumeSync(Sync, volptr);
3189 /* Does the caller has delete (&write) access to the parent dir? */
3190 if (errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE)) {
3194 debugvnode2 = *parentptr;
3195 /* Do the actual delete of the desired (empty) directory, Name */
3196 if (errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid,
3201 /* Update the status for the parent dir; link count is also adjusted */
3202 #if FS_STATS_DETAILED
3203 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3204 parentptr->disk.linkCount-1, client->InSameNetwork);
3206 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3207 parentptr->disk.linkCount-1);
3208 #endif /* FS_STATS_DETAILED */
3210 /* Return to the caller the updated parent dir status */
3211 GetStatus(parentptr, OutDirStatus, rights, anyrights, (struct Vnode *)0);
3214 * Note: it is not necessary to break the callback on fileFid, since
3215 * refcount is now 0, so no one should be able to refer to the dir
3218 DeleteFileCallBacks(&fileFid);
3220 /* convert the write lock to a read lock before breaking callbacks */
3221 VVnodeWriteToRead(&errorCode, parentptr);
3222 assert(!errorCode || errorCode == VSALVAGE);
3224 /* break call back on DirFid and fileFid */
3225 BreakCallBack(client->host, DirFid, 0);
3228 /* Write the all modified vnodes (parent, new files) and volume back */
3229 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3230 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
3233 } /*SAFSS_RemoveDir*/
3236 afs_int32 SRXAFS_RemoveDir (acall, DirFid, Name, OutDirStatus, Sync)
3237 struct rx_call *acall; /* Rx call */
3238 struct AFSFid *DirFid; /* Parent dir's fid */
3239 char *Name; /* (Empty) dir's name to be removed */
3240 struct AFSFetchStatus *OutDirStatus; /* Output status for the parent dir */
3241 struct AFSVolSync *Sync;
3244 struct rx_connection *tcon;
3245 #if FS_STATS_DETAILED
3246 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3247 struct timeval opStartTime,
3248 opStopTime; /* Start/stop times for RPC op*/
3249 struct timeval elapsedTime; /* Transfer time */
3252 * Set our stats pointer, remember when the RPC operation started, and
3253 * tally the operation.
3255 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
3259 TM_GetTimeOfDay(&opStartTime, 0);
3260 #endif /* FS_STATS_DETAILED */
3262 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
3265 code = SAFSS_RemoveDir (acall, DirFid, Name, OutDirStatus, Sync);
3268 CallPostamble(tcon);
3270 #if FS_STATS_DETAILED
3271 TM_GetTimeOfDay(&opStopTime, 0);
3274 (opP->numSuccesses)++;
3275 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3276 fs_stats_AddTo((opP->sumTime), elapsedTime);
3277 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3278 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3279 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3281 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3282 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3287 #endif /* FS_STATS_DETAILED */
3289 osi_auditU (acall, RemoveDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3292 } /*SRXAFS_RemoveDir*/
3296 * This routine is called exclusively by SRXAFS_SetLock(), and should be
3297 * merged into it when possible.
3299 SAFSS_SetLock (acall, Fid, type, Sync)
3300 struct rx_call *acall; /* Rx call */
3301 struct AFSFid *Fid; /* Fid of file to lock */
3302 ViceLockType type; /* Type of lock (Read or write) */
3303 struct AFSVolSync *Sync;
3306 Vnode * targetptr = 0; /* vnode of input file */
3307 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3308 int errorCode = 0; /* error code */
3309 Volume * volptr = 0; /* pointer to the volume header */
3310 struct client * client; /* pointer to client structure */
3311 afs_int32 rights, anyrights; /* rights for this and any user */
3312 struct client *t_client; /* tmp ptr to client data */
3313 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3314 static char * locktype[2] = {"LockRead","LockWrite"};
3315 struct rx_connection *tcon = rx_ConnectionOf(acall);
3317 if (type != LockRead && type != LockWrite) {
3321 /* Get ptr to client data for user Id for logging */
3322 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3323 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3324 ViceLog(1,("SAFS_SetLock type = %s Fid = %u.%d.%d, Host %s, Id %d\n",
3325 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
3326 inet_ntoa(logHostAddr), t_client->ViceId));
3328 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
3332 * Get the vnode and volume for the desired file along with the caller's
3335 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3336 DONTCHECK, &parentwhentargetnotdir,
3337 &client, WRITE_LOCK, &rights, &anyrights)) {
3341 /* set volume synchronization information */
3342 SetVolumeSync(Sync, volptr);
3344 /* Handle the particular type of set locking, type */
3345 errorCode = HandleLocking(targetptr, rights, type);
3348 /* Write the all modified vnodes (parent, new files) and volume back */
3349 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3351 if ((errorCode == VREADONLY) && (type == LockRead))
3352 errorCode = 0; /* allow read locks on RO volumes without saving state */
3354 ViceLog(2,("SAFS_SetLock returns %d\n", errorCode));
3360 afs_int32 SRXAFS_OldSetLock(acall, Fid, type, Sync)
3361 struct rx_call *acall; /* Rx call */
3362 struct AFSFid *Fid; /* Fid of file to lock */
3363 ViceLockType type; /* Type of lock (Read or write) */
3364 struct AFSVolSync *Sync;
3366 return SRXAFS_SetLock(acall, Fid, type, Sync);
3368 } /*SRXAFS_OldSetLock*/
3371 afs_int32 SRXAFS_SetLock (acall, Fid, type, Sync)
3372 struct rx_call *acall; /* Rx call */
3373 struct AFSFid *Fid; /* Fid of file to lock */
3374 ViceLockType type; /* Type of lock (Read or write) */
3375 struct AFSVolSync *Sync;
3378 struct rx_connection *tcon;
3379 #if FS_STATS_DETAILED
3380 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3381 struct timeval opStartTime,
3382 opStopTime; /* Start/stop times for RPC op*/
3383 struct timeval elapsedTime; /* Transfer time */
3386 * Set our stats pointer, remember when the RPC operation started, and
3387 * tally the operation.
3389 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
3393 TM_GetTimeOfDay(&opStartTime, 0);
3394 #endif /* FS_STATS_DETAILED */
3396 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
3399 code = SAFSS_SetLock (acall, Fid, type, Sync);
3402 CallPostamble(tcon);
3404 #if FS_STATS_DETAILED
3405 TM_GetTimeOfDay(&opStopTime, 0);
3408 (opP->numSuccesses)++;
3409 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3410 fs_stats_AddTo((opP->sumTime), elapsedTime);
3411 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3412 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3413 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3415 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3416 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3420 #endif /* FS_STATS_DETAILED */
3422 osi_auditU (acall, SetLockEvent, code, AUD_FID, Fid, AUD_LONG, type, AUD_END);
3425 } /*SRXAFS_SetLock*/
3429 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
3430 * merged into it when possible.
3432 SAFSS_ExtendLock (acall, Fid, Sync)
3433 struct rx_call *acall; /* Rx call */
3434 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3435 struct AFSVolSync *Sync;
3438 Vnode * targetptr = 0; /* vnode of input file */
3439 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3440 int errorCode = 0; /* error code */
3441 Volume * volptr = 0; /* pointer to the volume header */
3442 struct client * client; /* pointer to client structure */
3443 afs_int32 rights, anyrights; /* rights for this and any user */
3444 struct client *t_client; /* tmp ptr to client data */
3445 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3446 struct rx_connection *tcon = rx_ConnectionOf(acall);
3448 /* Get ptr to client data for user Id for logging */
3449 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3450 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3451 ViceLog(1,("SAFS_ExtendLock Fid = %u.%d.%d, Host %s, Id %d\n",
3452 Fid->Volume, Fid->Vnode, Fid->Unique,
3453 inet_ntoa(logHostAddr), t_client->ViceId));
3455 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
3458 * Get the vnode and volume for the desired file along with the caller's
3461 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3462 DONTCHECK, &parentwhentargetnotdir,
3463 &client, WRITE_LOCK, &rights, &anyrights)) {
3464 goto Bad_ExtendLock;
3467 /* set volume synchronization information */
3468 SetVolumeSync(Sync, volptr);
3470 /* Handle the actual lock extension */
3471 errorCode = HandleLocking(targetptr, rights, LockExtend);
3474 /* Put back file's vnode and volume */
3475 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3477 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3478 errorCode = 0; /* under our generous policy re RO vols */
3480 ViceLog(2,("SAFS_ExtendLock returns %d\n", errorCode));
3483 } /*SAFSS_ExtendLock*/
3486 afs_int32 SRXAFS_OldExtendLock (acall, Fid, Sync)
3487 struct rx_call *acall; /* Rx call */
3488 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3489 struct AFSVolSync *Sync;
3491 return SRXAFS_ExtendLock(acall, Fid, Sync);
3493 } /*SRXAFS_OldExtendLock*/
3496 afs_int32 SRXAFS_ExtendLock (acall, Fid, Sync)
3497 struct rx_call *acall; /* Rx call */
3498 struct AFSFid *Fid; /* Fid of file whose lock we extend */
3499 struct AFSVolSync *Sync;
3502 struct rx_connection *tcon;
3503 #if FS_STATS_DETAILED
3504 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3505 struct timeval opStartTime,
3506 opStopTime; /* Start/stop times for RPC op*/
3507 struct timeval elapsedTime; /* Transfer time */
3510 * Set our stats pointer, remember when the RPC operation started, and
3511 * tally the operation.
3513 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
3517 TM_GetTimeOfDay(&opStartTime, 0);
3518 #endif /* FS_STATS_DETAILED */
3520 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
3521 goto Bad_ExtendLock;
3523 code = SAFSS_ExtendLock (acall, Fid, Sync);
3526 CallPostamble(tcon);
3528 #if FS_STATS_DETAILED
3529 TM_GetTimeOfDay(&opStopTime, 0);
3532 (opP->numSuccesses)++;
3533 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3534 fs_stats_AddTo((opP->sumTime), elapsedTime);
3535 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3536 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3537 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3539 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3540 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3545 #endif /* FS_STATS_DETAILED */
3547 osi_auditU (acall, ExtendLockEvent, code, AUD_FID, Fid , AUD_END);
3550 } /*SRXAFS_ExtendLock*/
3554 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
3555 * merged into it when possible.
3557 SAFSS_ReleaseLock (acall, Fid, Sync)
3558 struct rx_call *acall; /* Rx call */
3559 struct AFSFid *Fid; /* Fid of file to release lock */
3560 struct AFSVolSync *Sync;
3563 Vnode * targetptr = 0; /* vnode of input file */
3564 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3565 int errorCode = 0; /* error code */
3566 Volume * volptr = 0; /* pointer to the volume header */
3567 struct client * client; /* pointer to client structure */
3568 afs_int32 rights, anyrights; /* rights for this and any user */
3569 struct client *t_client; /* tmp ptr to client data */
3570 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3571 struct rx_connection *tcon = rx_ConnectionOf(acall);
3573 /* Get ptr to client data for user Id for logging */
3574 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3575 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3576 ViceLog(1,("SAFS_ReleaseLock Fid = %u.%d.%d, Host %s, Id %d\n",
3577 Fid->Volume, Fid->Vnode, Fid->Unique,
3578 inet_ntoa(logHostAddr), t_client->ViceId));
3580 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
3583 * Get the vnode and volume for the desired file along with the caller's
3586 if (errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3587 DONTCHECK, &parentwhentargetnotdir,
3588 &client, WRITE_LOCK, &rights, &anyrights)) {
3589 goto Bad_ReleaseLock;
3592 /* set volume synchronization information */
3593 SetVolumeSync(Sync, volptr);
3595 /* Handle the actual lock release */
3596 if (errorCode = HandleLocking(targetptr, rights, LockRelease))
3597 goto Bad_ReleaseLock;
3599 /* if no more locks left, a callback would be triggered here */
3600 if (targetptr->disk.lock.lockCount <= 0) {
3601 /* convert the write lock to a read lock before breaking callbacks */
3602 VVnodeWriteToRead(&errorCode, targetptr);
3603 assert(!errorCode || errorCode == VSALVAGE);
3604 BreakCallBack(client->host, Fid, 0);
3608 /* Put back file's vnode and volume */
3609 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3611 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
3612 errorCode = 0; /* under our generous policy re RO vols */
3614 ViceLog(2,("SAFS_ReleaseLock returns %d\n", errorCode));
3617 } /*SAFSS_ReleaseLock*/
3620 afs_int32 SRXAFS_OldReleaseLock (acall, Fid, Sync)
3621 struct rx_call *acall; /* Rx call */
3622 struct AFSFid *Fid; /* Fid of file to release lock */
3623 struct AFSVolSync *Sync;
3625 return SRXAFS_ReleaseLock(acall, Fid, Sync);
3627 } /*SRXAFS_OldReleaseLock*/
3630 afs_int32 SRXAFS_ReleaseLock (acall, Fid, Sync)
3631 struct rx_call *acall; /* Rx call */
3632 struct AFSFid *Fid; /* Fid of file to release lock */
3633 struct AFSVolSync *Sync;
3636 struct rx_connection *tcon;
3637 #if FS_STATS_DETAILED
3638 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3639 struct timeval opStartTime,
3640 opStopTime; /* Start/stop times for RPC op*/
3641 struct timeval elapsedTime; /* Transfer time */
3644 * Set our stats pointer, remember when the RPC operation started, and
3645 * tally the operation.
3647 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
3651 TM_GetTimeOfDay(&opStartTime, 0);
3652 #endif /* FS_STATS_DETAILED */
3654 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
3655 goto Bad_ReleaseLock;
3657 code = SAFSS_ReleaseLock (acall, Fid, Sync);
3660 CallPostamble(tcon);
3662 #if FS_STATS_DETAILED
3663 TM_GetTimeOfDay(&opStopTime, 0);
3666 (opP->numSuccesses)++;
3667 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3668 fs_stats_AddTo((opP->sumTime), elapsedTime);
3669 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3670 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3671 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3673 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3674 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3679 #endif /* FS_STATS_DETAILED */
3681 osi_auditU (acall, ReleaseLockEvent, code, AUD_FID, Fid , AUD_END);
3684 } /*SRXAFS_ReleaseLock*/
3688 * This routine is called exclusively by SRXAFS_GetStatistics(), and should be
3689 * merged into it when possible.
3691 static GetStatistics (acall, Statistics)
3692 struct rx_call *acall; /* Rx call */
3693 struct AFSStatistics *Statistics; /* Placeholder for returned AFS statistics */
3695 ViceLog(1, ("SAFS_GetStatistics Received\n"));
3697 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
3699 memset(Statistics, 0, sizeof(*Statistics));
3700 SetAFSStats(Statistics);
3701 SetVolumeStats(Statistics);
3702 SetSystemStats(Statistics);
3709 afs_int32 SRXAFS_GetStatistics (acall, Statistics)
3710 struct rx_call *acall; /* Rx call */
3711 struct ViceStatistics *Statistics; /* Placeholder for returned AFS statistics */
3715 struct rx_connection *tcon;
3716 #if FS_STATS_DETAILED
3717 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3718 struct timeval opStartTime,
3719 opStopTime; /* Start/stop times for RPC op*/
3720 struct timeval elapsedTime; /* Transfer time */
3723 * Set our stats pointer, remember when the RPC operation started, and
3724 * tally the operation.
3726 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
3730 TM_GetTimeOfDay(&opStartTime, 0);
3731 #endif /* FS_STATS_DETAILED */
3733 if (code = CallPreamble(acall, NOTACTIVECALL, &tcon))
3734 goto Bad_GetStatistics;
3736 code = GetStatistics (tcon, Statistics);
3739 CallPostamble(tcon);
3741 #if FS_STATS_DETAILED
3742 TM_GetTimeOfDay(&opStopTime, 0);
3745 (opP->numSuccesses)++;
3746 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3747 fs_stats_AddTo((opP->sumTime), elapsedTime);
3748 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3749 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3750 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3752 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3753 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3757 #endif /* FS_STATS_DETAILED */
3761 } /*SRXAFS_GetStatistics*/
3764 /*------------------------------------------------------------------------
3765 * EXPORTED SRXAFS_XStatsVersion
3768 * Routine called by the server-side RPC interface to implement
3769 * pulling out the xstat version number for the File Server.
3772 * a_versionP : Ptr to the version number variable to set.
3778 * Nothing interesting.
3782 *------------------------------------------------------------------------*/
3784 afs_int32 SRXAFS_XStatsVersion(a_call, a_versionP)
3785 struct rx_call *a_call;
3786 afs_int32 *a_versionP;
3788 { /*SRXAFS_XStatsVersion*/
3790 #if FS_STATS_DETAILED
3791 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3792 struct timeval opStartTime,
3793 opStopTime; /* Start/stop times for RPC op*/
3794 struct timeval elapsedTime; /* Transfer time */
3797 * Set our stats pointer, remember when the RPC operation started, and
3798 * tally the operation.
3800 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
3804 TM_GetTimeOfDay(&opStartTime, 0);
3805 #endif /* FS_STATS_DETAILED */
3807 *a_versionP = AFS_XSTAT_VERSION;
3809 #if FS_STATS_DETAILED
3810 TM_GetTimeOfDay(&opStopTime, 0);
3811 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3812 fs_stats_AddTo((opP->sumTime), elapsedTime);
3813 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3814 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3815 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3817 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3818 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3821 (opP->numSuccesses)++;
3823 #endif /* FS_STATS_DETAILED */
3827 } /*SRXAFS_XStatsVersion*/
3830 /*------------------------------------------------------------------------
3831 * PRIVATE FillPerfValues
3834 * Routine called to fill a regular performance data structure.
3837 * a_perfP : Ptr to perf structure to fill
3843 * Various collections need this info, so the guts were put in
3844 * this separate routine.
3848 *------------------------------------------------------------------------*/
3850 static void FillPerfValues(a_perfP)
3851 struct afs_PerfStats *a_perfP;
3853 { /*FillPerfValues*/
3855 int dir_Buffers; /*# buffers in use by dir package*/
3856 int dir_Calls; /*# read calls in dir package*/
3857 int dir_IOs; /*# I/O ops in dir package*/
3860 * Vnode cache section.
3862 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
3863 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
3864 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
3865 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
3866 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
3867 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
3868 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
3869 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
3870 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
3871 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
3872 a_perfP->vcache_H_Entries = VolumeCacheSize;
3873 a_perfP->vcache_H_Gets = VolumeGets;
3874 a_perfP->vcache_H_Replacements = VolumeReplacements;
3877 * Directory section.
3879 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
3880 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
3881 a_perfP->dir_Calls = (afs_int32 )dir_Calls;
3882 a_perfP->dir_IOs = (afs_int32) dir_IOs;
3887 a_perfP->rx_packetRequests =
3888 (afs_int32) rx_stats.packetRequests;
3889 a_perfP->rx_noPackets_RcvClass =
3890 (afs_int32) rx_stats.receivePktAllocFailures;
3891 a_perfP->rx_noPackets_SendClass =
3892 (afs_int32) rx_stats.sendPktAllocFailures;
3893 a_perfP->rx_noPackets_SpecialClass =
3894 (afs_int32) rx_stats.specialPktAllocFailures;
3895 a_perfP->rx_socketGreedy =
3896 (afs_int32) rx_stats.socketGreedy;
3897 a_perfP->rx_bogusPacketOnRead =
3898 (afs_int32) rx_stats.bogusPacketOnRead;
3899 a_perfP->rx_bogusHost =
3900 (afs_int32) rx_stats.bogusHost;
3901 a_perfP->rx_noPacketOnRead =
3902 (afs_int32) rx_stats.noPacketOnRead;
3903 a_perfP->rx_noPacketBuffersOnRead =
3904 (afs_int32) rx_stats.noPacketBuffersOnRead;
3905 a_perfP->rx_selects =
3906 (afs_int32) rx_stats.selects;
3907 a_perfP->rx_sendSelects =
3908 (afs_int32) rx_stats.sendSelects;
3909 a_perfP->rx_packetsRead_RcvClass =
3910 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
3911 a_perfP->rx_packetsRead_SendClass =
3912 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
3913 a_perfP->rx_packetsRead_SpecialClass =
3914 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
3915 a_perfP->rx_dataPacketsRead =
3916 (afs_int32) rx_stats.dataPacketsRead;
3917 a_perfP->rx_ackPacketsRead =
3918 (afs_int32) rx_stats.ackPacketsRead;
3919 a_perfP->rx_dupPacketsRead =
3920 (afs_int32) rx_stats.dupPacketsRead;
3921 a_perfP->rx_spuriousPacketsRead =
3922 (afs_int32) rx_stats.spuriousPacketsRead;
3923 a_perfP->rx_packetsSent_RcvClass =
3924 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
3925 a_perfP->rx_packetsSent_SendClass =
3926 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
3927 a_perfP->rx_packetsSent_SpecialClass =
3928 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
3929 a_perfP->rx_ackPacketsSent =
3930 (afs_int32) rx_stats.ackPacketsSent;
3931 a_perfP->rx_pingPacketsSent =
3932 (afs_int32) rx_stats.pingPacketsSent;
3933 a_perfP->rx_abortPacketsSent =
3934 (afs_int32) rx_stats.abortPacketsSent;
3935 a_perfP->rx_busyPacketsSent =
3936 (afs_int32) rx_stats.busyPacketsSent;
3937 a_perfP->rx_dataPacketsSent =
3938 (afs_int32) rx_stats.dataPacketsSent;
3939 a_perfP->rx_dataPacketsReSent =
3940 (afs_int32) rx_stats.dataPacketsReSent;
3941 a_perfP->rx_dataPacketsPushed =
3942 (afs_int32) rx_stats.dataPacketsPushed;
3943 a_perfP->rx_ignoreAckedPacket =
3944 (afs_int32) rx_stats.ignoreAckedPacket;
3945 a_perfP->rx_totalRtt_Sec =
3946 (afs_int32) rx_stats.totalRtt.sec;
3947 a_perfP->rx_totalRtt_Usec =
3948 (afs_int32) rx_stats.totalRtt.usec;
3949 a_perfP->rx_minRtt_Sec =
3950 (afs_int32) rx_stats.minRtt.sec;
3951 a_perfP->rx_minRtt_Usec =
3952 (afs_int32) rx_stats.minRtt.usec;
3953 a_perfP->rx_maxRtt_Sec =
3954 (afs_int32) rx_stats.maxRtt.sec;
3955 a_perfP->rx_maxRtt_Usec =
3956 (afs_int32) rx_stats.maxRtt.usec;
3957 a_perfP->rx_nRttSamples =
3958 (afs_int32) rx_stats.nRttSamples;
3959 a_perfP->rx_nServerConns =
3960 (afs_int32) rx_stats.nServerConns;
3961 a_perfP->rx_nClientConns =
3962 (afs_int32) rx_stats.nClientConns;
3963 a_perfP->rx_nPeerStructs =
3964 (afs_int32) rx_stats.nPeerStructs;
3965 a_perfP->rx_nCallStructs =
3966 (afs_int32) rx_stats.nCallStructs;
3967 a_perfP->rx_nFreeCallStructs =
3968 (afs_int32) rx_stats.nFreeCallStructs;
3970 a_perfP->host_NumHostEntries = HTs;
3971 a_perfP->host_HostBlocks = HTBlocks;
3972 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
3973 &(a_perfP->host_HostsInSameNetOrSubnet),
3974 &(a_perfP->host_HostsInDiffSubnet),
3975 &(a_perfP->host_HostsInDiffNetwork));
3976 a_perfP->host_NumClients = CEs;
3977 a_perfP->host_ClientBlocks = CEBlocks;
3979 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
3981 } /*FillPerfValues*/
3984 /*------------------------------------------------------------------------
3985 * EXPORTED SRXAFS_GetXStats
3988 * Routine called by the server-side callback RPC interface to
3989 * implement getting the given data collection from the extended
3990 * File Server statistics.
3993 * a_call : Ptr to Rx call on which this request came in.
3994 * a_clientVersionNum : Client version number.
3995 * a_opCode : Desired operation.
3996 * a_serverVersionNumP : Ptr to version number to set.
3997 * a_timeP : Ptr to time value (seconds) to set.
3998 * a_dataP : Ptr to variable array structure to return
4005 * Nothing interesting.
4009 *------------------------------------------------------------------------*/
4011 afs_int32 SRXAFS_GetXStats(a_call, a_clientVersionNum, a_collectionNumber, a_srvVersionNumP, a_timeP, a_dataP)
4012 struct rx_call *a_call;
4013 afs_int32 a_clientVersionNum;
4014 afs_int32 a_collectionNumber;
4015 afs_int32 *a_srvVersionNumP;
4017 AFS_CollData *a_dataP;
4019 { /*SRXAFS_GetXStats*/
4021 register int code; /*Return value*/
4022 afs_int32 *dataBuffP; /*Ptr to data to be returned*/
4023 afs_int32 dataBytes; /*Bytes in data buffer*/
4024 #if FS_STATS_DETAILED
4025 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4026 struct timeval opStartTime,
4027 opStopTime; /* Start/stop times for RPC op*/
4028 struct timeval elapsedTime; /* Transfer time */
4031 * Set our stats pointer, remember when the RPC operation started, and
4032 * tally the operation.
4034 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
4038 TM_GetTimeOfDay(&opStartTime, 0);
4039 #endif /* FS_STATS_DETAILED */
4042 * Record the time of day and the server version number.
4044 *a_srvVersionNumP = AFS_XSTAT_VERSION;
4045 *a_timeP = FT_ApproxTime();
4048 * Stuff the appropriate data in there (assume victory)
4052 ViceLog(1, ("Received GetXStats call for collection %d\n", a_collectionNumber));
4056 * We're not keeping stats, so just return successfully with
4059 a_dataP->AFS_CollData_len = 0;
4060 a_dataP->AFS_CollData_val = (afs_int32 *)0;
4063 switch(a_collectionNumber) {
4064 case AFS_XSTATSCOLL_CALL_INFO:
4066 * Pass back all the call-count-related data.
4068 * >>> We are forced to allocate a separate area in which to
4069 * >>> put this stuff in by the RPC stub generator, since it
4070 * >>> will be freed at the tail end of the server stub code.
4074 * I don't think call-level stats are being collected yet
4075 * for the File Server.
4077 dataBytes = sizeof(struct afs_Stats);
4078 dataBuffP = (afs_int32 *)malloc(dataBytes);
4079 memcpy(dataBuffP, &afs_cmstats, dataBytes);
4080 a_dataP->AFS_CollData_len = dataBytes>>2;
4081 a_dataP->AFS_CollData_val = dataBuffP;
4083 a_dataP->AFS_CollData_len = 0;
4084 a_dataP->AFS_CollData_val = (afs_int32 *)0;
4088 case AFS_XSTATSCOLL_PERF_INFO:
4090 * Pass back all the regular performance-related data.
4092 * >>> We are forced to allocate a separate area in which to
4093 * >>> put this stuff in by the RPC stub generator, since it
4094 * >>> will be freed at the tail end of the server stub code.
4097 afs_perfstats.numPerfCalls++;
4098 FillPerfValues(&afs_perfstats);
4101 * Don't overwrite the spares at the end.
4104 dataBytes = sizeof(struct afs_PerfStats);
4105 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
4106 memcpy(dataBuffP, &afs_perfstats, dataBytes);
4107 a_dataP->AFS_CollData_len = dataBytes>>2;
4108 a_dataP->AFS_CollData_val = dataBuffP;
4111 case AFS_XSTATSCOLL_FULL_PERF_INFO:
4113 * Pass back the full collection of performance-related data.
4114 * We have to stuff the basic, overall numbers in, but the
4115 * detailed numbers are kept in the structure already.
4117 * >>> We are forced to allocate a separate area in which to
4118 * >>> put this stuff in by the RPC stub generator, since it
4119 * >>> will be freed at the tail end of the server stub code.
4122 afs_perfstats.numPerfCalls++;
4123 #if FS_STATS_DETAILED
4124 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
4125 FillPerfValues(&afs_FullPerfStats.overall);
4128 * Don't overwrite the spares at the end.
4131 dataBytes = sizeof(struct fs_stats_FullPerfStats);
4132 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
4133 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
4134 a_dataP->AFS_CollData_len = dataBytes>>2;
4135 a_dataP->AFS_CollData_val = dataBuffP;
4141 * Illegal collection number.
4143 a_dataP->AFS_CollData_len = 0;
4144 a_dataP->AFS_CollData_val = (afs_int32 *)0;
4146 } /*Switch on collection number*/
4148 #if FS_STATS_DETAILED
4149 TM_GetTimeOfDay(&opStopTime, 0);
4152 (opP->numSuccesses)++;
4153 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4154 fs_stats_AddTo((opP->sumTime), elapsedTime);
4155 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4156 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4157 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4159 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4160 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4165 #endif /* FS_STATS_DETAILED */
4169 } /*SRXAFS_GetXStats*/
4172 afs_int32 SRXAFS_GiveUpCallBacks (acall, FidArray, CallBackArray)
4173 struct rx_call *acall; /* Rx call */
4174 struct AFSCBFids *FidArray; /* Array of Fids entries */
4175 struct AFSCBs *CallBackArray; /* array of callbacks */
4178 afs_int32 errorCode;
4180 struct client *client;
4181 struct rx_connection *tcon;
4182 #if FS_STATS_DETAILED
4183 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4184 struct timeval opStartTime,
4185 opStopTime; /* Start/stop times for RPC op*/
4186 struct timeval elapsedTime; /* Transfer time */
4189 * Set our stats pointer, remember when the RPC operation started, and
4190 * tally the operation.
4192 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
4196 TM_GetTimeOfDay(&opStartTime, 0);
4197 #endif /* FS_STATS_DETAILED */
4199 ViceLog(1, ("SAFS_GiveUpCallBacks (Noffids=%d)\n", FidArray->AFSCBFids_len));
4201 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
4203 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
4204 goto Bad_GiveUpCallBacks;
4206 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
4207 ViceLog(0, ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
4208 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
4209 (tcon->peer ? tcon->peer->host : 0)));
4211 goto Bad_GiveUpCallBacks;
4214 errorCode = GetClient(tcon, &client);
4216 for (i=0; i < FidArray->AFSCBFids_len; i++) {
4217 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
4218 DeleteCallBack(client->host, fid);
4222 Bad_GiveUpCallBacks:
4223 CallPostamble(tcon);
4225 #if FS_STATS_DETAILED
4226 TM_GetTimeOfDay(&opStopTime, 0);
4227 if (errorCode == 0) {
4229 (opP->numSuccesses)++;
4230 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4231 fs_stats_AddTo((opP->sumTime), elapsedTime);
4232 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4233 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4234 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4236 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4237 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4241 #endif /* FS_STATS_DETAILED */
4245 } /*SRXAFS_GiveUpCallBacks*/
4248 afs_int32 SRXAFS_NGetVolumeInfo (acall, avolid, avolinfo)
4249 struct rx_call *acall; /* Rx call */
4250 char *avolid; /* Volume name/id */
4251 struct AFSVolumeInfo *avolinfo; /* Returned volume's specific info */
4254 return(VNOVOL); /* XXX Obsolete routine XXX */
4256 } /*SRXAFS_NGetVolumeInfo*/
4260 * Dummy routine. Should never be called (the cache manager should only
4261 * invoke this interface when communicating with a AFS/DFS Protocol
4264 afs_int32 SRXAFS_Lookup(call_p, afs_dfid_p, afs_name_p, afs_fid_p,
4265 afs_status_p, afs_dir_status_p, afs_callback_p, afs_sync_p)
4266 struct rx_call *call_p; /* Rx call handle */
4267 struct AFSFid *afs_dfid_p; /* Directory */
4268 char *afs_name_p; /* Name of file to lookup */
4269 struct AFSFid *afs_fid_p; /* Place to return fid of file */
4270 struct AFSFetchStatus *afs_status_p; /* Place to return file status */
4271 struct AFSFetchStatus *afs_dir_status_p;/* Place to return file status */
4272 struct AFSCallBack *afs_callback_p; /* If r/w, callback promise for Fid */
4273 struct AFSVolSync *afs_sync_p; /* Volume sync info */
4279 afs_int32 SRXAFS_FlushCPS(acall, vids, addrs, spare1, spare2, spare3)
4280 struct rx_call *acall;
4281 struct ViceIds *vids;
4282 struct IPAddrs *addrs;
4283 afs_int32 spare1, *spare2, *spare3;
4286 afs_int32 nids, naddrs;
4287 afs_int32 *vd, *addr;
4288 int errorCode = 0; /* return code to caller */
4289 struct client *client;
4290 struct rx_connection *tcon = rx_ConnectionOf(acall);
4292 ViceLog(1, ("SRXAFS_FlushCPS\n"));
4294 AFSCallStats.TotalCalls++;
4296 nids = vids->ViceIds_len; /* # of users in here */
4297 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
4298 if (nids < 0 || naddrs < 0) {
4303 vd = vids->ViceIds_val;
4304 for (i=0; i<nids; i++, vd++) {
4307 client = h_ID2Client(*vd); /* returns client locked, or NULL */
4311 BoostSharedLock(&client->lock);
4312 client->prfail = 2; /* Means re-eval client's cps */
4315 rx_SetRock(((struct rx_connection *) client->tcon), 0);
4318 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
4319 free(client->CPS.prlist_val);
4320 client->CPS.prlist_val = (afs_int32 *)0;
4322 ReleaseWriteLock(&client->lock);
4325 addr = addrs->IPAddrs_val;
4326 for (i=0; i<naddrs; i++, addr++) {
4328 h_flushhostcps(*addr, 7001);
4332 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
4334 } /*SRXAFS_FlushCPS */
4338 static GetVolumeInfo (acall, avolid, avolinfo)
4339 struct rx_call *acall; /* Rx call */
4340 char *avolid; /* Volume name/id */
4341 struct VolumeInfo *avolinfo; /* Returned volume's specific info */
4344 int errorCode = 0; /* error code */
4347 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
4350 errorCode = TryLocalVLServer(avolid, avolinfo);
4351 ViceLog(1, ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
4352 errorCode, avolinfo->Vid, avolinfo->Type,
4353 avolinfo->Server0, avolinfo->Server1, avolinfo->Server2,
4354 avolinfo->Server3));
4359 /* worthless hack to let CS keep running ancient software */
4360 static afs_vtoi(aname)
4361 register char *aname;
4364 register afs_int32 temp;
4368 while(tc = *aname++) {
4369 if (tc > '9' || tc < '0') return 0; /* invalid name */
4377 * may get name or #, but must handle all weird cases (recognize readonly
4378 * or backup volumes by name or #
4380 static CopyVolumeEntry(aname, ave, av)
4382 register struct VolumeInfo *av;
4383 register struct vldbentry *ave;
4386 register int i, j, vol;
4387 afs_int32 mask, whichType;
4388 afs_uint32 *serverHost, *typePtr;
4390 /* figure out what type we want if by name */
4392 if (i >= 8 && strcmp(aname+i-7, ".backup") == 0)
4393 whichType = BACKVOL;
4394 else if (i >= 10 && strcmp(aname+i-9, ".readonly")==0)
4396 else whichType = RWVOL;
4398 vol = afs_vtoi(aname);
4399 if (vol == 0) vol = ave->volumeId[whichType];
4402 * Now vol has volume # we're interested in. Next, figure out the type
4403 * of the volume by looking finding it in the vldb entry
4405 if ((ave->flags&VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
4409 else if ((ave->flags&VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
4413 else if ((ave->flags&VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
4414 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
4415 whichType = BACKVOL;
4418 return EINVAL; /* error: can't find volume in vldb entry */
4420 typePtr = &av->Type0;
4421 serverHost = &av->Server0;
4423 av->Type = whichType;
4424 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
4425 if (ave->flags & VLF_RWEXISTS) typePtr[RWVOL] = ave->volumeId[RWVOL];
4426 if (ave->flags & VLF_ROEXISTS) typePtr[ROVOL] = ave->volumeId[ROVOL];
4427 if (ave->flags & VLF_BACKEXISTS) typePtr[BACKVOL] = ave->volumeId[BACKVOL];
4429 for(i=0,j=0; i<ave->nServers; i++) {
4430 if ((ave->serverFlags[i] & mask) == 0) continue; /* wrong volume */
4431 serverHost[j] = ave->serverNumber[i];
4434 av->ServerCount = j;
4435 if (j < 8) serverHost[j++] = 0; /* bogus 8, but compat only now */
4440 static TryLocalVLServer(avolid, avolinfo)
4442 struct VolumeInfo *avolinfo;
4445 static struct rx_connection *vlConn = 0;
4446 static int down = 0;
4447 static afs_int32 lastDownTime = 0;
4448 struct vldbentry tve;
4449 struct rx_securityClass *vlSec;
4450 register afs_int32 code;
4453 vlSec = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
4454 vlConn = rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
4455 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
4457 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
4458 return 1; /* failure */
4461 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
4462 if (code >= 0) down = 0; /* call worked */
4465 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
4471 /* otherwise convert to old format vldb entry */
4472 code = CopyVolumeEntry(avolid, &tve, avolinfo);
4477 afs_int32 SRXAFS_GetVolumeInfo (acall, avolid, avolinfo)
4478 struct rx_call *acall; /* Rx call */
4479 char *avolid; /* Volume name/id */
4480 struct VolumeInfo *avolinfo; /* Returned volume's specific info */
4484 struct rx_connection *tcon;
4485 #if FS_STATS_DETAILED
4486 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4487 struct timeval opStartTime,
4488 opStopTime; /* Start/stop times for RPC op*/
4489 struct timeval elapsedTime; /* Transfer time */
4492 * Set our stats pointer, remember when the RPC operation started, and
4493 * tally the operation.
4495 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
4499 TM_GetTimeOfDay(&opStartTime, 0);
4500 #endif /* FS_STATS_DETAILED */
4501 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
4502 goto Bad_GetVolumeInfo;
4504 code = GetVolumeInfo (tcon, avolid, avolinfo);
4505 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
4508 CallPostamble(tcon);
4510 #if FS_STATS_DETAILED
4511 TM_GetTimeOfDay(&opStopTime, 0);
4514 (opP->numSuccesses)++;
4515 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4516 fs_stats_AddTo((opP->sumTime), elapsedTime);
4517 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4518 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4519 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4521 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4522 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4527 #endif /* FS_STATS_DETAILED */
4531 } /*SRXAFS_GetVolumeInfo*/
4534 afs_int32 SRXAFS_GetVolumeStatus (acall, avolid, FetchVolStatus, Name, OfflineMsg, Motd)
4535 struct rx_call *acall; /* Rx call */
4536 afs_int32 avolid; /* Volume's id */
4537 AFSFetchVolumeStatus *FetchVolStatus; /* Place to hold volume's status info */
4538 char **Name; /* Returned volume's name */
4539 char **OfflineMsg; /* Returned offline msg, if any */
4540 char **Motd; /* Returned Motd msg, if any */
4543 Vnode * targetptr = 0; /* vnode of the new file */
4544 Vnode * parentwhentargetnotdir = 0; /* vnode of parent */
4545 int errorCode = 0; /* error code */
4546 Volume * volptr = 0; /* pointer to the volume header */
4547 struct client * client; /* pointer to client entry */
4548 afs_int32 rights, anyrights; /* rights for this and any user */
4550 struct rx_connection *tcon;
4551 #if FS_STATS_DETAILED
4552 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4553 struct timeval opStartTime,
4554 opStopTime; /* Start/stop times for RPC op*/
4555 struct timeval elapsedTime; /* Transfer time */
4558 * Set our stats pointer, remember when the RPC operation started, and
4559 * tally the operation.
4561 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
4565 TM_GetTimeOfDay(&opStartTime, 0);
4566 #endif /* FS_STATS_DETAILED */
4568 ViceLog(1,("SAFS_GetVolumeStatus for volume %u\n", avolid));
4569 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
4570 goto Bad_GetVolumeStatus;
4573 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
4578 goto Bad_GetVolumeStatus;
4580 dummyFid.Volume = avolid, dummyFid.Vnode = (afs_int32)ROOTVNODE, dummyFid.Unique = 1;
4582 if (errorCode = GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr,
4583 MustBeDIR, &parentwhentargetnotdir,
4584 &client, READ_LOCK, &rights, &anyrights))
4585 goto Bad_GetVolumeStatus;
4587 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
4589 goto Bad_GetVolumeStatus;
4591 RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
4593 Bad_GetVolumeStatus:
4594 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
4595 ViceLog(2,("SAFS_GetVolumeStatus returns %d\n",errorCode));
4596 /* next is to guarantee out strings exist for stub */
4597 if (*Name == 0) {*Name = (char *) malloc(1); **Name = 0;}
4598 if (*Motd == 0) {*Motd = (char *) malloc(1); **Motd = 0;}
4599 if (*OfflineMsg == 0) {*OfflineMsg = (char *) malloc(1); **OfflineMsg = 0;}
4600 CallPostamble(tcon);
4602 #if FS_STATS_DETAILED
4603 TM_GetTimeOfDay(&opStopTime, 0);
4604 if (errorCode == 0) {
4606 (opP->numSuccesses)++;
4607 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4608 fs_stats_AddTo((opP->sumTime), elapsedTime);
4609 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4610 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4611 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4613 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4614 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4619 #endif /* FS_STATS_DETAILED */
4622 } /*SRXAFS_GetVolumeStatus*/
4625 afs_int32 SRXAFS_SetVolumeStatus (acall, avolid, StoreVolStatus, Name, OfflineMsg, Motd)
4626 struct rx_call *acall; /* Rx call */
4627 afs_int32 avolid; /* Volume's id */
4628 AFSStoreVolumeStatus *StoreVolStatus; /* Adjusted output volume's status */
4629 char *Name; /* Set new volume's name, if applicable */
4630 char *OfflineMsg; /* Set new offline msg, if applicable */
4631 char *Motd; /* Set new motd msg, if applicable */
4634 Vnode * targetptr = 0; /* vnode of the new file */
4635 Vnode * parentwhentargetnotdir = 0; /* vnode of parent */
4636 int errorCode = 0; /* error code */
4637 Volume * volptr = 0; /* pointer to the volume header */
4638 struct client * client; /* pointer to client entry */
4639 afs_int32 rights, anyrights; /* rights for this and any user */
4641 struct rx_connection *tcon = rx_ConnectionOf(acall);
4642 #if FS_STATS_DETAILED
4643 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4644 struct timeval opStartTime,
4645 opStopTime; /* Start/stop times for RPC op*/
4646 struct timeval elapsedTime; /* Transfer time */
4649 * Set our stats pointer, remember when the RPC operation started, and
4650 * tally the operation.
4652 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
4656 TM_GetTimeOfDay(&opStartTime, 0);
4657 #endif /* FS_STATS_DETAILED */
4659 ViceLog(1,("SAFS_SetVolumeStatus for volume %u\n", avolid));
4660 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
4661 goto Bad_SetVolumeStatus;
4664 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
4669 goto Bad_SetVolumeStatus;
4671 dummyFid.Volume = avolid, dummyFid.Vnode = (afs_int32)ROOTVNODE, dummyFid.Unique = 1;
4673 if (errorCode = GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr,
4674 MustBeDIR, &parentwhentargetnotdir,
4675 &client, READ_LOCK, &rights, &anyrights))
4676 goto Bad_SetVolumeStatus;
4678 if (VanillaUser(client)) {
4680 goto Bad_SetVolumeStatus;
4683 errorCode = RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name,
4686 Bad_SetVolumeStatus:
4687 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
4688 ViceLog(2,("SAFS_SetVolumeStatus returns %d\n",errorCode));
4689 CallPostamble(tcon);
4691 #if FS_STATS_DETAILED
4692 TM_GetTimeOfDay(&opStopTime, 0);
4693 if (errorCode == 0) {
4695 (opP->numSuccesses)++;
4696 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4697 fs_stats_AddTo((opP->sumTime), elapsedTime);
4698 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4699 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4700 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4702 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4703 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4708 #endif /* FS_STATS_DETAILED */
4710 osi_auditU (acall, SetVolumeStatusEvent, errorCode, AUD_LONG, avolid, AUD_STR, Name, AUD_END);
4713 } /*SRXAFS_SetVolumeStatus*/
4715 #define DEFAULTVOLUME "root.afs"
4718 afs_int32 SRXAFS_GetRootVolume (acall, VolumeName)
4719 struct rx_call *acall; /* Rx call */
4720 char **VolumeName; /* Returned AFS's root volume name */
4726 int errorCode = 0; /* error code */
4727 struct rx_connection *tcon;
4728 #if FS_STATS_DETAILED
4729 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4730 struct timeval opStartTime,
4731 opStopTime; /* Start/stop times for RPC op*/
4732 struct timeval elapsedTime; /* Transfer time */
4735 * Set our stats pointer, remember when the RPC operation started, and
4736 * tally the operation.
4738 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
4742 TM_GetTimeOfDay(&opStartTime, 0);
4743 #endif /* FS_STATS_DETAILED */
4745 return FSERR_EOPNOTSUPP;
4748 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
4749 goto Bad_GetRootVolume;
4751 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
4755 fd = open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
4757 strcpy(temp, DEFAULTVOLUME);
4759 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
4760 lockf(fd, F_LOCK, 0);
4764 len = read(fd, temp, 256);
4765 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
4766 lockf(fd, F_ULOCK, 0);
4771 if (temp[len-1] == '\n') len--;
4774 *VolumeName = temp; /* freed by rx server-side stub */
4777 CallPostamble(tcon);
4779 #if FS_STATS_DETAILED
4780 TM_GetTimeOfDay(&opStopTime, 0);
4781 if (errorCode == 0) {
4783 (opP->numSuccesses)++;
4784 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4785 fs_stats_AddTo((opP->sumTime), elapsedTime);
4786 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4787 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4788 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4790 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4791 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4795 #endif /* FS_STATS_DETAILED */
4800 } /*SRXAFS_GetRootVolume*/
4803 /* still works because a struct CBS is the same as a struct AFSOpaque */
4804 afs_int32 SRXAFS_CheckToken (acall, AfsId, Token)
4805 struct rx_call *acall; /* Rx call */
4806 afs_int32 AfsId; /* AFS id whose token we verify */
4807 struct AFSOpaque *Token; /* Token value for used Afsid */
4811 struct rx_connection *tcon;
4812 #if FS_STATS_DETAILED
4813 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4814 struct timeval opStartTime,
4815 opStopTime; /* Start/stop times for RPC op*/
4816 struct timeval elapsedTime; /* Transfer time */
4819 * Set our stats pointer, remember when the RPC operation started, and
4820 * tally the operation.
4822 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
4826 TM_GetTimeOfDay(&opStartTime, 0);
4827 #endif /* FS_STATS_DETAILED */
4829 if (code = CallPreamble(acall, ACTIVECALL, &tcon))
4830 goto Bad_CheckToken;
4832 code = FSERR_ECONNREFUSED;
4835 CallPostamble(tcon);
4837 #if FS_STATS_DETAILED
4838 TM_GetTimeOfDay(&opStopTime, 0);
4841 (opP->numSuccesses)++;
4842 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4843 fs_stats_AddTo((opP->sumTime), elapsedTime);
4844 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4845 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4846 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4848 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4849 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4854 #endif /* FS_STATS_DETAILED */
4858 } /*SRXAFS_CheckToken*/
4861 static GetTime (acall, Seconds, USeconds)
4862 struct rx_call *acall; /* Rx call */
4863 afs_uint32 *Seconds; /* Returned time in seconds */
4864 afs_uint32 *USeconds; /* Returned leftovers in useconds */
4870 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
4873 TM_GetTimeOfDay(&tpl, 0);
4874 *Seconds = tpl.tv_sec;
4875 *USeconds = tpl.tv_usec;
4877 ViceLog(2, ("SAFS_GetTime returns %d, %d\n", *Seconds, *USeconds));
4883 afs_int32 SRXAFS_GetTime (acall, Seconds, USeconds)
4884 struct rx_call *acall; /* Rx call */
4885 afs_uint32 *Seconds; /* Returned time in seconds */
4886 afs_uint32 *USeconds; /* Returned leftovers in useconds */
4889 struct rx_connection *tcon;
4890 #if FS_STATS_DETAILED
4891 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4892 struct timeval opStartTime,
4893 opStopTime; /* Start/stop times for RPC op*/
4894 struct timeval elapsedTime; /* Transfer time */
4897 * Set our stats pointer, remember when the RPC operation started, and
4898 * tally the operation.
4900 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
4904 TM_GetTimeOfDay(&opStartTime, 0);
4905 #endif /* FS_STATS_DETAILED */
4907 if (code = CallPreamble(acall, NOTACTIVECALL, &tcon))
4910 code = GetTime (tcon, Seconds, USeconds);
4913 CallPostamble(tcon);
4915 #if FS_STATS_DETAILED
4916 TM_GetTimeOfDay(&opStopTime, 0);
4917 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4920 (opP->numSuccesses)++;
4921 fs_stats_AddTo((opP->sumTime), elapsedTime);
4922 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4923 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4924 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4926 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4927 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4932 #endif /* FS_STATS_DETAILED */
4936 } /*SRXAFS_GetTime*/
4939 /*=============================================================================*/
4941 /* AUXILIARY functions that are used by the main AFS interface procedure calls */
4943 /*=============================================================================*/
4947 * This unusual afs_int32-parameter routine encapsulates all volume package related
4948 * operations together in a single function; it's called by almost all AFS
4951 GetVolumePackage(tcon, Fid, volptr, targetptr, chkforDir, parent, client, locktype, rights, anyrights)
4952 struct rx_connection *tcon; /* Rx connection */
4953 AFSFid *Fid; /* Fid that we are dealing with */
4954 Volume **volptr; /* Returns pointer to volume associated with Fid */
4955 Vnode **targetptr; /* Returns pointer to vnode associated with Fid */
4956 int chkforDir; /* Flag testing whether Fid is/or not a dir */
4957 Vnode **parent; /* If Fid not a dir, this points to the parent dir */
4958 struct client **client; /* Returns the client associated with the conn */
4959 int locktype; /* locktype (READ or WRITE) for the Fid vnode */
4960 afs_int32 *rights, *anyrights; /* Returns user's & any acl rights */
4963 struct acl_accessList * aCL; /* Internal access List */
4964 int aCLSize; /* size of the access list */
4965 int errorCode = 0; /* return code to caller */
4967 if (errorCode = CheckVnode(Fid, volptr, targetptr, locktype))
4970 if (chkforDir == MustNOTBeDIR && ((*targetptr)->disk.type == vDirectory))
4972 else if (chkforDir == MustBeDIR && ((*targetptr)->disk.type != vDirectory))
4975 if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent, (chkforDir == MustBeDIR ? (AFSFid *)0 : Fid), (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
4977 if (chkforDir == MustBeDIR) assert((*parent) == 0);
4978 if ((errorCode = GetClient(tcon, client)) != 0)
4982 assert(GetRights(*client, aCL, rights, anyrights) == 0);
4983 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
4984 if ((*targetptr)->disk.type != vDirectory) {
4985 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
4986 if ((*targetptr)->disk.owner == (*client)->ViceId)
4987 (*rights) |= PRSFS_ADMINISTER;
4989 (*rights) &= ~PRSFS_ADMINISTER;
4991 #ifdef ADMIN_IMPLICIT_LOOKUP
4992 /* admins get automatic lookup on everything */
4993 if (!VanillaUser(*client)) (*rights) |= PRSFS_LOOKUP;
4994 #endif /* ADMIN_IMPLICIT_LOOKUP */
4997 } /*GetVolumePackage*/
5001 * This is the opposite of GetVolumePackage(), and is always used at the end of
5002 * AFS calls to put back all used vnodes and the volume in the proper order!
5004 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr)
5005 Vnode *parentwhentargetnotdir, *targetptr, *parentptr;
5009 int fileCode = 0; /* Error code returned by the volume package */
5011 if (parentwhentargetnotdir) {
5012 VPutVnode(&fileCode, parentwhentargetnotdir);
5013 assert(!fileCode || (fileCode == VSALVAGE));
5016 VPutVnode(&fileCode, targetptr);
5017 assert(!fileCode || (fileCode == VSALVAGE));
5020 VPutVnode(&fileCode, parentptr);
5021 assert(!fileCode || (fileCode == VSALVAGE));
5026 } /*PutVolumePackage*/
5029 #if FS_STATS_DETAILED
5034 * Implement a client's data fetch using Rx.
5037 * volptr : Ptr to the given volume's info.
5038 * targetptr : Pointer to the vnode involved.
5039 * Call : Ptr to the Rx call involved.
5040 * Pos : Offset within the file.
5041 * Len : Length in bytes to read; this value is bogus!
5042 * a_bytesToFetchP : Set to the number of bytes to be fetched from
5044 * a_bytesFetchedP : Set to the actual number of bytes fetched from
5048 FetchData_RXStyle(volptr, targetptr, Call, Pos, Len, Int64Mode, a_bytesToFetchP, a_bytesFetchedP)
5050 FetchData_RXStyle(volptr, targetptr, Call, Pos, Len, Int64Mode)
5051 #endif /* FS_STATS_DETAILED */
5054 register struct rx_call * Call;
5057 afs_int32 Int64Mode;
5058 #if FS_STATS_DETAILED
5059 afs_int32 *a_bytesToFetchP;
5060 afs_int32 *a_bytesFetchedP;
5061 #endif /* FS_STATS_DETAILED */
5063 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
5064 int errorCode = 0; /* Returned error code to caller */
5069 register char *tbuffer;
5070 #else /* AFS_NT40_ENV */
5071 struct iovec tiov[RX_MAXIOVECS];
5073 #endif /* AFS_NT40_ENV */
5078 struct statfs tstatfs;
5081 #if FS_STATS_DETAILED
5083 * Initialize the byte count arguments.
5085 (*a_bytesToFetchP) = 0;
5086 (*a_bytesFetchedP) = 0;
5087 #endif /* FS_STATS_DETAILED */
5089 if (!VN_GET_INO(targetptr)) {
5091 * This is used for newly created files; we simply send 0 bytes
5092 * back to make the cache manager happy...
5096 rx_Write(Call, &tlen, sizeof(afs_int32)); /* send 0-length */
5097 rx_Write(Call, &tlen, sizeof(afs_int32)); /* send 0-length */
5100 TM_GetTimeOfDay(&StartTime, 0);
5101 ihP = targetptr->handle;
5103 if (fdP == NULL) return EIO;
5104 optSize = AFSV_BUFFERSIZE;
5105 tlen = FDH_SIZE(fdP);
5111 if (Pos + Len > tlen) Len = tlen - Pos; /* get length we should send */
5112 FDH_SEEK(fdP, Pos, 0);
5116 rx_Write(Call, &zero, sizeof(afs_int32)); /* High order bits */
5118 rx_Write(Call, &tlen, sizeof(afs_int32)); /* send length on fetch */
5119 #if FS_STATS_DETAILED
5120 (*a_bytesToFetchP) = Len;
5121 #endif /* FS_STATS_DETAILED */
5123 tbuffer = AllocSendBuffer();
5124 #endif /* AFS_NT40_ENV */
5126 if (Len > optSize) tlen = optSize;
5129 errorCode = FDH_READ(fdP, tbuffer, tlen);
5130 if (errorCode != tlen) {
5132 FreeSendBuffer((struct afs_buffer *) tbuffer);
5135 errorCode = rx_Write(Call, tbuffer, tlen);
5136 #else /* AFS_NT40_ENV */
5137 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, tlen);
5138 if (errorCode <= 0) {
5143 errorCode = FDH_READV(fdP, tiov, tnio);
5144 if (errorCode != tlen) {
5148 errorCode = rx_Writev(Call, tiov, tnio, tlen);
5149 #endif /* AFS_NT40_ENV */
5150 #if FS_STATS_DETAILED
5152 * Bump the number of bytes actually sent by the number from this
5155 (*a_bytesFetchedP) += errorCode;
5156 #endif /* FS_STATS_DETAILED */
5157 if (errorCode != tlen) {
5160 FreeSendBuffer((struct afs_buffer *) tbuffer);
5161 #endif /* AFS_NT40_ENV */
5167 FreeSendBuffer((struct afs_buffer *) tbuffer);
5168 #endif /* AFS_NT40_ENV */
5170 TM_GetTimeOfDay(&StopTime, 0);
5172 /* Adjust all Fetch Data related stats */
5174 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
5175 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
5176 AFSCallStats.AccumFetchTime += ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
5177 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
5178 AFSCallStats.TotalFetchedBytes += targetptr->disk.length;
5179 AFSCallStats.FetchSize1++;
5180 if (targetptr->disk.length < SIZE2)
5181 AFSCallStats.FetchSize2++;
5182 else if (targetptr->disk.length < SIZE3)
5183 AFSCallStats.FetchSize3++;
5184 else if (targetptr->disk.length < SIZE4)
5185 AFSCallStats.FetchSize4++;
5187 AFSCallStats.FetchSize5++;
5191 } /*FetchData_RXStyle*/
5193 static int GetLinkCountAndSize(Volume *vp, FdHandle_t *fdP, int *lc, int *size)
5195 #ifdef AFS_NAMEI_ENV
5197 lhp = IH_OPEN(V_linkHandle(vp));
5201 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
5203 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
5208 *size = OS_SIZE(fdP->fd_fd);
5209 return (*size == -1) ? -1 : 0;
5213 if (fstat(fdP->fd_fd, &status)<0) {
5217 *lc = GetLinkCount(vp, &status);
5218 *size = status.st_size;
5223 #if FS_STATS_DETAILED
5228 * Implement a client's data store using Rx.
5231 * volptr : Ptr to the given volume's info.
5232 * targetptr : Pointer to the vnode involved.
5233 * Call : Ptr to the Rx call involved.
5234 * Pos : Offset within the file.
5235 * Len : Length in bytes to store; this value is bogus!
5236 * a_bytesToStoreP : Set to the number of bytes to be stored to
5238 * a_bytesStoredP : Set to the actual number of bytes stored to
5242 StoreData_RXStyle(volptr, targetptr, Fid, client, Call, Pos, Length,
5243 FileLength, sync, a_bytesToStoreP, a_bytesStoredP)
5245 StoreData_RXStyle(volptr, targetptr, Fid, client, Call, Pos, Length,
5247 #endif /* FS_STATS_DETAILED */
5252 struct client *client;
5253 register struct rx_call *Call;
5256 afs_uint32 FileLength;
5258 #if FS_STATS_DETAILED
5259 afs_int32 *a_bytesToStoreP;
5260 afs_int32 *a_bytesStoredP;
5261 #endif /* FS_STATS_DETAILED */
5264 int bytesTransfered; /* number of bytes actually transfered */
5265 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
5266 int errorCode = 0; /* Returned error code to caller */
5268 register char *tbuffer; /* data copying buffer */
5269 #else /* AFS_NT40_ENV */
5270 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
5271 int tnio; /* temp for iovec size */
5272 #endif /* AFS_NT40_ENV */
5273 int tlen; /* temp for xfr length */
5274 Inode tinode; /* inode for I/O */
5275 afs_int32 optSize; /* optimal transfer size */
5276 int DataLength; /* size of inode */
5277 afs_int32 TruncatedLength; /* size after ftruncate */
5278 afs_int32 NewLength; /* size after this store completes */
5279 afs_int32 adjustSize; /* bytes to call VAdjust... with */
5280 int linkCount; /* link count on inode */
5283 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5285 #if FS_STATS_DETAILED
5287 * Initialize the byte count arguments.
5289 (*a_bytesToStoreP) = 0;
5290 (*a_bytesStoredP) = 0;
5291 #endif /* FS_STATS_DETAILED */
5294 * We break the callbacks here so that the following signal will not
5297 BreakCallBack(client->host, Fid, 0);
5299 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
5300 /* the inode should have been created in Alloc_NewVnode */
5301 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(Call)));
5302 ViceLog(0, ("StoreData_RXStyle : Inode non-existent Fid = %u.%d.%d, inode = %d, Pos %d Host %s\n",
5303 Fid->Volume, Fid->Vnode, Fid->Unique,
5304 VN_GET_INO(targetptr), Pos, inet_ntoa(logHostAddr) ));
5305 return ENOENT; /* is this proper error code? */
5309 * See if the file has several links (from other volumes). If it
5310 * does, then we have to make a copy before changing it to avoid
5311 *changing read-only clones of this dude
5313 ViceLog(25, ("StoreData_RXStyle : Opening inode %s\n",
5314 PrintInode(NULL, VN_GET_INO(targetptr))));
5315 fdP = IH_OPEN(targetptr->handle);
5318 if (GetLinkCountAndSize(volptr, fdP, &linkCount,
5324 if (linkCount != 1) {
5326 ViceLog(25, ("StoreData_RXStyle : inode %s has more than onelink\n",
5327 PrintInode(NULL, VN_GET_INO(targetptr))));
5328 /* other volumes share this data, better copy it first */
5330 /* Adjust the disk block count by the creation of the new inode.
5331 * We call the special VDiskUsage so we don't adjust the volume's
5332 * quota since we don't want to penalyze the user for afs's internal
5333 * mechanisms (i.e. copy on write overhead.) Also the right size
5334 * of the disk will be recorded...
5337 size = targetptr->disk.length;
5338 volptr->partition->flags &= ~PART_DONTUPDATE;
5339 VSetPartitionDiskUsage(volptr->partition);
5340 volptr->partition->flags |= PART_DONTUPDATE;
5341 if (errorCode = VDiskUsage(volptr, nBlocks(size))) {
5342 volptr->partition->flags &= ~PART_DONTUPDATE;
5346 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
5347 if ( errorCode = CopyOnWrite(targetptr, volptr))
5349 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
5350 volptr->partition->flags &= ~PART_DONTUPDATE;
5353 volptr->partition->flags &= ~PART_DONTUPDATE;
5354 VSetPartitionDiskUsage(volptr->partition);
5355 fdP = IH_OPEN(targetptr->handle);
5357 ViceLog(25, ("StoreData : Reopen after CopyOnWrite failed\n"));
5361 tinode = VN_GET_INO(targetptr);
5363 assert(VALID_INO(tinode));
5365 /* compute new file length */
5366 NewLength = DataLength;
5367 if (FileLength < NewLength)
5368 /* simulate truncate */
5369 NewLength = FileLength;
5370 TruncatedLength = NewLength; /* remember length after possible ftruncate */
5371 if (Pos + Length > NewLength)
5372 NewLength = Pos+Length; /* and write */
5374 /* adjust the disk block count by the difference in the files */
5375 adjustSize = (int) (nBlocks(NewLength) - nBlocks(targetptr->disk.length));
5376 if(errorCode = AdjustDiskUsage(volptr, adjustSize,
5377 adjustSize - SpareComp(volptr))) {
5382 /* can signal cache manager to proceed from close now */
5383 /* this bit means that the locks are set and protections are OK */
5384 rx_SetLocalStatus(Call, 1);
5386 TM_GetTimeOfDay(&StartTime, 0);
5388 optSize = AFSV_BUFFERSIZE;
5390 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
5391 if (FileLength < DataLength) FDH_TRUNC(fdP, FileLength);
5392 if (Pos > 0) FDH_SEEK(fdP, Pos, 0);
5393 bytesTransfered = 0;
5395 tbuffer = AllocSendBuffer();
5396 #endif /* AFS_NT40_ENV */
5397 /* if length == 0, the loop below isn't going to do anything, including
5398 * extend the length of the inode, which it must do, since the file system
5399 * assumes that the inode length == vnode's file length. So, we extend
5400 * the file length manually if need be. Note that if file is bigger than
5401 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
5402 * do what we're going to do below.
5404 if (Length == 0 && Pos > TruncatedLength) {
5405 /* Set the file's length; we've already done an lseek to the right
5408 errorCode = FDH_WRITE(fdP, &tlen, 1);
5409 if (errorCode != 1) goto done;
5410 errorCode = FDH_TRUNC(fdP, Pos);
5413 /* have some data to copy */
5414 #if FS_STATS_DETAILED
5415 (*a_bytesToStoreP) = Length;
5416 #endif /* FS_STATS_DETAILED */
5418 if (bytesTransfered >= Length) {
5422 tlen = Length - bytesTransfered; /* how much more to do */
5423 if (tlen > optSize) tlen = optSize; /* bound by buffer size */
5425 errorCode = rx_Read(Call, tbuffer, tlen);
5426 #else /* AFS_NT40_ENV */
5427 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, tlen);
5428 #endif /* AFS_NT40_ENV */
5429 #if FS_STATS_DETAILED
5430 (*a_bytesStoredP) += errorCode;
5431 #endif /* FS_STATS_DETAILED */
5432 if (errorCode <= 0) {
5438 errorCode = FDH_WRITE(fdP, tbuffer, tlen);
5439 #else /* AFS_NT40_ENV */
5440 errorCode = FDH_WRITEV(fdP, tiov, tnio);
5441 #endif /* AFS_NT40_ENV */
5442 if (errorCode != tlen) {
5443 errorCode = VDISKFULL;
5446 bytesTransfered += tlen;
5451 FreeSendBuffer((struct afs_buffer *) tbuffer);
5452 #endif /* AFS_NT40_ENV */
5457 /* something went wrong: adjust size and return */
5458 targetptr->disk.length = FDH_SIZE(fdP); /* set new file size. */
5459 /* changed_newTime is tested in StoreData to detemine if we
5460 * need to update the target vnode.
5462 targetptr->changed_newTime = 1;
5464 /* set disk usage to be correct */
5465 VAdjustDiskUsage(&errorCode, volptr,
5466 (int)(nBlocks(targetptr->disk.length)
5467 - nBlocks(NewLength)), 0);
5472 TM_GetTimeOfDay(&StopTime, 0);
5474 targetptr->disk.length = NewLength;
5476 /* Update all StoreData related stats */
5478 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
5479 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
5480 AFSCallStats.StoreSize1++; /* Piggybacked data */
5481 if (targetptr->disk.length < SIZE2)
5482 AFSCallStats.StoreSize2++;
5483 else if (targetptr->disk.length < SIZE3)
5484 AFSCallStats.StoreSize3++;
5485 else if (targetptr->disk.length < SIZE4)
5486 AFSCallStats.StoreSize4++;
5488 AFSCallStats.StoreSize5++;
5492 } /*StoreData_RXStyle*/
5496 * Check if target file has the proper access permissions for the Fetch
5497 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
5498 * StoreStatus) related calls
5500 /* this code should probably just set a "priv" flag where all the audit events
5501 * are now, and only generate the audit event once at the end of the routine,
5502 * thus only generating the event if all the checks succeed, but only because
5503 * of the privilege XXX
5505 Check_PermissionRights(targetptr, client, rights, CallingRoutine, InStatus)
5507 struct client *client;
5510 AFSStoreStatus *InStatus;
5514 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
5515 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
5516 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
5518 if (CallingRoutine & CHK_FETCH) {
5520 if (VanillaUser(client))
5522 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client))
5525 if (targetptr->disk.type == vDirectory || targetptr->disk.type == vSymlink) {
5526 if ( !(rights & PRSFS_LOOKUP)
5527 #ifdef ADMIN_IMPLICIT_LOOKUP
5528 /* grant admins fetch on all directories */
5529 && VanillaUser(client)
5530 #endif /* ADMIN_IMPLICIT_LOOKUP */
5531 && !OWNSp(client, targetptr)
5532 && !acl_IsAMember(targetptr->disk.owner, &client->CPS)
5533 && !VolumeOwner(client, targetptr))
5536 /* must have read access, or be owner and have insert access */
5537 if (!(rights & PRSFS_READ) &&
5538 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
5541 if (CallingRoutine == CHK_FETCHDATA && targetptr->disk.type == vFile)
5542 #ifdef USE_GROUP_PERMS
5543 if (!OWNSp(client, targetptr) &&
5544 !acl_IsAMember(targetptr->disk.owner, &client->CPS)) {
5545 errorCode = (((GROUPREAD|GROUPEXEC) & targetptr->disk.modeBits)
5548 errorCode =(((OWNERREAD|OWNEREXEC) & targetptr->disk.modeBits)
5553 * The check with the ownership below is a kludge to allow
5554 * reading of files created with no read permission. The owner
5555 * of the file is always allowed to read it.
5557 if ((client->ViceId != targetptr->disk.owner) && VanillaUser(client))
5558 errorCode =(((OWNERREAD|OWNEREXEC) & targetptr->disk.modeBits) ? 0: EACCES);
5561 else /* !VanillaUser(client) && !FetchData */ {
5562 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
5563 AUD_INT, CallingRoutine, AUD_END);
5566 else { /* a store operation */
5567 if ( (rights & PRSFS_INSERT) && OWNSp(client, targetptr)
5568 && (CallingRoutine != CHK_STOREACL)
5569 && (targetptr->disk.type == vFile))
5571 /* bypass protection checks on first store after a create
5572 * for the creator; also prevent chowns during this time
5573 * unless you are a system administrator */
5574 /****** InStatus->Owner && UnixModeBits better be SET!! */
5575 if ( CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
5576 if (VanillaUser (client))
5577 return(EPERM); /* Was EACCES */
5579 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
5580 AUD_INT, CallingRoutine, AUD_END);
5583 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
5584 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
5585 AUD_INT, CallingRoutine, AUD_END);
5588 if (CallingRoutine == CHK_STOREACL) {
5589 if (!(rights & PRSFS_ADMINISTER) &&
5590 !OWNSp(client, targetptr) &&
5591 !acl_IsAMember(targetptr->disk.owner, &client->CPS) &&
5592 !VolumeOwner(client, targetptr)) return(EACCES);
5594 else { /* store data or status */
5595 /* watch for chowns and chgrps */
5596 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr))
5597 return(EPERM); /* Was EACCES */
5598 /* must be sysadmin to set suid/sgid bits */
5599 if ((InStatus->Mask & AFS_SETMODE) &&
5601 (InStatus->UnixModeBits & 0xc00) != 0) {
5603 (InStatus->UnixModeBits & (S_ISUID|S_ISGID)) != 0) {
5605 if (VanillaUser(client))
5607 else osi_audit( PrivSetID, 0, AUD_INT, (client ? client->ViceId : 0),
5608 AUD_INT, CallingRoutine, AUD_END);
5610 if (CallingRoutine == CHK_STOREDATA) {
5611 if (!(rights & PRSFS_WRITE))
5613 /* Next thing is tricky. We want to prevent people
5614 * from writing files sans 0200 bit, but we want
5615 * creating new files with 0444 mode to work. We
5616 * don't check the 0200 bit in the "you are the owner"
5617 * path above, but here we check the bit. However, if
5618 * you're a system administrator, we ignore the 0200
5619 * bit anyway, since you may have fchowned the file,
5621 #ifdef USE_GROUP_PERMS
5622 if ((targetptr->disk.type == vFile)
5623 && VanillaUser(client)) {
5624 if (!OWNSp(client, targetptr) &&
5625 !acl_IsAMember(targetptr->disk.owner,
5627 errorCode = ((GROUPWRITE & targetptr->disk.modeBits)
5630 errorCode = ((OWNERWRITE & targetptr->disk.modeBits)
5635 if ((targetptr->disk.type != vDirectory)
5636 && (!(targetptr->disk.modeBits & OWNERWRITE)))
5637 if (VanillaUser(client))
5639 else osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
5640 AUD_INT, CallingRoutine, AUD_END);
5642 else { /* a status store */
5643 if (targetptr->disk.type == vDirectory) {
5644 if (!(rights & PRSFS_DELETE) && !(rights & PRSFS_INSERT))
5647 else { /* a file or symlink */
5648 if (!(rights & PRSFS_WRITE)) return(EACCES);
5657 } /*Check_PermissionRights*/
5661 * The Access List information is converted from its internal form in the
5662 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
5663 * external form and returned back to the caller, via the AccessList
5666 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)
5668 Vnode * parentwhentargetnotdir;
5669 struct AFSOpaque * AccessList;
5671 char * eACL; /* External access list placeholder */
5673 if (acl_Externalize((targetptr->disk.type == vDirectory ?
5674 VVnodeACL(targetptr) :
5675 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
5678 if ((strlen(eACL)+1) > AFSOPAQUEMAX) {
5679 acl_FreeExternalACL(&eACL);
5682 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
5683 AccessList->AFSOpaque_len = strlen(eACL) +1;
5685 acl_FreeExternalACL(&eACL);
5688 } /*RXFetch_AccessList*/
5692 * The Access List information is converted from its external form in the
5693 * input AccessList structure to the internal representation and copied into
5694 * the target dir's vnode storage.
5696 RXStore_AccessList(targetptr, AccessList)
5698 struct AFSOpaque *AccessList;
5701 struct acl_accessList * newACL; /* PlaceHolder for new access list */
5703 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
5705 if ((newACL->size + 4) > VAclSize(targetptr))
5707 memcpy((char *) VVnodeACL(targetptr), (char *) newACL, (int)(newACL->size));
5708 acl_FreeACL(&newACL);
5711 } /*RXStore_AccessList*/
5714 Fetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)
5716 Vnode *parentwhentargetnotdir;
5717 struct AFSAccessList *AccessList;
5720 char * eACL; /* External access list placeholder */
5722 assert(acl_Externalize((targetptr->disk.type == vDirectory ?
5723 VVnodeACL(targetptr) :
5724 VVnodeACL(parentwhentargetnotdir)), &eACL) == 0);
5725 if ((strlen(eACL)+1) > AccessList->MaxSeqLen) {
5726 acl_FreeExternalACL(&eACL);
5729 strcpy((char *)(AccessList->SeqBody), (char *)eACL);
5730 AccessList->SeqLen = strlen(eACL) +1;
5732 acl_FreeExternalACL(&eACL);
5735 } /*Fetch_AccessList*/
5739 * The Access List information is converted from its external form in the
5740 * input AccessList structure to the internal representation and copied into
5741 * the target dir's vnode storage.
5743 Store_AccessList(targetptr, AccessList)
5745 struct AFSAccessList *AccessList;
5748 struct acl_accessList * newACL; /* PlaceHolder for new access list */
5750 if (acl_Internalize(AccessList->SeqBody, &newACL) != 0)
5752 if ((newACL->size + 4) > VAclSize(targetptr))
5754 memcpy((char *) VVnodeACL(targetptr), (char *) newACL, (int)(newACL->size));
5755 acl_FreeACL(&newACL);
5758 } /*Store_AccessList*/
5762 * Common code to handle with removing the Name (file when it's called from
5763 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
5764 * given directory, parentptr.
5767 DeleteTarget(parentptr, volptr, targetptr, dir, fileFid, Name, ChkForDir)
5776 DirHandle childdir; /* Handle for dir package I/O */
5780 /* watch for invalid names */
5781 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
5783 if (parentptr->disk.cloned)
5785 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
5786 if ( errorCode = CopyOnWrite(parentptr, volptr))
5788 ViceLog(20, ("DeleteTarget %s: CopyOnWrite failed %d\n",Name,errorCode));
5793 /* check that the file is in the directory */
5794 SetDirHandle(dir, parentptr);
5795 if (Lookup(dir, Name, fileFid))
5797 fileFid->Volume = V_id(volptr);
5799 /* just-in-case check for something causing deadlock */
5800 if (fileFid->Vnode == parentptr->vnodeNumber)
5803 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
5807 if (ChkForDir == MustBeDIR) {
5808 if ((*targetptr)->disk.type != vDirectory)
5810 } else if ((*targetptr)->disk.type == vDirectory)
5813 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique);*/
5815 * If the uniquifiers dont match then instead of asserting
5816 * take the volume offline and return VSALVAGE
5818 if ( (*targetptr)->disk.uniquifier != fileFid->Unique ) {
5819 VTakeOffline(volptr);
5820 errorCode = VSALVAGE;
5824 if (ChkForDir == MustBeDIR) {
5825 SetDirHandle(&childdir, *targetptr);
5826 if (IsEmpty(&childdir) != 0)
5829 (*targetptr)->delete = 1;
5830 } else if ((--(*targetptr)->disk.linkCount) == 0)
5831 (*targetptr)->delete = 1;
5832 if ((*targetptr)->delete) {
5833 if (VN_GET_INO(*targetptr)) {
5835 IH_REALLYCLOSE((*targetptr)->handle);
5836 errorCode = IH_DEC(V_linkHandle(volptr),
5837 VN_GET_INO(*targetptr),
5838 V_parentId(volptr));
5839 IH_RELEASE((*targetptr)->handle);
5840 if (errorCode == -1) {
5841 ViceLog(0, ("DT: inode=%s, name=%s, errno=%d\n",
5842 PrintInode(NULL, VN_GET_INO(*targetptr)),
5845 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
5847 if (errno != ENOENT)
5850 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
5852 VTakeOffline(volptr);
5859 VN_SET_INO(*targetptr, (Inode)0);
5860 VAdjustDiskUsage(&errorCode, volptr,
5861 -(int)nBlocks((*targetptr)->disk.length), 0);
5864 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
5866 code = Delete(dir,(char *) Name);
5868 ViceLog(0, ("Error %d deleting %s\n", code,
5869 (((*targetptr)->disk.type== Directory)?"directory":"file")));
5870 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
5872 VTakeOffline(volptr);
5873 if (!errorCode) errorCode = code;
5883 * This routine updates the parent directory's status block after the
5884 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
5885 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
5888 #if FS_STATS_DETAILED
5889 Update_ParentVnodeStatus(parentptr, volptr, dir, author, linkcount, a_inSameNetwork)
5891 Update_ParentVnodeStatus(parentptr, volptr, dir, author, linkcount)
5892 #endif /* FS_STATS_DETAILED */
5898 #if FS_STATS_DETAILED
5899 char a_inSameNetwork; /*Client in the same net as File Server?*/
5900 #endif /* FS_STATS_DETAILED */
5903 int newlength; /* Holds new directory length */
5905 #if FS_STATS_DETAILED
5906 Date currDate; /*Current date*/
5907 int writeIdx; /*Write index to bump*/
5908 int timeIdx; /*Authorship time index to bump*/
5909 #endif /* FS_STATS_DETAILED */
5911 parentptr->disk.dataVersion++;
5912 newlength = Length(dir);
5914 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
5915 * (create, symlink, link, makedir) so we need to check if we have enough space
5916 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
5917 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
5919 if (nBlocks(newlength) != nBlocks(parentptr->disk.length))
5920 VAdjustDiskUsage(&errorCode, volptr,
5921 (int)(nBlocks(newlength) - nBlocks(parentptr->disk.length)),
5922 (int)(nBlocks(newlength) - nBlocks(parentptr->disk.length)));
5923 parentptr->disk.length = newlength;
5925 #if FS_STATS_DETAILED
5927 * Update directory write stats for this volume. Note that the auth
5928 * counter is located immediately after its associated ``distance''
5931 if (a_inSameNetwork)
5932 writeIdx = VOL_STATS_SAME_NET;
5934 writeIdx = VOL_STATS_DIFF_NET;
5935 V_stat_writes(volptr, writeIdx)++;
5936 if (author != AnonymousID) {
5937 V_stat_writes(volptr, writeIdx+1)++;
5941 * Update the volume's authorship information in response to this
5942 * directory operation. Get the current time, decide to which time
5943 * slot this operation belongs, and bump the appropriate slot.
5945 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
5946 timeIdx = (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 :
5947 currDate < VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 :
5948 currDate < VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 :
5949 currDate < VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 :
5950 currDate < VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
5951 VOL_STATS_TIME_IDX_5);
5952 if (parentptr->disk.author == author) {
5953 V_stat_dirSameAuthor(volptr, timeIdx)++;
5956 V_stat_dirDiffAuthor(volptr, timeIdx)++;
5958 #endif /* FS_STATS_DETAILED */
5960 parentptr->disk.author = author;
5961 parentptr->disk.linkCount = linkcount;
5962 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
5963 parentptr->disk.serverModifyTime = FT_ApproxTime();
5964 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
5969 * Update the target file's (or dir's) status block after the specified
5970 * operation is complete. Note that some other fields maybe updated by
5971 * the individual module.
5974 /* INCOMPLETE - More attention is needed here! */
5976 Update_TargetVnodeStatus(targetptr, Caller, client, InStatus, parentptr, volptr,
5980 struct client *client;
5981 AFSStoreStatus *InStatus;
5987 #if FS_STATS_DETAILED
5988 Date currDate; /*Current date*/
5989 int writeIdx; /*Write index to bump*/
5990 int timeIdx; /*Authorship time index to bump*/
5991 #endif /* FS_STATS_DETAILED */
5993 if (Caller & (TVS_CFILE|TVS_SLINK|TVS_MKDIR)) { /* initialize new file */
5994 targetptr->disk.parent = parentptr->vnodeNumber;
5995 targetptr->disk.length = length;
5996 /* targetptr->disk.group = 0; save some cycles */
5997 targetptr->disk.modeBits = 0777;
5998 targetptr->disk.owner = client->ViceId;
5999 targetptr->disk.dataVersion = 0 ; /* consistent with the client */
6000 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
6001 /* the inode was created in Alloc_NewVnode() */
6004 #if FS_STATS_DETAILED
6006 * Update file write stats for this volume. Note that the auth
6007 * counter is located immediately after its associated ``distance''
6010 if (client->InSameNetwork)
6011 writeIdx = VOL_STATS_SAME_NET;
6013 writeIdx = VOL_STATS_DIFF_NET;
6014 V_stat_writes(volptr, writeIdx)++;
6015 if (client->ViceId != AnonymousID) {
6016 V_stat_writes(volptr, writeIdx+1)++;
6020 * We only count operations that DON'T involve creating new objects
6021 * (files, symlinks, directories) or simply setting status as
6022 * authorship-change operations.
6024 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
6026 * Update the volume's authorship information in response to this
6027 * file operation. Get the current time, decide to which time
6028 * slot this operation belongs, and bump the appropriate slot.
6030 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
6031 timeIdx = (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 :
6032 currDate < VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 :
6033 currDate < VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 :
6034 currDate < VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 :
6035 currDate < VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
6036 VOL_STATS_TIME_IDX_5);
6037 if (targetptr->disk.author == client->ViceId) {
6038 V_stat_fileSameAuthor(volptr, timeIdx)++;
6040 V_stat_fileDiffAuthor(volptr, timeIdx)++;
6043 #endif /* FS_STATS_DETAILED */
6045 if (!(Caller & TVS_SSTATUS))
6046 targetptr->disk.author = client->ViceId;
6047 if (Caller & TVS_SDATA) {
6048 targetptr->disk.dataVersion++;
6049 if (VanillaUser(client))
6050 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
6052 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
6053 /* store status, must explicitly request to change the date */
6054 if (InStatus->Mask & AFS_SETMODTIME)
6055 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
6057 else {/* other: date always changes, but perhaps to what is specified by caller */
6058 targetptr->disk.unixModifyTime = (InStatus->Mask & AFS_SETMODTIME ? InStatus->ClientModTime : FT_ApproxTime());
6060 if (InStatus->Mask & AFS_SETOWNER) {
6061 /* admin is allowed to do chmod, chown as well as chown, chmod. */
6062 if (VanillaUser(client))
6063 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
6064 targetptr->disk.owner = InStatus->Owner;
6065 if (VolumeRootVnode (targetptr)) {
6066 Error errorCode = 0; /* what should be done with this? */
6068 V_owner(targetptr->volumePtr) = InStatus->Owner;
6069 VUpdateVolume(&errorCode, targetptr->volumePtr);
6072 if (InStatus->Mask & AFS_SETMODE) {
6073 int modebits = InStatus->UnixModeBits;
6074 #define CREATE_SGUID_ADMIN_ONLY 1
6075 #ifdef CREATE_SGUID_ADMIN_ONLY
6076 if (VanillaUser(client))
6077 modebits = modebits & 0777;
6079 if (VanillaUser(client)) {
6080 targetptr->disk.modeBits = modebits;
6083 targetptr->disk.modeBits = modebits;
6085 case TVS_SDATA: osi_audit( PrivSetID, 0, AUD_INT, client->ViceId,
6086 AUD_INT, CHK_STOREDATA, AUD_END); break;
6088 case TVS_SSTATUS: osi_audit( PrivSetID, 0, AUD_INT, client->ViceId,
6089 AUD_INT, CHK_STORESTATUS, AUD_END); break;
6094 targetptr->disk.serverModifyTime = FT_ApproxTime();
6095 if (InStatus->Mask & AFS_SETGROUP)
6096 targetptr->disk.group = InStatus->Group;
6097 /* vnode changed : to be written back by VPutVnode */
6098 targetptr->changed_newTime = 1;
6100 } /*Update_TargetVnodeStatus*/
6104 * Fills the CallBack structure with the expiration time and type of callback
6105 * structure. Warning: this function is currently incomplete.
6107 SetCallBackStruct(CallBackTime, CallBack)
6108 afs_uint32 CallBackTime;
6109 struct AFSCallBack *CallBack;
6112 /* CallBackTime could not be 0 */
6113 if (CallBackTime == 0) {
6114 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
6115 CallBack->ExpirationTime = 0;
6117 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
6118 CallBack->CallBackVersion = CALLBACK_VERSION;
6119 CallBack->CallBackType = CB_SHARED; /* The default for now */
6121 } /*SetCallBackStruct*/
6125 * Returns the volume and vnode pointers associated with file Fid; the lock
6126 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
6127 * are incremented and they must be eventualy released.
6129 CheckVnode(fid, volptr, vptr, lock)
6138 static struct timeval restartedat = {0,0};
6140 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
6142 if ((*volptr) == 0) {
6147 *volptr = VGetVolume(&errorCode, (afs_int32)fid->Volume);
6152 if ((errorCode == VOFFLINE) && (VInit < 2)) {
6153 /* The volume we want may not be attached yet because
6154 * the volume initialization is not yet complete.
6155 * We can do several things:
6156 * 1. return -1, which will cause users to see
6157 * "connection timed out". This is more or
6158 * less the same as always, except that the servers
6159 * may appear to bounce up and down while they
6160 * are actually restarting.
6161 * 2. return VBUSY which will cause clients to
6162 * sleep and retry for 6.5 - 15 minutes, depending
6163 * on what version of the CM they are running. If
6164 * the file server takes longer than that interval
6165 * to attach the desired volume, then the application
6166 * will see an ENODEV or EIO. This approach has
6167 * the advantage that volumes which have been attached
6168 * are immediately available, it keeps the server's
6169 * immediate backlog low, and the call is interruptible
6170 * by the user. Users see "waiting for busy volume."
6171 * 3. sleep here and retry. Some people like this approach
6172 * because there is no danger of seeing errors. However,
6173 * this approach only works with a bounded number of
6174 * clients, since the pending queues will grow without
6175 * stopping. It might be better to find a way to take
6176 * this call and stick it back on a queue in order to
6177 * recycle this thread for a different request.
6178 * 4. Return a new error code, which new cache managers will
6179 * know enough to interpret as "sleep and retry", without
6180 * the upper bound of 6-15 minutes that is imposed by the
6181 * VBUSY handling. Users will see "waiting for
6182 * busy volume," so they know that something is
6183 * happening. Old cache managers must be able to do
6184 * something reasonable with this, for instance, mark the
6185 * server down. Fortunately, any error code < 0
6186 * will elicit that behavior. See #1.
6187 * 5. Some combination of the above. I like doing #2 for 10
6188 * minutes, followed by #4. 3.1b and 3.2 cache managers
6189 * will be fine as long as the restart period is
6190 * not longer than 6.5 minutes, otherwise they may
6191 * return ENODEV to users. 3.3 cache managers will be
6192 * fine for 10 minutes, then will return
6193 * ETIMEDOUT. 3.4 cache managers will just wait
6194 * until the call works or fails definitively.
6195 * NB. The problem with 2,3,4,5 is that old clients won't
6196 * fail over to an alternate read-only replica while this
6197 * server is restarting. 3.4 clients will fail over right away.
6199 if (restartedat.tv_sec == 0) {
6200 /* I'm not really worried about when we restarted, I'm */
6201 /* just worried about when the first VBUSY was returned. */
6202 TM_GetTimeOfDay(&restartedat, 0);
6207 TM_GetTimeOfDay(&now, 0);
6208 if ((now.tv_sec - restartedat.tv_sec) < (11*60)) {
6212 return (VRESTARTING);
6216 /* allow read operations on busy volume */
6217 else if(errorCode==VBUSY && lock==READ_LOCK) {
6228 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
6231 if ((*vptr)->disk.uniquifier != fid->Unique) {
6232 VPutVnode(&fileCode, *vptr);
6233 assert(fileCode == 0);
6235 return(VNOVNODE); /* return the right error code, at least */
6243 * This routine returns the ACL associated with the targetptr. If the
6244 * targetptr isn't a directory, we access its parent dir and get the ACL
6245 * thru the parent; in such case the parent's vnode is returned in
6248 SetAccessList(targetptr, volume, ACL, ACLSize, parent, Fid, Lock)
6249 Vnode **targetptr; /*Target vnode pointer; returned locked*/
6250 Volume **volume; /*Volume ptr associated with targetptr*/
6251 struct acl_accessList **ACL; /*The returned ACL for the vnode*/
6252 int * ACLSize; /*Returned ACL's size*/
6253 Vnode **parent; /*If target not Dir, it's its locked parent*/
6254 AFSFid *Fid; /*Fid associated with targetptr*/
6255 int Lock; /*Lock type to be applied to targetptr*/
6258 if ((*targetptr)->disk.type == vDirectory) {
6260 *ACL = VVnodeACL(*targetptr);
6261 *ACLSize = VAclSize(*targetptr);
6267 VnodeId parentvnode;
6270 parentvnode = (*targetptr)->disk.parent;
6271 VPutVnode(&errorCode,*targetptr);
6273 if (errorCode) return(errorCode);
6274 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
6275 if (errorCode) return(errorCode);
6276 *ACL = VVnodeACL(*parent);
6277 *ACLSize = VAclSize(*parent);
6278 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
6280 if ((*targetptr)->disk.parent != parentvnode) {
6281 VPutVnode(&errorCode, *parent);
6283 if (errorCode) return(errorCode);
6293 * Common code that handles the creation of a new file (SAFS_CreateFile and
6294 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
6296 Alloc_NewVnode(parentptr, dir, volptr, targetptr, Name, OutFid, FileType, BlocksPreallocatedForVnode)
6302 struct AFSFid *OutFid;
6304 int BlocksPreallocatedForVnode;
6307 int errorCode = 0; /* Error code returned back */
6310 Inode nearInode; /* hint for inode allocation in solaris */
6312 if (errorCode = AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
6313 BlocksPreallocatedForVnode)) {
6314 ViceLog(25, ("Insufficient space to allocate %d blocks\n",
6315 BlocksPreallocatedForVnode));
6319 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
6320 if (errorCode != 0) {
6321 VAdjustDiskUsage(&temp, volptr, - BlocksPreallocatedForVnode, 0);
6324 OutFid->Volume = V_id(volptr);
6325 OutFid->Vnode = (*targetptr)->vnodeNumber;
6326 OutFid->Unique = (*targetptr)->disk.uniquifier;
6328 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
6330 /* create the inode now itself */
6331 inode = IH_CREATE(V_linkHandle(volptr), V_device(volptr),
6332 VPartitionPath(V_partition(volptr)), nearInode,
6333 V_id(volptr), (*targetptr)->vnodeNumber,
6334 (*targetptr)->disk.uniquifier, 1);
6336 /* error in creating inode */
6337 if (!VALID_INO(inode))
6339 ViceLog(0, ("Volume : %d vnode = %d Failed to create inode: errno = %d\n",
6340 (*targetptr)->volumePtr->header->diskstuff.id,
6341 (*targetptr)->vnodeNumber,
6343 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode,0);
6344 (*targetptr)->delete = 1; /* delete vnode */
6347 VN_SET_INO(*targetptr, inode);
6348 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
6350 /* copy group from parent dir */
6351 (*targetptr)->disk.group = parentptr->disk.group;
6353 if (parentptr->disk.cloned)
6355 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
6356 if ( errorCode = CopyOnWrite(parentptr, volptr)) /* disk full */
6358 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
6359 /* delete the vnode previously allocated */
6360 (*targetptr)->delete = 1;
6361 VAdjustDiskUsage(&temp, volptr,
6362 -BlocksPreallocatedForVnode, 0);
6363 IH_REALLYCLOSE((*targetptr)->handle);
6364 if ( IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)) )
6365 ViceLog(0,("Alloc_NewVnode: partition %s idec %s failed\n",
6366 volptr->partition->name,
6367 PrintInode(NULL, inode)));
6368 IH_RELEASE((*targetptr)->handle);
6374 /* add the name to the directory */
6375 SetDirHandle(dir, parentptr);
6376 if (errorCode = Create(dir,(char *)Name, OutFid)) {
6377 (*targetptr)->delete = 1;
6378 VAdjustDiskUsage(&temp, volptr, - BlocksPreallocatedForVnode, 0);
6379 IH_REALLYCLOSE((*targetptr)->handle);
6380 if ( IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
6381 ViceLog(0,("Alloc_NewVnode: partition %s idec %s failed\n",
6382 volptr->partition->name,
6383 PrintInode(NULL, inode)));
6384 IH_RELEASE((*targetptr)->handle);
6390 } /*Alloc_NewVnode*/
6394 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
6397 HandleLocking(targetptr, rights, LockingType)
6400 ViceLockType LockingType;
6403 int Time; /* Used for time */
6404 int writeVnode = targetptr->changed_oldTime; /* save original status */
6406 /* Does the caller has Lock priviledges; root extends locks, however */
6407 if (LockingType != LockExtend && !(rights & PRSFS_LOCK))
6409 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
6410 Time = FT_ApproxTime();
6411 switch (LockingType) {
6414 if (Time > targetptr->disk.lock.lockTime)
6415 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount = 0;
6416 Time += AFS_LOCKWAIT;
6417 if (LockingType == LockRead) {
6418 if (targetptr->disk.lock.lockCount >= 0) {
6419 ++(targetptr->disk.lock.lockCount);
6420 targetptr->disk.lock.lockTime = Time;
6421 } else return(EAGAIN);
6423 if (targetptr->disk.lock.lockCount == 0) {
6424 targetptr->disk.lock.lockCount = -1;
6425 targetptr->disk.lock.lockTime = Time;
6426 } else return(EAGAIN);
6430 Time += AFS_LOCKWAIT;
6431 if (targetptr->disk.lock.lockCount != 0)
6432 targetptr->disk.lock.lockTime = Time;
6433 else return(EINVAL);
6436 if ((--targetptr->disk.lock.lockCount) <= 0)
6437 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime = 0;
6440 targetptr->changed_oldTime = writeVnode; /* restore old status */
6441 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
6449 * This routine returns the status info associated with the targetptr vnode
6450 * in the AFSFetchStatus structure. Some of the newer fields, such as
6451 * SegSize and Group are not yet implemented
6453 void GetStatus(targetptr, status, rights, anyrights, parentptr)
6454 Vnode *targetptr; /*vnode of desired Fid*/
6455 AFSFetchStatus *status; /*the status info is returned here*/
6456 afs_int32 rights; /*Sets the 'CallerAccess' status field*/
6457 afs_int32 anyrights; /*Sets the 'AnonymousAccess' status field*/
6458 Vnode *parentptr; /*target's parent vnode*/
6461 /* initialize return status from a vnode */
6462 status->InterfaceVersion = 1;
6463 status->SyncCounter = status->dataVersionHigh = status->lockCount =
6464 status->errorCode = 0;
6465 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
6466 if (targetptr->disk.type == vFile)
6467 status->FileType = File;
6468 else if (targetptr->disk.type == vDirectory)
6469 status->FileType = Directory;
6470 else if (targetptr->disk.type == vSymlink)
6471 status->FileType = SymbolicLink;
6473 status->FileType = Invalid; /*invalid type field */
6474 status->LinkCount = targetptr->disk.linkCount;
6475 status->Length_hi = 0;
6476 status->Length = targetptr->disk.length;
6477 status->DataVersion = targetptr->disk.dataVersion;
6478 status->Author = targetptr->disk.author;
6479 status->Owner = targetptr->disk.owner;
6480 status->CallerAccess = rights;
6481 status->AnonymousAccess = anyrights;
6482 status->UnixModeBits = targetptr->disk.modeBits;
6483 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
6484 status->ParentVnode = (status->FileType == Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
6485 status->ParentUnique = (status->FileType == Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
6486 status->ServerModTime = targetptr->disk.serverModifyTime;
6487 status->Group = targetptr->disk.group;
6488 status->lockCount = targetptr->disk.lock.lockCount;
6489 status->errorCode = 0;
6495 * Compare the directory's ACL with the user's access rights in the client
6496 * connection and return the user's and everybody else's access permissions
6497 * in rights and anyrights, respectively
6499 GetRights (client, ACL, rights, anyrights)
6500 struct client *client; /* Client struct */
6501 struct acl_accessList *ACL; /* Access List for the current directory */
6502 afs_int32 *rights; /* Returns access rights for caller */
6503 afs_int32 *anyrights; /* Returns access rights for 'anyuser' */
6506 extern prlist SystemAnyUserCPS;
6507 afs_int32 hrights = 0;
6510 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
6512 ViceLog(0,("CheckRights failed\n"));
6516 acl_CheckRights(ACL, &client->CPS, rights);
6518 /* wait if somebody else is already doing the getCPS call */
6520 while ( client->host->hostFlags & HPCS_INPROGRESS )
6522 client->host->hostFlags |= HPCS_WAITING; /* I am waiting */
6523 #ifdef AFS_PTHREAD_ENV
6524 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
6525 #else /* AFS_PTHREAD_ENV */
6526 if ((code=LWP_WaitProcess( &(client->host->hostFlags))) !=LWP_SUCCESS)
6527 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
6528 #endif /* AFS_PTHREAD_ENV */
6531 if (client->host->hcps.prlist_len && !client->host->hcps.prlist_val) {
6532 ViceLog(0,("CheckRights: len=%d, for host=0x%x\n", client->host->hcps.prlist_len, client->host->host));
6534 acl_CheckRights(ACL, &client->host->hcps, &hrights);
6536 /* Allow system:admin the rights given with the -implicit option */
6537 if (acl_IsAMember(SystemId, &client->CPS))
6538 *rights |= implicitAdminRights;
6540 *anyrights |= hrights;
6547 /* Checks if caller has the proper AFS and Unix (WRITE) access permission to the target directory; Prfs_Mode refers to the AFS Mode operation while rights contains the caller's access permissions to the directory. */
6549 CheckWriteMode(targetptr, rights, Prfs_Mode)
6554 if (!(rights & Prfs_Mode))
6556 if ((targetptr->disk.type != vDirectory) && (!(targetptr->disk.modeBits & OWNERWRITE)))
6562 /* In our current implementation, each successive data store (new file
6563 * data version) creates a new inode. This function creates the new
6564 * inode, copies the old inode's contents to the new one, remove the old
6565 * inode (i.e. decrement inode count -- if it's currently used the delete
6566 * will be delayed), and modify some fields (i.e. vnode's
6567 * disk.inodeNumber and cloned)
6569 #define COPYBUFFSIZE 8192
6570 int CopyOnWrite(targetptr, volptr)
6575 Inode ino, nearInode;
6578 register int size, length;
6581 int rc; /* return code */
6582 IHandle_t *newH; /* Use until finished copying, then cp to vnode.*/
6583 FdHandle_t *targFdP; /* Source Inode file handle */
6584 FdHandle_t *newFdP; /* Dest Inode file handle */
6586 if (targetptr->disk.type == vDirectory) DFlush(); /* just in case? */
6588 size = targetptr->disk.length;
6589 buff = (char *)malloc(COPYBUFFSIZE);
6594 ino = VN_GET_INO(targetptr);
6595 assert(VALID_INO(ino));
6596 targFdP = IH_OPEN(targetptr->handle);
6597 if (targFdP == NULL) {
6599 ViceLog(0, ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n", targetptr->vnodeNumber, V_id(volptr), rc));
6601 VTakeOffline (volptr);
6605 nearInode = VN_GET_INO(targetptr);
6606 ino = IH_CREATE(V_linkHandle(volptr), V_device(volptr),
6607 VPartitionPath(V_partition(volptr)),nearInode, V_id(volptr),
6608 targetptr->vnodeNumber, targetptr->disk.uniquifier,
6609 (int)targetptr->disk.dataVersion);
6610 if (!VALID_INO(ino))
6612 ViceLog(0,("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n", volptr->partition->name, V_id(volptr), errno));
6617 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
6618 newFdP = IH_OPEN(newH);
6619 assert(newFdP != NULL);
6622 if (size > COPYBUFFSIZE) { /* more than a buffer */
6623 length = COPYBUFFSIZE;
6624 size -= COPYBUFFSIZE;
6629 rdlen = FDH_READ(targFdP, buff, length);
6630 if (rdlen == length)
6631 wrlen = FDH_WRITE(newFdP, buff, length);
6634 /* Callers of this function are not prepared to recover
6635 * from error that put the filesystem in an inconsistent
6636 * state. Make sure that we force the volume off-line if
6637 * we some error other than ENOSPC - 4.29.99)
6639 * In case we are unable to write the required bytes, and the
6640 * error code indicates that the disk is full, we roll-back to
6641 * the initial state.
6643 if((rdlen != length) || (wrlen != length))
6644 if ( (wrlen < 0) && (errno == ENOSPC) ) /* disk full */
6646 ViceLog(0,("CopyOnWrite failed: Partition %s containing volume %u is full\n",
6647 volptr->partition->name, V_id(volptr)));
6648 /* remove destination inode which was partially copied till now*/
6649 FDH_REALLYCLOSE(newFdP);
6651 FDH_REALLYCLOSE(targFdP);
6652 rc = IH_DEC(V_linkHandle(volptr), ino,
6653 V_parentId(volptr));
6655 ViceLog(0,("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
6657 volptr->partition->name));
6658 VTakeOffline (volptr);
6664 ViceLog(0,("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
6665 V_id(volptr), volptr->partition->name, length,
6666 rdlen, wrlen, errno));
6667 /* Decrement this inode so salvager doesn't find it. */
6668 FDH_REALLYCLOSE(newFdP);
6670 FDH_REALLYCLOSE(targFdP);
6671 rc = IH_DEC(V_linkHandle(volptr), ino,
6672 V_parentId(volptr));
6674 VTakeOffline (volptr);
6677 #ifndef AFS_PTHREAD_ENV
6679 #endif /* !AFS_PTHREAD_ENV */
6681 FDH_REALLYCLOSE(targFdP);
6682 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
6683 V_parentId(volptr)) ;
6685 IH_RELEASE(targetptr->handle);
6687 rc = FDH_SYNC(newFdP);
6690 targetptr->handle = newH;
6691 VN_SET_INO(targetptr, ino);
6692 targetptr->disk.cloned = 0;
6693 /* Internal change to vnode, no user level change to volume - def 5445 */
6694 targetptr->changed_oldTime = 1;
6696 return 0; /* success */
6701 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
6702 * a System:Administrator)
6705 struct client *client;
6708 if (acl_IsAMember(SystemId, &client->CPS))
6709 return(0); /* not a system administrator, then you're "vanilla" */
6716 * Adjusts (Subtract) "length" number of blocks from the volume's disk
6717 * allocation; if some error occured (exceeded volume quota or partition
6718 * was full, or whatever), it frees the space back and returns the code.
6719 * We usually pre-adjust the volume space to make sure that there's
6720 * enough space before consuming some.
6722 AdjustDiskUsage(volptr, length, checkLength)
6724 afs_int32 checkLength;
6731 VAdjustDiskUsage(&rc, volptr, length, checkLength);
6733 VAdjustDiskUsage(&nc, volptr, -length, 0);
6734 if (rc == VOVERQUOTA) {
6735 ViceLog(2,("Volume %u (%s) is full\n",
6736 V_id(volptr), V_name(volptr)));
6739 if (rc == VDISKFULL) {
6740 ViceLog(0,("Partition %s that contains volume %u is full\n",
6741 volptr->partition->name, V_id(volptr)));
6744 ViceLog(0,("Got error return %d from VAdjustDiskUsage\n",rc));
6749 } /*AdjustDiskUsage*/
6753 * If some flags (i.e. min or max quota) are set, the volume's in disk
6754 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
6755 * update, if applicable.
6757 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd)
6759 AFSStoreVolumeStatus* StoreVolStatus;
6765 Error errorCode = 0;
6767 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
6768 V_minquota(volptr) = StoreVolStatus->MinQuota;
6769 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
6770 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
6771 if (strlen(OfflineMsg) > 0) {
6772 strcpy(V_offlineMessage(volptr), OfflineMsg);
6774 if (strlen(Name) > 0) {
6775 strcpy(V_name(volptr), Name);
6777 #if TRANSARC_VOL_STATS
6779 * We don't overwrite the motd field, since it's now being used
6783 if (strlen(Motd) > 0) {
6784 strcpy(V_motd(volptr), Motd);
6786 #endif /* FS_STATS_DETAILED */
6787 VUpdateVolume(&errorCode, volptr);
6790 } /*RXUpdate_VolumeStatus*/
6794 Update_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd)
6796 VolumeStatus *StoreVolStatus;
6798 struct BBS *OfflineMsg;
6802 Error errorCode = 0;
6804 if (StoreVolStatus->MinQuota > -1)
6805 V_minquota(volptr) = StoreVolStatus->MinQuota;
6806 if (StoreVolStatus->MaxQuota > -1)
6807 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
6808 if (OfflineMsg->SeqLen > 1)
6809 strcpy(V_offlineMessage(volptr), OfflineMsg->SeqBody);
6810 if (Name->SeqLen > 1)
6811 strcpy(V_name(volptr), Name->SeqBody);
6812 #if TRANSARC_VOL_STATS
6814 * We don't overwrite the motd field, since it's now being used
6818 if (Motd->SeqLen > 1)
6819 strcpy(V_motd(volptr), Motd->SeqBody);
6820 #endif /* FS_STATS_DETAILED */
6821 VUpdateVolume(&errorCode, volptr);
6824 } /*Update_VolumeStatus*/
6828 * Get internal volume-related statistics from the Volume disk label
6829 * structure and put it into the VolumeStatus structure, status; it's
6830 * used by both SAFS_GetVolumeStatus and SAFS_SetVolumeStatus to return
6831 * the volume status to the caller.
6833 GetVolumeStatus(status, name, offMsg, motd, volptr)
6834 VolumeStatus * status;
6836 struct BBS * offMsg;
6841 status->Vid = V_id(volptr);
6842 status->ParentId = V_parentId(volptr);
6843 status->Online = V_inUse(volptr);
6844 status->InService = V_inService(volptr);
6845 status->Blessed = V_blessed(volptr);
6846 status->NeedsSalvage = V_needsSalvaged(volptr);
6847 if (VolumeWriteable(volptr))
6848 status->Type = ReadWrite;
6850 status->Type = ReadOnly;
6851 status->MinQuota = V_minquota(volptr);
6852 status->MaxQuota = V_maxquota(volptr);
6853 status->BlocksInUse = V_diskused(volptr);
6854 status->PartBlocksAvail = volptr->partition->free;
6855 status->PartMaxBlocks = volptr->partition->totalUsable;
6856 strncpy(name->SeqBody, V_name(volptr), (int)name->MaxSeqLen);
6857 name->SeqLen = strlen(V_name(volptr)) + 1;
6858 if (name->SeqLen > name->MaxSeqLen) name->SeqLen = name -> MaxSeqLen;
6859 strncpy(offMsg->SeqBody, V_offlineMessage(volptr), (int)name->MaxSeqLen);
6860 offMsg->SeqLen = strlen(V_offlineMessage(volptr)) + 1;
6861 if (offMsg->SeqLen > offMsg->MaxSeqLen)
6862 offMsg->SeqLen = offMsg -> MaxSeqLen;
6864 /*Don't do anything with the motd field*/
6865 strncpy(motd->SeqBody, nullString, (int)offMsg->MaxSeqLen);
6866 motd->SeqLen = strlen(nullString) + 1;
6868 if (motd->SeqLen > motd->MaxSeqLen)
6869 motd->SeqLen = motd -> MaxSeqLen;
6871 } /*GetVolumeStatus*/
6874 RXGetVolumeStatus(status, name, offMsg, motd, volptr)
6875 AFSFetchVolumeStatus *status;
6884 status->Vid = V_id(volptr);
6885 status->ParentId = V_parentId(volptr);
6886 status->Online = V_inUse(volptr);
6887 status->InService = V_inService(volptr);
6888 status->Blessed = V_blessed(volptr);
6889 status->NeedsSalvage = V_needsSalvaged(volptr);
6890 if (VolumeWriteable(volptr))
6891 status->Type = ReadWrite;
6893 status->Type = ReadOnly;
6894 status->MinQuota = V_minquota(volptr);
6895 status->MaxQuota = V_maxquota(volptr);
6896 status->BlocksInUse = V_diskused(volptr);
6897 status->PartBlocksAvail = volptr->partition->free;
6898 status->PartMaxBlocks = volptr->partition->totalUsable;
6900 /* now allocate and copy these things; they're freed by the RXGEN stub */
6901 temp = strlen(V_name(volptr)) + 1;
6902 *name = malloc(temp);
6903 strcpy(*name, V_name(volptr));
6904 temp = strlen(V_offlineMessage(volptr)) + 1;
6905 *offMsg = malloc(temp);
6906 strcpy(*offMsg, V_offlineMessage(volptr));
6907 #if TRANSARC_VOL_STATS
6909 strcpy(*motd, nullString);
6911 temp = strlen(V_motd(volptr)) + 1;
6912 *motd = malloc(temp);
6913 strcpy(*motd, V_motd(volptr));
6914 #endif /* FS_STATS_DETAILED */
6916 } /*RXGetVolumeStatus*/
6919 /* Set AFS Data Fetch/Store related statistics. */
6921 void SetAFSStats(stats)
6922 struct AFSStatistics *stats;
6925 extern afs_int32 StartTime, CurrentConnections;
6929 stats->CurrentMsgNumber = 0;
6930 stats->OldestMsgNumber = 0;
6931 stats->StartTime = StartTime;
6932 stats->CurrentConnections = CurrentConnections;
6933 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
6934 stats->TotalFetchs = AFSCallStats.FetchData+AFSCallStats.FetchACL+AFSCallStats.FetchStatus;
6935 stats->FetchDatas = AFSCallStats.FetchData;
6936 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
6937 seconds = AFSCallStats.AccumFetchTime/1000;
6938 if (seconds <= 0) seconds = 1;
6939 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes/seconds;
6940 stats->TotalStores = AFSCallStats.StoreData+AFSCallStats.StoreACL+AFSCallStats.StoreStatus;
6941 stats->StoreDatas = AFSCallStats.StoreData;
6942 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
6943 seconds = AFSCallStats.AccumStoreTime/1000;
6944 if (seconds <= 0) seconds = 1;
6945 stats->StoreDataRate = AFSCallStats.TotalStoredBytes/seconds;
6947 stats->ProcessSize = -1; /* TODO: */
6949 stats->ProcessSize = (afs_int32)((long) sbrk(0) >> 10);
6952 h_GetWorkStats((int *)&(stats->WorkStations),(int *)&(stats->ActiveWorkStations),
6953 (int *)0, (afs_int32)(FT_ApproxTime())-(15*60));
6958 /* Get disk related information from all AFS partitions. */
6960 void SetVolumeStats(stats)
6961 struct AFSStatistics *stats;
6964 struct DiskPartition * part;
6967 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS; part = part->next) {
6968 stats->Disks[i].TotalBlocks = part->totalUsable;
6969 stats->Disks[i].BlocksAvailable = part->free;
6970 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
6971 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
6974 while (i < AFS_MSTATDISKS) {
6975 stats->Disks[i].TotalBlocks = -1;
6978 } /*SetVolumeStats*/
6982 struct nlist RawStats[] = {
6998 #else /* AFS_SUN_ENV */
7007 /* Get some kernel specific related statistics */
7009 void SetSystemStats(stats)
7010 struct AFSStatistics * stats;
7013 /* Fix this sometime soon.. */
7015 static int kmem = 0;
7016 static struct mapent *swapMap = 0;
7017 static int swapMapAddr = 0;
7018 static int swapMapSize = 0;
7019 static int numSwapBlks = 0;
7024 afs_int32 busy[CPUSTATES];
7025 afs_int32 xfer[DK_NDRIVE];
7026 struct timeval bootTime;
7028 struct timeval time;
7030 /* this works on all system types */
7031 TM_GetTimeOfDay(&time, 0);
7032 stats->CurrentTime = time.tv_sec;
7035 stats->UserCPU =stats->SystemCPU =stats->NiceCPU =stats->IdleCPU =stats->BootTime =0;
7036 stats->TotalIO =stats->ActiveVM =stats->TotalVM = 0;
7037 for (i=0; i < AFS_MSTATSPARES; i++) stats->Spares[i] = 0;
7039 if (kmem == -1) return;
7041 nlist("/vmunix", RawStats);
7042 if (RawStats[0].n_type == 0) {
7043 ViceLog(0, ("Could not get a namelist from VMUNIX\n"));
7047 kmem = open("/dev/kmem",O_RDONLY,0);
7049 ViceLog(0, ("Could not open /dev/kmem\n"));
7054 lseek(kmem, (afs_int32) RawStats[CPTIME].n_value,0);
7055 read(kmem, (char *)busy, sizeof(busy));
7056 stats->SystemCPU = busy[CP_SYS];
7057 stats->UserCPU = busy[CP_USER];
7058 stats->NiceCPU = busy[CP_NICE];
7059 stats->IdleCPU = busy[CP_IDLE];
7060 lseek(kmem, (afs_int32) RawStats[BOOT].n_value,0);
7061 read(kmem, (char *)&bootTime, sizeof(bootTime));
7062 stats->BootTime = bootTime.tv_sec;
7063 lseek(kmem, (afs_int32) RawStats[DISK].n_value,0);
7064 read(kmem, (char *)xfer, sizeof(xfer));
7066 for(i = 0; i < DK_NDRIVE; i++) {
7067 stats->TotalIO += xfer[i];
7071 #include <vm/anon.h>
7073 #define ctok(x) ((ctob(x)) >> 10)
7075 lseek(kmem, (afs_int32)RawStats[SANON].n_value,0);
7076 read(kmem, (char *)&ai, sizeof (struct anoninfo));
7077 stats->TotalVM = ctok(ai.ani_max - ai.ani_resv); /* available */
7078 stats->ActiveVM = ctok(ai.ani_resv); /* used */
7082 lseek(kmem, (afs_int32)RawStats[SWAPMAP].n_value,0);
7083 read(kmem, (char *)&swapMapAddr, sizeof(swapMapAddr));
7084 swapMapAddr += sizeof(struct map);
7085 lseek(kmem, (afs_int32)RawStats[NSWAPMAP].n_value,0);
7086 read(kmem, (char *)&numSwapEntries, sizeof(numSwapEntries));
7087 swapMapSize = (--numSwapEntries)*sizeof(struct mapent);
7088 lseek(kmem, (afs_int32)RawStats[NSWAPBLKS].n_value,0);
7089 read(kmem, (char *)&numSwapBlks, sizeof(numSwapBlks));
7090 lseek(kmem, (afs_int32)RawStats[DMMAX].n_value,0);
7091 read(kmem, (char *)&dmmax, sizeof(dmmax));
7092 numSwapBlks -= dmmax/2;
7093 swapMap = (struct mapent *)malloc(swapMapSize);
7095 sp = (struct mapent *)swapMap;
7096 lseek(kmem, (afs_int32)swapMapAddr, 0);
7097 read(kmem, (char *)sp, swapMapSize);
7098 for(stats->TotalVM = stats->ActiveVM = numSwapBlks; sp->m_size; sp++) {
7099 stats->ActiveVM -= sp->m_size;
7101 #endif /* AFS_SUN_ENV */
7104 } /*SetSystemStats*/
7107 /* Validate target file */
7111 register char *aname;
7114 register afs_int32 i, tc;
7117 /* watch for @sys on the right */
7118 if (strcmp(aname+i-4, "@sys") == 0) return 0;
7120 while (tc = *aname++) {
7121 if (tc == '/') return 0; /* very bad character to encounter */
7123 return 1; /* file name is ok */
7128 /* Debugging tool to print Volume Statu's contents */
7130 PrintVolumeStatus(status)
7131 VolumeStatus *status;
7134 ViceLog(5,("Volume header contains:\n"));
7135 ViceLog(5,("Vid = %u, Parent = %u, Online = %d, InService = %d, Blessed = %d, NeedsSalvage = %d\n",
7136 status->Vid, status->ParentId, status->Online, status->InService,
7137 status->Blessed, status->NeedsSalvage));
7138 ViceLog(5,("MinQuota = %d, MaxQuota = %d\n", status->MinQuota, status->MaxQuota));
7139 ViceLog(5,("Type = %d, BlocksInUse = %d, PartBlocksAvail = %d, PartMaxBlocks = %d\n",
7140 status->Type, status->BlocksInUse, status->PartBlocksAvail, status->PartMaxBlocks));
7142 } /*PrintVolumeStatus*/
7146 * This variant of symlink is expressly to support the AFS/DFS translator
7147 * and is not supported by the AFS fileserver. We just return EINVAL.
7148 * The cache manager should not generate this call to an AFS cache manager.
7150 afs_int32 SRXAFS_DFSSymlink (acall, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, CallBack, Sync)
7151 struct rx_call *acall; /* Rx call */
7152 struct AFSFid *DirFid; /* Parent dir's fid */
7153 char *Name; /* File name to create */
7154 char *LinkContents; /* Contents of the new created file */
7155 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
7156 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
7157 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
7158 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
7159 struct AFSCallBack *CallBack; /* Callback on link */
7160 struct AFSVolSync *Sync;
7165 afs_int32 SRXAFS_ResidencyCmd (acall, Fid, Inputs, Outputs)
7166 struct rx_call *acall;
7168 struct ResidencyCmdInputs *Inputs;
7169 struct ResidencyCmdOutputs *Outputs;