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 */
77 #include <rx/rx_queue.h>
81 #include <afs/afsint.h>
82 #include <afs/vldbint.h>
83 #include <afs/errors.h>
84 #include <afs/ihandle.h>
85 #include <afs/vnode.h>
86 #include <afs/volume.h>
87 #include <afs/ptclient.h>
88 #include <afs/ptuser.h>
89 #include <afs/prs_fs.h>
92 #include <rx/rx_globals.h>
94 #include <afs/cellconfig.h>
97 #include <afs/partition.h>
98 #include "viced_prototypes.h"
101 #include "callback.h"
102 #include <afs/unified_afs.h>
103 #include <afs/audit.h>
104 #include <afs/afsutil.h>
107 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
108 extern void FidZap(DirHandle * file);
109 extern void FidZero(DirHandle * file);
111 pthread_mutex_t fileproc_glock_mutex;
113 /* Useful local defines used by this module */
116 #define MustNOTBeDIR 1
120 #define TVS_SSTATUS 2
123 #define TVS_MKDIR 0x10
125 #define CHK_FETCH 0x10
126 #define CHK_FETCHDATA 0x10
127 #define CHK_FETCHACL 0x11
128 #define CHK_FETCHSTATUS 0x12
129 #define CHK_STOREDATA 0x00
130 #define CHK_STOREACL 0x01
131 #define CHK_STORESTATUS 0x02
133 #define OWNERREAD 0400
134 #define OWNERWRITE 0200
135 #define OWNEREXEC 0100
136 #ifdef USE_GROUP_PERMS
137 #define GROUPREAD 0040
138 #define GROUPWRITE 0020
139 #define GROUPREXEC 0010
142 /* The following errors were not defined in NT. They are given unique
143 * names here to avoid any potential collision.
145 #define FSERR_ELOOP 90
146 #define FSERR_EOPNOTSUPP 122
147 #define FSERR_ECONNREFUSED 130
149 #define NOTACTIVECALL 0
152 #define CREATE_SGUID_ADMIN_ONLY 1
154 extern struct afsconf_dir *confDir;
155 extern afs_int32 dataVersionHigh;
158 static struct AFSCallStatistics AFSCallStats;
159 struct fs_stats_FullPerfStats afs_FullPerfStats;
160 extern int AnonymousID;
161 static const char nullString[] = "";
164 afs_int32 NothingYet;
167 struct afs_FSStats afs_fsstats;
172 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
174 extern afs_int32 implicitAdminRights;
175 extern afs_int32 readonlyServer;
176 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
177 extern afs_fsize_t CopyOnWrite_maxsize;
180 * Externals used by the xstat code.
182 extern VolPkgStats VStats;
183 extern int CEs, CEBlocks;
185 extern int HTs, HTBlocks;
187 static afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
188 struct rx_call *Call, afs_sfsize_t Pos,
189 afs_sfsize_t Len, afs_int32 Int64Mode,
190 afs_sfsize_t * a_bytesToFetchP,
191 afs_sfsize_t * a_bytesFetchedP);
193 static afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
194 struct AFSFid *Fid, struct client *client,
195 struct rx_call *Call, afs_fsize_t Pos,
196 afs_fsize_t Length, afs_fsize_t FileLength,
198 afs_sfsize_t * a_bytesToStoreP,
199 afs_sfsize_t * a_bytesStoredP);
201 #ifdef AFS_SGI_XFS_IOPS_ENV
202 #include <afs/xfsattrs.h>
204 GetLinkCount(Volume * avp, struct stat *astat)
206 if (!strcmp("xfs", astat->st_fstype)) {
207 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
209 return astat->st_nlink;
212 #define GetLinkCount(V, S) (S)->st_nlink
216 SpareComp(Volume * avolp)
222 temp = V_maxquota(avolp);
224 /* no matter; doesn't check in this case */
228 temp = (temp * PctSpare) / 100;
239 * Set the volume synchronization parameter for this volume. If it changes,
240 * the Cache Manager knows that the volume must be purged from the stat cache.
243 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
246 /* date volume instance was created */
249 async->spare1 = V_creationDate(avol);
262 * Verify that the on-disk size for a vnode matches the length in the vnode
265 * @param[in] vp Volume pointer
266 * @param[in] vnp Vnode pointer
267 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
268 * and CheckLength itself will determine the on-disk size.
270 * @return operation status
271 * @retval 0 lengths match
272 * @retval nonzero Error; either the lengths do not match or there was an
273 * error determining the on-disk size. The volume should be
274 * taken offline and salvaged.
277 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
280 VN_GET_LEN(vlen, vnp);
285 fdP = IH_OPEN(vnp->handle);
287 ViceLog(0, ("CheckLength: cannot open inode for fid %" AFS_VOLID_FMT ".%lu.%lu\n",
288 afs_printable_VolumeId_lu(vp->hashid),
289 afs_printable_uint32_lu(Vn_id(vnp)),
290 afs_printable_uint32_lu(vnp->disk.uniquifier)));
293 alen = FDH_SIZE(fdP);
296 afs_int64 alen64 = alen;
297 ViceLog(0, ("CheckLength: cannot get size for inode for fid %"
298 AFS_VOLID_FMT ".%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
299 afs_printable_VolumeId_lu(vp->hashid),
300 afs_printable_uint32_lu(Vn_id(vnp)),
301 afs_printable_uint32_lu(vnp->disk.uniquifier),
308 afs_int64 alen64 = alen, vlen64 = vlen;
309 ViceLog(0, ("Fid %" AFS_VOLID_FMT ".%lu.%lu has inconsistent length (index "
310 "%lld inode %lld ); volume must be salvaged\n",
311 afs_printable_VolumeId_lu(vp->hashid),
312 afs_printable_uint32_lu(Vn_id(vnp)),
313 afs_printable_uint32_lu(vnp->disk.uniquifier),
321 LogClientError(const char *message, struct rx_connection *tcon, afs_int32 viceid, struct AFSFid *Fid)
325 ViceLog(0, ("%s while handling request from host %s:%d viceid %d "
326 "fid %" AFS_VOLID_FMT ".%lu.%lu, failing request\n",
328 afs_inet_ntoa_r(rx_HostOf(rx_PeerOf(tcon)), hoststr),
329 (int)ntohs(rx_PortOf(rx_PeerOf(tcon))),
331 afs_printable_VolumeId_lu(Fid->Volume),
332 afs_printable_uint32_lu(Fid->Vnode),
333 afs_printable_uint32_lu(Fid->Unique)));
335 ViceLog(0, ("%s while handling request from host %s:%d viceid %d "
336 "fid (none), failing request\n",
338 afs_inet_ntoa_r(rx_HostOf(rx_PeerOf(tcon)), hoststr),
339 (int)ntohs(rx_PortOf(rx_PeerOf(tcon))),
345 * Note that this function always returns a held host, so
346 * that CallPostamble can block without the host's disappearing.
347 * Call returns rx connection in passed in *tconn
349 * 'Fid' is optional, and is just used for printing log messages.
352 CallPreamble(struct rx_call *acall, int activecall, struct AFSFid *Fid,
353 struct rx_connection **tconn, struct host **ahostp)
356 struct client *tclient;
357 afs_int32 viceid = -1;
360 char hoststr[16], hoststr2[16];
361 struct ubik_client *uclient;
365 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
368 *tconn = rx_ConnectionOf(acall);
372 tclient = h_FindClient_r(*tconn, &viceid);
375 LogClientError("CallPreamble: Couldn't get client", *tconn, viceid, Fid);
378 thost = tclient->host;
379 if (tclient->prfail == 1) { /* couldn't get the CPS */
381 h_ReleaseClient_r(tclient);
384 LogClientError("CallPreamble: Couldn't get CPS", *tconn, viceid, Fid);
387 retry_flag = 0; /* Retry once */
389 /* Take down the old connection and re-read the key file */
391 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
392 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
394 /* Is it still necessary to drop this? We hit the net, we should... */
400 code = hpr_Initialize(&uclient);
403 opr_Verify(pthread_setspecific(viced_uclient_key,
404 (void *)uclient) == 0);
408 h_ReleaseClient_r(tclient);
411 LogClientError("CallPreamble: couldn't reconnect to ptserver", *tconn, viceid, Fid);
415 tclient->prfail = 2; /* Means re-eval client's cps */
416 h_ReleaseClient_r(tclient);
421 tclient->LastCall = thost->LastCall = time(NULL);
422 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
423 thost->ActiveCall = thost->LastCall;
426 if (thost->hostFlags & HOSTDELETED) {
428 ("Discarded a packet for deleted host %s:%d\n",
429 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
430 code = VBUSY; /* raced, so retry */
431 } else if ((thost->hostFlags & VENUSDOWN)
432 || (thost->hostFlags & HFE_LATER)) {
433 if (BreakDelayedCallBacks_r(thost)) {
435 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
436 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
437 ntohs(rxr_PortOf(*tconn))));
438 if (MultiProbeAlternateAddress_r(thost)) {
440 ("MultiProbe failed to find new address for host %s:%d\n",
441 afs_inet_ntoa_r(thost->host, hoststr),
442 ntohs(thost->port)));
446 ("MultiProbe found new address for host %s:%d\n",
447 afs_inet_ntoa_r(thost->host, hoststr),
448 ntohs(thost->port)));
449 if (BreakDelayedCallBacks_r(thost)) {
451 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
452 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
453 ntohs(rxr_PortOf(*tconn))));
462 h_ReleaseClient_r(tclient);
472 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
476 struct client *tclient;
480 tclient = h_FindClient_r(aconn, NULL);
483 thost = tclient->host;
484 if (thost->hostFlags & HERRORTRANS)
486 h_ReleaseClient_r(tclient);
489 if (ahost != thost) {
490 /* host/client recycle */
491 char hoststr[16], hoststr2[16];
492 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
494 afs_inet_ntoa_r(ahost->host, hoststr),
497 afs_inet_ntoa_r(thost->host, hoststr2),
501 /* return the reference taken in CallPreamble */
505 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
506 afs_inet_ntoa_r(thost->host, hoststr),
511 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
512 * does not decrement refcount on client->host */
517 return (translate ? sys_error_to_et(ret) : ret);
521 * Returns the volume and vnode pointers associated with file Fid; the lock
522 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
523 * are incremented and they must be eventualy released.
526 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
527 Vnode ** vptr, int lock)
530 Error local_errorCode, errorCode = -1;
531 static struct timeval restartedat = { 0, 0 };
533 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
535 if ((*volptr) == 0) {
540 #ifdef AFS_DEMAND_ATTACH_FS
546 static const struct timespec timeout_ts = { 0, 0 };
547 static const struct timespec * const ts = &timeout_ts;
550 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
551 fid->Volume, ts, cbv);
556 if ((errorCode == VOFFLINE) && (VInit < 2)) {
557 /* The volume we want may not be attached yet because
558 * the volume initialization is not yet complete.
559 * We can do several things:
560 * 1. return -1, which will cause users to see
561 * "connection timed out". This is more or
562 * less the same as always, except that the servers
563 * may appear to bounce up and down while they
564 * are actually restarting.
565 * 2. return VBUSY which will cause clients to
566 * sleep and retry for 6.5 - 15 minutes, depending
567 * on what version of the CM they are running. If
568 * the file server takes longer than that interval
569 * to attach the desired volume, then the application
570 * will see an ENODEV or EIO. This approach has
571 * the advantage that volumes which have been attached
572 * are immediately available, it keeps the server's
573 * immediate backlog low, and the call is interruptible
574 * by the user. Users see "waiting for busy volume."
575 * 3. sleep here and retry. Some people like this approach
576 * because there is no danger of seeing errors. However,
577 * this approach only works with a bounded number of
578 * clients, since the pending queues will grow without
579 * stopping. It might be better to find a way to take
580 * this call and stick it back on a queue in order to
581 * recycle this thread for a different request.
582 * 4. Return a new error code, which new cache managers will
583 * know enough to interpret as "sleep and retry", without
584 * the upper bound of 6-15 minutes that is imposed by the
585 * VBUSY handling. Users will see "waiting for
586 * busy volume," so they know that something is
587 * happening. Old cache managers must be able to do
588 * something reasonable with this, for instance, mark the
589 * server down. Fortunately, any error code < 0
590 * will elicit that behavior. See #1.
591 * 5. Some combination of the above. I like doing #2 for 10
592 * minutes, followed by #4. 3.1b and 3.2 cache managers
593 * will be fine as long as the restart period is
594 * not longer than 6.5 minutes, otherwise they may
595 * return ENODEV to users. 3.3 cache managers will be
596 * fine for 10 minutes, then will return
597 * ETIMEDOUT. 3.4 cache managers will just wait
598 * until the call works or fails definitively.
599 * NB. The problem with 2,3,4,5 is that old clients won't
600 * fail over to an alternate read-only replica while this
601 * server is restarting. 3.4 clients will fail over right away.
603 if (restartedat.tv_sec == 0) {
604 /* I'm not really worried about when we restarted, I'm */
605 /* just worried about when the first VBUSY was returned. */
606 gettimeofday(&restartedat, 0);
609 afs_perfstats.fs_nBusies++;
612 return (busyonrst ? VBUSY : restarting);
615 gettimeofday(&now, 0);
616 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
619 afs_perfstats.fs_nBusies++;
622 return (busyonrst ? VBUSY : restarting);
628 /* allow read operations on busy volume.
629 * must check local_errorCode because demand attach fs
630 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
631 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
632 #ifdef AFS_DEMAND_ATTACH_FS
633 /* DAFS case is complicated by the fact that local_errorCode can
634 * be VBUSY in cases where the volume is truly offline */
636 /* volume is in VOL_STATE_UNATTACHED */
639 #endif /* AFS_DEMAND_ATTACH_FS */
642 } else if (errorCode)
649 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
652 if ((*vptr)->disk.uniquifier != fid->Unique) {
653 VPutVnode(&fileCode, *vptr);
654 opr_Assert(fileCode == 0);
656 return (VNOVNODE); /* return the right error code, at least */
661 static_inline afs_int32
662 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
664 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
668 * This routine returns the ACL associated with the targetptr. If the
669 * targetptr isn't a directory, we access its parent dir and get the ACL
670 * thru the parent; in such case the parent's vnode is returned in
674 SetAccessList(Vnode ** targetptr, Volume ** volume,
675 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
676 AFSFid * Fid, int Lock)
678 if ((*targetptr)->disk.type == vDirectory) {
680 *ACL = VVnodeACL(*targetptr);
681 *ACLSize = VAclSize(*targetptr);
684 opr_Assert(Fid != 0);
689 parentvnode = (*targetptr)->disk.parent;
690 VPutVnode(&errorCode, *targetptr);
694 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
697 *ACL = VVnodeACL(*parent);
698 *ACLSize = VAclSize(*parent);
699 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
701 if ((*targetptr)->disk.parent != parentvnode) {
702 VPutVnode(&errorCode, *parent);
713 /* Must not be called with H_LOCK held */
715 client_CheckRights(struct client *client, struct acl_accessList *ACL,
719 ObtainReadLock(&client->lock);
720 if (client->CPS.prlist_len > 0 && !client->deleted &&
721 client->host && !(client->host->hostFlags & HOSTDELETED))
722 acl_CheckRights(ACL, &client->CPS, rights);
723 ReleaseReadLock(&client->lock);
726 /* Must not be called with H_LOCK held */
728 client_HasAsMember(struct client *client, afs_int32 id)
732 ObtainReadLock(&client->lock);
733 if (client->CPS.prlist_len > 0 && !client->deleted &&
734 client->host && !(client->host->hostFlags & HOSTDELETED))
735 code = acl_IsAMember(id, &client->CPS);
736 ReleaseReadLock(&client->lock);
741 * Compare the directory's ACL with the user's access rights in the client
742 * connection and return the user's and everybody else's access permissions
743 * in rights and anyrights, respectively
746 GetRights(struct client *client, struct acl_accessList *ACL,
747 afs_int32 * rights, afs_int32 * anyrights)
749 extern prlist SystemAnyUserCPS;
750 afs_int32 hrights = 0;
752 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
753 ViceLog(0, ("CheckRights failed\n"));
758 client_CheckRights(client, ACL, rights);
760 /* wait if somebody else is already doing the getCPS call */
762 while (client->host->hostFlags & HCPS_INPROGRESS) {
763 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
764 opr_cv_wait(&client->host->cond, &host_glock_mutex);
767 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
770 ("CheckRights: len=%u, for host=%s:%d\n",
771 client->host->hcps.prlist_len,
772 afs_inet_ntoa_r(client->host->host, hoststr),
773 ntohs(client->host->port)));
775 acl_CheckRights(ACL, &client->host->hcps, &hrights);
777 /* Allow system:admin the rights given with the -implicit option */
778 if (client_HasAsMember(client, SystemId))
779 *rights |= implicitAdminRights;
782 *anyrights |= hrights;
789 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
790 * a System:Administrator)
793 VanillaUser(struct client *client)
795 if (client_HasAsMember(client, SystemId))
796 return (0); /* not a system administrator, then you're "vanilla" */
802 /*------------------------------------------------------------------------
803 * GetVolumePackageWithCall
806 * This unusual afs_int32-parameter routine encapsulates all volume
807 * package related operations together in a single function; it's
808 * called by almost all AFS interface calls.
811 * acall : Ptr to Rx call on which this request came in.
812 * cbv : struct containing the RX call for offline cancels
813 * Fid : the AFS fid the caller is acting on
814 * volptr : returns a pointer to the volume struct
815 * targetptr : returns a pointer to the vnode struct
816 * chkforDir : whether to check for if vnode is a dir
817 * parent : returns a pointer to the parent of this vnode
818 * client : returns a pointer to the calling client
819 * locktype : indicates what kind of lock to take on vnodes
820 * rights : returns a pointer to caller's rights
821 * anyrights : returns a pointer to anonymous' rights
822 * remote : indicates that the volume is a remote RW replica
826 * appropriate error based on permission or invalid operation.
829 * Nothing interesting.
832 * On success, disables keepalives on the call. Caller should re-enable
833 * after completing disk I/O.
834 *------------------------------------------------------------------------*/
836 GetVolumePackageWithCall(struct rx_call *acall, struct VCallByVol *cbv,
837 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
838 int chkforDir, Vnode ** parent,
839 struct client **client, int locktype,
840 afs_int32 * rights, afs_int32 * anyrights, int remote)
842 struct acl_accessList *aCL = NULL; /* Internal access List */
843 int aCLSize; /* size of the access list */
844 Error errorCode = 0; /* return code to caller */
845 struct rx_connection *tcon = rx_ConnectionOf(acall);
847 rx_KeepAliveOff(acall);
849 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
853 if (chkforDir == MustNOTBeDIR
854 && ((*targetptr)->disk.type == vDirectory)) {
858 else if (chkforDir == MustBeDIR
859 && ((*targetptr)->disk.type != vDirectory)) {
865 * If the remote flag is set, the current call is dealing with a remote RW
866 * replica, and it can be assumed that the appropriate access checks were
867 * done by the calling server hosting the master volume.
870 if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
871 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
872 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
874 if (chkforDir == MustBeDIR)
875 opr_Assert((*parent) == 0);
877 if ((errorCode = GetClient(tcon, client)) != 0)
884 GetRights(*client, aCL, rights, anyrights);
885 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
886 if ((*targetptr)->disk.type != vDirectory) {
887 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
888 if ((*targetptr)->disk.owner == (*client)->ViceId)
889 (*rights) |= PRSFS_ADMINISTER;
891 (*rights) &= ~PRSFS_ADMINISTER;
893 #ifdef ADMIN_IMPLICIT_LOOKUP
894 /* admins get automatic lookup on everything */
895 if (!VanillaUser(*client))
896 (*rights) |= PRSFS_LOOKUP;
897 #endif /* ADMIN_IMPLICIT_LOOKUP */
901 rx_KeepAliveOn(acall);
904 } /*GetVolumePackage */
906 static_inline afs_int32
907 GetVolumePackage(struct rx_call *acall, AFSFid * Fid, Volume ** volptr,
908 Vnode ** targetptr, int chkforDir, Vnode ** parent,
909 struct client **client, int locktype, afs_int32 * rights,
910 afs_int32 * anyrights)
912 return GetVolumePackageWithCall(acall, NULL, Fid, volptr, targetptr,
913 chkforDir, parent, client, locktype,
914 rights, anyrights, 0);
918 /*------------------------------------------------------------------------
919 * PutVolumePackageWithCall
922 * This is the opposite of GetVolumePackage(), and is always used at
923 * the end of AFS calls to put back all used vnodes and the volume
924 * in the proper order!
927 * acall : Ptr to Rx call on which this request came in.
928 * parentwhentargetnotdir : a pointer to the parent when the target isn't
930 * targetptr : a pointer to the vnode struct
931 * parentptr : a pointer to the parent of this vnode
932 * volptr : a pointer to the volume structure
933 * client : a pointer to the calling client
934 * cbv : struct containing the RX call for offline cancels
940 * Nothing interesting.
943 * Enables keepalives on the call.
944 *------------------------------------------------------------------------*/
946 PutVolumePackageWithCall(struct rx_call *acall, Vnode *
947 parentwhentargetnotdir, Vnode * targetptr,
948 Vnode * parentptr, Volume * volptr,
949 struct client **client, struct VCallByVol *cbv)
951 Error fileCode = 0; /* Error code returned by the volume package */
953 rx_KeepAliveOff(acall);
954 if (parentwhentargetnotdir) {
955 VPutVnode(&fileCode, parentwhentargetnotdir);
956 opr_Assert(!fileCode || (fileCode == VSALVAGE));
959 VPutVnode(&fileCode, targetptr);
960 opr_Assert(!fileCode || (fileCode == VSALVAGE));
963 VPutVnode(&fileCode, parentptr);
964 opr_Assert(!fileCode || (fileCode == VSALVAGE));
967 VPutVolumeWithCall(volptr, cbv);
969 rx_KeepAliveOn(acall);
974 } /*PutVolumePackage */
977 PutVolumePackage(struct rx_call *acall, Vnode * parentwhentargetnotdir,
978 Vnode * targetptr, Vnode * parentptr, Volume * volptr,
979 struct client **client)
981 PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
982 parentptr, volptr, client, NULL);
986 VolumeOwner(struct client *client, Vnode * targetptr)
988 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
991 return (client->ViceId == owner);
994 * We don't have to check for host's cps since only regular
995 * viceid are volume owners.
997 return (client_HasAsMember(client, owner));
1003 VolumeRootVnode(Vnode * targetptr)
1005 return ((targetptr->vnodeNumber == ROOTVNODE)
1006 && (targetptr->disk.uniquifier == 1));
1008 } /*VolumeRootVnode */
1011 * Check if target file has the proper access permissions for the Fetch
1012 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
1013 * StoreStatus) related calls
1015 /* this code should probably just set a "priv" flag where all the audit events
1016 * are now, and only generate the audit event once at the end of the routine,
1017 * thus only generating the event if all the checks succeed, but only because
1018 * of the privilege XXX
1021 Check_PermissionRights(Vnode * targetptr, struct client *client,
1022 afs_int32 rights, int CallingRoutine,
1023 AFSStoreStatus * InStatus)
1025 Error errorCode = 0;
1026 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
1027 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
1028 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
1030 if (CallingRoutine & CHK_FETCH) {
1031 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
1032 if (targetptr->disk.type == vDirectory
1033 || targetptr->disk.type == vSymlink) {
1034 if (!(rights & PRSFS_LOOKUP)
1035 #ifdef ADMIN_IMPLICIT_LOOKUP
1036 /* grant admins fetch on all directories */
1037 && VanillaUser(client)
1038 #endif /* ADMIN_IMPLICIT_LOOKUP */
1039 && !VolumeOwner(client, targetptr))
1042 /* must have read access, or be owner and have insert access */
1043 if (!(rights & PRSFS_READ)
1044 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
1045 && (client->ViceId != AnonymousID))))
1048 if (CallingRoutine == CHK_FETCHDATA
1049 && targetptr->disk.type == vFile)
1050 #ifdef USE_GROUP_PERMS
1051 if (!OWNSp(client, targetptr)
1052 && !client_HasAsMember(client, targetptr->disk.owner)) {
1054 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
1058 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
1063 * The check with the ownership below is a kludge to allow
1064 * reading of files created with no read permission. The owner
1065 * of the file is always allowed to read it.
1067 if ((client->ViceId != targetptr->disk.owner)
1068 && VanillaUser(client))
1070 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
1071 modeBits) ? 0 : EACCES);
1073 } else { /* !VanillaUser(client) && !FetchData */
1075 osi_audit(PrivilegeEvent, 0, AUD_ID,
1076 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
1079 } else { /* a store operation */
1080 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1081 && (CallingRoutine != CHK_STOREACL)
1082 && (targetptr->disk.type == vFile)) {
1083 /* bypass protection checks on first store after a create
1084 * for the creator; also prevent chowns during this time
1085 * unless you are a system administrator */
1086 /****** InStatus->Owner && UnixModeBits better be SET!! */
1087 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1090 else if (VanillaUser(client))
1091 return (EPERM); /* Was EACCES */
1093 osi_audit(PrivilegeEvent, 0, AUD_ID,
1094 (client ? client->ViceId : 0), AUD_INT,
1095 CallingRoutine, AUD_END);
1098 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1099 osi_audit(PrivilegeEvent, 0, AUD_ID,
1100 (client ? client->ViceId : 0), AUD_INT,
1101 CallingRoutine, AUD_END);
1103 if (readonlyServer) {
1106 if (CallingRoutine == CHK_STOREACL) {
1107 if (!(rights & PRSFS_ADMINISTER)
1108 && !VolumeOwner(client, targetptr))
1110 } else { /* store data or status */
1111 /* watch for chowns and chgrps */
1112 if (CHOWN(InStatus, targetptr)
1113 || CHGRP(InStatus, targetptr)) {
1116 else if (VanillaUser(client))
1117 return (EPERM); /* Was EACCES */
1119 osi_audit(PrivilegeEvent, 0, AUD_ID,
1120 (client ? client->ViceId : 0), AUD_INT,
1121 CallingRoutine, AUD_END);
1123 /* must be sysadmin to set suid/sgid bits */
1124 if ((InStatus->Mask & AFS_SETMODE) &&
1126 (InStatus->UnixModeBits & 0xc00) != 0) {
1128 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1132 if (VanillaUser(client))
1135 osi_audit(PrivSetID, 0, AUD_ID,
1136 (client ? client->ViceId : 0), AUD_INT,
1137 CallingRoutine, AUD_END);
1139 if (CallingRoutine == CHK_STOREDATA) {
1142 if (!(rights & PRSFS_WRITE))
1144 /* Next thing is tricky. We want to prevent people
1145 * from writing files sans 0200 bit, but we want
1146 * creating new files with 0444 mode to work. We
1147 * don't check the 0200 bit in the "you are the owner"
1148 * path above, but here we check the bit. However, if
1149 * you're a system administrator, we ignore the 0200
1150 * bit anyway, since you may have fchowned the file,
1152 #ifdef USE_GROUP_PERMS
1153 if ((targetptr->disk.type == vFile)
1154 && VanillaUser(client)) {
1155 if (!OWNSp(client, targetptr)
1156 && !client_HasAsMember(client, targetptr->disk.owner)) {
1158 ((GROUPWRITE & targetptr->disk.modeBits)
1162 ((OWNERWRITE & targetptr->disk.modeBits)
1167 if ((targetptr->disk.type != vDirectory)
1168 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1171 if (VanillaUser(client))
1174 osi_audit(PrivilegeEvent, 0, AUD_ID,
1175 (client ? client->ViceId : 0),
1176 AUD_INT, CallingRoutine, AUD_END);
1178 } else { /* a status store */
1181 if (targetptr->disk.type == vDirectory) {
1182 if (!(rights & PRSFS_DELETE)
1183 && !(rights & PRSFS_INSERT))
1185 } else { /* a file or symlink */
1186 if (!(rights & PRSFS_WRITE))
1196 } /*Check_PermissionRights */
1200 * The Access List information is converted from its internal form in the
1201 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1202 * external form and returned back to the caller, via the AccessList
1206 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1207 struct AFSOpaque *AccessList)
1209 char *eACL; /* External access list placeholder */
1211 if (acl_Externalize_pr
1212 (hpr_IdToName, (targetptr->disk.type ==
1213 vDirectory ? VVnodeACL(targetptr) :
1214 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1217 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1218 acl_FreeExternalACL(&eACL);
1221 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1222 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1224 acl_FreeExternalACL(&eACL);
1227 } /*RXFetch_AccessList */
1231 * The Access List information is converted from its external form in the
1232 * input AccessList structure to the internal representation and copied into
1233 * the target dir's vnode storage.
1236 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1238 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1240 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1243 if ((newACL->size + 4) > VAclSize(targetptr))
1245 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1246 acl_FreeACL(&newACL);
1249 } /*RXStore_AccessList */
1252 CheckLink(Volume *volptr, FdHandle_t *fdP, const char *descr)
1257 code = FDH_ISUNLINKED(fdP);
1259 ViceLog(0, ("CopyOnWrite: error fstating volume %u inode %s (%s), errno %d\n",
1260 V_id(volptr), PrintInode(ino, fdP->fd_ih->ih_ino), descr, errno));
1264 ViceLog(0, ("CopyOnWrite corruption prevention: detected zero nlink for "
1265 "volume %u inode %s (%s), forcing volume offline\n",
1266 V_id(volptr), PrintInode(ino, fdP->fd_ih->ih_ino), descr));
1272 /* In our current implementation, each successive data store (new file
1273 * data version) creates a new inode. This function creates the new
1274 * inode, copies the old inode's contents to the new one, remove the old
1275 * inode (i.e. decrement inode count -- if it's currently used the delete
1276 * will be delayed), and modify some fields (i.e. vnode's
1277 * disk.inodeNumber and cloned)
1279 #define COPYBUFFSIZE 8192
1280 #define MAXFSIZE (~(afs_fsize_t) 0)
1282 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1285 Inode nearInode AFS_UNUSED;
1292 int rc; /* return code */
1293 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1294 FdHandle_t *targFdP; /* Source Inode file handle */
1295 FdHandle_t *newFdP; /* Dest Inode file handle */
1297 if (targetptr->disk.type == vDirectory)
1298 DFlush(); /* just in case? */
1300 VN_GET_LEN(size, targetptr);
1308 buff = malloc(COPYBUFFSIZE);
1313 ino = VN_GET_INO(targetptr);
1314 if (!VALID_INO(ino)) {
1316 VTakeOffline(volptr);
1317 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1318 afs_printable_VolumeId_lu(volptr->hashid)));
1321 targFdP = IH_OPEN(targetptr->handle);
1322 if (targFdP == NULL) {
1325 ("CopyOnWrite failed: Failed to open target vnode %u in volume %" AFS_VOLID_FMT " (errno = %d)\n",
1326 targetptr->vnodeNumber, afs_printable_VolumeId_lu(V_id(volptr)), rc));
1328 VTakeOffline(volptr);
1332 nearInode = VN_GET_INO(targetptr);
1334 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1335 VPartitionPath(V_partition(volptr)), nearInode,
1336 V_id(volptr), targetptr->vnodeNumber,
1337 targetptr->disk.uniquifier,
1338 (int)targetptr->disk.dataVersion);
1339 if (!VALID_INO(ino)) {
1341 ("CopyOnWrite failed: Partition %s that contains volume %" AFS_VOLID_FMT " may be out of free inodes(errno = %d)\n",
1342 volptr->partition->name, afs_printable_VolumeId_lu(V_id(volptr)), errno));
1347 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1348 newFdP = IH_OPEN(newH);
1349 opr_Assert(newFdP != NULL);
1351 rc = CheckLink(volptr, targFdP, "source");
1353 rc = CheckLink(volptr, newFdP, "dest");
1356 FDH_REALLYCLOSE(newFdP);
1358 FDH_REALLYCLOSE(targFdP);
1359 IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1361 VTakeOffline(volptr);
1367 if (size > COPYBUFFSIZE) { /* more than a buffer */
1368 length = COPYBUFFSIZE;
1369 size -= COPYBUFFSIZE;
1374 rdlen = FDH_PREAD(targFdP, buff, length, done);
1375 if (rdlen == length) {
1376 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1380 /* Callers of this function are not prepared to recover
1381 * from error that put the filesystem in an inconsistent
1382 * state. Make sure that we force the volume off-line if
1383 * we some error other than ENOSPC - 4.29.99)
1385 * In case we are unable to write the required bytes, and the
1386 * error code indicates that the disk is full, we roll-back to
1387 * the initial state.
1389 if ((rdlen != length) || (wrlen != length)) {
1390 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1392 ("CopyOnWrite failed: Partition %s containing volume %" AFS_VOLID_FMT " is full\n",
1393 volptr->partition->name, afs_printable_VolumeId_lu(V_id(volptr))));
1394 /* remove destination inode which was partially copied till now */
1395 FDH_REALLYCLOSE(newFdP);
1397 FDH_REALLYCLOSE(targFdP);
1398 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1401 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %" AFS_VOLID_FMT " in partition %s needs salvage\n",
1402 rc, afs_printable_VolumeId_lu(V_id(volptr)), volptr->partition->name));
1403 VTakeOffline(volptr);
1408 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1409 * since we never do any I/O anywhere near 2^32 bytes at a
1410 * time, just case to an unsigned int for printing */
1413 ("CopyOnWrite failed: volume %" AFS_VOLID_FMT " in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1414 afs_printable_VolumeId_lu(V_id(volptr)), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1415 (unsigned)wrlen, errno));
1416 #if defined(AFS_DEMAND_ATTACH_FS)
1417 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1419 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1421 /* Decrement this inode so salvager doesn't find it. */
1422 FDH_REALLYCLOSE(newFdP);
1424 FDH_REALLYCLOSE(targFdP);
1425 IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1427 VTakeOffline(volptr);
1432 FDH_REALLYCLOSE(targFdP);
1433 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1434 V_parentId(volptr));
1436 IH_RELEASE(targetptr->handle);
1438 rc = FDH_SYNC(newFdP);
1439 opr_Assert(rc == 0);
1441 targetptr->handle = newH;
1442 VN_SET_INO(targetptr, ino);
1443 targetptr->disk.cloned = 0;
1444 /* Internal change to vnode, no user level change to volume - def 5445 */
1445 targetptr->changed_oldTime = 1;
1447 return 0; /* success */
1451 * Common code to handle with removing the Name (file when it's called from
1452 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1453 * given directory, parentptr.
1455 int DT1 = 0, DT0 = 0;
1457 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1458 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1460 DirHandle childdir; /* Handle for dir package I/O */
1461 Error errorCode = 0;
1465 /* watch for invalid names */
1466 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1469 if (CheckLength(volptr, parentptr, -1)) {
1470 VTakeOffline(volptr);
1474 if (parentptr->disk.cloned) {
1475 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1476 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1478 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1484 /* check that the file is in the directory */
1485 SetDirHandle(dir, parentptr);
1486 if (afs_dir_Lookup(dir, Name, fileFid))
1488 fileFid->Volume = V_id(volptr);
1490 /* just-in-case check for something causing deadlock */
1491 if (fileFid->Vnode == parentptr->vnodeNumber)
1494 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1498 if (ChkForDir == MustBeDIR) {
1499 if ((*targetptr)->disk.type != vDirectory)
1501 } else if ((*targetptr)->disk.type == vDirectory)
1504 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1506 * If the uniquifiers dont match then instead of asserting
1507 * take the volume offline and return VSALVAGE
1509 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1510 VTakeOffline(volptr);
1512 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1513 afs_printable_VolumeId_lu(volptr->hashid)));
1514 errorCode = VSALVAGE;
1518 if (ChkForDir == MustBeDIR) {
1519 SetDirHandle(&childdir, *targetptr);
1520 if (afs_dir_IsEmpty(&childdir) != 0)
1524 (*targetptr)->delete = 1;
1525 } else if ((--(*targetptr)->disk.linkCount) == 0)
1526 (*targetptr)->delete = 1;
1527 if ((*targetptr)->delete) {
1528 if (VN_GET_INO(*targetptr)) {
1530 IH_REALLYCLOSE((*targetptr)->handle);
1532 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1533 V_parentId(volptr));
1534 IH_RELEASE((*targetptr)->handle);
1535 if (errorCode == -1) {
1537 ("DT: inode=%s, name=%s, errno=%d\n",
1538 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1540 if (errno != ENOENT)
1542 VTakeOffline(volptr);
1544 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1545 afs_printable_VolumeId_lu(volptr->hashid)));
1552 VN_SET_INO(*targetptr, (Inode) 0);
1554 afs_fsize_t adjLength;
1555 VN_GET_LEN(adjLength, *targetptr);
1556 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1560 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1562 code = afs_dir_Delete(dir, Name);
1565 ("Error %d deleting %s\n", code,
1566 (((*targetptr)->disk.type ==
1567 Directory) ? "directory" : "file")));
1568 VTakeOffline(volptr);
1570 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1571 afs_printable_VolumeId_lu(volptr->hashid)));
1583 * This routine updates the parent directory's status block after the
1584 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1585 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1589 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1590 int author, int linkcount, char a_inSameNetwork)
1592 afs_fsize_t newlength; /* Holds new directory length */
1593 afs_fsize_t parentLength;
1595 Date currDate; /*Current date */
1596 int writeIdx; /*Write index to bump */
1597 int timeIdx; /*Authorship time index to bump */
1600 parentptr->disk.dataVersion++;
1601 newlength = (afs_fsize_t) afs_dir_Length(dir);
1603 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1604 * (create, symlink, link, makedir) so we need to check if we have enough space
1605 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1606 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1608 VN_GET_LEN(parentLength, parentptr);
1609 if (nBlocks(newlength) != nBlocks(parentLength)) {
1610 VAdjustDiskUsage(&errorCode, volptr,
1611 (nBlocks(newlength) - nBlocks(parentLength)),
1612 (nBlocks(newlength) - nBlocks(parentLength)));
1614 VN_SET_LEN(parentptr, newlength);
1617 * Update directory write stats for this volume. Note that the auth
1618 * counter is located immediately after its associated ``distance''
1621 if (a_inSameNetwork)
1622 writeIdx = VOL_STATS_SAME_NET;
1624 writeIdx = VOL_STATS_DIFF_NET;
1625 V_stat_writes(volptr, writeIdx)++;
1626 if (author != AnonymousID) {
1627 V_stat_writes(volptr, writeIdx + 1)++;
1631 * Update the volume's authorship information in response to this
1632 * directory operation. Get the current time, decide to which time
1633 * slot this operation belongs, and bump the appropriate slot.
1636 currDate = (now - parentptr->disk.unixModifyTime);
1638 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1639 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1640 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1641 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1642 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1643 if (parentptr->disk.author == author) {
1644 V_stat_dirSameAuthor(volptr, timeIdx)++;
1646 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1649 parentptr->disk.author = author;
1650 parentptr->disk.linkCount = linkcount;
1651 parentptr->disk.unixModifyTime = now; /* This should be set from CLIENT!! */
1652 parentptr->disk.serverModifyTime = now;
1653 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1658 * Update the target file's (or dir's) status block after the specified
1659 * operation is complete. Note that some other fields maybe updated by
1660 * the individual module.
1661 * If remote is set, the volume is a RW replica and access checks can
1665 /* XXX INCOMPLETE - More attention is needed here! */
1667 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1668 struct client *client, AFSStoreStatus * InStatus,
1669 Vnode * parentptr, Volume * volptr,
1670 afs_fsize_t length, int remote)
1672 Date currDate; /*Current date */
1673 int writeIdx; /*Write index to bump */
1674 int timeIdx; /*Authorship time index to bump */
1676 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1677 targetptr->disk.parent = parentptr->vnodeNumber;
1678 VN_SET_LEN(targetptr, length);
1679 /* targetptr->disk.group = 0; save some cycles */
1680 targetptr->disk.modeBits = 0777;
1681 targetptr->disk.owner = client->ViceId;
1682 targetptr->disk.dataVersion = 0; /* consistent with the client */
1683 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1684 /* the inode was created in Alloc_NewVnode() */
1687 * Update file write stats for this volume. Note that the auth
1688 * counter is located immediately after its associated ``distance''
1691 if (client->InSameNetwork)
1692 writeIdx = VOL_STATS_SAME_NET;
1694 writeIdx = VOL_STATS_DIFF_NET;
1695 V_stat_writes(volptr, writeIdx)++;
1696 if (client->ViceId != AnonymousID) {
1697 V_stat_writes(volptr, writeIdx + 1)++;
1701 * We only count operations that DON'T involve creating new objects
1702 * (files, symlinks, directories) or simply setting status as
1703 * authorship-change operations.
1705 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1707 * Update the volume's authorship information in response to this
1708 * file operation. Get the current time, decide to which time
1709 * slot this operation belongs, and bump the appropriate slot.
1711 currDate = (time(NULL) - targetptr->disk.unixModifyTime);
1714 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1715 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1716 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1717 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1718 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1719 VOL_STATS_TIME_IDX_5);
1720 if (targetptr->disk.author == client->ViceId) {
1721 V_stat_fileSameAuthor(volptr, timeIdx)++;
1723 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1727 if (!(Caller & TVS_SSTATUS))
1728 targetptr->disk.author = client->ViceId;
1729 if (Caller & TVS_SDATA) {
1730 targetptr->disk.dataVersion++;
1731 if (!remote && VanillaUser(client)) {
1733 targetptr->disk.modeBits = targetptr->disk.modeBits & ~04000;
1734 #ifdef CREATE_SGUID_ADMIN_ONLY
1736 targetptr->disk.modeBits = targetptr->disk.modeBits & ~02000;
1740 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1741 /* store status, must explicitly request to change the date */
1742 if (InStatus->Mask & AFS_SETMODTIME)
1743 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1744 } else { /* other: date always changes, but perhaps to what is specified by caller */
1745 targetptr->disk.unixModifyTime =
1746 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1747 ClientModTime : time(NULL));
1749 if (InStatus->Mask & AFS_SETOWNER) {
1750 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1751 if (!remote && VanillaUser(client)) {
1753 targetptr->disk.modeBits = targetptr->disk.modeBits & ~04000;
1754 #ifdef CREATE_SGUID_ADMIN_ONLY
1756 targetptr->disk.modeBits = targetptr->disk.modeBits & ~02000;
1759 targetptr->disk.owner = InStatus->Owner;
1760 if (VolumeRootVnode(targetptr)) {
1761 Error errorCode = 0; /* what should be done with this? */
1763 V_owner(targetptr->volumePtr) = InStatus->Owner;
1764 VUpdateVolume(&errorCode, targetptr->volumePtr);
1767 if (InStatus->Mask & AFS_SETMODE) {
1768 int modebits = InStatus->UnixModeBits;
1769 #define CREATE_SGUID_ADMIN_ONLY 1
1770 #ifdef CREATE_SGUID_ADMIN_ONLY
1771 if (!remote && VanillaUser(client))
1772 modebits = modebits & 0777;
1774 if (!remote && VanillaUser(client)) {
1775 targetptr->disk.modeBits = modebits;
1777 targetptr->disk.modeBits = modebits;
1780 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1781 CHK_STOREDATA, AUD_END);
1785 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1786 CHK_STORESTATUS, AUD_END);
1793 targetptr->disk.serverModifyTime = time(NULL);
1794 if (InStatus->Mask & AFS_SETGROUP)
1795 targetptr->disk.group = InStatus->Group;
1796 /* vnode changed : to be written back by VPutVnode */
1797 targetptr->changed_newTime = 1;
1799 } /*Update_TargetVnodeStatus */
1803 * Fills the CallBack structure with the expiration time and type of callback
1804 * structure. Warning: this function is currently incomplete.
1807 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1809 /* CallBackTime could not be 0 */
1810 if (CallBackTime == 0) {
1811 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1812 CallBack->ExpirationTime = 0;
1814 CallBack->ExpirationTime = CallBackTime - time(NULL);
1815 CallBack->CallBackVersion = CALLBACK_VERSION;
1816 CallBack->CallBackType = CB_SHARED; /* The default for now */
1818 } /*SetCallBackStruct */
1822 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1823 * allocation; if some error occured (exceeded volume quota or partition
1824 * was full, or whatever), it frees the space back and returns the code.
1825 * We usually pre-adjust the volume space to make sure that there's
1826 * enough space before consuming some.
1829 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1830 afs_sfsize_t checkLength)
1835 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1837 VAdjustDiskUsage(&nc, volptr, -length, 0);
1838 if (rc == VOVERQUOTA) {
1840 ("Volume %" AFS_VOLID_FMT " (%s) is full\n",
1841 afs_printable_VolumeId_lu(V_id(volptr)),
1845 if (rc == VDISKFULL) {
1847 ("Partition %s that contains volume %" AFS_VOLID_FMT " is full\n",
1848 volptr->partition->name,
1849 afs_printable_VolumeId_lu(V_id(volptr))));
1852 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1857 } /*AdjustDiskUsage */
1860 * Common code that handles the creation of a new file (SAFS_CreateFile and
1861 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1864 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1865 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1866 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1868 Error errorCode = 0; /* Error code returned back */
1871 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1875 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1876 BlocksPreallocatedForVnode))) {
1878 ("Insufficient space to allocate %lld blocks\n",
1879 (afs_intmax_t) BlocksPreallocatedForVnode));
1883 if (CheckLength(volptr, parentptr, -1)) {
1884 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1885 VTakeOffline(volptr);
1889 *targetptr = VAllocVnode(&errorCode, volptr, FileType, 0, 0);
1890 if (errorCode != 0) {
1891 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1894 OutFid->Volume = V_id(volptr);
1895 OutFid->Vnode = (*targetptr)->vnodeNumber;
1896 OutFid->Unique = (*targetptr)->disk.uniquifier;
1898 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1900 /* create the inode now itself */
1902 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1903 VPartitionPath(V_partition(volptr)), nearInode,
1904 V_id(volptr), (*targetptr)->vnodeNumber,
1905 (*targetptr)->disk.uniquifier, 1);
1907 /* error in creating inode */
1908 if (!VALID_INO(inode)) {
1910 ("Volume : %" AFS_VOLID_FMT " vnode = %u Failed to create inode: errno = %d\n",
1911 afs_printable_VolumeId_lu(V_id((*targetptr)->volumePtr)),
1912 (*targetptr)->vnodeNumber, errno));
1913 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1914 (*targetptr)->delete = 1; /* delete vnode */
1917 VN_SET_INO(*targetptr, inode);
1918 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1920 /* copy group from parent dir */
1921 (*targetptr)->disk.group = parentptr->disk.group;
1923 if (parentptr->disk.cloned) {
1924 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1925 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1926 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1927 /* delete the vnode previously allocated */
1928 (*targetptr)->delete = 1;
1929 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1930 IH_REALLYCLOSE((*targetptr)->handle);
1931 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1933 ("Alloc_NewVnode: partition %s idec %s failed\n",
1934 volptr->partition->name, PrintInode(stmp, inode)));
1935 IH_RELEASE((*targetptr)->handle);
1941 /* add the name to the directory */
1942 SetDirHandle(dir, parentptr);
1943 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1944 (*targetptr)->delete = 1;
1945 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1946 IH_REALLYCLOSE((*targetptr)->handle);
1947 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1949 ("Alloc_NewVnode: partition %s idec %s failed\n",
1950 volptr->partition->name, PrintInode(stmp, inode)));
1951 IH_RELEASE((*targetptr)->handle);
1957 } /*Alloc_NewVnode */
1961 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1965 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1967 int Time; /* Used for time */
1968 int writeVnode = targetptr->changed_oldTime; /* save original status */
1970 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1972 switch (LockingType) {
1975 if (Time > targetptr->disk.lock.lockTime)
1976 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1978 Time += AFS_LOCKWAIT;
1979 if (LockingType == LockRead) {
1980 if ( !(rights & PRSFS_LOCK) &&
1981 !(rights & PRSFS_WRITE) &&
1982 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1985 if (targetptr->disk.lock.lockCount >= 0) {
1986 ++(targetptr->disk.lock.lockCount);
1987 targetptr->disk.lock.lockTime = Time;
1990 } else if (LockingType == LockWrite) {
1991 if ( !(rights & PRSFS_WRITE) &&
1992 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1995 if (targetptr->disk.lock.lockCount == 0) {
1996 targetptr->disk.lock.lockCount = -1;
1997 targetptr->disk.lock.lockTime = Time;
2003 Time += AFS_LOCKWAIT;
2004 if (targetptr->disk.lock.lockCount != 0)
2005 targetptr->disk.lock.lockTime = Time;
2010 if ((--targetptr->disk.lock.lockCount) <= 0)
2011 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
2015 targetptr->changed_oldTime = writeVnode; /* restore old status */
2016 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
2019 } /*HandleLocking */
2021 /* 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. */
2024 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
2028 if (!(rights & Prfs_Mode))
2030 if ((targetptr->disk.type != vDirectory)
2031 && (!(targetptr->disk.modeBits & OWNERWRITE)))
2037 * If some flags (i.e. min or max quota) are set, the volume's in disk
2038 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
2039 * update, if applicable.
2042 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
2043 char *Name, char *OfflineMsg, char *Motd)
2045 Error errorCode = 0;
2047 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
2048 V_minquota(volptr) = StoreVolStatus->MinQuota;
2049 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
2050 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
2051 if (strlen(OfflineMsg) > 0) {
2052 strcpy(V_offlineMessage(volptr), OfflineMsg);
2054 if (strlen(Name) > 0) {
2055 strcpy(V_name(volptr), Name);
2058 * We don't overwrite the motd field, since it's now being used
2061 VUpdateVolume(&errorCode, volptr);
2064 } /*RXUpdate_VolumeStatus */
2068 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2069 char **motd, Volume * volptr)
2072 status->Vid = V_id(volptr);
2073 status->ParentId = V_parentId(volptr);
2074 status->Online = V_inUse(volptr);
2075 status->InService = V_inService(volptr);
2076 status->Blessed = V_blessed(volptr);
2077 status->NeedsSalvage = V_needsSalvaged(volptr);
2078 if (VolumeWriteable(volptr))
2079 status->Type = ReadWrite;
2081 status->Type = ReadOnly;
2082 status->MinQuota = V_minquota(volptr);
2083 status->MaxQuota = V_maxquota(volptr);
2084 status->BlocksInUse = V_diskused(volptr);
2085 status->PartBlocksAvail = RoundInt64ToInt31(volptr->partition->free);
2086 status->PartMaxBlocks = RoundInt64ToInt31(volptr->partition->totalUsable);
2088 /* now allocate and copy these things; they're freed by the RXGEN stub */
2089 *name = strdup(V_name(volptr));
2091 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2093 *offMsg = strdup(V_offlineMessage(volptr));
2095 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2099 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2101 strcpy(*motd, nullString);
2103 } /*RXGetVolumeStatus */
2107 FileNameOK(char *aname)
2112 /* watch for @sys on the right */
2113 if (strcmp(aname + i - 4, "@sys") == 0)
2116 while ((tc = *aname++)) {
2118 return 0; /* very bad character to encounter */
2120 return 1; /* file name is ok */
2126 * This variant of symlink is expressly to support the AFS/DFS translator
2127 * and is not supported by the AFS fileserver. We just return EINVAL.
2128 * The cache manager should not generate this call to an AFS cache manager.
2131 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2132 char *LinkContents, struct AFSStoreStatus *InStatus,
2133 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2134 struct AFSFetchStatus *OutDirStatus,
2135 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2141 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2142 struct FsCmdInputs * Inputs,
2143 struct FsCmdOutputs * Outputs)
2147 switch (Inputs->command) {
2151 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2152 Inputs->command, Outputs->code));
2157 static struct afs_buffer {
2158 struct afs_buffer *next;
2159 } *freeBufferList = 0;
2160 static int afs_buffersAlloced = 0;
2163 FreeSendBuffer(struct afs_buffer *adata)
2166 afs_buffersAlloced--;
2167 adata->next = freeBufferList;
2168 freeBufferList = adata;
2172 } /*FreeSendBuffer */
2174 /* allocate space for sender */
2176 AllocSendBuffer(void)
2178 struct afs_buffer *tp;
2181 afs_buffersAlloced++;
2182 if (!freeBufferList) {
2185 tmp = malloc(sendBufSize);
2187 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2191 tp = freeBufferList;
2192 freeBufferList = tp->next;
2196 } /*AllocSendBuffer */
2197 #endif /* HAVE_PIOV */
2200 * This routine returns the status info associated with the targetptr vnode
2201 * in the AFSFetchStatus structure. Some of the newer fields, such as
2202 * SegSize and Group are not yet implemented
2206 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2207 afs_int32 anyrights, Vnode * parentptr)
2209 int Time = time(NULL);
2211 /* initialize return status from a vnode */
2212 status->InterfaceVersion = 1;
2213 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2214 status->errorCode = 0;
2215 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2216 if (targetptr->disk.type == vFile)
2217 status->FileType = File;
2218 else if (targetptr->disk.type == vDirectory)
2219 status->FileType = Directory;
2220 else if (targetptr->disk.type == vSymlink)
2221 status->FileType = SymbolicLink;
2223 status->FileType = Invalid; /*invalid type field */
2224 status->LinkCount = targetptr->disk.linkCount;
2226 afs_fsize_t targetLen;
2227 VN_GET_LEN(targetLen, targetptr);
2228 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2230 status->DataVersion = targetptr->disk.dataVersion;
2231 status->Author = targetptr->disk.author;
2232 status->Owner = targetptr->disk.owner;
2233 status->CallerAccess = rights;
2234 status->AnonymousAccess = anyrights;
2235 status->UnixModeBits = targetptr->disk.modeBits;
2236 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2237 status->ParentVnode =
2238 (status->FileType ==
2239 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2240 status->ParentUnique =
2241 (status->FileType ==
2242 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2243 status->ServerModTime = targetptr->disk.serverModifyTime;
2244 status->Group = targetptr->disk.group;
2245 status->lockCount = Time > targetptr->disk.lock.lockTime ? 0 : targetptr->disk.lock.lockCount;
2246 status->errorCode = 0;
2251 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2252 afs_sfsize_t Pos, afs_sfsize_t Len,
2253 struct AFSFetchStatus *OutStatus,
2254 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2257 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2258 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2259 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2260 Error errorCode = 0; /* return code to caller */
2261 Error fileCode = 0; /* return code from vol package */
2262 Volume *volptr = 0; /* pointer to the volume */
2263 struct client *client = 0; /* pointer to the client data */
2264 struct rx_connection *tcon; /* the connection we're part of */
2266 afs_int32 rights, anyrights; /* rights for this and any user */
2267 struct client *t_client = NULL; /* tmp ptr to client data */
2268 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2269 struct VCallByVol tcbv, *cbv = NULL;
2270 static int remainder = 0; /* shared access protected by FS_LOCK */
2271 struct fsstats fsstats;
2272 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2273 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2274 int readIdx; /* Index of read stats array to bump */
2276 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2279 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2282 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2284 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2287 /* Get ptr to client data for user Id for logging */
2288 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2289 logHostAddr.s_addr = rxr_HostOf(tcon);
2291 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2292 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2293 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2295 queue_NodeInit(&tcbv);
2300 * Get volume/vnode for the fetched file; caller's access rights to
2301 * it are also returned
2304 GetVolumePackageWithCall(acall, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2305 &parentwhentargetnotdir, &client, READ_LOCK,
2306 &rights, &anyrights, 0)))
2309 SetVolumeSync(Sync, volptr);
2312 * Remember that another read operation was performed.
2315 if (client->InSameNetwork)
2316 readIdx = VOL_STATS_SAME_NET;
2318 readIdx = VOL_STATS_DIFF_NET;
2319 V_stat_reads(volptr, readIdx)++;
2320 if (client->ViceId != AnonymousID) {
2321 V_stat_reads(volptr, readIdx + 1)++;
2324 /* Check whether the caller has permission access to fetch the data */
2326 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2330 * Drop the read lock on the parent directory after saving the parent
2331 * vnode information we need to pass to GetStatus
2333 if (parentwhentargetnotdir != NULL) {
2334 tparentwhentargetnotdir = *parentwhentargetnotdir;
2335 VPutVnode(&fileCode, parentwhentargetnotdir);
2336 opr_Assert(!fileCode || (fileCode == VSALVAGE));
2337 parentwhentargetnotdir = NULL;
2340 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
2342 /* actually do the data transfer */
2344 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2345 &bytesToXfer, &bytesXferred);
2347 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2353 /* write back the OutStatus from the target vnode */
2354 GetStatus(targetptr, OutStatus, rights, anyrights,
2355 &tparentwhentargetnotdir);
2357 rx_KeepAliveOn(acall); /* I/O done */
2359 /* if a r/w volume, promise a callback to the caller */
2360 if (VolumeWriteable(volptr))
2361 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2363 struct AFSFid myFid;
2364 memset(&myFid, 0, sizeof(struct AFSFid));
2365 myFid.Volume = Fid->Volume;
2366 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2370 /* Update and store volume/vnode and parent vnodes back */
2371 (void)PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
2372 (Vnode *) 0, volptr, &client, cbv);
2373 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2374 errorCode = CallPostamble(tcon, errorCode, thost);
2376 fsstats_FinishOp(&fsstats, errorCode);
2378 osi_auditU(acall, FetchDataEvent, errorCode,
2379 AUD_ID, t_client ? t_client->ViceId : 0,
2380 AUD_FID, Fid, AUD_END);
2383 } /*SRXAFS_FetchData */
2386 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2387 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2388 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2390 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2395 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2396 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2397 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2400 afs_sfsize_t tPos, tLen;
2402 tPos = (afs_sfsize_t) Pos;
2403 tLen = (afs_sfsize_t) Len;
2406 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2412 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2413 struct AFSOpaque * AccessList,
2414 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2416 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2417 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2418 Error errorCode = 0; /* return error code to caller */
2419 Volume *volptr = 0; /* pointer to the volume */
2420 struct client *client = 0; /* pointer to the client data */
2421 afs_int32 rights, anyrights; /* rights for this and any user */
2422 struct rx_connection *tcon = rx_ConnectionOf(acall);
2424 struct client *t_client = NULL; /* tmp ptr to client data */
2425 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2426 struct fsstats fsstats;
2428 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2431 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2434 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2436 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2439 /* Get ptr to client data for user Id for logging */
2440 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2441 logHostAddr.s_addr = rxr_HostOf(tcon);
2443 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2444 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2445 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2447 AccessList->AFSOpaque_len = 0;
2448 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2449 if (!AccessList->AFSOpaque_val) {
2450 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2454 * Get volume/vnode for the fetched file; caller's access rights to it
2458 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2459 &parentwhentargetnotdir, &client, READ_LOCK,
2460 &rights, &anyrights)))
2463 SetVolumeSync(Sync, volptr);
2465 /* Check whether we have permission to fetch the ACL */
2467 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2470 /* Get the Access List from the dir's vnode */
2472 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2475 /* Get OutStatus back From the target Vnode */
2476 GetStatus(targetptr, OutStatus, rights, anyrights,
2477 parentwhentargetnotdir);
2480 /* Update and store volume/vnode and parent vnodes back */
2481 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2482 (Vnode *) 0, volptr, &client);
2484 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2485 AccessList->AFSOpaque_val));
2486 errorCode = CallPostamble(tcon, errorCode, thost);
2488 fsstats_FinishOp(&fsstats, errorCode);
2490 osi_auditU(acall, FetchACLEvent, errorCode,
2491 AUD_ID, t_client ? t_client->ViceId : 0,
2493 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2495 } /*SRXAFS_FetchACL */
2499 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2500 * merged into it when possible.
2503 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2504 struct AFSFetchStatus *OutStatus,
2505 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2507 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2508 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2509 Error errorCode = 0; /* return code to caller */
2510 Volume *volptr = 0; /* pointer to the volume */
2511 struct client *client = 0; /* pointer to the client data */
2512 afs_int32 rights, anyrights; /* rights for this and any user */
2513 struct client *t_client = NULL; /* tmp ptr to client data */
2514 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2515 struct rx_connection *tcon = rx_ConnectionOf(acall);
2517 /* Get ptr to client data for user Id for logging */
2518 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2519 logHostAddr.s_addr = rxr_HostOf(tcon);
2521 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2522 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2523 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2525 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2528 * Get volume/vnode for the fetched file; caller's rights to it are
2532 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2533 &parentwhentargetnotdir, &client, READ_LOCK,
2534 &rights, &anyrights)))
2535 goto Bad_FetchStatus;
2537 rx_KeepAliveOn(acall);
2539 /* set volume synchronization information */
2540 SetVolumeSync(Sync, volptr);
2542 /* Are we allowed to fetch Fid's status? */
2543 if (targetptr->disk.type != vDirectory) {
2545 Check_PermissionRights(targetptr, client, rights,
2546 CHK_FETCHSTATUS, 0))) {
2547 if (rx_GetCallAbortCode(acall) == errorCode)
2548 rx_SetCallAbortCode(acall, 0);
2549 goto Bad_FetchStatus;
2553 /* set OutStatus From the Fid */
2554 GetStatus(targetptr, OutStatus, rights, anyrights,
2555 parentwhentargetnotdir);
2557 /* If a r/w volume, also set the CallBack state */
2558 if (VolumeWriteable(volptr))
2559 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2561 struct AFSFid myFid;
2562 memset(&myFid, 0, sizeof(struct AFSFid));
2563 myFid.Volume = Fid->Volume;
2564 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2568 /* Update and store volume/vnode and parent vnodes back */
2569 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2570 (Vnode *) 0, volptr, &client);
2571 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2574 } /*SAFSS_FetchStatus */
2578 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2579 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2580 struct AFSVolSync * Sync)
2584 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2585 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2586 Error errorCode = 0; /* return code to caller */
2587 Volume *volptr = 0; /* pointer to the volume */
2588 struct client *client = 0; /* pointer to the client data */
2589 afs_int32 rights, anyrights; /* rights for this and any user */
2590 struct AFSFid *tfid; /* file id we're dealing with now */
2591 struct rx_connection *tcon = rx_ConnectionOf(acall);
2593 struct client *t_client = NULL; /* tmp pointer to the client data */
2594 struct fsstats fsstats;
2596 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2598 ViceLog(1, ("SAFS_BulkStatus\n"));
2600 AFSCallStats.TotalCalls++;
2602 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2603 if (nfiles <= 0) { /* Sanity check */
2605 goto Audit_and_Return;
2608 /* allocate space for return output parameters */
2609 OutStats->AFSBulkStats_val = malloc(nfiles * sizeof(struct AFSFetchStatus));
2610 if (!OutStats->AFSBulkStats_val) {
2611 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2613 OutStats->AFSBulkStats_len = nfiles;
2614 CallBacks->AFSCBs_val = malloc(nfiles * sizeof(struct AFSCallBack));
2615 if (!CallBacks->AFSCBs_val) {
2616 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2618 CallBacks->AFSCBs_len = nfiles;
2620 tfid = Fids->AFSCBFids_val;
2622 if ((errorCode = CallPreamble(acall, ACTIVECALL, tfid, &tcon, &thost)))
2623 goto Bad_BulkStatus;
2625 for (i = 0; i < nfiles; i++, tfid++) {
2627 * Get volume/vnode for the fetched file; caller's rights to it
2631 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2632 &parentwhentargetnotdir, &client, READ_LOCK,
2633 &rights, &anyrights)))
2634 goto Bad_BulkStatus;
2636 rx_KeepAliveOn(acall);
2638 /* set volume synchronization information, but only once per call */
2640 SetVolumeSync(Sync, volptr);
2642 /* Are we allowed to fetch Fid's status? */
2643 if (targetptr->disk.type != vDirectory) {
2645 Check_PermissionRights(targetptr, client, rights,
2646 CHK_FETCHSTATUS, 0))) {
2647 if (rx_GetCallAbortCode(acall) == errorCode)
2648 rx_SetCallAbortCode(acall, 0);
2649 goto Bad_BulkStatus;
2653 /* set OutStatus From the Fid */
2654 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2655 anyrights, parentwhentargetnotdir);
2657 /* If a r/w volume, also set the CallBack state */
2658 if (VolumeWriteable(volptr))
2659 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2660 &CallBacks->AFSCBs_val[i]);
2662 struct AFSFid myFid;
2663 memset(&myFid, 0, sizeof(struct AFSFid));
2664 myFid.Volume = tfid->Volume;
2665 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2666 &CallBacks->AFSCBs_val[i]);
2669 /* put back the file ID and volume */
2670 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2671 (Vnode *) 0, volptr, &client);
2672 parentwhentargetnotdir = (Vnode *) 0;
2673 targetptr = (Vnode *) 0;
2674 volptr = (Volume *) 0;
2675 client = (struct client *)0;
2679 /* Update and store volume/vnode and parent vnodes back */
2680 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2681 (Vnode *) 0, volptr, &client);
2682 errorCode = CallPostamble(tcon, errorCode, thost);
2684 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2686 fsstats_FinishOp(&fsstats, errorCode);
2689 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2690 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2691 AUD_ID, t_client ? t_client->ViceId : 0,
2692 AUD_FIDS, Fids, AUD_END);
2695 } /*SRXAFS_BulkStatus */
2699 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2700 struct AFSBulkStats * OutStats,
2701 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2705 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2706 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2707 Error errorCode = 0; /* return code to caller */
2708 Volume *volptr = 0; /* pointer to the volume */
2709 struct client *client = 0; /* pointer to the client data */
2710 afs_int32 rights, anyrights; /* rights for this and any user */
2711 struct AFSFid *tfid; /* file id we're dealing with now */
2712 struct rx_connection *tcon;
2714 struct client *t_client = NULL; /* tmp ptr to client data */
2715 AFSFetchStatus *tstatus;
2716 int VolSync_set = 0;
2717 struct fsstats fsstats;
2719 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2721 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2723 AFSCallStats.TotalCalls++;
2725 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2726 if (nfiles <= 0) { /* Sanity check */
2728 goto Audit_and_Return;
2731 /* allocate space for return output parameters */
2732 OutStats->AFSBulkStats_val = calloc(nfiles, sizeof(struct AFSFetchStatus));
2733 if (!OutStats->AFSBulkStats_val) {
2734 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2736 OutStats->AFSBulkStats_len = nfiles;
2737 CallBacks->AFSCBs_val = calloc(nfiles, sizeof(struct AFSCallBack));
2738 if (!CallBacks->AFSCBs_val) {
2739 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2741 CallBacks->AFSCBs_len = nfiles;
2743 /* Zero out return values to avoid leaking information on partial succes */
2744 memset(Sync, 0, sizeof(*Sync));
2746 tfid = Fids->AFSCBFids_val;
2748 if ((errorCode = CallPreamble(acall, ACTIVECALL, tfid, &tcon, &thost))) {
2749 goto Bad_InlineBulkStatus;
2752 for (i = 0; i < nfiles; i++, tfid++) {
2754 * Get volume/vnode for the fetched file; caller's rights to it
2758 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2759 &parentwhentargetnotdir, &client, READ_LOCK,
2760 &rights, &anyrights))) {
2761 tstatus = &OutStats->AFSBulkStats_val[i];
2763 if (thost->hostFlags & HERRORTRANS) {
2764 tstatus->errorCode = sys_error_to_et(errorCode);
2766 tstatus->errorCode = errorCode;
2769 PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2770 (Vnode *) 0, volptr, &client);
2771 parentwhentargetnotdir = (Vnode *) 0;
2772 targetptr = (Vnode *) 0;
2773 volptr = (Volume *) 0;
2774 client = (struct client *)0;
2778 rx_KeepAliveOn(acall);
2780 /* set volume synchronization information, but only once per call */
2782 SetVolumeSync(Sync, volptr);
2786 /* Are we allowed to fetch Fid's status? */
2787 if (targetptr->disk.type != vDirectory) {
2789 Check_PermissionRights(targetptr, client, rights,
2790 CHK_FETCHSTATUS, 0))) {
2791 tstatus = &OutStats->AFSBulkStats_val[i];
2793 if (thost->hostFlags & HERRORTRANS) {
2794 tstatus->errorCode = sys_error_to_et(errorCode);
2796 tstatus->errorCode = errorCode;
2799 (void)PutVolumePackage(acall, parentwhentargetnotdir,
2800 targetptr, (Vnode *) 0, volptr,
2802 parentwhentargetnotdir = (Vnode *) 0;
2803 targetptr = (Vnode *) 0;
2804 volptr = (Volume *) 0;
2805 client = (struct client *)0;
2810 /* set OutStatus From the Fid */
2811 GetStatus(targetptr,
2812 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2813 rights, anyrights, parentwhentargetnotdir);
2815 /* If a r/w volume, also set the CallBack state */
2816 if (VolumeWriteable(volptr))
2817 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2818 &CallBacks->AFSCBs_val[i]);
2820 struct AFSFid myFid;
2821 memset(&myFid, 0, sizeof(struct AFSFid));
2822 myFid.Volume = tfid->Volume;
2823 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2824 &CallBacks->AFSCBs_val[i]);
2827 /* put back the file ID and volume */
2828 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2829 (Vnode *) 0, volptr, &client);
2830 parentwhentargetnotdir = (Vnode *) 0;
2831 targetptr = (Vnode *) 0;
2832 volptr = (Volume *) 0;
2833 client = (struct client *)0;
2837 Bad_InlineBulkStatus:
2838 /* Update and store volume/vnode and parent vnodes back */
2839 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2840 (Vnode *) 0, volptr, &client);
2841 errorCode = CallPostamble(tcon, errorCode, thost);
2843 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2845 fsstats_FinishOp(&fsstats, errorCode);
2848 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2849 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2850 AUD_ID, t_client ? t_client->ViceId : 0,
2851 AUD_FIDS, Fids, AUD_END);
2854 } /*SRXAFS_InlineBulkStatus */
2858 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2859 struct AFSFetchStatus * OutStatus,
2860 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2863 struct rx_connection *tcon;
2865 struct client *t_client = NULL; /* tmp ptr to client data */
2866 struct fsstats fsstats;
2868 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2870 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2871 goto Bad_FetchStatus;
2873 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2876 code = CallPostamble(tcon, code, thost);
2878 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2880 fsstats_FinishOp(&fsstats, code);
2882 osi_auditU(acall, FetchStatusEvent, code,
2883 AUD_ID, t_client ? t_client->ViceId : 0,
2884 AUD_FID, Fid, AUD_END);
2887 } /*SRXAFS_FetchStatus */
2891 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2892 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2893 afs_fsize_t Length, afs_fsize_t FileLength,
2894 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2896 Vnode *targetptr = 0; /* pointer to input fid */
2897 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2898 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2899 Error errorCode = 0; /* return code for caller */
2900 Error fileCode = 0; /* return code from vol package */
2901 Volume *volptr = 0; /* pointer to the volume header */
2902 struct client *client = 0; /* pointer to client structure */
2903 afs_int32 rights, anyrights; /* rights for this and any user */
2904 struct client *t_client = NULL; /* tmp ptr to client data */
2905 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2906 struct rx_connection *tcon;
2908 struct fsstats fsstats;
2909 afs_sfsize_t bytesToXfer;
2910 afs_sfsize_t bytesXferred;
2911 static int remainder = 0;
2914 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2917 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2920 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2922 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2925 /* Get ptr to client data for user Id for logging */
2926 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2927 logHostAddr.s_addr = rxr_HostOf(tcon);
2929 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2930 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2931 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2934 * Get associated volume/vnode for the stored file; caller's rights
2938 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustNOTBeDIR,
2939 &parentwhentargetnotdir, &client, WRITE_LOCK,
2940 &rights, &anyrights))) {
2944 rx_KeepAliveOn(acall);
2946 /* set volume synchronization information */
2947 SetVolumeSync(Sync, volptr);
2949 if (targetptr->disk.type == vSymlink) {
2950 /* Should we return a better error code here??? */
2955 /* Check if we're allowed to store the data */
2957 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2963 * Drop the read lock on the parent directory after saving the parent
2964 * vnode information we need to pass to GetStatus
2966 if (parentwhentargetnotdir != NULL) {
2967 tparentwhentargetnotdir = *parentwhentargetnotdir;
2968 rx_KeepAliveOff(acall);
2969 VPutVnode(&fileCode, parentwhentargetnotdir);
2970 rx_KeepAliveOn(acall);
2971 opr_Assert(!fileCode || (fileCode == VSALVAGE));
2972 parentwhentargetnotdir = NULL;
2975 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
2978 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2979 FileLength, (InStatus->Mask & AFS_FSYNC),
2980 &bytesToXfer, &bytesXferred);
2982 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2985 if (errorCode && (!targetptr->changed_newTime))
2988 rx_KeepAliveOff(acall);
2989 /* Update the status of the target's vnode */
2990 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2991 targetptr, volptr, 0, 0);
2992 rx_KeepAliveOn(acall);
2994 /* Get the updated File's status back to the caller */
2995 GetStatus(targetptr, OutStatus, rights, anyrights,
2996 &tparentwhentargetnotdir);
2999 /* Update and store volume/vnode and parent vnodes back */
3000 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
3001 (Vnode *) 0, volptr, &client);
3002 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3004 errorCode = CallPostamble(tcon, errorCode, thost);
3006 fsstats_FinishOp(&fsstats, errorCode);
3008 osi_auditU(acall, StoreDataEvent, errorCode,
3009 AUD_ID, t_client ? t_client->ViceId : 0,
3010 AUD_FID, Fid, AUD_END);
3012 } /*common_StoreData64 */
3015 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3016 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3017 afs_uint32 Length, afs_uint32 FileLength,
3018 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3020 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3021 (0x7fffffff - Pos) < Length)
3024 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3026 } /*SRXAFS_StoreData */
3029 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3030 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3031 afs_uint64 Length, afs_uint64 FileLength,
3032 struct AFSFetchStatus * OutStatus,
3033 struct AFSVolSync * Sync)
3037 afs_fsize_t tLength;
3038 afs_fsize_t tFileLength;
3040 tPos = (afs_fsize_t) Pos;
3041 tLength = (afs_fsize_t) Length;
3042 tFileLength = (afs_fsize_t) FileLength;
3045 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3051 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3052 struct AFSOpaque * AccessList,
3053 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3055 Vnode *targetptr = 0; /* pointer to input fid */
3056 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3057 Error errorCode = 0; /* return code for caller */
3058 struct AFSStoreStatus InStatus; /* Input status for fid */
3059 Volume *volptr = 0; /* pointer to the volume header */
3060 struct client *client = 0; /* pointer to client structure */
3061 afs_int32 rights, anyrights; /* rights for this and any user */
3062 struct rx_connection *tcon;
3064 struct client *t_client = NULL; /* tmp ptr to client data */
3065 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3066 struct fsstats fsstats;
3068 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
3070 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
3073 /* Get ptr to client data for user Id for logging */
3074 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3075 logHostAddr.s_addr = rxr_HostOf(tcon);
3077 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3078 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3079 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3081 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3083 InStatus.Mask = 0; /* not storing any status */
3086 * Get associated volume/vnode for the target dir; caller's rights
3087 * are also returned.
3090 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustBeDIR,
3091 &parentwhentargetnotdir, &client, WRITE_LOCK,
3092 &rights, &anyrights))) {
3096 /* set volume synchronization information */
3097 SetVolumeSync(Sync, volptr);
3099 /* Check if we have permission to change the dir's ACL */
3101 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3106 /* Build and store the new Access List for the dir */
3107 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3111 targetptr->changed_newTime = 1; /* status change of directory */
3113 /* convert the write lock to a read lock before breaking callbacks */
3114 VVnodeWriteToRead(&errorCode, targetptr);
3115 opr_Assert(!errorCode || errorCode == VSALVAGE);
3117 rx_KeepAliveOn(acall);
3119 /* break call backs on the directory */
3120 BreakCallBack(client->host, Fid, 0);
3122 /* Get the updated dir's status back to the caller */
3123 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3126 /* Update and store volume/vnode and parent vnodes back */
3127 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3129 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3130 errorCode = CallPostamble(tcon, errorCode, thost);
3132 fsstats_FinishOp(&fsstats, errorCode);
3134 osi_auditU(acall, StoreACLEvent, errorCode,
3135 AUD_ID, t_client ? t_client->ViceId : 0,
3136 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3139 } /*SRXAFS_StoreACL */
3143 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3144 * should be merged when possible.
3147 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3148 struct AFSStoreStatus *InStatus,
3149 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3151 Vnode *targetptr = 0; /* pointer to input fid */
3152 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3153 Error errorCode = 0; /* return code for caller */
3154 Volume *volptr = 0; /* pointer to the volume header */
3155 struct client *client = 0; /* pointer to client structure */
3156 afs_int32 rights, anyrights; /* rights for this and any user */
3157 struct client *t_client = NULL; /* tmp ptr to client data */
3158 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3159 struct rx_connection *tcon = rx_ConnectionOf(acall);
3161 /* Get ptr to client data for user Id for logging */
3162 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3163 logHostAddr.s_addr = rxr_HostOf(tcon);
3165 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3166 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3167 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3169 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3172 * Get volume/vnode for the target file; caller's rights to it are
3176 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
3177 &parentwhentargetnotdir, &client, WRITE_LOCK,
3178 &rights, &anyrights))) {
3179 goto Bad_StoreStatus;
3182 /* set volume synchronization information */
3183 SetVolumeSync(Sync, volptr);
3185 /* Check if the caller has proper permissions to store status to Fid */
3187 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3189 goto Bad_StoreStatus;
3192 * Check for a symbolic link; we can't chmod these (otherwise could
3193 * change a symlink to a mt pt or vice versa)
3195 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3197 goto Bad_StoreStatus;
3200 /* Update the status of the target's vnode */
3201 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3202 (parentwhentargetnotdir ? parentwhentargetnotdir
3203 : targetptr), volptr, 0, 0);
3205 rx_KeepAliveOn(acall);
3207 /* convert the write lock to a read lock before breaking callbacks */
3208 VVnodeWriteToRead(&errorCode, targetptr);
3209 opr_Assert(!errorCode || errorCode == VSALVAGE);
3211 /* Break call backs on Fid */
3212 BreakCallBack(client->host, Fid, 0);
3214 /* Return the updated status back to caller */
3215 GetStatus(targetptr, OutStatus, rights, anyrights,
3216 parentwhentargetnotdir);
3219 /* Update and store volume/vnode and parent vnodes back */
3220 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3222 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3225 } /*SAFSS_StoreStatus */
3229 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3230 struct AFSStoreStatus * InStatus,
3231 struct AFSFetchStatus * OutStatus,
3232 struct AFSVolSync * Sync)
3235 struct rx_connection *tcon;
3237 struct client *t_client = NULL; /* tmp ptr to client data */
3238 struct fsstats fsstats;
3240 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3242 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
3243 goto Bad_StoreStatus;
3245 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3248 code = CallPostamble(tcon, code, thost);
3250 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3252 fsstats_FinishOp(&fsstats, code);
3254 osi_auditU(acall, StoreStatusEvent, code,
3255 AUD_ID, t_client ? t_client->ViceId : 0,
3256 AUD_FID, Fid, AUD_END);
3259 } /*SRXAFS_StoreStatus */
3263 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3264 * merged in when possible.
3267 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3268 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3270 Vnode *parentptr = 0; /* vnode of input Directory */
3271 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3272 Vnode *targetptr = 0; /* file to be deleted */
3273 Volume *volptr = 0; /* pointer to the volume header */
3274 AFSFid fileFid; /* area for Fid from the directory */
3275 Error errorCode = 0; /* error code */
3276 DirHandle dir; /* Handle for dir package I/O */
3277 struct client *client = 0; /* pointer to client structure */
3278 afs_int32 rights, anyrights; /* rights for this and any user */
3279 struct client *t_client; /* tmp ptr to client data */
3280 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3281 struct rx_connection *tcon = rx_ConnectionOf(acall);
3284 /* Get ptr to client data for user Id for logging */
3285 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3286 logHostAddr.s_addr = rxr_HostOf(tcon);
3288 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3289 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3290 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3292 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3295 * Get volume/vnode for the parent dir; caller's access rights are
3299 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3300 &parentwhentargetnotdir, &client, WRITE_LOCK,
3301 &rights, &anyrights))) {
3302 goto Bad_RemoveFile;
3304 /* set volume synchronization information */
3305 SetVolumeSync(Sync, volptr);
3307 /* Does the caller has delete (& write) access to the parent directory? */
3308 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3309 goto Bad_RemoveFile;
3312 /* Actually delete the desired file */
3314 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3316 goto Bad_RemoveFile;
3319 /* Update the vnode status of the parent dir */
3320 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3321 parentptr->disk.linkCount,
3322 client->InSameNetwork);
3324 rx_KeepAliveOn(acall);
3326 /* Return the updated parent dir's status back to caller */
3327 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3329 /* Handle internal callback state for the parent and the deleted file */
3330 if (targetptr->disk.linkCount == 0) {
3331 /* no references left, discard entry */
3332 DeleteFileCallBacks(&fileFid);
3333 /* convert the parent lock to a read lock before breaking callbacks */
3334 VVnodeWriteToRead(&errorCode, parentptr);
3335 opr_Assert(!errorCode || errorCode == VSALVAGE);
3337 /* convert the parent lock to a read lock before breaking callbacks */
3338 VVnodeWriteToRead(&errorCode, parentptr);
3339 opr_Assert(!errorCode || errorCode == VSALVAGE);
3340 /* convert the target lock to a read lock before breaking callbacks */
3341 VVnodeWriteToRead(&errorCode, targetptr);
3342 opr_Assert(!errorCode || errorCode == VSALVAGE);
3343 /* tell all the file has changed */
3344 BreakCallBack(client->host, &fileFid, 1);
3347 /* break call back on the directory */
3348 BreakCallBack(client->host, DirFid, 0);
3351 /* Update and store volume/vnode and parent vnodes back */
3352 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3355 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3358 } /*SAFSS_RemoveFile */
3362 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3363 struct AFSFetchStatus * OutDirStatus,
3364 struct AFSVolSync * Sync)
3367 struct rx_connection *tcon;
3369 struct client *t_client = NULL; /* tmp ptr to client data */
3370 struct fsstats fsstats;
3372 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3374 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
3375 goto Bad_RemoveFile;
3377 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3380 code = CallPostamble(tcon, code, thost);
3382 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3384 fsstats_FinishOp(&fsstats, code);
3386 osi_auditU(acall, RemoveFileEvent, code,
3387 AUD_ID, t_client ? t_client->ViceId : 0,
3388 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3391 } /*SRXAFS_RemoveFile */
3395 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3396 * be merged in when possible.
3399 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3400 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3401 struct AFSFetchStatus *OutFidStatus,
3402 struct AFSFetchStatus *OutDirStatus,
3403 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3405 Vnode *parentptr = 0; /* vnode of input Directory */
3406 Vnode *targetptr = 0; /* vnode of the new file */
3407 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3408 Volume *volptr = 0; /* pointer to the volume header */
3409 Error errorCode = 0; /* error code */
3410 DirHandle dir; /* Handle for dir package I/O */
3411 struct client *client = 0; /* pointer to client structure */
3412 afs_int32 rights, anyrights; /* rights for this and any user */
3413 struct client *t_client; /* tmp ptr to client data */
3414 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3415 struct rx_connection *tcon = rx_ConnectionOf(acall);
3419 /* Get ptr to client data for user Id for logging */
3420 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3421 logHostAddr.s_addr = rxr_HostOf(tcon);
3423 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3424 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3425 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3427 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3429 if (!FileNameOK(Name)) {
3431 goto Bad_CreateFile;
3435 * Get associated volume/vnode for the parent dir; caller long are
3439 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3440 &parentwhentargetnotdir, &client, WRITE_LOCK,
3441 &rights, &anyrights))) {
3442 goto Bad_CreateFile;
3445 /* set volume synchronization information */
3446 SetVolumeSync(Sync, volptr);
3448 /* Can we write (and insert) onto the parent directory? */
3449 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3450 goto Bad_CreateFile;
3453 /* get a new vnode for the file to be created and set it up */
3455 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3456 vFile, nBlocks(0))))
3457 goto Bad_CreateFile;
3459 /* update the status of the parent vnode */
3460 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3461 parentptr->disk.linkCount,
3462 client->InSameNetwork);
3464 /* update the status of the new file's vnode */
3465 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3466 parentptr, volptr, 0, 0);
3468 rx_KeepAliveOn(acall);
3470 /* 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 */
3471 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3472 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3474 /* convert the write lock to a read lock before breaking callbacks */
3475 VVnodeWriteToRead(&errorCode, parentptr);
3476 opr_Assert(!errorCode || errorCode == VSALVAGE);
3478 /* break call back on parent dir */
3479 BreakCallBack(client->host, DirFid, 0);
3481 /* Return a callback promise for the newly created file to the caller */
3482 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3485 /* Update and store volume/vnode and parent vnodes back */
3486 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3489 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3492 } /*SAFSS_CreateFile */
3496 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3497 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3498 struct AFSFetchStatus * OutFidStatus,
3499 struct AFSFetchStatus * OutDirStatus,
3500 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3503 struct rx_connection *tcon;
3505 struct client *t_client = NULL; /* tmp ptr to client data */
3506 struct fsstats fsstats;
3508 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CREATEFILE);
3510 memset(OutFid, 0, sizeof(struct AFSFid));
3512 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
3513 goto Bad_CreateFile;
3516 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3517 OutDirStatus, CallBack, Sync);
3520 code = CallPostamble(tcon, code, thost);
3522 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3524 fsstats_FinishOp(&fsstats, code);
3526 osi_auditU(acall, CreateFileEvent, code,
3527 AUD_ID, t_client ? t_client->ViceId : 0,
3528 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3531 } /*SRXAFS_CreateFile */
3535 * This routine is called exclusively from SRXAFS_Rename(), and should be
3536 * merged in when possible.
3539 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3540 struct AFSFid *NewDirFid, char *NewName,
3541 struct AFSFetchStatus *OutOldDirStatus,
3542 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3544 Vnode *oldvptr = 0; /* vnode of the old Directory */
3545 Vnode *newvptr = 0; /* vnode of the new Directory */
3546 Vnode *fileptr = 0; /* vnode of the file to move */
3547 Vnode *newfileptr = 0; /* vnode of the file to delete */
3548 Vnode *testvptr = 0; /* used in directory tree walk */
3549 Vnode *parent = 0; /* parent for use in SetAccessList */
3550 Error errorCode = 0; /* error code */
3551 Error fileCode = 0; /* used when writing Vnodes */
3552 VnodeId testnode; /* used in directory tree walk */
3553 AFSFid fileFid; /* Fid of file to move */
3554 AFSFid newFileFid; /* Fid of new file */
3555 DirHandle olddir; /* Handle for dir package I/O */
3556 DirHandle newdir; /* Handle for dir package I/O */
3557 DirHandle filedir; /* Handle for dir package I/O */
3558 DirHandle newfiledir; /* Handle for dir package I/O */
3559 Volume *volptr = 0; /* pointer to the volume header */
3560 struct client *client = 0; /* pointer to client structure */
3561 afs_int32 rights, anyrights; /* rights for this and any user */
3562 afs_int32 newrights; /* rights for this user */
3563 afs_int32 newanyrights; /* rights for any user */
3564 int doDelete; /* deleted the rename target (ref count now 0) */
3566 int updatefile = 0; /* are we changing the renamed file? (we do this
3567 * if we need to update .. on a renamed dir) */
3568 struct client *t_client; /* tmp ptr to client data */
3569 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3570 struct rx_connection *tcon = rx_ConnectionOf(acall);
3576 FidZero(&newfiledir);
3578 /* Get ptr to client data for user Id for logging */
3579 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3580 logHostAddr.s_addr = rxr_HostOf(tcon);
3582 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3583 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3584 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3585 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3587 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3589 if (!FileNameOK(NewName)) {
3593 if (OldDirFid->Volume != NewDirFid->Volume) {
3598 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3599 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3600 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3606 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3608 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3609 &parent, &client, WRITE_LOCK, &rights,
3614 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3616 newrights = rights, newanyrights = anyrights;
3619 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr,
3620 MustBeDIR, &parent, &client, WRITE_LOCK,
3621 &newrights, &newanyrights))) {
3627 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr, MustBeDIR,
3628 &parent, &client, WRITE_LOCK, &newrights,
3634 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3635 &parent, &client, WRITE_LOCK, &rights,
3642 /* set volume synchronization information */
3643 SetVolumeSync(Sync, volptr);
3645 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3648 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3652 if (CheckLength(volptr, oldvptr, -1) ||
3653 CheckLength(volptr, newvptr, -1)) {
3654 VTakeOffline(volptr);
3655 errorCode = VSALVAGE;
3659 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3660 * call to CopyOnWrite returns error, it is not necessary to revert back
3661 * the effects of the first call because the contents of the volume is
3662 * not modified, it is only replicated.
3664 if (oldvptr->disk.cloned) {
3665 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3666 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3669 SetDirHandle(&olddir, oldvptr);
3670 if (newvptr->disk.cloned) {
3671 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3672 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3676 SetDirHandle(&newdir, newvptr);
3678 /* Lookup the file to delete its vnode */
3679 if (afs_dir_Lookup(&olddir, OldName, &fileFid)) {
3683 if (fileFid.Vnode == oldvptr->vnodeNumber
3684 || fileFid.Vnode == newvptr->vnodeNumber) {
3685 errorCode = FSERR_ELOOP;
3688 fileFid.Volume = V_id(volptr);
3689 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3690 if (errorCode != 0) {
3692 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3693 OldName, errorCode));
3694 VTakeOffline(volptr);
3697 if (fileptr->disk.uniquifier != fileFid.Unique) {
3699 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3701 VTakeOffline(volptr);
3706 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3707 && fileptr->disk.linkCount != 1) {
3709 * Hard links exist to this file - cannot move one of the links to
3710 * a new directory because of AFS restrictions (this is the same
3711 * reason that links cannot be made across directories, i.e.
3718 /* Lookup the new file */
3719 if (!(afs_dir_Lookup(&newdir, NewName, &newFileFid))) {
3720 if (readonlyServer) {
3721 errorCode = VREADONLY;
3724 if (!(newrights & PRSFS_DELETE)) {
3728 if (newFileFid.Vnode == oldvptr->vnodeNumber
3729 || newFileFid.Vnode == newvptr->vnodeNumber
3730 || newFileFid.Vnode == fileFid.Vnode) {
3734 newFileFid.Volume = V_id(volptr);
3736 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3737 if (errorCode != 0) {
3739 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3740 NewName, errorCode));
3741 VTakeOffline(volptr);
3744 if (fileptr->disk.uniquifier != fileFid.Unique) {
3746 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3748 VTakeOffline(volptr);
3752 SetDirHandle(&newfiledir, newfileptr);
3753 /* Now check that we're moving directories over directories properly, etc.
3754 * return proper POSIX error codes:
3755 * if fileptr is a file and new is a dir: EISDIR.
3756 * if fileptr is a dir and new is a file: ENOTDIR.
3757 * Also, dir to be removed must be empty, of course.
3759 if (newfileptr->disk.type == vDirectory) {
3760 if (fileptr->disk.type != vDirectory) {
3764 if ((afs_dir_IsEmpty(&newfiledir))) {
3769 if (fileptr->disk.type == vDirectory) {
3770 errorCode = ENOTDIR;
3777 * ok - now we check that the old name is not above new name in the
3778 * directory structure. This is to prevent removing a subtree alltogether
3780 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3781 afs_int32 forpass = 0, vnum = 0, top = 0;
3782 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3783 if (testnode > vnum) vnum = testnode;
3784 if (forpass > vnum) {
3785 errorCode = FSERR_ELOOP;
3788 if (testnode == oldvptr->vnodeNumber) {
3789 testnode = oldvptr->disk.parent;
3792 if ((testnode == fileptr->vnodeNumber)
3793 || (testnode == newvptr->vnodeNumber)) {
3794 errorCode = FSERR_ELOOP;
3797 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3798 errorCode = FSERR_ELOOP;
3801 if (testnode == 1) top = 1;
3802 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3803 opr_Assert(errorCode == 0);
3804 testnode = testvptr->disk.parent;
3805 VPutVnode(&errorCode, testvptr);
3806 if ((top == 1) && (testnode != 0)) {
3807 VTakeOffline(volptr);
3809 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
3810 afs_printable_VolumeId_lu(volptr->hashid)));
3814 opr_Assert(errorCode == 0);
3818 if (fileptr->disk.type == vDirectory) {
3819 SetDirHandle(&filedir, fileptr);
3820 if (oldvptr != newvptr) {
3821 /* we always need to update .. if we've moving fileptr to a
3822 * different directory */
3825 struct AFSFid unused;
3827 code = afs_dir_Lookup(&filedir, "..", &unused);
3828 if (code == ENOENT) {
3829 /* only update .. if it doesn't already exist */
3835 /* Do the CopyonWrite first before modifying anything else. Copying is
3836 * required when we have to change entries for ..
3838 if (updatefile && (fileptr->disk.cloned)) {
3839 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3840 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
3842 /* since copyonwrite would mean fileptr has a new handle, do it here */
3844 SetDirHandle(&filedir, fileptr);
3847 /* If the new name exists already, delete it and the file it points to */
3850 /* Delete NewName from its directory */
3851 code = afs_dir_Delete(&newdir, NewName);
3852 opr_Assert(code == 0);
3854 /* Drop the link count */
3855 newfileptr->disk.linkCount--;
3856 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
3857 afs_fsize_t newSize;
3858 VN_GET_LEN(newSize, newfileptr);
3859 VAdjustDiskUsage((Error *) & errorCode, volptr,
3860 (afs_sfsize_t) - nBlocks(newSize), 0);
3861 if (VN_GET_INO(newfileptr)) {
3862 IH_REALLYCLOSE(newfileptr->handle);
3864 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
3865 V_parentId(volptr));
3866 IH_RELEASE(newfileptr->handle);
3867 if (errorCode == -1) {
3869 ("Del: inode=%s, name=%s, errno=%d\n",
3870 PrintInode(stmp, VN_GET_INO(newfileptr)),
3872 if ((errno != ENOENT) && (errno != EIO)
3873 && (errno != ENXIO))
3874 ViceLog(0, ("Do we need to fsck?"));
3877 VN_SET_INO(newfileptr, (Inode) 0);
3878 newfileptr->delete = 1; /* Mark NewName vnode to delete */
3881 /* Link count did not drop to zero.
3882 * Mark NewName vnode as changed - updates stime.
3884 newfileptr->changed_newTime = 1;
3889 * If the create below fails, and the delete above worked, we have
3890 * removed the new name and not replaced it. This is not very likely,
3891 * but possible. We could try to put the old file back, but it is
3892 * highly unlikely that it would work since it would involve issuing
3895 if ((errorCode = afs_dir_Create(&newdir, NewName, &fileFid)))
3898 /* Delete the old name */
3899 opr_Assert(afs_dir_Delete(&olddir, OldName) == 0);
3901 /* if the directory length changes, reflect it in the statistics */
3902 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
3903 oldvptr->disk.linkCount, client->InSameNetwork);
3904 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
3905 newvptr->disk.linkCount, client->InSameNetwork);
3907 if (oldvptr == newvptr)
3908 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
3910 if (fileptr->disk.parent != newvptr->vnodeNumber) {
3911 fileptr->disk.parent = newvptr->vnodeNumber;
3912 fileptr->changed_newTime = 1;
3915 /* if we are dealing with a rename of a directory, and we need to
3916 * update the .. entry of that directory */
3918 opr_Assert(!fileptr->disk.cloned);
3920 fileptr->changed_newTime = 1; /* status change of moved file */
3922 /* fix .. to point to the correct place */
3923 afs_dir_Delete(&filedir, ".."); /* No assert--some directories may be bad */
3924 opr_Assert(afs_dir_Create(&filedir, "..", NewDirFid) == 0);
3925 fileptr->disk.dataVersion++;
3927 /* if the parent directories are different the link counts have to be */
3928 /* changed due to .. in the renamed directory */
3929 if (oldvptr != newvptr) {
3930 oldvptr->disk.linkCount--;
3931 newvptr->disk.linkCount++;
3935 /* set up return status */
3936 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
3937 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
3938 if (newfileptr && doDelete) {
3939 DeleteFileCallBacks(&newFileFid); /* no other references */
3944 /* convert the write locks to a read locks before breaking callbacks */
3945 VVnodeWriteToRead(&errorCode, newvptr);
3946 opr_Assert(!errorCode || errorCode == VSALVAGE);
3947 if (oldvptr != newvptr) {
3948 VVnodeWriteToRead(&errorCode, oldvptr);
3949 opr_Assert(!errorCode || errorCode == VSALVAGE);
3951 if (newfileptr && !doDelete) {
3952 /* convert the write lock to a read lock before breaking callbacks */
3953 VVnodeWriteToRead(&errorCode, newfileptr);
3954 opr_Assert(!errorCode || errorCode == VSALVAGE);
3957 rx_KeepAliveOn(acall);
3959 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
3960 BreakCallBack(client->host, NewDirFid, 0);
3961 if (oldvptr != newvptr) {
3962 BreakCallBack(client->host, OldDirFid, 0);
3965 /* if a dir moved, .. changed */
3966 /* we do not give an AFSFetchStatus structure back to the
3967 * originating client, and the file's status has changed, so be
3968 * sure to send a callback break. In theory the client knows
3969 * enough to know that the callback could be broken implicitly,
3970 * but that may not be clear, and some client implementations
3971 * may not know to. */
3972 BreakCallBack(client->host, &fileFid, 1);
3975 /* Note: it is not necessary to break the callback */
3977 DeleteFileCallBacks(&newFileFid); /* no other references */
3979 /* other's still exist (with wrong link count) */
3980 BreakCallBack(client->host, &newFileFid, 1);
3985 rx_KeepAliveOff(acall);
3986 VPutVnode(&fileCode, newfileptr);
3987 opr_Assert(fileCode == 0);
3989 (void)PutVolumePackage(acall, fileptr, (newvptr && newvptr != oldvptr ?
3990 newvptr : 0), oldvptr, volptr, &client);
3994 FidZap(&newfiledir);
3995 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4002 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4003 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4004 struct AFSFetchStatus * OutOldDirStatus,
4005 struct AFSFetchStatus * OutNewDirStatus,
4006 struct AFSVolSync * Sync)
4009 struct rx_connection *tcon;
4011 struct client *t_client = NULL; /* tmp ptr to client data */
4012 struct fsstats fsstats;
4014 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RENAME);
4016 if ((code = CallPreamble(acall, ACTIVECALL, OldDirFid, &tcon, &thost)))
4020 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4021 OutOldDirStatus, OutNewDirStatus, Sync);
4024 code = CallPostamble(tcon, code, thost);
4026 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4028 fsstats_FinishOp(&fsstats, code);
4030 osi_auditU(acall, RenameFileEvent, code,
4031 AUD_ID, t_client ? t_client->ViceId : 0,
4032 AUD_FID, OldDirFid, AUD_STR, OldName,
4033 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4036 } /*SRXAFS_Rename */
4040 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4041 * merged into it when possible.
4044 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4045 char *LinkContents, struct AFSStoreStatus *InStatus,
4046 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4047 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4049 Vnode *parentptr = 0; /* vnode of input Directory */
4050 Vnode *targetptr = 0; /* vnode of the new link */
4051 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4052 Error errorCode = 0; /* error code */
4055 DirHandle dir; /* Handle for dir package I/O */
4056 Volume *volptr = 0; /* pointer to the volume header */
4057 struct client *client = 0; /* pointer to client structure */
4058 afs_int32 rights, anyrights; /* rights for this and any user */
4059 struct client *t_client; /* tmp ptr to client data */
4060 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4062 struct rx_connection *tcon = rx_ConnectionOf(acall);
4066 /* Get ptr to client data for user Id for logging */
4067 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4068 logHostAddr.s_addr = rxr_HostOf(tcon);
4070 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4071 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4072 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4074 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4076 if (!FileNameOK(Name)) {
4082 * Get the vnode and volume for the parent dir along with the caller's
4086 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4087 &parentwhentargetnotdir, &client, WRITE_LOCK,
4088 &rights, &anyrights)))
4091 /* set volume synchronization information */
4092 SetVolumeSync(Sync, volptr);
4094 /* Does the caller has insert (and write) access to the parent directory? */
4095 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)))
4099 * If we're creating a mount point (any x bits clear), we must have
4100 * administer access to the directory, too. Always allow sysadmins
4103 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4104 if (readonlyServer) {
4105 errorCode = VREADONLY;
4109 * We have a mountpoint, 'cause we're trying to set the Unix mode
4110 * bits to something with some x bits missing (default mode bits
4111 * if AFS_SETMODE is false is 0777)
4113 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4119 /* get a new vnode for the symlink and set it up */
4121 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4122 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4126 /* update the status of the parent vnode */
4127 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4128 parentptr->disk.linkCount,
4129 client->InSameNetwork);
4131 /* update the status of the new symbolic link file vnode */
4132 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4133 parentptr, volptr, strlen((char *)LinkContents), 0);
4135 /* Write the contents of the symbolic link name into the target inode */
4136 fdP = IH_OPEN(targetptr->handle);
4138 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4139 parentptr, volptr, &client);
4140 VTakeOffline(volptr);
4141 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
4142 afs_printable_VolumeId_lu(volptr->hashid)));
4145 len = strlen((char *) LinkContents);
4146 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4148 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4151 * Set up and return modified status for the parent dir and new symlink
4154 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4155 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4157 /* convert the write lock to a read lock before breaking callbacks */
4158 VVnodeWriteToRead(&errorCode, parentptr);
4159 opr_Assert(!errorCode || errorCode == VSALVAGE);
4161 rx_KeepAliveOn(acall);
4163 /* break call back on the parent dir */
4164 BreakCallBack(client->host, DirFid, 0);
4167 /* Write the all modified vnodes (parent, new files) and volume back */
4168 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4171 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4172 return ( errorCode ? errorCode : code );
4174 } /*SAFSS_Symlink */
4178 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4179 struct AFSFid *DirFid, /* Parent dir's fid */
4180 char *Name, /* File name to create */
4181 char *LinkContents, /* Contents of the new created file */
4182 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4183 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4184 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4185 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4186 struct AFSVolSync *Sync)
4189 struct rx_connection *tcon;
4191 struct client *t_client = NULL; /* tmp ptr to client data */
4192 struct fsstats fsstats;
4194 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SYMLINK);
4196 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4200 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4201 OutFidStatus, OutDirStatus, Sync);
4204 code = CallPostamble(tcon, code, thost);
4206 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4208 fsstats_FinishOp(&fsstats, code);
4210 osi_auditU(acall, SymlinkEvent, code,
4211 AUD_ID, t_client ? t_client->ViceId : 0,
4212 AUD_FID, DirFid, AUD_STR, Name,
4213 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4216 } /*SRXAFS_Symlink */
4220 * This routine is called exclusively by SRXAFS_Link(), and should be
4221 * merged into it when possible.
4224 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4225 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4226 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4228 Vnode *parentptr = 0; /* vnode of input Directory */
4229 Vnode *targetptr = 0; /* vnode of the new file */
4230 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4231 Volume *volptr = 0; /* pointer to the volume header */
4232 Error errorCode = 0; /* error code */
4233 DirHandle dir; /* Handle for dir package I/O */
4234 struct client *client = 0; /* pointer to client structure */
4235 afs_int32 rights, anyrights; /* rights for this and any user */
4236 struct client *t_client; /* tmp ptr to client data */
4237 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4238 struct rx_connection *tcon = rx_ConnectionOf(acall);
4242 /* Get ptr to client data for user Id for logging */
4243 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4244 logHostAddr.s_addr = rxr_HostOf(tcon);
4246 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4247 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4248 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4249 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4251 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4253 if (DirFid->Volume != ExistingFid->Volume) {
4257 if (!FileNameOK(Name)) {
4263 * Get the vnode and volume for the parent dir along with the caller's
4267 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4268 &parentwhentargetnotdir, &client, WRITE_LOCK,
4269 &rights, &anyrights))) {
4273 /* set volume synchronization information */
4274 SetVolumeSync(Sync, volptr);
4276 /* Can the caller insert into the parent directory? */
4277 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4281 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4282 /* AFS fileservers always have directory vnodes that are odd. */
4287 if (CheckLength(volptr, parentptr, -1)) {
4288 VTakeOffline(volptr);
4289 errorCode = VSALVAGE;
4293 /* get the file vnode */
4295 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4299 if (targetptr->disk.type != vFile) {
4303 if (targetptr->disk.parent != DirFid->Vnode) {
4307 if (parentptr->disk.cloned) {
4308 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4309 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4310 goto Bad_Link; /* disk full error */
4313 /* add the name to the directory */
4314 SetDirHandle(&dir, parentptr);
4315 if ((errorCode = afs_dir_Create(&dir, Name, ExistingFid)))
4319 /* update the status in the parent vnode */
4320 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4321 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4322 parentptr->disk.linkCount,
4323 client->InSameNetwork);
4325 targetptr->disk.linkCount++;
4326 targetptr->disk.author = client->ViceId;
4327 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4329 /* set up return status */
4330 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4331 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4333 /* convert the write locks to read locks before breaking callbacks */
4334 VVnodeWriteToRead(&errorCode, targetptr);
4335 opr_Assert(!errorCode || errorCode == VSALVAGE);
4336 VVnodeWriteToRead(&errorCode, parentptr);
4337 opr_Assert(!errorCode || errorCode == VSALVAGE);
4339 rx_KeepAliveOn(acall);
4341 /* break call back on DirFid */
4342 BreakCallBack(client->host, DirFid, 0);
4344 * We also need to break the callback for the file that is hard-linked since part
4345 * of its status (like linkcount) is changed
4347 BreakCallBack(client->host, ExistingFid, 0);
4350 /* Write the all modified vnodes (parent, new files) and volume back */
4351 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4354 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4361 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4362 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4363 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4366 struct rx_connection *tcon;
4368 struct client *t_client = NULL; /* tmp ptr to client data */
4369 struct fsstats fsstats;
4371 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_LINK);
4373 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4377 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4378 OutDirStatus, Sync);
4381 code = CallPostamble(tcon, code, thost);
4383 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4385 fsstats_FinishOp(&fsstats, code);
4387 osi_auditU(acall, LinkEvent, code,
4388 AUD_ID, t_client ? t_client->ViceId : 0,
4389 AUD_FID, DirFid, AUD_STR, Name,
4390 AUD_FID, ExistingFid, AUD_END);
4397 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4398 * merged into it when possible.
4401 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4402 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4403 struct AFSFetchStatus *OutFidStatus,
4404 struct AFSFetchStatus *OutDirStatus,
4405 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4407 Vnode *parentptr = 0; /* vnode of input Directory */
4408 Vnode *targetptr = 0; /* vnode of the new file */
4409 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4410 Volume *volptr = 0; /* pointer to the volume header */
4411 Error errorCode = 0; /* error code */
4412 struct acl_accessList *newACL; /* Access list */
4413 int newACLSize; /* Size of access list */
4414 DirHandle dir; /* Handle for dir package I/O */
4415 DirHandle parentdir; /* Handle for dir package I/O */
4416 struct client *client = 0; /* pointer to client structure */
4417 afs_int32 rights, anyrights; /* rights for this and any user */
4418 struct client *t_client; /* tmp ptr to client data */
4419 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4420 struct rx_connection *tcon = rx_ConnectionOf(acall);
4423 FidZero(&parentdir);
4425 /* Get ptr to client data for user Id for logging */
4426 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4427 logHostAddr.s_addr = rxr_HostOf(tcon);
4429 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4430 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4431 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4433 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4435 if (!FileNameOK(Name)) {
4441 * Get the vnode and volume for the parent dir along with the caller's
4445 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4446 &parentwhentargetnotdir, &client, WRITE_LOCK,
4447 &rights, &anyrights))) {
4451 /* set volume synchronization information */
4452 SetVolumeSync(Sync, volptr);
4454 /* Write access to the parent directory? */
4455 #ifdef DIRCREATE_NEED_WRITE
4457 * requires w access for the user to create a directory. this
4458 * closes a loophole in the current security arrangement, since a
4459 * user with i access only can create a directory and get the
4460 * implcit a access that goes with dir ownership, and proceed to
4461 * subvert quota in the volume.
4463 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4464 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4466 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4467 #endif /* DIRCREATE_NEED_WRITE */
4470 #define EMPTYDIRBLOCKS 2
4471 /* get a new vnode and set it up */
4473 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4474 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4478 /* Update the status for the parent dir */
4479 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4480 parentptr->disk.linkCount + 1,
4481 client->InSameNetwork);
4483 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4484 opr_Verify((SetAccessList(&targetptr, &volptr, &newACL, &newACLSize,
4485 &parentwhentargetnotdir, NULL, 0)) == 0);
4486 opr_Assert(parentwhentargetnotdir == 0);
4487 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4489 /* update the status for the target vnode */
4490 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4491 parentptr, volptr, 0, 0);
4493 /* Actually create the New directory in the directory package */
4494 SetDirHandle(&dir, targetptr);
4495 opr_Verify(!(afs_dir_MakeDir(&dir, (afs_int32 *)OutFid,
4496 (afs_int32 *)DirFid)));
4498 VN_SET_LEN(targetptr, (afs_fsize_t) afs_dir_Length(&dir));
4500 /* set up return status */
4501 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4502 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4504 /* convert the write lock to a read lock before breaking callbacks */
4505 VVnodeWriteToRead(&errorCode, parentptr);
4506 opr_Assert(!errorCode || errorCode == VSALVAGE);
4508 rx_KeepAliveOn(acall);
4510 /* break call back on DirFid */
4511 BreakCallBack(client->host, DirFid, 0);
4513 /* Return a callback promise to caller */
4514 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4517 /* Write the all modified vnodes (parent, new files) and volume back */
4518 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4522 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4525 } /*SAFSS_MakeDir */
4529 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4530 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4531 struct AFSFetchStatus * OutFidStatus,
4532 struct AFSFetchStatus * OutDirStatus,
4533 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4536 struct rx_connection *tcon;
4538 struct client *t_client = NULL; /* tmp ptr to client data */
4539 struct fsstats fsstats;
4541 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_MAKEDIR);
4543 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4547 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4548 OutDirStatus, CallBack, Sync);
4551 code = CallPostamble(tcon, code, thost);
4553 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4555 fsstats_FinishOp(&fsstats, code);
4557 osi_auditU(acall, MakeDirEvent, code,
4558 AUD_ID, t_client ? t_client->ViceId : 0,
4559 AUD_FID, DirFid, AUD_STR, Name,
4560 AUD_FID, OutFid, AUD_END);
4563 } /*SRXAFS_MakeDir */
4567 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4568 * merged into it when possible.
4571 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4572 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4574 Vnode *parentptr = 0; /* vnode of input Directory */
4575 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4576 Vnode *targetptr = 0; /* file to be deleted */
4577 AFSFid fileFid; /* area for Fid from the directory */
4578 Error errorCode = 0; /* error code */
4579 DirHandle dir; /* Handle for dir package I/O */
4580 Volume *volptr = 0; /* pointer to the volume header */
4581 struct client *client = 0; /* pointer to client structure */
4582 afs_int32 rights, anyrights; /* rights for this and any user */
4583 struct client *t_client; /* tmp ptr to client data */
4584 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4585 struct rx_connection *tcon = rx_ConnectionOf(acall);
4589 /* Get ptr to client data for user Id for logging */
4590 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4591 logHostAddr.s_addr = rxr_HostOf(tcon);
4593 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4594 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4595 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4597 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4600 * Get the vnode and volume for the parent dir along with the caller's
4604 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4605 &parentwhentargetnotdir, &client, WRITE_LOCK,
4606 &rights, &anyrights))) {
4610 /* set volume synchronization information */
4611 SetVolumeSync(Sync, volptr);
4613 /* Does the caller has delete (&write) access to the parent dir? */
4614 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4618 /* Do the actual delete of the desired (empty) directory, Name */
4620 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4625 /* Update the status for the parent dir; link count is also adjusted */
4626 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4627 parentptr->disk.linkCount - 1,
4628 client->InSameNetwork);
4630 /* Return to the caller the updated parent dir status */
4631 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4634 * Note: it is not necessary to break the callback on fileFid, since
4635 * refcount is now 0, so no one should be able to refer to the dir
4638 DeleteFileCallBacks(&fileFid);
4640 /* convert the write lock to a read lock before breaking callbacks */
4641 VVnodeWriteToRead(&errorCode, parentptr);
4642 opr_Assert(!errorCode || errorCode == VSALVAGE);
4644 rx_KeepAliveOn(acall);
4646 /* break call back on DirFid and fileFid */
4647 BreakCallBack(client->host, DirFid, 0);
4650 /* Write the all modified vnodes (parent, new files) and volume back */
4651 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4654 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4657 } /*SAFSS_RemoveDir */
4661 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4662 struct AFSFetchStatus * OutDirStatus,
4663 struct AFSVolSync * Sync)
4666 struct rx_connection *tcon;
4668 struct client *t_client = NULL; /* tmp ptr to client data */
4669 struct fsstats fsstats;
4671 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEDIR);
4673 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4676 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4679 code = CallPostamble(tcon, code, thost);
4681 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4683 fsstats_FinishOp(&fsstats, code);
4685 osi_auditU(acall, RemoveDirEvent, code,
4686 AUD_ID, t_client ? t_client->ViceId : 0,
4687 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4690 } /*SRXAFS_RemoveDir */
4694 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4695 * merged into it when possible.
4698 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4699 struct AFSVolSync *Sync)
4701 Vnode *targetptr = 0; /* vnode of input file */
4702 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4703 Error errorCode = 0; /* error code */
4704 Volume *volptr = 0; /* pointer to the volume header */
4705 struct client *client = 0; /* pointer to client structure */
4706 afs_int32 rights, anyrights; /* rights for this and any user */
4707 struct client *t_client; /* tmp ptr to client data */
4708 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4709 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
4710 struct rx_connection *tcon = rx_ConnectionOf(acall);
4712 if (type != LockRead && type != LockWrite) {
4716 /* Get ptr to client data for user Id for logging */
4717 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4718 logHostAddr.s_addr = rxr_HostOf(tcon);
4720 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4721 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4722 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4724 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4727 * Get the vnode and volume for the desired file along with the caller's
4731 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4732 &parentwhentargetnotdir, &client, WRITE_LOCK,
4733 &rights, &anyrights))) {
4737 /* set volume synchronization information */
4738 SetVolumeSync(Sync, volptr);
4740 /* Handle the particular type of set locking, type */
4741 errorCode = HandleLocking(targetptr, client, rights, type);
4744 /* Write the all modified vnodes (parent, new files) and volume back */
4745 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4746 (Vnode *) 0, volptr, &client);
4748 if ((errorCode == VREADONLY) && (type == LockRead))
4749 errorCode = 0; /* allow read locks on RO volumes without saving state */
4751 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
4754 } /*SAFSS_SetLock */
4758 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
4759 ViceLockType type, struct AFSVolSync * Sync)
4761 return SRXAFS_SetLock(acall, Fid, type, Sync);
4762 } /*SRXAFS_OldSetLock */
4766 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
4767 struct AFSVolSync * Sync)
4770 struct rx_connection *tcon;
4772 struct client *t_client = NULL; /* tmp ptr to client data */
4773 struct fsstats fsstats;
4775 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETLOCK);
4777 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
4780 code = SAFSS_SetLock(acall, Fid, type, Sync);
4783 code = CallPostamble(tcon, code, thost);
4785 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4787 fsstats_FinishOp(&fsstats, code);
4789 osi_auditU(acall, SetLockEvent, code,
4790 AUD_ID, t_client ? t_client->ViceId : 0,
4791 AUD_FID, Fid, AUD_LONG, type, AUD_END);
4793 } /*SRXAFS_SetLock */
4797 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
4798 * merged into it when possible.
4801 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
4802 struct AFSVolSync *Sync)
4804 Vnode *targetptr = 0; /* vnode of input file */
4805 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4806 Error errorCode = 0; /* error code */
4807 Volume *volptr = 0; /* pointer to the volume header */
4808 struct client *client = 0; /* pointer to client structure */
4809 afs_int32 rights, anyrights; /* rights for this and any user */
4810 struct client *t_client; /* tmp ptr to client data */
4811 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4812 struct rx_connection *tcon = rx_ConnectionOf(acall);
4814 /* Get ptr to client data for user Id for logging */
4815 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4816 logHostAddr.s_addr = rxr_HostOf(tcon);
4818 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4819 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4820 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4822 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
4825 * Get the vnode and volume for the desired file along with the caller's
4829 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4830 &parentwhentargetnotdir, &client, WRITE_LOCK,
4831 &rights, &anyrights))) {
4832 goto Bad_ExtendLock;
4835 /* set volume synchronization information */
4836 SetVolumeSync(Sync, volptr);
4838 /* Handle the actual lock extension */
4839 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
4842 /* Put back file's vnode and volume */
4843 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4844 (Vnode *) 0, volptr, &client);
4846 if (errorCode == VREADONLY) /* presumably, we already granted this lock */
4847 errorCode = 0; /* under our generous policy re RO vols */
4849 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
4852 } /*SAFSS_ExtendLock */
4856 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4857 struct AFSVolSync * Sync)
4859 return SRXAFS_ExtendLock(acall, Fid, Sync);
4860 } /*SRXAFS_OldExtendLock */
4864 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4865 struct AFSVolSync * Sync)
4868 struct rx_connection *tcon;
4870 struct client *t_client = NULL; /* tmp ptr to client data */
4871 struct fsstats fsstats;
4873 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_EXTENDLOCK);
4875 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
4876 goto Bad_ExtendLock;
4878 code = SAFSS_ExtendLock(acall, Fid, Sync);
4881 code = CallPostamble(tcon, code, thost);
4883 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4885 fsstats_FinishOp(&fsstats, code);
4887 osi_auditU(acall, ExtendLockEvent, code,
4888 AUD_ID, t_client ? t_client->ViceId : 0,
4889 AUD_FID, Fid, AUD_END);
4892 } /*SRXAFS_ExtendLock */
4896 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
4897 * merged into it when possible.
4900 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
4901 struct AFSVolSync *Sync)
4903 Vnode *targetptr = 0; /* vnode of input file */
4904 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4905 Error errorCode = 0; /* error code */
4906 Volume *volptr = 0; /* pointer to the volume header */
4907 struct client *client = 0; /* pointer to client structure */
4908 afs_int32 rights, anyrights; /* rights for this and any user */
4909 struct client *t_client; /* tmp ptr to client data */
4910 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4911 struct rx_connection *tcon = rx_ConnectionOf(acall);
4913 /* Get ptr to client data for user Id for logging */
4914 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4915 logHostAddr.s_addr = rxr_HostOf(tcon);
4917 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4918 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4919 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4921 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
4924 * Get the vnode and volume for the desired file along with the caller's
4928 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4929 &parentwhentargetnotdir, &client, WRITE_LOCK,
4930 &rights, &anyrights))) {
4931 goto Bad_ReleaseLock;
4934 /* set volume synchronization information */
4935 SetVolumeSync(Sync, volptr);
4937 /* Handle the actual lock release */
4938 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
4939 goto Bad_ReleaseLock;
4941 /* if no more locks left, a callback would be triggered here */
4942 if (targetptr->disk.lock.lockCount <= 0) {
4943 rx_KeepAliveOn(acall);
4944 /* convert the write lock to a read lock before breaking callbacks */
4945 VVnodeWriteToRead(&errorCode, targetptr);
4946 opr_Assert(!errorCode || errorCode == VSALVAGE);
4947 BreakCallBack(client->host, Fid, 0);
4951 /* Put back file's vnode and volume */
4952 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4953 (Vnode *) 0, volptr, &client);
4955 if (errorCode == VREADONLY) /* presumably, we already granted this lock */
4956 errorCode = 0; /* under our generous policy re RO vols */
4958 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
4961 } /*SAFSS_ReleaseLock */
4965 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4966 struct AFSVolSync * Sync)
4968 return SRXAFS_ReleaseLock(acall, Fid, Sync);
4969 } /*SRXAFS_OldReleaseLock */
4973 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4974 struct AFSVolSync * Sync)
4977 struct rx_connection *tcon;
4979 struct client *t_client = NULL; /* tmp ptr to client data */
4980 struct fsstats fsstats;
4982 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RELEASELOCK);
4984 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
4985 goto Bad_ReleaseLock;
4987 code = SAFSS_ReleaseLock(acall, Fid, Sync);
4990 code = CallPostamble(tcon, code, thost);
4992 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4994 fsstats_FinishOp(&fsstats, code);
4996 osi_auditU(acall, ReleaseLockEvent, code,
4997 AUD_ID, t_client ? t_client->ViceId : 0,
4998 AUD_FID, Fid, AUD_END);
5001 } /*SRXAFS_ReleaseLock */
5005 SetSystemStats(struct AFSStatistics *stats)
5007 /* Fix this sometime soon.. */
5008 /* Because hey, it's not like we have a network monitoring protocol... */
5010 stats->CurrentTime = time(NULL);
5011 } /*SetSystemStats */
5014 SetAFSStats(struct AFSStatistics *stats)
5016 extern afs_int32 StartTime, CurrentConnections;
5020 stats->CurrentMsgNumber = 0;
5021 stats->OldestMsgNumber = 0;
5022 stats->StartTime = StartTime;
5023 stats->CurrentConnections = CurrentConnections;
5024 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5025 stats->TotalFetchs =
5026 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5027 AFSCallStats.FetchStatus;
5028 stats->FetchDatas = AFSCallStats.FetchData;
5029 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5030 seconds = AFSCallStats.AccumFetchTime / 1000;
5033 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5034 stats->TotalStores =
5035 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5036 AFSCallStats.StoreStatus;
5037 stats->StoreDatas = AFSCallStats.StoreData;
5038 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5039 seconds = AFSCallStats.AccumStoreTime / 1000;
5042 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5043 stats->ProcessSize = opr_procsize();
5045 h_GetWorkStats((int *)&(stats->WorkStations),
5046 (int *)&(stats->ActiveWorkStations), (int *)0,
5047 (afs_int32) (time(NULL)) - (15 * 60));
5051 /* Get disk related information from all AFS partitions. */
5054 SetVolumeStats(struct AFSStatistics *stats)
5056 struct DiskPartition64 *part;
5059 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5060 part = part->next) {
5061 stats->Disks[i].TotalBlocks = RoundInt64ToInt31(part->totalUsable);
5062 stats->Disks[i].BlocksAvailable = RoundInt64ToInt31(part->free);
5063 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5064 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5067 while (i < AFS_MSTATDISKS) {
5068 stats->Disks[i].TotalBlocks = -1;
5071 } /*SetVolumeStats */
5074 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5077 struct rx_connection *tcon = rx_ConnectionOf(acall);
5079 struct client *t_client = NULL; /* tmp ptr to client data */
5080 struct fsstats fsstats;
5082 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5084 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
5085 goto Bad_GetStatistics;
5087 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5089 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5091 memset(Statistics, 0, sizeof(*Statistics));
5092 SetAFSStats((struct AFSStatistics *)Statistics);
5093 SetVolumeStats((struct AFSStatistics *)Statistics);
5094 SetSystemStats((struct AFSStatistics *)Statistics);
5097 code = CallPostamble(tcon, code, thost);
5099 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5101 fsstats_FinishOp(&fsstats, code);
5103 osi_auditU(acall, GetStatisticsEvent, code,
5104 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5106 } /*SRXAFS_GetStatistics */
5110 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5112 extern afs_int32 StartTime, CurrentConnections;
5115 struct rx_connection *tcon = rx_ConnectionOf(acall);
5117 struct client *t_client = NULL; /* tmp ptr to client data */
5118 struct fsstats fsstats;
5120 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5122 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
5123 goto Bad_GetStatistics64;
5125 if (statsVersion != STATS64_VERSION) {
5127 goto Bad_GetStatistics64;
5130 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5131 Statistics->ViceStatistics64_val =
5132 malloc(statsVersion*sizeof(afs_uint64));
5133 Statistics->ViceStatistics64_len = statsVersion;
5135 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5136 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5137 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5139 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5140 AFSCallStats.TotalCalls;
5141 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5142 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5143 AFSCallStats.FetchStatus;
5144 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5145 AFSCallStats.FetchData;
5146 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5147 AFSCallStats.TotalFetchedBytes;
5148 seconds = AFSCallStats.AccumFetchTime / 1000;
5151 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5152 AFSCallStats.TotalFetchedBytes / seconds;
5153 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5154 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5155 AFSCallStats.StoreStatus;
5156 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5157 AFSCallStats.StoreData;
5158 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5159 AFSCallStats.TotalStoredBytes;
5160 seconds = AFSCallStats.AccumStoreTime / 1000;
5163 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5164 AFSCallStats.TotalStoredBytes / seconds;
5165 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = opr_procsize();
5167 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5168 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5170 (afs_int32) (time(NULL)) - (15 * 60));
5172 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time(NULL);
5174 Bad_GetStatistics64:
5175 code = CallPostamble(tcon, code, thost);
5177 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5179 fsstats_FinishOp(&fsstats, code);
5181 osi_auditU(acall, GetStatisticsEvent, code,
5182 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5184 } /*SRXAFS_GetStatistics */
5187 /*------------------------------------------------------------------------
5188 * EXPORTED SRXAFS_XStatsVersion
5191 * Routine called by the server-side RPC interface to implement
5192 * pulling out the xstat version number for the File Server.
5195 * a_versionP : Ptr to the version number variable to set.
5201 * Nothing interesting.
5205 *------------------------------------------------------------------------*/
5208 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5209 { /*SRXAFS_XStatsVersion */
5211 struct client *t_client = NULL; /* tmp ptr to client data */
5212 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5213 struct fsstats fsstats;
5215 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_XSTATSVERSION);
5217 *a_versionP = AFS_XSTAT_VERSION;
5219 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5221 fsstats_FinishOp(&fsstats, 0);
5223 osi_auditU(a_call, XStatsVersionEvent, 0,
5224 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5226 } /*SRXAFS_XStatsVersion */
5229 /*------------------------------------------------------------------------
5230 * PRIVATE FillPerfValues
5233 * Routine called to fill a regular performance data structure.
5236 * a_perfP : Ptr to perf structure to fill
5242 * Various collections need this info, so the guts were put in
5243 * this separate routine.
5247 *------------------------------------------------------------------------*/
5250 FillPerfValues(struct afs_PerfStats *a_perfP)
5251 { /*FillPerfValues */
5252 int dir_Buffers; /*# buffers in use by dir package */
5253 int dir_Calls; /*# read calls in dir package */
5254 int dir_IOs; /*# I/O ops in dir package */
5255 struct rx_statistics *stats;
5258 * Vnode cache section.
5260 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5261 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5262 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5263 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5264 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5265 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5266 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5267 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5268 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5269 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5270 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5271 a_perfP->vcache_H_Gets = (int)VStats.hdr_gets;
5272 a_perfP->vcache_H_Replacements = (int)VStats.hdr_loads;
5275 * Directory section.
5277 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5278 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5279 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5280 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5285 stats = rx_GetStatistics();
5287 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5288 a_perfP->rx_noPackets_RcvClass =
5289 (afs_int32) stats->receivePktAllocFailures;
5290 a_perfP->rx_noPackets_SendClass =
5291 (afs_int32) stats->sendPktAllocFailures;
5292 a_perfP->rx_noPackets_SpecialClass =
5293 (afs_int32) stats->specialPktAllocFailures;
5294 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5295 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5296 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5297 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5298 a_perfP->rx_noPacketBuffersOnRead =
5299 (afs_int32) stats->noPacketBuffersOnRead;
5300 a_perfP->rx_selects = (afs_int32) stats->selects;
5301 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5302 a_perfP->rx_packetsRead_RcvClass =
5303 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5304 a_perfP->rx_packetsRead_SendClass =
5305 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5306 a_perfP->rx_packetsRead_SpecialClass =
5307 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5308 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5309 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5310 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5311 a_perfP->rx_spuriousPacketsRead =
5312 (afs_int32) stats->spuriousPacketsRead;
5313 a_perfP->rx_packetsSent_RcvClass =
5314 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5315 a_perfP->rx_packetsSent_SendClass =
5316 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5317 a_perfP->rx_packetsSent_SpecialClass =
5318 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5319 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5320 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5321 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
5322 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
5323 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
5324 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
5325 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
5326 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
5327 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
5328 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
5329 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
5330 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
5331 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
5332 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
5333 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
5334 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
5335 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
5336 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
5337 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
5338 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
5340 a_perfP->host_NumHostEntries = HTs;
5341 a_perfP->host_HostBlocks = HTBlocks;
5342 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5343 &(a_perfP->host_HostsInSameNetOrSubnet),
5344 &(a_perfP->host_HostsInDiffSubnet),
5345 &(a_perfP->host_HostsInDiffNetwork));
5346 a_perfP->host_NumClients = CEs;
5347 a_perfP->host_ClientBlocks = CEBlocks;
5349 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5350 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
5351 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5352 rx_FreeStatistics(&stats);
5353 } /*FillPerfValues */
5356 /*------------------------------------------------------------------------
5357 * EXPORTED SRXAFS_GetXStats
5360 * Routine called by the server-side callback RPC interface to
5361 * implement getting the given data collection from the extended
5362 * File Server statistics.
5365 * a_call : Ptr to Rx call on which this request came in.
5366 * a_clientVersionNum : Client version number.
5367 * a_opCode : Desired operation.
5368 * a_serverVersionNumP : Ptr to version number to set.
5369 * a_timeP : Ptr to time value (seconds) to set.
5370 * a_dataP : Ptr to variable array structure to return
5377 * Nothing interesting.
5381 *------------------------------------------------------------------------*/
5384 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5385 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5386 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5387 { /*SRXAFS_GetXStats */
5389 int code; /*Return value */
5390 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5391 afs_int32 dataBytes; /*Bytes in data buffer */
5392 struct fsstats fsstats;
5394 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETXSTATS);
5397 * Record the time of day and the server version number.
5399 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5400 *a_timeP = (afs_int32) time(NULL);
5403 * Stuff the appropriate data in there (assume victory)
5408 ("Received GetXStats call for collection %d\n",
5409 a_collectionNumber));
5413 * We're not keeping stats, so just return successfully with
5416 a_dataP->AFS_CollData_len = 0;
5417 a_dataP->AFS_CollData_val = NULL;
5420 switch (a_collectionNumber) {
5421 case AFS_XSTATSCOLL_CALL_INFO:
5423 * Pass back all the call-count-related data.
5425 * >>> We are forced to allocate a separate area in which to
5426 * >>> put this stuff in by the RPC stub generator, since it
5427 * >>> will be freed at the tail end of the server stub code.
5431 * I don't think call-level stats are being collected yet
5432 * for the File Server.
5434 dataBytes = sizeof(struct afs_Stats);
5435 dataBuffP = malloc(dataBytes);
5436 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5437 a_dataP->AFS_CollData_len = dataBytes >> 2;
5438 a_dataP->AFS_CollData_val = dataBuffP;
5440 a_dataP->AFS_CollData_len = 0;
5441 a_dataP->AFS_CollData_val = NULL;
5445 case AFS_XSTATSCOLL_PERF_INFO:
5447 * Pass back all the regular performance-related data.
5449 * >>> We are forced to allocate a separate area in which to
5450 * >>> put this stuff in by the RPC stub generator, since it
5451 * >>> will be freed at the tail end of the server stub code.
5454 afs_perfstats.numPerfCalls++;
5455 FillPerfValues(&afs_perfstats);
5458 * Don't overwrite the spares at the end.
5461 dataBytes = sizeof(struct afs_PerfStats);
5462 dataBuffP = malloc(dataBytes);
5463 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5464 a_dataP->AFS_CollData_len = dataBytes >> 2;
5465 a_dataP->AFS_CollData_val = dataBuffP;
5468 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5470 * Pass back the full collection of performance-related data.
5471 * We have to stuff the basic, overall numbers in, but the
5472 * detailed numbers are kept in the structure already.
5474 * >>> We are forced to allocate a separate area in which to
5475 * >>> put this stuff in by the RPC stub generator, since it
5476 * >>> will be freed at the tail end of the server stub code.
5479 afs_perfstats.numPerfCalls++;
5480 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5481 FillPerfValues(&afs_FullPerfStats.overall);
5484 * Don't overwrite the spares at the end.
5487 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5488 dataBuffP = malloc(dataBytes);
5489 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5490 a_dataP->AFS_CollData_len = dataBytes >> 2;
5491 a_dataP->AFS_CollData_val = dataBuffP;
5494 case AFS_XSTATSCOLL_CBSTATS:
5495 afs_perfstats.numPerfCalls++;
5497 dataBytes = sizeof(struct cbcounters);
5498 dataBuffP = malloc(dataBytes);
5500 extern struct cbcounters cbstuff;
5501 dataBuffP[0]=cbstuff.DeleteFiles;
5502 dataBuffP[1]=cbstuff.DeleteCallBacks;
5503 dataBuffP[2]=cbstuff.BreakCallBacks;
5504 dataBuffP[3]=cbstuff.AddCallBacks;
5505 dataBuffP[4]=cbstuff.GotSomeSpaces;
5506 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
5507 dataBuffP[6]=cbstuff.nFEs;
5508 dataBuffP[7]=cbstuff.nCBs;
5509 dataBuffP[8]=cbstuff.nblks;
5510 dataBuffP[9]=cbstuff.CBsTimedOut;
5511 dataBuffP[10]=cbstuff.nbreakers;
5512 dataBuffP[11]=cbstuff.GSS1;
5513 dataBuffP[12]=cbstuff.GSS2;
5514 dataBuffP[13]=cbstuff.GSS3;
5515 dataBuffP[14]=cbstuff.GSS4;
5516 dataBuffP[15]=cbstuff.GSS5;
5519 a_dataP->AFS_CollData_len = dataBytes >> 2;
5520 a_dataP->AFS_CollData_val = dataBuffP;
5526 * Illegal collection number.
5528 a_dataP->AFS_CollData_len = 0;
5529 a_dataP->AFS_CollData_val = NULL;
5531 } /*Switch on collection number */
5533 fsstats_FinishOp(&fsstats, code);
5537 } /*SRXAFS_GetXStats */
5541 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5542 struct AFSCBs *CallBackArray)
5544 afs_int32 errorCode = 0;
5546 struct client *client = 0;
5547 struct rx_connection *tcon;
5549 struct fsstats fsstats;
5551 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GIVEUPCALLBACKS);
5555 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5556 FidArray->AFSCBFids_len));
5559 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5561 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5562 goto Bad_GiveUpCallBacks;
5564 if (!FidArray && !CallBackArray) {
5566 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5567 (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
5568 errorCode = GetClient(tcon, &client);
5571 DeleteAllCallBacks_r(client->host, 1);
5576 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5578 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5579 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5580 (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
5582 goto Bad_GiveUpCallBacks;
5585 errorCode = GetClient(tcon, &client);
5587 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5588 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5589 DeleteCallBack(client->host, fid);
5595 Bad_GiveUpCallBacks:
5596 errorCode = CallPostamble(tcon, errorCode, thost);
5598 fsstats_FinishOp(&fsstats, errorCode);
5602 } /*common_GiveUpCallBacks */
5606 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5607 struct AFSCBs * CallBackArray)
5609 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5610 } /*SRXAFS_GiveUpCallBacks */
5613 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
5615 return common_GiveUpCallBacks(acall, 0, 0);
5616 } /*SRXAFS_GiveUpAllCallBacks */
5620 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
5621 struct AFSVolumeInfo * avolinfo)
5623 return (VNOVOL); /* XXX Obsolete routine XXX */
5625 } /*SRXAFS_NGetVolumeInfo */
5629 * Dummy routine. Should never be called (the cache manager should only
5630 * invoke this interface when communicating with a AFS/DFS Protocol
5634 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
5635 char *afs_name_p, struct AFSFid * afs_fid_p,
5636 struct AFSFetchStatus * afs_status_p,
5637 struct AFSFetchStatus * afs_dir_status_p,
5638 struct AFSCallBack * afs_callback_p,
5639 struct AFSVolSync * afs_sync_p)
5646 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
5649 struct rx_connection *tcon;
5651 afs_uint32 *dataBuffP;
5652 afs_int32 dataBytes;
5655 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
5656 afs_FullPerfStats.overall.fs_nGetCaps++;
5658 ViceLog(2, ("SAFS_GetCapabilties\n"));
5660 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
5663 dataBytes = 1 * sizeof(afs_int32);
5664 dataBuffP = malloc(dataBytes);
5665 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
5666 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
5668 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
5670 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
5671 capabilities->Capabilities_val = dataBuffP;
5674 code = CallPostamble(tcon, code, thost);
5680 /* client is held, but not locked */
5682 FlushClientCPS(struct client *client, void *arock)
5684 ObtainWriteLock(&client->lock);
5686 client->prfail = 2; /* Means re-eval client's cps */
5688 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
5689 free(client->CPS.prlist_val);
5690 client->CPS.prlist_val = NULL;
5691 client->CPS.prlist_len = 0;
5694 ReleaseWriteLock(&client->lock);
5700 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
5701 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
5705 afs_int32 nids, naddrs;
5706 afs_int32 *vd, *addr;
5707 Error errorCode = 0; /* return code to caller */
5709 ViceLog(1, ("SRXAFS_FlushCPS\n"));
5711 AFSCallStats.TotalCalls++;
5714 if (!viced_SuperUser(acall)) {
5719 nids = vids->ViceIds_len; /* # of users in here */
5720 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
5721 if (nids < 0 || naddrs < 0) {
5726 vd = vids->ViceIds_val;
5727 for (i = 0; i < nids; i++, vd++) {
5730 h_EnumerateClients(*vd, FlushClientCPS, NULL);
5733 addr = addrs->IPAddrs_val;
5734 for (i = 0; i < naddrs; i++, addr++) {
5736 h_flushhostcps(*addr, htons(7001));
5740 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
5742 } /*SRXAFS_FlushCPS */
5744 /* worthless hack to let CS keep running ancient software */
5746 afs_vtoi(char *aname)
5752 while ((tc = *aname++)) {
5753 if (tc > '9' || tc < '0')
5754 return 0; /* invalid name */
5762 * may get name or #, but must handle all weird cases (recognize readonly
5763 * or backup volumes by name or #
5766 CopyVolumeEntry(char *aname, struct vldbentry *ave,
5767 struct VolumeInfo *av)
5770 afs_int32 mask, whichType;
5771 afs_uint32 *serverHost, *typePtr;
5773 /* figure out what type we want if by name */
5775 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
5776 whichType = BACKVOL;
5777 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
5782 vol = afs_vtoi(aname);
5784 vol = ave->volumeId[whichType];
5787 * Now vol has volume # we're interested in. Next, figure out the type
5788 * of the volume by looking finding it in the vldb entry
5790 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
5793 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
5796 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
5797 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
5798 whichType = BACKVOL;
5800 return EINVAL; /* error: can't find volume in vldb entry */
5802 typePtr = &av->Type0;
5803 serverHost = &av->Server0;
5805 av->Type = whichType;
5806 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
5807 if (ave->flags & VLF_RWEXISTS)
5808 typePtr[RWVOL] = ave->volumeId[RWVOL];
5809 if (ave->flags & VLF_ROEXISTS)
5810 typePtr[ROVOL] = ave->volumeId[ROVOL];
5811 if (ave->flags & VLF_BACKEXISTS)
5812 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
5814 for (i = 0, j = 0; i < ave->nServers; i++) {
5815 if ((ave->serverFlags[i] & mask) == 0)
5816 continue; /* wrong volume */
5817 serverHost[j] = ave->serverNumber[i];
5820 av->ServerCount = j;
5822 serverHost[j++] = 0; /* bogus 8, but compat only now */
5827 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
5829 static struct rx_connection *vlConn = 0;
5830 static int down = 0;
5831 static afs_int32 lastDownTime = 0;
5832 struct vldbentry tve;
5833 struct rx_securityClass *vlSec;
5837 vlSec = rxnull_NewClientSecurityObject();
5839 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
5840 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
5842 if (down && (time(NULL) < lastDownTime + 180)) {
5843 return 1; /* failure */
5846 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
5848 down = 0; /* call worked */
5851 lastDownTime = time(NULL); /* last time we tried an RPC */
5857 /* otherwise convert to old format vldb entry */
5858 code = CopyVolumeEntry(avolid, &tve, avolinfo);
5868 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
5869 struct VolumeInfo * avolinfo)
5872 struct rx_connection *tcon;
5874 struct fsstats fsstats;
5876 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMEINFO);
5878 if ((code = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5879 goto Bad_GetVolumeInfo;
5882 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
5884 code = TryLocalVLServer(avolid, avolinfo);
5886 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
5887 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
5888 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
5889 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
5892 code = CallPostamble(tcon, code, thost);
5894 fsstats_FinishOp(&fsstats, code);
5898 } /*SRXAFS_GetVolumeInfo */
5902 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5903 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
5904 char **OfflineMsg, char **Motd)
5906 Vnode *targetptr = 0; /* vnode of the new file */
5907 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5908 Error errorCode = 0; /* error code */
5909 Volume *volptr = 0; /* pointer to the volume header */
5910 struct client *client = 0; /* pointer to client entry */
5911 afs_int32 rights, anyrights; /* rights for this and any user */
5913 struct rx_connection *tcon;
5915 struct client *t_client = NULL; /* tmp ptr to client data */
5916 struct fsstats fsstats;
5918 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMESTATUS);
5920 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
5921 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5922 goto Bad_GetVolumeStatus;
5925 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
5929 goto Bad_GetVolumeStatus;
5931 dummyFid.Volume = avolid, dummyFid.Vnode =
5932 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5935 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
5936 &parentwhentargetnotdir, &client, READ_LOCK,
5937 &rights, &anyrights)))
5938 goto Bad_GetVolumeStatus;
5940 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
5942 Bad_GetVolumeStatus:
5943 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
5944 (Vnode *) 0, volptr, &client);
5945 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
5946 /* next is to guarantee out strings exist for stub */
5955 if (*OfflineMsg == 0) {
5956 *OfflineMsg = malloc(1);
5959 errorCode = CallPostamble(tcon, errorCode, thost);
5961 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5963 fsstats_FinishOp(&fsstats, errorCode);
5965 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
5966 AUD_ID, t_client ? t_client->ViceId : 0,
5967 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
5970 } /*SRXAFS_GetVolumeStatus */
5974 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5975 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
5976 char *OfflineMsg, char *Motd)
5978 Vnode *targetptr = 0; /* vnode of the new file */
5979 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5980 Error errorCode = 0; /* error code */
5981 Volume *volptr = 0; /* pointer to the volume header */
5982 struct client *client = 0; /* pointer to client entry */
5983 afs_int32 rights, anyrights; /* rights for this and any user */
5985 struct rx_connection *tcon = rx_ConnectionOf(acall);
5987 struct client *t_client = NULL; /* tmp ptr to client data */
5988 struct fsstats fsstats;
5990 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETVOLUMESTATUS);
5992 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
5993 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5994 goto Bad_SetVolumeStatus;
5997 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6001 goto Bad_SetVolumeStatus;
6003 dummyFid.Volume = avolid, dummyFid.Vnode =
6004 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6007 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
6008 &parentwhentargetnotdir, &client, READ_LOCK,
6009 &rights, &anyrights)))
6010 goto Bad_SetVolumeStatus;
6012 if (readonlyServer) {
6013 errorCode = VREADONLY;
6014 goto Bad_SetVolumeStatus;
6016 if (VanillaUser(client)) {
6018 goto Bad_SetVolumeStatus;
6022 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6024 Bad_SetVolumeStatus:
6025 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
6027 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6028 errorCode = CallPostamble(tcon, errorCode, thost);
6030 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6032 fsstats_FinishOp(&fsstats, errorCode);
6034 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6035 AUD_ID, t_client ? t_client->ViceId : 0,
6036 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6038 } /*SRXAFS_SetVolumeStatus */
6040 #define DEFAULTVOLUME "root.afs"
6043 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6049 struct rx_connection *tcon;
6051 Error errorCode = 0;
6053 struct fsstats fsstats;
6055 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETROOTVOLUME);
6057 return FSERR_EOPNOTSUPP;
6060 if (errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost))
6061 goto Bad_GetRootVolume;
6063 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6066 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6068 strcpy(temp, DEFAULTVOLUME);
6070 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6071 lockf(fd, F_LOCK, 0);
6075 len = read(fd, temp, 256);
6076 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6077 lockf(fd, F_ULOCK, 0);
6082 if (temp[len - 1] == '\n')
6086 *VolumeName = temp; /* freed by rx server-side stub */
6089 errorCode = CallPostamble(tcon, errorCode, thost);
6091 fsstats_FinishOp(&fsstats, errorCode);
6096 } /*SRXAFS_GetRootVolume */
6099 /* still works because a struct CBS is the same as a struct AFSOpaque */
6101 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6102 struct AFSOpaque * Token)
6105 struct rx_connection *tcon;
6107 struct fsstats fsstats;
6109 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CHECKTOKEN);
6111 if ((code = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
6112 goto Bad_CheckToken;
6114 code = FSERR_ECONNREFUSED;
6117 code = CallPostamble(tcon, code, thost);
6119 fsstats_FinishOp(&fsstats, code);
6123 } /*SRXAFS_CheckToken */
6126 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6127 afs_uint32 * USeconds)
6130 struct rx_connection *tcon;
6133 struct fsstats fsstats;
6135 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETTIME);
6137 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
6141 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6143 gettimeofday(&tpl, 0);
6144 *Seconds = tpl.tv_sec;
6145 *USeconds = tpl.tv_usec;
6147 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6150 code = CallPostamble(tcon, code, thost);
6152 fsstats_FinishOp(&fsstats, code);
6156 } /*SRXAFS_GetTime */
6163 * Implement a client's data fetch using Rx.
6166 * volptr : Ptr to the given volume's info.
6167 * targetptr : Pointer to the vnode involved.
6168 * Call : Ptr to the Rx call involved.
6169 * Pos : Offset within the file.
6170 * Len : Length in bytes to read; this value is bogus!
6171 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6173 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6178 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6179 struct rx_call * Call, afs_sfsize_t Pos,
6180 afs_sfsize_t Len, afs_int32 Int64Mode,
6181 afs_sfsize_t * a_bytesToFetchP,
6182 afs_sfsize_t * a_bytesFetchedP)
6184 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6189 #else /* HAVE_PIOV */
6190 struct iovec tiov[RX_MAXIOVECS];
6192 #endif /* HAVE_PIOV */
6197 * Initialize the byte count arguments.
6199 (*a_bytesToFetchP) = 0;
6200 (*a_bytesFetchedP) = 0;
6203 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6204 (afs_uintmax_t) Len));
6206 if (!VN_GET_INO(targetptr)) {
6207 afs_int32 zero = htonl(0);
6209 * This is used for newly created files; we simply send 0 bytes
6210 * back to make the cache manager happy...
6213 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6214 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6217 gettimeofday(&StartTime, 0);
6218 ihP = targetptr->handle;
6221 VTakeOffline(volptr);
6222 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6223 afs_printable_VolumeId_lu(volptr->hashid)));
6226 optSize = sendBufSize;
6227 tlen = FDH_SIZE(fdP);
6229 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6232 VTakeOffline(volptr);
6233 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6234 afs_printable_VolumeId_lu(volptr->hashid)));
6237 if (CheckLength(volptr, targetptr, tlen)) {
6239 VTakeOffline(volptr);
6246 if (Pos + Len > tlen) /* get length we should send */
6247 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
6250 afs_int32 high, low;
6251 SplitOffsetOrSize(Len, high, low);
6252 opr_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6255 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6258 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6260 (*a_bytesToFetchP) = Len;
6262 tbuffer = AllocSendBuffer();
6263 #endif /* HAVE_PIOV */
6272 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
6273 if (nBytes != wlen) {
6275 FreeSendBuffer((struct afs_buffer *)tbuffer);
6276 VTakeOffline(volptr);
6277 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6278 afs_printable_VolumeId_lu(volptr->hashid)));
6281 nBytes = rx_Write(Call, tbuffer, wlen);
6282 #else /* HAVE_PIOV */
6283 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6289 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
6290 if (nBytes != wlen) {
6292 VTakeOffline(volptr);
6293 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6294 afs_printable_VolumeId_lu(volptr->hashid)));
6297 nBytes = rx_Writev(Call, tiov, tnio, wlen);
6298 #endif /* HAVE_PIOV */
6301 * Bump the number of bytes actually sent by the number from this
6304 (*a_bytesFetchedP) += nBytes;
6305 if (nBytes != wlen) {
6309 FreeSendBuffer((struct afs_buffer *)tbuffer);
6310 #endif /* HAVE_PIOV */
6311 err = VIsGoingOffline(volptr);
6320 FreeSendBuffer((struct afs_buffer *)tbuffer);
6321 #endif /* HAVE_PIOV */
6323 gettimeofday(&StopTime, 0);
6325 /* Adjust all Fetch Data related stats */
6327 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6328 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6329 AFSCallStats.AccumFetchTime +=
6330 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6331 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6333 afs_fsize_t targLen;
6334 VN_GET_LEN(targLen, targetptr);
6335 AFSCallStats.TotalFetchedBytes += targLen;
6336 AFSCallStats.FetchSize1++;
6337 if (targLen < SIZE2)
6338 AFSCallStats.FetchSize2++;
6339 else if (targLen < SIZE3)
6340 AFSCallStats.FetchSize3++;
6341 else if (targLen < SIZE4)
6342 AFSCallStats.FetchSize4++;
6344 AFSCallStats.FetchSize5++;
6349 } /*FetchData_RXStyle */
6352 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6353 afs_sfsize_t * size)
6355 #ifdef AFS_NAMEI_ENV
6357 lhp = IH_OPEN(V_linkHandle(vp));
6360 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
6364 *size = OS_SIZE(fdP->fd_fd);
6365 return (*size == -1) ? -1 : 0;
6367 struct afs_stat status;
6369 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6373 *lc = GetLinkCount(vp, &status);
6374 *size = status.st_size;
6383 * Implement a client's data store using Rx.
6386 * volptr : Ptr to the given volume's info.
6387 * targetptr : Pointer to the vnode involved.
6388 * Call : Ptr to the Rx call involved.
6389 * Pos : Offset within the file.
6390 * Len : Length in bytes to store; this value is bogus!
6391 * a_bytesToStoreP : Set to the number of bytes to be stored to
6393 * a_bytesStoredP : Set to the actual number of bytes stored to
6397 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6398 struct client * client, struct rx_call * Call,
6399 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6401 afs_sfsize_t * a_bytesToStoreP,
6402 afs_sfsize_t * a_bytesStoredP)
6404 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6405 Error errorCode = 0; /* Returned error code to caller */
6407 char *tbuffer; /* data copying buffer */
6408 #else /* HAVE_PIOV */
6409 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6410 int tnio; /* temp for iovec size */
6411 #endif /* HAVE_PIOV */
6412 afs_sfsize_t tlen; /* temp for xfr length */
6413 Inode tinode; /* inode for I/O */
6414 afs_int32 optSize; /* optimal transfer size */
6415 afs_sfsize_t DataLength = 0; /* size of inode */
6416 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6417 afs_fsize_t NewLength; /* size after this store completes */
6418 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6419 int linkCount = 0; /* link count on inode */
6422 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6426 * Initialize the byte count arguments.
6428 (*a_bytesToStoreP) = 0;
6429 (*a_bytesStoredP) = 0;
6432 * We break the callbacks here so that the following signal will not
6435 BreakCallBack(client->host, Fid, 0);
6437 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6438 /* the inode should have been created in Alloc_NewVnode */
6439 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
6441 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
6442 Fid->Volume, Fid->Vnode, Fid->Unique,
6443 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
6444 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
6445 return ENOENT; /* is this proper error code? */
6447 rx_KeepAliveOff(Call);
6449 * See if the file has several links (from other volumes). If it
6450 * does, then we have to make a copy before changing it to avoid
6451 *changing read-only clones of this dude
6454 ("StoreData_RXStyle : Opening inode %s\n",
6455 PrintInode(stmp, VN_GET_INO(targetptr))));
6456 fdP = IH_OPEN(targetptr->handle);
6459 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
6461 VTakeOffline(volptr);
6462 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6463 afs_printable_VolumeId_lu(volptr->hashid)));
6466 if (CheckLength(volptr, targetptr, DataLength)) {
6468 VTakeOffline(volptr);
6472 if (linkCount != 1) {
6475 ("StoreData_RXStyle : inode %s has more than onelink\n",
6476 PrintInode(stmp, VN_GET_INO(targetptr))));
6477 /* other volumes share this data, better copy it first */
6479 /* Adjust the disk block count by the creation of the new inode.
6480 * We call the special VDiskUsage so we don't adjust the volume's
6481 * quota since we don't want to penalyze the user for afs's internal
6482 * mechanisms (i.e. copy on write overhead.) Also the right size
6483 * of the disk will be recorded...
6486 VN_GET_LEN(size, targetptr);
6487 volptr->partition->flags &= ~PART_DONTUPDATE;
6488 VSetPartitionDiskUsage(volptr->partition);
6489 volptr->partition->flags |= PART_DONTUPDATE;
6490 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6491 volptr->partition->flags &= ~PART_DONTUPDATE;
6495 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6496 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, MAXFSIZE))) {
6497 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6498 volptr->partition->flags &= ~PART_DONTUPDATE;
6501 volptr->partition->flags &= ~PART_DONTUPDATE;
6502 VSetPartitionDiskUsage(volptr->partition);
6503 fdP = IH_OPEN(targetptr->handle);
6506 ("StoreData : Reopen after CopyOnWrite failed\n"));
6510 tinode = VN_GET_INO(targetptr);
6512 if (!VALID_INO(tinode)) {
6513 VTakeOffline(volptr);
6514 ViceLog(0,("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6515 afs_printable_VolumeId_lu(volptr->hashid)));
6519 /* compute new file length */
6520 NewLength = DataLength;
6521 if (FileLength < NewLength)
6522 /* simulate truncate */
6523 NewLength = FileLength;
6524 TruncatedLength = NewLength; /* remember length after possible ftruncate */
6525 if (Pos + Length > NewLength)
6526 NewLength = Pos + Length; /* and write */
6528 /* adjust the disk block count by the difference in the files */
6530 afs_fsize_t targSize;
6531 VN_GET_LEN(targSize, targetptr);
6532 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
6535 AdjustDiskUsage(volptr, adjustSize,
6536 adjustSize - SpareComp(volptr)))) {
6541 /* can signal cache manager to proceed from close now */
6542 /* this bit means that the locks are set and protections are OK */
6543 rx_SetLocalStatus(Call, 1);
6545 optSize = sendBufSize;
6547 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
6548 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
6549 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
6551 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
6552 if (FileLength < DataLength)
6553 FDH_TRUNC(fdP, FileLength);
6554 bytesTransfered = 0;
6556 tbuffer = AllocSendBuffer();
6557 #endif /* HAVE_PIOV */
6558 /* if length == 0, the loop below isn't going to do anything, including
6559 * extend the length of the inode, which it must do, since the file system
6560 * assumes that the inode length == vnode's file length. So, we extend
6561 * the file length manually if need be. Note that if file is bigger than
6562 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
6563 * do what we're going to do below.
6565 if (Length == 0 && Pos > TruncatedLength) {
6566 /* Set the file's length; we've already done an lseek to the right
6569 tlen = 0; /* Just a source of data for the write */
6570 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
6575 errorCode = FDH_TRUNC(fdP, Pos);
6577 /* have some data to copy */
6578 (*a_bytesToStoreP) = Length;
6581 if (bytesTransfered >= Length) {
6585 tlen = Length - bytesTransfered; /* how much more to do */
6587 rlen = optSize; /* bound by buffer size */
6591 errorCode = rx_Read(Call, tbuffer, rlen);
6592 #else /* HAVE_PIOV */
6593 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
6594 #endif /* HAVE_PIOV */
6595 if (errorCode <= 0) {
6599 (*a_bytesStoredP) += errorCode;
6602 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
6603 #else /* HAVE_PIOV */
6604 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
6605 #endif /* HAVE_PIOV */
6606 if (nBytes != rlen) {
6607 errorCode = VDISKFULL;
6610 bytesTransfered += rlen;
6616 FreeSendBuffer((struct afs_buffer *)tbuffer);
6617 #endif /* HAVE_PIOV */
6619 (void) FDH_SYNC(fdP);
6622 Error tmp_errorCode = 0;
6623 afs_sfsize_t nfSize = FDH_SIZE(fdP);
6624 opr_Assert(nfSize >= 0);
6625 /* something went wrong: adjust size and return */
6626 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
6627 /* changed_newTime is tested in StoreData to detemine if we
6628 * need to update the target vnode.
6630 targetptr->changed_newTime = 1;
6632 /* set disk usage to be correct */
6633 VAdjustDiskUsage(&tmp_errorCode, volptr,
6634 (afs_sfsize_t) (nBlocks(nfSize) -
6635 nBlocks(NewLength)), 0);
6636 if (tmp_errorCode) {
6637 errorCode = tmp_errorCode;
6643 VN_SET_LEN(targetptr, NewLength);
6645 /* Update all StoreData related stats */
6647 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
6648 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
6649 AFSCallStats.StoreSize1++; /* Piggybacked data */
6651 afs_fsize_t targLen;
6652 VN_GET_LEN(targLen, targetptr);
6653 if (targLen < SIZE2)
6654 AFSCallStats.StoreSize2++;
6655 else if (targLen < SIZE3)
6656 AFSCallStats.StoreSize3++;
6657 else if (targLen < SIZE4)
6658 AFSCallStats.StoreSize4++;
6660 AFSCallStats.StoreSize5++;
6665 } /*StoreData_RXStyle */
6667 static int sys2et[512];
6670 init_sys_error_to_et(void)
6672 memset(&sys2et, 0, sizeof(sys2et));
6673 sys2et[EPERM] = UAEPERM;
6674 sys2et[ENOENT] = UAENOENT;
6675 sys2et[ESRCH] = UAESRCH;
6676 sys2et[EINTR] = UAEINTR;
6677 sys2et[EIO] = UAEIO;
6678 sys2et[ENXIO] = UAENXIO;
6679 sys2et[E2BIG] = UAE2BIG;
6680 sys2et[ENOEXEC] = UAENOEXEC;
6681 sys2et[EBADF] = UAEBADF;
6682 sys2et[ECHILD] = UAECHILD;
6683 sys2et[EAGAIN] = UAEAGAIN;
6684 sys2et[ENOMEM] = UAENOMEM;
6685 sys2et[EACCES] = UAEACCES;
6686 sys2et[EFAULT] = UAEFAULT;
6687 sys2et[ENOTBLK] = UAENOTBLK;
6688 sys2et[EBUSY] = UAEBUSY;
6689 sys2et[EEXIST] = UAEEXIST;
6690 sys2et[EXDEV] = UAEXDEV;
6691 sys2et[ENODEV] = UAENODEV;
6692 sys2et[ENOTDIR] = UAENOTDIR;
6693 sys2et[EISDIR] = UAEISDIR;
6694 sys2et[EINVAL] = UAEINVAL;
6695 sys2et[ENFILE] = UAENFILE;
6696 sys2et[EMFILE] = UAEMFILE;
6697 sys2et[ENOTTY] = UAENOTTY;
6698 sys2et[ETXTBSY] = UAETXTBSY;
6699 sys2et[EFBIG] = UAEFBIG;
6700 sys2et[ENOSPC] = UAENOSPC;
6701 sys2et[ESPIPE] = UAESPIPE;
6702 sys2et[EROFS] = UAEROFS;
6703 sys2et[EMLINK] = UAEMLINK;
6704 sys2et[EPIPE] = UAEPIPE;
6705 sys2et[EDOM] = UAEDOM;
6706 sys2et[ERANGE] = UAERANGE;
6707 sys2et[EDEADLK] = UAEDEADLK;
6708 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
6709 sys2et[ENOLCK] = UAENOLCK;
6710 sys2et[ENOSYS] = UAENOSYS;
6711 #if (ENOTEMPTY != EEXIST)
6712 sys2et[ENOTEMPTY] = UAENOTEMPTY;
6714 sys2et[ELOOP] = UAELOOP;
6715 #if (EWOULDBLOCK != EAGAIN)
6716 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
6718 sys2et[ENOMSG] = UAENOMSG;
6719 sys2et[EIDRM] = UAEIDRM;
6720 sys2et[ECHRNG] = UAECHRNG;
6721 sys2et[EL2NSYNC] = UAEL2NSYNC;
6722 sys2et[EL3HLT] = UAEL3HLT;
6723 sys2et[EL3RST] = UAEL3RST;
6724 sys2et[ELNRNG] = UAELNRNG;
6725 sys2et[EUNATCH] = UAEUNATCH;
6726 sys2et[ENOCSI] = UAENOCSI;
6727 sys2et[EL2HLT] = UAEL2HLT;
6728 sys2et[EBADE] = UAEBADE;
6729 sys2et[EBADR] = UAEBADR;
6730 sys2et[EXFULL] = UAEXFULL;
6731 sys2et[ENOANO] = UAENOANO;
6732 sys2et[EBADRQC] = UAEBADRQC;
6733 sys2et[EBADSLT] = UAEBADSLT;
6734 sys2et[EDEADLK] = UAEDEADLK;
6735 sys2et[EBFONT] = UAEBFONT;
6736 sys2et[ENOSTR] = UAENOSTR;
6737 sys2et[ENODATA] = UAENODATA;
6738 sys2et[ETIME] = UAETIME;
6739 sys2et[ENOSR] = UAENOSR;
6740 sys2et[ENONET] = UAENONET;
6741 sys2et[ENOPKG] = UAENOPKG;
6742 sys2et[EREMOTE] = UAEREMOTE;
6743 sys2et[ENOLINK] = UAENOLINK;
6744 sys2et[EADV] = UAEADV;
6745 sys2et[ESRMNT] = UAESRMNT;
6746 sys2et[ECOMM] = UAECOMM;
6747 sys2et[EPROTO] = UAEPROTO;
6748 sys2et[EMULTIHOP] = UAEMULTIHOP;
6749 sys2et[EDOTDOT] = UAEDOTDOT;
6750 sys2et[EBADMSG] = UAEBADMSG;
6751 sys2et[EOVERFLOW] = UAEOVERFLOW;
6752 sys2et[ENOTUNIQ] = UAENOTUNIQ;
6753 sys2et[EBADFD] = UAEBADFD;
6754 sys2et[EREMCHG] = UAEREMCHG;
6755 sys2et[ELIBACC] = UAELIBACC;
6756 sys2et[ELIBBAD] = UAELIBBAD;
6757 sys2et[ELIBSCN] = UAELIBSCN;
6758 sys2et[ELIBMAX] = UAELIBMAX;
6759 sys2et[ELIBEXEC] = UAELIBEXEC;
6760 sys2et[EILSEQ] = UAEILSEQ;
6761 sys2et[ERESTART] = UAERESTART;
6762 sys2et[ESTRPIPE] = UAESTRPIPE;
6763 sys2et[EUSERS] = UAEUSERS;
6764 sys2et[ENOTSOCK] = UAENOTSOCK;
6765 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
6766 sys2et[EMSGSIZE] = UAEMSGSIZE;
6767 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
6768 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
6769 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
6770 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
6771 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
6772 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
6773 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
6774 sys2et[EADDRINUSE] = UAEADDRINUSE;
6775 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
6776 sys2et[ENETDOWN] = UAENETDOWN;
6777 sys2et[ENETUNREACH] = UAENETUNREACH;
6778 sys2et[ENETRESET] = UAENETRESET;
6779 sys2et[ECONNABORTED] = UAECONNABORTED;
6780 sys2et[ECONNRESET] = UAECONNRESET;
6781 sys2et[ENOBUFS] = UAENOBUFS;
6782 sys2et[EISCONN] = UAEISCONN;
6783 sys2et[ENOTCONN] = UAENOTCONN;
6784 sys2et[ESHUTDOWN] = UAESHUTDOWN;
6785 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
6786 sys2et[ETIMEDOUT] = UAETIMEDOUT;
6787 sys2et[ECONNREFUSED] = UAECONNREFUSED;
6788 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
6789 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
6790 sys2et[EALREADY] = UAEALREADY;
6791 sys2et[EINPROGRESS] = UAEINPROGRESS;
6792 sys2et[ESTALE] = UAESTALE;
6793 sys2et[EUCLEAN] = UAEUCLEAN;
6794 sys2et[ENOTNAM] = UAENOTNAM;
6795 sys2et[ENAVAIL] = UAENAVAIL;
6796 sys2et[EISNAM] = UAEISNAM;
6797 sys2et[EREMOTEIO] = UAEREMOTEIO;
6798 sys2et[EDQUOT] = UAEDQUOT;
6799 sys2et[ENOMEDIUM] = UAENOMEDIUM;
6800 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
6802 sys2et[EIO] = UAEIO;
6806 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
6807 * - pass back the connection, client, and host from CallPreamble
6808 * - keep a ref on the client, which we don't now
6809 * - keep a hold on the host, which we already do
6810 * - pass the connection, client, and host down into SAFSS_*, and use
6811 * them instead of independently discovering them via rx_ConnectionOf
6812 * (safe) and rx_GetSpecific (not so safe)
6813 * The idea being that we decide what client and host we're going to use
6814 * when CallPreamble is called, and stay consistent throughout the call.
6815 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
6819 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
6821 Error errorCode = 0;
6822 struct rx_connection *tcon;
6823 struct host *tcallhost;
6824 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6826 struct client *tclient;
6827 static struct rx_securityClass *sc = 0;
6829 struct rx_connection *conn;
6830 afs_int32 viceid = -1;
6833 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &tcallhost)))
6834 goto Bad_CallBackRxConnAddr1;
6836 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6840 tclient = h_FindClient_r(tcon, &viceid);
6843 LogClientError("Client host too busy (CallBackRxConnAddr)", tcon, viceid, NULL);
6844 goto Bad_CallBackRxConnAddr;
6846 thost = tclient->host;
6848 /* nothing more can be done */
6849 if ( !thost->interface )
6850 goto Bad_CallBackRxConnAddr;
6852 /* the only address is the primary interface */
6853 /* can't change when there's only 1 address, anyway */
6854 if ( thost->interface->numberOfInterfaces <= 1 )
6855 goto Bad_CallBackRxConnAddr;
6857 /* initialise a security object only once */
6859 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
6861 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
6863 if ( *addr == thost->interface->addr[i] ) {
6868 if ( *addr != thost->interface->addr[i] )
6869 goto Bad_CallBackRxConnAddr;
6871 conn = rx_NewConnection (thost->interface->addr[i],
6872 thost->port, 1, sc, 0);
6873 rx_SetConnDeadTime(conn, 2);
6874 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
6876 errorCode = RXAFSCB_Probe(conn);
6879 if ( thost->callback_rxcon )
6880 rx_DestroyConnection(thost->callback_rxcon);
6881 thost->callback_rxcon = conn;
6883 rx_SetConnDeadTime(thost->callback_rxcon, 50);
6884 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
6885 h_ReleaseClient_r(tclient);
6886 /* The hold on thost will be released by CallPostamble */
6888 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6891 rx_DestroyConnection(conn);
6893 Bad_CallBackRxConnAddr:
6894 h_ReleaseClient_r(tclient);
6895 /* The hold on thost will be released by CallPostamble */
6899 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6900 Bad_CallBackRxConnAddr1:
6901 return errorCode; /* failure */
6905 sys_error_to_et(afs_int32 in)
6909 if (in < 0 || in > 511)
6911 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
6913 if (sys2et[in] != 0)