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
796 * appropriate error based on permission or invalid operation.
799 * Nothing interesting.
802 * On success, disables keepalives on the call. Caller should re-enable
803 * after completing disk I/O.
804 *------------------------------------------------------------------------*/
806 GetVolumePackageWithCall(struct rx_call *acall, struct VCallByVol *cbv,
807 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
808 int chkforDir, Vnode ** parent,
809 struct client **client, int locktype,
810 afs_int32 * rights, afs_int32 * anyrights)
812 struct acl_accessList *aCL; /* Internal access List */
813 int aCLSize; /* size of the access list */
814 Error errorCode = 0; /* return code to caller */
815 struct rx_connection *tcon = rx_ConnectionOf(acall);
817 rx_KeepAliveOff(acall);
819 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
823 if (chkforDir == MustNOTBeDIR
824 && ((*targetptr)->disk.type == vDirectory)) {
828 else if (chkforDir == MustBeDIR
829 && ((*targetptr)->disk.type != vDirectory)) {
835 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
836 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
837 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
839 if (chkforDir == MustBeDIR)
840 osi_Assert((*parent) == 0);
842 if ((errorCode = GetClient(tcon, client)) != 0)
849 GetRights(*client, aCL, rights, anyrights);
850 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
851 if ((*targetptr)->disk.type != vDirectory) {
852 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
853 if ((*targetptr)->disk.owner == (*client)->ViceId)
854 (*rights) |= PRSFS_ADMINISTER;
856 (*rights) &= ~PRSFS_ADMINISTER;
858 #ifdef ADMIN_IMPLICIT_LOOKUP
859 /* admins get automatic lookup on everything */
860 if (!VanillaUser(*client))
861 (*rights) |= PRSFS_LOOKUP;
862 #endif /* ADMIN_IMPLICIT_LOOKUP */
865 rx_KeepAliveOn(acall);
868 } /*GetVolumePackage */
870 static_inline afs_int32
871 GetVolumePackage(struct rx_call *acall, AFSFid * Fid, Volume ** volptr,
872 Vnode ** targetptr, int chkforDir, Vnode ** parent,
873 struct client **client, int locktype, afs_int32 * rights,
874 afs_int32 * anyrights)
876 return GetVolumePackageWithCall(acall, NULL, Fid, volptr, targetptr,
877 chkforDir, parent, client, locktype,
882 /*------------------------------------------------------------------------
883 * PutVolumePackageWithCall
886 * This is the opposite of GetVolumePackage(), and is always used at
887 * the end of AFS calls to put back all used vnodes and the volume
888 * in the proper order!
891 * acall : Ptr to Rx call on which this request came in.
892 * parentwhentargetnotdir : a pointer to the parent when the target isn't
894 * targetptr : a pointer to the vnode struct
895 * parentptr : a pointer to the parent of this vnode
896 * volptr : a pointer to the volume structure
897 * client : a pointer to the calling client
898 * cbv : struct containing the RX call for offline cancels
904 * Nothing interesting.
907 * Enables keepalives on the call.
908 *------------------------------------------------------------------------*/
910 PutVolumePackageWithCall(struct rx_call *acall, Vnode *
911 parentwhentargetnotdir, Vnode * targetptr,
912 Vnode * parentptr, Volume * volptr,
913 struct client **client, struct VCallByVol *cbv)
915 Error fileCode = 0; /* Error code returned by the volume package */
917 rx_KeepAliveOff(acall);
918 if (parentwhentargetnotdir) {
919 VPutVnode(&fileCode, parentwhentargetnotdir);
920 osi_Assert(!fileCode || (fileCode == VSALVAGE));
923 VPutVnode(&fileCode, targetptr);
924 osi_Assert(!fileCode || (fileCode == VSALVAGE));
927 VPutVnode(&fileCode, parentptr);
928 osi_Assert(!fileCode || (fileCode == VSALVAGE));
931 VPutVolumeWithCall(volptr, cbv);
933 rx_KeepAliveOn(acall);
938 } /*PutVolumePackage */
941 PutVolumePackage(struct rx_call *acall, Vnode * parentwhentargetnotdir,
942 Vnode * targetptr, Vnode * parentptr, Volume * volptr,
943 struct client **client)
945 PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
946 parentptr, volptr, client, NULL);
950 VolumeOwner(struct client *client, Vnode * targetptr)
952 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
955 return (client->ViceId == owner);
958 * We don't have to check for host's cps since only regular
959 * viceid are volume owners.
961 return (client_HasAsMember(client, owner));
967 VolumeRootVnode(Vnode * targetptr)
969 return ((targetptr->vnodeNumber == ROOTVNODE)
970 && (targetptr->disk.uniquifier == 1));
972 } /*VolumeRootVnode */
975 * Check if target file has the proper access permissions for the Fetch
976 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
977 * StoreStatus) related calls
979 /* this code should probably just set a "priv" flag where all the audit events
980 * are now, and only generate the audit event once at the end of the routine,
981 * thus only generating the event if all the checks succeed, but only because
982 * of the privilege XXX
985 Check_PermissionRights(Vnode * targetptr, struct client *client,
986 afs_int32 rights, int CallingRoutine,
987 AFSStoreStatus * InStatus)
990 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
991 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
992 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
994 if (CallingRoutine & CHK_FETCH) {
995 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
996 if (targetptr->disk.type == vDirectory
997 || targetptr->disk.type == vSymlink) {
998 if (!(rights & PRSFS_LOOKUP)
999 #ifdef ADMIN_IMPLICIT_LOOKUP
1000 /* grant admins fetch on all directories */
1001 && VanillaUser(client)
1002 #endif /* ADMIN_IMPLICIT_LOOKUP */
1003 && !VolumeOwner(client, targetptr))
1006 /* must have read access, or be owner and have insert access */
1007 if (!(rights & PRSFS_READ)
1008 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
1009 && (client->ViceId != AnonymousID))))
1012 if (CallingRoutine == CHK_FETCHDATA
1013 && targetptr->disk.type == vFile)
1014 #ifdef USE_GROUP_PERMS
1015 if (!OWNSp(client, targetptr)
1016 && !client_HasAsMember(client, targetptr->disk.owner)) {
1018 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
1022 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
1027 * The check with the ownership below is a kludge to allow
1028 * reading of files created with no read permission. The owner
1029 * of the file is always allowed to read it.
1031 if ((client->ViceId != targetptr->disk.owner)
1032 && VanillaUser(client))
1034 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
1035 modeBits) ? 0 : EACCES);
1037 } else { /* !VanillaUser(client) && !FetchData */
1039 osi_audit(PrivilegeEvent, 0, AUD_ID,
1040 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
1043 } else { /* a store operation */
1044 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1045 && (CallingRoutine != CHK_STOREACL)
1046 && (targetptr->disk.type == vFile)) {
1047 /* bypass protection checks on first store after a create
1048 * for the creator; also prevent chowns during this time
1049 * unless you are a system administrator */
1050 /****** InStatus->Owner && UnixModeBits better be SET!! */
1051 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1054 else if (VanillaUser(client))
1055 return (EPERM); /* Was EACCES */
1057 osi_audit(PrivilegeEvent, 0, AUD_ID,
1058 (client ? client->ViceId : 0), AUD_INT,
1059 CallingRoutine, AUD_END);
1062 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1063 osi_audit(PrivilegeEvent, 0, AUD_ID,
1064 (client ? client->ViceId : 0), AUD_INT,
1065 CallingRoutine, AUD_END);
1067 if (readonlyServer) {
1070 if (CallingRoutine == CHK_STOREACL) {
1071 if (!(rights & PRSFS_ADMINISTER)
1072 && !VolumeOwner(client, targetptr))
1074 } else { /* store data or status */
1075 /* watch for chowns and chgrps */
1076 if (CHOWN(InStatus, targetptr)
1077 || CHGRP(InStatus, targetptr)) {
1080 else if (VanillaUser(client))
1081 return (EPERM); /* Was EACCES */
1083 osi_audit(PrivilegeEvent, 0, AUD_ID,
1084 (client ? client->ViceId : 0), AUD_INT,
1085 CallingRoutine, AUD_END);
1087 /* must be sysadmin to set suid/sgid bits */
1088 if ((InStatus->Mask & AFS_SETMODE) &&
1090 (InStatus->UnixModeBits & 0xc00) != 0) {
1092 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1096 if (VanillaUser(client))
1099 osi_audit(PrivSetID, 0, AUD_ID,
1100 (client ? client->ViceId : 0), AUD_INT,
1101 CallingRoutine, AUD_END);
1103 if (CallingRoutine == CHK_STOREDATA) {
1106 if (!(rights & PRSFS_WRITE))
1108 /* Next thing is tricky. We want to prevent people
1109 * from writing files sans 0200 bit, but we want
1110 * creating new files with 0444 mode to work. We
1111 * don't check the 0200 bit in the "you are the owner"
1112 * path above, but here we check the bit. However, if
1113 * you're a system administrator, we ignore the 0200
1114 * bit anyway, since you may have fchowned the file,
1116 #ifdef USE_GROUP_PERMS
1117 if ((targetptr->disk.type == vFile)
1118 && VanillaUser(client)) {
1119 if (!OWNSp(client, targetptr)
1120 && !client_HasAsMember(client, targetptr->disk.owner)) {
1122 ((GROUPWRITE & targetptr->disk.modeBits)
1126 ((OWNERWRITE & targetptr->disk.modeBits)
1131 if ((targetptr->disk.type != vDirectory)
1132 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1135 if (VanillaUser(client))
1138 osi_audit(PrivilegeEvent, 0, AUD_ID,
1139 (client ? client->ViceId : 0),
1140 AUD_INT, CallingRoutine, AUD_END);
1142 } else { /* a status store */
1145 if (targetptr->disk.type == vDirectory) {
1146 if (!(rights & PRSFS_DELETE)
1147 && !(rights & PRSFS_INSERT))
1149 } else { /* a file or symlink */
1150 if (!(rights & PRSFS_WRITE))
1160 } /*Check_PermissionRights */
1164 * The Access List information is converted from its internal form in the
1165 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1166 * external form and returned back to the caller, via the AccessList
1170 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1171 struct AFSOpaque *AccessList)
1173 char *eACL; /* External access list placeholder */
1175 if (acl_Externalize_pr
1176 (hpr_IdToName, (targetptr->disk.type ==
1177 vDirectory ? VVnodeACL(targetptr) :
1178 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1181 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1182 acl_FreeExternalACL(&eACL);
1185 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1186 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1188 acl_FreeExternalACL(&eACL);
1191 } /*RXFetch_AccessList */
1195 * The Access List information is converted from its external form in the
1196 * input AccessList structure to the internal representation and copied into
1197 * the target dir's vnode storage.
1200 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1202 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1204 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1207 if ((newACL->size + 4) > VAclSize(targetptr))
1209 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1210 acl_FreeACL(&newACL);
1213 } /*RXStore_AccessList */
1216 /* In our current implementation, each successive data store (new file
1217 * data version) creates a new inode. This function creates the new
1218 * inode, copies the old inode's contents to the new one, remove the old
1219 * inode (i.e. decrement inode count -- if it's currently used the delete
1220 * will be delayed), and modify some fields (i.e. vnode's
1221 * disk.inodeNumber and cloned)
1223 #define COPYBUFFSIZE 8192
1224 #define MAXFSIZE (~(afs_fsize_t) 0)
1226 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1229 Inode nearInode AFS_UNUSED;
1236 int rc; /* return code */
1237 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1238 FdHandle_t *targFdP; /* Source Inode file handle */
1239 FdHandle_t *newFdP; /* Dest Inode file handle */
1241 if (targetptr->disk.type == vDirectory)
1242 DFlush(); /* just in case? */
1244 VN_GET_LEN(size, targetptr);
1252 buff = (char *)malloc(COPYBUFFSIZE);
1257 ino = VN_GET_INO(targetptr);
1258 if (!VALID_INO(ino)) {
1260 VTakeOffline(volptr);
1261 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1265 targFdP = IH_OPEN(targetptr->handle);
1266 if (targFdP == NULL) {
1269 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1270 targetptr->vnodeNumber, V_id(volptr), rc));
1272 VTakeOffline(volptr);
1276 nearInode = VN_GET_INO(targetptr);
1278 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1279 VPartitionPath(V_partition(volptr)), nearInode,
1280 V_id(volptr), targetptr->vnodeNumber,
1281 targetptr->disk.uniquifier,
1282 (int)targetptr->disk.dataVersion);
1283 if (!VALID_INO(ino)) {
1285 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1286 volptr->partition->name, V_id(volptr), errno));
1291 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1292 newFdP = IH_OPEN(newH);
1293 osi_Assert(newFdP != NULL);
1297 if (size > COPYBUFFSIZE) { /* more than a buffer */
1298 length = COPYBUFFSIZE;
1299 size -= COPYBUFFSIZE;
1304 rdlen = FDH_PREAD(targFdP, buff, length, done);
1305 if (rdlen == length) {
1306 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1310 /* Callers of this function are not prepared to recover
1311 * from error that put the filesystem in an inconsistent
1312 * state. Make sure that we force the volume off-line if
1313 * we some error other than ENOSPC - 4.29.99)
1315 * In case we are unable to write the required bytes, and the
1316 * error code indicates that the disk is full, we roll-back to
1317 * the initial state.
1319 if ((rdlen != length) || (wrlen != length)) {
1320 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1322 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1323 volptr->partition->name, V_id(volptr)));
1324 /* remove destination inode which was partially copied till now */
1325 FDH_REALLYCLOSE(newFdP);
1327 FDH_REALLYCLOSE(targFdP);
1328 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1331 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1332 rc, V_id(volptr), volptr->partition->name));
1333 VTakeOffline(volptr);
1338 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1339 * since we never do any I/O anywhere near 2^32 bytes at a
1340 * time, just case to an unsigned int for printing */
1343 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1344 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1345 (unsigned)wrlen, errno));
1346 #if defined(AFS_DEMAND_ATTACH_FS)
1347 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1349 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1351 /* Decrement this inode so salvager doesn't find it. */
1352 FDH_REALLYCLOSE(newFdP);
1354 FDH_REALLYCLOSE(targFdP);
1355 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1357 VTakeOffline(volptr);
1362 FDH_REALLYCLOSE(targFdP);
1363 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1364 V_parentId(volptr));
1366 IH_RELEASE(targetptr->handle);
1368 rc = FDH_SYNC(newFdP);
1369 osi_Assert(rc == 0);
1371 targetptr->handle = newH;
1372 VN_SET_INO(targetptr, ino);
1373 targetptr->disk.cloned = 0;
1374 /* Internal change to vnode, no user level change to volume - def 5445 */
1375 targetptr->changed_oldTime = 1;
1377 return 0; /* success */
1381 * Common code to handle with removing the Name (file when it's called from
1382 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1383 * given directory, parentptr.
1385 int DT1 = 0, DT0 = 0;
1387 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1388 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1390 DirHandle childdir; /* Handle for dir package I/O */
1391 Error errorCode = 0;
1395 /* watch for invalid names */
1396 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1399 if (CheckLength(volptr, parentptr, -1)) {
1400 VTakeOffline(volptr);
1404 if (parentptr->disk.cloned) {
1405 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1406 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1408 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1414 /* check that the file is in the directory */
1415 SetDirHandle(dir, parentptr);
1416 if (afs_dir_Lookup(dir, Name, fileFid))
1418 fileFid->Volume = V_id(volptr);
1420 /* just-in-case check for something causing deadlock */
1421 if (fileFid->Vnode == parentptr->vnodeNumber)
1424 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1428 if (ChkForDir == MustBeDIR) {
1429 if ((*targetptr)->disk.type != vDirectory)
1431 } else if ((*targetptr)->disk.type == vDirectory)
1434 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1436 * If the uniquifiers dont match then instead of asserting
1437 * take the volume offline and return VSALVAGE
1439 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1440 VTakeOffline(volptr);
1442 ("Volume %u now offline, must be salvaged.\n",
1444 errorCode = VSALVAGE;
1448 if (ChkForDir == MustBeDIR) {
1449 SetDirHandle(&childdir, *targetptr);
1450 if (afs_dir_IsEmpty(&childdir) != 0)
1454 (*targetptr)->delete = 1;
1455 } else if ((--(*targetptr)->disk.linkCount) == 0)
1456 (*targetptr)->delete = 1;
1457 if ((*targetptr)->delete) {
1458 if (VN_GET_INO(*targetptr)) {
1460 IH_REALLYCLOSE((*targetptr)->handle);
1462 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1463 V_parentId(volptr));
1464 IH_RELEASE((*targetptr)->handle);
1465 if (errorCode == -1) {
1467 ("DT: inode=%s, name=%s, errno=%d\n",
1468 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1470 if (errno != ENOENT)
1472 VTakeOffline(volptr);
1474 ("Volume %u now offline, must be salvaged.\n",
1482 VN_SET_INO(*targetptr, (Inode) 0);
1484 afs_fsize_t adjLength;
1485 VN_GET_LEN(adjLength, *targetptr);
1486 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1490 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1492 code = afs_dir_Delete(dir, Name);
1495 ("Error %d deleting %s\n", code,
1496 (((*targetptr)->disk.type ==
1497 Directory) ? "directory" : "file")));
1498 VTakeOffline(volptr);
1500 ("Volume %u now offline, must be salvaged.\n",
1513 * This routine updates the parent directory's status block after the
1514 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1515 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1519 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1520 int author, int linkcount, char a_inSameNetwork)
1522 afs_fsize_t newlength; /* Holds new directory length */
1523 afs_fsize_t parentLength;
1525 Date currDate; /*Current date */
1526 int writeIdx; /*Write index to bump */
1527 int timeIdx; /*Authorship time index to bump */
1529 parentptr->disk.dataVersion++;
1530 newlength = (afs_fsize_t) afs_dir_Length(dir);
1532 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1533 * (create, symlink, link, makedir) so we need to check if we have enough space
1534 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1535 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1537 VN_GET_LEN(parentLength, parentptr);
1538 if (nBlocks(newlength) != nBlocks(parentLength)) {
1539 VAdjustDiskUsage(&errorCode, volptr,
1540 (nBlocks(newlength) - nBlocks(parentLength)),
1541 (nBlocks(newlength) - nBlocks(parentLength)));
1543 VN_SET_LEN(parentptr, newlength);
1546 * Update directory write stats for this volume. Note that the auth
1547 * counter is located immediately after its associated ``distance''
1550 if (a_inSameNetwork)
1551 writeIdx = VOL_STATS_SAME_NET;
1553 writeIdx = VOL_STATS_DIFF_NET;
1554 V_stat_writes(volptr, writeIdx)++;
1555 if (author != AnonymousID) {
1556 V_stat_writes(volptr, writeIdx + 1)++;
1560 * Update the volume's authorship information in response to this
1561 * directory operation. Get the current time, decide to which time
1562 * slot this operation belongs, and bump the appropriate slot.
1564 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1566 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1567 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1568 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1569 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1570 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1571 if (parentptr->disk.author == author) {
1572 V_stat_dirSameAuthor(volptr, timeIdx)++;
1574 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1577 parentptr->disk.author = author;
1578 parentptr->disk.linkCount = linkcount;
1579 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1580 parentptr->disk.serverModifyTime = FT_ApproxTime();
1581 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1586 * Update the target file's (or dir's) status block after the specified
1587 * operation is complete. Note that some other fields maybe updated by
1588 * the individual module.
1591 /* XXX INCOMPLETE - More attention is needed here! */
1593 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1594 struct client *client, AFSStoreStatus * InStatus,
1595 Vnode * parentptr, Volume * volptr,
1598 Date currDate; /*Current date */
1599 int writeIdx; /*Write index to bump */
1600 int timeIdx; /*Authorship time index to bump */
1602 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1603 targetptr->disk.parent = parentptr->vnodeNumber;
1604 VN_SET_LEN(targetptr, length);
1605 /* targetptr->disk.group = 0; save some cycles */
1606 targetptr->disk.modeBits = 0777;
1607 targetptr->disk.owner = client->ViceId;
1608 targetptr->disk.dataVersion = 0; /* consistent with the client */
1609 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1610 /* the inode was created in Alloc_NewVnode() */
1613 * Update file write stats for this volume. Note that the auth
1614 * counter is located immediately after its associated ``distance''
1617 if (client->InSameNetwork)
1618 writeIdx = VOL_STATS_SAME_NET;
1620 writeIdx = VOL_STATS_DIFF_NET;
1621 V_stat_writes(volptr, writeIdx)++;
1622 if (client->ViceId != AnonymousID) {
1623 V_stat_writes(volptr, writeIdx + 1)++;
1627 * We only count operations that DON'T involve creating new objects
1628 * (files, symlinks, directories) or simply setting status as
1629 * authorship-change operations.
1631 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1633 * Update the volume's authorship information in response to this
1634 * file operation. Get the current time, decide to which time
1635 * slot this operation belongs, and bump the appropriate slot.
1637 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1640 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1641 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1642 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1643 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1644 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1645 VOL_STATS_TIME_IDX_5);
1646 if (targetptr->disk.author == client->ViceId) {
1647 V_stat_fileSameAuthor(volptr, timeIdx)++;
1649 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1653 if (!(Caller & TVS_SSTATUS))
1654 targetptr->disk.author = client->ViceId;
1655 if (Caller & TVS_SDATA) {
1656 targetptr->disk.dataVersion++;
1657 if (VanillaUser(client)) {
1658 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1659 #ifdef CREATE_SGUID_ADMIN_ONLY
1660 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1664 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1665 /* store status, must explicitly request to change the date */
1666 if (InStatus->Mask & AFS_SETMODTIME)
1667 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1668 } else { /* other: date always changes, but perhaps to what is specified by caller */
1669 targetptr->disk.unixModifyTime =
1670 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1671 ClientModTime : FT_ApproxTime());
1673 if (InStatus->Mask & AFS_SETOWNER) {
1674 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1675 if (VanillaUser(client)) {
1676 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1677 #ifdef CREATE_SGUID_ADMIN_ONLY
1678 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1681 targetptr->disk.owner = InStatus->Owner;
1682 if (VolumeRootVnode(targetptr)) {
1683 Error errorCode = 0; /* what should be done with this? */
1685 V_owner(targetptr->volumePtr) = InStatus->Owner;
1686 VUpdateVolume(&errorCode, targetptr->volumePtr);
1689 if (InStatus->Mask & AFS_SETMODE) {
1690 int modebits = InStatus->UnixModeBits;
1691 #define CREATE_SGUID_ADMIN_ONLY 1
1692 #ifdef CREATE_SGUID_ADMIN_ONLY
1693 if (VanillaUser(client))
1694 modebits = modebits & 0777;
1696 if (VanillaUser(client)) {
1697 targetptr->disk.modeBits = modebits;
1699 targetptr->disk.modeBits = modebits;
1702 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1703 CHK_STOREDATA, AUD_END);
1707 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1708 CHK_STORESTATUS, AUD_END);
1715 targetptr->disk.serverModifyTime = FT_ApproxTime();
1716 if (InStatus->Mask & AFS_SETGROUP)
1717 targetptr->disk.group = InStatus->Group;
1718 /* vnode changed : to be written back by VPutVnode */
1719 targetptr->changed_newTime = 1;
1721 } /*Update_TargetVnodeStatus */
1725 * Fills the CallBack structure with the expiration time and type of callback
1726 * structure. Warning: this function is currently incomplete.
1729 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1731 /* CallBackTime could not be 0 */
1732 if (CallBackTime == 0) {
1733 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1734 CallBack->ExpirationTime = 0;
1736 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1737 CallBack->CallBackVersion = CALLBACK_VERSION;
1738 CallBack->CallBackType = CB_SHARED; /* The default for now */
1740 } /*SetCallBackStruct */
1744 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1745 * allocation; if some error occured (exceeded volume quota or partition
1746 * was full, or whatever), it frees the space back and returns the code.
1747 * We usually pre-adjust the volume space to make sure that there's
1748 * enough space before consuming some.
1751 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1752 afs_sfsize_t checkLength)
1757 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1759 VAdjustDiskUsage(&nc, volptr, -length, 0);
1760 if (rc == VOVERQUOTA) {
1762 ("Volume %u (%s) is full\n", V_id(volptr),
1766 if (rc == VDISKFULL) {
1768 ("Partition %s that contains volume %u is full\n",
1769 volptr->partition->name, V_id(volptr)));
1772 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1777 } /*AdjustDiskUsage */
1780 * Common code that handles the creation of a new file (SAFS_CreateFile and
1781 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1784 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1785 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1786 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1788 Error errorCode = 0; /* Error code returned back */
1791 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1795 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1796 BlocksPreallocatedForVnode))) {
1798 ("Insufficient space to allocate %lld blocks\n",
1799 (afs_intmax_t) BlocksPreallocatedForVnode));
1803 if (CheckLength(volptr, parentptr, -1)) {
1804 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1805 VTakeOffline(volptr);
1809 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1810 if (errorCode != 0) {
1811 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1814 OutFid->Volume = V_id(volptr);
1815 OutFid->Vnode = (*targetptr)->vnodeNumber;
1816 OutFid->Unique = (*targetptr)->disk.uniquifier;
1818 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1820 /* create the inode now itself */
1822 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1823 VPartitionPath(V_partition(volptr)), nearInode,
1824 V_id(volptr), (*targetptr)->vnodeNumber,
1825 (*targetptr)->disk.uniquifier, 1);
1827 /* error in creating inode */
1828 if (!VALID_INO(inode)) {
1830 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1831 (*targetptr)->volumePtr->header->diskstuff.id,
1832 (*targetptr)->vnodeNumber, errno));
1833 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1834 (*targetptr)->delete = 1; /* delete vnode */
1837 VN_SET_INO(*targetptr, inode);
1838 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1840 /* copy group from parent dir */
1841 (*targetptr)->disk.group = parentptr->disk.group;
1843 if (parentptr->disk.cloned) {
1844 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1845 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1846 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1847 /* delete the vnode previously allocated */
1848 (*targetptr)->delete = 1;
1849 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1850 IH_REALLYCLOSE((*targetptr)->handle);
1851 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1853 ("Alloc_NewVnode: partition %s idec %s failed\n",
1854 volptr->partition->name, PrintInode(stmp, inode)));
1855 IH_RELEASE((*targetptr)->handle);
1861 /* add the name to the directory */
1862 SetDirHandle(dir, parentptr);
1863 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1864 (*targetptr)->delete = 1;
1865 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1866 IH_REALLYCLOSE((*targetptr)->handle);
1867 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1869 ("Alloc_NewVnode: partition %s idec %s failed\n",
1870 volptr->partition->name, PrintInode(stmp, inode)));
1871 IH_RELEASE((*targetptr)->handle);
1877 } /*Alloc_NewVnode */
1881 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1885 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1887 int Time; /* Used for time */
1888 int writeVnode = targetptr->changed_oldTime; /* save original status */
1890 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1891 Time = FT_ApproxTime();
1892 switch (LockingType) {
1895 if (Time > targetptr->disk.lock.lockTime)
1896 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1898 Time += AFS_LOCKWAIT;
1899 if (LockingType == LockRead) {
1900 if ( !(rights & PRSFS_LOCK) &&
1901 !(rights & PRSFS_WRITE) &&
1902 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1905 if (targetptr->disk.lock.lockCount >= 0) {
1906 ++(targetptr->disk.lock.lockCount);
1907 targetptr->disk.lock.lockTime = Time;
1910 } else if (LockingType == LockWrite) {
1911 if ( !(rights & PRSFS_WRITE) &&
1912 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1915 if (targetptr->disk.lock.lockCount == 0) {
1916 targetptr->disk.lock.lockCount = -1;
1917 targetptr->disk.lock.lockTime = Time;
1923 Time += AFS_LOCKWAIT;
1924 if (targetptr->disk.lock.lockCount != 0)
1925 targetptr->disk.lock.lockTime = Time;
1930 if ((--targetptr->disk.lock.lockCount) <= 0)
1931 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1935 targetptr->changed_oldTime = writeVnode; /* restore old status */
1936 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1939 } /*HandleLocking */
1941 /* 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. */
1944 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1948 if (!(rights & Prfs_Mode))
1950 if ((targetptr->disk.type != vDirectory)
1951 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1957 * If some flags (i.e. min or max quota) are set, the volume's in disk
1958 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1959 * update, if applicable.
1962 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1963 char *Name, char *OfflineMsg, char *Motd)
1965 Error errorCode = 0;
1967 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1968 V_minquota(volptr) = StoreVolStatus->MinQuota;
1969 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1970 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1971 if (strlen(OfflineMsg) > 0) {
1972 strcpy(V_offlineMessage(volptr), OfflineMsg);
1974 if (strlen(Name) > 0) {
1975 strcpy(V_name(volptr), Name);
1978 * We don't overwrite the motd field, since it's now being used
1981 VUpdateVolume(&errorCode, volptr);
1984 } /*RXUpdate_VolumeStatus */
1988 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1989 char **motd, Volume * volptr)
1993 status->Vid = V_id(volptr);
1994 status->ParentId = V_parentId(volptr);
1995 status->Online = V_inUse(volptr);
1996 status->InService = V_inService(volptr);
1997 status->Blessed = V_blessed(volptr);
1998 status->NeedsSalvage = V_needsSalvaged(volptr);
1999 if (VolumeWriteable(volptr))
2000 status->Type = ReadWrite;
2002 status->Type = ReadOnly;
2003 status->MinQuota = V_minquota(volptr);
2004 status->MaxQuota = V_maxquota(volptr);
2005 status->BlocksInUse = V_diskused(volptr);
2006 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
2007 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
2009 /* now allocate and copy these things; they're freed by the RXGEN stub */
2010 temp = strlen(V_name(volptr)) + 1;
2011 *name = malloc(temp);
2013 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2015 strcpy(*name, V_name(volptr));
2016 temp = strlen(V_offlineMessage(volptr)) + 1;
2017 *offMsg = malloc(temp);
2019 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2021 strcpy(*offMsg, V_offlineMessage(volptr));
2024 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2026 strcpy(*motd, nullString);
2028 } /*RXGetVolumeStatus */
2032 FileNameOK(char *aname)
2037 /* watch for @sys on the right */
2038 if (strcmp(aname + i - 4, "@sys") == 0)
2041 while ((tc = *aname++)) {
2043 return 0; /* very bad character to encounter */
2045 return 1; /* file name is ok */
2051 * This variant of symlink is expressly to support the AFS/DFS translator
2052 * and is not supported by the AFS fileserver. We just return EINVAL.
2053 * The cache manager should not generate this call to an AFS cache manager.
2056 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2057 char *LinkContents, struct AFSStoreStatus *InStatus,
2058 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2059 struct AFSFetchStatus *OutDirStatus,
2060 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2066 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2067 struct FsCmdInputs * Inputs,
2068 struct FsCmdOutputs * Outputs)
2072 switch (Inputs->command) {
2076 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2077 Inputs->command, Outputs->code));
2082 static struct afs_buffer {
2083 struct afs_buffer *next;
2084 } *freeBufferList = 0;
2085 static int afs_buffersAlloced = 0;
2088 FreeSendBuffer(struct afs_buffer *adata)
2091 afs_buffersAlloced--;
2092 adata->next = freeBufferList;
2093 freeBufferList = adata;
2097 } /*FreeSendBuffer */
2099 /* allocate space for sender */
2101 AllocSendBuffer(void)
2103 struct afs_buffer *tp;
2106 afs_buffersAlloced++;
2107 if (!freeBufferList) {
2110 tmp = malloc(sendBufSize);
2112 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2116 tp = freeBufferList;
2117 freeBufferList = tp->next;
2121 } /*AllocSendBuffer */
2122 #endif /* HAVE_PIOV */
2125 * This routine returns the status info associated with the targetptr vnode
2126 * in the AFSFetchStatus structure. Some of the newer fields, such as
2127 * SegSize and Group are not yet implemented
2131 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2132 afs_int32 anyrights, Vnode * parentptr)
2134 int Time =FT_ApproxTime();
2136 /* initialize return status from a vnode */
2137 status->InterfaceVersion = 1;
2138 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2139 status->errorCode = 0;
2140 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2141 if (targetptr->disk.type == vFile)
2142 status->FileType = File;
2143 else if (targetptr->disk.type == vDirectory)
2144 status->FileType = Directory;
2145 else if (targetptr->disk.type == vSymlink)
2146 status->FileType = SymbolicLink;
2148 status->FileType = Invalid; /*invalid type field */
2149 status->LinkCount = targetptr->disk.linkCount;
2151 afs_fsize_t targetLen;
2152 VN_GET_LEN(targetLen, targetptr);
2153 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2155 status->DataVersion = targetptr->disk.dataVersion;
2156 status->Author = targetptr->disk.author;
2157 status->Owner = targetptr->disk.owner;
2158 status->CallerAccess = rights;
2159 status->AnonymousAccess = anyrights;
2160 status->UnixModeBits = targetptr->disk.modeBits;
2161 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2162 status->ParentVnode =
2163 (status->FileType ==
2164 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2165 status->ParentUnique =
2166 (status->FileType ==
2167 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2168 status->ServerModTime = targetptr->disk.serverModifyTime;
2169 status->Group = targetptr->disk.group;
2170 status->lockCount = Time > targetptr->disk.lock.lockTime ? 0 : targetptr->disk.lock.lockCount;
2171 status->errorCode = 0;
2176 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2177 afs_sfsize_t Pos, afs_sfsize_t Len,
2178 struct AFSFetchStatus *OutStatus,
2179 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2182 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2183 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2184 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2185 Error errorCode = 0; /* return code to caller */
2186 Error fileCode = 0; /* return code from vol package */
2187 Volume *volptr = 0; /* pointer to the volume */
2188 struct client *client = 0; /* pointer to the client data */
2189 struct rx_connection *tcon; /* the connection we're part of */
2191 afs_int32 rights, anyrights; /* rights for this and any user */
2192 struct client *t_client = NULL; /* tmp ptr to client data */
2193 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2194 struct VCallByVol tcbv, *cbv = NULL;
2195 static int remainder = 0; /* shared access protected by FS_LOCK */
2196 struct fsstats fsstats;
2197 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2198 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2199 int readIdx; /* Index of read stats array to bump */
2201 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2204 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2207 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2209 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2212 /* Get ptr to client data for user Id for logging */
2213 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2214 logHostAddr.s_addr = rxr_HostOf(tcon);
2216 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2217 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2218 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2220 queue_NodeInit(&tcbv);
2225 * Get volume/vnode for the fetched file; caller's access rights to
2226 * it are also returned
2229 GetVolumePackageWithCall(acall, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2230 &parentwhentargetnotdir, &client, READ_LOCK,
2231 &rights, &anyrights)))
2234 SetVolumeSync(Sync, volptr);
2237 * Remember that another read operation was performed.
2240 if (client->InSameNetwork)
2241 readIdx = VOL_STATS_SAME_NET;
2243 readIdx = VOL_STATS_DIFF_NET;
2244 V_stat_reads(volptr, readIdx)++;
2245 if (client->ViceId != AnonymousID) {
2246 V_stat_reads(volptr, readIdx + 1)++;
2249 /* Check whether the caller has permission access to fetch the data */
2251 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2255 * Drop the read lock on the parent directory after saving the parent
2256 * vnode information we need to pass to GetStatus
2258 if (parentwhentargetnotdir != NULL) {
2259 tparentwhentargetnotdir = *parentwhentargetnotdir;
2260 VPutVnode(&fileCode, parentwhentargetnotdir);
2261 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2262 parentwhentargetnotdir = NULL;
2265 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
2267 /* actually do the data transfer */
2269 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2270 &bytesToXfer, &bytesXferred);
2272 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2278 /* write back the OutStatus from the target vnode */
2279 GetStatus(targetptr, OutStatus, rights, anyrights,
2280 &tparentwhentargetnotdir);
2282 rx_KeepAliveOn(acall); /* I/O done */
2284 /* if a r/w volume, promise a callback to the caller */
2285 if (VolumeWriteable(volptr))
2286 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2288 struct AFSFid myFid;
2289 memset(&myFid, 0, sizeof(struct AFSFid));
2290 myFid.Volume = Fid->Volume;
2291 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2295 /* Update and store volume/vnode and parent vnodes back */
2296 (void)PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
2297 (Vnode *) 0, volptr, &client, cbv);
2298 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2299 errorCode = CallPostamble(tcon, errorCode, thost);
2301 fsstats_FinishOp(&fsstats, errorCode);
2303 osi_auditU(acall, FetchDataEvent, errorCode,
2304 AUD_ID, t_client ? t_client->ViceId : 0,
2305 AUD_FID, Fid, AUD_END);
2308 } /*SRXAFS_FetchData */
2311 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2312 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2313 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2315 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2320 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2321 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2322 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2325 afs_sfsize_t tPos, tLen;
2327 tPos = (afs_sfsize_t) Pos;
2328 tLen = (afs_sfsize_t) Len;
2331 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2337 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2338 struct AFSOpaque * AccessList,
2339 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2341 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2342 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2343 Error errorCode = 0; /* return error code to caller */
2344 Volume *volptr = 0; /* pointer to the volume */
2345 struct client *client = 0; /* pointer to the client data */
2346 afs_int32 rights, anyrights; /* rights for this and any user */
2347 struct rx_connection *tcon = rx_ConnectionOf(acall);
2349 struct client *t_client = NULL; /* tmp ptr to client data */
2350 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2351 struct fsstats fsstats;
2353 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2356 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2359 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2361 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2364 /* Get ptr to client data for user Id for logging */
2365 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2366 logHostAddr.s_addr = rxr_HostOf(tcon);
2368 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2369 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2370 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2372 AccessList->AFSOpaque_len = 0;
2373 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2374 if (!AccessList->AFSOpaque_val) {
2375 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2379 * Get volume/vnode for the fetched file; caller's access rights to it
2383 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2384 &parentwhentargetnotdir, &client, READ_LOCK,
2385 &rights, &anyrights)))
2388 SetVolumeSync(Sync, volptr);
2390 /* Check whether we have permission to fetch the ACL */
2392 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2395 /* Get the Access List from the dir's vnode */
2397 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2400 /* Get OutStatus back From the target Vnode */
2401 GetStatus(targetptr, OutStatus, rights, anyrights,
2402 parentwhentargetnotdir);
2405 /* Update and store volume/vnode and parent vnodes back */
2406 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2407 (Vnode *) 0, volptr, &client);
2409 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2410 AccessList->AFSOpaque_val));
2411 errorCode = CallPostamble(tcon, errorCode, thost);
2413 fsstats_FinishOp(&fsstats, errorCode);
2415 osi_auditU(acall, FetchACLEvent, errorCode,
2416 AUD_ID, t_client ? t_client->ViceId : 0,
2418 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2420 } /*SRXAFS_FetchACL */
2424 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2425 * merged into it when possible.
2428 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2429 struct AFSFetchStatus *OutStatus,
2430 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2432 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2433 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2434 Error errorCode = 0; /* return code to caller */
2435 Volume *volptr = 0; /* pointer to the volume */
2436 struct client *client = 0; /* pointer to the client data */
2437 afs_int32 rights, anyrights; /* rights for this and any user */
2438 struct client *t_client = NULL; /* tmp ptr to client data */
2439 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2440 struct rx_connection *tcon = rx_ConnectionOf(acall);
2442 /* Get ptr to client data for user Id for logging */
2443 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2444 logHostAddr.s_addr = rxr_HostOf(tcon);
2446 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2447 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2448 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2450 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2453 * Get volume/vnode for the fetched file; caller's rights to it are
2457 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2458 &parentwhentargetnotdir, &client, READ_LOCK,
2459 &rights, &anyrights)))
2460 goto Bad_FetchStatus;
2462 rx_KeepAliveOn(acall);
2464 /* set volume synchronization information */
2465 SetVolumeSync(Sync, volptr);
2467 /* Are we allowed to fetch Fid's status? */
2468 if (targetptr->disk.type != vDirectory) {
2470 Check_PermissionRights(targetptr, client, rights,
2471 CHK_FETCHSTATUS, 0))) {
2472 if (rx_GetCallAbortCode(acall) == errorCode)
2473 rx_SetCallAbortCode(acall, 0);
2474 goto Bad_FetchStatus;
2478 /* set OutStatus From the Fid */
2479 GetStatus(targetptr, OutStatus, rights, anyrights,
2480 parentwhentargetnotdir);
2482 /* If a r/w volume, also set the CallBack state */
2483 if (VolumeWriteable(volptr))
2484 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2486 struct AFSFid myFid;
2487 memset(&myFid, 0, sizeof(struct AFSFid));
2488 myFid.Volume = Fid->Volume;
2489 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2493 /* Update and store volume/vnode and parent vnodes back */
2494 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2495 (Vnode *) 0, volptr, &client);
2496 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2499 } /*SAFSS_FetchStatus */
2503 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2504 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2505 struct AFSVolSync * Sync)
2509 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2510 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2511 Error errorCode = 0; /* return code to caller */
2512 Volume *volptr = 0; /* pointer to the volume */
2513 struct client *client = 0; /* pointer to the client data */
2514 afs_int32 rights, anyrights; /* rights for this and any user */
2515 struct AFSFid *tfid; /* file id we're dealing with now */
2516 struct rx_connection *tcon = rx_ConnectionOf(acall);
2518 struct client *t_client = NULL; /* tmp pointer to the client data */
2519 struct fsstats fsstats;
2521 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2523 ViceLog(1, ("SAFS_BulkStatus\n"));
2525 AFSCallStats.TotalCalls++;
2527 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2528 if (nfiles <= 0) { /* Sanity check */
2530 goto Audit_and_Return;
2533 /* allocate space for return output parameters */
2534 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2535 malloc(nfiles * sizeof(struct AFSFetchStatus));
2536 if (!OutStats->AFSBulkStats_val) {
2537 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2539 OutStats->AFSBulkStats_len = nfiles;
2540 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2541 malloc(nfiles * sizeof(struct AFSCallBack));
2542 if (!CallBacks->AFSCBs_val) {
2543 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2545 CallBacks->AFSCBs_len = nfiles;
2547 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2548 goto Bad_BulkStatus;
2550 tfid = Fids->AFSCBFids_val;
2551 for (i = 0; i < nfiles; i++, tfid++) {
2553 * Get volume/vnode for the fetched file; caller's rights to it
2557 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2558 &parentwhentargetnotdir, &client, READ_LOCK,
2559 &rights, &anyrights)))
2560 goto Bad_BulkStatus;
2562 rx_KeepAliveOn(acall);
2564 /* set volume synchronization information, but only once per call */
2566 SetVolumeSync(Sync, volptr);
2568 /* Are we allowed to fetch Fid's status? */
2569 if (targetptr->disk.type != vDirectory) {
2571 Check_PermissionRights(targetptr, client, rights,
2572 CHK_FETCHSTATUS, 0))) {
2573 if (rx_GetCallAbortCode(acall) == errorCode)
2574 rx_SetCallAbortCode(acall, 0);
2575 goto Bad_BulkStatus;
2579 /* set OutStatus From the Fid */
2580 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2581 anyrights, parentwhentargetnotdir);
2583 /* If a r/w volume, also set the CallBack state */
2584 if (VolumeWriteable(volptr))
2585 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2586 &CallBacks->AFSCBs_val[i]);
2588 struct AFSFid myFid;
2589 memset(&myFid, 0, sizeof(struct AFSFid));
2590 myFid.Volume = tfid->Volume;
2591 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2592 &CallBacks->AFSCBs_val[i]);
2595 /* put back the file ID and volume */
2596 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2597 (Vnode *) 0, volptr, &client);
2598 parentwhentargetnotdir = (Vnode *) 0;
2599 targetptr = (Vnode *) 0;
2600 volptr = (Volume *) 0;
2601 client = (struct client *)0;
2605 /* Update and store volume/vnode and parent vnodes back */
2606 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2607 (Vnode *) 0, volptr, &client);
2608 errorCode = CallPostamble(tcon, errorCode, thost);
2610 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2612 fsstats_FinishOp(&fsstats, errorCode);
2615 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2616 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2617 AUD_ID, t_client ? t_client->ViceId : 0,
2618 AUD_FIDS, Fids, AUD_END);
2621 } /*SRXAFS_BulkStatus */
2625 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2626 struct AFSBulkStats * OutStats,
2627 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2631 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2632 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2633 Error errorCode = 0; /* return code to caller */
2634 Volume *volptr = 0; /* pointer to the volume */
2635 struct client *client = 0; /* pointer to the client data */
2636 afs_int32 rights, anyrights; /* rights for this and any user */
2637 struct AFSFid *tfid; /* file id we're dealing with now */
2638 struct rx_connection *tcon;
2640 struct client *t_client = NULL; /* tmp ptr to client data */
2641 AFSFetchStatus *tstatus;
2642 int VolSync_set = 0;
2643 struct fsstats fsstats;
2645 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2647 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2649 AFSCallStats.TotalCalls++;
2651 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2652 if (nfiles <= 0) { /* Sanity check */
2654 goto Audit_and_Return;
2657 /* allocate space for return output parameters */
2658 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2659 malloc(nfiles * sizeof(struct AFSFetchStatus));
2660 if (!OutStats->AFSBulkStats_val) {
2661 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2663 OutStats->AFSBulkStats_len = nfiles;
2664 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2665 malloc(nfiles * sizeof(struct AFSCallBack));
2666 if (!CallBacks->AFSCBs_val) {
2667 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2669 CallBacks->AFSCBs_len = nfiles;
2671 /* Zero out return values to avoid leaking information on partial succes */
2672 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2673 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2674 memset(Sync, 0, sizeof(*Sync));
2676 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2677 goto Bad_InlineBulkStatus;
2680 tfid = Fids->AFSCBFids_val;
2681 for (i = 0; i < nfiles; i++, tfid++) {
2683 * Get volume/vnode for the fetched file; caller's rights to it
2687 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2688 &parentwhentargetnotdir, &client, READ_LOCK,
2689 &rights, &anyrights))) {
2690 tstatus = &OutStats->AFSBulkStats_val[i];
2691 tstatus->errorCode = errorCode;
2692 PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2693 (Vnode *) 0, volptr, &client);
2694 parentwhentargetnotdir = (Vnode *) 0;
2695 targetptr = (Vnode *) 0;
2696 volptr = (Volume *) 0;
2697 client = (struct client *)0;
2701 rx_KeepAliveOn(acall);
2703 /* set volume synchronization information, but only once per call */
2705 SetVolumeSync(Sync, volptr);
2709 /* Are we allowed to fetch Fid's status? */
2710 if (targetptr->disk.type != vDirectory) {
2712 Check_PermissionRights(targetptr, client, rights,
2713 CHK_FETCHSTATUS, 0))) {
2714 tstatus = &OutStats->AFSBulkStats_val[i];
2715 tstatus->errorCode = errorCode;
2716 (void)PutVolumePackage(acall, parentwhentargetnotdir,
2717 targetptr, (Vnode *) 0, volptr,
2719 parentwhentargetnotdir = (Vnode *) 0;
2720 targetptr = (Vnode *) 0;
2721 volptr = (Volume *) 0;
2722 client = (struct client *)0;
2727 /* set OutStatus From the Fid */
2728 GetStatus(targetptr,
2729 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2730 rights, anyrights, parentwhentargetnotdir);
2732 /* If a r/w volume, also set the CallBack state */
2733 if (VolumeWriteable(volptr))
2734 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2735 &CallBacks->AFSCBs_val[i]);
2737 struct AFSFid myFid;
2738 memset(&myFid, 0, sizeof(struct AFSFid));
2739 myFid.Volume = tfid->Volume;
2740 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2741 &CallBacks->AFSCBs_val[i]);
2744 /* put back the file ID and volume */
2745 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2746 (Vnode *) 0, volptr, &client);
2747 parentwhentargetnotdir = (Vnode *) 0;
2748 targetptr = (Vnode *) 0;
2749 volptr = (Volume *) 0;
2750 client = (struct client *)0;
2753 Bad_InlineBulkStatus:
2754 /* Update and store volume/vnode and parent vnodes back */
2755 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2756 (Vnode *) 0, volptr, &client);
2757 errorCode = CallPostamble(tcon, errorCode, thost);
2759 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2761 fsstats_FinishOp(&fsstats, errorCode);
2764 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2765 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2766 AUD_ID, t_client ? t_client->ViceId : 0,
2767 AUD_FIDS, Fids, AUD_END);
2770 } /*SRXAFS_InlineBulkStatus */
2774 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2775 struct AFSFetchStatus * OutStatus,
2776 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2779 struct rx_connection *tcon;
2781 struct client *t_client = NULL; /* tmp ptr to client data */
2782 struct fsstats fsstats;
2784 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2786 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2787 goto Bad_FetchStatus;
2789 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2792 code = CallPostamble(tcon, code, thost);
2794 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2796 fsstats_FinishOp(&fsstats, code);
2798 osi_auditU(acall, FetchStatusEvent, code,
2799 AUD_ID, t_client ? t_client->ViceId : 0,
2800 AUD_FID, Fid, AUD_END);
2803 } /*SRXAFS_FetchStatus */
2807 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2808 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2809 afs_fsize_t Length, afs_fsize_t FileLength,
2810 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2812 Vnode *targetptr = 0; /* pointer to input fid */
2813 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2814 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2815 Error errorCode = 0; /* return code for caller */
2816 Error fileCode = 0; /* return code from vol package */
2817 Volume *volptr = 0; /* pointer to the volume header */
2818 struct client *client = 0; /* pointer to client structure */
2819 afs_int32 rights, anyrights; /* rights for this and any user */
2820 struct client *t_client = NULL; /* tmp ptr to client data */
2821 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2822 struct rx_connection *tcon;
2824 struct fsstats fsstats;
2825 afs_sfsize_t bytesToXfer;
2826 afs_sfsize_t bytesXferred;
2827 static int remainder = 0;
2830 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2833 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2836 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2838 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2841 /* Get ptr to client data for user Id for logging */
2842 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2843 logHostAddr.s_addr = rxr_HostOf(tcon);
2845 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2846 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2847 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2850 * Get associated volume/vnode for the stored file; caller's rights
2854 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustNOTBeDIR,
2855 &parentwhentargetnotdir, &client, WRITE_LOCK,
2856 &rights, &anyrights))) {
2860 rx_KeepAliveOn(acall);
2862 /* set volume synchronization information */
2863 SetVolumeSync(Sync, volptr);
2865 if ((targetptr->disk.type == vSymlink)) {
2866 /* Should we return a better error code here??? */
2871 /* Check if we're allowed to store the data */
2873 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2879 * Drop the read lock on the parent directory after saving the parent
2880 * vnode information we need to pass to GetStatus
2882 if (parentwhentargetnotdir != NULL) {
2883 tparentwhentargetnotdir = *parentwhentargetnotdir;
2884 rx_KeepAliveOff(acall);
2885 VPutVnode(&fileCode, parentwhentargetnotdir);
2886 rx_KeepAliveOn(acall);
2887 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2888 parentwhentargetnotdir = NULL;
2891 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
2894 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2895 FileLength, (InStatus->Mask & AFS_FSYNC),
2896 &bytesToXfer, &bytesXferred);
2898 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2901 if (errorCode && (!targetptr->changed_newTime))
2904 rx_KeepAliveOff(acall);
2905 /* Update the status of the target's vnode */
2906 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2907 targetptr, volptr, 0);
2908 rx_KeepAliveOn(acall);
2910 /* Get the updated File's status back to the caller */
2911 GetStatus(targetptr, OutStatus, rights, anyrights,
2912 &tparentwhentargetnotdir);
2915 /* Update and store volume/vnode and parent vnodes back */
2916 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2917 (Vnode *) 0, volptr, &client);
2918 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
2920 errorCode = CallPostamble(tcon, errorCode, thost);
2922 fsstats_FinishOp(&fsstats, errorCode);
2924 osi_auditU(acall, StoreDataEvent, errorCode,
2925 AUD_ID, t_client ? t_client->ViceId : 0,
2926 AUD_FID, Fid, AUD_END);
2928 } /*common_StoreData64 */
2931 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
2932 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
2933 afs_uint32 Length, afs_uint32 FileLength,
2934 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2936 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
2937 (0x7fffffff - Pos) < Length)
2940 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
2942 } /*SRXAFS_StoreData */
2945 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
2946 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
2947 afs_uint64 Length, afs_uint64 FileLength,
2948 struct AFSFetchStatus * OutStatus,
2949 struct AFSVolSync * Sync)
2953 afs_fsize_t tLength;
2954 afs_fsize_t tFileLength;
2956 tPos = (afs_fsize_t) Pos;
2957 tLength = (afs_fsize_t) Length;
2958 tFileLength = (afs_fsize_t) FileLength;
2961 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
2967 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
2968 struct AFSOpaque * AccessList,
2969 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2971 Vnode *targetptr = 0; /* pointer to input fid */
2972 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2973 Error errorCode = 0; /* return code for caller */
2974 struct AFSStoreStatus InStatus; /* Input status for fid */
2975 Volume *volptr = 0; /* pointer to the volume header */
2976 struct client *client = 0; /* pointer to client structure */
2977 afs_int32 rights, anyrights; /* rights for this and any user */
2978 struct rx_connection *tcon;
2980 struct client *t_client = NULL; /* tmp ptr to client data */
2981 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2982 struct fsstats fsstats;
2984 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
2986 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2989 /* Get ptr to client data for user Id for logging */
2990 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2991 logHostAddr.s_addr = rxr_HostOf(tcon);
2993 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
2994 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
2995 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2997 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
2999 InStatus.Mask = 0; /* not storing any status */
3002 * Get associated volume/vnode for the target dir; caller's rights
3003 * are also returned.
3006 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustBeDIR,
3007 &parentwhentargetnotdir, &client, WRITE_LOCK,
3008 &rights, &anyrights))) {
3012 /* set volume synchronization information */
3013 SetVolumeSync(Sync, volptr);
3015 /* Check if we have permission to change the dir's ACL */
3017 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3022 /* Build and store the new Access List for the dir */
3023 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3027 targetptr->changed_newTime = 1; /* status change of directory */
3029 /* convert the write lock to a read lock before breaking callbacks */
3030 VVnodeWriteToRead(&errorCode, targetptr);
3031 osi_Assert(!errorCode || errorCode == VSALVAGE);
3033 rx_KeepAliveOn(acall);
3035 /* break call backs on the directory */
3036 BreakCallBack(client->host, Fid, 0);
3038 /* Get the updated dir's status back to the caller */
3039 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3042 /* Update and store volume/vnode and parent vnodes back */
3043 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3045 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3046 errorCode = CallPostamble(tcon, errorCode, thost);
3048 fsstats_FinishOp(&fsstats, errorCode);
3050 osi_auditU(acall, StoreACLEvent, errorCode,
3051 AUD_ID, t_client ? t_client->ViceId : 0,
3052 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3055 } /*SRXAFS_StoreACL */
3059 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3060 * should be merged when possible.
3063 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3064 struct AFSStoreStatus *InStatus,
3065 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3067 Vnode *targetptr = 0; /* pointer to input fid */
3068 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3069 Error errorCode = 0; /* return code for caller */
3070 Volume *volptr = 0; /* pointer to the volume header */
3071 struct client *client = 0; /* pointer to client structure */
3072 afs_int32 rights, anyrights; /* rights for this and any user */
3073 struct client *t_client = NULL; /* tmp ptr to client data */
3074 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3075 struct rx_connection *tcon = rx_ConnectionOf(acall);
3077 /* Get ptr to client data for user Id for logging */
3078 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3079 logHostAddr.s_addr = rxr_HostOf(tcon);
3081 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3082 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3083 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3085 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3088 * Get volume/vnode for the target file; caller's rights to it are
3092 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
3093 &parentwhentargetnotdir, &client, WRITE_LOCK,
3094 &rights, &anyrights))) {
3095 goto Bad_StoreStatus;
3098 /* set volume synchronization information */
3099 SetVolumeSync(Sync, volptr);
3101 /* Check if the caller has proper permissions to store status to Fid */
3103 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3105 goto Bad_StoreStatus;
3108 * Check for a symbolic link; we can't chmod these (otherwise could
3109 * change a symlink to a mt pt or vice versa)
3111 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3113 goto Bad_StoreStatus;
3116 /* Update the status of the target's vnode */
3117 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3118 (parentwhentargetnotdir ? parentwhentargetnotdir
3119 : targetptr), volptr, 0);
3121 rx_KeepAliveOn(acall);
3123 /* convert the write lock to a read lock before breaking callbacks */
3124 VVnodeWriteToRead(&errorCode, targetptr);
3125 osi_Assert(!errorCode || errorCode == VSALVAGE);
3127 /* Break call backs on Fid */
3128 BreakCallBack(client->host, Fid, 0);
3130 /* Return the updated status back to caller */
3131 GetStatus(targetptr, OutStatus, rights, anyrights,
3132 parentwhentargetnotdir);
3135 /* Update and store volume/vnode and parent vnodes back */
3136 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3138 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3141 } /*SAFSS_StoreStatus */
3145 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3146 struct AFSStoreStatus * InStatus,
3147 struct AFSFetchStatus * OutStatus,
3148 struct AFSVolSync * Sync)
3151 struct rx_connection *tcon;
3153 struct client *t_client = NULL; /* tmp ptr to client data */
3154 struct fsstats fsstats;
3156 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3158 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3159 goto Bad_StoreStatus;
3161 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3164 code = CallPostamble(tcon, code, thost);
3166 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3168 fsstats_FinishOp(&fsstats, code);
3170 osi_auditU(acall, StoreStatusEvent, code,
3171 AUD_ID, t_client ? t_client->ViceId : 0,
3172 AUD_FID, Fid, AUD_END);
3175 } /*SRXAFS_StoreStatus */
3179 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3180 * merged in when possible.
3183 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3184 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3186 Vnode *parentptr = 0; /* vnode of input Directory */
3187 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3188 Vnode *targetptr = 0; /* file to be deleted */
3189 Volume *volptr = 0; /* pointer to the volume header */
3190 AFSFid fileFid; /* area for Fid from the directory */
3191 Error errorCode = 0; /* error code */
3192 DirHandle dir; /* Handle for dir package I/O */
3193 struct client *client = 0; /* pointer to client structure */
3194 afs_int32 rights, anyrights; /* rights for this and any user */
3195 struct client *t_client; /* tmp ptr to client data */
3196 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3197 struct rx_connection *tcon = rx_ConnectionOf(acall);
3200 /* Get ptr to client data for user Id for logging */
3201 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3202 logHostAddr.s_addr = rxr_HostOf(tcon);
3204 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3205 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3206 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3208 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3211 * Get volume/vnode for the parent dir; caller's access rights are
3215 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3216 &parentwhentargetnotdir, &client, WRITE_LOCK,
3217 &rights, &anyrights))) {
3218 goto Bad_RemoveFile;
3220 /* set volume synchronization information */
3221 SetVolumeSync(Sync, volptr);
3223 /* Does the caller has delete (& write) access to the parent directory? */
3224 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3225 goto Bad_RemoveFile;
3228 /* Actually delete the desired file */
3230 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3232 goto Bad_RemoveFile;
3235 /* Update the vnode status of the parent dir */
3236 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3237 parentptr->disk.linkCount,
3238 client->InSameNetwork);
3240 rx_KeepAliveOn(acall);
3242 /* Return the updated parent dir's status back to caller */
3243 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3245 /* Handle internal callback state for the parent and the deleted file */
3246 if (targetptr->disk.linkCount == 0) {
3247 /* no references left, discard entry */
3248 DeleteFileCallBacks(&fileFid);
3249 /* convert the parent lock to a read lock before breaking callbacks */
3250 VVnodeWriteToRead(&errorCode, parentptr);
3251 osi_Assert(!errorCode || errorCode == VSALVAGE);
3253 /* convert the parent lock to a read lock before breaking callbacks */
3254 VVnodeWriteToRead(&errorCode, parentptr);
3255 osi_Assert(!errorCode || errorCode == VSALVAGE);
3256 /* convert the target lock to a read lock before breaking callbacks */
3257 VVnodeWriteToRead(&errorCode, targetptr);
3258 osi_Assert(!errorCode || errorCode == VSALVAGE);
3259 /* tell all the file has changed */
3260 BreakCallBack(client->host, &fileFid, 1);
3263 /* break call back on the directory */
3264 BreakCallBack(client->host, DirFid, 0);
3267 /* Update and store volume/vnode and parent vnodes back */
3268 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3271 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3274 } /*SAFSS_RemoveFile */
3278 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3279 struct AFSFetchStatus * OutDirStatus,
3280 struct AFSVolSync * Sync)
3283 struct rx_connection *tcon;
3285 struct client *t_client = NULL; /* tmp ptr to client data */
3286 struct fsstats fsstats;
3288 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3290 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3291 goto Bad_RemoveFile;
3293 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3296 code = CallPostamble(tcon, code, thost);
3298 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3300 fsstats_FinishOp(&fsstats, code);
3302 osi_auditU(acall, RemoveFileEvent, code,
3303 AUD_ID, t_client ? t_client->ViceId : 0,
3304 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3307 } /*SRXAFS_RemoveFile */
3311 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3312 * be merged in when possible.
3315 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3316 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3317 struct AFSFetchStatus *OutFidStatus,
3318 struct AFSFetchStatus *OutDirStatus,
3319 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3321 Vnode *parentptr = 0; /* vnode of input Directory */
3322 Vnode *targetptr = 0; /* vnode of the new file */
3323 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3324 Volume *volptr = 0; /* pointer to the volume header */
3325 Error errorCode = 0; /* error code */
3326 DirHandle dir; /* Handle for dir package I/O */
3327 struct client *client = 0; /* pointer to client structure */
3328 afs_int32 rights, anyrights; /* rights for this and any user */
3329 struct client *t_client; /* tmp ptr to client data */
3330 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3331 struct rx_connection *tcon = rx_ConnectionOf(acall);
3335 /* Get ptr to client data for user Id for logging */
3336 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3337 logHostAddr.s_addr = rxr_HostOf(tcon);
3339 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3340 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3341 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3343 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3345 if (!FileNameOK(Name)) {
3347 goto Bad_CreateFile;
3351 * Get associated volume/vnode for the parent dir; caller long are
3355 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3356 &parentwhentargetnotdir, &client, WRITE_LOCK,
3357 &rights, &anyrights))) {
3358 goto Bad_CreateFile;
3361 /* set volume synchronization information */
3362 SetVolumeSync(Sync, volptr);
3364 /* Can we write (and insert) onto the parent directory? */
3365 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3366 goto Bad_CreateFile;
3369 /* get a new vnode for the file to be created and set it up */
3371 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3372 vFile, nBlocks(0))))
3373 goto Bad_CreateFile;
3375 /* update the status of the parent vnode */
3376 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3377 parentptr->disk.linkCount,
3378 client->InSameNetwork);
3380 /* update the status of the new file's vnode */
3381 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3382 parentptr, volptr, 0);
3384 rx_KeepAliveOn(acall);
3386 /* 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 */
3387 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3388 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3390 /* convert the write lock to a read lock before breaking callbacks */
3391 VVnodeWriteToRead(&errorCode, parentptr);
3392 osi_Assert(!errorCode || errorCode == VSALVAGE);
3394 /* break call back on parent dir */
3395 BreakCallBack(client->host, DirFid, 0);
3397 /* Return a callback promise for the newly created file to the caller */
3398 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3401 /* Update and store volume/vnode and parent vnodes back */
3402 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3405 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3408 } /*SAFSS_CreateFile */
3412 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3413 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3414 struct AFSFetchStatus * OutFidStatus,
3415 struct AFSFetchStatus * OutDirStatus,
3416 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3419 struct rx_connection *tcon;
3421 struct client *t_client = NULL; /* tmp ptr to client data */
3422 struct fsstats fsstats;
3424 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CREATEFILE);
3426 memset(OutFid, 0, sizeof(struct AFSFid));
3428 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3429 goto Bad_CreateFile;
3432 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3433 OutDirStatus, CallBack, Sync);
3436 code = CallPostamble(tcon, code, thost);
3438 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3440 fsstats_FinishOp(&fsstats, code);
3442 osi_auditU(acall, CreateFileEvent, code,
3443 AUD_ID, t_client ? t_client->ViceId : 0,
3444 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3447 } /*SRXAFS_CreateFile */
3451 * This routine is called exclusively from SRXAFS_Rename(), and should be
3452 * merged in when possible.
3455 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3456 struct AFSFid *NewDirFid, char *NewName,
3457 struct AFSFetchStatus *OutOldDirStatus,
3458 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3460 Vnode *oldvptr = 0; /* vnode of the old Directory */
3461 Vnode *newvptr = 0; /* vnode of the new Directory */
3462 Vnode *fileptr = 0; /* vnode of the file to move */
3463 Vnode *newfileptr = 0; /* vnode of the file to delete */
3464 Vnode *testvptr = 0; /* used in directory tree walk */
3465 Vnode *parent = 0; /* parent for use in SetAccessList */
3466 Error errorCode = 0; /* error code */
3467 Error fileCode = 0; /* used when writing Vnodes */
3468 VnodeId testnode; /* used in directory tree walk */
3469 AFSFid fileFid; /* Fid of file to move */
3470 AFSFid newFileFid; /* Fid of new file */
3471 DirHandle olddir; /* Handle for dir package I/O */
3472 DirHandle newdir; /* Handle for dir package I/O */
3473 DirHandle filedir; /* Handle for dir package I/O */
3474 DirHandle newfiledir; /* Handle for dir package I/O */
3475 Volume *volptr = 0; /* pointer to the volume header */
3476 struct client *client = 0; /* pointer to client structure */
3477 afs_int32 rights, anyrights; /* rights for this and any user */
3478 afs_int32 newrights; /* rights for this user */
3479 afs_int32 newanyrights; /* rights for any user */
3480 int doDelete; /* deleted the rename target (ref count now 0) */
3482 int updatefile = 0; /* are we changing the renamed file? (we do this
3483 * if we need to update .. on a renamed dir) */
3484 struct client *t_client; /* tmp ptr to client data */
3485 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3486 struct rx_connection *tcon = rx_ConnectionOf(acall);
3492 FidZero(&newfiledir);
3494 /* Get ptr to client data for user Id for logging */
3495 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3496 logHostAddr.s_addr = rxr_HostOf(tcon);
3498 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3499 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3500 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3501 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3503 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3505 if (!FileNameOK(NewName)) {
3509 if (OldDirFid->Volume != NewDirFid->Volume) {
3514 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3515 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3516 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3522 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3524 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3525 &parent, &client, WRITE_LOCK, &rights,
3530 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3532 newrights = rights, newanyrights = anyrights;
3535 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr,
3536 MustBeDIR, &parent, &client, WRITE_LOCK,
3537 &newrights, &newanyrights))) {
3543 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr, MustBeDIR,
3544 &parent, &client, WRITE_LOCK, &newrights,
3550 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3551 &parent, &client, WRITE_LOCK, &rights,
3558 /* set volume synchronization information */
3559 SetVolumeSync(Sync, volptr);
3561 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3564 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3568 if (CheckLength(volptr, oldvptr, -1) ||
3569 CheckLength(volptr, newvptr, -1)) {
3570 VTakeOffline(volptr);
3571 errorCode = VSALVAGE;
3575 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3576 * call to CopyOnWrite returns error, it is not necessary to revert back
3577 * the effects of the first call because the contents of the volume is
3578 * not modified, it is only replicated.
3580 if (oldvptr->disk.cloned) {
3581 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3582 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3585 SetDirHandle(&olddir, oldvptr);
3586 if (newvptr->disk.cloned) {
3587 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3588 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3592 SetDirHandle(&newdir, newvptr);
3594 /* Lookup the file to delete its vnode */
3595 if (afs_dir_Lookup(&olddir, OldName, &fileFid)) {
3599 if (fileFid.Vnode == oldvptr->vnodeNumber
3600 || fileFid.Vnode == newvptr->vnodeNumber) {
3601 errorCode = FSERR_ELOOP;
3604 fileFid.Volume = V_id(volptr);
3605 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3606 if (errorCode != 0) {
3608 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3609 OldName, errorCode));
3610 VTakeOffline(volptr);
3613 if (fileptr->disk.uniquifier != fileFid.Unique) {
3615 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3617 VTakeOffline(volptr);
3622 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3623 && fileptr->disk.linkCount != 1) {
3625 * Hard links exist to this file - cannot move one of the links to
3626 * a new directory because of AFS restrictions (this is the same
3627 * reason that links cannot be made across directories, i.e.
3634 /* Lookup the new file */
3635 if (!(afs_dir_Lookup(&newdir, NewName, &newFileFid))) {
3636 if (readonlyServer) {
3637 errorCode = VREADONLY;
3640 if (!(newrights & PRSFS_DELETE)) {
3644 if (newFileFid.Vnode == oldvptr->vnodeNumber
3645 || newFileFid.Vnode == newvptr->vnodeNumber
3646 || newFileFid.Vnode == fileFid.Vnode) {
3650 newFileFid.Volume = V_id(volptr);
3652 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3653 if (errorCode != 0) {
3655 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3656 NewName, errorCode));
3657 VTakeOffline(volptr);
3660 if (fileptr->disk.uniquifier != fileFid.Unique) {
3662 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3664 VTakeOffline(volptr);
3668 SetDirHandle(&newfiledir, newfileptr);
3669 /* Now check that we're moving directories over directories properly, etc.
3670 * return proper POSIX error codes:
3671 * if fileptr is a file and new is a dir: EISDIR.
3672 * if fileptr is a dir and new is a file: ENOTDIR.
3673 * Also, dir to be removed must be empty, of course.
3675 if (newfileptr->disk.type == vDirectory) {
3676 if (fileptr->disk.type != vDirectory) {
3680 if ((afs_dir_IsEmpty(&newfiledir))) {
3685 if (fileptr->disk.type == vDirectory) {
3686 errorCode = ENOTDIR;
3693 * ok - now we check that the old name is not above new name in the
3694 * directory structure. This is to prevent removing a subtree alltogether
3696 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3697 afs_int32 forpass = 0, vnum = 0, top = 0;
3698 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3699 if (testnode > vnum) vnum = testnode;
3700 if (forpass > vnum) {
3701 errorCode = FSERR_ELOOP;
3704 if (testnode == oldvptr->vnodeNumber) {
3705 testnode = oldvptr->disk.parent;
3708 if ((testnode == fileptr->vnodeNumber)
3709 || (testnode == newvptr->vnodeNumber)) {
3710 errorCode = FSERR_ELOOP;
3713 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3714 errorCode = FSERR_ELOOP;
3717 if (testnode == 1) top = 1;
3718 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3719 osi_Assert(errorCode == 0);
3720 testnode = testvptr->disk.parent;
3721 VPutVnode(&errorCode, testvptr);
3722 if ((top == 1) && (testnode != 0)) {
3723 VTakeOffline(volptr);
3725 ("Volume %u now offline, must be salvaged.\n",
3730 osi_Assert(errorCode == 0);
3734 if (fileptr->disk.type == vDirectory) {
3735 SetDirHandle(&filedir, fileptr);
3736 if (oldvptr != newvptr) {
3737 /* we always need to update .. if we've moving fileptr to a
3738 * different directory */
3741 struct AFSFid unused;
3743 code = afs_dir_Lookup(&filedir, "..", &unused);
3744 if (code == ENOENT) {
3745 /* only update .. if it doesn't already exist */
3751 /* Do the CopyonWrite first before modifying anything else. Copying is
3752 * required when we have to change entries for ..
3754 if (updatefile && (fileptr->disk.cloned)) {
3755 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3756 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
3758 /* since copyonwrite would mean fileptr has a new handle, do it here */
3760 SetDirHandle(&filedir, fileptr);
3763 /* If the new name exists already, delete it and the file it points to */
3766 /* Delete NewName from its directory */
3767 code = afs_dir_Delete(&newdir, NewName);
3768 osi_Assert(code == 0);
3770 /* Drop the link count */
3771 newfileptr->disk.linkCount--;
3772 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
3773 afs_fsize_t newSize;
3774 VN_GET_LEN(newSize, newfileptr);
3775 VAdjustDiskUsage((Error *) & errorCode, volptr,
3776 (afs_sfsize_t) - nBlocks(newSize), 0);
3777 if (VN_GET_INO(newfileptr)) {
3778 IH_REALLYCLOSE(newfileptr->handle);
3780 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
3781 V_parentId(volptr));
3782 IH_RELEASE(newfileptr->handle);
3783 if (errorCode == -1) {
3785 ("Del: inode=%s, name=%s, errno=%d\n",
3786 PrintInode(stmp, VN_GET_INO(newfileptr)),
3788 if ((errno != ENOENT) && (errno != EIO)
3789 && (errno != ENXIO))
3790 ViceLog(0, ("Do we need to fsck?"));
3793 VN_SET_INO(newfileptr, (Inode) 0);
3794 newfileptr->delete = 1; /* Mark NewName vnode to delete */
3797 /* Link count did not drop to zero.
3798 * Mark NewName vnode as changed - updates stime.
3800 newfileptr->changed_newTime = 1;
3805 * If the create below fails, and the delete above worked, we have
3806 * removed the new name and not replaced it. This is not very likely,
3807 * but possible. We could try to put the old file back, but it is
3808 * highly unlikely that it would work since it would involve issuing
3811 if ((errorCode = afs_dir_Create(&newdir, NewName, &fileFid)))
3814 /* Delete the old name */
3815 osi_Assert(afs_dir_Delete(&olddir, OldName) == 0);
3817 /* if the directory length changes, reflect it in the statistics */
3818 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
3819 oldvptr->disk.linkCount, client->InSameNetwork);
3820 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
3821 newvptr->disk.linkCount, client->InSameNetwork);
3823 if (oldvptr == newvptr)
3824 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
3826 if (fileptr->disk.parent != newvptr->vnodeNumber) {
3827 fileptr->disk.parent = newvptr->vnodeNumber;
3828 fileptr->changed_newTime = 1;
3831 /* if we are dealing with a rename of a directory, and we need to
3832 * update the .. entry of that directory */
3834 osi_Assert(!fileptr->disk.cloned);
3836 fileptr->changed_newTime = 1; /* status change of moved file */
3838 /* fix .. to point to the correct place */
3839 afs_dir_Delete(&filedir, ".."); /* No assert--some directories may be bad */
3840 osi_Assert(afs_dir_Create(&filedir, "..", NewDirFid) == 0);
3841 fileptr->disk.dataVersion++;
3843 /* if the parent directories are different the link counts have to be */
3844 /* changed due to .. in the renamed directory */
3845 if (oldvptr != newvptr) {
3846 oldvptr->disk.linkCount--;
3847 newvptr->disk.linkCount++;
3851 /* set up return status */
3852 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
3853 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
3854 if (newfileptr && doDelete) {
3855 DeleteFileCallBacks(&newFileFid); /* no other references */
3860 /* convert the write locks to a read locks before breaking callbacks */
3861 VVnodeWriteToRead(&errorCode, newvptr);
3862 osi_Assert(!errorCode || errorCode == VSALVAGE);
3863 if (oldvptr != newvptr) {
3864 VVnodeWriteToRead(&errorCode, oldvptr);
3865 osi_Assert(!errorCode || errorCode == VSALVAGE);
3867 if (newfileptr && !doDelete) {
3868 /* convert the write lock to a read lock before breaking callbacks */
3869 VVnodeWriteToRead(&errorCode, newfileptr);
3870 osi_Assert(!errorCode || errorCode == VSALVAGE);
3873 rx_KeepAliveOn(acall);
3875 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
3876 BreakCallBack(client->host, NewDirFid, 0);
3877 if (oldvptr != newvptr) {
3878 BreakCallBack(client->host, OldDirFid, 0);
3881 /* if a dir moved, .. changed */
3882 /* we do not give an AFSFetchStatus structure back to the
3883 * originating client, and the file's status has changed, so be
3884 * sure to send a callback break. In theory the client knows
3885 * enough to know that the callback could be broken implicitly,
3886 * but that may not be clear, and some client implementations
3887 * may not know to. */
3888 BreakCallBack(client->host, &fileFid, 1);
3891 /* Note: it is not necessary to break the callback */
3893 DeleteFileCallBacks(&newFileFid); /* no other references */
3895 /* other's still exist (with wrong link count) */
3896 BreakCallBack(client->host, &newFileFid, 1);
3901 rx_KeepAliveOff(acall);
3902 VPutVnode(&fileCode, newfileptr);
3903 osi_Assert(fileCode == 0);
3905 (void)PutVolumePackage(acall, fileptr, (newvptr && newvptr != oldvptr ?
3906 newvptr : 0), oldvptr, volptr, &client);
3910 FidZap(&newfiledir);
3911 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
3918 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
3919 char *OldName, struct AFSFid * NewDirFid, char *NewName,
3920 struct AFSFetchStatus * OutOldDirStatus,
3921 struct AFSFetchStatus * OutNewDirStatus,
3922 struct AFSVolSync * Sync)
3925 struct rx_connection *tcon;
3927 struct client *t_client = NULL; /* tmp ptr to client data */
3928 struct fsstats fsstats;
3930 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RENAME);
3932 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3936 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
3937 OutOldDirStatus, OutNewDirStatus, Sync);
3940 code = CallPostamble(tcon, code, thost);
3942 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3944 fsstats_FinishOp(&fsstats, code);
3946 osi_auditU(acall, RenameFileEvent, code,
3947 AUD_ID, t_client ? t_client->ViceId : 0,
3948 AUD_FID, OldDirFid, AUD_STR, OldName,
3949 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
3952 } /*SRXAFS_Rename */
3956 * This routine is called exclusively by SRXAFS_Symlink(), and should be
3957 * merged into it when possible.
3960 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3961 char *LinkContents, struct AFSStoreStatus *InStatus,
3962 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
3963 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3965 Vnode *parentptr = 0; /* vnode of input Directory */
3966 Vnode *targetptr = 0; /* vnode of the new link */
3967 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3968 Error errorCode = 0; /* error code */
3971 DirHandle dir; /* Handle for dir package I/O */
3972 Volume *volptr = 0; /* pointer to the volume header */
3973 struct client *client = 0; /* pointer to client structure */
3974 afs_int32 rights, anyrights; /* rights for this and any user */
3975 struct client *t_client; /* tmp ptr to client data */
3976 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3978 struct rx_connection *tcon = rx_ConnectionOf(acall);
3982 /* Get ptr to client data for user Id for logging */
3983 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3984 logHostAddr.s_addr = rxr_HostOf(tcon);
3986 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3987 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3988 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3990 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
3992 if (!FileNameOK(Name)) {
3998 * Get the vnode and volume for the parent dir along with the caller's
4002 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4003 &parentwhentargetnotdir, &client, WRITE_LOCK,
4004 &rights, &anyrights)))
4007 /* set volume synchronization information */
4008 SetVolumeSync(Sync, volptr);
4010 /* Does the caller has insert (and write) access to the parent directory? */
4011 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)))
4015 * If we're creating a mount point (any x bits clear), we must have
4016 * administer access to the directory, too. Always allow sysadmins
4019 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4020 if (readonlyServer) {
4021 errorCode = VREADONLY;
4025 * We have a mountpoint, 'cause we're trying to set the Unix mode
4026 * bits to something with some x bits missing (default mode bits
4027 * if AFS_SETMODE is false is 0777)
4029 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4035 /* get a new vnode for the symlink and set it up */
4037 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4038 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4042 /* update the status of the parent vnode */
4043 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4044 parentptr->disk.linkCount,
4045 client->InSameNetwork);
4047 /* update the status of the new symbolic link file vnode */
4048 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4049 parentptr, volptr, strlen((char *)LinkContents));
4051 /* Write the contents of the symbolic link name into the target inode */
4052 fdP = IH_OPEN(targetptr->handle);
4054 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4055 parentptr, volptr, &client);
4056 VTakeOffline(volptr);
4057 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4061 len = strlen((char *) LinkContents);
4062 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4064 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4067 * Set up and return modified status for the parent dir and new symlink
4070 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4071 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4073 /* convert the write lock to a read lock before breaking callbacks */
4074 VVnodeWriteToRead(&errorCode, parentptr);
4075 osi_Assert(!errorCode || errorCode == VSALVAGE);
4077 rx_KeepAliveOn(acall);
4079 /* break call back on the parent dir */
4080 BreakCallBack(client->host, DirFid, 0);
4083 /* Write the all modified vnodes (parent, new files) and volume back */
4084 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4087 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4088 return ( errorCode ? errorCode : code );
4090 } /*SAFSS_Symlink */
4094 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4095 struct AFSFid *DirFid, /* Parent dir's fid */
4096 char *Name, /* File name to create */
4097 char *LinkContents, /* Contents of the new created file */
4098 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4099 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4100 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4101 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4102 struct AFSVolSync *Sync)
4105 struct rx_connection *tcon;
4107 struct client *t_client = NULL; /* tmp ptr to client data */
4108 struct fsstats fsstats;
4110 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SYMLINK);
4112 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4116 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4117 OutFidStatus, OutDirStatus, Sync);
4120 code = CallPostamble(tcon, code, thost);
4122 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4124 fsstats_FinishOp(&fsstats, code);
4126 osi_auditU(acall, SymlinkEvent, code,
4127 AUD_ID, t_client ? t_client->ViceId : 0,
4128 AUD_FID, DirFid, AUD_STR, Name,
4129 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4132 } /*SRXAFS_Symlink */
4136 * This routine is called exclusively by SRXAFS_Link(), and should be
4137 * merged into it when possible.
4140 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4141 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4142 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4144 Vnode *parentptr = 0; /* vnode of input Directory */
4145 Vnode *targetptr = 0; /* vnode of the new file */
4146 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4147 Volume *volptr = 0; /* pointer to the volume header */
4148 Error errorCode = 0; /* error code */
4149 DirHandle dir; /* Handle for dir package I/O */
4150 struct client *client = 0; /* pointer to client structure */
4151 afs_int32 rights, anyrights; /* rights for this and any user */
4152 struct client *t_client; /* tmp ptr to client data */
4153 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4154 struct rx_connection *tcon = rx_ConnectionOf(acall);
4158 /* Get ptr to client data for user Id for logging */
4159 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4160 logHostAddr.s_addr = rxr_HostOf(tcon);
4162 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4163 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4164 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4165 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4167 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4169 if (DirFid->Volume != ExistingFid->Volume) {
4173 if (!FileNameOK(Name)) {
4179 * Get the vnode and volume for the parent dir along with the caller's
4183 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4184 &parentwhentargetnotdir, &client, WRITE_LOCK,
4185 &rights, &anyrights))) {
4189 /* set volume synchronization information */
4190 SetVolumeSync(Sync, volptr);
4192 /* Can the caller insert into the parent directory? */
4193 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4197 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4198 /* AFS fileservers always have directory vnodes that are odd. */
4203 if (CheckLength(volptr, parentptr, -1)) {
4204 VTakeOffline(volptr);
4205 errorCode = VSALVAGE;
4209 /* get the file vnode */
4211 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4215 if (targetptr->disk.type != vFile) {
4219 if (targetptr->disk.parent != DirFid->Vnode) {
4223 if (parentptr->disk.cloned) {
4224 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4225 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4226 goto Bad_Link; /* disk full error */
4229 /* add the name to the directory */
4230 SetDirHandle(&dir, parentptr);
4231 if ((errorCode = afs_dir_Create(&dir, Name, ExistingFid)))
4235 /* update the status in the parent vnode */
4236 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4237 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4238 parentptr->disk.linkCount,
4239 client->InSameNetwork);
4241 targetptr->disk.linkCount++;
4242 targetptr->disk.author = client->ViceId;
4243 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4245 /* set up return status */
4246 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4247 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4249 /* convert the write locks to read locks before breaking callbacks */
4250 VVnodeWriteToRead(&errorCode, targetptr);
4251 osi_Assert(!errorCode || errorCode == VSALVAGE);
4252 VVnodeWriteToRead(&errorCode, parentptr);
4253 osi_Assert(!errorCode || errorCode == VSALVAGE);
4255 rx_KeepAliveOn(acall);
4257 /* break call back on DirFid */
4258 BreakCallBack(client->host, DirFid, 0);
4260 * We also need to break the callback for the file that is hard-linked since part
4261 * of its status (like linkcount) is changed
4263 BreakCallBack(client->host, ExistingFid, 0);
4266 /* Write the all modified vnodes (parent, new files) and volume back */
4267 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4270 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4277 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4278 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4279 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4282 struct rx_connection *tcon;
4284 struct client *t_client = NULL; /* tmp ptr to client data */
4285 struct fsstats fsstats;
4287 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_LINK);
4289 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4293 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4294 OutDirStatus, Sync);
4297 code = CallPostamble(tcon, code, thost);
4299 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4301 fsstats_FinishOp(&fsstats, code);
4303 osi_auditU(acall, LinkEvent, code,
4304 AUD_ID, t_client ? t_client->ViceId : 0,
4305 AUD_FID, DirFid, AUD_STR, Name,
4306 AUD_FID, ExistingFid, AUD_END);
4313 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4314 * merged into it when possible.
4317 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4318 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4319 struct AFSFetchStatus *OutFidStatus,
4320 struct AFSFetchStatus *OutDirStatus,
4321 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4323 Vnode *parentptr = 0; /* vnode of input Directory */
4324 Vnode *targetptr = 0; /* vnode of the new file */
4325 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4326 Volume *volptr = 0; /* pointer to the volume header */
4327 Error errorCode = 0; /* error code */
4328 struct acl_accessList *newACL; /* Access list */
4329 int newACLSize; /* Size of access list */
4330 DirHandle dir; /* Handle for dir package I/O */
4331 DirHandle parentdir; /* Handle for dir package I/O */
4332 struct client *client = 0; /* pointer to client structure */
4333 afs_int32 rights, anyrights; /* rights for this and any user */
4334 struct client *t_client; /* tmp ptr to client data */
4335 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4336 struct rx_connection *tcon = rx_ConnectionOf(acall);
4339 FidZero(&parentdir);
4341 /* Get ptr to client data for user Id for logging */
4342 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4343 logHostAddr.s_addr = rxr_HostOf(tcon);
4345 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4346 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4347 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4349 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4351 if (!FileNameOK(Name)) {
4357 * Get the vnode and volume for the parent dir along with the caller's
4361 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4362 &parentwhentargetnotdir, &client, WRITE_LOCK,
4363 &rights, &anyrights))) {
4367 /* set volume synchronization information */
4368 SetVolumeSync(Sync, volptr);
4370 /* Write access to the parent directory? */
4371 #ifdef DIRCREATE_NEED_WRITE
4373 * requires w access for the user to create a directory. this
4374 * closes a loophole in the current security arrangement, since a
4375 * user with i access only can create a directory and get the
4376 * implcit a access that goes with dir ownership, and proceed to
4377 * subvert quota in the volume.
4379 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4380 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4382 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4383 #endif /* DIRCREATE_NEED_WRITE */
4386 #define EMPTYDIRBLOCKS 2
4387 /* get a new vnode and set it up */
4389 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4390 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4394 /* Update the status for the parent dir */
4395 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4396 parentptr->disk.linkCount + 1,
4397 client->InSameNetwork);
4399 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4400 osi_Assert((SetAccessList
4401 (&targetptr, &volptr, &newACL, &newACLSize,
4402 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4403 osi_Assert(parentwhentargetnotdir == 0);
4404 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4406 /* update the status for the target vnode */
4407 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4408 parentptr, volptr, 0);
4410 /* Actually create the New directory in the directory package */
4411 SetDirHandle(&dir, targetptr);
4412 osi_Assert(!(afs_dir_MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4414 VN_SET_LEN(targetptr, (afs_fsize_t) afs_dir_Length(&dir));
4416 /* set up return status */
4417 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4418 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4420 /* convert the write lock to a read lock before breaking callbacks */
4421 VVnodeWriteToRead(&errorCode, parentptr);
4422 osi_Assert(!errorCode || errorCode == VSALVAGE);
4424 rx_KeepAliveOn(acall);
4426 /* break call back on DirFid */
4427 BreakCallBack(client->host, DirFid, 0);
4429 /* Return a callback promise to caller */
4430 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4433 /* Write the all modified vnodes (parent, new files) and volume back */
4434 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4438 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4441 } /*SAFSS_MakeDir */
4445 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4446 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4447 struct AFSFetchStatus * OutFidStatus,
4448 struct AFSFetchStatus * OutDirStatus,
4449 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4452 struct rx_connection *tcon;
4454 struct client *t_client = NULL; /* tmp ptr to client data */
4455 struct fsstats fsstats;
4457 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_MAKEDIR);
4459 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4463 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4464 OutDirStatus, CallBack, Sync);
4467 code = CallPostamble(tcon, code, thost);
4469 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4471 fsstats_FinishOp(&fsstats, code);
4473 osi_auditU(acall, MakeDirEvent, code,
4474 AUD_ID, t_client ? t_client->ViceId : 0,
4475 AUD_FID, DirFid, AUD_STR, Name,
4476 AUD_FID, OutFid, AUD_END);
4479 } /*SRXAFS_MakeDir */
4483 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4484 * merged into it when possible.
4487 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4488 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4490 Vnode *parentptr = 0; /* vnode of input Directory */
4491 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4492 Vnode *targetptr = 0; /* file to be deleted */
4493 AFSFid fileFid; /* area for Fid from the directory */
4494 Error errorCode = 0; /* error code */
4495 DirHandle dir; /* Handle for dir package I/O */
4496 Volume *volptr = 0; /* pointer to the volume header */
4497 struct client *client = 0; /* pointer to client structure */
4498 afs_int32 rights, anyrights; /* rights for this and any user */
4499 struct client *t_client; /* tmp ptr to client data */
4500 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4501 struct rx_connection *tcon = rx_ConnectionOf(acall);
4505 /* Get ptr to client data for user Id for logging */
4506 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4507 logHostAddr.s_addr = rxr_HostOf(tcon);
4509 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4510 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4511 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4513 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4516 * Get the vnode and volume for the parent dir along with the caller's
4520 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4521 &parentwhentargetnotdir, &client, WRITE_LOCK,
4522 &rights, &anyrights))) {
4526 /* set volume synchronization information */
4527 SetVolumeSync(Sync, volptr);
4529 /* Does the caller has delete (&write) access to the parent dir? */
4530 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4534 /* Do the actual delete of the desired (empty) directory, Name */
4536 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4541 /* Update the status for the parent dir; link count is also adjusted */
4542 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4543 parentptr->disk.linkCount - 1,
4544 client->InSameNetwork);
4546 /* Return to the caller the updated parent dir status */
4547 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4550 * Note: it is not necessary to break the callback on fileFid, since
4551 * refcount is now 0, so no one should be able to refer to the dir
4554 DeleteFileCallBacks(&fileFid);
4556 /* convert the write lock to a read lock before breaking callbacks */
4557 VVnodeWriteToRead(&errorCode, parentptr);
4558 osi_Assert(!errorCode || errorCode == VSALVAGE);
4560 rx_KeepAliveOn(acall);
4562 /* break call back on DirFid and fileFid */
4563 BreakCallBack(client->host, DirFid, 0);
4566 /* Write the all modified vnodes (parent, new files) and volume back */
4567 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4570 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4573 } /*SAFSS_RemoveDir */
4577 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4578 struct AFSFetchStatus * OutDirStatus,
4579 struct AFSVolSync * Sync)
4582 struct rx_connection *tcon;
4584 struct client *t_client = NULL; /* tmp ptr to client data */
4585 struct fsstats fsstats;
4587 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEDIR);
4589 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4592 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4595 code = CallPostamble(tcon, code, thost);
4597 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4599 fsstats_FinishOp(&fsstats, code);
4601 osi_auditU(acall, RemoveDirEvent, code,
4602 AUD_ID, t_client ? t_client->ViceId : 0,
4603 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4606 } /*SRXAFS_RemoveDir */
4610 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4611 * merged into it when possible.
4614 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4615 struct AFSVolSync *Sync)
4617 Vnode *targetptr = 0; /* vnode of input file */
4618 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4619 Error errorCode = 0; /* error code */
4620 Volume *volptr = 0; /* pointer to the volume header */
4621 struct client *client = 0; /* pointer to client structure */
4622 afs_int32 rights, anyrights; /* rights for this and any user */
4623 struct client *t_client; /* tmp ptr to client data */
4624 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4625 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
4626 struct rx_connection *tcon = rx_ConnectionOf(acall);
4628 if (type != LockRead && type != LockWrite) {
4632 /* Get ptr to client data for user Id for logging */
4633 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4634 logHostAddr.s_addr = rxr_HostOf(tcon);
4636 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4637 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4638 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4640 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4643 * Get the vnode and volume for the desired file along with the caller's
4647 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4648 &parentwhentargetnotdir, &client, WRITE_LOCK,
4649 &rights, &anyrights))) {
4653 /* set volume synchronization information */
4654 SetVolumeSync(Sync, volptr);
4656 /* Handle the particular type of set locking, type */
4657 errorCode = HandleLocking(targetptr, client, rights, type);
4660 /* Write the all modified vnodes (parent, new files) and volume back */
4661 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4662 (Vnode *) 0, volptr, &client);
4664 if ((errorCode == VREADONLY) && (type == LockRead))
4665 errorCode = 0; /* allow read locks on RO volumes without saving state */
4667 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
4670 } /*SAFSS_SetLock */
4674 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
4675 ViceLockType type, struct AFSVolSync * Sync)
4677 return SRXAFS_SetLock(acall, Fid, type, Sync);
4678 } /*SRXAFS_OldSetLock */
4682 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
4683 struct AFSVolSync * Sync)
4686 struct rx_connection *tcon;
4688 struct client *t_client = NULL; /* tmp ptr to client data */
4689 struct fsstats fsstats;
4691 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETLOCK);
4693 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4696 code = SAFSS_SetLock(acall, Fid, type, Sync);
4699 code = CallPostamble(tcon, code, thost);
4701 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4703 fsstats_FinishOp(&fsstats, code);
4705 osi_auditU(acall, SetLockEvent, code,
4706 AUD_ID, t_client ? t_client->ViceId : 0,
4707 AUD_FID, Fid, AUD_LONG, type, AUD_END);
4709 } /*SRXAFS_SetLock */
4713 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
4714 * merged into it when possible.
4717 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
4718 struct AFSVolSync *Sync)
4720 Vnode *targetptr = 0; /* vnode of input file */
4721 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4722 Error errorCode = 0; /* error code */
4723 Volume *volptr = 0; /* pointer to the volume header */
4724 struct client *client = 0; /* pointer to client structure */
4725 afs_int32 rights, anyrights; /* rights for this and any user */
4726 struct client *t_client; /* tmp ptr to client data */
4727 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4728 struct rx_connection *tcon = rx_ConnectionOf(acall);
4730 /* Get ptr to client data for user Id for logging */
4731 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4732 logHostAddr.s_addr = rxr_HostOf(tcon);
4734 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4735 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4736 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4738 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
4741 * Get the vnode and volume for the desired file along with the caller's
4745 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4746 &parentwhentargetnotdir, &client, WRITE_LOCK,
4747 &rights, &anyrights))) {
4748 goto Bad_ExtendLock;
4751 /* set volume synchronization information */
4752 SetVolumeSync(Sync, volptr);
4754 /* Handle the actual lock extension */
4755 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
4758 /* Put back file's vnode and volume */
4759 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4760 (Vnode *) 0, volptr, &client);
4762 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
4763 errorCode = 0; /* under our generous policy re RO vols */
4765 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
4768 } /*SAFSS_ExtendLock */
4772 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4773 struct AFSVolSync * Sync)
4775 return SRXAFS_ExtendLock(acall, Fid, Sync);
4776 } /*SRXAFS_OldExtendLock */
4780 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4781 struct AFSVolSync * Sync)
4784 struct rx_connection *tcon;
4786 struct client *t_client = NULL; /* tmp ptr to client data */
4787 struct fsstats fsstats;
4789 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_EXTENDLOCK);
4791 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4792 goto Bad_ExtendLock;
4794 code = SAFSS_ExtendLock(acall, Fid, Sync);
4797 code = CallPostamble(tcon, code, thost);
4799 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4801 fsstats_FinishOp(&fsstats, code);
4803 osi_auditU(acall, ExtendLockEvent, code,
4804 AUD_ID, t_client ? t_client->ViceId : 0,
4805 AUD_FID, Fid, AUD_END);
4808 } /*SRXAFS_ExtendLock */
4812 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
4813 * merged into it when possible.
4816 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
4817 struct AFSVolSync *Sync)
4819 Vnode *targetptr = 0; /* vnode of input file */
4820 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4821 Error errorCode = 0; /* error code */
4822 Volume *volptr = 0; /* pointer to the volume header */
4823 struct client *client = 0; /* pointer to client structure */
4824 afs_int32 rights, anyrights; /* rights for this and any user */
4825 struct client *t_client; /* tmp ptr to client data */
4826 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4827 struct rx_connection *tcon = rx_ConnectionOf(acall);
4829 /* Get ptr to client data for user Id for logging */
4830 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4831 logHostAddr.s_addr = rxr_HostOf(tcon);
4833 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4834 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4835 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4837 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
4840 * Get the vnode and volume for the desired file along with the caller's
4844 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4845 &parentwhentargetnotdir, &client, WRITE_LOCK,
4846 &rights, &anyrights))) {
4847 goto Bad_ReleaseLock;
4850 /* set volume synchronization information */
4851 SetVolumeSync(Sync, volptr);
4853 /* Handle the actual lock release */
4854 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
4855 goto Bad_ReleaseLock;
4857 /* if no more locks left, a callback would be triggered here */
4858 if (targetptr->disk.lock.lockCount <= 0) {
4859 rx_KeepAliveOn(acall);
4860 /* convert the write lock to a read lock before breaking callbacks */
4861 VVnodeWriteToRead(&errorCode, targetptr);
4862 osi_Assert(!errorCode || errorCode == VSALVAGE);
4863 BreakCallBack(client->host, Fid, 0);
4867 /* Put back file's vnode and volume */
4868 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4869 (Vnode *) 0, volptr, &client);
4871 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
4872 errorCode = 0; /* under our generous policy re RO vols */
4874 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
4877 } /*SAFSS_ReleaseLock */
4881 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4882 struct AFSVolSync * Sync)
4884 return SRXAFS_ReleaseLock(acall, Fid, Sync);
4885 } /*SRXAFS_OldReleaseLock */
4889 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4890 struct AFSVolSync * Sync)
4893 struct rx_connection *tcon;
4895 struct client *t_client = NULL; /* tmp ptr to client data */
4896 struct fsstats fsstats;
4898 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RELEASELOCK);
4900 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4901 goto Bad_ReleaseLock;
4903 code = SAFSS_ReleaseLock(acall, Fid, Sync);
4906 code = CallPostamble(tcon, code, thost);
4908 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4910 fsstats_FinishOp(&fsstats, code);
4912 osi_auditU(acall, ReleaseLockEvent, code,
4913 AUD_ID, t_client ? t_client->ViceId : 0,
4914 AUD_FID, Fid, AUD_END);
4917 } /*SRXAFS_ReleaseLock */
4921 SetSystemStats(struct AFSStatistics *stats)
4923 /* Fix this sometime soon.. */
4924 /* Because hey, it's not like we have a network monitoring protocol... */
4925 struct timeval time;
4927 /* this works on all system types */
4928 FT_GetTimeOfDay(&time, 0);
4929 stats->CurrentTime = time.tv_sec;
4930 } /*SetSystemStats */
4933 SetAFSStats(struct AFSStatistics *stats)
4935 extern afs_int32 StartTime, CurrentConnections;
4939 stats->CurrentMsgNumber = 0;
4940 stats->OldestMsgNumber = 0;
4941 stats->StartTime = StartTime;
4942 stats->CurrentConnections = CurrentConnections;
4943 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
4944 stats->TotalFetchs =
4945 AFSCallStats.FetchData + AFSCallStats.FetchACL +
4946 AFSCallStats.FetchStatus;
4947 stats->FetchDatas = AFSCallStats.FetchData;
4948 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
4949 seconds = AFSCallStats.AccumFetchTime / 1000;
4952 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
4953 stats->TotalStores =
4954 AFSCallStats.StoreData + AFSCallStats.StoreACL +
4955 AFSCallStats.StoreStatus;
4956 stats->StoreDatas = AFSCallStats.StoreData;
4957 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
4958 seconds = AFSCallStats.AccumStoreTime / 1000;
4961 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
4963 stats->ProcessSize = -1; /* TODO: */
4965 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
4968 h_GetWorkStats((int *)&(stats->WorkStations),
4969 (int *)&(stats->ActiveWorkStations), (int *)0,
4970 (afs_int32) (FT_ApproxTime()) - (15 * 60));
4974 /* Get disk related information from all AFS partitions. */
4977 SetVolumeStats(struct AFSStatistics *stats)
4979 struct DiskPartition64 *part;
4982 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
4983 part = part->next) {
4984 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
4985 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
4986 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
4987 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
4990 while (i < AFS_MSTATDISKS) {
4991 stats->Disks[i].TotalBlocks = -1;
4994 } /*SetVolumeStats */
4997 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5000 struct rx_connection *tcon = rx_ConnectionOf(acall);
5002 struct client *t_client = NULL; /* tmp ptr to client data */
5003 struct fsstats fsstats;
5005 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5007 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5008 goto Bad_GetStatistics;
5010 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5012 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5014 memset(Statistics, 0, sizeof(*Statistics));
5015 SetAFSStats((struct AFSStatistics *)Statistics);
5016 SetVolumeStats((struct AFSStatistics *)Statistics);
5017 SetSystemStats((struct AFSStatistics *)Statistics);
5020 code = CallPostamble(tcon, code, thost);
5022 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5024 fsstats_FinishOp(&fsstats, code);
5026 osi_auditU(acall, GetStatisticsEvent, code,
5027 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5029 } /*SRXAFS_GetStatistics */
5033 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5035 extern afs_int32 StartTime, CurrentConnections;
5038 struct rx_connection *tcon = rx_ConnectionOf(acall);
5040 struct client *t_client = NULL; /* tmp ptr to client data */
5041 struct timeval time;
5042 struct fsstats fsstats;
5044 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5046 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5047 goto Bad_GetStatistics64;
5049 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5050 Statistics->ViceStatistics64_val =
5051 malloc(statsVersion*sizeof(afs_int64));
5052 Statistics->ViceStatistics64_len = statsVersion;
5054 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5055 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5056 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5058 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5059 AFSCallStats.TotalCalls;
5060 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5061 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5062 AFSCallStats.FetchStatus;
5063 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5064 AFSCallStats.FetchData;
5065 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5066 AFSCallStats.TotalFetchedBytes;
5067 seconds = AFSCallStats.AccumFetchTime / 1000;
5070 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5071 AFSCallStats.TotalFetchedBytes / seconds;
5072 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5073 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5074 AFSCallStats.StoreStatus;
5075 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5076 AFSCallStats.StoreData;
5077 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5078 AFSCallStats.TotalStoredBytes;
5079 seconds = AFSCallStats.AccumStoreTime / 1000;
5082 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5083 AFSCallStats.TotalStoredBytes / seconds;
5085 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5087 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5088 (afs_int32) ((long)sbrk(0) >> 10);
5091 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5092 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5094 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5098 /* this works on all system types */
5099 FT_GetTimeOfDay(&time, 0);
5100 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5102 Bad_GetStatistics64:
5103 code = CallPostamble(tcon, code, thost);
5105 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5107 fsstats_FinishOp(&fsstats, code);
5109 osi_auditU(acall, GetStatisticsEvent, code,
5110 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5112 } /*SRXAFS_GetStatistics */
5115 /*------------------------------------------------------------------------
5116 * EXPORTED SRXAFS_XStatsVersion
5119 * Routine called by the server-side RPC interface to implement
5120 * pulling out the xstat version number for the File Server.
5123 * a_versionP : Ptr to the version number variable to set.
5129 * Nothing interesting.
5133 *------------------------------------------------------------------------*/
5136 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5137 { /*SRXAFS_XStatsVersion */
5139 struct client *t_client = NULL; /* tmp ptr to client data */
5140 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5141 struct fsstats fsstats;
5143 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_XSTATSVERSION);
5145 *a_versionP = AFS_XSTAT_VERSION;
5147 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5149 fsstats_FinishOp(&fsstats, 0);
5151 osi_auditU(a_call, XStatsVersionEvent, 0,
5152 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5154 } /*SRXAFS_XStatsVersion */
5157 /*------------------------------------------------------------------------
5158 * PRIVATE FillPerfValues
5161 * Routine called to fill a regular performance data structure.
5164 * a_perfP : Ptr to perf structure to fill
5170 * Various collections need this info, so the guts were put in
5171 * this separate routine.
5175 *------------------------------------------------------------------------*/
5178 FillPerfValues(struct afs_PerfStats *a_perfP)
5179 { /*FillPerfValues */
5180 int dir_Buffers; /*# buffers in use by dir package */
5181 int dir_Calls; /*# read calls in dir package */
5182 int dir_IOs; /*# I/O ops in dir package */
5183 struct rx_statistics *stats;
5186 * Vnode cache section.
5188 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5189 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5190 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5191 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5192 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5193 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5194 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5195 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5196 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5197 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5198 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5199 a_perfP->vcache_H_Gets = (int)VStats.hdr_gets;
5200 a_perfP->vcache_H_Replacements = (int)VStats.hdr_loads;
5203 * Directory section.
5205 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5206 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5207 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5208 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5213 stats = rx_GetStatistics();
5215 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5216 a_perfP->rx_noPackets_RcvClass =
5217 (afs_int32) stats->receivePktAllocFailures;
5218 a_perfP->rx_noPackets_SendClass =
5219 (afs_int32) stats->sendPktAllocFailures;
5220 a_perfP->rx_noPackets_SpecialClass =
5221 (afs_int32) stats->specialPktAllocFailures;
5222 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5223 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5224 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5225 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5226 a_perfP->rx_noPacketBuffersOnRead =
5227 (afs_int32) stats->noPacketBuffersOnRead;
5228 a_perfP->rx_selects = (afs_int32) stats->selects;
5229 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5230 a_perfP->rx_packetsRead_RcvClass =
5231 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5232 a_perfP->rx_packetsRead_SendClass =
5233 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5234 a_perfP->rx_packetsRead_SpecialClass =
5235 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5236 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5237 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5238 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5239 a_perfP->rx_spuriousPacketsRead =
5240 (afs_int32) stats->spuriousPacketsRead;
5241 a_perfP->rx_packetsSent_RcvClass =
5242 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5243 a_perfP->rx_packetsSent_SendClass =
5244 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5245 a_perfP->rx_packetsSent_SpecialClass =
5246 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5247 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5248 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5249 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
5250 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
5251 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
5252 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
5253 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
5254 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
5255 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
5256 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
5257 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
5258 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
5259 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
5260 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
5261 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
5262 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
5263 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
5264 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
5265 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
5266 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
5268 a_perfP->host_NumHostEntries = HTs;
5269 a_perfP->host_HostBlocks = HTBlocks;
5270 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5271 &(a_perfP->host_HostsInSameNetOrSubnet),
5272 &(a_perfP->host_HostsInDiffSubnet),
5273 &(a_perfP->host_HostsInDiffNetwork));
5274 a_perfP->host_NumClients = CEs;
5275 a_perfP->host_ClientBlocks = CEBlocks;
5277 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5278 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
5279 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5280 rx_FreeStatistics(&stats);
5281 } /*FillPerfValues */
5284 /*------------------------------------------------------------------------
5285 * EXPORTED SRXAFS_GetXStats
5288 * Routine called by the server-side callback RPC interface to
5289 * implement getting the given data collection from the extended
5290 * File Server statistics.
5293 * a_call : Ptr to Rx call on which this request came in.
5294 * a_clientVersionNum : Client version number.
5295 * a_opCode : Desired operation.
5296 * a_serverVersionNumP : Ptr to version number to set.
5297 * a_timeP : Ptr to time value (seconds) to set.
5298 * a_dataP : Ptr to variable array structure to return
5305 * Nothing interesting.
5309 *------------------------------------------------------------------------*/
5312 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5313 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5314 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5315 { /*SRXAFS_GetXStats */
5317 int code; /*Return value */
5318 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5319 afs_int32 dataBytes; /*Bytes in data buffer */
5320 struct fsstats fsstats;
5322 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETXSTATS);
5325 * Record the time of day and the server version number.
5327 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5328 *a_timeP = FT_ApproxTime();
5331 * Stuff the appropriate data in there (assume victory)
5336 ("Received GetXStats call for collection %d\n",
5337 a_collectionNumber));
5341 * We're not keeping stats, so just return successfully with
5344 a_dataP->AFS_CollData_len = 0;
5345 a_dataP->AFS_CollData_val = NULL;
5348 switch (a_collectionNumber) {
5349 case AFS_XSTATSCOLL_CALL_INFO:
5351 * Pass back all the call-count-related data.
5353 * >>> We are forced to allocate a separate area in which to
5354 * >>> put this stuff in by the RPC stub generator, since it
5355 * >>> will be freed at the tail end of the server stub code.
5359 * I don't think call-level stats are being collected yet
5360 * for the File Server.
5362 dataBytes = sizeof(struct afs_Stats);
5363 dataBuffP = (afs_int32 *) malloc(dataBytes);
5364 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5365 a_dataP->AFS_CollData_len = dataBytes >> 2;
5366 a_dataP->AFS_CollData_val = dataBuffP;
5368 a_dataP->AFS_CollData_len = 0;
5369 a_dataP->AFS_CollData_val = NULL;
5373 case AFS_XSTATSCOLL_PERF_INFO:
5375 * Pass back all the regular performance-related data.
5377 * >>> We are forced to allocate a separate area in which to
5378 * >>> put this stuff in by the RPC stub generator, since it
5379 * >>> will be freed at the tail end of the server stub code.
5382 afs_perfstats.numPerfCalls++;
5383 FillPerfValues(&afs_perfstats);
5386 * Don't overwrite the spares at the end.
5389 dataBytes = sizeof(struct afs_PerfStats);
5390 dataBuffP = (afs_int32 *) malloc(dataBytes);
5391 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5392 a_dataP->AFS_CollData_len = dataBytes >> 2;
5393 a_dataP->AFS_CollData_val = dataBuffP;
5396 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5398 * Pass back the full collection of performance-related data.
5399 * We have to stuff the basic, overall numbers in, but the
5400 * detailed numbers are kept in the structure already.
5402 * >>> We are forced to allocate a separate area in which to
5403 * >>> put this stuff in by the RPC stub generator, since it
5404 * >>> will be freed at the tail end of the server stub code.
5407 afs_perfstats.numPerfCalls++;
5408 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5409 FillPerfValues(&afs_FullPerfStats.overall);
5412 * Don't overwrite the spares at the end.
5415 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5416 dataBuffP = (afs_int32 *) malloc(dataBytes);
5417 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5418 a_dataP->AFS_CollData_len = dataBytes >> 2;
5419 a_dataP->AFS_CollData_val = dataBuffP;
5422 case AFS_XSTATSCOLL_CBSTATS:
5423 afs_perfstats.numPerfCalls++;
5425 dataBytes = sizeof(struct cbcounters);
5426 dataBuffP = (afs_int32 *) malloc(dataBytes);
5428 extern struct cbcounters cbstuff;
5429 dataBuffP[0]=cbstuff.DeleteFiles;
5430 dataBuffP[1]=cbstuff.DeleteCallBacks;
5431 dataBuffP[2]=cbstuff.BreakCallBacks;
5432 dataBuffP[3]=cbstuff.AddCallBacks;
5433 dataBuffP[4]=cbstuff.GotSomeSpaces;
5434 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
5435 dataBuffP[6]=cbstuff.nFEs;
5436 dataBuffP[7]=cbstuff.nCBs;
5437 dataBuffP[8]=cbstuff.nblks;
5438 dataBuffP[9]=cbstuff.CBsTimedOut;
5439 dataBuffP[10]=cbstuff.nbreakers;
5440 dataBuffP[11]=cbstuff.GSS1;
5441 dataBuffP[12]=cbstuff.GSS2;
5442 dataBuffP[13]=cbstuff.GSS3;
5443 dataBuffP[14]=cbstuff.GSS4;
5444 dataBuffP[15]=cbstuff.GSS5;
5447 a_dataP->AFS_CollData_len = dataBytes >> 2;
5448 a_dataP->AFS_CollData_val = dataBuffP;
5454 * Illegal collection number.
5456 a_dataP->AFS_CollData_len = 0;
5457 a_dataP->AFS_CollData_val = NULL;
5459 } /*Switch on collection number */
5461 fsstats_FinishOp(&fsstats, code);
5465 } /*SRXAFS_GetXStats */
5469 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5470 struct AFSCBs *CallBackArray)
5472 afs_int32 errorCode = 0;
5474 struct client *client = 0;
5475 struct rx_connection *tcon;
5477 struct fsstats fsstats;
5479 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GIVEUPCALLBACKS);
5483 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5484 FidArray->AFSCBFids_len));
5487 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5489 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5490 goto Bad_GiveUpCallBacks;
5492 if (!FidArray && !CallBackArray) {
5494 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5495 (rx_PeerOf(tcon) ? rx_PeerOf(tcon)->host : 0)));
5496 errorCode = GetClient(tcon, &client);
5499 DeleteAllCallBacks_r(client->host, 1);
5504 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5506 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5507 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5508 (rx_PeerOf(tcon) ? rx_PeerOf(tcon)->host : 0)));
5510 goto Bad_GiveUpCallBacks;
5513 errorCode = GetClient(tcon, &client);
5515 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5516 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5517 DeleteCallBack(client->host, fid);
5523 Bad_GiveUpCallBacks:
5524 errorCode = CallPostamble(tcon, errorCode, thost);
5526 fsstats_FinishOp(&fsstats, errorCode);
5530 } /*common_GiveUpCallBacks */
5534 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5535 struct AFSCBs * CallBackArray)
5537 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5538 } /*SRXAFS_GiveUpCallBacks */
5541 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
5543 return common_GiveUpCallBacks(acall, 0, 0);
5544 } /*SRXAFS_GiveUpAllCallBacks */
5548 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
5549 struct AFSVolumeInfo * avolinfo)
5551 return (VNOVOL); /* XXX Obsolete routine XXX */
5553 } /*SRXAFS_NGetVolumeInfo */
5557 * Dummy routine. Should never be called (the cache manager should only
5558 * invoke this interface when communicating with a AFS/DFS Protocol
5562 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
5563 char *afs_name_p, struct AFSFid * afs_fid_p,
5564 struct AFSFetchStatus * afs_status_p,
5565 struct AFSFetchStatus * afs_dir_status_p,
5566 struct AFSCallBack * afs_callback_p,
5567 struct AFSVolSync * afs_sync_p)
5574 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
5577 struct rx_connection *tcon;
5579 afs_uint32 *dataBuffP;
5580 afs_int32 dataBytes;
5583 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
5584 afs_FullPerfStats.overall.fs_nGetCaps++;
5586 ViceLog(2, ("SAFS_GetCapabilties\n"));
5588 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5591 dataBytes = 1 * sizeof(afs_int32);
5592 dataBuffP = (afs_uint32 *) malloc(dataBytes);
5593 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
5594 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
5596 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
5598 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
5599 capabilities->Capabilities_val = dataBuffP;
5602 code = CallPostamble(tcon, code, thost);
5609 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
5610 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
5614 afs_int32 nids, naddrs;
5615 afs_int32 *vd, *addr;
5616 Error errorCode = 0; /* return code to caller */
5617 struct client *client = 0;
5619 ViceLog(1, ("SRXAFS_FlushCPS\n"));
5621 AFSCallStats.TotalCalls++;
5623 nids = vids->ViceIds_len; /* # of users in here */
5624 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
5625 if (nids < 0 || naddrs < 0) {
5630 vd = vids->ViceIds_val;
5631 for (i = 0; i < nids; i++, vd++) {
5634 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
5638 client->prfail = 2; /* Means re-eval client's cps */
5641 rx_SetRock(((struct rx_connection *)client->tcon), 0);
5644 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
5645 free(client->CPS.prlist_val);
5646 client->CPS.prlist_val = NULL;
5647 client->CPS.prlist_len = 0;
5649 ReleaseWriteLock(&client->lock);
5653 addr = addrs->IPAddrs_val;
5654 for (i = 0; i < naddrs; i++, addr++) {
5656 h_flushhostcps(*addr, htons(7001));
5660 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
5662 } /*SRXAFS_FlushCPS */
5664 /* worthless hack to let CS keep running ancient software */
5666 afs_vtoi(char *aname)
5672 while ((tc = *aname++)) {
5673 if (tc > '9' || tc < '0')
5674 return 0; /* invalid name */
5682 * may get name or #, but must handle all weird cases (recognize readonly
5683 * or backup volumes by name or #
5686 CopyVolumeEntry(char *aname, struct vldbentry *ave,
5687 struct VolumeInfo *av)
5690 afs_int32 mask, whichType;
5691 afs_uint32 *serverHost, *typePtr;
5693 /* figure out what type we want if by name */
5695 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
5696 whichType = BACKVOL;
5697 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
5702 vol = afs_vtoi(aname);
5704 vol = ave->volumeId[whichType];
5707 * Now vol has volume # we're interested in. Next, figure out the type
5708 * of the volume by looking finding it in the vldb entry
5710 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
5713 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
5716 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
5717 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
5718 whichType = BACKVOL;
5720 return EINVAL; /* error: can't find volume in vldb entry */
5722 typePtr = &av->Type0;
5723 serverHost = &av->Server0;
5725 av->Type = whichType;
5726 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
5727 if (ave->flags & VLF_RWEXISTS)
5728 typePtr[RWVOL] = ave->volumeId[RWVOL];
5729 if (ave->flags & VLF_ROEXISTS)
5730 typePtr[ROVOL] = ave->volumeId[ROVOL];
5731 if (ave->flags & VLF_BACKEXISTS)
5732 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
5734 for (i = 0, j = 0; i < ave->nServers; i++) {
5735 if ((ave->serverFlags[i] & mask) == 0)
5736 continue; /* wrong volume */
5737 serverHost[j] = ave->serverNumber[i];
5740 av->ServerCount = j;
5742 serverHost[j++] = 0; /* bogus 8, but compat only now */
5747 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
5749 static struct rx_connection *vlConn = 0;
5750 static int down = 0;
5751 static afs_int32 lastDownTime = 0;
5752 struct vldbentry tve;
5753 struct rx_securityClass *vlSec;
5757 vlSec = rxnull_NewClientSecurityObject();
5759 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
5760 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
5762 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
5763 return 1; /* failure */
5766 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
5768 down = 0; /* call worked */
5771 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
5777 /* otherwise convert to old format vldb entry */
5778 code = CopyVolumeEntry(avolid, &tve, avolinfo);
5788 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
5789 struct VolumeInfo * avolinfo)
5792 struct rx_connection *tcon;
5794 struct fsstats fsstats;
5796 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMEINFO);
5798 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5799 goto Bad_GetVolumeInfo;
5802 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
5804 code = TryLocalVLServer(avolid, avolinfo);
5806 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
5807 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
5808 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
5809 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
5812 code = CallPostamble(tcon, code, thost);
5814 fsstats_FinishOp(&fsstats, code);
5818 } /*SRXAFS_GetVolumeInfo */
5822 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5823 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
5824 char **OfflineMsg, char **Motd)
5826 Vnode *targetptr = 0; /* vnode of the new file */
5827 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5828 Error errorCode = 0; /* error code */
5829 Volume *volptr = 0; /* pointer to the volume header */
5830 struct client *client = 0; /* pointer to client entry */
5831 afs_int32 rights, anyrights; /* rights for this and any user */
5833 struct rx_connection *tcon;
5835 struct client *t_client = NULL; /* tmp ptr to client data */
5836 struct fsstats fsstats;
5838 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMESTATUS);
5840 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
5841 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5842 goto Bad_GetVolumeStatus;
5845 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
5849 goto Bad_GetVolumeStatus;
5851 dummyFid.Volume = avolid, dummyFid.Vnode =
5852 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5855 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
5856 &parentwhentargetnotdir, &client, READ_LOCK,
5857 &rights, &anyrights)))
5858 goto Bad_GetVolumeStatus;
5860 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
5862 goto Bad_GetVolumeStatus;
5864 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
5866 Bad_GetVolumeStatus:
5867 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
5868 (Vnode *) 0, volptr, &client);
5869 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
5870 /* next is to guarantee out strings exist for stub */
5872 *Name = (char *)malloc(1);
5876 *Motd = (char *)malloc(1);
5879 if (*OfflineMsg == 0) {
5880 *OfflineMsg = (char *)malloc(1);
5883 errorCode = CallPostamble(tcon, errorCode, thost);
5885 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5887 fsstats_FinishOp(&fsstats, errorCode);
5889 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
5890 AUD_ID, t_client ? t_client->ViceId : 0,
5891 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
5894 } /*SRXAFS_GetVolumeStatus */
5898 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5899 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
5900 char *OfflineMsg, char *Motd)
5902 Vnode *targetptr = 0; /* vnode of the new file */
5903 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5904 Error errorCode = 0; /* error code */
5905 Volume *volptr = 0; /* pointer to the volume header */
5906 struct client *client = 0; /* pointer to client entry */
5907 afs_int32 rights, anyrights; /* rights for this and any user */
5909 struct rx_connection *tcon = rx_ConnectionOf(acall);
5911 struct client *t_client = NULL; /* tmp ptr to client data */
5912 struct fsstats fsstats;
5914 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETVOLUMESTATUS);
5916 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
5917 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5918 goto Bad_SetVolumeStatus;
5921 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
5925 goto Bad_SetVolumeStatus;
5927 dummyFid.Volume = avolid, dummyFid.Vnode =
5928 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5931 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
5932 &parentwhentargetnotdir, &client, READ_LOCK,
5933 &rights, &anyrights)))
5934 goto Bad_SetVolumeStatus;
5936 if (readonlyServer) {
5937 errorCode = VREADONLY;
5938 goto Bad_SetVolumeStatus;
5940 if (VanillaUser(client)) {
5942 goto Bad_SetVolumeStatus;
5946 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
5948 Bad_SetVolumeStatus:
5949 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
5951 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
5952 errorCode = CallPostamble(tcon, errorCode, thost);
5954 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5956 fsstats_FinishOp(&fsstats, errorCode);
5958 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
5959 AUD_ID, t_client ? t_client->ViceId : 0,
5960 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
5962 } /*SRXAFS_SetVolumeStatus */
5964 #define DEFAULTVOLUME "root.afs"
5967 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
5973 struct rx_connection *tcon;
5975 Error errorCode = 0;
5977 struct fsstats fsstats;
5979 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETROOTVOLUME);
5981 return FSERR_EOPNOTSUPP;
5984 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
5985 goto Bad_GetRootVolume;
5987 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
5990 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
5992 strcpy(temp, DEFAULTVOLUME);
5994 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
5995 lockf(fd, F_LOCK, 0);
5999 len = read(fd, temp, 256);
6000 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6001 lockf(fd, F_ULOCK, 0);
6006 if (temp[len - 1] == '\n')
6010 *VolumeName = temp; /* freed by rx server-side stub */
6013 errorCode = CallPostamble(tcon, errorCode, thost);
6015 fsstats_FinishOp(&fsstats, errorCode);
6020 } /*SRXAFS_GetRootVolume */
6023 /* still works because a struct CBS is the same as a struct AFSOpaque */
6025 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6026 struct AFSOpaque * Token)
6029 struct rx_connection *tcon;
6031 struct fsstats fsstats;
6033 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CHECKTOKEN);
6035 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6036 goto Bad_CheckToken;
6038 code = FSERR_ECONNREFUSED;
6041 code = CallPostamble(tcon, code, thost);
6043 fsstats_FinishOp(&fsstats, code);
6047 } /*SRXAFS_CheckToken */
6050 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6051 afs_uint32 * USeconds)
6054 struct rx_connection *tcon;
6057 struct fsstats fsstats;
6059 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETTIME);
6061 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6065 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6067 FT_GetTimeOfDay(&tpl, 0);
6068 *Seconds = tpl.tv_sec;
6069 *USeconds = tpl.tv_usec;
6071 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6074 code = CallPostamble(tcon, code, thost);
6076 fsstats_FinishOp(&fsstats, code);
6080 } /*SRXAFS_GetTime */
6087 * Implement a client's data fetch using Rx.
6090 * volptr : Ptr to the given volume's info.
6091 * targetptr : Pointer to the vnode involved.
6092 * Call : Ptr to the Rx call involved.
6093 * Pos : Offset within the file.
6094 * Len : Length in bytes to read; this value is bogus!
6095 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6097 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6102 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6103 struct rx_call * Call, afs_sfsize_t Pos,
6104 afs_sfsize_t Len, afs_int32 Int64Mode,
6105 afs_sfsize_t * a_bytesToFetchP,
6106 afs_sfsize_t * a_bytesFetchedP)
6108 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6113 #else /* HAVE_PIOV */
6114 struct iovec tiov[RX_MAXIOVECS];
6116 #endif /* HAVE_PIOV */
6121 * Initialize the byte count arguments.
6123 (*a_bytesToFetchP) = 0;
6124 (*a_bytesFetchedP) = 0;
6127 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6128 (afs_uintmax_t) Len));
6130 if (!VN_GET_INO(targetptr)) {
6131 afs_int32 zero = htonl(0);
6133 * This is used for newly created files; we simply send 0 bytes
6134 * back to make the cache manager happy...
6137 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6138 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6141 FT_GetTimeOfDay(&StartTime, 0);
6142 ihP = targetptr->handle;
6145 VTakeOffline(volptr);
6146 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6150 optSize = sendBufSize;
6151 tlen = FDH_SIZE(fdP);
6153 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6156 VTakeOffline(volptr);
6157 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6161 if (CheckLength(volptr, targetptr, tlen)) {
6163 VTakeOffline(volptr);
6170 if (Pos + Len > tlen) /* get length we should send */
6171 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
6174 afs_int32 high, low;
6175 SplitOffsetOrSize(Len, high, low);
6176 osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6179 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6182 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6184 (*a_bytesToFetchP) = Len;
6186 tbuffer = AllocSendBuffer();
6187 #endif /* HAVE_PIOV */
6196 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
6197 if (nBytes != wlen) {
6199 FreeSendBuffer((struct afs_buffer *)tbuffer);
6200 VTakeOffline(volptr);
6201 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6205 nBytes = rx_Write(Call, tbuffer, wlen);
6206 #else /* HAVE_PIOV */
6207 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6213 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
6214 if (nBytes != wlen) {
6216 VTakeOffline(volptr);
6217 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6221 nBytes = rx_Writev(Call, tiov, tnio, wlen);
6222 #endif /* HAVE_PIOV */
6225 * Bump the number of bytes actually sent by the number from this
6228 (*a_bytesFetchedP) += nBytes;
6229 if (nBytes != wlen) {
6233 FreeSendBuffer((struct afs_buffer *)tbuffer);
6234 #endif /* HAVE_PIOV */
6235 err = VIsGoingOffline(volptr);
6244 FreeSendBuffer((struct afs_buffer *)tbuffer);
6245 #endif /* HAVE_PIOV */
6247 FT_GetTimeOfDay(&StopTime, 0);
6249 /* Adjust all Fetch Data related stats */
6251 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6252 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6253 AFSCallStats.AccumFetchTime +=
6254 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6255 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6257 afs_fsize_t targLen;
6258 VN_GET_LEN(targLen, targetptr);
6259 AFSCallStats.TotalFetchedBytes += targLen;
6260 AFSCallStats.FetchSize1++;
6261 if (targLen < SIZE2)
6262 AFSCallStats.FetchSize2++;
6263 else if (targLen < SIZE3)
6264 AFSCallStats.FetchSize3++;
6265 else if (targLen < SIZE4)
6266 AFSCallStats.FetchSize4++;
6268 AFSCallStats.FetchSize5++;
6273 } /*FetchData_RXStyle */
6276 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6277 afs_sfsize_t * size)
6279 #ifdef AFS_NAMEI_ENV
6281 lhp = IH_OPEN(V_linkHandle(vp));
6284 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
6288 *size = OS_SIZE(fdP->fd_fd);
6289 return (*size == -1) ? -1 : 0;
6291 struct afs_stat status;
6293 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6297 *lc = GetLinkCount(vp, &status);
6298 *size = status.st_size;
6307 * Implement a client's data store using Rx.
6310 * volptr : Ptr to the given volume's info.
6311 * targetptr : Pointer to the vnode involved.
6312 * Call : Ptr to the Rx call involved.
6313 * Pos : Offset within the file.
6314 * Len : Length in bytes to store; this value is bogus!
6315 * a_bytesToStoreP : Set to the number of bytes to be stored to
6317 * a_bytesStoredP : Set to the actual number of bytes stored to
6321 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6322 struct client * client, struct rx_call * Call,
6323 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6325 afs_sfsize_t * a_bytesToStoreP,
6326 afs_sfsize_t * a_bytesStoredP)
6328 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6329 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6330 Error errorCode = 0; /* Returned error code to caller */
6332 char *tbuffer; /* data copying buffer */
6333 #else /* HAVE_PIOV */
6334 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6335 int tnio; /* temp for iovec size */
6336 #endif /* HAVE_PIOV */
6337 afs_sfsize_t tlen; /* temp for xfr length */
6338 Inode tinode; /* inode for I/O */
6339 afs_int32 optSize; /* optimal transfer size */
6340 afs_sfsize_t DataLength = 0; /* size of inode */
6341 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6342 afs_fsize_t NewLength; /* size after this store completes */
6343 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6344 int linkCount = 0; /* link count on inode */
6347 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6351 * Initialize the byte count arguments.
6353 (*a_bytesToStoreP) = 0;
6354 (*a_bytesStoredP) = 0;
6357 * We break the callbacks here so that the following signal will not
6360 BreakCallBack(client->host, Fid, 0);
6362 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6363 /* the inode should have been created in Alloc_NewVnode */
6364 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
6366 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
6367 Fid->Volume, Fid->Vnode, Fid->Unique,
6368 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
6369 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
6370 return ENOENT; /* is this proper error code? */
6372 rx_KeepAliveOff(Call);
6374 * See if the file has several links (from other volumes). If it
6375 * does, then we have to make a copy before changing it to avoid
6376 *changing read-only clones of this dude
6379 ("StoreData_RXStyle : Opening inode %s\n",
6380 PrintInode(stmp, VN_GET_INO(targetptr))));
6381 fdP = IH_OPEN(targetptr->handle);
6384 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
6386 VTakeOffline(volptr);
6387 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6391 if (CheckLength(volptr, targetptr, DataLength)) {
6393 VTakeOffline(volptr);
6397 if (linkCount != 1) {
6400 ("StoreData_RXStyle : inode %s has more than onelink\n",
6401 PrintInode(stmp, VN_GET_INO(targetptr))));
6402 /* other volumes share this data, better copy it first */
6404 /* Adjust the disk block count by the creation of the new inode.
6405 * We call the special VDiskUsage so we don't adjust the volume's
6406 * quota since we don't want to penalyze the user for afs's internal
6407 * mechanisms (i.e. copy on write overhead.) Also the right size
6408 * of the disk will be recorded...
6411 VN_GET_LEN(size, targetptr);
6412 volptr->partition->flags &= ~PART_DONTUPDATE;
6413 VSetPartitionDiskUsage(volptr->partition);
6414 volptr->partition->flags |= PART_DONTUPDATE;
6415 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6416 volptr->partition->flags &= ~PART_DONTUPDATE;
6420 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6421 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, MAXFSIZE))) {
6422 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6423 volptr->partition->flags &= ~PART_DONTUPDATE;
6426 volptr->partition->flags &= ~PART_DONTUPDATE;
6427 VSetPartitionDiskUsage(volptr->partition);
6428 fdP = IH_OPEN(targetptr->handle);
6431 ("StoreData : Reopen after CopyOnWrite failed\n"));
6435 tinode = VN_GET_INO(targetptr);
6437 if (!VALID_INO(tinode)) {
6438 VTakeOffline(volptr);
6439 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
6444 /* compute new file length */
6445 NewLength = DataLength;
6446 if (FileLength < NewLength)
6447 /* simulate truncate */
6448 NewLength = FileLength;
6449 TruncatedLength = NewLength; /* remember length after possible ftruncate */
6450 if (Pos + Length > NewLength)
6451 NewLength = Pos + Length; /* and write */
6453 /* adjust the disk block count by the difference in the files */
6455 afs_fsize_t targSize;
6456 VN_GET_LEN(targSize, targetptr);
6457 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
6460 AdjustDiskUsage(volptr, adjustSize,
6461 adjustSize - SpareComp(volptr)))) {
6466 /* can signal cache manager to proceed from close now */
6467 /* this bit means that the locks are set and protections are OK */
6468 rx_SetLocalStatus(Call, 1);
6470 FT_GetTimeOfDay(&StartTime, 0);
6472 optSize = sendBufSize;
6474 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
6475 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
6476 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
6478 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
6479 if (FileLength < DataLength)
6480 FDH_TRUNC(fdP, FileLength);
6481 bytesTransfered = 0;
6483 tbuffer = AllocSendBuffer();
6484 #endif /* HAVE_PIOV */
6485 /* if length == 0, the loop below isn't going to do anything, including
6486 * extend the length of the inode, which it must do, since the file system
6487 * assumes that the inode length == vnode's file length. So, we extend
6488 * the file length manually if need be. Note that if file is bigger than
6489 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
6490 * do what we're going to do below.
6492 if (Length == 0 && Pos > TruncatedLength) {
6493 /* Set the file's length; we've already done an lseek to the right
6496 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
6501 errorCode = FDH_TRUNC(fdP, Pos);
6503 /* have some data to copy */
6504 (*a_bytesToStoreP) = Length;
6507 if (bytesTransfered >= Length) {
6511 tlen = Length - bytesTransfered; /* how much more to do */
6513 rlen = optSize; /* bound by buffer size */
6517 errorCode = rx_Read(Call, tbuffer, rlen);
6518 #else /* HAVE_PIOV */
6519 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
6520 #endif /* HAVE_PIOV */
6521 if (errorCode <= 0) {
6525 (*a_bytesStoredP) += errorCode;
6528 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
6529 #else /* HAVE_PIOV */
6530 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
6531 #endif /* HAVE_PIOV */
6532 if (nBytes != rlen) {
6533 errorCode = VDISKFULL;
6536 bytesTransfered += rlen;
6542 FreeSendBuffer((struct afs_buffer *)tbuffer);
6543 #endif /* HAVE_PIOV */
6548 Error tmp_errorCode = 0;
6549 afs_sfsize_t nfSize = FDH_SIZE(fdP);
6550 osi_Assert(nfSize >= 0);
6551 /* something went wrong: adjust size and return */
6552 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
6553 /* changed_newTime is tested in StoreData to detemine if we
6554 * need to update the target vnode.
6556 targetptr->changed_newTime = 1;
6558 /* set disk usage to be correct */
6559 VAdjustDiskUsage(&tmp_errorCode, volptr,
6560 (afs_sfsize_t) (nBlocks(nfSize) -
6561 nBlocks(NewLength)), 0);
6562 if (tmp_errorCode) {
6563 errorCode = tmp_errorCode;
6569 FT_GetTimeOfDay(&StopTime, 0);
6571 VN_SET_LEN(targetptr, NewLength);
6573 /* Update all StoreData related stats */
6575 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
6576 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
6577 AFSCallStats.StoreSize1++; /* Piggybacked data */
6579 afs_fsize_t targLen;
6580 VN_GET_LEN(targLen, targetptr);
6581 if (targLen < SIZE2)
6582 AFSCallStats.StoreSize2++;
6583 else if (targLen < SIZE3)
6584 AFSCallStats.StoreSize3++;
6585 else if (targLen < SIZE4)
6586 AFSCallStats.StoreSize4++;
6588 AFSCallStats.StoreSize5++;
6593 } /*StoreData_RXStyle */
6595 static int sys2et[512];
6598 init_sys_error_to_et(void)
6600 memset(&sys2et, 0, sizeof(sys2et));
6601 sys2et[EPERM] = UAEPERM;
6602 sys2et[ENOENT] = UAENOENT;
6603 sys2et[ESRCH] = UAESRCH;
6604 sys2et[EINTR] = UAEINTR;
6605 sys2et[EIO] = UAEIO;
6606 sys2et[ENXIO] = UAENXIO;
6607 sys2et[E2BIG] = UAE2BIG;
6608 sys2et[ENOEXEC] = UAENOEXEC;
6609 sys2et[EBADF] = UAEBADF;
6610 sys2et[ECHILD] = UAECHILD;
6611 sys2et[EAGAIN] = UAEAGAIN;
6612 sys2et[ENOMEM] = UAENOMEM;
6613 sys2et[EACCES] = UAEACCES;
6614 sys2et[EFAULT] = UAEFAULT;
6615 sys2et[ENOTBLK] = UAENOTBLK;
6616 sys2et[EBUSY] = UAEBUSY;
6617 sys2et[EEXIST] = UAEEXIST;
6618 sys2et[EXDEV] = UAEXDEV;
6619 sys2et[ENODEV] = UAENODEV;
6620 sys2et[ENOTDIR] = UAENOTDIR;
6621 sys2et[EISDIR] = UAEISDIR;
6622 sys2et[EINVAL] = UAEINVAL;
6623 sys2et[ENFILE] = UAENFILE;
6624 sys2et[EMFILE] = UAEMFILE;
6625 sys2et[ENOTTY] = UAENOTTY;
6626 sys2et[ETXTBSY] = UAETXTBSY;
6627 sys2et[EFBIG] = UAEFBIG;
6628 sys2et[ENOSPC] = UAENOSPC;
6629 sys2et[ESPIPE] = UAESPIPE;
6630 sys2et[EROFS] = UAEROFS;
6631 sys2et[EMLINK] = UAEMLINK;
6632 sys2et[EPIPE] = UAEPIPE;
6633 sys2et[EDOM] = UAEDOM;
6634 sys2et[ERANGE] = UAERANGE;
6635 sys2et[EDEADLK] = UAEDEADLK;
6636 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
6637 sys2et[ENOLCK] = UAENOLCK;
6638 sys2et[ENOSYS] = UAENOSYS;
6639 #if (ENOTEMPTY != EEXIST)
6640 sys2et[ENOTEMPTY] = UAENOTEMPTY;
6642 sys2et[ELOOP] = UAELOOP;
6643 #if (EWOULDBLOCK != EAGAIN)
6644 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
6646 sys2et[ENOMSG] = UAENOMSG;
6647 sys2et[EIDRM] = UAEIDRM;
6648 sys2et[ECHRNG] = UAECHRNG;
6649 sys2et[EL2NSYNC] = UAEL2NSYNC;
6650 sys2et[EL3HLT] = UAEL3HLT;
6651 sys2et[EL3RST] = UAEL3RST;
6652 sys2et[ELNRNG] = UAELNRNG;
6653 sys2et[EUNATCH] = UAEUNATCH;
6654 sys2et[ENOCSI] = UAENOCSI;
6655 sys2et[EL2HLT] = UAEL2HLT;
6656 sys2et[EBADE] = UAEBADE;
6657 sys2et[EBADR] = UAEBADR;
6658 sys2et[EXFULL] = UAEXFULL;
6659 sys2et[ENOANO] = UAENOANO;
6660 sys2et[EBADRQC] = UAEBADRQC;
6661 sys2et[EBADSLT] = UAEBADSLT;
6662 sys2et[EDEADLK] = UAEDEADLK;
6663 sys2et[EBFONT] = UAEBFONT;
6664 sys2et[ENOSTR] = UAENOSTR;
6665 sys2et[ENODATA] = UAENODATA;
6666 sys2et[ETIME] = UAETIME;
6667 sys2et[ENOSR] = UAENOSR;
6668 sys2et[ENONET] = UAENONET;
6669 sys2et[ENOPKG] = UAENOPKG;
6670 sys2et[EREMOTE] = UAEREMOTE;
6671 sys2et[ENOLINK] = UAENOLINK;
6672 sys2et[EADV] = UAEADV;
6673 sys2et[ESRMNT] = UAESRMNT;
6674 sys2et[ECOMM] = UAECOMM;
6675 sys2et[EPROTO] = UAEPROTO;
6676 sys2et[EMULTIHOP] = UAEMULTIHOP;
6677 sys2et[EDOTDOT] = UAEDOTDOT;
6678 sys2et[EBADMSG] = UAEBADMSG;
6679 sys2et[EOVERFLOW] = UAEOVERFLOW;
6680 sys2et[ENOTUNIQ] = UAENOTUNIQ;
6681 sys2et[EBADFD] = UAEBADFD;
6682 sys2et[EREMCHG] = UAEREMCHG;
6683 sys2et[ELIBACC] = UAELIBACC;
6684 sys2et[ELIBBAD] = UAELIBBAD;
6685 sys2et[ELIBSCN] = UAELIBSCN;
6686 sys2et[ELIBMAX] = UAELIBMAX;
6687 sys2et[ELIBEXEC] = UAELIBEXEC;
6688 sys2et[EILSEQ] = UAEILSEQ;
6689 sys2et[ERESTART] = UAERESTART;
6690 sys2et[ESTRPIPE] = UAESTRPIPE;
6691 sys2et[EUSERS] = UAEUSERS;
6692 sys2et[ENOTSOCK] = UAENOTSOCK;
6693 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
6694 sys2et[EMSGSIZE] = UAEMSGSIZE;
6695 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
6696 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
6697 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
6698 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
6699 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
6700 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
6701 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
6702 sys2et[EADDRINUSE] = UAEADDRINUSE;
6703 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
6704 sys2et[ENETDOWN] = UAENETDOWN;
6705 sys2et[ENETUNREACH] = UAENETUNREACH;
6706 sys2et[ENETRESET] = UAENETRESET;
6707 sys2et[ECONNABORTED] = UAECONNABORTED;
6708 sys2et[ECONNRESET] = UAECONNRESET;
6709 sys2et[ENOBUFS] = UAENOBUFS;
6710 sys2et[EISCONN] = UAEISCONN;
6711 sys2et[ENOTCONN] = UAENOTCONN;
6712 sys2et[ESHUTDOWN] = UAESHUTDOWN;
6713 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
6714 sys2et[ETIMEDOUT] = UAETIMEDOUT;
6715 sys2et[ECONNREFUSED] = UAECONNREFUSED;
6716 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
6717 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
6718 sys2et[EALREADY] = UAEALREADY;
6719 sys2et[EINPROGRESS] = UAEINPROGRESS;
6720 sys2et[ESTALE] = UAESTALE;
6721 sys2et[EUCLEAN] = UAEUCLEAN;
6722 sys2et[ENOTNAM] = UAENOTNAM;
6723 sys2et[ENAVAIL] = UAENAVAIL;
6724 sys2et[EISNAM] = UAEISNAM;
6725 sys2et[EREMOTEIO] = UAEREMOTEIO;
6726 sys2et[EDQUOT] = UAEDQUOT;
6727 sys2et[ENOMEDIUM] = UAENOMEDIUM;
6728 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
6730 sys2et[EIO] = UAEIO;
6734 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
6735 * - pass back the connection, client, and host from CallPreamble
6736 * - keep a ref on the client, which we don't now
6737 * - keep a hold on the host, which we already do
6738 * - pass the connection, client, and host down into SAFSS_*, and use
6739 * them instead of independently discovering them via rx_ConnectionOf
6740 * (safe) and rx_GetSpecific (not so safe)
6741 * The idea being that we decide what client and host we're going to use
6742 * when CallPreamble is called, and stay consistent throughout the call.
6743 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
6747 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
6749 Error errorCode = 0;
6750 struct rx_connection *tcon;
6751 struct host *tcallhost;
6752 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6754 struct client *tclient;
6755 static struct rx_securityClass *sc = 0;
6757 struct rx_connection *conn;
6760 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
6761 goto Bad_CallBackRxConnAddr1;
6763 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6767 tclient = h_FindClient_r(tcon);
6770 goto Bad_CallBackRxConnAddr;
6772 thost = tclient->host;
6774 /* nothing more can be done */
6775 if ( !thost->interface )
6776 goto Bad_CallBackRxConnAddr;
6778 /* the only address is the primary interface */
6779 /* can't change when there's only 1 address, anyway */
6780 if ( thost->interface->numberOfInterfaces <= 1 )
6781 goto Bad_CallBackRxConnAddr;
6783 /* initialise a security object only once */
6785 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
6787 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
6789 if ( *addr == thost->interface->addr[i] ) {
6794 if ( *addr != thost->interface->addr[i] )
6795 goto Bad_CallBackRxConnAddr;
6797 conn = rx_NewConnection (thost->interface->addr[i],
6798 thost->port, 1, sc, 0);
6799 rx_SetConnDeadTime(conn, 2);
6800 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
6802 errorCode = RXAFSCB_Probe(conn);
6805 if ( thost->callback_rxcon )
6806 rx_DestroyConnection(thost->callback_rxcon);
6807 thost->callback_rxcon = conn;
6809 rx_SetConnDeadTime(thost->callback_rxcon, 50);
6810 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
6811 h_ReleaseClient_r(tclient);
6812 /* The hold on thost will be released by CallPostamble */
6814 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6817 rx_DestroyConnection(conn);
6819 Bad_CallBackRxConnAddr:
6820 h_ReleaseClient_r(tclient);
6821 /* The hold on thost will be released by CallPostamble */
6825 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6826 Bad_CallBackRxConnAddr1:
6827 return errorCode; /* failure */
6831 sys_error_to_et(afs_int32 in)
6835 if (in < 0 || in > 511)
6837 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
6839 if (sys2et[in] != 0)