2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * GetVolumePackage disables Rx keepalives; PutVolumePackage re-enables.
24 * If callbacks are to be broken, keepalives should be enabled in the
25 * stub while that occurs; disabled while disk I/O is in process.
29 * in Check_PermissionRights, certain privileges are afforded to the owner
30 * of the volume, or the owner of a file. Are these considered "use of
34 #include <afsconfig.h>
35 #include <afs/param.h>
41 #undef SHARED /* XXX */
48 #ifdef HAVE_NETINET_IF_ETHER_H
49 #include <netinet/if_ether.h>
52 #if !defined(AFS_SGI_ENV) && defined(HAVE_SYS_MAP_H)
56 #ifdef HAVE_SYS_STATFS_H
57 #include <sys/statfs.h>
60 #ifdef HAVE_SYS_LOCKF_H
61 #include <sys/lockf.h>
69 /* included early because of name conflict on IOPEN */
70 #include <sys/inode.h>
74 #endif /* AFS_HPUX_ENV */
80 #include <afs/afsint.h>
81 #include <afs/vldbint.h>
82 #include <afs/errors.h>
83 #include <afs/ihandle.h>
84 #include <afs/vnode.h>
85 #include <afs/volume.h>
86 #include <afs/ptclient.h>
87 #include <afs/ptuser.h>
88 #include <afs/prs_fs.h>
91 #include <rx/rx_globals.h>
93 #include <afs/cellconfig.h>
96 #include <afs/partition.h>
97 #include "viced_prototypes.h"
100 #include "callback.h"
101 #include <afs/unified_afs.h>
102 #include <afs/audit.h>
103 #include <afs/afsutil.h>
106 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
107 extern void FidZap(DirHandle * file);
108 extern void FidZero(DirHandle * file);
110 pthread_mutex_t fileproc_glock_mutex;
112 /* Useful local defines used by this module */
115 #define MustNOTBeDIR 1
119 #define TVS_SSTATUS 2
122 #define TVS_MKDIR 0x10
124 #define CHK_FETCH 0x10
125 #define CHK_FETCHDATA 0x10
126 #define CHK_FETCHACL 0x11
127 #define CHK_FETCHSTATUS 0x12
128 #define CHK_STOREDATA 0x00
129 #define CHK_STOREACL 0x01
130 #define CHK_STORESTATUS 0x02
132 #define OWNERREAD 0400
133 #define OWNERWRITE 0200
134 #define OWNEREXEC 0100
135 #ifdef USE_GROUP_PERMS
136 #define GROUPREAD 0040
137 #define GROUPWRITE 0020
138 #define GROUPREXEC 0010
141 /* The following errors were not defined in NT. They are given unique
142 * names here to avoid any potential collision.
144 #define FSERR_ELOOP 90
145 #define FSERR_EOPNOTSUPP 122
146 #define FSERR_ECONNREFUSED 130
148 #define NOTACTIVECALL 0
151 #define CREATE_SGUID_ADMIN_ONLY 1
153 extern struct afsconf_dir *confDir;
154 extern afs_int32 dataVersionHigh;
157 static struct AFSCallStatistics AFSCallStats;
158 struct fs_stats_FullPerfStats afs_FullPerfStats;
159 extern int AnonymousID;
160 static const char nullString[] = "";
163 afs_int32 NothingYet;
166 struct afs_FSStats afs_fsstats;
171 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
173 extern afs_int32 implicitAdminRights;
174 extern afs_int32 readonlyServer;
175 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
176 extern afs_fsize_t CopyOnWrite_maxsize;
179 * Externals used by the xstat code.
181 extern VolPkgStats VStats;
182 extern int CEs, CEBlocks;
184 extern int HTs, HTBlocks;
186 static afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
187 struct rx_call *Call, afs_sfsize_t Pos,
188 afs_sfsize_t Len, afs_int32 Int64Mode,
189 afs_sfsize_t * a_bytesToFetchP,
190 afs_sfsize_t * a_bytesFetchedP);
192 static afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
193 struct AFSFid *Fid, struct client *client,
194 struct rx_call *Call, afs_fsize_t Pos,
195 afs_fsize_t Length, afs_fsize_t FileLength,
197 afs_sfsize_t * a_bytesToStoreP,
198 afs_sfsize_t * a_bytesStoredP);
200 #ifdef AFS_SGI_XFS_IOPS_ENV
201 #include <afs/xfsattrs.h>
203 GetLinkCount(Volume * avp, struct stat *astat)
205 if (!strcmp("xfs", astat->st_fstype)) {
206 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
208 return astat->st_nlink;
211 #define GetLinkCount(V, S) (S)->st_nlink
215 SpareComp(Volume * avolp)
221 temp = V_maxquota(avolp);
223 /* no matter; doesn't check in this case */
227 temp = (temp * PctSpare) / 100;
238 * Set the volume synchronization parameter for this volume. If it changes,
239 * the Cache Manager knows that the volume must be purged from the stat cache.
242 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
245 /* date volume instance was created */
248 async->spare1 = avol->header->diskstuff.creationDate;
261 * Verify that the on-disk size for a vnode matches the length in the vnode
264 * @param[in] vp Volume pointer
265 * @param[in] vnp Vnode pointer
266 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
267 * and CheckLength itself will determine the on-disk size.
269 * @return operation status
270 * @retval 0 lengths match
271 * @retval nonzero Error; either the lengths do not match or there was an
272 * error determining the on-disk size. The volume should be
273 * taken offline and salvaged.
276 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
279 VN_GET_LEN(vlen, vnp);
284 fdP = IH_OPEN(vnp->handle);
286 ViceLog(0, ("CheckLength: cannot open inode for fid %lu.%lu.%lu\n",
287 afs_printable_uint32_lu(vp->hashid),
288 afs_printable_uint32_lu(Vn_id(vnp)),
289 afs_printable_uint32_lu(vnp->disk.uniquifier)));
292 alen = FDH_SIZE(fdP);
295 afs_int64 alen64 = alen;
296 ViceLog(0, ("CheckLength: cannot get size for inode for fid "
297 "%lu.%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
298 afs_printable_uint32_lu(vp->hashid),
299 afs_printable_uint32_lu(Vn_id(vnp)),
300 afs_printable_uint32_lu(vnp->disk.uniquifier),
307 afs_int64 alen64 = alen, vlen64 = vlen;
308 ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index "
309 "%lld inode %lld ); volume must be salvaged\n",
310 afs_printable_uint32_lu(vp->hashid),
311 afs_printable_uint32_lu(Vn_id(vnp)),
312 afs_printable_uint32_lu(vnp->disk.uniquifier),
320 * Note that this function always returns a held host, so
321 * that CallPostamble can block without the host's disappearing.
322 * Call returns rx connection in passed in *tconn
325 CallPreamble(struct rx_call *acall, int activecall,
326 struct rx_connection **tconn, struct host **ahostp)
329 struct client *tclient;
332 char hoststr[16], hoststr2[16];
333 struct ubik_client *uclient;
337 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
340 *tconn = rx_ConnectionOf(acall);
344 tclient = h_FindClient_r(*tconn);
346 ViceLog(0, ("CallPreamble: Couldn't get client.\n"));
350 thost = tclient->host;
351 if (tclient->prfail == 1) { /* couldn't get the CPS */
353 h_ReleaseClient_r(tclient);
355 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
359 retry_flag = 0; /* Retry once */
361 /* Take down the old connection and re-read the key file */
363 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
364 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
366 /* Is it still necessary to drop this? We hit the net, we should... */
372 code = hpr_Initialize(&uclient);
375 opr_Verify(pthread_setspecific(viced_uclient_key,
376 (void *)uclient) == 0);
380 h_ReleaseClient_r(tclient);
383 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
387 tclient->prfail = 2; /* Means re-eval client's cps */
388 h_ReleaseClient_r(tclient);
393 tclient->LastCall = thost->LastCall = time(NULL);
394 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
395 thost->ActiveCall = thost->LastCall;
398 if (thost->hostFlags & HOSTDELETED) {
400 ("Discarded a packet for deleted host %s:%d\n",
401 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
402 code = VBUSY; /* raced, so retry */
403 } else if ((thost->hostFlags & VENUSDOWN)
404 || (thost->hostFlags & HFE_LATER)) {
405 if (BreakDelayedCallBacks_r(thost)) {
407 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
408 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
409 ntohs(rxr_PortOf(*tconn))));
410 if (MultiProbeAlternateAddress_r(thost)) {
412 ("MultiProbe failed to find new address for host %s:%d\n",
413 afs_inet_ntoa_r(thost->host, hoststr),
414 ntohs(thost->port)));
418 ("MultiProbe found new address for host %s:%d\n",
419 afs_inet_ntoa_r(thost->host, hoststr),
420 ntohs(thost->port)));
421 if (BreakDelayedCallBacks_r(thost)) {
423 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
424 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
425 ntohs(rxr_PortOf(*tconn))));
434 h_ReleaseClient_r(tclient);
444 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
448 struct client *tclient;
452 tclient = h_FindClient_r(aconn);
455 thost = tclient->host;
456 if (thost->hostFlags & HERRORTRANS)
458 h_ReleaseClient_r(tclient);
461 if (ahost != thost) {
462 /* host/client recycle */
463 char hoststr[16], hoststr2[16];
464 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
466 afs_inet_ntoa_r(ahost->host, hoststr),
469 afs_inet_ntoa_r(thost->host, hoststr2),
473 /* return the reference taken in CallPreamble */
477 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
478 afs_inet_ntoa_r(thost->host, hoststr),
483 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
484 * does not decrement refcount on client->host */
489 return (translate ? sys_error_to_et(ret) : ret);
493 * Returns the volume and vnode pointers associated with file Fid; the lock
494 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
495 * are incremented and they must be eventualy released.
498 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
499 Vnode ** vptr, int lock)
502 Error local_errorCode, errorCode = -1;
503 static struct timeval restartedat = { 0, 0 };
505 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
507 if ((*volptr) == 0) {
512 #ifdef AFS_DEMAND_ATTACH_FS
518 static const struct timespec timeout_ts = { 0, 0 };
519 static const struct timespec * const ts = &timeout_ts;
522 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
523 fid->Volume, ts, cbv);
528 if ((errorCode == VOFFLINE) && (VInit < 2)) {
529 /* The volume we want may not be attached yet because
530 * the volume initialization is not yet complete.
531 * We can do several things:
532 * 1. return -1, which will cause users to see
533 * "connection timed out". This is more or
534 * less the same as always, except that the servers
535 * may appear to bounce up and down while they
536 * are actually restarting.
537 * 2. return VBUSY which will cause clients to
538 * sleep and retry for 6.5 - 15 minutes, depending
539 * on what version of the CM they are running. If
540 * the file server takes longer than that interval
541 * to attach the desired volume, then the application
542 * will see an ENODEV or EIO. This approach has
543 * the advantage that volumes which have been attached
544 * are immediately available, it keeps the server's
545 * immediate backlog low, and the call is interruptible
546 * by the user. Users see "waiting for busy volume."
547 * 3. sleep here and retry. Some people like this approach
548 * because there is no danger of seeing errors. However,
549 * this approach only works with a bounded number of
550 * clients, since the pending queues will grow without
551 * stopping. It might be better to find a way to take
552 * this call and stick it back on a queue in order to
553 * recycle this thread for a different request.
554 * 4. Return a new error code, which new cache managers will
555 * know enough to interpret as "sleep and retry", without
556 * the upper bound of 6-15 minutes that is imposed by the
557 * VBUSY handling. Users will see "waiting for
558 * busy volume," so they know that something is
559 * happening. Old cache managers must be able to do
560 * something reasonable with this, for instance, mark the
561 * server down. Fortunately, any error code < 0
562 * will elicit that behavior. See #1.
563 * 5. Some combination of the above. I like doing #2 for 10
564 * minutes, followed by #4. 3.1b and 3.2 cache managers
565 * will be fine as long as the restart period is
566 * not longer than 6.5 minutes, otherwise they may
567 * return ENODEV to users. 3.3 cache managers will be
568 * fine for 10 minutes, then will return
569 * ETIMEDOUT. 3.4 cache managers will just wait
570 * until the call works or fails definitively.
571 * NB. The problem with 2,3,4,5 is that old clients won't
572 * fail over to an alternate read-only replica while this
573 * server is restarting. 3.4 clients will fail over right away.
575 if (restartedat.tv_sec == 0) {
576 /* I'm not really worried about when we restarted, I'm */
577 /* just worried about when the first VBUSY was returned. */
578 gettimeofday(&restartedat, 0);
581 afs_perfstats.fs_nBusies++;
584 return (busyonrst ? VBUSY : restarting);
587 gettimeofday(&now, 0);
588 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
591 afs_perfstats.fs_nBusies++;
594 return (busyonrst ? VBUSY : restarting);
600 /* allow read operations on busy volume.
601 * must check local_errorCode because demand attach fs
602 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
603 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
604 #ifdef AFS_DEMAND_ATTACH_FS
605 /* DAFS case is complicated by the fact that local_errorCode can
606 * be VBUSY in cases where the volume is truly offline */
608 /* volume is in VOL_STATE_UNATTACHED */
611 #endif /* AFS_DEMAND_ATTACH_FS */
614 } else if (errorCode)
621 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
624 if ((*vptr)->disk.uniquifier != fid->Unique) {
625 VPutVnode(&fileCode, *vptr);
626 opr_Assert(fileCode == 0);
628 return (VNOVNODE); /* return the right error code, at least */
633 static_inline afs_int32
634 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
636 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
640 * This routine returns the ACL associated with the targetptr. If the
641 * targetptr isn't a directory, we access its parent dir and get the ACL
642 * thru the parent; in such case the parent's vnode is returned in
646 SetAccessList(Vnode ** targetptr, Volume ** volume,
647 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
648 AFSFid * Fid, int Lock)
650 if ((*targetptr)->disk.type == vDirectory) {
652 *ACL = VVnodeACL(*targetptr);
653 *ACLSize = VAclSize(*targetptr);
656 opr_Assert(Fid != 0);
661 parentvnode = (*targetptr)->disk.parent;
662 VPutVnode(&errorCode, *targetptr);
666 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
669 *ACL = VVnodeACL(*parent);
670 *ACLSize = VAclSize(*parent);
671 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
673 if ((*targetptr)->disk.parent != parentvnode) {
674 VPutVnode(&errorCode, *parent);
685 /* Must not be called with H_LOCK held */
687 client_CheckRights(struct client *client, struct acl_accessList *ACL,
691 ObtainReadLock(&client->lock);
692 if (client->CPS.prlist_len > 0 && !client->deleted &&
693 client->host && !(client->host->hostFlags & HOSTDELETED))
694 acl_CheckRights(ACL, &client->CPS, rights);
695 ReleaseReadLock(&client->lock);
698 /* Must not be called with H_LOCK held */
700 client_HasAsMember(struct client *client, afs_int32 id)
704 ObtainReadLock(&client->lock);
705 if (client->CPS.prlist_len > 0 && !client->deleted &&
706 client->host && !(client->host->hostFlags & HOSTDELETED))
707 code = acl_IsAMember(id, &client->CPS);
708 ReleaseReadLock(&client->lock);
713 * Compare the directory's ACL with the user's access rights in the client
714 * connection and return the user's and everybody else's access permissions
715 * in rights and anyrights, respectively
718 GetRights(struct client *client, struct acl_accessList *ACL,
719 afs_int32 * rights, afs_int32 * anyrights)
721 extern prlist SystemAnyUserCPS;
722 afs_int32 hrights = 0;
724 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
725 ViceLog(0, ("CheckRights failed\n"));
730 client_CheckRights(client, ACL, rights);
732 /* wait if somebody else is already doing the getCPS call */
734 while (client->host->hostFlags & HCPS_INPROGRESS) {
735 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
736 CV_WAIT(&client->host->cond, &host_glock_mutex);
739 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
742 ("CheckRights: len=%u, for host=%s:%d\n",
743 client->host->hcps.prlist_len,
744 afs_inet_ntoa_r(client->host->host, hoststr),
745 ntohs(client->host->port)));
747 acl_CheckRights(ACL, &client->host->hcps, &hrights);
749 /* Allow system:admin the rights given with the -implicit option */
750 if (client_HasAsMember(client, SystemId))
751 *rights |= implicitAdminRights;
754 *anyrights |= hrights;
761 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
762 * a System:Administrator)
765 VanillaUser(struct client *client)
767 if (client_HasAsMember(client, SystemId))
768 return (0); /* not a system administrator, then you're "vanilla" */
774 /*------------------------------------------------------------------------
775 * GetVolumePackageWithCall
778 * This unusual afs_int32-parameter routine encapsulates all volume
779 * package related operations together in a single function; it's
780 * called by almost all AFS interface calls.
783 * acall : Ptr to Rx call on which this request came in.
784 * cbv : struct containing the RX call for offline cancels
785 * Fid : the AFS fid the caller is acting on
786 * volptr : returns a pointer to the volume struct
787 * targetptr : returns a pointer to the vnode struct
788 * chkforDir : whether to check for if vnode is a dir
789 * parent : returns a pointer to the parent of this vnode
790 * client : returns a pointer to the calling client
791 * locktype : indicates what kind of lock to take on vnodes
792 * rights : returns a pointer to caller's rights
793 * anyrights : returns a pointer to anonymous' rights
794 * remote : indicates that the volume is a remote RW replica
798 * appropriate error based on permission or invalid operation.
801 * Nothing interesting.
804 * On success, disables keepalives on the call. Caller should re-enable
805 * after completing disk I/O.
806 *------------------------------------------------------------------------*/
808 GetVolumePackageWithCall(struct rx_call *acall, struct VCallByVol *cbv,
809 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
810 int chkforDir, Vnode ** parent,
811 struct client **client, int locktype,
812 afs_int32 * rights, afs_int32 * anyrights, int remote)
814 struct acl_accessList *aCL; /* Internal access List */
815 int aCLSize; /* size of the access list */
816 Error errorCode = 0; /* return code to caller */
817 struct rx_connection *tcon = rx_ConnectionOf(acall);
819 rx_KeepAliveOff(acall);
821 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
825 if (chkforDir == MustNOTBeDIR
826 && ((*targetptr)->disk.type == vDirectory)) {
830 else if (chkforDir == MustBeDIR
831 && ((*targetptr)->disk.type != vDirectory)) {
837 * If the remote flag is set, the current call is dealing with a remote RW
838 * replica, and it can be assumed that the appropriate access checks were
839 * done by the calling server hosting the master volume.
842 if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
843 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
844 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
846 if (chkforDir == MustBeDIR)
847 opr_Assert((*parent) == 0);
849 if ((errorCode = GetClient(tcon, client)) != 0)
856 GetRights(*client, aCL, rights, anyrights);
857 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
858 if ((*targetptr)->disk.type != vDirectory) {
859 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
860 if ((*targetptr)->disk.owner == (*client)->ViceId)
861 (*rights) |= PRSFS_ADMINISTER;
863 (*rights) &= ~PRSFS_ADMINISTER;
865 #ifdef ADMIN_IMPLICIT_LOOKUP
866 /* admins get automatic lookup on everything */
867 if (!VanillaUser(*client))
868 (*rights) |= PRSFS_LOOKUP;
869 #endif /* ADMIN_IMPLICIT_LOOKUP */
873 rx_KeepAliveOn(acall);
876 } /*GetVolumePackage */
878 static_inline afs_int32
879 GetVolumePackage(struct rx_call *acall, AFSFid * Fid, Volume ** volptr,
880 Vnode ** targetptr, int chkforDir, Vnode ** parent,
881 struct client **client, int locktype, afs_int32 * rights,
882 afs_int32 * anyrights)
884 return GetVolumePackageWithCall(acall, NULL, Fid, volptr, targetptr,
885 chkforDir, parent, client, locktype,
886 rights, anyrights, 0);
890 /*------------------------------------------------------------------------
891 * PutVolumePackageWithCall
894 * This is the opposite of GetVolumePackage(), and is always used at
895 * the end of AFS calls to put back all used vnodes and the volume
896 * in the proper order!
899 * acall : Ptr to Rx call on which this request came in.
900 * parentwhentargetnotdir : a pointer to the parent when the target isn't
902 * targetptr : a pointer to the vnode struct
903 * parentptr : a pointer to the parent of this vnode
904 * volptr : a pointer to the volume structure
905 * client : a pointer to the calling client
906 * cbv : struct containing the RX call for offline cancels
912 * Nothing interesting.
915 * Enables keepalives on the call.
916 *------------------------------------------------------------------------*/
918 PutVolumePackageWithCall(struct rx_call *acall, Vnode *
919 parentwhentargetnotdir, Vnode * targetptr,
920 Vnode * parentptr, Volume * volptr,
921 struct client **client, struct VCallByVol *cbv)
923 Error fileCode = 0; /* Error code returned by the volume package */
925 rx_KeepAliveOff(acall);
926 if (parentwhentargetnotdir) {
927 VPutVnode(&fileCode, parentwhentargetnotdir);
928 opr_Assert(!fileCode || (fileCode == VSALVAGE));
931 VPutVnode(&fileCode, targetptr);
932 opr_Assert(!fileCode || (fileCode == VSALVAGE));
935 VPutVnode(&fileCode, parentptr);
936 opr_Assert(!fileCode || (fileCode == VSALVAGE));
939 VPutVolumeWithCall(volptr, cbv);
941 rx_KeepAliveOn(acall);
946 } /*PutVolumePackage */
949 PutVolumePackage(struct rx_call *acall, Vnode * parentwhentargetnotdir,
950 Vnode * targetptr, Vnode * parentptr, Volume * volptr,
951 struct client **client)
953 PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
954 parentptr, volptr, client, NULL);
958 VolumeOwner(struct client *client, Vnode * targetptr)
960 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
963 return (client->ViceId == owner);
966 * We don't have to check for host's cps since only regular
967 * viceid are volume owners.
969 return (client_HasAsMember(client, owner));
975 VolumeRootVnode(Vnode * targetptr)
977 return ((targetptr->vnodeNumber == ROOTVNODE)
978 && (targetptr->disk.uniquifier == 1));
980 } /*VolumeRootVnode */
983 * Check if target file has the proper access permissions for the Fetch
984 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
985 * StoreStatus) related calls
987 /* this code should probably just set a "priv" flag where all the audit events
988 * are now, and only generate the audit event once at the end of the routine,
989 * thus only generating the event if all the checks succeed, but only because
990 * of the privilege XXX
993 Check_PermissionRights(Vnode * targetptr, struct client *client,
994 afs_int32 rights, int CallingRoutine,
995 AFSStoreStatus * InStatus)
998 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
999 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
1000 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
1002 if (CallingRoutine & CHK_FETCH) {
1003 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
1004 if (targetptr->disk.type == vDirectory
1005 || targetptr->disk.type == vSymlink) {
1006 if (!(rights & PRSFS_LOOKUP)
1007 #ifdef ADMIN_IMPLICIT_LOOKUP
1008 /* grant admins fetch on all directories */
1009 && VanillaUser(client)
1010 #endif /* ADMIN_IMPLICIT_LOOKUP */
1011 && !VolumeOwner(client, targetptr))
1014 /* must have read access, or be owner and have insert access */
1015 if (!(rights & PRSFS_READ)
1016 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
1017 && (client->ViceId != AnonymousID))))
1020 if (CallingRoutine == CHK_FETCHDATA
1021 && targetptr->disk.type == vFile)
1022 #ifdef USE_GROUP_PERMS
1023 if (!OWNSp(client, targetptr)
1024 && !client_HasAsMember(client, targetptr->disk.owner)) {
1026 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
1030 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
1035 * The check with the ownership below is a kludge to allow
1036 * reading of files created with no read permission. The owner
1037 * of the file is always allowed to read it.
1039 if ((client->ViceId != targetptr->disk.owner)
1040 && VanillaUser(client))
1042 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
1043 modeBits) ? 0 : EACCES);
1045 } else { /* !VanillaUser(client) && !FetchData */
1047 osi_audit(PrivilegeEvent, 0, AUD_ID,
1048 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
1051 } else { /* a store operation */
1052 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1053 && (CallingRoutine != CHK_STOREACL)
1054 && (targetptr->disk.type == vFile)) {
1055 /* bypass protection checks on first store after a create
1056 * for the creator; also prevent chowns during this time
1057 * unless you are a system administrator */
1058 /****** InStatus->Owner && UnixModeBits better be SET!! */
1059 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1062 else if (VanillaUser(client))
1063 return (EPERM); /* Was EACCES */
1065 osi_audit(PrivilegeEvent, 0, AUD_ID,
1066 (client ? client->ViceId : 0), AUD_INT,
1067 CallingRoutine, AUD_END);
1070 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1071 osi_audit(PrivilegeEvent, 0, AUD_ID,
1072 (client ? client->ViceId : 0), AUD_INT,
1073 CallingRoutine, AUD_END);
1075 if (readonlyServer) {
1078 if (CallingRoutine == CHK_STOREACL) {
1079 if (!(rights & PRSFS_ADMINISTER)
1080 && !VolumeOwner(client, targetptr))
1082 } else { /* store data or status */
1083 /* watch for chowns and chgrps */
1084 if (CHOWN(InStatus, targetptr)
1085 || CHGRP(InStatus, targetptr)) {
1088 else if (VanillaUser(client))
1089 return (EPERM); /* Was EACCES */
1091 osi_audit(PrivilegeEvent, 0, AUD_ID,
1092 (client ? client->ViceId : 0), AUD_INT,
1093 CallingRoutine, AUD_END);
1095 /* must be sysadmin to set suid/sgid bits */
1096 if ((InStatus->Mask & AFS_SETMODE) &&
1098 (InStatus->UnixModeBits & 0xc00) != 0) {
1100 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1104 if (VanillaUser(client))
1107 osi_audit(PrivSetID, 0, AUD_ID,
1108 (client ? client->ViceId : 0), AUD_INT,
1109 CallingRoutine, AUD_END);
1111 if (CallingRoutine == CHK_STOREDATA) {
1114 if (!(rights & PRSFS_WRITE))
1116 /* Next thing is tricky. We want to prevent people
1117 * from writing files sans 0200 bit, but we want
1118 * creating new files with 0444 mode to work. We
1119 * don't check the 0200 bit in the "you are the owner"
1120 * path above, but here we check the bit. However, if
1121 * you're a system administrator, we ignore the 0200
1122 * bit anyway, since you may have fchowned the file,
1124 #ifdef USE_GROUP_PERMS
1125 if ((targetptr->disk.type == vFile)
1126 && VanillaUser(client)) {
1127 if (!OWNSp(client, targetptr)
1128 && !client_HasAsMember(client, targetptr->disk.owner)) {
1130 ((GROUPWRITE & targetptr->disk.modeBits)
1134 ((OWNERWRITE & targetptr->disk.modeBits)
1139 if ((targetptr->disk.type != vDirectory)
1140 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1143 if (VanillaUser(client))
1146 osi_audit(PrivilegeEvent, 0, AUD_ID,
1147 (client ? client->ViceId : 0),
1148 AUD_INT, CallingRoutine, AUD_END);
1150 } else { /* a status store */
1153 if (targetptr->disk.type == vDirectory) {
1154 if (!(rights & PRSFS_DELETE)
1155 && !(rights & PRSFS_INSERT))
1157 } else { /* a file or symlink */
1158 if (!(rights & PRSFS_WRITE))
1168 } /*Check_PermissionRights */
1172 * The Access List information is converted from its internal form in the
1173 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1174 * external form and returned back to the caller, via the AccessList
1178 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1179 struct AFSOpaque *AccessList)
1181 char *eACL; /* External access list placeholder */
1183 if (acl_Externalize_pr
1184 (hpr_IdToName, (targetptr->disk.type ==
1185 vDirectory ? VVnodeACL(targetptr) :
1186 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1189 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1190 acl_FreeExternalACL(&eACL);
1193 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1194 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1196 acl_FreeExternalACL(&eACL);
1199 } /*RXFetch_AccessList */
1203 * The Access List information is converted from its external form in the
1204 * input AccessList structure to the internal representation and copied into
1205 * the target dir's vnode storage.
1208 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1210 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1212 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1215 if ((newACL->size + 4) > VAclSize(targetptr))
1217 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1218 acl_FreeACL(&newACL);
1221 } /*RXStore_AccessList */
1224 /* In our current implementation, each successive data store (new file
1225 * data version) creates a new inode. This function creates the new
1226 * inode, copies the old inode's contents to the new one, remove the old
1227 * inode (i.e. decrement inode count -- if it's currently used the delete
1228 * will be delayed), and modify some fields (i.e. vnode's
1229 * disk.inodeNumber and cloned)
1231 #define COPYBUFFSIZE 8192
1232 #define MAXFSIZE (~(afs_fsize_t) 0)
1234 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1237 Inode nearInode AFS_UNUSED;
1244 int rc; /* return code */
1245 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1246 FdHandle_t *targFdP; /* Source Inode file handle */
1247 FdHandle_t *newFdP; /* Dest Inode file handle */
1249 if (targetptr->disk.type == vDirectory)
1250 DFlush(); /* just in case? */
1252 VN_GET_LEN(size, targetptr);
1260 buff = malloc(COPYBUFFSIZE);
1265 ino = VN_GET_INO(targetptr);
1266 if (!VALID_INO(ino)) {
1268 VTakeOffline(volptr);
1269 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1273 targFdP = IH_OPEN(targetptr->handle);
1274 if (targFdP == NULL) {
1277 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1278 targetptr->vnodeNumber, V_id(volptr), rc));
1280 VTakeOffline(volptr);
1284 nearInode = VN_GET_INO(targetptr);
1286 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1287 VPartitionPath(V_partition(volptr)), nearInode,
1288 V_id(volptr), targetptr->vnodeNumber,
1289 targetptr->disk.uniquifier,
1290 (int)targetptr->disk.dataVersion);
1291 if (!VALID_INO(ino)) {
1293 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1294 volptr->partition->name, V_id(volptr), errno));
1299 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1300 newFdP = IH_OPEN(newH);
1301 opr_Assert(newFdP != NULL);
1305 if (size > COPYBUFFSIZE) { /* more than a buffer */
1306 length = COPYBUFFSIZE;
1307 size -= COPYBUFFSIZE;
1312 rdlen = FDH_PREAD(targFdP, buff, length, done);
1313 if (rdlen == length) {
1314 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1318 /* Callers of this function are not prepared to recover
1319 * from error that put the filesystem in an inconsistent
1320 * state. Make sure that we force the volume off-line if
1321 * we some error other than ENOSPC - 4.29.99)
1323 * In case we are unable to write the required bytes, and the
1324 * error code indicates that the disk is full, we roll-back to
1325 * the initial state.
1327 if ((rdlen != length) || (wrlen != length)) {
1328 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1330 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1331 volptr->partition->name, V_id(volptr)));
1332 /* remove destination inode which was partially copied till now */
1333 FDH_REALLYCLOSE(newFdP);
1335 FDH_REALLYCLOSE(targFdP);
1336 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1339 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1340 rc, V_id(volptr), volptr->partition->name));
1341 VTakeOffline(volptr);
1346 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1347 * since we never do any I/O anywhere near 2^32 bytes at a
1348 * time, just case to an unsigned int for printing */
1351 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1352 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1353 (unsigned)wrlen, errno));
1354 #if defined(AFS_DEMAND_ATTACH_FS)
1355 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1357 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1359 /* Decrement this inode so salvager doesn't find it. */
1360 FDH_REALLYCLOSE(newFdP);
1362 FDH_REALLYCLOSE(targFdP);
1363 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1365 VTakeOffline(volptr);
1370 FDH_REALLYCLOSE(targFdP);
1371 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1372 V_parentId(volptr));
1374 IH_RELEASE(targetptr->handle);
1376 rc = FDH_SYNC(newFdP);
1377 opr_Assert(rc == 0);
1379 targetptr->handle = newH;
1380 VN_SET_INO(targetptr, ino);
1381 targetptr->disk.cloned = 0;
1382 /* Internal change to vnode, no user level change to volume - def 5445 */
1383 targetptr->changed_oldTime = 1;
1385 return 0; /* success */
1389 * Common code to handle with removing the Name (file when it's called from
1390 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1391 * given directory, parentptr.
1393 int DT1 = 0, DT0 = 0;
1395 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1396 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1398 DirHandle childdir; /* Handle for dir package I/O */
1399 Error errorCode = 0;
1403 /* watch for invalid names */
1404 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1407 if (CheckLength(volptr, parentptr, -1)) {
1408 VTakeOffline(volptr);
1412 if (parentptr->disk.cloned) {
1413 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1414 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1416 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1422 /* check that the file is in the directory */
1423 SetDirHandle(dir, parentptr);
1424 if (afs_dir_Lookup(dir, Name, fileFid))
1426 fileFid->Volume = V_id(volptr);
1428 /* just-in-case check for something causing deadlock */
1429 if (fileFid->Vnode == parentptr->vnodeNumber)
1432 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1436 if (ChkForDir == MustBeDIR) {
1437 if ((*targetptr)->disk.type != vDirectory)
1439 } else if ((*targetptr)->disk.type == vDirectory)
1442 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1444 * If the uniquifiers dont match then instead of asserting
1445 * take the volume offline and return VSALVAGE
1447 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1448 VTakeOffline(volptr);
1450 ("Volume %u now offline, must be salvaged.\n",
1452 errorCode = VSALVAGE;
1456 if (ChkForDir == MustBeDIR) {
1457 SetDirHandle(&childdir, *targetptr);
1458 if (afs_dir_IsEmpty(&childdir) != 0)
1462 (*targetptr)->delete = 1;
1463 } else if ((--(*targetptr)->disk.linkCount) == 0)
1464 (*targetptr)->delete = 1;
1465 if ((*targetptr)->delete) {
1466 if (VN_GET_INO(*targetptr)) {
1468 IH_REALLYCLOSE((*targetptr)->handle);
1470 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1471 V_parentId(volptr));
1472 IH_RELEASE((*targetptr)->handle);
1473 if (errorCode == -1) {
1475 ("DT: inode=%s, name=%s, errno=%d\n",
1476 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1478 if (errno != ENOENT)
1480 VTakeOffline(volptr);
1482 ("Volume %u now offline, must be salvaged.\n",
1490 VN_SET_INO(*targetptr, (Inode) 0);
1492 afs_fsize_t adjLength;
1493 VN_GET_LEN(adjLength, *targetptr);
1494 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1498 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1500 code = afs_dir_Delete(dir, Name);
1503 ("Error %d deleting %s\n", code,
1504 (((*targetptr)->disk.type ==
1505 Directory) ? "directory" : "file")));
1506 VTakeOffline(volptr);
1508 ("Volume %u now offline, must be salvaged.\n",
1521 * This routine updates the parent directory's status block after the
1522 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1523 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1527 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1528 int author, int linkcount, char a_inSameNetwork)
1530 afs_fsize_t newlength; /* Holds new directory length */
1531 afs_fsize_t parentLength;
1533 Date currDate; /*Current date */
1534 int writeIdx; /*Write index to bump */
1535 int timeIdx; /*Authorship time index to bump */
1538 parentptr->disk.dataVersion++;
1539 newlength = (afs_fsize_t) afs_dir_Length(dir);
1541 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1542 * (create, symlink, link, makedir) so we need to check if we have enough space
1543 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1544 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1546 VN_GET_LEN(parentLength, parentptr);
1547 if (nBlocks(newlength) != nBlocks(parentLength)) {
1548 VAdjustDiskUsage(&errorCode, volptr,
1549 (nBlocks(newlength) - nBlocks(parentLength)),
1550 (nBlocks(newlength) - nBlocks(parentLength)));
1552 VN_SET_LEN(parentptr, newlength);
1555 * Update directory write stats for this volume. Note that the auth
1556 * counter is located immediately after its associated ``distance''
1559 if (a_inSameNetwork)
1560 writeIdx = VOL_STATS_SAME_NET;
1562 writeIdx = VOL_STATS_DIFF_NET;
1563 V_stat_writes(volptr, writeIdx)++;
1564 if (author != AnonymousID) {
1565 V_stat_writes(volptr, writeIdx + 1)++;
1569 * Update the volume's authorship information in response to this
1570 * directory operation. Get the current time, decide to which time
1571 * slot this operation belongs, and bump the appropriate slot.
1574 currDate = (now - parentptr->disk.unixModifyTime);
1576 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1577 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1578 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1579 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1580 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1581 if (parentptr->disk.author == author) {
1582 V_stat_dirSameAuthor(volptr, timeIdx)++;
1584 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1587 parentptr->disk.author = author;
1588 parentptr->disk.linkCount = linkcount;
1589 parentptr->disk.unixModifyTime = now; /* This should be set from CLIENT!! */
1590 parentptr->disk.serverModifyTime = now;
1591 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1596 * Update the target file's (or dir's) status block after the specified
1597 * operation is complete. Note that some other fields maybe updated by
1598 * the individual module.
1599 * If remote is set, the volume is a RW replica and access checks can
1603 /* XXX INCOMPLETE - More attention is needed here! */
1605 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1606 struct client *client, AFSStoreStatus * InStatus,
1607 Vnode * parentptr, Volume * volptr,
1608 afs_fsize_t length, int remote)
1610 Date currDate; /*Current date */
1611 int writeIdx; /*Write index to bump */
1612 int timeIdx; /*Authorship time index to bump */
1614 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1615 targetptr->disk.parent = parentptr->vnodeNumber;
1616 VN_SET_LEN(targetptr, length);
1617 /* targetptr->disk.group = 0; save some cycles */
1618 targetptr->disk.modeBits = 0777;
1619 targetptr->disk.owner = client->ViceId;
1620 targetptr->disk.dataVersion = 0; /* consistent with the client */
1621 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1622 /* the inode was created in Alloc_NewVnode() */
1625 * Update file write stats for this volume. Note that the auth
1626 * counter is located immediately after its associated ``distance''
1629 if (client->InSameNetwork)
1630 writeIdx = VOL_STATS_SAME_NET;
1632 writeIdx = VOL_STATS_DIFF_NET;
1633 V_stat_writes(volptr, writeIdx)++;
1634 if (client->ViceId != AnonymousID) {
1635 V_stat_writes(volptr, writeIdx + 1)++;
1639 * We only count operations that DON'T involve creating new objects
1640 * (files, symlinks, directories) or simply setting status as
1641 * authorship-change operations.
1643 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1645 * Update the volume's authorship information in response to this
1646 * file operation. Get the current time, decide to which time
1647 * slot this operation belongs, and bump the appropriate slot.
1649 currDate = (time(NULL) - targetptr->disk.unixModifyTime);
1652 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1653 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1654 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1655 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1656 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1657 VOL_STATS_TIME_IDX_5);
1658 if (targetptr->disk.author == client->ViceId) {
1659 V_stat_fileSameAuthor(volptr, timeIdx)++;
1661 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1665 if (!(Caller & TVS_SSTATUS))
1666 targetptr->disk.author = client->ViceId;
1667 if (Caller & TVS_SDATA) {
1668 targetptr->disk.dataVersion++;
1669 if (!remote && VanillaUser(client)) {
1670 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1671 #ifdef CREATE_SGUID_ADMIN_ONLY
1672 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1676 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1677 /* store status, must explicitly request to change the date */
1678 if (InStatus->Mask & AFS_SETMODTIME)
1679 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1680 } else { /* other: date always changes, but perhaps to what is specified by caller */
1681 targetptr->disk.unixModifyTime =
1682 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1683 ClientModTime : time(NULL));
1685 if (InStatus->Mask & AFS_SETOWNER) {
1686 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1687 if (!remote && VanillaUser(client)) {
1688 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1689 #ifdef CREATE_SGUID_ADMIN_ONLY
1690 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1693 targetptr->disk.owner = InStatus->Owner;
1694 if (VolumeRootVnode(targetptr)) {
1695 Error errorCode = 0; /* what should be done with this? */
1697 V_owner(targetptr->volumePtr) = InStatus->Owner;
1698 VUpdateVolume(&errorCode, targetptr->volumePtr);
1701 if (InStatus->Mask & AFS_SETMODE) {
1702 int modebits = InStatus->UnixModeBits;
1703 #define CREATE_SGUID_ADMIN_ONLY 1
1704 #ifdef CREATE_SGUID_ADMIN_ONLY
1705 if (!remote && VanillaUser(client))
1706 modebits = modebits & 0777;
1708 if (!remote && VanillaUser(client)) {
1709 targetptr->disk.modeBits = modebits;
1711 targetptr->disk.modeBits = modebits;
1714 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1715 CHK_STOREDATA, AUD_END);
1719 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1720 CHK_STORESTATUS, AUD_END);
1727 targetptr->disk.serverModifyTime = time(NULL);
1728 if (InStatus->Mask & AFS_SETGROUP)
1729 targetptr->disk.group = InStatus->Group;
1730 /* vnode changed : to be written back by VPutVnode */
1731 targetptr->changed_newTime = 1;
1733 } /*Update_TargetVnodeStatus */
1737 * Fills the CallBack structure with the expiration time and type of callback
1738 * structure. Warning: this function is currently incomplete.
1741 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1743 /* CallBackTime could not be 0 */
1744 if (CallBackTime == 0) {
1745 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1746 CallBack->ExpirationTime = 0;
1748 CallBack->ExpirationTime = CallBackTime - time(NULL);
1749 CallBack->CallBackVersion = CALLBACK_VERSION;
1750 CallBack->CallBackType = CB_SHARED; /* The default for now */
1752 } /*SetCallBackStruct */
1756 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1757 * allocation; if some error occured (exceeded volume quota or partition
1758 * was full, or whatever), it frees the space back and returns the code.
1759 * We usually pre-adjust the volume space to make sure that there's
1760 * enough space before consuming some.
1763 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1764 afs_sfsize_t checkLength)
1769 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1771 VAdjustDiskUsage(&nc, volptr, -length, 0);
1772 if (rc == VOVERQUOTA) {
1774 ("Volume %u (%s) is full\n", V_id(volptr),
1778 if (rc == VDISKFULL) {
1780 ("Partition %s that contains volume %u is full\n",
1781 volptr->partition->name, V_id(volptr)));
1784 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1789 } /*AdjustDiskUsage */
1792 * Common code that handles the creation of a new file (SAFS_CreateFile and
1793 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1796 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1797 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1798 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1800 Error errorCode = 0; /* Error code returned back */
1803 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1807 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1808 BlocksPreallocatedForVnode))) {
1810 ("Insufficient space to allocate %lld blocks\n",
1811 (afs_intmax_t) BlocksPreallocatedForVnode));
1815 if (CheckLength(volptr, parentptr, -1)) {
1816 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1817 VTakeOffline(volptr);
1821 *targetptr = VAllocVnode(&errorCode, volptr, FileType, 0, 0);
1822 if (errorCode != 0) {
1823 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1826 OutFid->Volume = V_id(volptr);
1827 OutFid->Vnode = (*targetptr)->vnodeNumber;
1828 OutFid->Unique = (*targetptr)->disk.uniquifier;
1830 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1832 /* create the inode now itself */
1834 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1835 VPartitionPath(V_partition(volptr)), nearInode,
1836 V_id(volptr), (*targetptr)->vnodeNumber,
1837 (*targetptr)->disk.uniquifier, 1);
1839 /* error in creating inode */
1840 if (!VALID_INO(inode)) {
1842 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1843 (*targetptr)->volumePtr->header->diskstuff.id,
1844 (*targetptr)->vnodeNumber, errno));
1845 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1846 (*targetptr)->delete = 1; /* delete vnode */
1849 VN_SET_INO(*targetptr, inode);
1850 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1852 /* copy group from parent dir */
1853 (*targetptr)->disk.group = parentptr->disk.group;
1855 if (parentptr->disk.cloned) {
1856 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1857 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1858 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1859 /* delete the vnode previously allocated */
1860 (*targetptr)->delete = 1;
1861 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1862 IH_REALLYCLOSE((*targetptr)->handle);
1863 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1865 ("Alloc_NewVnode: partition %s idec %s failed\n",
1866 volptr->partition->name, PrintInode(stmp, inode)));
1867 IH_RELEASE((*targetptr)->handle);
1873 /* add the name to the directory */
1874 SetDirHandle(dir, parentptr);
1875 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1876 (*targetptr)->delete = 1;
1877 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1878 IH_REALLYCLOSE((*targetptr)->handle);
1879 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1881 ("Alloc_NewVnode: partition %s idec %s failed\n",
1882 volptr->partition->name, PrintInode(stmp, inode)));
1883 IH_RELEASE((*targetptr)->handle);
1889 } /*Alloc_NewVnode */
1893 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1897 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1899 int Time; /* Used for time */
1900 int writeVnode = targetptr->changed_oldTime; /* save original status */
1902 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1904 switch (LockingType) {
1907 if (Time > targetptr->disk.lock.lockTime)
1908 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1910 Time += AFS_LOCKWAIT;
1911 if (LockingType == LockRead) {
1912 if ( !(rights & PRSFS_LOCK) &&
1913 !(rights & PRSFS_WRITE) &&
1914 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1917 if (targetptr->disk.lock.lockCount >= 0) {
1918 ++(targetptr->disk.lock.lockCount);
1919 targetptr->disk.lock.lockTime = Time;
1922 } else if (LockingType == LockWrite) {
1923 if ( !(rights & PRSFS_WRITE) &&
1924 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1927 if (targetptr->disk.lock.lockCount == 0) {
1928 targetptr->disk.lock.lockCount = -1;
1929 targetptr->disk.lock.lockTime = Time;
1935 Time += AFS_LOCKWAIT;
1936 if (targetptr->disk.lock.lockCount != 0)
1937 targetptr->disk.lock.lockTime = Time;
1942 if ((--targetptr->disk.lock.lockCount) <= 0)
1943 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1947 targetptr->changed_oldTime = writeVnode; /* restore old status */
1948 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1951 } /*HandleLocking */
1953 /* 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. */
1956 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1960 if (!(rights & Prfs_Mode))
1962 if ((targetptr->disk.type != vDirectory)
1963 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1969 * If some flags (i.e. min or max quota) are set, the volume's in disk
1970 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1971 * update, if applicable.
1974 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1975 char *Name, char *OfflineMsg, char *Motd)
1977 Error errorCode = 0;
1979 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1980 V_minquota(volptr) = StoreVolStatus->MinQuota;
1981 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1982 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1983 if (strlen(OfflineMsg) > 0) {
1984 strcpy(V_offlineMessage(volptr), OfflineMsg);
1986 if (strlen(Name) > 0) {
1987 strcpy(V_name(volptr), Name);
1990 * We don't overwrite the motd field, since it's now being used
1993 VUpdateVolume(&errorCode, volptr);
1996 } /*RXUpdate_VolumeStatus */
2000 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2001 char **motd, Volume * volptr)
2004 status->Vid = V_id(volptr);
2005 status->ParentId = V_parentId(volptr);
2006 status->Online = V_inUse(volptr);
2007 status->InService = V_inService(volptr);
2008 status->Blessed = V_blessed(volptr);
2009 status->NeedsSalvage = V_needsSalvaged(volptr);
2010 if (VolumeWriteable(volptr))
2011 status->Type = ReadWrite;
2013 status->Type = ReadOnly;
2014 status->MinQuota = V_minquota(volptr);
2015 status->MaxQuota = V_maxquota(volptr);
2016 status->BlocksInUse = V_diskused(volptr);
2017 status->PartBlocksAvail = RoundInt64ToInt31(volptr->partition->free);
2018 status->PartMaxBlocks = RoundInt64ToInt31(volptr->partition->totalUsable);
2020 /* now allocate and copy these things; they're freed by the RXGEN stub */
2021 *name = strdup(V_name(volptr));
2023 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2025 *offMsg = strdup(V_offlineMessage(volptr));
2027 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2031 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2033 strcpy(*motd, nullString);
2035 } /*RXGetVolumeStatus */
2039 FileNameOK(char *aname)
2044 /* watch for @sys on the right */
2045 if (strcmp(aname + i - 4, "@sys") == 0)
2048 while ((tc = *aname++)) {
2050 return 0; /* very bad character to encounter */
2052 return 1; /* file name is ok */
2058 * This variant of symlink is expressly to support the AFS/DFS translator
2059 * and is not supported by the AFS fileserver. We just return EINVAL.
2060 * The cache manager should not generate this call to an AFS cache manager.
2063 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2064 char *LinkContents, struct AFSStoreStatus *InStatus,
2065 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2066 struct AFSFetchStatus *OutDirStatus,
2067 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2073 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2074 struct FsCmdInputs * Inputs,
2075 struct FsCmdOutputs * Outputs)
2079 switch (Inputs->command) {
2083 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2084 Inputs->command, Outputs->code));
2089 static struct afs_buffer {
2090 struct afs_buffer *next;
2091 } *freeBufferList = 0;
2092 static int afs_buffersAlloced = 0;
2095 FreeSendBuffer(struct afs_buffer *adata)
2098 afs_buffersAlloced--;
2099 adata->next = freeBufferList;
2100 freeBufferList = adata;
2104 } /*FreeSendBuffer */
2106 /* allocate space for sender */
2108 AllocSendBuffer(void)
2110 struct afs_buffer *tp;
2113 afs_buffersAlloced++;
2114 if (!freeBufferList) {
2117 tmp = malloc(sendBufSize);
2119 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2123 tp = freeBufferList;
2124 freeBufferList = tp->next;
2128 } /*AllocSendBuffer */
2129 #endif /* HAVE_PIOV */
2132 * This routine returns the status info associated with the targetptr vnode
2133 * in the AFSFetchStatus structure. Some of the newer fields, such as
2134 * SegSize and Group are not yet implemented
2138 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2139 afs_int32 anyrights, Vnode * parentptr)
2141 int Time = time(NULL);
2143 /* initialize return status from a vnode */
2144 status->InterfaceVersion = 1;
2145 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2146 status->errorCode = 0;
2147 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2148 if (targetptr->disk.type == vFile)
2149 status->FileType = File;
2150 else if (targetptr->disk.type == vDirectory)
2151 status->FileType = Directory;
2152 else if (targetptr->disk.type == vSymlink)
2153 status->FileType = SymbolicLink;
2155 status->FileType = Invalid; /*invalid type field */
2156 status->LinkCount = targetptr->disk.linkCount;
2158 afs_fsize_t targetLen;
2159 VN_GET_LEN(targetLen, targetptr);
2160 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2162 status->DataVersion = targetptr->disk.dataVersion;
2163 status->Author = targetptr->disk.author;
2164 status->Owner = targetptr->disk.owner;
2165 status->CallerAccess = rights;
2166 status->AnonymousAccess = anyrights;
2167 status->UnixModeBits = targetptr->disk.modeBits;
2168 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2169 status->ParentVnode =
2170 (status->FileType ==
2171 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2172 status->ParentUnique =
2173 (status->FileType ==
2174 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2175 status->ServerModTime = targetptr->disk.serverModifyTime;
2176 status->Group = targetptr->disk.group;
2177 status->lockCount = Time > targetptr->disk.lock.lockTime ? 0 : targetptr->disk.lock.lockCount;
2178 status->errorCode = 0;
2183 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2184 afs_sfsize_t Pos, afs_sfsize_t Len,
2185 struct AFSFetchStatus *OutStatus,
2186 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2189 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2190 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2191 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2192 Error errorCode = 0; /* return code to caller */
2193 Error fileCode = 0; /* return code from vol package */
2194 Volume *volptr = 0; /* pointer to the volume */
2195 struct client *client = 0; /* pointer to the client data */
2196 struct rx_connection *tcon; /* the connection we're part of */
2198 afs_int32 rights, anyrights; /* rights for this and any user */
2199 struct client *t_client = NULL; /* tmp ptr to client data */
2200 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2201 struct VCallByVol tcbv, *cbv = NULL;
2202 static int remainder = 0; /* shared access protected by FS_LOCK */
2203 struct fsstats fsstats;
2204 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2205 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2206 int readIdx; /* Index of read stats array to bump */
2208 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2211 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2214 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2216 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2219 /* Get ptr to client data for user Id for logging */
2220 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2221 logHostAddr.s_addr = rxr_HostOf(tcon);
2223 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2224 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2225 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2227 queue_NodeInit(&tcbv);
2232 * Get volume/vnode for the fetched file; caller's access rights to
2233 * it are also returned
2236 GetVolumePackageWithCall(acall, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2237 &parentwhentargetnotdir, &client, READ_LOCK,
2238 &rights, &anyrights, 0)))
2241 SetVolumeSync(Sync, volptr);
2244 * Remember that another read operation was performed.
2247 if (client->InSameNetwork)
2248 readIdx = VOL_STATS_SAME_NET;
2250 readIdx = VOL_STATS_DIFF_NET;
2251 V_stat_reads(volptr, readIdx)++;
2252 if (client->ViceId != AnonymousID) {
2253 V_stat_reads(volptr, readIdx + 1)++;
2256 /* Check whether the caller has permission access to fetch the data */
2258 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2262 * Drop the read lock on the parent directory after saving the parent
2263 * vnode information we need to pass to GetStatus
2265 if (parentwhentargetnotdir != NULL) {
2266 tparentwhentargetnotdir = *parentwhentargetnotdir;
2267 VPutVnode(&fileCode, parentwhentargetnotdir);
2268 opr_Assert(!fileCode || (fileCode == VSALVAGE));
2269 parentwhentargetnotdir = NULL;
2272 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
2274 /* actually do the data transfer */
2276 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2277 &bytesToXfer, &bytesXferred);
2279 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2285 /* write back the OutStatus from the target vnode */
2286 GetStatus(targetptr, OutStatus, rights, anyrights,
2287 &tparentwhentargetnotdir);
2289 rx_KeepAliveOn(acall); /* I/O done */
2291 /* if a r/w volume, promise a callback to the caller */
2292 if (VolumeWriteable(volptr))
2293 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2295 struct AFSFid myFid;
2296 memset(&myFid, 0, sizeof(struct AFSFid));
2297 myFid.Volume = Fid->Volume;
2298 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2302 /* Update and store volume/vnode and parent vnodes back */
2303 (void)PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
2304 (Vnode *) 0, volptr, &client, cbv);
2305 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2306 errorCode = CallPostamble(tcon, errorCode, thost);
2308 fsstats_FinishOp(&fsstats, errorCode);
2310 osi_auditU(acall, FetchDataEvent, errorCode,
2311 AUD_ID, t_client ? t_client->ViceId : 0,
2312 AUD_FID, Fid, AUD_END);
2315 } /*SRXAFS_FetchData */
2318 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2319 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2320 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2322 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2327 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2328 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2329 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2332 afs_sfsize_t tPos, tLen;
2334 tPos = (afs_sfsize_t) Pos;
2335 tLen = (afs_sfsize_t) Len;
2338 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2344 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2345 struct AFSOpaque * AccessList,
2346 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2348 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2349 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2350 Error errorCode = 0; /* return error code to caller */
2351 Volume *volptr = 0; /* pointer to the volume */
2352 struct client *client = 0; /* pointer to the client data */
2353 afs_int32 rights, anyrights; /* rights for this and any user */
2354 struct rx_connection *tcon = rx_ConnectionOf(acall);
2356 struct client *t_client = NULL; /* tmp ptr to client data */
2357 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2358 struct fsstats fsstats;
2360 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2363 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2366 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2368 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2371 /* Get ptr to client data for user Id for logging */
2372 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2373 logHostAddr.s_addr = rxr_HostOf(tcon);
2375 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2376 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2377 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2379 AccessList->AFSOpaque_len = 0;
2380 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2381 if (!AccessList->AFSOpaque_val) {
2382 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2386 * Get volume/vnode for the fetched file; caller's access rights to it
2390 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2391 &parentwhentargetnotdir, &client, READ_LOCK,
2392 &rights, &anyrights)))
2395 SetVolumeSync(Sync, volptr);
2397 /* Check whether we have permission to fetch the ACL */
2399 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2402 /* Get the Access List from the dir's vnode */
2404 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2407 /* Get OutStatus back From the target Vnode */
2408 GetStatus(targetptr, OutStatus, rights, anyrights,
2409 parentwhentargetnotdir);
2412 /* Update and store volume/vnode and parent vnodes back */
2413 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2414 (Vnode *) 0, volptr, &client);
2416 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2417 AccessList->AFSOpaque_val));
2418 errorCode = CallPostamble(tcon, errorCode, thost);
2420 fsstats_FinishOp(&fsstats, errorCode);
2422 osi_auditU(acall, FetchACLEvent, errorCode,
2423 AUD_ID, t_client ? t_client->ViceId : 0,
2425 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2427 } /*SRXAFS_FetchACL */
2431 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2432 * merged into it when possible.
2435 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2436 struct AFSFetchStatus *OutStatus,
2437 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2439 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2440 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2441 Error errorCode = 0; /* return code to caller */
2442 Volume *volptr = 0; /* pointer to the volume */
2443 struct client *client = 0; /* pointer to the client data */
2444 afs_int32 rights, anyrights; /* rights for this and any user */
2445 struct client *t_client = NULL; /* tmp ptr to client data */
2446 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2447 struct rx_connection *tcon = rx_ConnectionOf(acall);
2449 /* Get ptr to client data for user Id for logging */
2450 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2451 logHostAddr.s_addr = rxr_HostOf(tcon);
2453 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2454 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2455 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2457 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2460 * Get volume/vnode for the fetched file; caller's rights to it are
2464 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2465 &parentwhentargetnotdir, &client, READ_LOCK,
2466 &rights, &anyrights)))
2467 goto Bad_FetchStatus;
2469 rx_KeepAliveOn(acall);
2471 /* set volume synchronization information */
2472 SetVolumeSync(Sync, volptr);
2474 /* Are we allowed to fetch Fid's status? */
2475 if (targetptr->disk.type != vDirectory) {
2477 Check_PermissionRights(targetptr, client, rights,
2478 CHK_FETCHSTATUS, 0))) {
2479 if (rx_GetCallAbortCode(acall) == errorCode)
2480 rx_SetCallAbortCode(acall, 0);
2481 goto Bad_FetchStatus;
2485 /* set OutStatus From the Fid */
2486 GetStatus(targetptr, OutStatus, rights, anyrights,
2487 parentwhentargetnotdir);
2489 /* If a r/w volume, also set the CallBack state */
2490 if (VolumeWriteable(volptr))
2491 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2493 struct AFSFid myFid;
2494 memset(&myFid, 0, sizeof(struct AFSFid));
2495 myFid.Volume = Fid->Volume;
2496 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2500 /* Update and store volume/vnode and parent vnodes back */
2501 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2502 (Vnode *) 0, volptr, &client);
2503 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2506 } /*SAFSS_FetchStatus */
2510 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2511 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2512 struct AFSVolSync * Sync)
2516 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2517 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2518 Error errorCode = 0; /* return code to caller */
2519 Volume *volptr = 0; /* pointer to the volume */
2520 struct client *client = 0; /* pointer to the client data */
2521 afs_int32 rights, anyrights; /* rights for this and any user */
2522 struct AFSFid *tfid; /* file id we're dealing with now */
2523 struct rx_connection *tcon = rx_ConnectionOf(acall);
2525 struct client *t_client = NULL; /* tmp pointer to the client data */
2526 struct fsstats fsstats;
2528 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2530 ViceLog(1, ("SAFS_BulkStatus\n"));
2532 AFSCallStats.TotalCalls++;
2534 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2535 if (nfiles <= 0) { /* Sanity check */
2537 goto Audit_and_Return;
2540 /* allocate space for return output parameters */
2541 OutStats->AFSBulkStats_val = malloc(nfiles * sizeof(struct AFSFetchStatus));
2542 if (!OutStats->AFSBulkStats_val) {
2543 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2545 OutStats->AFSBulkStats_len = nfiles;
2546 CallBacks->AFSCBs_val = malloc(nfiles * sizeof(struct AFSCallBack));
2547 if (!CallBacks->AFSCBs_val) {
2548 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2550 CallBacks->AFSCBs_len = nfiles;
2552 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2553 goto Bad_BulkStatus;
2555 tfid = Fids->AFSCBFids_val;
2556 for (i = 0; i < nfiles; i++, tfid++) {
2558 * Get volume/vnode for the fetched file; caller's rights to it
2562 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2563 &parentwhentargetnotdir, &client, READ_LOCK,
2564 &rights, &anyrights)))
2565 goto Bad_BulkStatus;
2567 rx_KeepAliveOn(acall);
2569 /* set volume synchronization information, but only once per call */
2571 SetVolumeSync(Sync, volptr);
2573 /* Are we allowed to fetch Fid's status? */
2574 if (targetptr->disk.type != vDirectory) {
2576 Check_PermissionRights(targetptr, client, rights,
2577 CHK_FETCHSTATUS, 0))) {
2578 if (rx_GetCallAbortCode(acall) == errorCode)
2579 rx_SetCallAbortCode(acall, 0);
2580 goto Bad_BulkStatus;
2584 /* set OutStatus From the Fid */
2585 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2586 anyrights, parentwhentargetnotdir);
2588 /* If a r/w volume, also set the CallBack state */
2589 if (VolumeWriteable(volptr))
2590 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2591 &CallBacks->AFSCBs_val[i]);
2593 struct AFSFid myFid;
2594 memset(&myFid, 0, sizeof(struct AFSFid));
2595 myFid.Volume = tfid->Volume;
2596 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2597 &CallBacks->AFSCBs_val[i]);
2600 /* put back the file ID and volume */
2601 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2602 (Vnode *) 0, volptr, &client);
2603 parentwhentargetnotdir = (Vnode *) 0;
2604 targetptr = (Vnode *) 0;
2605 volptr = (Volume *) 0;
2606 client = (struct client *)0;
2610 /* Update and store volume/vnode and parent vnodes back */
2611 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2612 (Vnode *) 0, volptr, &client);
2613 errorCode = CallPostamble(tcon, errorCode, thost);
2615 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2617 fsstats_FinishOp(&fsstats, errorCode);
2620 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2621 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2622 AUD_ID, t_client ? t_client->ViceId : 0,
2623 AUD_FIDS, Fids, AUD_END);
2626 } /*SRXAFS_BulkStatus */
2630 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2631 struct AFSBulkStats * OutStats,
2632 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2636 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2637 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2638 Error errorCode = 0; /* return code to caller */
2639 Volume *volptr = 0; /* pointer to the volume */
2640 struct client *client = 0; /* pointer to the client data */
2641 afs_int32 rights, anyrights; /* rights for this and any user */
2642 struct AFSFid *tfid; /* file id we're dealing with now */
2643 struct rx_connection *tcon;
2645 struct client *t_client = NULL; /* tmp ptr to client data */
2646 AFSFetchStatus *tstatus;
2647 int VolSync_set = 0;
2648 struct fsstats fsstats;
2650 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2652 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2654 AFSCallStats.TotalCalls++;
2656 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2657 if (nfiles <= 0) { /* Sanity check */
2659 goto Audit_and_Return;
2662 /* allocate space for return output parameters */
2663 OutStats->AFSBulkStats_val = calloc(nfiles, sizeof(struct AFSFetchStatus));
2664 if (!OutStats->AFSBulkStats_val) {
2665 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2667 OutStats->AFSBulkStats_len = nfiles;
2668 CallBacks->AFSCBs_val = calloc(nfiles, sizeof(struct AFSCallBack));
2669 if (!CallBacks->AFSCBs_val) {
2670 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2672 CallBacks->AFSCBs_len = nfiles;
2674 /* Zero out return values to avoid leaking information on partial succes */
2675 memset(Sync, 0, sizeof(*Sync));
2677 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2678 goto Bad_InlineBulkStatus;
2681 tfid = Fids->AFSCBFids_val;
2682 for (i = 0; i < nfiles; i++, tfid++) {
2684 * Get volume/vnode for the fetched file; caller's rights to it
2688 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2689 &parentwhentargetnotdir, &client, READ_LOCK,
2690 &rights, &anyrights))) {
2691 tstatus = &OutStats->AFSBulkStats_val[i];
2693 if (thost->hostFlags & HERRORTRANS) {
2694 tstatus->errorCode = sys_error_to_et(errorCode);
2696 tstatus->errorCode = errorCode;
2699 PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2700 (Vnode *) 0, volptr, &client);
2701 parentwhentargetnotdir = (Vnode *) 0;
2702 targetptr = (Vnode *) 0;
2703 volptr = (Volume *) 0;
2704 client = (struct client *)0;
2708 rx_KeepAliveOn(acall);
2710 /* set volume synchronization information, but only once per call */
2712 SetVolumeSync(Sync, volptr);
2716 /* Are we allowed to fetch Fid's status? */
2717 if (targetptr->disk.type != vDirectory) {
2719 Check_PermissionRights(targetptr, client, rights,
2720 CHK_FETCHSTATUS, 0))) {
2721 tstatus = &OutStats->AFSBulkStats_val[i];
2723 if (thost->hostFlags & HERRORTRANS) {
2724 tstatus->errorCode = sys_error_to_et(errorCode);
2726 tstatus->errorCode = errorCode;
2729 (void)PutVolumePackage(acall, parentwhentargetnotdir,
2730 targetptr, (Vnode *) 0, volptr,
2732 parentwhentargetnotdir = (Vnode *) 0;
2733 targetptr = (Vnode *) 0;
2734 volptr = (Volume *) 0;
2735 client = (struct client *)0;
2740 /* set OutStatus From the Fid */
2741 GetStatus(targetptr,
2742 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2743 rights, anyrights, parentwhentargetnotdir);
2745 /* If a r/w volume, also set the CallBack state */
2746 if (VolumeWriteable(volptr))
2747 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2748 &CallBacks->AFSCBs_val[i]);
2750 struct AFSFid myFid;
2751 memset(&myFid, 0, sizeof(struct AFSFid));
2752 myFid.Volume = tfid->Volume;
2753 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2754 &CallBacks->AFSCBs_val[i]);
2757 /* put back the file ID and volume */
2758 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2759 (Vnode *) 0, volptr, &client);
2760 parentwhentargetnotdir = (Vnode *) 0;
2761 targetptr = (Vnode *) 0;
2762 volptr = (Volume *) 0;
2763 client = (struct client *)0;
2767 Bad_InlineBulkStatus:
2768 /* Update and store volume/vnode and parent vnodes back */
2769 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2770 (Vnode *) 0, volptr, &client);
2771 errorCode = CallPostamble(tcon, errorCode, thost);
2773 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2775 fsstats_FinishOp(&fsstats, errorCode);
2778 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2779 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2780 AUD_ID, t_client ? t_client->ViceId : 0,
2781 AUD_FIDS, Fids, AUD_END);
2784 } /*SRXAFS_InlineBulkStatus */
2788 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2789 struct AFSFetchStatus * OutStatus,
2790 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2793 struct rx_connection *tcon;
2795 struct client *t_client = NULL; /* tmp ptr to client data */
2796 struct fsstats fsstats;
2798 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2800 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2801 goto Bad_FetchStatus;
2803 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2806 code = CallPostamble(tcon, code, thost);
2808 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2810 fsstats_FinishOp(&fsstats, code);
2812 osi_auditU(acall, FetchStatusEvent, code,
2813 AUD_ID, t_client ? t_client->ViceId : 0,
2814 AUD_FID, Fid, AUD_END);
2817 } /*SRXAFS_FetchStatus */
2821 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2822 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2823 afs_fsize_t Length, afs_fsize_t FileLength,
2824 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2826 Vnode *targetptr = 0; /* pointer to input fid */
2827 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2828 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2829 Error errorCode = 0; /* return code for caller */
2830 Error fileCode = 0; /* return code from vol package */
2831 Volume *volptr = 0; /* pointer to the volume header */
2832 struct client *client = 0; /* pointer to client structure */
2833 afs_int32 rights, anyrights; /* rights for this and any user */
2834 struct client *t_client = NULL; /* tmp ptr to client data */
2835 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2836 struct rx_connection *tcon;
2838 struct fsstats fsstats;
2839 afs_sfsize_t bytesToXfer;
2840 afs_sfsize_t bytesXferred;
2841 static int remainder = 0;
2844 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2847 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2850 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2852 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2855 /* Get ptr to client data for user Id for logging */
2856 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2857 logHostAddr.s_addr = rxr_HostOf(tcon);
2859 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2860 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2861 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2864 * Get associated volume/vnode for the stored file; caller's rights
2868 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustNOTBeDIR,
2869 &parentwhentargetnotdir, &client, WRITE_LOCK,
2870 &rights, &anyrights))) {
2874 rx_KeepAliveOn(acall);
2876 /* set volume synchronization information */
2877 SetVolumeSync(Sync, volptr);
2879 if (targetptr->disk.type == vSymlink) {
2880 /* Should we return a better error code here??? */
2885 /* Check if we're allowed to store the data */
2887 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2893 * Drop the read lock on the parent directory after saving the parent
2894 * vnode information we need to pass to GetStatus
2896 if (parentwhentargetnotdir != NULL) {
2897 tparentwhentargetnotdir = *parentwhentargetnotdir;
2898 rx_KeepAliveOff(acall);
2899 VPutVnode(&fileCode, parentwhentargetnotdir);
2900 rx_KeepAliveOn(acall);
2901 opr_Assert(!fileCode || (fileCode == VSALVAGE));
2902 parentwhentargetnotdir = NULL;
2905 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
2908 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2909 FileLength, (InStatus->Mask & AFS_FSYNC),
2910 &bytesToXfer, &bytesXferred);
2912 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2915 if (errorCode && (!targetptr->changed_newTime))
2918 rx_KeepAliveOff(acall);
2919 /* Update the status of the target's vnode */
2920 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2921 targetptr, volptr, 0, 0);
2922 rx_KeepAliveOn(acall);
2924 /* Get the updated File's status back to the caller */
2925 GetStatus(targetptr, OutStatus, rights, anyrights,
2926 &tparentwhentargetnotdir);
2929 /* Update and store volume/vnode and parent vnodes back */
2930 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2931 (Vnode *) 0, volptr, &client);
2932 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
2934 errorCode = CallPostamble(tcon, errorCode, thost);
2936 fsstats_FinishOp(&fsstats, errorCode);
2938 osi_auditU(acall, StoreDataEvent, errorCode,
2939 AUD_ID, t_client ? t_client->ViceId : 0,
2940 AUD_FID, Fid, AUD_END);
2942 } /*common_StoreData64 */
2945 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
2946 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
2947 afs_uint32 Length, afs_uint32 FileLength,
2948 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2950 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
2951 (0x7fffffff - Pos) < Length)
2954 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
2956 } /*SRXAFS_StoreData */
2959 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
2960 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
2961 afs_uint64 Length, afs_uint64 FileLength,
2962 struct AFSFetchStatus * OutStatus,
2963 struct AFSVolSync * Sync)
2967 afs_fsize_t tLength;
2968 afs_fsize_t tFileLength;
2970 tPos = (afs_fsize_t) Pos;
2971 tLength = (afs_fsize_t) Length;
2972 tFileLength = (afs_fsize_t) FileLength;
2975 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
2981 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
2982 struct AFSOpaque * AccessList,
2983 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2985 Vnode *targetptr = 0; /* pointer to input fid */
2986 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2987 Error errorCode = 0; /* return code for caller */
2988 struct AFSStoreStatus InStatus; /* Input status for fid */
2989 Volume *volptr = 0; /* pointer to the volume header */
2990 struct client *client = 0; /* pointer to client structure */
2991 afs_int32 rights, anyrights; /* rights for this and any user */
2992 struct rx_connection *tcon;
2994 struct client *t_client = NULL; /* tmp ptr to client data */
2995 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2996 struct fsstats fsstats;
2998 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
3000 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3003 /* Get ptr to client data for user Id for logging */
3004 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3005 logHostAddr.s_addr = rxr_HostOf(tcon);
3007 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3008 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3009 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3011 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3013 InStatus.Mask = 0; /* not storing any status */
3016 * Get associated volume/vnode for the target dir; caller's rights
3017 * are also returned.
3020 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustBeDIR,
3021 &parentwhentargetnotdir, &client, WRITE_LOCK,
3022 &rights, &anyrights))) {
3026 /* set volume synchronization information */
3027 SetVolumeSync(Sync, volptr);
3029 /* Check if we have permission to change the dir's ACL */
3031 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3036 /* Build and store the new Access List for the dir */
3037 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3041 targetptr->changed_newTime = 1; /* status change of directory */
3043 /* convert the write lock to a read lock before breaking callbacks */
3044 VVnodeWriteToRead(&errorCode, targetptr);
3045 opr_Assert(!errorCode || errorCode == VSALVAGE);
3047 rx_KeepAliveOn(acall);
3049 /* break call backs on the directory */
3050 BreakCallBack(client->host, Fid, 0);
3052 /* Get the updated dir's status back to the caller */
3053 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3056 /* Update and store volume/vnode and parent vnodes back */
3057 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3059 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3060 errorCode = CallPostamble(tcon, errorCode, thost);
3062 fsstats_FinishOp(&fsstats, errorCode);
3064 osi_auditU(acall, StoreACLEvent, errorCode,
3065 AUD_ID, t_client ? t_client->ViceId : 0,
3066 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3069 } /*SRXAFS_StoreACL */
3073 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3074 * should be merged when possible.
3077 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3078 struct AFSStoreStatus *InStatus,
3079 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3081 Vnode *targetptr = 0; /* pointer to input fid */
3082 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3083 Error errorCode = 0; /* return code for caller */
3084 Volume *volptr = 0; /* pointer to the volume header */
3085 struct client *client = 0; /* pointer to client structure */
3086 afs_int32 rights, anyrights; /* rights for this and any user */
3087 struct client *t_client = NULL; /* tmp ptr to client data */
3088 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3089 struct rx_connection *tcon = rx_ConnectionOf(acall);
3091 /* Get ptr to client data for user Id for logging */
3092 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3093 logHostAddr.s_addr = rxr_HostOf(tcon);
3095 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3096 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3097 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3099 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3102 * Get volume/vnode for the target file; caller's rights to it are
3106 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
3107 &parentwhentargetnotdir, &client, WRITE_LOCK,
3108 &rights, &anyrights))) {
3109 goto Bad_StoreStatus;
3112 /* set volume synchronization information */
3113 SetVolumeSync(Sync, volptr);
3115 /* Check if the caller has proper permissions to store status to Fid */
3117 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3119 goto Bad_StoreStatus;
3122 * Check for a symbolic link; we can't chmod these (otherwise could
3123 * change a symlink to a mt pt or vice versa)
3125 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3127 goto Bad_StoreStatus;
3130 /* Update the status of the target's vnode */
3131 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3132 (parentwhentargetnotdir ? parentwhentargetnotdir
3133 : targetptr), volptr, 0, 0);
3135 rx_KeepAliveOn(acall);
3137 /* convert the write lock to a read lock before breaking callbacks */
3138 VVnodeWriteToRead(&errorCode, targetptr);
3139 opr_Assert(!errorCode || errorCode == VSALVAGE);
3141 /* Break call backs on Fid */
3142 BreakCallBack(client->host, Fid, 0);
3144 /* Return the updated status back to caller */
3145 GetStatus(targetptr, OutStatus, rights, anyrights,
3146 parentwhentargetnotdir);
3149 /* Update and store volume/vnode and parent vnodes back */
3150 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3152 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3155 } /*SAFSS_StoreStatus */
3159 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3160 struct AFSStoreStatus * InStatus,
3161 struct AFSFetchStatus * OutStatus,
3162 struct AFSVolSync * Sync)
3165 struct rx_connection *tcon;
3167 struct client *t_client = NULL; /* tmp ptr to client data */
3168 struct fsstats fsstats;
3170 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3172 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3173 goto Bad_StoreStatus;
3175 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3178 code = CallPostamble(tcon, code, thost);
3180 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3182 fsstats_FinishOp(&fsstats, code);
3184 osi_auditU(acall, StoreStatusEvent, code,
3185 AUD_ID, t_client ? t_client->ViceId : 0,
3186 AUD_FID, Fid, AUD_END);
3189 } /*SRXAFS_StoreStatus */
3193 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3194 * merged in when possible.
3197 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3198 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3200 Vnode *parentptr = 0; /* vnode of input Directory */
3201 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3202 Vnode *targetptr = 0; /* file to be deleted */
3203 Volume *volptr = 0; /* pointer to the volume header */
3204 AFSFid fileFid; /* area for Fid from the directory */
3205 Error errorCode = 0; /* error code */
3206 DirHandle dir; /* Handle for dir package I/O */
3207 struct client *client = 0; /* pointer to client structure */
3208 afs_int32 rights, anyrights; /* rights for this and any user */
3209 struct client *t_client; /* tmp ptr to client data */
3210 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3211 struct rx_connection *tcon = rx_ConnectionOf(acall);
3214 /* Get ptr to client data for user Id for logging */
3215 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3216 logHostAddr.s_addr = rxr_HostOf(tcon);
3218 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3219 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3220 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3222 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3225 * Get volume/vnode for the parent dir; caller's access rights are
3229 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3230 &parentwhentargetnotdir, &client, WRITE_LOCK,
3231 &rights, &anyrights))) {
3232 goto Bad_RemoveFile;
3234 /* set volume synchronization information */
3235 SetVolumeSync(Sync, volptr);
3237 /* Does the caller has delete (& write) access to the parent directory? */
3238 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3239 goto Bad_RemoveFile;
3242 /* Actually delete the desired file */
3244 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3246 goto Bad_RemoveFile;
3249 /* Update the vnode status of the parent dir */
3250 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3251 parentptr->disk.linkCount,
3252 client->InSameNetwork);
3254 rx_KeepAliveOn(acall);
3256 /* Return the updated parent dir's status back to caller */
3257 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3259 /* Handle internal callback state for the parent and the deleted file */
3260 if (targetptr->disk.linkCount == 0) {
3261 /* no references left, discard entry */
3262 DeleteFileCallBacks(&fileFid);
3263 /* convert the parent lock to a read lock before breaking callbacks */
3264 VVnodeWriteToRead(&errorCode, parentptr);
3265 opr_Assert(!errorCode || errorCode == VSALVAGE);
3267 /* convert the parent lock to a read lock before breaking callbacks */
3268 VVnodeWriteToRead(&errorCode, parentptr);
3269 opr_Assert(!errorCode || errorCode == VSALVAGE);
3270 /* convert the target lock to a read lock before breaking callbacks */
3271 VVnodeWriteToRead(&errorCode, targetptr);
3272 opr_Assert(!errorCode || errorCode == VSALVAGE);
3273 /* tell all the file has changed */
3274 BreakCallBack(client->host, &fileFid, 1);
3277 /* break call back on the directory */
3278 BreakCallBack(client->host, DirFid, 0);
3281 /* Update and store volume/vnode and parent vnodes back */
3282 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3285 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3288 } /*SAFSS_RemoveFile */
3292 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3293 struct AFSFetchStatus * OutDirStatus,
3294 struct AFSVolSync * Sync)
3297 struct rx_connection *tcon;
3299 struct client *t_client = NULL; /* tmp ptr to client data */
3300 struct fsstats fsstats;
3302 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3304 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3305 goto Bad_RemoveFile;
3307 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3310 code = CallPostamble(tcon, code, thost);
3312 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3314 fsstats_FinishOp(&fsstats, code);
3316 osi_auditU(acall, RemoveFileEvent, code,
3317 AUD_ID, t_client ? t_client->ViceId : 0,
3318 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3321 } /*SRXAFS_RemoveFile */
3325 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3326 * be merged in when possible.
3329 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3330 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3331 struct AFSFetchStatus *OutFidStatus,
3332 struct AFSFetchStatus *OutDirStatus,
3333 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3335 Vnode *parentptr = 0; /* vnode of input Directory */
3336 Vnode *targetptr = 0; /* vnode of the new file */
3337 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3338 Volume *volptr = 0; /* pointer to the volume header */
3339 Error errorCode = 0; /* error code */
3340 DirHandle dir; /* Handle for dir package I/O */
3341 struct client *client = 0; /* pointer to client structure */
3342 afs_int32 rights, anyrights; /* rights for this and any user */
3343 struct client *t_client; /* tmp ptr to client data */
3344 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3345 struct rx_connection *tcon = rx_ConnectionOf(acall);
3349 /* Get ptr to client data for user Id for logging */
3350 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3351 logHostAddr.s_addr = rxr_HostOf(tcon);
3353 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3354 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3355 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3357 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3359 if (!FileNameOK(Name)) {
3361 goto Bad_CreateFile;
3365 * Get associated volume/vnode for the parent dir; caller long are
3369 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3370 &parentwhentargetnotdir, &client, WRITE_LOCK,
3371 &rights, &anyrights))) {
3372 goto Bad_CreateFile;
3375 /* set volume synchronization information */
3376 SetVolumeSync(Sync, volptr);
3378 /* Can we write (and insert) onto the parent directory? */
3379 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3380 goto Bad_CreateFile;
3383 /* get a new vnode for the file to be created and set it up */
3385 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3386 vFile, nBlocks(0))))
3387 goto Bad_CreateFile;
3389 /* update the status of the parent vnode */
3390 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3391 parentptr->disk.linkCount,
3392 client->InSameNetwork);
3394 /* update the status of the new file's vnode */
3395 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3396 parentptr, volptr, 0, 0);
3398 rx_KeepAliveOn(acall);
3400 /* 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 */
3401 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3402 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3404 /* convert the write lock to a read lock before breaking callbacks */
3405 VVnodeWriteToRead(&errorCode, parentptr);
3406 opr_Assert(!errorCode || errorCode == VSALVAGE);
3408 /* break call back on parent dir */
3409 BreakCallBack(client->host, DirFid, 0);
3411 /* Return a callback promise for the newly created file to the caller */
3412 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3415 /* Update and store volume/vnode and parent vnodes back */
3416 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3419 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3422 } /*SAFSS_CreateFile */
3426 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3427 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3428 struct AFSFetchStatus * OutFidStatus,
3429 struct AFSFetchStatus * OutDirStatus,
3430 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3433 struct rx_connection *tcon;
3435 struct client *t_client = NULL; /* tmp ptr to client data */
3436 struct fsstats fsstats;