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 * GetVolumePackage disables Rx keepalives; PutVolumePackage re-enables.
24 * If callbacks are to be broken, keepalives should be enabled in the
25 * stub while that occurs; disabled while disk I/O is in process.
29 * in Check_PermissionRights, certain privileges are afforded to the owner
30 * of the volume, or the owner of a file. Are these considered "use of
34 #include <afsconfig.h>
35 #include <afs/param.h>
41 #undef SHARED /* XXX */
48 #ifdef HAVE_NETINET_IF_ETHER_H
49 #include <netinet/if_ether.h>
52 #if !defined(AFS_SGI_ENV) && defined(HAVE_SYS_MAP_H)
56 #ifdef HAVE_SYS_STATFS_H
57 #include <sys/statfs.h>
60 #ifdef HAVE_SYS_LOCKF_H
61 #include <sys/lockf.h>
69 /* included early because of name conflict on IOPEN */
70 #include <sys/inode.h>
74 #endif /* AFS_HPUX_ENV */
80 #include <afs/afsint.h>
81 #include <afs/vldbint.h>
82 #include <afs/errors.h>
83 #include <afs/ihandle.h>
84 #include <afs/vnode.h>
85 #include <afs/volume.h>
86 #include <afs/ptclient.h>
87 #include <afs/ptuser.h>
88 #include <afs/prs_fs.h>
91 #include <rx/rx_globals.h>
93 #include <afs/cellconfig.h>
96 #include <afs/partition.h>
97 #include "viced_prototypes.h"
100 #include "callback.h"
101 #include <afs/unified_afs.h>
102 #include <afs/audit.h>
103 #include <afs/afsutil.h>
106 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
107 extern void FidZap(DirHandle * file);
108 extern void FidZero(DirHandle * file);
110 pthread_mutex_t fileproc_glock_mutex;
112 /* Useful local defines used by this module */
115 #define MustNOTBeDIR 1
119 #define TVS_SSTATUS 2
122 #define TVS_MKDIR 0x10
124 #define CHK_FETCH 0x10
125 #define CHK_FETCHDATA 0x10
126 #define CHK_FETCHACL 0x11
127 #define CHK_FETCHSTATUS 0x12
128 #define CHK_STOREDATA 0x00
129 #define CHK_STOREACL 0x01
130 #define CHK_STORESTATUS 0x02
132 #define OWNERREAD 0400
133 #define OWNERWRITE 0200
134 #define OWNEREXEC 0100
135 #ifdef USE_GROUP_PERMS
136 #define GROUPREAD 0040
137 #define GROUPWRITE 0020
138 #define GROUPREXEC 0010
141 /* The following errors were not defined in NT. They are given unique
142 * names here to avoid any potential collision.
144 #define FSERR_ELOOP 90
145 #define FSERR_EOPNOTSUPP 122
146 #define FSERR_ECONNREFUSED 130
148 #define NOTACTIVECALL 0
151 #define CREATE_SGUID_ADMIN_ONLY 1
153 extern struct afsconf_dir *confDir;
154 extern afs_int32 dataVersionHigh;
157 static struct AFSCallStatistics AFSCallStats;
158 struct fs_stats_FullPerfStats afs_FullPerfStats;
159 extern int AnonymousID;
160 static const char nullString[] = "";
163 afs_int32 NothingYet;
166 struct afs_FSStats afs_fsstats;
171 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
173 extern afs_int32 implicitAdminRights;
174 extern afs_int32 readonlyServer;
175 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
176 extern afs_fsize_t CopyOnWrite_maxsize;
179 * Externals used by the xstat code.
181 extern VolPkgStats VStats;
182 extern int CEs, CEBlocks;
184 extern int HTs, HTBlocks;
186 static afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
187 struct rx_call *Call, afs_sfsize_t Pos,
188 afs_sfsize_t Len, afs_int32 Int64Mode,
189 afs_sfsize_t * a_bytesToFetchP,
190 afs_sfsize_t * a_bytesFetchedP);
192 static afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
193 struct AFSFid *Fid, struct client *client,
194 struct rx_call *Call, afs_fsize_t Pos,
195 afs_fsize_t Length, afs_fsize_t FileLength,
197 afs_sfsize_t * a_bytesToStoreP,
198 afs_sfsize_t * a_bytesStoredP);
200 #ifdef AFS_SGI_XFS_IOPS_ENV
201 #include <afs/xfsattrs.h>
203 GetLinkCount(Volume * avp, struct stat *astat)
205 if (!strcmp("xfs", astat->st_fstype)) {
206 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
208 return astat->st_nlink;
211 #define GetLinkCount(V, S) (S)->st_nlink
215 SpareComp(Volume * avolp)
221 temp = V_maxquota(avolp);
223 /* no matter; doesn't check in this case */
227 temp = (temp * PctSpare) / 100;
238 * Set the volume synchronization parameter for this volume. If it changes,
239 * the Cache Manager knows that the volume must be purged from the stat cache.
242 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
245 /* date volume instance was created */
248 async->spare1 = avol->header->diskstuff.creationDate;
261 * Verify that the on-disk size for a vnode matches the length in the vnode
264 * @param[in] vp Volume pointer
265 * @param[in] vnp Vnode pointer
266 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
267 * and CheckLength itself will determine the on-disk size.
269 * @return operation status
270 * @retval 0 lengths match
271 * @retval nonzero Error; either the lengths do not match or there was an
272 * error determining the on-disk size. The volume should be
273 * taken offline and salvaged.
276 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
279 VN_GET_LEN(vlen, vnp);
284 fdP = IH_OPEN(vnp->handle);
286 ViceLog(0, ("CheckLength: cannot open inode for fid %lu.%lu.%lu\n",
287 afs_printable_uint32_lu(vp->hashid),
288 afs_printable_uint32_lu(Vn_id(vnp)),
289 afs_printable_uint32_lu(vnp->disk.uniquifier)));
292 alen = FDH_SIZE(fdP);
295 afs_int64 alen64 = alen;
296 ViceLog(0, ("CheckLength: cannot get size for inode for fid "
297 "%lu.%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
298 afs_printable_uint32_lu(vp->hashid),
299 afs_printable_uint32_lu(Vn_id(vnp)),
300 afs_printable_uint32_lu(vnp->disk.uniquifier),
307 afs_int64 alen64 = alen, vlen64 = vlen;
308 ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index "
309 "%lld inode %lld ); volume must be salvaged\n",
310 afs_printable_uint32_lu(vp->hashid),
311 afs_printable_uint32_lu(Vn_id(vnp)),
312 afs_printable_uint32_lu(vnp->disk.uniquifier),
320 * Note that this function always returns a held host, so
321 * that CallPostamble can block without the host's disappearing.
322 * Call returns rx connection in passed in *tconn
325 CallPreamble(struct rx_call *acall, int activecall,
326 struct rx_connection **tconn, struct host **ahostp)
329 struct client *tclient;
332 char hoststr[16], hoststr2[16];
333 struct ubik_client *uclient;
337 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
340 *tconn = rx_ConnectionOf(acall);
344 tclient = h_FindClient_r(*tconn);
346 ViceLog(0, ("CallPreamble: Couldn't get client.\n"));
350 thost = tclient->host;
351 if (tclient->prfail == 1) { /* couldn't get the CPS */
353 h_ReleaseClient_r(tclient);
355 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
359 retry_flag = 0; /* Retry once */
361 /* Take down the old connection and re-read the key file */
363 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
364 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
366 /* Is it still necessary to drop this? We hit the net, we should... */
372 code = hpr_Initialize(&uclient);
375 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
379 h_ReleaseClient_r(tclient);
382 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
386 tclient->prfail = 2; /* Means re-eval client's cps */
387 h_ReleaseClient_r(tclient);
392 tclient->LastCall = thost->LastCall = FT_ApproxTime();
393 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
394 thost->ActiveCall = thost->LastCall;
397 if (thost->hostFlags & HOSTDELETED) {
399 ("Discarded a packet for deleted host %s:%d\n",
400 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
401 code = VBUSY; /* raced, so retry */
402 } else if ((thost->hostFlags & VENUSDOWN)
403 || (thost->hostFlags & HFE_LATER)) {
404 if (BreakDelayedCallBacks_r(thost)) {
406 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
407 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
408 ntohs(rxr_PortOf(*tconn))));
409 if (MultiProbeAlternateAddress_r(thost)) {
411 ("MultiProbe failed to find new address for host %s:%d\n",
412 afs_inet_ntoa_r(thost->host, hoststr),
413 ntohs(thost->port)));
417 ("MultiProbe found new address for host %s:%d\n",
418 afs_inet_ntoa_r(thost->host, hoststr),
419 ntohs(thost->port)));
420 if (BreakDelayedCallBacks_r(thost)) {
422 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
423 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
424 ntohs(rxr_PortOf(*tconn))));
433 h_ReleaseClient_r(tclient);
443 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
447 struct client *tclient;
451 tclient = h_FindClient_r(aconn);
454 thost = tclient->host;
455 if (thost->hostFlags & HERRORTRANS)
457 h_ReleaseClient_r(tclient);
460 if (ahost != thost) {
461 /* host/client recycle */
462 char hoststr[16], hoststr2[16];
463 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
465 afs_inet_ntoa_r(ahost->host, hoststr),
468 afs_inet_ntoa_r(thost->host, hoststr2),
472 /* return the reference taken in CallPreamble */
476 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
477 afs_inet_ntoa_r(thost->host, hoststr),
482 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
483 * does not decrement refcount on client->host */
488 return (translate ? sys_error_to_et(ret) : ret);
492 * Returns the volume and vnode pointers associated with file Fid; the lock
493 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
494 * are incremented and they must be eventualy released.
497 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
498 Vnode ** vptr, int lock)
501 Error local_errorCode, errorCode = -1;
502 static struct timeval restartedat = { 0, 0 };
504 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
506 if ((*volptr) == 0) {
511 #ifdef AFS_DEMAND_ATTACH_FS
517 static const struct timespec timeout_ts = { 0, 0 };
518 static const struct timespec * const ts = &timeout_ts;
521 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
522 fid->Volume, ts, cbv);
527 if ((errorCode == VOFFLINE) && (VInit < 2)) {
528 /* The volume we want may not be attached yet because
529 * the volume initialization is not yet complete.
530 * We can do several things:
531 * 1. return -1, which will cause users to see
532 * "connection timed out". This is more or
533 * less the same as always, except that the servers
534 * may appear to bounce up and down while they
535 * are actually restarting.
536 * 2. return VBUSY which will cause clients to
537 * sleep and retry for 6.5 - 15 minutes, depending
538 * on what version of the CM they are running. If
539 * the file server takes longer than that interval
540 * to attach the desired volume, then the application
541 * will see an ENODEV or EIO. This approach has
542 * the advantage that volumes which have been attached
543 * are immediately available, it keeps the server's
544 * immediate backlog low, and the call is interruptible
545 * by the user. Users see "waiting for busy volume."
546 * 3. sleep here and retry. Some people like this approach
547 * because there is no danger of seeing errors. However,
548 * this approach only works with a bounded number of
549 * clients, since the pending queues will grow without
550 * stopping. It might be better to find a way to take
551 * this call and stick it back on a queue in order to
552 * recycle this thread for a different request.
553 * 4. Return a new error code, which new cache managers will
554 * know enough to interpret as "sleep and retry", without
555 * the upper bound of 6-15 minutes that is imposed by the
556 * VBUSY handling. Users will see "waiting for
557 * busy volume," so they know that something is
558 * happening. Old cache managers must be able to do
559 * something reasonable with this, for instance, mark the
560 * server down. Fortunately, any error code < 0
561 * will elicit that behavior. See #1.
562 * 5. Some combination of the above. I like doing #2 for 10
563 * minutes, followed by #4. 3.1b and 3.2 cache managers
564 * will be fine as long as the restart period is
565 * not longer than 6.5 minutes, otherwise they may
566 * return ENODEV to users. 3.3 cache managers will be
567 * fine for 10 minutes, then will return
568 * ETIMEDOUT. 3.4 cache managers will just wait
569 * until the call works or fails definitively.
570 * NB. The problem with 2,3,4,5 is that old clients won't
571 * fail over to an alternate read-only replica while this
572 * server is restarting. 3.4 clients will fail over right away.
574 if (restartedat.tv_sec == 0) {
575 /* I'm not really worried about when we restarted, I'm */
576 /* just worried about when the first VBUSY was returned. */
577 FT_GetTimeOfDay(&restartedat, 0);
580 afs_perfstats.fs_nBusies++;
583 return (busyonrst ? VBUSY : restarting);
586 FT_GetTimeOfDay(&now, 0);
587 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
590 afs_perfstats.fs_nBusies++;
593 return (busyonrst ? VBUSY : restarting);
599 /* allow read operations on busy volume.
600 * must check local_errorCode because demand attach fs
601 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
602 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
603 #ifdef AFS_DEMAND_ATTACH_FS
604 /* DAFS case is complicated by the fact that local_errorCode can
605 * be VBUSY in cases where the volume is truly offline */
607 /* volume is in VOL_STATE_UNATTACHED */
610 #endif /* AFS_DEMAND_ATTACH_FS */
613 } else if (errorCode)
620 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
623 if ((*vptr)->disk.uniquifier != fid->Unique) {
624 VPutVnode(&fileCode, *vptr);
625 osi_Assert(fileCode == 0);
627 return (VNOVNODE); /* return the right error code, at least */
632 static_inline afs_int32
633 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
635 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
639 * This routine returns the ACL associated with the targetptr. If the
640 * targetptr isn't a directory, we access its parent dir and get the ACL
641 * thru the parent; in such case the parent's vnode is returned in
645 SetAccessList(Vnode ** targetptr, Volume ** volume,
646 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
647 AFSFid * Fid, int Lock)
649 if ((*targetptr)->disk.type == vDirectory) {
651 *ACL = VVnodeACL(*targetptr);
652 *ACLSize = VAclSize(*targetptr);
655 osi_Assert(Fid != 0);
660 parentvnode = (*targetptr)->disk.parent;
661 VPutVnode(&errorCode, *targetptr);
665 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
668 *ACL = VVnodeACL(*parent);
669 *ACLSize = VAclSize(*parent);
670 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
672 if ((*targetptr)->disk.parent != parentvnode) {
673 VPutVnode(&errorCode, *parent);
684 /* Must not be called with H_LOCK held */
686 client_CheckRights(struct client *client, struct acl_accessList *ACL,
690 ObtainReadLock(&client->lock);
691 if (client->CPS.prlist_len > 0 && !client->deleted &&
692 client->host && !(client->host->hostFlags & HOSTDELETED))
693 acl_CheckRights(ACL, &client->CPS, rights);
694 ReleaseReadLock(&client->lock);
697 /* Must not be called with H_LOCK held */
699 client_HasAsMember(struct client *client, afs_int32 id)
703 ObtainReadLock(&client->lock);
704 if (client->CPS.prlist_len > 0 && !client->deleted &&
705 client->host && !(client->host->hostFlags & HOSTDELETED))
706 code = acl_IsAMember(id, &client->CPS);
707 ReleaseReadLock(&client->lock);
712 * Compare the directory's ACL with the user's access rights in the client
713 * connection and return the user's and everybody else's access permissions
714 * in rights and anyrights, respectively
717 GetRights(struct client *client, struct acl_accessList *ACL,
718 afs_int32 * rights, afs_int32 * anyrights)
720 extern prlist SystemAnyUserCPS;
721 afs_int32 hrights = 0;
723 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
724 ViceLog(0, ("CheckRights failed\n"));
729 client_CheckRights(client, ACL, rights);
731 /* wait if somebody else is already doing the getCPS call */
733 while (client->host->hostFlags & HCPS_INPROGRESS) {
734 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
735 CV_WAIT(&client->host->cond, &host_glock_mutex);
738 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
741 ("CheckRights: len=%u, for host=%s:%d\n",
742 client->host->hcps.prlist_len,
743 afs_inet_ntoa_r(client->host->host, hoststr),
744 ntohs(client->host->port)));
746 acl_CheckRights(ACL, &client->host->hcps, &hrights);
748 /* Allow system:admin the rights given with the -implicit option */
749 if (client_HasAsMember(client, SystemId))
750 *rights |= implicitAdminRights;
753 *anyrights |= hrights;
760 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
761 * a System:Administrator)
764 VanillaUser(struct client *client)
766 if (client_HasAsMember(client, SystemId))
767 return (0); /* not a system administrator, then you're "vanilla" */
773 /*------------------------------------------------------------------------
774 * GetVolumePackageWithCall
777 * This unusual afs_int32-parameter routine encapsulates all volume
778 * package related operations together in a single function; it's
779 * called by almost all AFS interface calls.
782 * acall : Ptr to Rx call on which this request came in.
783 * cbv : struct containing the RX call for offline cancels
784 * Fid : the AFS fid the caller is acting on
785 * volptr : returns a pointer to the volume struct
786 * targetptr : returns a pointer to the vnode struct
787 * chkforDir : whether to check for if vnode is a dir
788 * parent : returns a pointer to the parent of this vnode
789 * client : returns a pointer to the calling client
790 * locktype : indicates what kind of lock to take on vnodes
791 * rights : returns a pointer to caller's rights
792 * anyrights : returns a pointer to anonymous' rights
793 * remote : indicates that the volume is a remote RW replica
797 * appropriate error based on permission or invalid operation.
800 * Nothing interesting.
803 * On success, disables keepalives on the call. Caller should re-enable
804 * after completing disk I/O.
805 *------------------------------------------------------------------------*/
807 GetVolumePackageWithCall(struct rx_call *acall, struct VCallByVol *cbv,
808 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
809 int chkforDir, Vnode ** parent,
810 struct client **client, int locktype,
811 afs_int32 * rights, afs_int32 * anyrights, int remote)
813 struct acl_accessList *aCL; /* Internal access List */
814 int aCLSize; /* size of the access list */
815 Error errorCode = 0; /* return code to caller */
816 struct rx_connection *tcon = rx_ConnectionOf(acall);
818 rx_KeepAliveOff(acall);
820 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
824 if (chkforDir == MustNOTBeDIR
825 && ((*targetptr)->disk.type == vDirectory)) {
829 else if (chkforDir == MustBeDIR
830 && ((*targetptr)->disk.type != vDirectory)) {
836 * If the remote flag is set, the current call is dealing with a remote RW
837 * replica, and it can be assumed that the appropriate access checks were
838 * done by the calling server hosting the master volume.
841 if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
842 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
843 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
845 if (chkforDir == MustBeDIR)
846 osi_Assert((*parent) == 0);
848 if ((errorCode = GetClient(tcon, client)) != 0)
854 GetRights(*client, aCL, rights, anyrights);
855 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
856 if ((*targetptr)->disk.type != vDirectory) {
857 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
858 if ((*targetptr)->disk.owner == (*client)->ViceId)
859 (*rights) |= PRSFS_ADMINISTER;
861 (*rights) &= ~PRSFS_ADMINISTER;
863 #ifdef ADMIN_IMPLICIT_LOOKUP
864 /* admins get automatic lookup on everything */
865 if (!VanillaUser(*client))
866 (*rights) |= PRSFS_LOOKUP;
867 #endif /* ADMIN_IMPLICIT_LOOKUP */
870 rx_KeepAliveOn(acall);
874 } /*GetVolumePackage */
876 static_inline afs_int32
877 GetVolumePackage(struct rx_call *acall, AFSFid * Fid, Volume ** volptr,
878 Vnode ** targetptr, int chkforDir, Vnode ** parent,
879 struct client **client, int locktype, afs_int32 * rights,
880 afs_int32 * anyrights)
882 return GetVolumePackageWithCall(acall, NULL, Fid, volptr, targetptr,
883 chkforDir, parent, client, locktype,
884 rights, anyrights, 0);
888 /*------------------------------------------------------------------------
889 * PutVolumePackageWithCall
892 * This is the opposite of GetVolumePackage(), and is always used at
893 * the end of AFS calls to put back all used vnodes and the volume
894 * in the proper order!
897 * acall : Ptr to Rx call on which this request came in.
898 * parentwhentargetnotdir : a pointer to the parent when the target isn't
900 * targetptr : a pointer to the vnode struct
901 * parentptr : a pointer to the parent of this vnode
902 * volptr : a pointer to the volume structure
903 * client : a pointer to the calling client
904 * cbv : struct containing the RX call for offline cancels
910 * Nothing interesting.
913 * Enables keepalives on the call.
914 *------------------------------------------------------------------------*/
916 PutVolumePackageWithCall(struct rx_call *acall, Vnode *
917 parentwhentargetnotdir, Vnode * targetptr,
918 Vnode * parentptr, Volume * volptr,
919 struct client **client, struct VCallByVol *cbv)
921 Error fileCode = 0; /* Error code returned by the volume package */
923 rx_KeepAliveOff(acall);
924 if (parentwhentargetnotdir) {
925 VPutVnode(&fileCode, parentwhentargetnotdir);
926 osi_Assert(!fileCode || (fileCode == VSALVAGE));
929 VPutVnode(&fileCode, targetptr);
930 osi_Assert(!fileCode || (fileCode == VSALVAGE));
933 VPutVnode(&fileCode, parentptr);
934 osi_Assert(!fileCode || (fileCode == VSALVAGE));
937 VPutVolumeWithCall(volptr, cbv);
939 rx_KeepAliveOn(acall);
944 } /*PutVolumePackage */
947 PutVolumePackage(struct rx_call *acall, Vnode * parentwhentargetnotdir,
948 Vnode * targetptr, Vnode * parentptr, Volume * volptr,
949 struct client **client)
951 PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
952 parentptr, volptr, client, NULL);
956 VolumeOwner(struct client *client, Vnode * targetptr)
958 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
961 return (client->ViceId == owner);
964 * We don't have to check for host's cps since only regular
965 * viceid are volume owners.
967 return (client_HasAsMember(client, owner));
973 VolumeRootVnode(Vnode * targetptr)
975 return ((targetptr->vnodeNumber == ROOTVNODE)
976 && (targetptr->disk.uniquifier == 1));
978 } /*VolumeRootVnode */
981 * Check if target file has the proper access permissions for the Fetch
982 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
983 * StoreStatus) related calls
985 /* this code should probably just set a "priv" flag where all the audit events
986 * are now, and only generate the audit event once at the end of the routine,
987 * thus only generating the event if all the checks succeed, but only because
988 * of the privilege XXX
991 Check_PermissionRights(Vnode * targetptr, struct client *client,
992 afs_int32 rights, int CallingRoutine,
993 AFSStoreStatus * InStatus)
996 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
997 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
998 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
1000 if (CallingRoutine & CHK_FETCH) {
1001 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
1002 if (targetptr->disk.type == vDirectory
1003 || targetptr->disk.type == vSymlink) {
1004 if (!(rights & PRSFS_LOOKUP)
1005 #ifdef ADMIN_IMPLICIT_LOOKUP
1006 /* grant admins fetch on all directories */
1007 && VanillaUser(client)
1008 #endif /* ADMIN_IMPLICIT_LOOKUP */
1009 && !VolumeOwner(client, targetptr))
1012 /* must have read access, or be owner and have insert access */
1013 if (!(rights & PRSFS_READ)
1014 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
1015 && (client->ViceId != AnonymousID))))
1018 if (CallingRoutine == CHK_FETCHDATA
1019 && targetptr->disk.type == vFile)
1020 #ifdef USE_GROUP_PERMS
1021 if (!OWNSp(client, targetptr)
1022 && !client_HasAsMember(client, targetptr->disk.owner)) {
1024 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
1028 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
1033 * The check with the ownership below is a kludge to allow
1034 * reading of files created with no read permission. The owner
1035 * of the file is always allowed to read it.
1037 if ((client->ViceId != targetptr->disk.owner)
1038 && VanillaUser(client))
1040 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
1041 modeBits) ? 0 : EACCES);
1043 } else { /* !VanillaUser(client) && !FetchData */
1045 osi_audit(PrivilegeEvent, 0, AUD_ID,
1046 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
1049 } else { /* a store operation */
1050 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1051 && (CallingRoutine != CHK_STOREACL)
1052 && (targetptr->disk.type == vFile)) {
1053 /* bypass protection checks on first store after a create
1054 * for the creator; also prevent chowns during this time
1055 * unless you are a system administrator */
1056 /****** InStatus->Owner && UnixModeBits better be SET!! */
1057 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1060 else if (VanillaUser(client))
1061 return (EPERM); /* Was EACCES */
1063 osi_audit(PrivilegeEvent, 0, AUD_ID,
1064 (client ? client->ViceId : 0), AUD_INT,
1065 CallingRoutine, AUD_END);
1068 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1069 osi_audit(PrivilegeEvent, 0, AUD_ID,
1070 (client ? client->ViceId : 0), AUD_INT,
1071 CallingRoutine, AUD_END);
1073 if (readonlyServer) {
1076 if (CallingRoutine == CHK_STOREACL) {
1077 if (!(rights & PRSFS_ADMINISTER)
1078 && !VolumeOwner(client, targetptr))
1080 } else { /* store data or status */
1081 /* watch for chowns and chgrps */
1082 if (CHOWN(InStatus, targetptr)
1083 || CHGRP(InStatus, targetptr)) {
1086 else if (VanillaUser(client))
1087 return (EPERM); /* Was EACCES */
1089 osi_audit(PrivilegeEvent, 0, AUD_ID,
1090 (client ? client->ViceId : 0), AUD_INT,
1091 CallingRoutine, AUD_END);
1093 /* must be sysadmin to set suid/sgid bits */
1094 if ((InStatus->Mask & AFS_SETMODE) &&
1096 (InStatus->UnixModeBits & 0xc00) != 0) {
1098 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1102 if (VanillaUser(client))
1105 osi_audit(PrivSetID, 0, AUD_ID,
1106 (client ? client->ViceId : 0), AUD_INT,
1107 CallingRoutine, AUD_END);
1109 if (CallingRoutine == CHK_STOREDATA) {
1112 if (!(rights & PRSFS_WRITE))
1114 /* Next thing is tricky. We want to prevent people
1115 * from writing files sans 0200 bit, but we want
1116 * creating new files with 0444 mode to work. We
1117 * don't check the 0200 bit in the "you are the owner"
1118 * path above, but here we check the bit. However, if
1119 * you're a system administrator, we ignore the 0200
1120 * bit anyway, since you may have fchowned the file,
1122 #ifdef USE_GROUP_PERMS
1123 if ((targetptr->disk.type == vFile)
1124 && VanillaUser(client)) {
1125 if (!OWNSp(client, targetptr)
1126 && !client_HasAsMember(client, targetptr->disk.owner)) {
1128 ((GROUPWRITE & targetptr->disk.modeBits)
1132 ((OWNERWRITE & targetptr->disk.modeBits)
1137 if ((targetptr->disk.type != vDirectory)
1138 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1141 if (VanillaUser(client))
1144 osi_audit(PrivilegeEvent, 0, AUD_ID,
1145 (client ? client->ViceId : 0),
1146 AUD_INT, CallingRoutine, AUD_END);
1148 } else { /* a status store */
1151 if (targetptr->disk.type == vDirectory) {
1152 if (!(rights & PRSFS_DELETE)
1153 && !(rights & PRSFS_INSERT))
1155 } else { /* a file or symlink */
1156 if (!(rights & PRSFS_WRITE))
1166 } /*Check_PermissionRights */
1170 * The Access List information is converted from its internal form in the
1171 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1172 * external form and returned back to the caller, via the AccessList
1176 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1177 struct AFSOpaque *AccessList)
1179 char *eACL; /* External access list placeholder */
1181 if (acl_Externalize_pr
1182 (hpr_IdToName, (targetptr->disk.type ==
1183 vDirectory ? VVnodeACL(targetptr) :
1184 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1187 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1188 acl_FreeExternalACL(&eACL);
1191 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1192 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1194 acl_FreeExternalACL(&eACL);
1197 } /*RXFetch_AccessList */
1201 * The Access List information is converted from its external form in the
1202 * input AccessList structure to the internal representation and copied into
1203 * the target dir's vnode storage.
1206 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1208 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1210 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1213 if ((newACL->size + 4) > VAclSize(targetptr))
1215 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1216 acl_FreeACL(&newACL);
1219 } /*RXStore_AccessList */
1222 /* In our current implementation, each successive data store (new file
1223 * data version) creates a new inode. This function creates the new
1224 * inode, copies the old inode's contents to the new one, remove the old
1225 * inode (i.e. decrement inode count -- if it's currently used the delete
1226 * will be delayed), and modify some fields (i.e. vnode's
1227 * disk.inodeNumber and cloned)
1229 #define COPYBUFFSIZE 8192
1230 #define MAXFSIZE (~(afs_fsize_t) 0)
1232 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1235 Inode nearInode AFS_UNUSED;
1242 int rc; /* return code */
1243 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1244 FdHandle_t *targFdP; /* Source Inode file handle */
1245 FdHandle_t *newFdP; /* Dest Inode file handle */
1247 if (targetptr->disk.type == vDirectory)
1248 DFlush(); /* just in case? */
1250 VN_GET_LEN(size, targetptr);
1258 buff = (char *)malloc(COPYBUFFSIZE);
1263 ino = VN_GET_INO(targetptr);
1264 if (!VALID_INO(ino)) {
1266 VTakeOffline(volptr);
1267 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1271 targFdP = IH_OPEN(targetptr->handle);
1272 if (targFdP == NULL) {
1275 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1276 targetptr->vnodeNumber, V_id(volptr), rc));
1278 VTakeOffline(volptr);
1282 nearInode = VN_GET_INO(targetptr);
1284 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1285 VPartitionPath(V_partition(volptr)), nearInode,
1286 V_id(volptr), targetptr->vnodeNumber,
1287 targetptr->disk.uniquifier,
1288 (int)targetptr->disk.dataVersion);
1289 if (!VALID_INO(ino)) {
1291 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1292 volptr->partition->name, V_id(volptr), errno));
1297 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1298 newFdP = IH_OPEN(newH);
1299 osi_Assert(newFdP != NULL);
1303 if (size > COPYBUFFSIZE) { /* more than a buffer */
1304 length = COPYBUFFSIZE;
1305 size -= COPYBUFFSIZE;
1310 rdlen = FDH_PREAD(targFdP, buff, length, done);
1311 if (rdlen == length) {
1312 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1316 /* Callers of this function are not prepared to recover
1317 * from error that put the filesystem in an inconsistent
1318 * state. Make sure that we force the volume off-line if
1319 * we some error other than ENOSPC - 4.29.99)
1321 * In case we are unable to write the required bytes, and the
1322 * error code indicates that the disk is full, we roll-back to
1323 * the initial state.
1325 if ((rdlen != length) || (wrlen != length)) {
1326 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1328 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1329 volptr->partition->name, V_id(volptr)));
1330 /* remove destination inode which was partially copied till now */
1331 FDH_REALLYCLOSE(newFdP);
1333 FDH_REALLYCLOSE(targFdP);
1334 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1337 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1338 rc, V_id(volptr), volptr->partition->name));
1339 VTakeOffline(volptr);
1344 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1345 * since we never do any I/O anywhere near 2^32 bytes at a
1346 * time, just case to an unsigned int for printing */
1349 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1350 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1351 (unsigned)wrlen, errno));
1352 #if defined(AFS_DEMAND_ATTACH_FS)
1353 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1355 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1357 /* Decrement this inode so salvager doesn't find it. */
1358 FDH_REALLYCLOSE(newFdP);
1360 FDH_REALLYCLOSE(targFdP);
1361 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1363 VTakeOffline(volptr);
1368 FDH_REALLYCLOSE(targFdP);
1369 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1370 V_parentId(volptr));
1372 IH_RELEASE(targetptr->handle);
1374 rc = FDH_SYNC(newFdP);
1375 osi_Assert(rc == 0);
1377 targetptr->handle = newH;
1378 VN_SET_INO(targetptr, ino);
1379 targetptr->disk.cloned = 0;
1380 /* Internal change to vnode, no user level change to volume - def 5445 */
1381 targetptr->changed_oldTime = 1;
1383 return 0; /* success */
1387 * Common code to handle with removing the Name (file when it's called from
1388 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1389 * given directory, parentptr.
1391 int DT1 = 0, DT0 = 0;
1393 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1394 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1396 DirHandle childdir; /* Handle for dir package I/O */
1397 Error errorCode = 0;
1401 /* watch for invalid names */
1402 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1405 if (CheckLength(volptr, parentptr, -1)) {
1406 VTakeOffline(volptr);
1410 if (parentptr->disk.cloned) {
1411 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1412 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1414 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1420 /* check that the file is in the directory */
1421 SetDirHandle(dir, parentptr);
1422 if (afs_dir_Lookup(dir, Name, fileFid))
1424 fileFid->Volume = V_id(volptr);
1426 /* just-in-case check for something causing deadlock */
1427 if (fileFid->Vnode == parentptr->vnodeNumber)
1430 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1434 if (ChkForDir == MustBeDIR) {
1435 if ((*targetptr)->disk.type != vDirectory)
1437 } else if ((*targetptr)->disk.type == vDirectory)
1440 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1442 * If the uniquifiers dont match then instead of asserting
1443 * take the volume offline and return VSALVAGE
1445 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1446 VTakeOffline(volptr);
1448 ("Volume %u now offline, must be salvaged.\n",
1450 errorCode = VSALVAGE;
1454 if (ChkForDir == MustBeDIR) {
1455 SetDirHandle(&childdir, *targetptr);
1456 if (afs_dir_IsEmpty(&childdir) != 0)
1460 (*targetptr)->delete = 1;
1461 } else if ((--(*targetptr)->disk.linkCount) == 0)
1462 (*targetptr)->delete = 1;
1463 if ((*targetptr)->delete) {
1464 if (VN_GET_INO(*targetptr)) {
1466 IH_REALLYCLOSE((*targetptr)->handle);
1468 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1469 V_parentId(volptr));
1470 IH_RELEASE((*targetptr)->handle);
1471 if (errorCode == -1) {
1473 ("DT: inode=%s, name=%s, errno=%d\n",
1474 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1476 if (errno != ENOENT)
1478 VTakeOffline(volptr);
1480 ("Volume %u now offline, must be salvaged.\n",
1488 VN_SET_INO(*targetptr, (Inode) 0);
1490 afs_fsize_t adjLength;
1491 VN_GET_LEN(adjLength, *targetptr);
1492 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1496 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1498 code = afs_dir_Delete(dir, Name);
1501 ("Error %d deleting %s\n", code,
1502 (((*targetptr)->disk.type ==
1503 Directory) ? "directory" : "file")));
1504 VTakeOffline(volptr);
1506 ("Volume %u now offline, must be salvaged.\n",
1519 * This routine updates the parent directory's status block after the
1520 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1521 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1525 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1526 int author, int linkcount, char a_inSameNetwork)
1528 afs_fsize_t newlength; /* Holds new directory length */
1529 afs_fsize_t parentLength;
1531 Date currDate; /*Current date */
1532 int writeIdx; /*Write index to bump */
1533 int timeIdx; /*Authorship time index to bump */
1535 parentptr->disk.dataVersion++;
1536 newlength = (afs_fsize_t) afs_dir_Length(dir);
1538 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1539 * (create, symlink, link, makedir) so we need to check if we have enough space
1540 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1541 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1543 VN_GET_LEN(parentLength, parentptr);
1544 if (nBlocks(newlength) != nBlocks(parentLength)) {
1545 VAdjustDiskUsage(&errorCode, volptr,
1546 (nBlocks(newlength) - nBlocks(parentLength)),
1547 (nBlocks(newlength) - nBlocks(parentLength)));
1549 VN_SET_LEN(parentptr, newlength);
1552 * Update directory write stats for this volume. Note that the auth
1553 * counter is located immediately after its associated ``distance''
1556 if (a_inSameNetwork)
1557 writeIdx = VOL_STATS_SAME_NET;
1559 writeIdx = VOL_STATS_DIFF_NET;
1560 V_stat_writes(volptr, writeIdx)++;
1561 if (author != AnonymousID) {
1562 V_stat_writes(volptr, writeIdx + 1)++;
1566 * Update the volume's authorship information in response to this
1567 * directory operation. Get the current time, decide to which time
1568 * slot this operation belongs, and bump the appropriate slot.
1570 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1572 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1573 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1574 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1575 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1576 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1577 if (parentptr->disk.author == author) {
1578 V_stat_dirSameAuthor(volptr, timeIdx)++;
1580 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1583 parentptr->disk.author = author;
1584 parentptr->disk.linkCount = linkcount;
1585 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1586 parentptr->disk.serverModifyTime = FT_ApproxTime();
1587 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1592 * Update the target file's (or dir's) status block after the specified
1593 * operation is complete. Note that some other fields maybe updated by
1594 * the individual module.
1595 * If remote is set, the volume is a RW replica and access checks can
1599 /* XXX INCOMPLETE - More attention is needed here! */
1601 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1602 struct client *client, AFSStoreStatus * InStatus,
1603 Vnode * parentptr, Volume * volptr,
1604 afs_fsize_t length, int remote)
1606 Date currDate; /*Current date */
1607 int writeIdx; /*Write index to bump */
1608 int timeIdx; /*Authorship time index to bump */
1610 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1611 targetptr->disk.parent = parentptr->vnodeNumber;
1612 VN_SET_LEN(targetptr, length);
1613 /* targetptr->disk.group = 0; save some cycles */
1614 targetptr->disk.modeBits = 0777;
1615 targetptr->disk.owner = client->ViceId;
1616 targetptr->disk.dataVersion = 0; /* consistent with the client */
1617 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1618 /* the inode was created in Alloc_NewVnode() */
1621 * Update file write stats for this volume. Note that the auth
1622 * counter is located immediately after its associated ``distance''
1625 if (client->InSameNetwork)
1626 writeIdx = VOL_STATS_SAME_NET;
1628 writeIdx = VOL_STATS_DIFF_NET;
1629 V_stat_writes(volptr, writeIdx)++;
1630 if (client->ViceId != AnonymousID) {
1631 V_stat_writes(volptr, writeIdx + 1)++;
1635 * We only count operations that DON'T involve creating new objects
1636 * (files, symlinks, directories) or simply setting status as
1637 * authorship-change operations.
1639 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1641 * Update the volume's authorship information in response to this
1642 * file operation. Get the current time, decide to which time
1643 * slot this operation belongs, and bump the appropriate slot.
1645 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1648 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1649 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1650 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1651 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1652 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1653 VOL_STATS_TIME_IDX_5);
1654 if (targetptr->disk.author == client->ViceId) {
1655 V_stat_fileSameAuthor(volptr, timeIdx)++;
1657 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1661 if (!(Caller & TVS_SSTATUS))
1662 targetptr->disk.author = client->ViceId;
1663 if (Caller & TVS_SDATA) {
1664 targetptr->disk.dataVersion++;
1665 if (!remote && VanillaUser(client)) {
1666 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1667 #ifdef CREATE_SGUID_ADMIN_ONLY
1668 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1672 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1673 /* store status, must explicitly request to change the date */
1674 if (InStatus->Mask & AFS_SETMODTIME)
1675 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1676 } else { /* other: date always changes, but perhaps to what is specified by caller */
1677 targetptr->disk.unixModifyTime =
1678 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1679 ClientModTime : FT_ApproxTime());
1681 if (InStatus->Mask & AFS_SETOWNER) {
1682 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1683 if (!remote && VanillaUser(client)) {
1684 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1685 #ifdef CREATE_SGUID_ADMIN_ONLY
1686 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1689 targetptr->disk.owner = InStatus->Owner;
1690 if (VolumeRootVnode(targetptr)) {
1691 Error errorCode = 0; /* what should be done with this? */
1693 V_owner(targetptr->volumePtr) = InStatus->Owner;
1694 VUpdateVolume(&errorCode, targetptr->volumePtr);
1697 if (InStatus->Mask & AFS_SETMODE) {
1698 int modebits = InStatus->UnixModeBits;
1699 #define CREATE_SGUID_ADMIN_ONLY 1
1700 #ifdef CREATE_SGUID_ADMIN_ONLY
1701 if (!remote && VanillaUser(client))
1702 modebits = modebits & 0777;
1704 if (!remote && VanillaUser(client)) {
1705 targetptr->disk.modeBits = modebits;
1707 targetptr->disk.modeBits = modebits;
1710 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1711 CHK_STOREDATA, AUD_END);
1715 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1716 CHK_STORESTATUS, AUD_END);
1723 targetptr->disk.serverModifyTime = FT_ApproxTime();
1724 if (InStatus->Mask & AFS_SETGROUP)
1725 targetptr->disk.group = InStatus->Group;
1726 /* vnode changed : to be written back by VPutVnode */
1727 targetptr->changed_newTime = 1;
1729 } /*Update_TargetVnodeStatus */
1733 * Fills the CallBack structure with the expiration time and type of callback
1734 * structure. Warning: this function is currently incomplete.
1737 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1739 /* CallBackTime could not be 0 */
1740 if (CallBackTime == 0) {
1741 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1742 CallBack->ExpirationTime = 0;
1744 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1745 CallBack->CallBackVersion = CALLBACK_VERSION;
1746 CallBack->CallBackType = CB_SHARED; /* The default for now */
1748 } /*SetCallBackStruct */
1752 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1753 * allocation; if some error occured (exceeded volume quota or partition
1754 * was full, or whatever), it frees the space back and returns the code.
1755 * We usually pre-adjust the volume space to make sure that there's
1756 * enough space before consuming some.
1759 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1760 afs_sfsize_t checkLength)
1765 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1767 VAdjustDiskUsage(&nc, volptr, -length, 0);
1768 if (rc == VOVERQUOTA) {
1770 ("Volume %u (%s) is full\n", V_id(volptr),
1774 if (rc == VDISKFULL) {
1776 ("Partition %s that contains volume %u is full\n",
1777 volptr->partition->name, V_id(volptr)));
1780 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1785 } /*AdjustDiskUsage */
1788 * Common code that handles the creation of a new file (SAFS_CreateFile and
1789 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1792 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1793 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1794 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1796 Error errorCode = 0; /* Error code returned back */
1799 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1803 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1804 BlocksPreallocatedForVnode))) {
1806 ("Insufficient space to allocate %lld blocks\n",
1807 (afs_intmax_t) BlocksPreallocatedForVnode));
1811 if (CheckLength(volptr, parentptr, -1)) {
1812 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1813 VTakeOffline(volptr);
1817 *targetptr = VAllocVnode(&errorCode, volptr, FileType, 0, 0);
1818 if (errorCode != 0) {
1819 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1822 OutFid->Volume = V_id(volptr);
1823 OutFid->Vnode = (*targetptr)->vnodeNumber;
1824 OutFid->Unique = (*targetptr)->disk.uniquifier;
1826 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1828 /* create the inode now itself */
1830 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1831 VPartitionPath(V_partition(volptr)), nearInode,
1832 V_id(volptr), (*targetptr)->vnodeNumber,
1833 (*targetptr)->disk.uniquifier, 1);
1835 /* error in creating inode */
1836 if (!VALID_INO(inode)) {
1838 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1839 (*targetptr)->volumePtr->header->diskstuff.id,
1840 (*targetptr)->vnodeNumber, errno));
1841 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1842 (*targetptr)->delete = 1; /* delete vnode */
1845 VN_SET_INO(*targetptr, inode);
1846 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1848 /* copy group from parent dir */
1849 (*targetptr)->disk.group = parentptr->disk.group;
1851 if (parentptr->disk.cloned) {
1852 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1853 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1854 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1855 /* delete the vnode previously allocated */
1856 (*targetptr)->delete = 1;
1857 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1858 IH_REALLYCLOSE((*targetptr)->handle);
1859 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1861 ("Alloc_NewVnode: partition %s idec %s failed\n",
1862 volptr->partition->name, PrintInode(stmp, inode)));
1863 IH_RELEASE((*targetptr)->handle);
1869 /* add the name to the directory */
1870 SetDirHandle(dir, parentptr);
1871 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1872 (*targetptr)->delete = 1;
1873 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1874 IH_REALLYCLOSE((*targetptr)->handle);
1875 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1877 ("Alloc_NewVnode: partition %s idec %s failed\n",
1878 volptr->partition->name, PrintInode(stmp, inode)));
1879 IH_RELEASE((*targetptr)->handle);
1885 } /*Alloc_NewVnode */
1889 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1893 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1895 int Time; /* Used for time */
1896 int writeVnode = targetptr->changed_oldTime; /* save original status */
1898 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1899 Time = FT_ApproxTime();
1900 switch (LockingType) {
1903 if (Time > targetptr->disk.lock.lockTime)
1904 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1906 Time += AFS_LOCKWAIT;
1907 if (LockingType == LockRead) {
1908 if ( !(rights & PRSFS_LOCK) &&
1909 !(rights & PRSFS_WRITE) &&
1910 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1913 if (targetptr->disk.lock.lockCount >= 0) {
1914 ++(targetptr->disk.lock.lockCount);
1915 targetptr->disk.lock.lockTime = Time;
1918 } else if (LockingType == LockWrite) {
1919 if ( !(rights & PRSFS_WRITE) &&
1920 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1923 if (targetptr->disk.lock.lockCount == 0) {
1924 targetptr->disk.lock.lockCount = -1;
1925 targetptr->disk.lock.lockTime = Time;
1931 Time += AFS_LOCKWAIT;
1932 if (targetptr->disk.lock.lockCount != 0)
1933 targetptr->disk.lock.lockTime = Time;
1938 if ((--targetptr->disk.lock.lockCount) <= 0)
1939 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1943 targetptr->changed_oldTime = writeVnode; /* restore old status */
1944 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1947 } /*HandleLocking */
1949 /* Checks if caller has the proper AFS and Unix (WRITE) access permission to the target directory; Prfs_Mode refers to the AFS Mode operation while rights contains the caller's access permissions to the directory. */
1952 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1956 if (!(rights & Prfs_Mode))
1958 if ((targetptr->disk.type != vDirectory)
1959 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1965 * If some flags (i.e. min or max quota) are set, the volume's in disk
1966 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1967 * update, if applicable.
1970 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1971 char *Name, char *OfflineMsg, char *Motd)
1973 Error errorCode = 0;
1975 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1976 V_minquota(volptr) = StoreVolStatus->MinQuota;
1977 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1978 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1979 if (strlen(OfflineMsg) > 0) {
1980 strcpy(V_offlineMessage(volptr), OfflineMsg);
1982 if (strlen(Name) > 0) {
1983 strcpy(V_name(volptr), Name);
1986 * We don't overwrite the motd field, since it's now being used
1989 VUpdateVolume(&errorCode, volptr);
1992 } /*RXUpdate_VolumeStatus */
1996 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1997 char **motd, Volume * volptr)
2000 status->Vid = V_id(volptr);
2001 status->ParentId = V_parentId(volptr);
2002 status->Online = V_inUse(volptr);
2003 status->InService = V_inService(volptr);
2004 status->Blessed = V_blessed(volptr);
2005 status->NeedsSalvage = V_needsSalvaged(volptr);
2006 if (VolumeWriteable(volptr))
2007 status->Type = ReadWrite;
2009 status->Type = ReadOnly;
2010 status->MinQuota = V_minquota(volptr);
2011 status->MaxQuota = V_maxquota(volptr);
2012 status->BlocksInUse = V_diskused(volptr);
2013 status->PartBlocksAvail = RoundInt64ToInt31(volptr->partition->free);
2014 status->PartMaxBlocks = RoundInt64ToInt31(volptr->partition->totalUsable);
2016 /* now allocate and copy these things; they're freed by the RXGEN stub */
2017 *name = strdup(V_name(volptr));
2019 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2021 *offMsg = strdup(V_offlineMessage(volptr));
2023 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2027 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2029 strcpy(*motd, nullString);
2031 } /*RXGetVolumeStatus */
2035 FileNameOK(char *aname)
2040 /* watch for @sys on the right */
2041 if (strcmp(aname + i - 4, "@sys") == 0)
2044 while ((tc = *aname++)) {
2046 return 0; /* very bad character to encounter */
2048 return 1; /* file name is ok */
2054 * This variant of symlink is expressly to support the AFS/DFS translator
2055 * and is not supported by the AFS fileserver. We just return EINVAL.
2056 * The cache manager should not generate this call to an AFS cache manager.
2059 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2060 char *LinkContents, struct AFSStoreStatus *InStatus,
2061 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2062 struct AFSFetchStatus *OutDirStatus,
2063 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2069 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2070 struct FsCmdInputs * Inputs,
2071 struct FsCmdOutputs * Outputs)
2075 switch (Inputs->command) {
2079 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2080 Inputs->command, Outputs->code));
2085 static struct afs_buffer {
2086 struct afs_buffer *next;
2087 } *freeBufferList = 0;
2088 static int afs_buffersAlloced = 0;
2091 FreeSendBuffer(struct afs_buffer *adata)
2094 afs_buffersAlloced--;
2095 adata->next = freeBufferList;
2096 freeBufferList = adata;
2100 } /*FreeSendBuffer */
2102 /* allocate space for sender */
2104 AllocSendBuffer(void)
2106 struct afs_buffer *tp;
2109 afs_buffersAlloced++;
2110 if (!freeBufferList) {
2113 tmp = malloc(sendBufSize);
2115 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2119 tp = freeBufferList;
2120 freeBufferList = tp->next;
2124 } /*AllocSendBuffer */
2125 #endif /* HAVE_PIOV */
2128 * This routine returns the status info associated with the targetptr vnode
2129 * in the AFSFetchStatus structure. Some of the newer fields, such as
2130 * SegSize and Group are not yet implemented
2134 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2135 afs_int32 anyrights, Vnode * parentptr)
2137 int Time =FT_ApproxTime();
2139 /* initialize return status from a vnode */
2140 status->InterfaceVersion = 1;
2141 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2142 status->errorCode = 0;
2143 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2144 if (targetptr->disk.type == vFile)
2145 status->FileType = File;
2146 else if (targetptr->disk.type == vDirectory)
2147 status->FileType = Directory;
2148 else if (targetptr->disk.type == vSymlink)
2149 status->FileType = SymbolicLink;
2151 status->FileType = Invalid; /*invalid type field */
2152 status->LinkCount = targetptr->disk.linkCount;
2154 afs_fsize_t targetLen;
2155 VN_GET_LEN(targetLen, targetptr);
2156 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2158 status->DataVersion = targetptr->disk.dataVersion;
2159 status->Author = targetptr->disk.author;
2160 status->Owner = targetptr->disk.owner;
2161 status->CallerAccess = rights;
2162 status->AnonymousAccess = anyrights;
2163 status->UnixModeBits = targetptr->disk.modeBits;
2164 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2165 status->ParentVnode =
2166 (status->FileType ==
2167 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2168 status->ParentUnique =
2169 (status->FileType ==
2170 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2171 status->ServerModTime = targetptr->disk.serverModifyTime;
2172 status->Group = targetptr->disk.group;
2173 status->lockCount = Time > targetptr->disk.lock.lockTime ? 0 : targetptr->disk.lock.lockCount;
2174 status->errorCode = 0;
2179 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2180 afs_sfsize_t Pos, afs_sfsize_t Len,
2181 struct AFSFetchStatus *OutStatus,
2182 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2185 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2186 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2187 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2188 Error errorCode = 0; /* return code to caller */
2189 Error fileCode = 0; /* return code from vol package */
2190 Volume *volptr = 0; /* pointer to the volume */
2191 struct client *client = 0; /* pointer to the client data */
2192 struct rx_connection *tcon; /* the connection we're part of */
2194 afs_int32 rights, anyrights; /* rights for this and any user */
2195 struct client *t_client = NULL; /* tmp ptr to client data */
2196 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2197 struct VCallByVol tcbv, *cbv = NULL;
2198 static int remainder = 0; /* shared access protected by FS_LOCK */
2199 struct fsstats fsstats;
2200 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2201 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2202 int readIdx; /* Index of read stats array to bump */
2204 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2207 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2210 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2212 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2215 /* Get ptr to client data for user Id for logging */
2216 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2217 logHostAddr.s_addr = rxr_HostOf(tcon);
2219 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2220 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2221 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2223 queue_NodeInit(&tcbv);
2228 * Get volume/vnode for the fetched file; caller's access rights to
2229 * it are also returned
2232 GetVolumePackageWithCall(acall, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2233 &parentwhentargetnotdir, &client, READ_LOCK,
2234 &rights, &anyrights, 0)))
2237 SetVolumeSync(Sync, volptr);
2240 * Remember that another read operation was performed.
2243 if (client->InSameNetwork)
2244 readIdx = VOL_STATS_SAME_NET;
2246 readIdx = VOL_STATS_DIFF_NET;
2247 V_stat_reads(volptr, readIdx)++;
2248 if (client->ViceId != AnonymousID) {
2249 V_stat_reads(volptr, readIdx + 1)++;
2252 /* Check whether the caller has permission access to fetch the data */
2254 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2258 * Drop the read lock on the parent directory after saving the parent
2259 * vnode information we need to pass to GetStatus
2261 if (parentwhentargetnotdir != NULL) {
2262 tparentwhentargetnotdir = *parentwhentargetnotdir;
2263 VPutVnode(&fileCode, parentwhentargetnotdir);
2264 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2265 parentwhentargetnotdir = NULL;
2268 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
2270 /* actually do the data transfer */
2272 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2273 &bytesToXfer, &bytesXferred);
2275 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2281 /* write back the OutStatus from the target vnode */
2282 GetStatus(targetptr, OutStatus, rights, anyrights,
2283 &tparentwhentargetnotdir);
2285 rx_KeepAliveOn(acall); /* I/O done */
2287 /* if a r/w volume, promise a callback to the caller */
2288 if (VolumeWriteable(volptr))
2289 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2291 struct AFSFid myFid;
2292 memset(&myFid, 0, sizeof(struct AFSFid));
2293 myFid.Volume = Fid->Volume;
2294 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2298 /* Update and store volume/vnode and parent vnodes back */
2299 (void)PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
2300 (Vnode *) 0, volptr, &client, cbv);
2301 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2302 errorCode = CallPostamble(tcon, errorCode, thost);
2304 fsstats_FinishOp(&fsstats, errorCode);
2306 osi_auditU(acall, FetchDataEvent, errorCode,
2307 AUD_ID, t_client ? t_client->ViceId : 0,
2308 AUD_FID, Fid, AUD_END);
2311 } /*SRXAFS_FetchData */
2314 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2315 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2316 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2318 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2323 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2324 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2325 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2328 afs_sfsize_t tPos, tLen;
2330 tPos = (afs_sfsize_t) Pos;
2331 tLen = (afs_sfsize_t) Len;
2334 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2340 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2341 struct AFSOpaque * AccessList,
2342 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2344 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2345 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2346 Error errorCode = 0; /* return error code to caller */
2347 Volume *volptr = 0; /* pointer to the volume */
2348 struct client *client = 0; /* pointer to the client data */
2349 afs_int32 rights, anyrights; /* rights for this and any user */
2350 struct rx_connection *tcon = rx_ConnectionOf(acall);
2352 struct client *t_client = NULL; /* tmp ptr to client data */
2353 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2354 struct fsstats fsstats;
2356 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2359 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2362 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2364 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2367 /* Get ptr to client data for user Id for logging */
2368 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2369 logHostAddr.s_addr = rxr_HostOf(tcon);
2371 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2372 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2373 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2375 AccessList->AFSOpaque_len = 0;
2376 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2377 if (!AccessList->AFSOpaque_val) {
2378 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2382 * Get volume/vnode for the fetched file; caller's access rights to it
2386 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2387 &parentwhentargetnotdir, &client, READ_LOCK,
2388 &rights, &anyrights)))
2391 SetVolumeSync(Sync, volptr);
2393 /* Check whether we have permission to fetch the ACL */
2395 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2398 /* Get the Access List from the dir's vnode */
2400 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2403 /* Get OutStatus back From the target Vnode */
2404 GetStatus(targetptr, OutStatus, rights, anyrights,
2405 parentwhentargetnotdir);
2408 /* Update and store volume/vnode and parent vnodes back */
2409 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2410 (Vnode *) 0, volptr, &client);
2412 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2413 AccessList->AFSOpaque_val));
2414 errorCode = CallPostamble(tcon, errorCode, thost);
2416 fsstats_FinishOp(&fsstats, errorCode);
2418 osi_auditU(acall, FetchACLEvent, errorCode,
2419 AUD_ID, t_client ? t_client->ViceId : 0,
2421 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2423 } /*SRXAFS_FetchACL */
2427 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2428 * merged into it when possible.
2431 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2432 struct AFSFetchStatus *OutStatus,
2433 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2435 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2436 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2437 Error errorCode = 0; /* return code to caller */
2438 Volume *volptr = 0; /* pointer to the volume */
2439 struct client *client = 0; /* pointer to the client data */
2440 afs_int32 rights, anyrights; /* rights for this and any user */
2441 struct client *t_client = NULL; /* tmp ptr to client data */
2442 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2443 struct rx_connection *tcon = rx_ConnectionOf(acall);
2445 /* Get ptr to client data for user Id for logging */
2446 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2447 logHostAddr.s_addr = rxr_HostOf(tcon);
2449 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2450 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2451 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2453 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2456 * Get volume/vnode for the fetched file; caller's rights to it are
2460 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2461 &parentwhentargetnotdir, &client, READ_LOCK,
2462 &rights, &anyrights)))
2463 goto Bad_FetchStatus;
2465 rx_KeepAliveOn(acall);
2467 /* set volume synchronization information */
2468 SetVolumeSync(Sync, volptr);
2470 /* Are we allowed to fetch Fid's status? */
2471 if (targetptr->disk.type != vDirectory) {
2473 Check_PermissionRights(targetptr, client, rights,
2474 CHK_FETCHSTATUS, 0))) {
2475 if (rx_GetCallAbortCode(acall) == errorCode)
2476 rx_SetCallAbortCode(acall, 0);
2477 goto Bad_FetchStatus;
2481 /* set OutStatus From the Fid */
2482 GetStatus(targetptr, OutStatus, rights, anyrights,
2483 parentwhentargetnotdir);
2485 /* If a r/w volume, also set the CallBack state */
2486 if (VolumeWriteable(volptr))
2487 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2489 struct AFSFid myFid;
2490 memset(&myFid, 0, sizeof(struct AFSFid));
2491 myFid.Volume = Fid->Volume;
2492 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2496 /* Update and store volume/vnode and parent vnodes back */
2497 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2498 (Vnode *) 0, volptr, &client);
2499 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2502 } /*SAFSS_FetchStatus */
2506 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2507 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2508 struct AFSVolSync * Sync)
2512 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2513 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2514 Error errorCode = 0; /* return code to caller */
2515 Volume *volptr = 0; /* pointer to the volume */
2516 struct client *client = 0; /* pointer to the client data */
2517 afs_int32 rights, anyrights; /* rights for this and any user */
2518 struct AFSFid *tfid; /* file id we're dealing with now */
2519 struct rx_connection *tcon = rx_ConnectionOf(acall);
2521 struct client *t_client = NULL; /* tmp pointer to the client data */
2522 struct fsstats fsstats;
2524 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2526 ViceLog(1, ("SAFS_BulkStatus\n"));
2528 AFSCallStats.TotalCalls++;
2530 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2531 if (nfiles <= 0) { /* Sanity check */
2533 goto Audit_and_Return;
2536 /* allocate space for return output parameters */
2537 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2538 malloc(nfiles * sizeof(struct AFSFetchStatus));
2539 if (!OutStats->AFSBulkStats_val) {
2540 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2542 OutStats->AFSBulkStats_len = nfiles;
2543 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2544 malloc(nfiles * sizeof(struct AFSCallBack));
2545 if (!CallBacks->AFSCBs_val) {
2546 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2548 CallBacks->AFSCBs_len = nfiles;
2550 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2551 goto Bad_BulkStatus;
2553 tfid = Fids->AFSCBFids_val;
2554 for (i = 0; i < nfiles; i++, tfid++) {
2556 * Get volume/vnode for the fetched file; caller's rights to it
2560 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2561 &parentwhentargetnotdir, &client, READ_LOCK,
2562 &rights, &anyrights)))
2563 goto Bad_BulkStatus;
2565 rx_KeepAliveOn(acall);
2567 /* set volume synchronization information, but only once per call */
2569 SetVolumeSync(Sync, volptr);
2571 /* Are we allowed to fetch Fid's status? */
2572 if (targetptr->disk.type != vDirectory) {
2574 Check_PermissionRights(targetptr, client, rights,
2575 CHK_FETCHSTATUS, 0))) {
2576 if (rx_GetCallAbortCode(acall) == errorCode)
2577 rx_SetCallAbortCode(acall, 0);
2578 goto Bad_BulkStatus;
2582 /* set OutStatus From the Fid */
2583 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2584 anyrights, parentwhentargetnotdir);
2586 /* If a r/w volume, also set the CallBack state */
2587 if (VolumeWriteable(volptr))
2588 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2589 &CallBacks->AFSCBs_val[i]);
2591 struct AFSFid myFid;
2592 memset(&myFid, 0, sizeof(struct AFSFid));
2593 myFid.Volume = tfid->Volume;
2594 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2595 &CallBacks->AFSCBs_val[i]);
2598 /* put back the file ID and volume */
2599 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2600 (Vnode *) 0, volptr, &client);
2601 parentwhentargetnotdir = (Vnode *) 0;
2602 targetptr = (Vnode *) 0;
2603 volptr = (Volume *) 0;
2604 client = (struct client *)0;
2608 /* Update and store volume/vnode and parent vnodes back */
2609 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2610 (Vnode *) 0, volptr, &client);
2611 errorCode = CallPostamble(tcon, errorCode, thost);
2613 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2615 fsstats_FinishOp(&fsstats, errorCode);
2618 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2619 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2620 AUD_ID, t_client ? t_client->ViceId : 0,
2621 AUD_FIDS, Fids, AUD_END);
2624 } /*SRXAFS_BulkStatus */
2628 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2629 struct AFSBulkStats * OutStats,
2630 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2634 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2635 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2636 Error errorCode = 0; /* return code to caller */
2637 Volume *volptr = 0; /* pointer to the volume */
2638 struct client *client = 0; /* pointer to the client data */
2639 afs_int32 rights, anyrights; /* rights for this and any user */
2640 struct AFSFid *tfid; /* file id we're dealing with now */
2641 struct rx_connection *tcon;
2643 struct client *t_client = NULL; /* tmp ptr to client data */
2644 AFSFetchStatus *tstatus;
2645 int VolSync_set = 0;
2646 struct fsstats fsstats;
2648 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2650 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2652 AFSCallStats.TotalCalls++;
2654 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2655 if (nfiles <= 0) { /* Sanity check */
2657 goto Audit_and_Return;
2660 /* allocate space for return output parameters */
2661 OutStats->AFSBulkStats_val = calloc(nfiles, sizeof(struct AFSFetchStatus));
2662 if (!OutStats->AFSBulkStats_val) {
2663 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2665 OutStats->AFSBulkStats_len = nfiles;
2666 CallBacks->AFSCBs_val = calloc(nfiles, sizeof(struct AFSCallBack));
2667 if (!CallBacks->AFSCBs_val) {
2668 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2670 CallBacks->AFSCBs_len = nfiles;
2672 /* Zero out return values to avoid leaking information on partial succes */
2673 memset(Sync, 0, sizeof(*Sync));
2675 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2676 goto Bad_InlineBulkStatus;
2679 tfid = Fids->AFSCBFids_val;
2680 for (i = 0; i < nfiles; i++, tfid++) {
2682 * Get volume/vnode for the fetched file; caller's rights to it
2686 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2687 &parentwhentargetnotdir, &client, READ_LOCK,
2688 &rights, &anyrights))) {
2689 tstatus = &OutStats->AFSBulkStats_val[i];
2691 if (thost->hostFlags & HERRORTRANS) {
2692 tstatus->errorCode = sys_error_to_et(errorCode);
2694 tstatus->errorCode = errorCode;
2697 PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2698 (Vnode *) 0, volptr, &client);
2699 parentwhentargetnotdir = (Vnode *) 0;
2700 targetptr = (Vnode *) 0;
2701 volptr = (Volume *) 0;
2702 client = (struct client *)0;
2706 rx_KeepAliveOn(acall);
2708 /* set volume synchronization information, but only once per call */
2710 SetVolumeSync(Sync, volptr);
2714 /* Are we allowed to fetch Fid's status? */
2715 if (targetptr->disk.type != vDirectory) {
2717 Check_PermissionRights(targetptr, client, rights,
2718 CHK_FETCHSTATUS, 0))) {
2719 tstatus = &OutStats->AFSBulkStats_val[i];
2721 if (thost->hostFlags & HERRORTRANS) {
2722 tstatus->errorCode = sys_error_to_et(errorCode);
2724 tstatus->errorCode = errorCode;
2727 (void)PutVolumePackage(acall, parentwhentargetnotdir,
2728 targetptr, (Vnode *) 0, volptr,
2730 parentwhentargetnotdir = (Vnode *) 0;
2731 targetptr = (Vnode *) 0;
2732 volptr = (Volume *) 0;
2733 client = (struct client *)0;
2738 /* set OutStatus From the Fid */
2739 GetStatus(targetptr,
2740 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2741 rights, anyrights, parentwhentargetnotdir);
2743 /* If a r/w volume, also set the CallBack state */
2744 if (VolumeWriteable(volptr))
2745 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2746 &CallBacks->AFSCBs_val[i]);
2748 struct AFSFid myFid;
2749 memset(&myFid, 0, sizeof(struct AFSFid));
2750 myFid.Volume = tfid->Volume;
2751 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2752 &CallBacks->AFSCBs_val[i]);
2755 /* put back the file ID and volume */
2756 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2757 (Vnode *) 0, volptr, &client);
2758 parentwhentargetnotdir = (Vnode *) 0;
2759 targetptr = (Vnode *) 0;
2760 volptr = (Volume *) 0;
2761 client = (struct client *)0;
2765 Bad_InlineBulkStatus:
2766 /* Update and store volume/vnode and parent vnodes back */
2767 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2768 (Vnode *) 0, volptr, &client);
2769 errorCode = CallPostamble(tcon, errorCode, thost);
2771 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2773 fsstats_FinishOp(&fsstats, errorCode);
2776 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2777 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2778 AUD_ID, t_client ? t_client->ViceId : 0,
2779 AUD_FIDS, Fids, AUD_END);
2782 } /*SRXAFS_InlineBulkStatus */
2786 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2787 struct AFSFetchStatus * OutStatus,
2788 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2791 struct rx_connection *tcon;
2793 struct client *t_client = NULL; /* tmp ptr to client data */
2794 struct fsstats fsstats;
2796 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2798 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2799 goto Bad_FetchStatus;
2801 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2804 code = CallPostamble(tcon, code, thost);
2806 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2808 fsstats_FinishOp(&fsstats, code);
2810 osi_auditU(acall, FetchStatusEvent, code,
2811 AUD_ID, t_client ? t_client->ViceId : 0,
2812 AUD_FID, Fid, AUD_END);
2815 } /*SRXAFS_FetchStatus */
2819 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2820 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2821 afs_fsize_t Length, afs_fsize_t FileLength,
2822 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2824 Vnode *targetptr = 0; /* pointer to input fid */
2825 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2826 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2827 Error errorCode = 0; /* return code for caller */
2828 Error fileCode = 0; /* return code from vol package */
2829 Volume *volptr = 0; /* pointer to the volume header */
2830 struct client *client = 0; /* pointer to client structure */
2831 afs_int32 rights, anyrights; /* rights for this and any user */
2832 struct client *t_client = NULL; /* tmp ptr to client data */
2833 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2834 struct rx_connection *tcon;
2836 struct fsstats fsstats;
2837 afs_sfsize_t bytesToXfer;
2838 afs_sfsize_t bytesXferred;
2839 static int remainder = 0;
2842 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2845 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2848 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2850 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2853 /* Get ptr to client data for user Id for logging */
2854 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2855 logHostAddr.s_addr = rxr_HostOf(tcon);
2857 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2858 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2859 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2862 * Get associated volume/vnode for the stored file; caller's rights
2866 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustNOTBeDIR,
2867 &parentwhentargetnotdir, &client, WRITE_LOCK,
2868 &rights, &anyrights))) {
2872 rx_KeepAliveOn(acall);
2874 /* set volume synchronization information */
2875 SetVolumeSync(Sync, volptr);
2877 if (targetptr->disk.type == vSymlink) {
2878 /* Should we return a better error code here??? */
2883 /* Check if we're allowed to store the data */
2885 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2891 * Drop the read lock on the parent directory after saving the parent
2892 * vnode information we need to pass to GetStatus
2894 if (parentwhentargetnotdir != NULL) {
2895 tparentwhentargetnotdir = *parentwhentargetnotdir;
2896 rx_KeepAliveOff(acall);
2897 VPutVnode(&fileCode, parentwhentargetnotdir);
2898 rx_KeepAliveOn(acall);
2899 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2900 parentwhentargetnotdir = NULL;
2903 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
2906 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2907 FileLength, (InStatus->Mask & AFS_FSYNC),
2908 &bytesToXfer, &bytesXferred);
2910 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2913 if (errorCode && (!targetptr->changed_newTime))
2916 rx_KeepAliveOff(acall);
2917 /* Update the status of the target's vnode */
2918 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2919 targetptr, volptr, 0, 0);
2920 rx_KeepAliveOn(acall);
2922 /* Get the updated File's status back to the caller */
2923 GetStatus(targetptr, OutStatus, rights, anyrights,
2924 &tparentwhentargetnotdir);
2927 /* Update and store volume/vnode and parent vnodes back */
2928 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2929 (Vnode *) 0, volptr, &client);
2930 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
2932 errorCode = CallPostamble(tcon, errorCode, thost);
2934 fsstats_FinishOp(&fsstats, errorCode);
2936 osi_auditU(acall, StoreDataEvent, errorCode,
2937 AUD_ID, t_client ? t_client->ViceId : 0,
2938 AUD_FID, Fid, AUD_END);
2940 } /*common_StoreData64 */
2943 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
2944 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
2945 afs_uint32 Length, afs_uint32 FileLength,
2946 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2948 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
2949 (0x7fffffff - Pos) < Length)
2952 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
2954 } /*SRXAFS_StoreData */
2957 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
2958 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
2959 afs_uint64 Length, afs_uint64 FileLength,
2960 struct AFSFetchStatus * OutStatus,
2961 struct AFSVolSync * Sync)
2965 afs_fsize_t tLength;
2966 afs_fsize_t tFileLength;
2968 tPos = (afs_fsize_t) Pos;
2969 tLength = (afs_fsize_t) Length;
2970 tFileLength = (afs_fsize_t) FileLength;
2973 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
2979 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
2980 struct AFSOpaque * AccessList,
2981 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2983 Vnode *targetptr = 0; /* pointer to input fid */
2984 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2985 Error errorCode = 0; /* return code for caller */
2986 struct AFSStoreStatus InStatus; /* Input status for fid */
2987 Volume *volptr = 0; /* pointer to the volume header */
2988 struct client *client = 0; /* pointer to client structure */
2989 afs_int32 rights, anyrights; /* rights for this and any user */
2990 struct rx_connection *tcon;
2992 struct client *t_client = NULL; /* tmp ptr to client data */
2993 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2994 struct fsstats fsstats;
2996 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
2998 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3001 /* Get ptr to client data for user Id for logging */
3002 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3003 logHostAddr.s_addr = rxr_HostOf(tcon);
3005 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3006 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3007 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3009 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3011 InStatus.Mask = 0; /* not storing any status */
3014 * Get associated volume/vnode for the target dir; caller's rights
3015 * are also returned.
3018 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustBeDIR,
3019 &parentwhentargetnotdir, &client, WRITE_LOCK,
3020 &rights, &anyrights))) {
3024 /* set volume synchronization information */
3025 SetVolumeSync(Sync, volptr);
3027 /* Check if we have permission to change the dir's ACL */
3029 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3034 /* Build and store the new Access List for the dir */
3035 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3039 targetptr->changed_newTime = 1; /* status change of directory */
3041 /* convert the write lock to a read lock before breaking callbacks */
3042 VVnodeWriteToRead(&errorCode, targetptr);
3043 osi_Assert(!errorCode || errorCode == VSALVAGE);
3045 rx_KeepAliveOn(acall);
3047 /* break call backs on the directory */
3048 BreakCallBack(client->host, Fid, 0);
3050 /* Get the updated dir's status back to the caller */
3051 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3054 /* Update and store volume/vnode and parent vnodes back */
3055 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3057 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3058 errorCode = CallPostamble(tcon, errorCode, thost);
3060 fsstats_FinishOp(&fsstats, errorCode);
3062 osi_auditU(acall, StoreACLEvent, errorCode,
3063 AUD_ID, t_client ? t_client->ViceId : 0,
3064 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3067 } /*SRXAFS_StoreACL */
3071 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3072 * should be merged when possible.
3075 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3076 struct AFSStoreStatus *InStatus,
3077 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3079 Vnode *targetptr = 0; /* pointer to input fid */
3080 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3081 Error errorCode = 0; /* return code for caller */
3082 Volume *volptr = 0; /* pointer to the volume header */
3083 struct client *client = 0; /* pointer to client structure */
3084 afs_int32 rights, anyrights; /* rights for this and any user */
3085 struct client *t_client = NULL; /* tmp ptr to client data */
3086 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3087 struct rx_connection *tcon = rx_ConnectionOf(acall);
3089 /* Get ptr to client data for user Id for logging */
3090 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3091 logHostAddr.s_addr = rxr_HostOf(tcon);
3093 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3094 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3095 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3097 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3100 * Get volume/vnode for the target file; caller's rights to it are
3104 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
3105 &parentwhentargetnotdir, &client, WRITE_LOCK,
3106 &rights, &anyrights))) {
3107 goto Bad_StoreStatus;
3110 /* set volume synchronization information */
3111 SetVolumeSync(Sync, volptr);
3113 /* Check if the caller has proper permissions to store status to Fid */
3115 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3117 goto Bad_StoreStatus;
3120 * Check for a symbolic link; we can't chmod these (otherwise could
3121 * change a symlink to a mt pt or vice versa)
3123 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3125 goto Bad_StoreStatus;
3128 /* Update the status of the target's vnode */
3129 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3130 (parentwhentargetnotdir ? parentwhentargetnotdir
3131 : targetptr), volptr, 0, 0);
3133 rx_KeepAliveOn(acall);
3135 /* convert the write lock to a read lock before breaking callbacks */
3136 VVnodeWriteToRead(&errorCode, targetptr);
3137 osi_Assert(!errorCode || errorCode == VSALVAGE);
3139 /* Break call backs on Fid */
3140 BreakCallBack(client->host, Fid, 0);
3142 /* Return the updated status back to caller */
3143 GetStatus(targetptr, OutStatus, rights, anyrights,
3144 parentwhentargetnotdir);
3147 /* Update and store volume/vnode and parent vnodes back */
3148 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3150 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3153 } /*SAFSS_StoreStatus */
3157 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3158 struct AFSStoreStatus * InStatus,
3159 struct AFSFetchStatus * OutStatus,
3160 struct AFSVolSync * Sync)
3163 struct rx_connection *tcon;
3165 struct client *t_client = NULL; /* tmp ptr to client data */
3166 struct fsstats fsstats;
3168 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3170 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3171 goto Bad_StoreStatus;
3173 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3176 code = CallPostamble(tcon, code, thost);
3178 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3180 fsstats_FinishOp(&fsstats, code);
3182 osi_auditU(acall, StoreStatusEvent, code,
3183 AUD_ID, t_client ? t_client->ViceId : 0,
3184 AUD_FID, Fid, AUD_END);
3187 } /*SRXAFS_StoreStatus */
3191 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3192 * merged in when possible.
3195 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3196 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3198 Vnode *parentptr = 0; /* vnode of input Directory */
3199 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3200 Vnode *targetptr = 0; /* file to be deleted */
3201 Volume *volptr = 0; /* pointer to the volume header */
3202 AFSFid fileFid; /* area for Fid from the directory */
3203 Error errorCode = 0; /* error code */
3204 DirHandle dir; /* Handle for dir package I/O */
3205 struct client *client = 0; /* pointer to client structure */
3206 afs_int32 rights, anyrights; /* rights for this and any user */
3207 struct client *t_client; /* tmp ptr to client data */
3208 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3209 struct rx_connection *tcon = rx_ConnectionOf(acall);
3212 /* Get ptr to client data for user Id for logging */
3213 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3214 logHostAddr.s_addr = rxr_HostOf(tcon);
3216 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3217 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3218 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3220 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3223 * Get volume/vnode for the parent dir; caller's access rights are
3227 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3228 &parentwhentargetnotdir, &client, WRITE_LOCK,
3229 &rights, &anyrights))) {
3230 goto Bad_RemoveFile;
3232 /* set volume synchronization information */
3233 SetVolumeSync(Sync, volptr);
3235 /* Does the caller has delete (& write) access to the parent directory? */
3236 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3237 goto Bad_RemoveFile;
3240 /* Actually delete the desired file */
3242 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3244 goto Bad_RemoveFile;
3247 /* Update the vnode status of the parent dir */
3248 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3249 parentptr->disk.linkCount,
3250 client->InSameNetwork);
3252 rx_KeepAliveOn(acall);
3254 /* Return the updated parent dir's status back to caller */
3255 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3257 /* Handle internal callback state for the parent and the deleted file */
3258 if (targetptr->disk.linkCount == 0) {
3259 /* no references left, discard entry */
3260 DeleteFileCallBacks(&fileFid);
3261 /* convert the parent lock to a read lock before breaking callbacks */
3262 VVnodeWriteToRead(&errorCode, parentptr);
3263 osi_Assert(!errorCode || errorCode == VSALVAGE);
3265 /* convert the parent lock to a read lock before breaking callbacks */
3266 VVnodeWriteToRead(&errorCode, parentptr);
3267 osi_Assert(!errorCode || errorCode == VSALVAGE);
3268 /* convert the target lock to a read lock before breaking callbacks */
3269 VVnodeWriteToRead(&errorCode, targetptr);
3270 osi_Assert(!errorCode || errorCode == VSALVAGE);
3271 /* tell all the file has changed */
3272 BreakCallBack(client->host, &fileFid, 1);
3275 /* break call back on the directory */
3276 BreakCallBack(client->host, DirFid, 0);
3279 /* Update and store volume/vnode and parent vnodes back */
3280 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3283 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3286 } /*SAFSS_RemoveFile */
3290 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3291 struct AFSFetchStatus * OutDirStatus,
3292 struct AFSVolSync * Sync)
3295 struct rx_connection *tcon;
3297 struct client *t_client = NULL; /* tmp ptr to client data */
3298 struct fsstats fsstats;
3300 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3302 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3303 goto Bad_RemoveFile;
3305 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3308 code = CallPostamble(tcon, code, thost);
3310 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3312 fsstats_FinishOp(&fsstats, code);
3314 osi_auditU(acall, RemoveFileEvent, code,
3315 AUD_ID, t_client ? t_client->ViceId : 0,
3316 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3319 } /*SRXAFS_RemoveFile */
3323 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3324 * be merged in when possible.
3327 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3328 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3329 struct AFSFetchStatus *OutFidStatus,
3330 struct AFSFetchStatus *OutDirStatus,
3331 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3333 Vnode *parentptr = 0; /* vnode of input Directory */
3334 Vnode *targetptr = 0; /* vnode of the new file */
3335 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3336 Volume *volptr = 0; /* pointer to the volume header */
3337 Error errorCode = 0; /* error code */
3338 DirHandle dir; /* Handle for dir package I/O */
3339 struct client *client = 0; /* pointer to client structure */
3340 afs_int32 rights, anyrights; /* rights for this and any user */
3341 struct client *t_client; /* tmp ptr to client data */
3342 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3343 struct rx_connection *tcon = rx_ConnectionOf(acall);
3347 /* Get ptr to client data for user Id for logging */
3348 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3349 logHostAddr.s_addr = rxr_HostOf(tcon);
3351 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3352 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3353 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3355 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3357 if (!FileNameOK(Name)) {
3359 goto Bad_CreateFile;
3363 * Get associated volume/vnode for the parent dir; caller long are
3367 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3368 &parentwhentargetnotdir, &client, WRITE_LOCK,
3369 &rights, &anyrights))) {
3370 goto Bad_CreateFile;
3373 /* set volume synchronization information */
3374 SetVolumeSync(Sync, volptr);
3376 /* Can we write (and insert) onto the parent directory? */
3377 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3378 goto Bad_CreateFile;
3381 /* get a new vnode for the file to be created and set it up */
3383 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3384 vFile, nBlocks(0))))
3385 goto Bad_CreateFile;
3387 /* update the status of the parent vnode */
3388 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3389 parentptr->disk.linkCount,
3390 client->InSameNetwork);
3392 /* update the status of the new file's vnode */
3393 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3394 parentptr, volptr, 0, 0);
3396 rx_KeepAliveOn(acall);
3398 /* set up the return status for the parent dir and the newly created file, and since the newly created file is owned by the creator, give it PRSFS_ADMINISTER to tell the client its the owner of the file */
3399 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3400 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3402 /* convert the write lock to a read lock before breaking callbacks */
3403 VVnodeWriteToRead(&errorCode, parentptr);
3404 osi_Assert(!errorCode || errorCode == VSALVAGE);
3406 /* break call back on parent dir */
3407 BreakCallBack(client->host, DirFid, 0);
3409 /* Return a callback promise for the newly created file to the caller */
3410 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3413 /* Update and store volume/vnode and parent vnodes back */
3414 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3417 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3420 } /*SAFSS_CreateFile */
3424 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3425 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3426 struct AFSFetchStatus * OutFidStatus,
3427 struct AFSFetchStatus * OutDirStatus,
3428 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3431 struct rx_connection *tcon;
3433 struct client *t_client = NULL; /* tmp ptr to client data */
3434 struct fsstats fsstats;
3436 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CREATEFILE);
3438 memset(OutFid, 0, sizeof(struct AFSFid));
3440 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3441 goto Bad_CreateFile;
3444 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3445 OutDirStatus, CallBack, Sync);
3448 code = CallPostamble(tcon, code, thost);
3450 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3452 fsstats_FinishOp(&fsstats, code);
3454 osi_auditU(acall, CreateFileEvent, code,
3455 AUD_ID, t_client ? t_client->ViceId : 0,
3456 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3459 } /*SRXAFS_CreateFile */
3463 * This routine is called exclusively from SRXAFS_Rename(), and should be
3464 * merged in when possible.
3467 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3468 struct AFSFid *NewDirFid, char *NewName,
3469 struct AFSFetchStatus *OutOldDirStatus,
3470 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3472 Vnode *oldvptr = 0; /* vnode of the old Directory */
3473 Vnode *newvptr = 0; /* vnode of the new Directory */
3474 Vnode *fileptr = 0; /* vnode of the file to move */
3475 Vnode *newfileptr = 0; /* vnode of the file to delete */
3476 Vnode *testvptr = 0; /* used in directory tree walk */
3477 Vnode *parent = 0; /* parent for use in SetAccessList */
3478 Error errorCode = 0; /* error code */
3479 Error fileCode = 0; /* used when writing Vnodes */
3480 VnodeId testnode; /* used in directory tree walk */
3481 AFSFid fileFid; /* Fid of file to move */
3482 AFSFid newFileFid; /* Fid of new file */
3483 DirHandle olddir; /* Handle for dir package I/O */
3484 DirHandle newdir; /* Handle for dir package I/O */
3485 DirHandle filedir; /* Handle for dir package I/O */
3486 DirHandle newfiledir; /* Handle for dir package I/O */
3487 Volume *volptr = 0; /* pointer to the volume header */
3488 struct client *client = 0; /* pointer to client structure */
3489 afs_int32 rights, anyrights; /* rights for this and any user */
3490 afs_int32 newrights; /* rights for this user */
3491 afs_int32 newanyrights; /* rights for any user */
3492 int doDelete; /* deleted the rename target (ref count now 0) */
3494 int updatefile = 0; /* are we changing the renamed file? (we do this
3495 * if we need to update .. on a renamed dir) */
3496 struct client *t_client; /* tmp ptr to client data */
3497 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3498 struct rx_connection *tcon = rx_ConnectionOf(acall);
3504 FidZero(&newfiledir);
3506 /* Get ptr to client data for user Id for logging */
3507 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3508 logHostAddr.s_addr = rxr_HostOf(tcon);
3510 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3511 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3512 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3513 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3515 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3517 if (!FileNameOK(NewName)) {
3521 if (OldDirFid->Volume != NewDirFid->Volume) {
3526 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3527 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3528 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3534 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3536 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3537 &parent, &client, WRITE_LOCK, &rights,
3542 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3544 newrights = rights, newanyrights = anyrights;
3547 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr,
3548 MustBeDIR, &parent, &client, WRITE_LOCK,
3549 &newrights, &newanyrights))) {
3555 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr, MustBeDIR,
3556 &parent, &client, WRITE_LOCK, &newrights,
3562 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3563 &parent, &client, WRITE_LOCK, &rights,
3570 /* set volume synchronization information */
3571 SetVolumeSync(Sync, volptr);
3573 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3576 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3580 if (CheckLength(volptr, oldvptr, -1) ||
3581 CheckLength(volptr, newvptr, -1)) {
3582 VTakeOffline(volptr);
3583 errorCode = VSALVAGE;
3587 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3588 * call to CopyOnWrite returns error, it is not necessary to revert back
3589 * the effects of the first call because the contents of the volume is
3590 * not modified, it is only replicated.
3592 if (oldvptr->disk.cloned) {
3593 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3594 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3597 SetDirHandle(&olddir, oldvptr);
3598 if (newvptr->disk.cloned) {
3599 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3600 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3604 SetDirHandle(&newdir, newvptr);
3606 /* Lookup the file to delete its vnode */
3607 if (afs_dir_Lookup(&olddir, OldName, &fileFid)) {
3611 if (fileFid.Vnode == oldvptr->vnodeNumber
3612 || fileFid.Vnode == newvptr->vnodeNumber) {
3613 errorCode = FSERR_ELOOP;
3616 fileFid.Volume = V_id(volptr);
3617 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3618 if (errorCode != 0) {
3620 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3621 OldName, errorCode));
3622 VTakeOffline(volptr);
3625 if (fileptr->disk.uniquifier != fileFid.Unique) {
3627 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3629 VTakeOffline(volptr);
3634 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3635 && fileptr->disk.linkCount != 1) {
3637 * Hard links exist to this file - cannot move one of the links to
3638 * a new directory because of AFS restrictions (this is the same
3639 * reason that links cannot be made across directories, i.e.
3646 /* Lookup the new file */
3647 if (!(afs_dir_Lookup(&newdir, NewName, &newFileFid))) {
3648 if (readonlyServer) {
3649 errorCode = VREADONLY;
3652 if (!(newrights & PRSFS_DELETE)) {
3656 if (newFileFid.Vnode == oldvptr->vnodeNumber
3657 || newFileFid.Vnode == newvptr->vnodeNumber
3658 || newFileFid.Vnode == fileFid.Vnode) {
3662 newFileFid.Volume = V_id(volptr);
3664 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3665 if (errorCode != 0) {
3667 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3668 NewName, errorCode));
3669 VTakeOffline(volptr);
3672 if (fileptr->disk.uniquifier != fileFid.Unique) {
3674 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3676 VTakeOffline(volptr);
3680 SetDirHandle(&newfiledir, newfileptr);
3681 /* Now check that we're moving directories over directories properly, etc.
3682 * return proper POSIX error codes:
3683 * if fileptr is a file and new is a dir: EISDIR.
3684 * if fileptr is a dir and new is a file: ENOTDIR.
3685 * Also, dir to be removed must be empty, of course.
3687 if (newfileptr->disk.type == vDirectory) {
3688 if (fileptr->disk.type != vDirectory) {
3692 if ((afs_dir_IsEmpty(&newfiledir))) {
3697 if (fileptr->disk.type == vDirectory) {
3698 errorCode = ENOTDIR;
3705 * ok - now we check that the old name is not above new name in the
3706 * directory structure. This is to prevent removing a subtree alltogether
3708 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3709 afs_int32 forpass = 0, vnum = 0, top = 0;
3710 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3711 if (testnode > vnum) vnum = testnode;
3712 if (forpass > vnum) {
3713 errorCode = FSERR_ELOOP;
3716 if (testnode == oldvptr->vnodeNumber) {
3717 testnode = oldvptr->disk.parent;
3720 if ((testnode == fileptr->vnodeNumber)
3721 || (testnode == newvptr->vnodeNumber)) {
3722 errorCode = FSERR_ELOOP;
3725 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3726 errorCode = FSERR_ELOOP;
3729 if (testnode == 1) top = 1;
3730 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3731 osi_Assert(errorCode == 0);
3732 testnode = testvptr->disk.parent;
3733 VPutVnode(&errorCode, testvptr);
3734 if ((top == 1) && (testnode != 0)) {
3735 VTakeOffline(volptr);
3737 ("Volume %u now offline, must be salvaged.\n",
3742 osi_Assert(errorCode == 0);
3746 if (fileptr->disk.type == vDirectory) {
3747 SetDirHandle(&filedir, fileptr);
3748 if (oldvptr != newvptr) {
3749 /* we always need to update .. if we've moving fileptr to a
3750 * different directory */
3753 struct AFSFid unused;
3755 code = afs_dir_Lookup(&filedir, "..", &unused);
3756 if (code == ENOENT) {
3757 /* only update .. if it doesn't already exist */
3763 /* Do the CopyonWrite first before modifying anything else. Copying is
3764 * required when we have to change entries for ..
3766 if (updatefile && (fileptr->disk.cloned)) {
3767 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3768 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
3770 /* since copyonwrite would mean fileptr has a new handle, do it here */
3772 SetDirHandle(&filedir, fileptr);
3775 /* If the new name exists already, delete it and the file it points to */
3778 /* Delete NewName from its directory */
3779 code = afs_dir_Delete(&newdir, NewName);
3780 osi_Assert(code == 0);
3782 /* Drop the link count */
3783 newfileptr->disk.linkCount--;
3784 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
3785 afs_fsize_t newSize;
3786 VN_GET_LEN(newSize, newfileptr);
3787 VAdjustDiskUsage((Error *) & errorCode, volptr,
3788 (afs_sfsize_t) - nBlocks(newSize), 0);
3789 if (VN_GET_INO(newfileptr)) {
3790 IH_REALLYCLOSE(newfileptr->handle);
3792 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
3793 V_parentId(volptr));
3794 IH_RELEASE(newfileptr->handle);
3795 if (errorCode == -1) {
3797 ("Del: inode=%s, name=%s, errno=%d\n",
3798 PrintInode(stmp, VN_GET_INO(newfileptr)),
3800 if ((errno != ENOENT) && (errno != EIO)
3801 && (errno != ENXIO))
3802 ViceLog(0, ("Do we need to fsck?"));
3805 VN_SET_INO(newfileptr, (Inode) 0);
3806 newfileptr->delete = 1; /* Mark NewName vnode to delete */
3809 /* Link count did not drop to zero.
3810 * Mark NewName vnode as changed - updates stime.
3812 newfileptr->changed_newTime = 1;
3817 * If the create below fails, and the delete above worked, we have
3818 * removed the new name and not replaced it. This is not very likely,
3819 * but possible. We could try to put the old file back, but it is
3820 * highly unlikely that it would work since it would involve issuing
3823 if ((errorCode = afs_dir_Create(&newdir, NewName, &fileFid)))
3826 /* Delete the old name */
3827 osi_Assert(afs_dir_Delete(&olddir, OldName) == 0);
3829 /* if the directory length changes, reflect it in the statistics */
3830 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
3831 oldvptr->disk.linkCount, client->InSameNetwork);
3832 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
3833 newvptr->disk.linkCount, client->InSameNetwork);
3835 if (oldvptr == newvptr)
3836 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
3838 if (fileptr->disk.parent != newvptr->vnodeNumber) {
3839 fileptr->disk.parent = newvptr->vnodeNumber;
3840 fileptr->changed_newTime = 1;
3843 /* if we are dealing with a rename of a directory, and we need to
3844 * update the .. entry of that directory */
3846 osi_Assert(!fileptr->disk.cloned);
3848 fileptr->changed_newTime = 1; /* status change of moved file */
3850 /* fix .. to point to the correct place */
3851 afs_dir_Delete(&filedir, ".."); /* No assert--some directories may be bad */
3852 osi_Assert(afs_dir_Create(&filedir, "..", NewDirFid) == 0);
3853 fileptr->disk.dataVersion++;
3855 /* if the parent directories are different the link counts have to be */
3856 /* changed due to .. in the renamed directory */
3857 if (oldvptr != newvptr) {
3858 oldvptr->disk.linkCount--;
3859 newvptr->disk.linkCount++;
3863 /* set up return status */
3864 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
3865 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
3866 if (newfileptr && doDelete) {
3867 DeleteFileCallBacks(&newFileFid); /* no other references */
3872 /* convert the write locks to a read locks before breaking callbacks */
3873 VVnodeWriteToRead(&errorCode, newvptr);
3874 osi_Assert(!errorCode || errorCode == VSALVAGE);
3875 if (oldvptr != newvptr) {
3876 VVnodeWriteToRead(&errorCode, oldvptr);
3877 osi_Assert(!errorCode || errorCode == VSALVAGE);
3879 if (newfileptr && !doDelete) {
3880 /* convert the write lock to a read lock before breaking callbacks */
3881 VVnodeWriteToRead(&errorCode, newfileptr);
3882 osi_Assert(!errorCode || errorCode == VSALVAGE);
3885 rx_KeepAliveOn(acall);
3887 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
3888 BreakCallBack(client->host, NewDirFid, 0);
3889 if (oldvptr != newvptr) {
3890 BreakCallBack(client->host, OldDirFid, 0);
3893 /* if a dir moved, .. changed */
3894 /* we do not give an AFSFetchStatus structure back to the
3895 * originating client, and the file's status has changed, so be
3896 * sure to send a callback break. In theory the client knows
3897 * enough to know that the callback could be broken implicitly,
3898 * but that may not be clear, and some client implementations
3899 * may not know to. */
3900 BreakCallBack(client->host, &fileFid, 1);
3903 /* Note: it is not necessary to break the callback */
3905 DeleteFileCallBacks(&newFileFid); /* no other references */
3907 /* other's still exist (with wrong link count) */
3908 BreakCallBack(client->host, &newFileFid, 1);
3913 rx_KeepAliveOff(acall);
3914 VPutVnode(&fileCode, newfileptr);
3915 osi_Assert(fileCode == 0);
3917 (void)PutVolumePackage(acall, fileptr, (newvptr && newvptr != oldvptr ?
3918 newvptr : 0), oldvptr, volptr, &client);
3922 FidZap(&newfiledir);
3923 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
3930 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
3931 char *OldName, struct AFSFid * NewDirFid, char *NewName,
3932 struct AFSFetchStatus * OutOldDirStatus,
3933 struct AFSFetchStatus * OutNewDirStatus,
3934 struct AFSVolSync * Sync)
3937 struct rx_connection *tcon;
3939 struct client *t_client = NULL; /* tmp ptr to client data */
3940 struct fsstats fsstats;
3942 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RENAME);
3944 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3948 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
3949 OutOldDirStatus, OutNewDirStatus, Sync);
3952 code = CallPostamble(tcon, code, thost);
3954 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3956 fsstats_FinishOp(&fsstats, code);
3958 osi_auditU(acall, RenameFileEvent, code,
3959 AUD_ID, t_client ? t_client->ViceId : 0,
3960 AUD_FID, OldDirFid, AUD_STR, OldName,
3961 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
3964 } /*SRXAFS_Rename */
3968 * This routine is called exclusively by SRXAFS_Symlink(), and should be
3969 * merged into it when possible.
3972 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3973 char *LinkContents, struct AFSStoreStatus *InStatus,
3974 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
3975 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3977 Vnode *parentptr = 0; /* vnode of input Directory */
3978 Vnode *targetptr = 0; /* vnode of the new link */
3979 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3980 Error errorCode = 0; /* error code */
3983 DirHandle dir; /* Handle for dir package I/O */
3984 Volume *volptr = 0; /* pointer to the volume header */
3985 struct client *client = 0; /* pointer to client structure */
3986 afs_int32 rights, anyrights; /* rights for this and any user */
3987 struct client *t_client; /* tmp ptr to client data */
3988 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3990 struct rx_connection *tcon = rx_ConnectionOf(acall);
3994 /* Get ptr to client data for user Id for logging */
3995 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3996 logHostAddr.s_addr = rxr_HostOf(tcon);
3998 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3999 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4000 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4002 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4004 if (!FileNameOK(Name)) {
4010 * Get the vnode and volume for the parent dir along with the caller's
4014 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4015 &parentwhentargetnotdir, &client, WRITE_LOCK,
4016 &rights, &anyrights)))
4019 /* set volume synchronization information */
4020 SetVolumeSync(Sync, volptr);
4022 /* Does the caller has insert (and write) access to the parent directory? */
4023 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)))
4027 * If we're creating a mount point (any x bits clear), we must have
4028 * administer access to the directory, too. Always allow sysadmins
4031 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4032 if (readonlyServer) {
4033 errorCode = VREADONLY;
4037 * We have a mountpoint, 'cause we're trying to set the Unix mode
4038 * bits to something with some x bits missing (default mode bits
4039 * if AFS_SETMODE is false is 0777)
4041 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4047 /* get a new vnode for the symlink and set it up */
4049 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4050 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4054 /* update the status of the parent vnode */
4055 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4056 parentptr->disk.linkCount,
4057 client->InSameNetwork);
4059 /* update the status of the new symbolic link file vnode */
4060 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4061 parentptr, volptr, strlen((char *)LinkContents), 0);
4063 /* Write the contents of the symbolic link name into the target inode */
4064 fdP = IH_OPEN(targetptr->handle);
4066 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4067 parentptr, volptr, &client);
4068 VTakeOffline(volptr);
4069 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4073 len = strlen((char *) LinkContents);
4074 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4076 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4079 * Set up and return modified status for the parent dir and new symlink
4082 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4083 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4085 /* convert the write lock to a read lock before breaking callbacks */
4086 VVnodeWriteToRead(&errorCode, parentptr);
4087 osi_Assert(!errorCode || errorCode == VSALVAGE);
4089 rx_KeepAliveOn(acall);
4091 /* break call back on the parent dir */
4092 BreakCallBack(client->host, DirFid, 0);
4095 /* Write the all modified vnodes (parent, new files) and volume back */
4096 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4099 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4100 return ( errorCode ? errorCode : code );
4102 } /*SAFSS_Symlink */
4106 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4107 struct AFSFid *DirFid, /* Parent dir's fid */
4108 char *Name, /* File name to create */
4109 char *LinkContents, /* Contents of the new created file */
4110 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4111 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4112 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4113 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4114 struct AFSVolSync *Sync)
4117 struct rx_connection *tcon;
4119 struct client *t_client = NULL; /* tmp ptr to client data */
4120 struct fsstats fsstats;
4122 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SYMLINK);
4124 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4128 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4129 OutFidStatus, OutDirStatus, Sync);
4132 code = CallPostamble(tcon, code, thost);
4134 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4136 fsstats_FinishOp(&fsstats, code);
4138 osi_auditU(acall, SymlinkEvent, code,
4139 AUD_ID, t_client ? t_client->ViceId : 0,
4140 AUD_FID, DirFid, AUD_STR, Name,
4141 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4144 } /*SRXAFS_Symlink */
4148 * This routine is called exclusively by SRXAFS_Link(), and should be
4149 * merged into it when possible.
4152 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4153 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4154 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4156 Vnode *parentptr = 0; /* vnode of input Directory */
4157 Vnode *targetptr = 0; /* vnode of the new file */
4158 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4159 Volume *volptr = 0; /* pointer to the volume header */
4160 Error errorCode = 0; /* error code */
4161 DirHandle dir; /* Handle for dir package I/O */
4162 struct client *client = 0; /* pointer to client structure */
4163 afs_int32 rights, anyrights; /* rights for this and any user */
4164 struct client *t_client; /* tmp ptr to client data */
4165 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4166 struct rx_connection *tcon = rx_ConnectionOf(acall);
4170 /* Get ptr to client data for user Id for logging */
4171 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4172 logHostAddr.s_addr = rxr_HostOf(tcon);
4174 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4175 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4176 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4177 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4179 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4181 if (DirFid->Volume != ExistingFid->Volume) {
4185 if (!FileNameOK(Name)) {
4191 * Get the vnode and volume for the parent dir along with the caller's
4195 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4196 &parentwhentargetnotdir, &client, WRITE_LOCK,
4197 &rights, &anyrights))) {
4201 /* set volume synchronization information */
4202 SetVolumeSync(Sync, volptr);
4204 /* Can the caller insert into the parent directory? */
4205 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4209 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4210 /* AFS fileservers always have directory vnodes that are odd. */
4215 if (CheckLength(volptr, parentptr, -1)) {
4216 VTakeOffline(volptr);
4217 errorCode = VSALVAGE;
4221 /* get the file vnode */
4223 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4227 if (targetptr->disk.type != vFile) {
4231 if (targetptr->disk.parent != DirFid->Vnode) {
4235 if (parentptr->disk.cloned) {
4236 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4237 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4238 goto Bad_Link; /* disk full error */
4241 /* add the name to the directory */
4242 SetDirHandle(&dir, parentptr);
4243 if ((errorCode = afs_dir_Create(&dir, Name, ExistingFid)))
4247 /* update the status in the parent vnode */
4248 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4249 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4250 parentptr->disk.linkCount,
4251 client->InSameNetwork);
4253 targetptr->disk.linkCount++;
4254 targetptr->disk.author = client->ViceId;
4255 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4257 /* set up return status */
4258 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4259 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4261 /* convert the write locks to read locks before breaking callbacks */
4262 VVnodeWriteToRead(&errorCode, targetptr);
4263 osi_Assert(!errorCode || errorCode == VSALVAGE);
4264 VVnodeWriteToRead(&errorCode, parentptr);
4265 osi_Assert(!errorCode || errorCode == VSALVAGE);
4267 rx_KeepAliveOn(acall);
4269 /* break call back on DirFid */
4270 BreakCallBack(client->host, DirFid, 0);
4272 * We also need to break the callback for the file that is hard-linked since part
4273 * of its status (like linkcount) is changed
4275 BreakCallBack(client->host, ExistingFid, 0);
4278 /* Write the all modified vnodes (parent, new files) and volume back */
4279 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4282 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4289 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4290 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4291 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4294 struct rx_connection *tcon;
4296 struct client *t_client = NULL; /* tmp ptr to client data */
4297 struct fsstats fsstats;
4299 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_LINK);
4301 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4305 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4306 OutDirStatus, Sync);
4309 code = CallPostamble(tcon, code, thost);
4311 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4313 fsstats_FinishOp(&fsstats, code);
4315 osi_auditU(acall, LinkEvent, code,
4316 AUD_ID, t_client ? t_client->ViceId : 0,
4317 AUD_FID, DirFid, AUD_STR, Name,
4318 AUD_FID, ExistingFid, AUD_END);
4325 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4326 * merged into it when possible.
4329 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4330 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4331 struct AFSFetchStatus *OutFidStatus,
4332 struct AFSFetchStatus *OutDirStatus,
4333 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4335 Vnode *parentptr = 0; /* vnode of input Directory */
4336 Vnode *targetptr = 0; /* vnode of the new file */
4337 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4338 Volume *volptr = 0; /* pointer to the volume header */
4339 Error errorCode = 0; /* error code */
4340 struct acl_accessList *newACL; /* Access list */
4341 int newACLSize; /* Size of access list */
4342 DirHandle dir; /* Handle for dir package I/O */
4343 DirHandle parentdir; /* Handle for dir package I/O */
4344 struct client *client = 0; /* pointer to client structure */
4345 afs_int32 rights, anyrights; /* rights for this and any user */
4346 struct client *t_client; /* tmp ptr to client data */
4347 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4348 struct rx_connection *tcon = rx_ConnectionOf(acall);
4351 FidZero(&parentdir);
4353 /* Get ptr to client data for user Id for logging */
4354 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4355 logHostAddr.s_addr = rxr_HostOf(tcon);
4357 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4358 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4359 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4361 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4363 if (!FileNameOK(Name)) {
4369 * Get the vnode and volume for the parent dir along with the caller's
4373 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4374 &parentwhentargetnotdir, &client, WRITE_LOCK,
4375 &rights, &anyrights))) {
4379 /* set volume synchronization information */
4380 SetVolumeSync(Sync, volptr);
4382 /* Write access to the parent directory? */
4383 #ifdef DIRCREATE_NEED_WRITE
4385 * requires w access for the user to create a directory. this
4386 * closes a loophole in the current security arrangement, since a
4387 * user with i access only can create a directory and get the
4388 * implcit a access that goes with dir ownership, and proceed to
4389 * subvert quota in the volume.
4391 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4392 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4394 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4395 #endif /* DIRCREATE_NEED_WRITE */
4398 #define EMPTYDIRBLOCKS 2
4399 /* get a new vnode and set it up */
4401 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4402 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4406 /* Update the status for the parent dir */
4407 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4408 parentptr->disk.linkCount + 1,
4409 client->InSameNetwork);
4411 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4412 osi_Assert((SetAccessList
4413 (&targetptr, &volptr, &newACL, &newACLSize,
4414 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4415 osi_Assert(parentwhentargetnotdir == 0);
4416 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4418 /* update the status for the target vnode */
4419 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4420 parentptr, volptr, 0, 0);
4422 /* Actually create the New directory in the directory package */
4423 SetDirHandle(&dir, targetptr);
4424 osi_Assert(!(afs_dir_MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4426 VN_SET_LEN(targetptr, (afs_fsize_t) afs_dir_Length(&dir));
4428 /* set up return status */
4429 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4430 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4432 /* convert the write lock to a read lock before breaking callbacks */
4433 VVnodeWriteToRead(&errorCode, parentptr);
4434 osi_Assert(!errorCode || errorCode == VSALVAGE);
4436 rx_KeepAliveOn(acall);
4438 /* break call back on DirFid */
4439 BreakCallBack(client->host, DirFid, 0);
4441 /* Return a callback promise to caller */
4442 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4445 /* Write the all modified vnodes (parent, new files) and volume back */
4446 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4450 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4453 } /*SAFSS_MakeDir */
4457 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4458 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4459 struct AFSFetchStatus * OutFidStatus,
4460 struct AFSFetchStatus * OutDirStatus,
4461 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4464 struct rx_connection *tcon;
4466 struct client *t_client = NULL; /* tmp ptr to client data */
4467 struct fsstats fsstats;
4469 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_MAKEDIR);
4471 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4475 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4476 OutDirStatus, CallBack, Sync);
4479 code = CallPostamble(tcon, code, thost);
4481 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4483 fsstats_FinishOp(&fsstats, code);
4485 osi_auditU(acall, MakeDirEvent, code,
4486 AUD_ID, t_client ? t_client->ViceId : 0,
4487 AUD_FID, DirFid, AUD_STR, Name,
4488 AUD_FID, OutFid, AUD_END);
4491 } /*SRXAFS_MakeDir */
4495 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4496 * merged into it when possible.
4499 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4500 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4502 Vnode *parentptr = 0; /* vnode of input Directory */
4503 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4504 Vnode *targetptr = 0; /* file to be deleted */
4505 AFSFid fileFid; /* area for Fid from the directory */
4506 Error errorCode = 0; /* error code */
4507 DirHandle dir; /* Handle for dir package I/O */
4508 Volume *volptr = 0; /* pointer to the volume header */
4509 struct client *client = 0; /* pointer to client structure */
4510 afs_int32 rights, anyrights; /* rights for this and any user */
4511 struct client *t_client; /* tmp ptr to client data */
4512 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4513 struct rx_connection *tcon = rx_ConnectionOf(acall);
4517 /* Get ptr to client data for user Id for logging */
4518 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4519 logHostAddr.s_addr = rxr_HostOf(tcon);
4521 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4522 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4523 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4525 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4528 * Get the vnode and volume for the parent dir along with the caller's
4532 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4533 &parentwhentargetnotdir, &client, WRITE_LOCK,
4534 &rights, &anyrights))) {
4538 /* set volume synchronization information */
4539 SetVolumeSync(Sync, volptr);
4541 /* Does the caller has delete (&write) access to the parent dir? */
4542 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4546 /* Do the actual delete of the desired (empty) directory, Name */
4548 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4553 /* Update the status for the parent dir; link count is also adjusted */
4554 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4555 parentptr->disk.linkCount - 1,
4556 client->InSameNetwork);
4558 /* Return to the caller the updated parent dir status */
4559 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4562 * Note: it is not necessary to break the callback on fileFid, since
4563 * refcount is now 0, so no one should be able to refer to the dir
4566 DeleteFileCallBacks(&fileFid);
4568 /* convert the write lock to a read lock before breaking callbacks */
4569 VVnodeWriteToRead(&errorCode, parentptr);
4570 osi_Assert(!errorCode || errorCode == VSALVAGE);
4572 rx_KeepAliveOn(acall);
4574 /* break call back on DirFid and fileFid */
4575 BreakCallBack(client->host, DirFid, 0);
4578 /* Write the all modified vnodes (parent, new files) and volume back */
4579 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4582 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4585 } /*SAFSS_RemoveDir */
4589 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4590 struct AFSFetchStatus * OutDirStatus,
4591 struct AFSVolSync * Sync)
4594 struct rx_connection *tcon;
4596 struct client *t_client = NULL; /* tmp ptr to client data */
4597 struct fsstats fsstats;
4599 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEDIR);
4601 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4604 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4607 code = CallPostamble(tcon, code, thost);
4609 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4611 fsstats_FinishOp(&fsstats, code);
4613 osi_auditU(acall, RemoveDirEvent, code,
4614 AUD_ID, t_client ? t_client->ViceId : 0,
4615 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4618 } /*SRXAFS_RemoveDir */
4622 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4623 * merged into it when possible.
4626 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4627 struct AFSVolSync *Sync)
4629 Vnode *targetptr = 0; /* vnode of input file */
4630 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4631 Error errorCode = 0; /* error code */
4632 Volume *volptr = 0; /* pointer to the volume header */
4633 struct client *client = 0; /* pointer to client structure */
4634 afs_int32 rights, anyrights; /* rights for this and any user */
4635 struct client *t_client; /* tmp ptr to client data */
4636 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4637 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
4638 struct rx_connection *tcon = rx_ConnectionOf(acall);
4640 if (type != LockRead && type != LockWrite) {
4644 /* Get ptr to client data for user Id for logging */
4645 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4646 logHostAddr.s_addr = rxr_HostOf(tcon);
4648 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4649 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4650 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4652 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4655 * Get the vnode and volume for the desired file along with the caller's
4659 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4660 &parentwhentargetnotdir, &client, WRITE_LOCK,
4661 &rights, &anyrights))) {
4665 /* set volume synchronization information */
4666 SetVolumeSync(Sync, volptr);
4668 /* Handle the particular type of set locking, type */
4669 errorCode = HandleLocking(targetptr, client, rights, type);
4672 /* Write the all modified vnodes (parent, new files) and volume back */
4673 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4674 (Vnode *) 0, volptr, &client);
4676 if ((errorCode == VREADONLY) && (type == LockRead))
4677 errorCode = 0; /* allow read locks on RO volumes without saving state */
4679 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
4682 } /*SAFSS_SetLock */
4686 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
4687 ViceLockType type, struct AFSVolSync * Sync)
4689 return SRXAFS_SetLock(acall, Fid, type, Sync);
4690 } /*SRXAFS_OldSetLock */
4694 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
4695 struct AFSVolSync * Sync)
4698 struct rx_connection *tcon;
4700 struct client *t_client = NULL; /* tmp ptr to client data */
4701 struct fsstats fsstats;
4703 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETLOCK);
4705 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4708 code = SAFSS_SetLock(acall, Fid, type, Sync);
4711 code = CallPostamble(tcon, code, thost);
4713 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4715 fsstats_FinishOp(&fsstats, code);
4717 osi_auditU(acall, SetLockEvent, code,
4718 AUD_ID, t_client ? t_client->ViceId : 0,
4719 AUD_FID, Fid, AUD_LONG, type, AUD_END);
4721 } /*SRXAFS_SetLock */
4725 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
4726 * merged into it when possible.
4729 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
4730 struct AFSVolSync *Sync)
4732 Vnode *targetptr = 0; /* vnode of input file */
4733 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4734 Error errorCode = 0; /* error code */
4735 Volume *volptr = 0; /* pointer to the volume header */
4736 struct client *client = 0; /* pointer to client structure */
4737 afs_int32 rights, anyrights; /* rights for this and any user */
4738 struct client *t_client; /* tmp ptr to client data */
4739 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4740 struct rx_connection *tcon = rx_ConnectionOf(acall);
4742 /* Get ptr to client data for user Id for logging */
4743 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4744 logHostAddr.s_addr = rxr_HostOf(tcon);
4746 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4747 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4748 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4750 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
4753 * Get the vnode and volume for the desired file along with the caller's
4757 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4758 &parentwhentargetnotdir, &client, WRITE_LOCK,
4759 &rights, &anyrights))) {
4760 goto Bad_ExtendLock;
4763 /* set volume synchronization information */
4764 SetVolumeSync(Sync, volptr);
4766 /* Handle the actual lock extension */
4767 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
4770 /* Put back file's vnode and volume */
4771 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4772 (Vnode *) 0, volptr, &client);
4774 if (errorCode == VREADONLY) /* presumably, we already granted this lock */
4775 errorCode = 0; /* under our generous policy re RO vols */
4777 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
4780 } /*SAFSS_ExtendLock */
4784 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4785 struct AFSVolSync * Sync)
4787 return SRXAFS_ExtendLock(acall, Fid, Sync);
4788 } /*SRXAFS_OldExtendLock */
4792 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4793 struct AFSVolSync * Sync)
4796 struct rx_connection *tcon;
4798 struct client *t_client = NULL; /* tmp ptr to client data */
4799 struct fsstats fsstats;
4801 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_EXTENDLOCK);
4803 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4804 goto Bad_ExtendLock;
4806 code = SAFSS_ExtendLock(acall, Fid, Sync);
4809 code = CallPostamble(tcon, code, thost);
4811 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4813 fsstats_FinishOp(&fsstats, code);
4815 osi_auditU(acall, ExtendLockEvent, code,
4816 AUD_ID, t_client ? t_client->ViceId : 0,
4817 AUD_FID, Fid, AUD_END);
4820 } /*SRXAFS_ExtendLock */
4824 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
4825 * merged into it when possible.
4828 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
4829 struct AFSVolSync *Sync)
4831 Vnode *targetptr = 0; /* vnode of input file */
4832 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4833 Error errorCode = 0; /* error code */
4834 Volume *volptr = 0; /* pointer to the volume header */
4835 struct client *client = 0; /* pointer to client structure */
4836 afs_int32 rights, anyrights; /* rights for this and any user */
4837 struct client *t_client; /* tmp ptr to client data */
4838 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4839 struct rx_connection *tcon = rx_ConnectionOf(acall);
4841 /* Get ptr to client data for user Id for logging */
4842 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4843 logHostAddr.s_addr = rxr_HostOf(tcon);
4845 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4846 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4847 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4849 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
4852 * Get the vnode and volume for the desired file along with the caller's
4856 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4857 &parentwhentargetnotdir, &client, WRITE_LOCK,
4858 &rights, &anyrights))) {
4859 goto Bad_ReleaseLock;
4862 /* set volume synchronization information */
4863 SetVolumeSync(Sync, volptr);
4865 /* Handle the actual lock release */
4866 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
4867 goto Bad_ReleaseLock;
4869 /* if no more locks left, a callback would be triggered here */
4870 if (targetptr->disk.lock.lockCount <= 0) {
4871 rx_KeepAliveOn(acall);
4872 /* convert the write lock to a read lock before breaking callbacks */
4873 VVnodeWriteToRead(&errorCode, targetptr);
4874 osi_Assert(!errorCode || errorCode == VSALVAGE);
4875 BreakCallBack(client->host, Fid, 0);
4879 /* Put back file's vnode and volume */
4880 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4881 (Vnode *) 0, volptr, &client);
4883 if (errorCode == VREADONLY) /* presumably, we already granted this lock */
4884 errorCode = 0; /* under our generous policy re RO vols */
4886 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
4889 } /*SAFSS_ReleaseLock */
4893 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4894 struct AFSVolSync * Sync)
4896 return SRXAFS_ReleaseLock(acall, Fid, Sync);
4897 } /*SRXAFS_OldReleaseLock */
4901 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4902 struct AFSVolSync * Sync)
4905 struct rx_connection *tcon;
4907 struct client *t_client = NULL; /* tmp ptr to client data */
4908 struct fsstats fsstats;
4910 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RELEASELOCK);
4912 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4913 goto Bad_ReleaseLock;
4915 code = SAFSS_ReleaseLock(acall, Fid, Sync);
4918 code = CallPostamble(tcon, code, thost);
4920 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4922 fsstats_FinishOp(&fsstats, code);
4924 osi_auditU(acall, ReleaseLockEvent, code,
4925 AUD_ID, t_client ? t_client->ViceId : 0,
4926 AUD_FID, Fid, AUD_END);
4929 } /*SRXAFS_ReleaseLock */
4933 SetSystemStats(struct AFSStatistics *stats)
4935 /* Fix this sometime soon.. */
4936 /* Because hey, it's not like we have a network monitoring protocol... */
4937 struct timeval time;
4939 /* this works on all system types */
4940 FT_GetTimeOfDay(&time, 0);
4941 stats->CurrentTime = time.tv_sec;
4942 } /*SetSystemStats */
4945 SetAFSStats(struct AFSStatistics *stats)
4947 extern afs_int32 StartTime, CurrentConnections;
4951 stats->CurrentMsgNumber = 0;
4952 stats->OldestMsgNumber = 0;
4953 stats->StartTime = StartTime;
4954 stats->CurrentConnections = CurrentConnections;
4955 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
4956 stats->TotalFetchs =
4957 AFSCallStats.FetchData + AFSCallStats.FetchACL +
4958 AFSCallStats.FetchStatus;
4959 stats->FetchDatas = AFSCallStats.FetchData;
4960 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
4961 seconds = AFSCallStats.AccumFetchTime / 1000;
4964 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
4965 stats->TotalStores =
4966 AFSCallStats.StoreData + AFSCallStats.StoreACL +
4967 AFSCallStats.StoreStatus;
4968 stats->StoreDatas = AFSCallStats.StoreData;
4969 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
4970 seconds = AFSCallStats.AccumStoreTime / 1000;
4973 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
4975 stats->ProcessSize = -1; /* TODO: */
4977 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
4980 h_GetWorkStats((int *)&(stats->WorkStations),
4981 (int *)&(stats->ActiveWorkStations), (int *)0,
4982 (afs_int32) (FT_ApproxTime()) - (15 * 60));
4986 /* Get disk related information from all AFS partitions. */
4989 SetVolumeStats(struct AFSStatistics *stats)
4991 struct DiskPartition64 *part;
4994 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
4995 part = part->next) {
4996 stats->Disks[i].TotalBlocks = RoundInt64ToInt31(part->totalUsable);
4997 stats->Disks[i].BlocksAvailable = RoundInt64ToInt31(part->free);
4998 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
4999 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5002 while (i < AFS_MSTATDISKS) {
5003 stats->Disks[i].TotalBlocks = -1;
5006 } /*SetVolumeStats */
5009 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5012 struct rx_connection *tcon = rx_ConnectionOf(acall);
5014 struct client *t_client = NULL; /* tmp ptr to client data */
5015 struct fsstats fsstats;
5017 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5019 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5020 goto Bad_GetStatistics;
5022 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5024 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5026 memset(Statistics, 0, sizeof(*Statistics));
5027 SetAFSStats((struct AFSStatistics *)Statistics);
5028 SetVolumeStats((struct AFSStatistics *)Statistics);
5029 SetSystemStats((struct AFSStatistics *)Statistics);
5032 code = CallPostamble(tcon, code, thost);
5034 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5036 fsstats_FinishOp(&fsstats, code);
5038 osi_auditU(acall, GetStatisticsEvent, code,
5039 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5041 } /*SRXAFS_GetStatistics */
5045 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5047 extern afs_int32 StartTime, CurrentConnections;
5050 struct rx_connection *tcon = rx_ConnectionOf(acall);
5052 struct client *t_client = NULL; /* tmp ptr to client data */
5053 struct timeval time;
5054 struct fsstats fsstats;
5056 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5058 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5059 goto Bad_GetStatistics64;
5061 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5062 Statistics->ViceStatistics64_val =
5063 malloc(statsVersion*sizeof(afs_int64));
5064 Statistics->ViceStatistics64_len = statsVersion;
5066 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5067 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5068 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5070 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5071 AFSCallStats.TotalCalls;
5072 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5073 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5074 AFSCallStats.FetchStatus;
5075 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5076 AFSCallStats.FetchData;
5077 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5078 AFSCallStats.TotalFetchedBytes;
5079 seconds = AFSCallStats.AccumFetchTime / 1000;
5082 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5083 AFSCallStats.TotalFetchedBytes / seconds;
5084 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5085 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5086 AFSCallStats.StoreStatus;
5087 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5088 AFSCallStats.StoreData;
5089 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5090 AFSCallStats.TotalStoredBytes;
5091 seconds = AFSCallStats.AccumStoreTime / 1000;
5094 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5095 AFSCallStats.TotalStoredBytes / seconds;
5097 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5099 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5100 (afs_int32) ((long)sbrk(0) >> 10);
5103 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5104 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5106 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5110 /* this works on all system types */
5111 FT_GetTimeOfDay(&time, 0);
5112 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5114 Bad_GetStatistics64:
5115 code = CallPostamble(tcon, code, thost);
5117 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5119 fsstats_FinishOp(&fsstats, code);
5121 osi_auditU(acall, GetStatisticsEvent, code,
5122 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5124 } /*SRXAFS_GetStatistics */
5127 /*------------------------------------------------------------------------
5128 * EXPORTED SRXAFS_XStatsVersion
5131 * Routine called by the server-side RPC interface to implement
5132 * pulling out the xstat version number for the File Server.
5135 * a_versionP : Ptr to the version number variable to set.
5141 * Nothing interesting.
5145 *------------------------------------------------------------------------*/
5148 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5149 { /*SRXAFS_XStatsVersion */
5151 struct client *t_client = NULL; /* tmp ptr to client data */
5152 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5153 struct fsstats fsstats;
5155 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_XSTATSVERSION);
5157 *a_versionP = AFS_XSTAT_VERSION;
5159 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5161 fsstats_FinishOp(&fsstats, 0);
5163 osi_auditU(a_call, XStatsVersionEvent, 0,
5164 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5166 } /*SRXAFS_XStatsVersion */
5169 /*------------------------------------------------------------------------
5170 * PRIVATE FillPerfValues
5173 * Routine called to fill a regular performance data structure.
5176 * a_perfP : Ptr to perf structure to fill
5182 * Various collections need this info, so the guts were put in
5183 * this separate routine.
5187 *------------------------------------------------------------------------*/
5190 FillPerfValues(struct afs_PerfStats *a_perfP)
5191 { /*FillPerfValues */
5192 int dir_Buffers; /*# buffers in use by dir package */
5193 int dir_Calls; /*# read calls in dir package */
5194 int dir_IOs; /*# I/O ops in dir package */
5195 struct rx_statistics *stats;
5198 * Vnode cache section.
5200 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5201 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5202 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5203 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5204 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5205 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5206 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5207 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5208 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5209 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5210 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5211 a_perfP->vcache_H_Gets = (int)VStats.hdr_gets;
5212 a_perfP->vcache_H_Replacements = (int)VStats.hdr_loads;
5215 * Directory section.
5217 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5218 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5219 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5220 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5225 stats = rx_GetStatistics();
5227 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5228 a_perfP->rx_noPackets_RcvClass =
5229 (afs_int32) stats->receivePktAllocFailures;
5230 a_perfP->rx_noPackets_SendClass =
5231 (afs_int32) stats->sendPktAllocFailures;
5232 a_perfP->rx_noPackets_SpecialClass =
5233 (afs_int32) stats->specialPktAllocFailures;
5234 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5235 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5236 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5237 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5238 a_perfP->rx_noPacketBuffersOnRead =
5239 (afs_int32) stats->noPacketBuffersOnRead;
5240 a_perfP->rx_selects = (afs_int32) stats->selects;
5241 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5242 a_perfP->rx_packetsRead_RcvClass =
5243 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5244 a_perfP->rx_packetsRead_SendClass =
5245 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5246 a_perfP->rx_packetsRead_SpecialClass =
5247 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5248 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5249 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5250 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5251 a_perfP->rx_spuriousPacketsRead =
5252 (afs_int32) stats->spuriousPacketsRead;
5253 a_perfP->rx_packetsSent_RcvClass =
5254 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5255 a_perfP->rx_packetsSent_SendClass =
5256 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5257 a_perfP->rx_packetsSent_SpecialClass =
5258 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5259 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5260 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5261 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
5262 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
5263 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
5264 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
5265 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
5266 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
5267 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
5268 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
5269 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
5270 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
5271 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
5272 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
5273 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
5274 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
5275 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
5276 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
5277 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
5278 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
5280 a_perfP->host_NumHostEntries = HTs;
5281 a_perfP->host_HostBlocks = HTBlocks;
5282 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5283 &(a_perfP->host_HostsInSameNetOrSubnet),
5284 &(a_perfP->host_HostsInDiffSubnet),
5285 &(a_perfP->host_HostsInDiffNetwork));
5286 a_perfP->host_NumClients = CEs;
5287 a_perfP->host_ClientBlocks = CEBlocks;
5289 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5290 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
5291 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5292 rx_FreeStatistics(&stats);
5293 } /*FillPerfValues */
5296 /*------------------------------------------------------------------------
5297 * EXPORTED SRXAFS_GetXStats
5300 * Routine called by the server-side callback RPC interface to
5301 * implement getting the given data collection from the extended
5302 * File Server statistics.
5305 * a_call : Ptr to Rx call on which this request came in.
5306 * a_clientVersionNum : Client version number.
5307 * a_opCode : Desired operation.
5308 * a_serverVersionNumP : Ptr to version number to set.
5309 * a_timeP : Ptr to time value (seconds) to set.
5310 * a_dataP : Ptr to variable array structure to return
5317 * Nothing interesting.
5321 *------------------------------------------------------------------------*/
5324 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5325 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5326 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5327 { /*SRXAFS_GetXStats */
5329 int code; /*Return value */
5330 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5331 afs_int32 dataBytes; /*Bytes in data buffer */
5332 struct fsstats fsstats;
5334 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETXSTATS);
5337 * Record the time of day and the server version number.
5339 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5340 *a_timeP = FT_ApproxTime();
5343 * Stuff the appropriate data in there (assume victory)
5348 ("Received GetXStats call for collection %d\n",
5349 a_collectionNumber));
5353 * We're not keeping stats, so just return successfully with
5356 a_dataP->AFS_CollData_len = 0;
5357 a_dataP->AFS_CollData_val = NULL;
5360 switch (a_collectionNumber) {
5361 case AFS_XSTATSCOLL_CALL_INFO:
5363 * Pass back all the call-count-related data.
5365 * >>> We are forced to allocate a separate area in which to
5366 * >>> put this stuff in by the RPC stub generator, since it
5367 * >>> will be freed at the tail end of the server stub code.
5371 * I don't think call-level stats are being collected yet
5372 * for the File Server.
5374 dataBytes = sizeof(struct afs_Stats);
5375 dataBuffP = (afs_int32 *) malloc(dataBytes);
5376 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5377 a_dataP->AFS_CollData_len = dataBytes >> 2;
5378 a_dataP->AFS_CollData_val = dataBuffP;
5380 a_dataP->AFS_CollData_len = 0;
5381 a_dataP->AFS_CollData_val = NULL;
5385 case AFS_XSTATSCOLL_PERF_INFO:
5387 * Pass back all the regular performance-related data.
5389 * >>> We are forced to allocate a separate area in which to
5390 * >>> put this stuff in by the RPC stub generator, since it
5391 * >>> will be freed at the tail end of the server stub code.
5394 afs_perfstats.numPerfCalls++;
5395 FillPerfValues(&afs_perfstats);
5398 * Don't overwrite the spares at the end.
5401 dataBytes = sizeof(struct afs_PerfStats);
5402 dataBuffP = (afs_int32 *) malloc(dataBytes);
5403 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5404 a_dataP->AFS_CollData_len = dataBytes >> 2;
5405 a_dataP->AFS_CollData_val = dataBuffP;
5408 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5410 * Pass back the full collection of performance-related data.
5411 * We have to stuff the basic, overall numbers in, but the
5412 * detailed numbers are kept in the structure already.
5414 * >>> We are forced to allocate a separate area in which to
5415 * >>> put this stuff in by the RPC stub generator, since it
5416 * >>> will be freed at the tail end of the server stub code.
5419 afs_perfstats.numPerfCalls++;
5420 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5421 FillPerfValues(&afs_FullPerfStats.overall);
5424 * Don't overwrite the spares at the end.
5427 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5428 dataBuffP = (afs_int32 *) malloc(dataBytes);
5429 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5430 a_dataP->AFS_CollData_len = dataBytes >> 2;
5431 a_dataP->AFS_CollData_val = dataBuffP;
5434 case AFS_XSTATSCOLL_CBSTATS:
5435 afs_perfstats.numPerfCalls++;
5437 dataBytes = sizeof(struct cbcounters);
5438 dataBuffP = (afs_int32 *) malloc(dataBytes);
5440 extern struct cbcounters cbstuff;
5441 dataBuffP[0]=cbstuff.DeleteFiles;
5442 dataBuffP[1]=cbstuff.DeleteCallBacks;
5443 dataBuffP[2]=cbstuff.BreakCallBacks;
5444 dataBuffP[3]=cbstuff.AddCallBacks;
5445 dataBuffP[4]=cbstuff.GotSomeSpaces;
5446 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
5447 dataBuffP[6]=cbstuff.nFEs;
5448 dataBuffP[7]=cbstuff.nCBs;
5449 dataBuffP[8]=cbstuff.nblks;
5450 dataBuffP[9]=cbstuff.CBsTimedOut;
5451 dataBuffP[10]=cbstuff.nbreakers;
5452 dataBuffP[11]=cbstuff.GSS1;
5453 dataBuffP[12]=cbstuff.GSS2;
5454 dataBuffP[13]=cbstuff.GSS3;
5455 dataBuffP[14]=cbstuff.GSS4;
5456 dataBuffP[15]=cbstuff.GSS5;
5459 a_dataP->AFS_CollData_len = dataBytes >> 2;
5460 a_dataP->AFS_CollData_val = dataBuffP;
5466 * Illegal collection number.
5468 a_dataP->AFS_CollData_len = 0;
5469 a_dataP->AFS_CollData_val = NULL;
5471 } /*Switch on collection number */
5473 fsstats_FinishOp(&fsstats, code);
5477 } /*SRXAFS_GetXStats */
5481 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5482 struct AFSCBs *CallBackArray)
5484 afs_int32 errorCode = 0;
5486 struct client *client = 0;
5487 struct rx_connection *tcon;
5489 struct fsstats fsstats;
5491 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GIVEUPCALLBACKS);
5495 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5496 FidArray->AFSCBFids_len));
5499 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5501 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5502 goto Bad_GiveUpCallBacks;
5504 if (!FidArray && !CallBackArray) {
5506 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5507 (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
5508 errorCode = GetClient(tcon, &client);
5511 DeleteAllCallBacks_r(client->host, 1);
5516 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5518 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5519 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5520 (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
5522 goto Bad_GiveUpCallBacks;
5525 errorCode = GetClient(tcon, &client);
5527 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5528 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5529 DeleteCallBack(client->host, fid);
5535 Bad_GiveUpCallBacks:
5536 errorCode = CallPostamble(tcon, errorCode, thost);
5538 fsstats_FinishOp(&fsstats, errorCode);
5542 } /*common_GiveUpCallBacks */
5546 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5547 struct AFSCBs * CallBackArray)
5549 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5550 } /*SRXAFS_GiveUpCallBacks */
5553 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
5555 return common_GiveUpCallBacks(acall, 0, 0);
5556 } /*SRXAFS_GiveUpAllCallBacks */
5560 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
5561 struct AFSVolumeInfo * avolinfo)
5563 return (VNOVOL); /* XXX Obsolete routine XXX */
5565 } /*SRXAFS_NGetVolumeInfo */
5569 * Dummy routine. Should never be called (the cache manager should only
5570 * invoke this interface when communicating with a AFS/DFS Protocol
5574 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
5575 char *afs_name_p, struct AFSFid * afs_fid_p,
5576 struct AFSFetchStatus * afs_status_p,
5577 struct AFSFetchStatus * afs_dir_status_p,
5578 struct AFSCallBack * afs_callback_p,
5579 struct AFSVolSync * afs_sync_p)
5586 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
5589 struct rx_connection *tcon;
5591 afs_uint32 *dataBuffP;
5592 afs_int32 dataBytes;
5595 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
5596 afs_FullPerfStats.overall.fs_nGetCaps++;
5598 ViceLog(2, ("SAFS_GetCapabilties\n"));
5600 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5603 dataBytes = 1 * sizeof(afs_int32);
5604 dataBuffP = (afs_uint32 *) malloc(dataBytes);
5605 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
5606 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
5608 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
5610 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
5611 capabilities->Capabilities_val = dataBuffP;
5614 code = CallPostamble(tcon, code, thost);
5621 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
5622 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
5626 afs_int32 nids, naddrs;
5627 afs_int32 *vd, *addr;
5628 Error errorCode = 0; /* return code to caller */
5629 struct client *client = 0;
5631 ViceLog(1, ("SRXAFS_FlushCPS\n"));
5633 AFSCallStats.TotalCalls++;
5635 nids = vids->ViceIds_len; /* # of users in here */
5636 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
5637 if (nids < 0 || naddrs < 0) {
5642 vd = vids->ViceIds_val;
5643 for (i = 0; i < nids; i++, vd++) {
5646 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
5650 client->prfail = 2; /* Means re-eval client's cps */
5653 rx_SetRock(((struct rx_connection *)client->tcon), 0);
5656 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
5657 free(client->CPS.prlist_val);
5658 client->CPS.prlist_val = NULL;
5659 client->CPS.prlist_len = 0;
5661 ReleaseWriteLock(&client->lock);
5665 addr = addrs->IPAddrs_val;
5666 for (i = 0; i < naddrs; i++, addr++) {
5668 h_flushhostcps(*addr, htons(7001));
5672 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
5674 } /*SRXAFS_FlushCPS */
5676 /* worthless hack to let CS keep running ancient software */
5678 afs_vtoi(char *aname)
5684 while ((tc = *aname++)) {
5685 if (tc > '9' || tc < '0')
5686 return 0; /* invalid name */
5694 * may get name or #, but must handle all weird cases (recognize readonly
5695 * or backup volumes by name or #
5698 CopyVolumeEntry(char *aname, struct vldbentry *ave,
5699 struct VolumeInfo *av)
5702 afs_int32 mask, whichType;
5703 afs_uint32 *serverHost, *typePtr;
5705 /* figure out what type we want if by name */
5707 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
5708 whichType = BACKVOL;
5709 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
5714 vol = afs_vtoi(aname);
5716 vol = ave->volumeId[whichType];
5719 * Now vol has volume # we're interested in. Next, figure out the type
5720 * of the volume by looking finding it in the vldb entry
5722 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
5725 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
5728 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
5729 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
5730 whichType = BACKVOL;
5732 return EINVAL; /* error: can't find volume in vldb entry */
5734 typePtr = &av->Type0;
5735 serverHost = &av->Server0;
5737 av->Type = whichType;
5738 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
5739 if (ave->flags & VLF_RWEXISTS)
5740 typePtr[RWVOL] = ave->volumeId[RWVOL];
5741 if (ave->flags & VLF_ROEXISTS)
5742 typePtr[ROVOL] = ave->volumeId[ROVOL];
5743 if (ave->flags & VLF_BACKEXISTS)
5744 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
5746 for (i = 0, j = 0; i < ave->nServers; i++) {
5747 if ((ave->serverFlags[i] & mask) == 0)
5748 continue; /* wrong volume */
5749 serverHost[j] = ave->serverNumber[i];
5752 av->ServerCount = j;
5754 serverHost[j++] = 0; /* bogus 8, but compat only now */
5759 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
5761 static struct rx_connection *vlConn = 0;
5762 static int down = 0;
5763 static afs_int32 lastDownTime = 0;
5764 struct vldbentry tve;
5765 struct rx_securityClass *vlSec;
5769 vlSec = rxnull_NewClientSecurityObject();
5771 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
5772 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
5774 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
5775 return 1; /* failure */
5778 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
5780 down = 0; /* call worked */
5783 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
5789 /* otherwise convert to old format vldb entry */
5790 code = CopyVolumeEntry(avolid, &tve, avolinfo);
5800 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
5801 struct VolumeInfo * avolinfo)
5804 struct rx_connection *tcon;
5806 struct fsstats fsstats;
5808 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMEINFO);
5810 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5811 goto Bad_GetVolumeInfo;
5814 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
5816 code = TryLocalVLServer(avolid, avolinfo);
5818 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
5819 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
5820 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
5821 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
5824 code = CallPostamble(tcon, code, thost);
5826 fsstats_FinishOp(&fsstats, code);
5830 } /*SRXAFS_GetVolumeInfo */
5834 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5835 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
5836 char **OfflineMsg, char **Motd)
5838 Vnode *targetptr = 0; /* vnode of the new file */
5839 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5840 Error errorCode = 0; /* error code */
5841 Volume *volptr = 0; /* pointer to the volume header */
5842 struct client *client = 0; /* pointer to client entry */
5843 afs_int32 rights, anyrights; /* rights for this and any user */
5845 struct rx_connection *tcon;
5847 struct client *t_client = NULL; /* tmp ptr to client data */
5848 struct fsstats fsstats;
5850 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMESTATUS);
5852 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
5853 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5854 goto Bad_GetVolumeStatus;
5857 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
5861 goto Bad_GetVolumeStatus;
5863 dummyFid.Volume = avolid, dummyFid.Vnode =
5864 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5867 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
5868 &parentwhentargetnotdir, &client, READ_LOCK,
5869 &rights, &anyrights)))
5870 goto Bad_GetVolumeStatus;
5872 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
5874 goto Bad_GetVolumeStatus;
5876 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
5878 Bad_GetVolumeStatus:
5879 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
5880 (Vnode *) 0, volptr, &client);
5881 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
5882 /* next is to guarantee out strings exist for stub */
5884 *Name = (char *)malloc(1);
5888 *Motd = (char *)malloc(1);
5891 if (*OfflineMsg == 0) {
5892 *OfflineMsg = (char *)malloc(1);
5895 errorCode = CallPostamble(tcon, errorCode, thost);
5897 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5899 fsstats_FinishOp(&fsstats, errorCode);
5901 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
5902 AUD_ID, t_client ? t_client->ViceId : 0,
5903 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
5906 } /*SRXAFS_GetVolumeStatus */
5910 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5911 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
5912 char *OfflineMsg, char *Motd)
5914 Vnode *targetptr = 0; /* vnode of the new file */
5915 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5916 Error errorCode = 0; /* error code */
5917 Volume *volptr = 0; /* pointer to the volume header */
5918 struct client *client = 0; /* pointer to client entry */
5919 afs_int32 rights, anyrights; /* rights for this and any user */
5921 struct rx_connection *tcon = rx_ConnectionOf(acall);
5923 struct client *t_client = NULL; /* tmp ptr to client data */
5924 struct fsstats fsstats;
5926 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETVOLUMESTATUS);
5928 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
5929 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5930 goto Bad_SetVolumeStatus;
5933 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
5937 goto Bad_SetVolumeStatus;
5939 dummyFid.Volume = avolid, dummyFid.Vnode =
5940 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5943 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
5944 &parentwhentargetnotdir, &client, READ_LOCK,
5945 &rights, &anyrights)))
5946 goto Bad_SetVolumeStatus;
5948 if (readonlyServer) {
5949 errorCode = VREADONLY;
5950 goto Bad_SetVolumeStatus;
5952 if (VanillaUser(client)) {
5954 goto Bad_SetVolumeStatus;
5958 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
5960 Bad_SetVolumeStatus:
5961 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
5963 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
5964 errorCode = CallPostamble(tcon, errorCode, thost);
5966 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5968 fsstats_FinishOp(&fsstats, errorCode);
5970 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
5971 AUD_ID, t_client ? t_client->ViceId : 0,
5972 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
5974 } /*SRXAFS_SetVolumeStatus */
5976 #define DEFAULTVOLUME "root.afs"
5979 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
5985 struct rx_connection *tcon;
5987 Error errorCode = 0;
5989 struct fsstats fsstats;
5991 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETROOTVOLUME);
5993 return FSERR_EOPNOTSUPP;
5996 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
5997 goto Bad_GetRootVolume;
5999 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6002 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6004 strcpy(temp, DEFAULTVOLUME);
6006 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6007 lockf(fd, F_LOCK, 0);
6011 len = read(fd, temp, 256);
6012 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6013 lockf(fd, F_ULOCK, 0);
6018 if (temp[len - 1] == '\n')
6022 *VolumeName = temp; /* freed by rx server-side stub */
6025 errorCode = CallPostamble(tcon, errorCode, thost);
6027 fsstats_FinishOp(&fsstats, errorCode);
6032 } /*SRXAFS_GetRootVolume */
6035 /* still works because a struct CBS is the same as a struct AFSOpaque */
6037 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6038 struct AFSOpaque * Token)
6041 struct rx_connection *tcon;
6043 struct fsstats fsstats;
6045 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CHECKTOKEN);
6047 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6048 goto Bad_CheckToken;
6050 code = FSERR_ECONNREFUSED;
6053 code = CallPostamble(tcon, code, thost);
6055 fsstats_FinishOp(&fsstats, code);
6059 } /*SRXAFS_CheckToken */
6062 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6063 afs_uint32 * USeconds)
6066 struct rx_connection *tcon;
6069 struct fsstats fsstats;
6071 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETTIME);
6073 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6077 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6079 FT_GetTimeOfDay(&tpl, 0);
6080 *Seconds = tpl.tv_sec;
6081 *USeconds = tpl.tv_usec;
6083 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6086 code = CallPostamble(tcon, code, thost);
6088 fsstats_FinishOp(&fsstats, code);
6092 } /*SRXAFS_GetTime */
6099 * Implement a client's data fetch using Rx.
6102 * volptr : Ptr to the given volume's info.
6103 * targetptr : Pointer to the vnode involved.
6104 * Call : Ptr to the Rx call involved.
6105 * Pos : Offset within the file.
6106 * Len : Length in bytes to read; this value is bogus!
6107 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6109 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6114 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6115 struct rx_call * Call, afs_sfsize_t Pos,
6116 afs_sfsize_t Len, afs_int32 Int64Mode,
6117 afs_sfsize_t * a_bytesToFetchP,
6118 afs_sfsize_t * a_bytesFetchedP)
6120 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6125 #else /* HAVE_PIOV */
6126 struct iovec tiov[RX_MAXIOVECS];
6128 #endif /* HAVE_PIOV */
6133 * Initialize the byte count arguments.
6135 (*a_bytesToFetchP) = 0;
6136 (*a_bytesFetchedP) = 0;
6139 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6140 (afs_uintmax_t) Len));
6142 if (!VN_GET_INO(targetptr)) {
6143 afs_int32 zero = htonl(0);
6145 * This is used for newly created files; we simply send 0 bytes
6146 * back to make the cache manager happy...
6149 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6150 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6153 FT_GetTimeOfDay(&StartTime, 0);
6154 ihP = targetptr->handle;
6157 VTakeOffline(volptr);
6158 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6162 optSize = sendBufSize;
6163 tlen = FDH_SIZE(fdP);
6165 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6168 VTakeOffline(volptr);
6169 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6173 if (CheckLength(volptr, targetptr, tlen)) {
6175 VTakeOffline(volptr);
6182 if (Pos + Len > tlen) /* get length we should send */
6183 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
6186 afs_int32 high, low;
6187 SplitOffsetOrSize(Len, high, low);
6188 osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6191 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6194 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6196 (*a_bytesToFetchP) = Len;
6198 tbuffer = AllocSendBuffer();
6199 #endif /* HAVE_PIOV */
6208 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
6209 if (nBytes != wlen) {
6211 FreeSendBuffer((struct afs_buffer *)tbuffer);
6212 VTakeOffline(volptr);
6213 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6217 nBytes = rx_Write(Call, tbuffer, wlen);
6218 #else /* HAVE_PIOV */
6219 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6225 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
6226 if (nBytes != wlen) {
6228 VTakeOffline(volptr);
6229 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6233 nBytes = rx_Writev(Call, tiov, tnio, wlen);
6234 #endif /* HAVE_PIOV */
6237 * Bump the number of bytes actually sent by the number from this
6240 (*a_bytesFetchedP) += nBytes;
6241 if (nBytes != wlen) {
6245 FreeSendBuffer((struct afs_buffer *)tbuffer);
6246 #endif /* HAVE_PIOV */
6247 err = VIsGoingOffline(volptr);
6256 FreeSendBuffer((struct afs_buffer *)tbuffer);
6257 #endif /* HAVE_PIOV */
6259 FT_GetTimeOfDay(&StopTime, 0);
6261 /* Adjust all Fetch Data related stats */
6263 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6264 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6265 AFSCallStats.AccumFetchTime +=
6266 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6267 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6269 afs_fsize_t targLen;
6270 VN_GET_LEN(targLen, targetptr);
6271 AFSCallStats.TotalFetchedBytes += targLen;
6272 AFSCallStats.FetchSize1++;
6273 if (targLen < SIZE2)
6274 AFSCallStats.FetchSize2++;
6275 else if (targLen < SIZE3)
6276 AFSCallStats.FetchSize3++;
6277 else if (targLen < SIZE4)
6278 AFSCallStats.FetchSize4++;
6280 AFSCallStats.FetchSize5++;
6285 } /*FetchData_RXStyle */
6288 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6289 afs_sfsize_t * size)
6291 #ifdef AFS_NAMEI_ENV
6293 lhp = IH_OPEN(V_linkHandle(vp));
6296 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
6300 *size = OS_SIZE(fdP->fd_fd);
6301 return (*size == -1) ? -1 : 0;
6303 struct afs_stat status;
6305 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6309 *lc = GetLinkCount(vp, &status);
6310 *size = status.st_size;
6319 * Implement a client's data store using Rx.
6322 * volptr : Ptr to the given volume's info.
6323 * targetptr : Pointer to the vnode involved.
6324 * Call : Ptr to the Rx call involved.
6325 * Pos : Offset within the file.
6326 * Len : Length in bytes to store; this value is bogus!
6327 * a_bytesToStoreP : Set to the number of bytes to be stored to
6329 * a_bytesStoredP : Set to the actual number of bytes stored to
6333 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6334 struct client * client, struct rx_call * Call,
6335 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6337 afs_sfsize_t * a_bytesToStoreP,
6338 afs_sfsize_t * a_bytesStoredP)
6340 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6341 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6342 Error errorCode = 0; /* Returned error code to caller */
6344 char *tbuffer; /* data copying buffer */
6345 #else /* HAVE_PIOV */
6346 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6347 int tnio; /* temp for iovec size */
6348 #endif /* HAVE_PIOV */
6349 afs_sfsize_t tlen; /* temp for xfr length */
6350 Inode tinode; /* inode for I/O */
6351 afs_int32 optSize; /* optimal transfer size */
6352 afs_sfsize_t DataLength = 0; /* size of inode */
6353 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6354 afs_fsize_t NewLength; /* size after this store completes */
6355 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6356 int linkCount = 0; /* link count on inode */
6359 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6363 * Initialize the byte count arguments.
6365 (*a_bytesToStoreP) = 0;
6366 (*a_bytesStoredP) = 0;
6369 * We break the callbacks here so that the following signal will not
6372 BreakCallBack(client->host, Fid, 0);
6374 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6375 /* the inode should have been created in Alloc_NewVnode */
6376 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
6378 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
6379 Fid->Volume, Fid->Vnode, Fid->Unique,
6380 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
6381 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
6382 return ENOENT; /* is this proper error code? */
6384 rx_KeepAliveOff(Call);
6386 * See if the file has several links (from other volumes). If it
6387 * does, then we have to make a copy before changing it to avoid
6388 *changing read-only clones of this dude
6391 ("StoreData_RXStyle : Opening inode %s\n",
6392 PrintInode(stmp, VN_GET_INO(targetptr))));
6393 fdP = IH_OPEN(targetptr->handle);
6396 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
6398 VTakeOffline(volptr);
6399 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6403 if (CheckLength(volptr, targetptr, DataLength)) {
6405 VTakeOffline(volptr);
6409 if (linkCount != 1) {
6412 ("StoreData_RXStyle : inode %s has more than onelink\n",
6413 PrintInode(stmp, VN_GET_INO(targetptr))));
6414 /* other volumes share this data, better copy it first */
6416 /* Adjust the disk block count by the creation of the new inode.
6417 * We call the special VDiskUsage so we don't adjust the volume's
6418 * quota since we don't want to penalyze the user for afs's internal
6419 * mechanisms (i.e. copy on write overhead.) Also the right size
6420 * of the disk will be recorded...
6423 VN_GET_LEN(size, targetptr);
6424 volptr->partition->flags &= ~PART_DONTUPDATE;
6425 VSetPartitionDiskUsage(volptr->partition);
6426 volptr->partition->flags |= PART_DONTUPDATE;
6427 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6428 volptr->partition->flags &= ~PART_DONTUPDATE;
6432 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6433 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, MAXFSIZE))) {
6434 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6435 volptr->partition->flags &= ~PART_DONTUPDATE;
6438 volptr->partition->flags &= ~PART_DONTUPDATE;
6439 VSetPartitionDiskUsage(volptr->partition);
6440 fdP = IH_OPEN(targetptr->handle);
6443 ("StoreData : Reopen after CopyOnWrite failed\n"));
6447 tinode = VN_GET_INO(targetptr);
6449 if (!VALID_INO(tinode)) {
6450 VTakeOffline(volptr);
6451 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
6456 /* compute new file length */
6457 NewLength = DataLength;
6458 if (FileLength < NewLength)
6459 /* simulate truncate */
6460 NewLength = FileLength;
6461 TruncatedLength = NewLength; /* remember length after possible ftruncate */
6462 if (Pos + Length > NewLength)
6463 NewLength = Pos + Length; /* and write */
6465 /* adjust the disk block count by the difference in the files */
6467 afs_fsize_t targSize;
6468 VN_GET_LEN(targSize, targetptr);
6469 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
6472 AdjustDiskUsage(volptr, adjustSize,
6473 adjustSize - SpareComp(volptr)))) {
6478 /* can signal cache manager to proceed from close now */
6479 /* this bit means that the locks are set and protections are OK */
6480 rx_SetLocalStatus(Call, 1);
6482 FT_GetTimeOfDay(&StartTime, 0);
6484 optSize = sendBufSize;
6486 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
6487 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
6488 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
6490 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
6491 if (FileLength < DataLength)
6492 FDH_TRUNC(fdP, FileLength);
6493 bytesTransfered = 0;
6495 tbuffer = AllocSendBuffer();
6496 #endif /* HAVE_PIOV */
6497 /* if length == 0, the loop below isn't going to do anything, including
6498 * extend the length of the inode, which it must do, since the file system
6499 * assumes that the inode length == vnode's file length. So, we extend
6500 * the file length manually if need be. Note that if file is bigger than
6501 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
6502 * do what we're going to do below.
6504 if (Length == 0 && Pos > TruncatedLength) {
6505 /* Set the file's length; we've already done an lseek to the right
6508 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
6513 errorCode = FDH_TRUNC(fdP, Pos);
6515 /* have some data to copy */
6516 (*a_bytesToStoreP) = Length;
6519 if (bytesTransfered >= Length) {
6523 tlen = Length - bytesTransfered; /* how much more to do */
6525 rlen = optSize; /* bound by buffer size */
6529 errorCode = rx_Read(Call, tbuffer, rlen);
6530 #else /* HAVE_PIOV */
6531 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
6532 #endif /* HAVE_PIOV */
6533 if (errorCode <= 0) {
6537 (*a_bytesStoredP) += errorCode;
6540 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
6541 #else /* HAVE_PIOV */
6542 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
6543 #endif /* HAVE_PIOV */
6544 if (nBytes != rlen) {
6545 errorCode = VDISKFULL;
6548 bytesTransfered += rlen;
6554 FreeSendBuffer((struct afs_buffer *)tbuffer);
6555 #endif /* HAVE_PIOV */
6557 (void) FDH_SYNC(fdP);
6560 Error tmp_errorCode = 0;
6561 afs_sfsize_t nfSize = FDH_SIZE(fdP);
6562 osi_Assert(nfSize >= 0);
6563 /* something went wrong: adjust size and return */
6564 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
6565 /* changed_newTime is tested in StoreData to detemine if we
6566 * need to update the target vnode.
6568 targetptr->changed_newTime = 1;
6570 /* set disk usage to be correct */
6571 VAdjustDiskUsage(&tmp_errorCode, volptr,
6572 (afs_sfsize_t) (nBlocks(nfSize) -
6573 nBlocks(NewLength)), 0);
6574 if (tmp_errorCode) {
6575 errorCode = tmp_errorCode;
6581 FT_GetTimeOfDay(&StopTime, 0);
6583 VN_SET_LEN(targetptr, NewLength);
6585 /* Update all StoreData related stats */
6587 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
6588 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
6589 AFSCallStats.StoreSize1++; /* Piggybacked data */
6591 afs_fsize_t targLen;
6592 VN_GET_LEN(targLen, targetptr);
6593 if (targLen < SIZE2)
6594 AFSCallStats.StoreSize2++;
6595 else if (targLen < SIZE3)
6596 AFSCallStats.StoreSize3++;
6597 else if (targLen < SIZE4)
6598 AFSCallStats.StoreSize4++;
6600 AFSCallStats.StoreSize5++;
6605 } /*StoreData_RXStyle */
6607 static int sys2et[512];
6610 init_sys_error_to_et(void)
6612 memset(&sys2et, 0, sizeof(sys2et));
6613 sys2et[EPERM] = UAEPERM;
6614 sys2et[ENOENT] = UAENOENT;
6615 sys2et[ESRCH] = UAESRCH;
6616 sys2et[EINTR] = UAEINTR;
6617 sys2et[EIO] = UAEIO;
6618 sys2et[ENXIO] = UAENXIO;
6619 sys2et[E2BIG] = UAE2BIG;
6620 sys2et[ENOEXEC] = UAENOEXEC;
6621 sys2et[EBADF] = UAEBADF;
6622 sys2et[ECHILD] = UAECHILD;
6623 sys2et[EAGAIN] = UAEAGAIN;
6624 sys2et[ENOMEM] = UAENOMEM;
6625 sys2et[EACCES] = UAEACCES;
6626 sys2et[EFAULT] = UAEFAULT;
6627 sys2et[ENOTBLK] = UAENOTBLK;
6628 sys2et[EBUSY] = UAEBUSY;
6629 sys2et[EEXIST] = UAEEXIST;
6630 sys2et[EXDEV] = UAEXDEV;
6631 sys2et[ENODEV] = UAENODEV;
6632 sys2et[ENOTDIR] = UAENOTDIR;
6633 sys2et[EISDIR] = UAEISDIR;
6634 sys2et[EINVAL] = UAEINVAL;
6635 sys2et[ENFILE] = UAENFILE;
6636 sys2et[EMFILE] = UAEMFILE;
6637 sys2et[ENOTTY] = UAENOTTY;
6638 sys2et[ETXTBSY] = UAETXTBSY;
6639 sys2et[EFBIG] = UAEFBIG;
6640 sys2et[ENOSPC] = UAENOSPC;
6641 sys2et[ESPIPE] = UAESPIPE;
6642 sys2et[EROFS] = UAEROFS;
6643 sys2et[EMLINK] = UAEMLINK;
6644 sys2et[EPIPE] = UAEPIPE;
6645 sys2et[EDOM] = UAEDOM;
6646 sys2et[ERANGE] = UAERANGE;
6647 sys2et[EDEADLK] = UAEDEADLK;
6648 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
6649 sys2et[ENOLCK] = UAENOLCK;
6650 sys2et[ENOSYS] = UAENOSYS;
6651 #if (ENOTEMPTY != EEXIST)
6652 sys2et[ENOTEMPTY] = UAENOTEMPTY;
6654 sys2et[ELOOP] = UAELOOP;
6655 #if (EWOULDBLOCK != EAGAIN)
6656 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
6658 sys2et[ENOMSG] = UAENOMSG;
6659 sys2et[EIDRM] = UAEIDRM;
6660 sys2et[ECHRNG] = UAECHRNG;
6661 sys2et[EL2NSYNC] = UAEL2NSYNC;
6662 sys2et[EL3HLT] = UAEL3HLT;
6663 sys2et[EL3RST] = UAEL3RST;
6664 sys2et[ELNRNG] = UAELNRNG;
6665 sys2et[EUNATCH] = UAEUNATCH;
6666 sys2et[ENOCSI] = UAENOCSI;
6667 sys2et[EL2HLT] = UAEL2HLT;
6668 sys2et[EBADE] = UAEBADE;
6669 sys2et[EBADR] = UAEBADR;
6670 sys2et[EXFULL] = UAEXFULL;
6671 sys2et[ENOANO] = UAENOANO;
6672 sys2et[EBADRQC] = UAEBADRQC;
6673 sys2et[EBADSLT] = UAEBADSLT;
6674 sys2et[EDEADLK] = UAEDEADLK;
6675 sys2et[EBFONT] = UAEBFONT;
6676 sys2et[ENOSTR] = UAENOSTR;
6677 sys2et[ENODATA] = UAENODATA;
6678 sys2et[ETIME] = UAETIME;
6679 sys2et[ENOSR] = UAENOSR;
6680 sys2et[ENONET] = UAENONET;
6681 sys2et[ENOPKG] = UAENOPKG;
6682 sys2et[EREMOTE] = UAEREMOTE;
6683 sys2et[ENOLINK] = UAENOLINK;
6684 sys2et[EADV] = UAEADV;
6685 sys2et[ESRMNT] = UAESRMNT;
6686 sys2et[ECOMM] = UAECOMM;
6687 sys2et[EPROTO] = UAEPROTO;
6688 sys2et[EMULTIHOP] = UAEMULTIHOP;
6689 sys2et[EDOTDOT] = UAEDOTDOT;
6690 sys2et[EBADMSG] = UAEBADMSG;
6691 sys2et[EOVERFLOW] = UAEOVERFLOW;
6692 sys2et[ENOTUNIQ] = UAENOTUNIQ;
6693 sys2et[EBADFD] = UAEBADFD;
6694 sys2et[EREMCHG] = UAEREMCHG;
6695 sys2et[ELIBACC] = UAELIBACC;
6696 sys2et[ELIBBAD] = UAELIBBAD;
6697 sys2et[ELIBSCN] = UAELIBSCN;
6698 sys2et[ELIBMAX] = UAELIBMAX;
6699 sys2et[ELIBEXEC] = UAELIBEXEC;
6700 sys2et[EILSEQ] = UAEILSEQ;
6701 sys2et[ERESTART] = UAERESTART;
6702 sys2et[ESTRPIPE] = UAESTRPIPE;
6703 sys2et[EUSERS] = UAEUSERS;
6704 sys2et[ENOTSOCK] = UAENOTSOCK;
6705 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
6706 sys2et[EMSGSIZE] = UAEMSGSIZE;
6707 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
6708 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
6709 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
6710 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
6711 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
6712 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
6713 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
6714 sys2et[EADDRINUSE] = UAEADDRINUSE;
6715 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
6716 sys2et[ENETDOWN] = UAENETDOWN;
6717 sys2et[ENETUNREACH] = UAENETUNREACH;
6718 sys2et[ENETRESET] = UAENETRESET;
6719 sys2et[ECONNABORTED] = UAECONNABORTED;
6720 sys2et[ECONNRESET] = UAECONNRESET;
6721 sys2et[ENOBUFS] = UAENOBUFS;
6722 sys2et[EISCONN] = UAEISCONN;
6723 sys2et[ENOTCONN] = UAENOTCONN;
6724 sys2et[ESHUTDOWN] = UAESHUTDOWN;
6725 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
6726 sys2et[ETIMEDOUT] = UAETIMEDOUT;
6727 sys2et[ECONNREFUSED] = UAECONNREFUSED;
6728 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
6729 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
6730 sys2et[EALREADY] = UAEALREADY;
6731 sys2et[EINPROGRESS] = UAEINPROGRESS;
6732 sys2et[ESTALE] = UAESTALE;
6733 sys2et[EUCLEAN] = UAEUCLEAN;
6734 sys2et[ENOTNAM] = UAENOTNAM;
6735 sys2et[ENAVAIL] = UAENAVAIL;
6736 sys2et[EISNAM] = UAEISNAM;
6737 sys2et[EREMOTEIO] = UAEREMOTEIO;
6738 sys2et[EDQUOT] = UAEDQUOT;
6739 sys2et[ENOMEDIUM] = UAENOMEDIUM;
6740 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
6742 sys2et[EIO] = UAEIO;
6746 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
6747 * - pass back the connection, client, and host from CallPreamble
6748 * - keep a ref on the client, which we don't now
6749 * - keep a hold on the host, which we already do
6750 * - pass the connection, client, and host down into SAFSS_*, and use
6751 * them instead of independently discovering them via rx_ConnectionOf
6752 * (safe) and rx_GetSpecific (not so safe)
6753 * The idea being that we decide what client and host we're going to use
6754 * when CallPreamble is called, and stay consistent throughout the call.
6755 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
6759 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
6761 Error errorCode = 0;
6762 struct rx_connection *tcon;
6763 struct host *tcallhost;
6764 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6766 struct client *tclient;
6767 static struct rx_securityClass *sc = 0;
6769 struct rx_connection *conn;
6772 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
6773 goto Bad_CallBackRxConnAddr1;
6775 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6779 tclient = h_FindClient_r(tcon);
6782 goto Bad_CallBackRxConnAddr;
6784 thost = tclient->host;
6786 /* nothing more can be done */
6787 if ( !thost->interface )
6788 goto Bad_CallBackRxConnAddr;
6790 /* the only address is the primary interface */
6791 /* can't change when there's only 1 address, anyway */
6792 if ( thost->interface->numberOfInterfaces <= 1 )
6793 goto Bad_CallBackRxConnAddr;
6795 /* initialise a security object only once */
6797 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
6799 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
6801 if ( *addr == thost->interface->addr[i] ) {
6806 if ( *addr != thost->interface->addr[i] )
6807 goto Bad_CallBackRxConnAddr;
6809 conn = rx_NewConnection (thost->interface->addr[i],
6810 thost->port, 1, sc, 0);
6811 rx_SetConnDeadTime(conn, 2);
6812 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
6814 errorCode = RXAFSCB_Probe(conn);
6817 if ( thost->callback_rxcon )
6818 rx_DestroyConnection(thost->callback_rxcon);
6819 thost->callback_rxcon = conn;
6821 rx_SetConnDeadTime(thost->callback_rxcon, 50);
6822 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
6823 h_ReleaseClient_r(tclient);
6824 /* The hold on thost will be released by CallPostamble */
6826 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6829 rx_DestroyConnection(conn);
6831 Bad_CallBackRxConnAddr:
6832 h_ReleaseClient_r(tclient);
6833 /* The hold on thost will be released by CallPostamble */
6837 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6838 Bad_CallBackRxConnAddr1:
6839 return errorCode; /* failure */
6843 sys_error_to_et(afs_int32 in)
6847 if (in < 0 || in > 511)
6849 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
6851 if (sys2et[in] != 0)