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 */