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("Client host too busy", *tconn, viceid, Fid);
378 thost = tclient->host;
379 if (tclient->prfail == 1) { /* couldn't get the CPS */
381 h_ReleaseClient_r(tclient);
384 LogClientError("Cannot get CPS for client", *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("Cannot 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