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 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
35 #undef SHARED /* XXX */
42 #ifdef HAVE_NETINET_IF_ETHER_H
43 #include <netinet/if_ether.h>
46 #if !defined(AFS_SGI_ENV) && defined(HAVE_SYS_MAP_H)
50 #ifdef HAVE_SYS_STATFS_H
51 #include <sys/statfs.h>
54 #ifdef HAVE_SYS_LOCKF_H
55 #include <sys/lockf.h>
63 /* included early because of name conflict on IOPEN */
64 #include <sys/inode.h>
68 #endif /* AFS_HPUX_ENV */
74 #include <afs/afsint.h>
75 #include <afs/vldbint.h>
76 #include <afs/errors.h>
77 #include <afs/ihandle.h>
78 #include <afs/vnode.h>
79 #include <afs/volume.h>
80 #include <afs/ptclient.h>
81 #include <afs/ptuser.h>
82 #include <afs/prs_fs.h>
85 #include <rx/rx_globals.h>
87 #include <afs/cellconfig.h>
90 #include <afs/partition.h>
91 #include "viced_prototypes.h"
95 #include <afs/unified_afs.h>
96 #include <afs/audit.h>
97 #include <afs/afsutil.h>
100 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
101 extern void FidZap(DirHandle * file);
102 extern void FidZero(DirHandle * file);
104 #ifdef AFS_PTHREAD_ENV
105 pthread_mutex_t fileproc_glock_mutex;
106 #endif /* AFS_PTHREAD_ENV */
108 /* Useful local defines used by this module */
111 #define MustNOTBeDIR 1
115 #define TVS_SSTATUS 2
118 #define TVS_MKDIR 0x10
120 #define CHK_FETCH 0x10
121 #define CHK_FETCHDATA 0x10
122 #define CHK_FETCHACL 0x11
123 #define CHK_FETCHSTATUS 0x12
124 #define CHK_STOREDATA 0x00
125 #define CHK_STOREACL 0x01
126 #define CHK_STORESTATUS 0x02
128 #define OWNERREAD 0400
129 #define OWNERWRITE 0200
130 #define OWNEREXEC 0100
131 #ifdef USE_GROUP_PERMS
132 #define GROUPREAD 0040
133 #define GROUPWRITE 0020
134 #define GROUPREXEC 0010
137 /* The following errors were not defined in NT. They are given unique
138 * names here to avoid any potential collision.
140 #define FSERR_ELOOP 90
141 #define FSERR_EOPNOTSUPP 122
142 #define FSERR_ECONNREFUSED 130
144 #define NOTACTIVECALL 0
147 #define CREATE_SGUID_ADMIN_ONLY 1
149 extern struct afsconf_dir *confDir;
150 extern afs_int32 dataVersionHigh;
153 static struct AFSCallStatistics AFSCallStats;
154 #if FS_STATS_DETAILED
155 struct fs_stats_FullPerfStats afs_FullPerfStats;
156 extern int AnonymousID;
157 #endif /* FS_STATS_DETAILED */
158 #if OPENAFS_VOL_STATS
159 static const char nullString[] = "";
160 #endif /* OPENAFS_VOL_STATS */
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 #ifdef AFS_PTHREAD_ENV
334 struct ubik_client *uclient;
339 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
342 *tconn = rx_ConnectionOf(acall);
346 tclient = h_FindClient_r(*tconn);
348 ViceLog(0, ("CallPreamble: Couldn't get client.\n"));
352 thost = tclient->host;
353 if (tclient->prfail == 1) { /* couldn't get the CPS */
355 h_ReleaseClient_r(tclient);
357 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
361 retry_flag = 0; /* Retry once */
363 /* Take down the old connection and re-read the key file */
365 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
366 #ifdef AFS_PTHREAD_ENV
367 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
369 /* Is it still necessary to drop this? We hit the net, we should... */
375 code = hpr_Initialize(&uclient);
378 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
381 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
384 h_ReleaseClient_r(tclient);
387 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
391 tclient->prfail = 2; /* Means re-eval client's cps */
392 h_ReleaseClient_r(tclient);
397 tclient->LastCall = thost->LastCall = FT_ApproxTime();
398 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
399 thost->ActiveCall = thost->LastCall;
402 if (thost->hostFlags & HOSTDELETED) {
404 ("Discarded a packet for deleted host %s:%d\n",
405 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
406 code = VBUSY; /* raced, so retry */
407 } else if ((thost->hostFlags & VENUSDOWN)
408 || (thost->hostFlags & HFE_LATER)) {
409 if (BreakDelayedCallBacks_r(thost)) {
411 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
412 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
413 ntohs(rxr_PortOf(*tconn))));
414 if (MultiProbeAlternateAddress_r(thost)) {
416 ("MultiProbe failed to find new address for host %s:%d\n",
417 afs_inet_ntoa_r(thost->host, hoststr),
418 ntohs(thost->port)));
422 ("MultiProbe found new address for host %s:%d\n",
423 afs_inet_ntoa_r(thost->host, hoststr),
424 ntohs(thost->port)));
425 if (BreakDelayedCallBacks_r(thost)) {
427 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
428 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
429 ntohs(rxr_PortOf(*tconn))));
438 h_ReleaseClient_r(tclient);
448 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
452 struct client *tclient;
456 tclient = h_FindClient_r(aconn);
459 thost = tclient->host;
460 if (thost->hostFlags & HERRORTRANS)
462 h_ReleaseClient_r(tclient);
465 if (ahost != thost) {
466 /* host/client recycle */
467 char hoststr[16], hoststr2[16];
468 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
470 afs_inet_ntoa_r(ahost->host, hoststr),
473 afs_inet_ntoa_r(thost->host, hoststr2),
477 /* return the reference taken in CallPreamble */
481 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
482 afs_inet_ntoa_r(thost->host, hoststr),
487 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
488 * does not decrement refcount on client->host */
493 return (translate ? sys_error_to_et(ret) : ret);
497 * Returns the volume and vnode pointers associated with file Fid; the lock
498 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
499 * are incremented and they must be eventualy released.
502 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
503 Vnode ** vptr, int lock)
506 Error local_errorCode, errorCode = -1;
507 static struct timeval restartedat = { 0, 0 };
509 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
511 if ((*volptr) == 0) {
516 #ifdef AFS_DEMAND_ATTACH_FS
522 #ifdef AFS_PTHREAD_ENV
523 static const struct timespec timeout_ts = { 0, 0 };
524 static const struct timespec * const ts = &timeout_ts;
526 static const struct timespec * const ts = NULL;
530 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
531 fid->Volume, ts, cbv);
536 if ((errorCode == VOFFLINE) && (VInit < 2)) {
537 /* The volume we want may not be attached yet because
538 * the volume initialization is not yet complete.
539 * We can do several things:
540 * 1. return -1, which will cause users to see
541 * "connection timed out". This is more or
542 * less the same as always, except that the servers
543 * may appear to bounce up and down while they
544 * are actually restarting.
545 * 2. return VBUSY which will cause clients to
546 * sleep and retry for 6.5 - 15 minutes, depending
547 * on what version of the CM they are running. If
548 * the file server takes longer than that interval
549 * to attach the desired volume, then the application
550 * will see an ENODEV or EIO. This approach has
551 * the advantage that volumes which have been attached
552 * are immediately available, it keeps the server's
553 * immediate backlog low, and the call is interruptible
554 * by the user. Users see "waiting for busy volume."
555 * 3. sleep here and retry. Some people like this approach
556 * because there is no danger of seeing errors. However,
557 * this approach only works with a bounded number of
558 * clients, since the pending queues will grow without
559 * stopping. It might be better to find a way to take
560 * this call and stick it back on a queue in order to
561 * recycle this thread for a different request.
562 * 4. Return a new error code, which new cache managers will
563 * know enough to interpret as "sleep and retry", without
564 * the upper bound of 6-15 minutes that is imposed by the
565 * VBUSY handling. Users will see "waiting for
566 * busy volume," so they know that something is
567 * happening. Old cache managers must be able to do
568 * something reasonable with this, for instance, mark the
569 * server down. Fortunately, any error code < 0
570 * will elicit that behavior. See #1.
571 * 5. Some combination of the above. I like doing #2 for 10
572 * minutes, followed by #4. 3.1b and 3.2 cache managers
573 * will be fine as long as the restart period is
574 * not longer than 6.5 minutes, otherwise they may
575 * return ENODEV to users. 3.3 cache managers will be
576 * fine for 10 minutes, then will return
577 * ETIMEDOUT. 3.4 cache managers will just wait
578 * until the call works or fails definitively.
579 * NB. The problem with 2,3,4,5 is that old clients won't
580 * fail over to an alternate read-only replica while this
581 * server is restarting. 3.4 clients will fail over right away.
583 if (restartedat.tv_sec == 0) {
584 /* I'm not really worried about when we restarted, I'm */
585 /* just worried about when the first VBUSY was returned. */
586 FT_GetTimeOfDay(&restartedat, 0);
589 afs_perfstats.fs_nBusies++;
592 return (busyonrst ? VBUSY : restarting);
595 FT_GetTimeOfDay(&now, 0);
596 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
599 afs_perfstats.fs_nBusies++;
602 return (busyonrst ? VBUSY : restarting);
608 /* allow read operations on busy volume.
609 * must check local_errorCode because demand attach fs
610 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
611 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
612 #ifdef AFS_DEMAND_ATTACH_FS
613 /* DAFS case is complicated by the fact that local_errorCode can
614 * be VBUSY in cases where the volume is truly offline */
616 /* volume is in VOL_STATE_UNATTACHED */
619 #endif /* AFS_DEMAND_ATTACH_FS */
622 } else if (errorCode)
629 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
632 if ((*vptr)->disk.uniquifier != fid->Unique) {
633 VPutVnode(&fileCode, *vptr);
634 osi_Assert(fileCode == 0);
636 return (VNOVNODE); /* return the right error code, at least */
641 static_inline afs_int32
642 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
644 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
648 * This routine returns the ACL associated with the targetptr. If the
649 * targetptr isn't a directory, we access its parent dir and get the ACL
650 * thru the parent; in such case the parent's vnode is returned in
654 SetAccessList(Vnode ** targetptr, Volume ** volume,
655 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
656 AFSFid * Fid, int Lock)
658 if ((*targetptr)->disk.type == vDirectory) {
660 *ACL = VVnodeACL(*targetptr);
661 *ACLSize = VAclSize(*targetptr);
664 osi_Assert(Fid != 0);
669 parentvnode = (*targetptr)->disk.parent;
670 VPutVnode(&errorCode, *targetptr);
674 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
677 *ACL = VVnodeACL(*parent);
678 *ACLSize = VAclSize(*parent);
679 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
681 if ((*targetptr)->disk.parent != parentvnode) {
682 VPutVnode(&errorCode, *parent);
693 /* Must not be called with H_LOCK held */
695 client_CheckRights(struct client *client, struct acl_accessList *ACL,
699 ObtainReadLock(&client->lock);
700 if (client->CPS.prlist_len > 0 && !client->deleted &&
701 client->host && !(client->host->hostFlags & HOSTDELETED))
702 acl_CheckRights(ACL, &client->CPS, rights);
703 ReleaseReadLock(&client->lock);
706 /* Must not be called with H_LOCK held */
708 client_HasAsMember(struct client *client, afs_int32 id)
712 ObtainReadLock(&client->lock);
713 if (client->CPS.prlist_len > 0 && !client->deleted &&
714 client->host && !(client->host->hostFlags & HOSTDELETED))
715 code = acl_IsAMember(id, &client->CPS);
716 ReleaseReadLock(&client->lock);
721 * Compare the directory's ACL with the user's access rights in the client
722 * connection and return the user's and everybody else's access permissions
723 * in rights and anyrights, respectively
726 GetRights(struct client *client, struct acl_accessList *ACL,
727 afs_int32 * rights, afs_int32 * anyrights)
729 extern prlist SystemAnyUserCPS;
730 afs_int32 hrights = 0;
731 #ifndef AFS_PTHREAD_ENV
735 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
736 ViceLog(0, ("CheckRights failed\n"));
741 client_CheckRights(client, ACL, rights);
743 /* wait if somebody else is already doing the getCPS call */
745 while (client->host->hostFlags & HCPS_INPROGRESS) {
746 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
747 #ifdef AFS_PTHREAD_ENV
748 CV_WAIT(&client->host->cond, &host_glock_mutex);
749 #else /* AFS_PTHREAD_ENV */
751 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
752 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
753 #endif /* AFS_PTHREAD_ENV */
756 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
759 ("CheckRights: len=%u, for host=%s:%d\n",
760 client->host->hcps.prlist_len,
761 afs_inet_ntoa_r(client->host->host, hoststr),
762 ntohs(client->host->port)));
764 acl_CheckRights(ACL, &client->host->hcps, &hrights);
766 /* Allow system:admin the rights given with the -implicit option */
767 if (client_HasAsMember(client, SystemId))
768 *rights |= implicitAdminRights;
771 *anyrights |= hrights;
778 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
779 * a System:Administrator)
782 VanillaUser(struct client *client)
784 if (client_HasAsMember(client, SystemId))
785 return (0); /* not a system administrator, then you're "vanilla" */
792 * This unusual afs_int32-parameter routine encapsulates all volume package related
793 * operations together in a single function; it's called by almost all AFS
797 GetVolumePackageWithCall(struct rx_connection *tcon, struct VCallByVol *cbv,
798 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
799 int chkforDir, Vnode ** parent, struct client **client,
800 int locktype, afs_int32 * rights, afs_int32 * anyrights)
802 struct acl_accessList *aCL; /* Internal access List */
803 int aCLSize; /* size of the access list */
804 Error errorCode = 0; /* return code to caller */
806 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
809 if (chkforDir == MustNOTBeDIR
810 && ((*targetptr)->disk.type == vDirectory))
812 else if (chkforDir == MustBeDIR
813 && ((*targetptr)->disk.type != vDirectory))
817 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
818 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
819 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
821 if (chkforDir == MustBeDIR)
822 osi_Assert((*parent) == 0);
824 if ((errorCode = GetClient(tcon, client)) != 0)
829 GetRights(*client, aCL, rights, anyrights);
830 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
831 if ((*targetptr)->disk.type != vDirectory) {
832 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
833 if ((*targetptr)->disk.owner == (*client)->ViceId)
834 (*rights) |= PRSFS_ADMINISTER;
836 (*rights) &= ~PRSFS_ADMINISTER;
838 #ifdef ADMIN_IMPLICIT_LOOKUP
839 /* admins get automatic lookup on everything */
840 if (!VanillaUser(*client))
841 (*rights) |= PRSFS_LOOKUP;
842 #endif /* ADMIN_IMPLICIT_LOOKUP */
845 } /*GetVolumePackage */
847 static_inline afs_int32
848 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
849 Vnode ** targetptr, int chkforDir, Vnode ** parent,
850 struct client **client, int locktype, afs_int32 * rights,
851 afs_int32 * anyrights)
853 return GetVolumePackageWithCall(tcon, NULL, Fid, volptr, targetptr,
854 chkforDir, parent, client, locktype,
860 * This is the opposite of GetVolumePackage(), and is always used at the end of
861 * AFS calls to put back all used vnodes and the volume in the proper order!
864 PutVolumePackageWithCall(Vnode * parentwhentargetnotdir, Vnode * targetptr,
865 Vnode * parentptr, Volume * volptr,
866 struct client **client, struct VCallByVol *cbv)
868 Error fileCode = 0; /* Error code returned by the volume package */
870 if (parentwhentargetnotdir) {
871 VPutVnode(&fileCode, parentwhentargetnotdir);
872 osi_Assert(!fileCode || (fileCode == VSALVAGE));
875 VPutVnode(&fileCode, targetptr);
876 osi_Assert(!fileCode || (fileCode == VSALVAGE));
879 VPutVnode(&fileCode, parentptr);
880 osi_Assert(!fileCode || (fileCode == VSALVAGE));
883 VPutVolumeWithCall(volptr, cbv);
888 } /*PutVolumePackage */
891 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
892 Vnode * parentptr, Volume * volptr, struct client **client)
894 PutVolumePackageWithCall(parentwhentargetnotdir, targetptr, parentptr,
895 volptr, client, NULL);
899 VolumeOwner(struct client *client, Vnode * targetptr)
901 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
904 return (client->ViceId == owner);
907 * We don't have to check for host's cps since only regular
908 * viceid are volume owners.
910 return (client_HasAsMember(client, owner));
916 VolumeRootVnode(Vnode * targetptr)
918 return ((targetptr->vnodeNumber == ROOTVNODE)
919 && (targetptr->disk.uniquifier == 1));
921 } /*VolumeRootVnode */
924 * Check if target file has the proper access permissions for the Fetch
925 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
926 * StoreStatus) related calls
928 /* this code should probably just set a "priv" flag where all the audit events
929 * are now, and only generate the audit event once at the end of the routine,
930 * thus only generating the event if all the checks succeed, but only because
931 * of the privilege XXX
934 Check_PermissionRights(Vnode * targetptr, struct client *client,
935 afs_int32 rights, int CallingRoutine,
936 AFSStoreStatus * InStatus)
939 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
940 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
941 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
943 if (CallingRoutine & CHK_FETCH) {
944 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
945 if (targetptr->disk.type == vDirectory
946 || targetptr->disk.type == vSymlink) {
947 if (!(rights & PRSFS_LOOKUP)
948 #ifdef ADMIN_IMPLICIT_LOOKUP
949 /* grant admins fetch on all directories */
950 && VanillaUser(client)
951 #endif /* ADMIN_IMPLICIT_LOOKUP */
952 && !VolumeOwner(client, targetptr))
955 /* must have read access, or be owner and have insert access */
956 if (!(rights & PRSFS_READ)
957 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
958 && (client->ViceId != AnonymousID))))
961 if (CallingRoutine == CHK_FETCHDATA
962 && targetptr->disk.type == vFile)
963 #ifdef USE_GROUP_PERMS
964 if (!OWNSp(client, targetptr)
965 && !client_HasAsMember(client, targetptr->disk.owner)) {
967 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
971 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
976 * The check with the ownership below is a kludge to allow
977 * reading of files created with no read permission. The owner
978 * of the file is always allowed to read it.
980 if ((client->ViceId != targetptr->disk.owner)
981 && VanillaUser(client))
983 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
984 modeBits) ? 0 : EACCES);
986 } else { /* !VanillaUser(client) && !FetchData */
988 osi_audit(PrivilegeEvent, 0, AUD_ID,
989 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
992 } else { /* a store operation */
993 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
994 && (CallingRoutine != CHK_STOREACL)
995 && (targetptr->disk.type == vFile)) {
996 /* bypass protection checks on first store after a create
997 * for the creator; also prevent chowns during this time
998 * unless you are a system administrator */
999 /****** InStatus->Owner && UnixModeBits better be SET!! */
1000 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1003 else if (VanillaUser(client))
1004 return (EPERM); /* Was EACCES */
1006 osi_audit(PrivilegeEvent, 0, AUD_ID,
1007 (client ? client->ViceId : 0), AUD_INT,
1008 CallingRoutine, AUD_END);
1011 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1012 osi_audit(PrivilegeEvent, 0, AUD_ID,
1013 (client ? client->ViceId : 0), AUD_INT,
1014 CallingRoutine, AUD_END);
1016 if (readonlyServer) {
1019 if (CallingRoutine == CHK_STOREACL) {
1020 if (!(rights & PRSFS_ADMINISTER)
1021 && !VolumeOwner(client, targetptr))
1023 } else { /* store data or status */
1024 /* watch for chowns and chgrps */
1025 if (CHOWN(InStatus, targetptr)
1026 || CHGRP(InStatus, targetptr)) {
1029 else if (VanillaUser(client))
1030 return (EPERM); /* Was EACCES */
1032 osi_audit(PrivilegeEvent, 0, AUD_ID,
1033 (client ? client->ViceId : 0), AUD_INT,
1034 CallingRoutine, AUD_END);
1036 /* must be sysadmin to set suid/sgid bits */
1037 if ((InStatus->Mask & AFS_SETMODE) &&
1039 (InStatus->UnixModeBits & 0xc00) != 0) {
1041 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1045 if (VanillaUser(client))
1048 osi_audit(PrivSetID, 0, AUD_ID,
1049 (client ? client->ViceId : 0), AUD_INT,
1050 CallingRoutine, AUD_END);
1052 if (CallingRoutine == CHK_STOREDATA) {
1055 if (!(rights & PRSFS_WRITE))
1057 /* Next thing is tricky. We want to prevent people
1058 * from writing files sans 0200 bit, but we want
1059 * creating new files with 0444 mode to work. We
1060 * don't check the 0200 bit in the "you are the owner"
1061 * path above, but here we check the bit. However, if
1062 * you're a system administrator, we ignore the 0200
1063 * bit anyway, since you may have fchowned the file,
1065 #ifdef USE_GROUP_PERMS
1066 if ((targetptr->disk.type == vFile)
1067 && VanillaUser(client)) {
1068 if (!OWNSp(client, targetptr)
1069 && !client_HasAsMember(client, targetptr->disk.owner)) {
1071 ((GROUPWRITE & targetptr->disk.modeBits)
1075 ((OWNERWRITE & targetptr->disk.modeBits)
1080 if ((targetptr->disk.type != vDirectory)
1081 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1084 if (VanillaUser(client))
1087 osi_audit(PrivilegeEvent, 0, AUD_ID,
1088 (client ? client->ViceId : 0),
1089 AUD_INT, CallingRoutine, AUD_END);
1091 } else { /* a status store */
1094 if (targetptr->disk.type == vDirectory) {
1095 if (!(rights & PRSFS_DELETE)
1096 && !(rights & PRSFS_INSERT))
1098 } else { /* a file or symlink */
1099 if (!(rights & PRSFS_WRITE))
1109 } /*Check_PermissionRights */
1113 * The Access List information is converted from its internal form in the
1114 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1115 * external form and returned back to the caller, via the AccessList
1119 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1120 struct AFSOpaque *AccessList)
1122 char *eACL; /* External access list placeholder */
1124 if (acl_Externalize_pr
1125 (hpr_IdToName, (targetptr->disk.type ==
1126 vDirectory ? VVnodeACL(targetptr) :
1127 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1130 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1131 acl_FreeExternalACL(&eACL);
1134 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1135 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1137 acl_FreeExternalACL(&eACL);
1140 } /*RXFetch_AccessList */
1144 * The Access List information is converted from its external form in the
1145 * input AccessList structure to the internal representation and copied into
1146 * the target dir's vnode storage.
1149 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1151 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1153 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1156 if ((newACL->size + 4) > VAclSize(targetptr))
1158 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1159 acl_FreeACL(&newACL);
1162 } /*RXStore_AccessList */
1165 /* In our current implementation, each successive data store (new file
1166 * data version) creates a new inode. This function creates the new
1167 * inode, copies the old inode's contents to the new one, remove the old
1168 * inode (i.e. decrement inode count -- if it's currently used the delete
1169 * will be delayed), and modify some fields (i.e. vnode's
1170 * disk.inodeNumber and cloned)
1172 #define COPYBUFFSIZE 8192
1173 #define MAXFSIZE (~(afs_fsize_t) 0)
1175 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1178 Inode nearInode AFS_UNUSED;
1185 int rc; /* return code */
1186 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1187 FdHandle_t *targFdP; /* Source Inode file handle */
1188 FdHandle_t *newFdP; /* Dest Inode file handle */
1190 if (targetptr->disk.type == vDirectory)
1191 DFlush(); /* just in case? */
1193 VN_GET_LEN(size, targetptr);
1201 buff = (char *)malloc(COPYBUFFSIZE);
1206 ino = VN_GET_INO(targetptr);
1207 if (!VALID_INO(ino)) {
1209 VTakeOffline(volptr);
1210 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1214 targFdP = IH_OPEN(targetptr->handle);
1215 if (targFdP == NULL) {
1218 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1219 targetptr->vnodeNumber, V_id(volptr), rc));
1221 VTakeOffline(volptr);
1225 nearInode = VN_GET_INO(targetptr);
1227 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1228 VPartitionPath(V_partition(volptr)), nearInode,
1229 V_id(volptr), targetptr->vnodeNumber,
1230 targetptr->disk.uniquifier,
1231 (int)targetptr->disk.dataVersion);
1232 if (!VALID_INO(ino)) {
1234 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1235 volptr->partition->name, V_id(volptr), errno));
1240 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1241 newFdP = IH_OPEN(newH);
1242 osi_Assert(newFdP != NULL);
1246 if (size > COPYBUFFSIZE) { /* more than a buffer */
1247 length = COPYBUFFSIZE;
1248 size -= COPYBUFFSIZE;
1253 rdlen = FDH_PREAD(targFdP, buff, length, done);
1254 if (rdlen == length) {
1255 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1259 /* Callers of this function are not prepared to recover
1260 * from error that put the filesystem in an inconsistent
1261 * state. Make sure that we force the volume off-line if
1262 * we some error other than ENOSPC - 4.29.99)
1264 * In case we are unable to write the required bytes, and the
1265 * error code indicates that the disk is full, we roll-back to
1266 * the initial state.
1268 if ((rdlen != length) || (wrlen != length)) {
1269 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1271 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1272 volptr->partition->name, V_id(volptr)));
1273 /* remove destination inode which was partially copied till now */
1274 FDH_REALLYCLOSE(newFdP);
1276 FDH_REALLYCLOSE(targFdP);
1277 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1280 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1281 rc, V_id(volptr), volptr->partition->name));
1282 VTakeOffline(volptr);
1287 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1288 * since we never do any I/O anywhere near 2^32 bytes at a
1289 * time, just case to an unsigned int for printing */
1292 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1293 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1294 (unsigned)wrlen, errno));
1295 #if defined(AFS_DEMAND_ATTACH_FS)
1296 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1298 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1300 /* Decrement this inode so salvager doesn't find it. */
1301 FDH_REALLYCLOSE(newFdP);
1303 FDH_REALLYCLOSE(targFdP);
1304 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1306 VTakeOffline(volptr);
1310 #ifndef AFS_PTHREAD_ENV
1312 #endif /* !AFS_PTHREAD_ENV */
1314 FDH_REALLYCLOSE(targFdP);
1315 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1316 V_parentId(volptr));
1318 IH_RELEASE(targetptr->handle);
1320 rc = FDH_SYNC(newFdP);
1321 osi_Assert(rc == 0);
1323 targetptr->handle = newH;
1324 VN_SET_INO(targetptr, ino);
1325 targetptr->disk.cloned = 0;
1326 /* Internal change to vnode, no user level change to volume - def 5445 */
1327 targetptr->changed_oldTime = 1;
1329 return 0; /* success */
1333 * Common code to handle with removing the Name (file when it's called from
1334 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1335 * given directory, parentptr.
1337 int DT1 = 0, DT0 = 0;
1339 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1340 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1342 DirHandle childdir; /* Handle for dir package I/O */
1343 Error errorCode = 0;
1347 /* watch for invalid names */
1348 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1351 if (CheckLength(volptr, parentptr, -1)) {
1352 VTakeOffline(volptr);
1356 if (parentptr->disk.cloned) {
1357 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1358 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1360 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1366 /* check that the file is in the directory */
1367 SetDirHandle(dir, parentptr);
1368 if (afs_dir_Lookup(dir, Name, fileFid))
1370 fileFid->Volume = V_id(volptr);
1372 /* just-in-case check for something causing deadlock */
1373 if (fileFid->Vnode == parentptr->vnodeNumber)
1376 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1380 if (ChkForDir == MustBeDIR) {
1381 if ((*targetptr)->disk.type != vDirectory)
1383 } else if ((*targetptr)->disk.type == vDirectory)
1386 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1388 * If the uniquifiers dont match then instead of asserting
1389 * take the volume offline and return VSALVAGE
1391 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1392 VTakeOffline(volptr);
1394 ("Volume %u now offline, must be salvaged.\n",
1396 errorCode = VSALVAGE;
1400 if (ChkForDir == MustBeDIR) {
1401 SetDirHandle(&childdir, *targetptr);
1402 if (afs_dir_IsEmpty(&childdir) != 0)
1406 (*targetptr)->delete = 1;
1407 } else if ((--(*targetptr)->disk.linkCount) == 0)
1408 (*targetptr)->delete = 1;
1409 if ((*targetptr)->delete) {
1410 if (VN_GET_INO(*targetptr)) {
1412 IH_REALLYCLOSE((*targetptr)->handle);
1414 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1415 V_parentId(volptr));
1416 IH_RELEASE((*targetptr)->handle);
1417 if (errorCode == -1) {
1419 ("DT: inode=%s, name=%s, errno=%d\n",
1420 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1422 if (errno != ENOENT)
1424 VTakeOffline(volptr);
1426 ("Volume %u now offline, must be salvaged.\n",
1434 VN_SET_INO(*targetptr, (Inode) 0);
1436 afs_fsize_t adjLength;
1437 VN_GET_LEN(adjLength, *targetptr);
1438 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1442 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1444 code = afs_dir_Delete(dir, Name);
1447 ("Error %d deleting %s\n", code,
1448 (((*targetptr)->disk.type ==
1449 Directory) ? "directory" : "file")));
1450 VTakeOffline(volptr);
1452 ("Volume %u now offline, must be salvaged.\n",
1465 * This routine updates the parent directory's status block after the
1466 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1467 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1471 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1472 int author, int linkcount,
1473 #if FS_STATS_DETAILED
1474 char a_inSameNetwork
1475 #endif /* FS_STATS_DETAILED */
1478 afs_fsize_t newlength; /* Holds new directory length */
1479 afs_fsize_t parentLength;
1481 #if FS_STATS_DETAILED
1482 Date currDate; /*Current date */
1483 int writeIdx; /*Write index to bump */
1484 int timeIdx; /*Authorship time index to bump */
1485 #endif /* FS_STATS_DETAILED */
1487 parentptr->disk.dataVersion++;
1488 newlength = (afs_fsize_t) afs_dir_Length(dir);
1490 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1491 * (create, symlink, link, makedir) so we need to check if we have enough space
1492 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1493 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1495 VN_GET_LEN(parentLength, parentptr);
1496 if (nBlocks(newlength) != nBlocks(parentLength)) {
1497 VAdjustDiskUsage(&errorCode, volptr,
1498 (nBlocks(newlength) - nBlocks(parentLength)),
1499 (nBlocks(newlength) - nBlocks(parentLength)));
1501 VN_SET_LEN(parentptr, newlength);
1503 #if FS_STATS_DETAILED
1505 * Update directory write stats for this volume. Note that the auth
1506 * counter is located immediately after its associated ``distance''
1509 if (a_inSameNetwork)
1510 writeIdx = VOL_STATS_SAME_NET;
1512 writeIdx = VOL_STATS_DIFF_NET;
1513 V_stat_writes(volptr, writeIdx)++;
1514 if (author != AnonymousID) {
1515 V_stat_writes(volptr, writeIdx + 1)++;
1519 * Update the volume's authorship information in response to this
1520 * directory operation. Get the current time, decide to which time
1521 * slot this operation belongs, and bump the appropriate slot.
1523 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1525 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1526 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1527 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1528 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1529 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1530 if (parentptr->disk.author == author) {
1531 V_stat_dirSameAuthor(volptr, timeIdx)++;
1533 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1535 #endif /* FS_STATS_DETAILED */
1537 parentptr->disk.author = author;
1538 parentptr->disk.linkCount = linkcount;
1539 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1540 parentptr->disk.serverModifyTime = FT_ApproxTime();
1541 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1546 * Update the target file's (or dir's) status block after the specified
1547 * operation is complete. Note that some other fields maybe updated by
1548 * the individual module.
1551 /* XXX INCOMPLETE - More attention is needed here! */
1553 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1554 struct client *client, AFSStoreStatus * InStatus,
1555 Vnode * parentptr, Volume * volptr,
1558 #if FS_STATS_DETAILED
1559 Date currDate; /*Current date */
1560 int writeIdx; /*Write index to bump */
1561 int timeIdx; /*Authorship time index to bump */
1562 #endif /* FS_STATS_DETAILED */
1564 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1565 targetptr->disk.parent = parentptr->vnodeNumber;
1566 VN_SET_LEN(targetptr, length);
1567 /* targetptr->disk.group = 0; save some cycles */
1568 targetptr->disk.modeBits = 0777;
1569 targetptr->disk.owner = client->ViceId;
1570 targetptr->disk.dataVersion = 0; /* consistent with the client */
1571 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1572 /* the inode was created in Alloc_NewVnode() */
1574 #if FS_STATS_DETAILED
1576 * Update file write stats for this volume. Note that the auth
1577 * counter is located immediately after its associated ``distance''
1580 if (client->InSameNetwork)
1581 writeIdx = VOL_STATS_SAME_NET;
1583 writeIdx = VOL_STATS_DIFF_NET;
1584 V_stat_writes(volptr, writeIdx)++;
1585 if (client->ViceId != AnonymousID) {
1586 V_stat_writes(volptr, writeIdx + 1)++;
1590 * We only count operations that DON'T involve creating new objects
1591 * (files, symlinks, directories) or simply setting status as
1592 * authorship-change operations.
1594 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1596 * Update the volume's authorship information in response to this
1597 * file operation. Get the current time, decide to which time
1598 * slot this operation belongs, and bump the appropriate slot.
1600 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1603 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1604 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1605 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1606 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1607 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1608 VOL_STATS_TIME_IDX_5);
1609 if (targetptr->disk.author == client->ViceId) {
1610 V_stat_fileSameAuthor(volptr, timeIdx)++;
1612 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1615 #endif /* FS_STATS_DETAILED */
1617 if (!(Caller & TVS_SSTATUS))
1618 targetptr->disk.author = client->ViceId;
1619 if (Caller & TVS_SDATA) {
1620 targetptr->disk.dataVersion++;
1621 if (VanillaUser(client)) {
1622 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1623 #ifdef CREATE_SGUID_ADMIN_ONLY
1624 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1628 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1629 /* store status, must explicitly request to change the date */
1630 if (InStatus->Mask & AFS_SETMODTIME)
1631 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1632 } else { /* other: date always changes, but perhaps to what is specified by caller */
1633 targetptr->disk.unixModifyTime =
1634 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1635 ClientModTime : FT_ApproxTime());
1637 if (InStatus->Mask & AFS_SETOWNER) {
1638 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1639 if (VanillaUser(client)) {
1640 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1641 #ifdef CREATE_SGUID_ADMIN_ONLY
1642 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1645 targetptr->disk.owner = InStatus->Owner;
1646 if (VolumeRootVnode(targetptr)) {
1647 Error errorCode = 0; /* what should be done with this? */
1649 V_owner(targetptr->volumePtr) = InStatus->Owner;
1650 VUpdateVolume(&errorCode, targetptr->volumePtr);
1653 if (InStatus->Mask & AFS_SETMODE) {
1654 int modebits = InStatus->UnixModeBits;
1655 #define CREATE_SGUID_ADMIN_ONLY 1
1656 #ifdef CREATE_SGUID_ADMIN_ONLY
1657 if (VanillaUser(client))
1658 modebits = modebits & 0777;
1660 if (VanillaUser(client)) {
1661 targetptr->disk.modeBits = modebits;
1663 targetptr->disk.modeBits = modebits;
1666 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1667 CHK_STOREDATA, AUD_END);
1671 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1672 CHK_STORESTATUS, AUD_END);
1679 targetptr->disk.serverModifyTime = FT_ApproxTime();
1680 if (InStatus->Mask & AFS_SETGROUP)
1681 targetptr->disk.group = InStatus->Group;
1682 /* vnode changed : to be written back by VPutVnode */
1683 targetptr->changed_newTime = 1;
1685 } /*Update_TargetVnodeStatus */
1689 * Fills the CallBack structure with the expiration time and type of callback
1690 * structure. Warning: this function is currently incomplete.
1693 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1695 /* CallBackTime could not be 0 */
1696 if (CallBackTime == 0) {
1697 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1698 CallBack->ExpirationTime = 0;
1700 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1701 CallBack->CallBackVersion = CALLBACK_VERSION;
1702 CallBack->CallBackType = CB_SHARED; /* The default for now */
1704 } /*SetCallBackStruct */
1708 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1709 * allocation; if some error occured (exceeded volume quota or partition
1710 * was full, or whatever), it frees the space back and returns the code.
1711 * We usually pre-adjust the volume space to make sure that there's
1712 * enough space before consuming some.
1715 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1716 afs_sfsize_t checkLength)
1721 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1723 VAdjustDiskUsage(&nc, volptr, -length, 0);
1724 if (rc == VOVERQUOTA) {
1726 ("Volume %u (%s) is full\n", V_id(volptr),
1730 if (rc == VDISKFULL) {
1732 ("Partition %s that contains volume %u is full\n",
1733 volptr->partition->name, V_id(volptr)));
1736 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1741 } /*AdjustDiskUsage */
1744 * Common code that handles the creation of a new file (SAFS_CreateFile and
1745 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1748 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1749 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1750 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1752 Error errorCode = 0; /* Error code returned back */
1755 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1759 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1760 BlocksPreallocatedForVnode))) {
1762 ("Insufficient space to allocate %lld blocks\n",
1763 (afs_intmax_t) BlocksPreallocatedForVnode));
1767 if (CheckLength(volptr, parentptr, -1)) {
1768 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1769 VTakeOffline(volptr);
1773 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1774 if (errorCode != 0) {
1775 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1778 OutFid->Volume = V_id(volptr);
1779 OutFid->Vnode = (*targetptr)->vnodeNumber;
1780 OutFid->Unique = (*targetptr)->disk.uniquifier;
1782 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1784 /* create the inode now itself */
1786 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1787 VPartitionPath(V_partition(volptr)), nearInode,
1788 V_id(volptr), (*targetptr)->vnodeNumber,
1789 (*targetptr)->disk.uniquifier, 1);
1791 /* error in creating inode */
1792 if (!VALID_INO(inode)) {
1794 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1795 (*targetptr)->volumePtr->header->diskstuff.id,
1796 (*targetptr)->vnodeNumber, errno));
1797 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1798 (*targetptr)->delete = 1; /* delete vnode */
1801 VN_SET_INO(*targetptr, inode);
1802 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1804 /* copy group from parent dir */
1805 (*targetptr)->disk.group = parentptr->disk.group;
1807 if (parentptr->disk.cloned) {
1808 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1809 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1810 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1811 /* delete the vnode previously allocated */
1812 (*targetptr)->delete = 1;
1813 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1814 IH_REALLYCLOSE((*targetptr)->handle);
1815 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1817 ("Alloc_NewVnode: partition %s idec %s failed\n",
1818 volptr->partition->name, PrintInode(stmp, inode)));
1819 IH_RELEASE((*targetptr)->handle);
1825 /* add the name to the directory */
1826 SetDirHandle(dir, parentptr);
1827 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1828 (*targetptr)->delete = 1;
1829 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1830 IH_REALLYCLOSE((*targetptr)->handle);
1831 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1833 ("Alloc_NewVnode: partition %s idec %s failed\n",
1834 volptr->partition->name, PrintInode(stmp, inode)));
1835 IH_RELEASE((*targetptr)->handle);
1841 } /*Alloc_NewVnode */
1845 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1849 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1851 int Time; /* Used for time */
1852 int writeVnode = targetptr->changed_oldTime; /* save original status */
1854 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1855 Time = FT_ApproxTime();
1856 switch (LockingType) {
1859 if (Time > targetptr->disk.lock.lockTime)
1860 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1862 Time += AFS_LOCKWAIT;
1863 if (LockingType == LockRead) {
1864 if ( !(rights & PRSFS_LOCK) &&
1865 !(rights & PRSFS_WRITE) &&
1866 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1869 if (targetptr->disk.lock.lockCount >= 0) {
1870 ++(targetptr->disk.lock.lockCount);
1871 targetptr->disk.lock.lockTime = Time;
1874 } else if (LockingType == LockWrite) {
1875 if ( !(rights & PRSFS_WRITE) &&
1876 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1879 if (targetptr->disk.lock.lockCount == 0) {
1880 targetptr->disk.lock.lockCount = -1;
1881 targetptr->disk.lock.lockTime = Time;
1887 Time += AFS_LOCKWAIT;
1888 if (targetptr->disk.lock.lockCount != 0)
1889 targetptr->disk.lock.lockTime = Time;
1894 if ((--targetptr->disk.lock.lockCount) <= 0)
1895 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1899 targetptr->changed_oldTime = writeVnode; /* restore old status */
1900 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1903 } /*HandleLocking */
1905 /* 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. */
1908 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1912 if (!(rights & Prfs_Mode))
1914 if ((targetptr->disk.type != vDirectory)
1915 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1921 * If some flags (i.e. min or max quota) are set, the volume's in disk
1922 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1923 * update, if applicable.
1926 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1927 char *Name, char *OfflineMsg, char *Motd)
1929 Error errorCode = 0;
1931 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1932 V_minquota(volptr) = StoreVolStatus->MinQuota;
1933 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1934 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1935 if (strlen(OfflineMsg) > 0) {
1936 strcpy(V_offlineMessage(volptr), OfflineMsg);
1938 if (strlen(Name) > 0) {
1939 strcpy(V_name(volptr), Name);
1941 #if OPENAFS_VOL_STATS
1943 * We don't overwrite the motd field, since it's now being used
1947 if (strlen(Motd) > 0) {
1948 strcpy(V_motd(volptr), Motd);
1950 #endif /* FS_STATS_DETAILED */
1951 VUpdateVolume(&errorCode, volptr);
1954 } /*RXUpdate_VolumeStatus */
1958 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1959 char **motd, Volume * volptr)
1963 status->Vid = V_id(volptr);
1964 status->ParentId = V_parentId(volptr);
1965 status->Online = V_inUse(volptr);
1966 status->InService = V_inService(volptr);
1967 status->Blessed = V_blessed(volptr);
1968 status->NeedsSalvage = V_needsSalvaged(volptr);
1969 if (VolumeWriteable(volptr))
1970 status->Type = ReadWrite;
1972 status->Type = ReadOnly;
1973 status->MinQuota = V_minquota(volptr);
1974 status->MaxQuota = V_maxquota(volptr);
1975 status->BlocksInUse = V_diskused(volptr);
1976 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1977 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1979 /* now allocate and copy these things; they're freed by the RXGEN stub */
1980 temp = strlen(V_name(volptr)) + 1;
1981 *name = malloc(temp);
1983 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
1985 strcpy(*name, V_name(volptr));
1986 temp = strlen(V_offlineMessage(volptr)) + 1;
1987 *offMsg = malloc(temp);
1989 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
1991 strcpy(*offMsg, V_offlineMessage(volptr));
1992 #if OPENAFS_VOL_STATS
1995 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
1997 strcpy(*motd, nullString);
1999 temp = strlen(V_motd(volptr)) + 1;
2000 *motd = malloc(temp);
2002 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2004 strcpy(*motd, V_motd(volptr));
2005 #endif /* OPENAFS_VOL_STATS */
2007 } /*RXGetVolumeStatus */
2011 FileNameOK(char *aname)
2016 /* watch for @sys on the right */
2017 if (strcmp(aname + i - 4, "@sys") == 0)
2020 while ((tc = *aname++)) {
2022 return 0; /* very bad character to encounter */
2024 return 1; /* file name is ok */
2030 * This variant of symlink is expressly to support the AFS/DFS translator
2031 * and is not supported by the AFS fileserver. We just return EINVAL.
2032 * The cache manager should not generate this call to an AFS cache manager.
2035 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2036 char *LinkContents, struct AFSStoreStatus *InStatus,
2037 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2038 struct AFSFetchStatus *OutDirStatus,
2039 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2045 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2046 struct FsCmdInputs * Inputs,
2047 struct FsCmdOutputs * Outputs)
2051 switch (Inputs->command) {
2055 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2056 Inputs->command, Outputs->code));
2061 static struct afs_buffer {
2062 struct afs_buffer *next;
2063 } *freeBufferList = 0;
2064 static int afs_buffersAlloced = 0;
2067 FreeSendBuffer(struct afs_buffer *adata)
2070 afs_buffersAlloced--;
2071 adata->next = freeBufferList;
2072 freeBufferList = adata;
2076 } /*FreeSendBuffer */
2078 /* allocate space for sender */
2080 AllocSendBuffer(void)
2082 struct afs_buffer *tp;
2085 afs_buffersAlloced++;
2086 if (!freeBufferList) {
2089 tmp = malloc(sendBufSize);
2091 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2095 tp = freeBufferList;
2096 freeBufferList = tp->next;
2100 } /*AllocSendBuffer */
2101 #endif /* HAVE_PIOV */
2104 * This routine returns the status info associated with the targetptr vnode
2105 * in the AFSFetchStatus structure. Some of the newer fields, such as
2106 * SegSize and Group are not yet implemented
2110 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2111 afs_int32 anyrights, Vnode * parentptr)
2113 /* initialize return status from a vnode */
2114 status->InterfaceVersion = 1;
2115 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2116 status->errorCode = 0;
2117 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2118 if (targetptr->disk.type == vFile)
2119 status->FileType = File;
2120 else if (targetptr->disk.type == vDirectory)
2121 status->FileType = Directory;
2122 else if (targetptr->disk.type == vSymlink)
2123 status->FileType = SymbolicLink;
2125 status->FileType = Invalid; /*invalid type field */
2126 status->LinkCount = targetptr->disk.linkCount;
2128 afs_fsize_t targetLen;
2129 VN_GET_LEN(targetLen, targetptr);
2130 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2132 status->DataVersion = targetptr->disk.dataVersion;
2133 status->Author = targetptr->disk.author;
2134 status->Owner = targetptr->disk.owner;
2135 status->CallerAccess = rights;
2136 status->AnonymousAccess = anyrights;
2137 status->UnixModeBits = targetptr->disk.modeBits;
2138 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2139 status->ParentVnode =
2140 (status->FileType ==
2141 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2142 status->ParentUnique =
2143 (status->FileType ==
2144 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2145 status->ServerModTime = targetptr->disk.serverModifyTime;
2146 status->Group = targetptr->disk.group;
2147 status->lockCount = targetptr->disk.lock.lockCount;
2148 status->errorCode = 0;
2154 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2155 afs_sfsize_t Pos, afs_sfsize_t Len,
2156 struct AFSFetchStatus *OutStatus,
2157 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2160 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2161 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2162 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2163 Error errorCode = 0; /* return code to caller */
2164 Error fileCode = 0; /* return code from vol package */
2165 Volume *volptr = 0; /* pointer to the volume */
2166 struct client *client = 0; /* pointer to the client data */
2167 struct rx_connection *tcon; /* the connection we're part of */
2169 afs_int32 rights, anyrights; /* rights for this and any user */
2170 struct client *t_client = NULL; /* tmp ptr to client data */
2171 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2172 struct VCallByVol tcbv, *cbv = NULL;
2173 static int remainder = 0; /* shared access protected by FS_LOCK */
2174 struct fsstats fsstats;
2175 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2176 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2178 #if FS_STATS_DETAILED
2179 int readIdx; /* Index of read stats array to bump */
2180 #endif /* FS_STATS_DETAILED */
2182 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2185 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2188 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2190 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2193 /* Get ptr to client data for user Id for logging */
2194 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2195 logHostAddr.s_addr = rxr_HostOf(tcon);
2197 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2198 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2199 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2201 queue_NodeInit(&tcbv);
2206 * Get volume/vnode for the fetched file; caller's access rights to
2207 * it are also returned
2210 GetVolumePackageWithCall(tcon, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2211 &parentwhentargetnotdir, &client, READ_LOCK,
2212 &rights, &anyrights)))
2215 SetVolumeSync(Sync, volptr);
2217 #if FS_STATS_DETAILED
2219 * Remember that another read operation was performed.
2222 if (client->InSameNetwork)
2223 readIdx = VOL_STATS_SAME_NET;
2225 readIdx = VOL_STATS_DIFF_NET;
2226 V_stat_reads(volptr, readIdx)++;
2227 if (client->ViceId != AnonymousID) {
2228 V_stat_reads(volptr, readIdx + 1)++;
2231 #endif /* FS_STATS_DETAILED */
2232 /* Check whether the caller has permission access to fetch the data */
2234 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2238 * Drop the read lock on the parent directory after saving the parent
2239 * vnode information we need to pass to GetStatus
2241 if (parentwhentargetnotdir != NULL) {
2242 tparentwhentargetnotdir = *parentwhentargetnotdir;
2243 VPutVnode(&fileCode, parentwhentargetnotdir);
2244 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2245 parentwhentargetnotdir = NULL;
2248 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
2250 /* actually do the data transfer */
2252 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2253 &bytesToXfer, &bytesXferred);
2255 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2261 /* write back the OutStatus from the target vnode */
2262 GetStatus(targetptr, OutStatus, rights, anyrights,
2263 &tparentwhentargetnotdir);
2265 /* if a r/w volume, promise a callback to the caller */
2266 if (VolumeWriteable(volptr))
2267 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2269 struct AFSFid myFid;
2270 memset(&myFid, 0, sizeof(struct AFSFid));
2271 myFid.Volume = Fid->Volume;
2272 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2276 /* Update and store volume/vnode and parent vnodes back */
2277 (void)PutVolumePackageWithCall(parentwhentargetnotdir, targetptr,
2278 (Vnode *) 0, volptr, &client, cbv);
2279 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2280 errorCode = CallPostamble(tcon, errorCode, thost);
2282 fsstats_FinishOp(&fsstats, errorCode);
2284 osi_auditU(acall, FetchDataEvent, errorCode,
2285 AUD_ID, t_client ? t_client->ViceId : 0,
2286 AUD_FID, Fid, AUD_END);
2289 } /*SRXAFS_FetchData */
2292 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2293 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2294 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2296 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2301 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2302 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2303 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2306 afs_sfsize_t tPos, tLen;
2308 tPos = (afs_sfsize_t) Pos;
2309 tLen = (afs_sfsize_t) Len;
2312 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2318 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2319 struct AFSOpaque * AccessList,
2320 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2322 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2323 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2324 Error errorCode = 0; /* return error code to caller */
2325 Volume *volptr = 0; /* pointer to the volume */
2326 struct client *client = 0; /* pointer to the client data */
2327 afs_int32 rights, anyrights; /* rights for this and any user */
2328 struct rx_connection *tcon = rx_ConnectionOf(acall);
2330 struct client *t_client = NULL; /* tmp ptr to client data */
2331 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2332 struct fsstats fsstats;
2334 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2337 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2340 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2342 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2345 /* Get ptr to client data for user Id for logging */
2346 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2347 logHostAddr.s_addr = rxr_HostOf(tcon);
2349 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2350 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2351 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2353 AccessList->AFSOpaque_len = 0;
2354 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2355 if (!AccessList->AFSOpaque_val) {
2356 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2360 * Get volume/vnode for the fetched file; caller's access rights to it
2364 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2365 &parentwhentargetnotdir, &client, READ_LOCK,
2366 &rights, &anyrights)))
2369 SetVolumeSync(Sync, volptr);
2371 /* Check whether we have permission to fetch the ACL */
2373 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2376 /* Get the Access List from the dir's vnode */
2378 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2381 /* Get OutStatus back From the target Vnode */
2382 GetStatus(targetptr, OutStatus, rights, anyrights,
2383 parentwhentargetnotdir);
2386 /* Update and store volume/vnode and parent vnodes back */
2387 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2390 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2391 AccessList->AFSOpaque_val));
2392 errorCode = CallPostamble(tcon, errorCode, thost);
2394 fsstats_FinishOp(&fsstats, errorCode);
2396 osi_auditU(acall, FetchACLEvent, errorCode,
2397 AUD_ID, t_client ? t_client->ViceId : 0,
2399 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2401 } /*SRXAFS_FetchACL */
2405 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2406 * merged into it when possible.
2410 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2411 struct AFSFetchStatus *OutStatus,
2412 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2414 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2415 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2416 Error errorCode = 0; /* return code to caller */
2417 Volume *volptr = 0; /* pointer to the volume */
2418 struct client *client = 0; /* pointer to the client data */
2419 afs_int32 rights, anyrights; /* rights for this and any user */
2420 struct client *t_client = NULL; /* tmp ptr to client data */
2421 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2422 struct rx_connection *tcon = rx_ConnectionOf(acall);
2424 /* Get ptr to client data for user Id for logging */
2425 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2426 logHostAddr.s_addr = rxr_HostOf(tcon);
2428 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2429 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2430 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2432 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2435 * Get volume/vnode for the fetched file; caller's rights to it are
2439 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2440 &parentwhentargetnotdir, &client, READ_LOCK,
2441 &rights, &anyrights)))
2442 goto Bad_FetchStatus;
2444 /* set volume synchronization information */
2445 SetVolumeSync(Sync, volptr);
2447 /* Are we allowed to fetch Fid's status? */
2448 if (targetptr->disk.type != vDirectory) {
2450 Check_PermissionRights(targetptr, client, rights,
2451 CHK_FETCHSTATUS, 0))) {
2452 if (rx_GetCallAbortCode(acall) == errorCode)
2453 rx_SetCallAbortCode(acall, 0);
2454 goto Bad_FetchStatus;
2458 /* set OutStatus From the Fid */
2459 GetStatus(targetptr, OutStatus, rights, anyrights,
2460 parentwhentargetnotdir);
2462 /* If a r/w volume, also set the CallBack state */
2463 if (VolumeWriteable(volptr))
2464 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2466 struct AFSFid myFid;
2467 memset(&myFid, 0, sizeof(struct AFSFid));
2468 myFid.Volume = Fid->Volume;
2469 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2473 /* Update and store volume/vnode and parent vnodes back */
2474 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2476 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2479 } /*SAFSS_FetchStatus */
2483 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2484 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2485 struct AFSVolSync * Sync)
2489 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2490 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2491 Error errorCode = 0; /* return code to caller */
2492 Volume *volptr = 0; /* pointer to the volume */
2493 struct client *client = 0; /* pointer to the client data */
2494 afs_int32 rights, anyrights; /* rights for this and any user */
2495 struct AFSFid *tfid; /* file id we're dealing with now */
2496 struct rx_connection *tcon = rx_ConnectionOf(acall);
2498 struct client *t_client = NULL; /* tmp pointer to the client data */
2499 struct fsstats fsstats;
2501 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2503 ViceLog(1, ("SAFS_BulkStatus\n"));
2505 AFSCallStats.TotalCalls++;
2507 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2508 if (nfiles <= 0) { /* Sanity check */
2510 goto Audit_and_Return;
2513 /* allocate space for return output parameters */
2514 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2515 malloc(nfiles * sizeof(struct AFSFetchStatus));
2516 if (!OutStats->AFSBulkStats_val) {
2517 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2519 OutStats->AFSBulkStats_len = nfiles;
2520 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2521 malloc(nfiles * sizeof(struct AFSCallBack));
2522 if (!CallBacks->AFSCBs_val) {
2523 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2525 CallBacks->AFSCBs_len = nfiles;
2527 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2528 goto Bad_BulkStatus;
2530 tfid = Fids->AFSCBFids_val;
2531 for (i = 0; i < nfiles; i++, tfid++) {
2533 * Get volume/vnode for the fetched file; caller's rights to it
2537 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2538 &parentwhentargetnotdir, &client, READ_LOCK,
2539 &rights, &anyrights)))
2540 goto Bad_BulkStatus;
2541 /* set volume synchronization information, but only once per call */
2543 SetVolumeSync(Sync, volptr);
2545 /* Are we allowed to fetch Fid's status? */
2546 if (targetptr->disk.type != vDirectory) {
2548 Check_PermissionRights(targetptr, client, rights,
2549 CHK_FETCHSTATUS, 0))) {
2550 if (rx_GetCallAbortCode(acall) == errorCode)
2551 rx_SetCallAbortCode(acall, 0);
2552 goto Bad_BulkStatus;
2556 /* set OutStatus From the Fid */
2557 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2558 anyrights, parentwhentargetnotdir);
2560 /* If a r/w volume, also set the CallBack state */
2561 if (VolumeWriteable(volptr))
2562 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2563 &CallBacks->AFSCBs_val[i]);
2565 struct AFSFid myFid;
2566 memset(&myFid, 0, sizeof(struct AFSFid));
2567 myFid.Volume = tfid->Volume;
2568 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2569 &CallBacks->AFSCBs_val[i]);
2572 /* put back the file ID and volume */
2573 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2575 parentwhentargetnotdir = (Vnode *) 0;
2576 targetptr = (Vnode *) 0;
2577 volptr = (Volume *) 0;
2578 client = (struct client *)0;
2582 /* Update and store volume/vnode and parent vnodes back */
2583 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2585 errorCode = CallPostamble(tcon, errorCode, thost);
2587 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2589 fsstats_FinishOp(&fsstats, errorCode);
2592 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2593 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2594 AUD_ID, t_client ? t_client->ViceId : 0,
2595 AUD_FIDS, Fids, AUD_END);
2598 } /*SRXAFS_BulkStatus */
2602 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2603 struct AFSBulkStats * OutStats,
2604 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2608 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2609 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2610 Error errorCode = 0; /* return code to caller */
2611 Volume *volptr = 0; /* pointer to the volume */
2612 struct client *client = 0; /* pointer to the client data */
2613 afs_int32 rights, anyrights; /* rights for this and any user */
2614 struct AFSFid *tfid; /* file id we're dealing with now */
2615 struct rx_connection *tcon;
2617 struct client *t_client = NULL; /* tmp ptr to client data */
2618 AFSFetchStatus *tstatus;
2619 int VolSync_set = 0;
2620 struct fsstats fsstats;
2622 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2624 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2626 AFSCallStats.TotalCalls++;
2628 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2629 if (nfiles <= 0) { /* Sanity check */
2631 goto Audit_and_Return;
2634 /* allocate space for return output parameters */
2635 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2636 malloc(nfiles * sizeof(struct AFSFetchStatus));
2637 if (!OutStats->AFSBulkStats_val) {
2638 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2640 OutStats->AFSBulkStats_len = nfiles;
2641 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2642 malloc(nfiles * sizeof(struct AFSCallBack));
2643 if (!CallBacks->AFSCBs_val) {
2644 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2646 CallBacks->AFSCBs_len = nfiles;
2648 /* Zero out return values to avoid leaking information on partial succes */
2649 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2650 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2651 memset(Sync, 0, sizeof(*Sync));
2653 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2654 goto Bad_InlineBulkStatus;
2657 tfid = Fids->AFSCBFids_val;
2658 for (i = 0; i < nfiles; i++, tfid++) {
2660 * Get volume/vnode for the fetched file; caller's rights to it
2664 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2665 &parentwhentargetnotdir, &client, READ_LOCK,
2666 &rights, &anyrights))) {
2667 tstatus = &OutStats->AFSBulkStats_val[i];
2668 tstatus->errorCode = errorCode;
2669 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2671 parentwhentargetnotdir = (Vnode *) 0;
2672 targetptr = (Vnode *) 0;
2673 volptr = (Volume *) 0;
2674 client = (struct client *)0;
2678 /* set volume synchronization information, but only once per call */
2680 SetVolumeSync(Sync, volptr);
2684 /* Are we allowed to fetch Fid's status? */
2685 if (targetptr->disk.type != vDirectory) {
2687 Check_PermissionRights(targetptr, client, rights,
2688 CHK_FETCHSTATUS, 0))) {
2689 tstatus = &OutStats->AFSBulkStats_val[i];
2690 tstatus->errorCode = errorCode;
2691 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2692 (Vnode *) 0, volptr, &client);
2693 parentwhentargetnotdir = (Vnode *) 0;
2694 targetptr = (Vnode *) 0;
2695 volptr = (Volume *) 0;
2696 client = (struct client *)0;
2701 /* set OutStatus From the Fid */
2702 GetStatus(targetptr,
2703 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2704 rights, anyrights, parentwhentargetnotdir);
2706 /* If a r/w volume, also set the CallBack state */
2707 if (VolumeWriteable(volptr))
2708 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2709 &CallBacks->AFSCBs_val[i]);
2711 struct AFSFid myFid;
2712 memset(&myFid, 0, sizeof(struct AFSFid));
2713 myFid.Volume = tfid->Volume;
2714 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2715 &CallBacks->AFSCBs_val[i]);
2718 /* put back the file ID and volume */
2719 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2721 parentwhentargetnotdir = (Vnode *) 0;
2722 targetptr = (Vnode *) 0;
2723 volptr = (Volume *) 0;
2724 client = (struct client *)0;
2727 Bad_InlineBulkStatus:
2728 /* Update and store volume/vnode and parent vnodes back */
2729 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2731 errorCode = CallPostamble(tcon, errorCode, thost);
2733 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2735 fsstats_FinishOp(&fsstats, errorCode);
2738 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2739 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2740 AUD_ID, t_client ? t_client->ViceId : 0,
2741 AUD_FIDS, Fids, AUD_END);
2744 } /*SRXAFS_InlineBulkStatus */
2748 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2749 struct AFSFetchStatus * OutStatus,
2750 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2753 struct rx_connection *tcon;
2755 struct client *t_client = NULL; /* tmp ptr to client data */
2756 struct fsstats fsstats;
2758 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2760 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2761 goto Bad_FetchStatus;
2763 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2766 code = CallPostamble(tcon, code, thost);
2768 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2770 fsstats_FinishOp(&fsstats, code);
2772 osi_auditU(acall, FetchStatusEvent, code,
2773 AUD_ID, t_client ? t_client->ViceId : 0,
2774 AUD_FID, Fid, AUD_END);
2777 } /*SRXAFS_FetchStatus */
2781 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2782 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2783 afs_fsize_t Length, afs_fsize_t FileLength,
2784 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2786 Vnode *targetptr = 0; /* pointer to input fid */
2787 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2788 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2789 Error errorCode = 0; /* return code for caller */
2790 Error fileCode = 0; /* return code from vol package */
2791 Volume *volptr = 0; /* pointer to the volume header */
2792 struct client *client = 0; /* pointer to client structure */
2793 afs_int32 rights, anyrights; /* rights for this and any user */
2794 struct client *t_client = NULL; /* tmp ptr to client data */
2795 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2796 struct rx_connection *tcon;
2798 struct fsstats fsstats;
2799 afs_sfsize_t bytesToXfer;
2800 afs_sfsize_t bytesXferred;
2801 static int remainder = 0;
2804 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2807 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2810 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2812 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2815 /* Get ptr to client data for user Id for logging */
2816 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2817 logHostAddr.s_addr = rxr_HostOf(tcon);
2819 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2820 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2821 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2824 * Get associated volume/vnode for the stored file; caller's rights
2828 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2829 &parentwhentargetnotdir, &client, WRITE_LOCK,
2830 &rights, &anyrights))) {
2834 /* set volume synchronization information */
2835 SetVolumeSync(Sync, volptr);
2837 if ((targetptr->disk.type == vSymlink)) {
2838 /* Should we return a better error code here??? */
2843 /* Check if we're allowed to store the data */
2845 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2851 * Drop the read lock on the parent directory after saving the parent
2852 * vnode information we need to pass to GetStatus
2854 if (parentwhentargetnotdir != NULL) {
2855 tparentwhentargetnotdir = *parentwhentargetnotdir;
2856 VPutVnode(&fileCode, parentwhentargetnotdir);
2857 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2858 parentwhentargetnotdir = NULL;
2861 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
2864 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2865 FileLength, (InStatus->Mask & AFS_FSYNC),
2866 &bytesToXfer, &bytesXferred);
2868 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2871 if (errorCode && (!targetptr->changed_newTime))
2874 /* Update the status of the target's vnode */
2875 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2876 targetptr, volptr, 0);
2878 /* Get the updated File's status back to the caller */
2879 GetStatus(targetptr, OutStatus, rights, anyrights,
2880 &tparentwhentargetnotdir);
2883 /* Update and store volume/vnode and parent vnodes back */
2884 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2886 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
2888 errorCode = CallPostamble(tcon, errorCode, thost);
2890 fsstats_FinishOp(&fsstats, errorCode);
2892 osi_auditU(acall, StoreDataEvent, errorCode,
2893 AUD_ID, t_client ? t_client->ViceId : 0,
2894 AUD_FID, Fid, AUD_END);
2896 } /*common_StoreData64 */
2899 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
2900 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
2901 afs_uint32 Length, afs_uint32 FileLength,
2902 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2904 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
2905 (0x7fffffff - Pos) < Length)
2908 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
2910 } /*SRXAFS_StoreData */
2913 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
2914 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
2915 afs_uint64 Length, afs_uint64 FileLength,
2916 struct AFSFetchStatus * OutStatus,
2917 struct AFSVolSync * Sync)
2921 afs_fsize_t tLength;
2922 afs_fsize_t tFileLength;
2924 tPos = (afs_fsize_t) Pos;
2925 tLength = (afs_fsize_t) Length;
2926 tFileLength = (afs_fsize_t) FileLength;
2929 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
2935 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
2936 struct AFSOpaque * AccessList,
2937 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2939 Vnode *targetptr = 0; /* pointer to input fid */
2940 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2941 Error errorCode = 0; /* return code for caller */
2942 struct AFSStoreStatus InStatus; /* Input status for fid */
2943 Volume *volptr = 0; /* pointer to the volume header */
2944 struct client *client = 0; /* pointer to client structure */
2945 afs_int32 rights, anyrights; /* rights for this and any user */
2946 struct rx_connection *tcon;
2948 struct client *t_client = NULL; /* tmp ptr to client data */
2949 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2950 struct fsstats fsstats;
2952 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
2954 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2957 /* Get ptr to client data for user Id for logging */
2958 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2959 logHostAddr.s_addr = rxr_HostOf(tcon);
2961 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
2962 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
2963 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2965 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
2967 InStatus.Mask = 0; /* not storing any status */
2970 * Get associated volume/vnode for the target dir; caller's rights
2971 * are also returned.
2974 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
2975 &parentwhentargetnotdir, &client, WRITE_LOCK,
2976 &rights, &anyrights))) {
2980 /* set volume synchronization information */
2981 SetVolumeSync(Sync, volptr);
2983 /* Check if we have permission to change the dir's ACL */
2985 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
2990 /* Build and store the new Access List for the dir */
2991 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
2995 targetptr->changed_newTime = 1; /* status change of directory */
2997 /* convert the write lock to a read lock before breaking callbacks */
2998 VVnodeWriteToRead(&errorCode, targetptr);
2999 osi_Assert(!errorCode || errorCode == VSALVAGE);
3001 /* break call backs on the directory */
3002 BreakCallBack(client->host, Fid, 0);
3004 /* Get the updated dir's status back to the caller */
3005 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3008 /* Update and store volume/vnode and parent vnodes back */
3009 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3011 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3012 errorCode = CallPostamble(tcon, errorCode, thost);
3014 fsstats_FinishOp(&fsstats, errorCode);
3016 osi_auditU(acall, StoreACLEvent, errorCode,
3017 AUD_ID, t_client ? t_client->ViceId : 0,
3018 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3021 } /*SRXAFS_StoreACL */
3025 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3026 * should be merged when possible.
3029 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3030 struct AFSStoreStatus *InStatus,
3031 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3033 Vnode *targetptr = 0; /* pointer to input fid */
3034 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3035 Error errorCode = 0; /* return code for caller */
3036 Volume *volptr = 0; /* pointer to the volume header */
3037 struct client *client = 0; /* pointer to client structure */
3038 afs_int32 rights, anyrights; /* rights for this and any user */
3039 struct client *t_client = NULL; /* tmp ptr to client data */
3040 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3041 struct rx_connection *tcon = rx_ConnectionOf(acall);
3043 /* Get ptr to client data for user Id for logging */
3044 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3045 logHostAddr.s_addr = rxr_HostOf(tcon);
3047 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3048 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3049 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3051 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3054 * Get volume/vnode for the target file; caller's rights to it are
3058 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3059 &parentwhentargetnotdir, &client, WRITE_LOCK,
3060 &rights, &anyrights))) {
3061 goto Bad_StoreStatus;
3064 /* set volume synchronization information */
3065 SetVolumeSync(Sync, volptr);
3067 /* Check if the caller has proper permissions to store status to Fid */
3069 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3071 goto Bad_StoreStatus;
3074 * Check for a symbolic link; we can't chmod these (otherwise could
3075 * change a symlink to a mt pt or vice versa)
3077 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3079 goto Bad_StoreStatus;
3082 /* Update the status of the target's vnode */
3083 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3084 (parentwhentargetnotdir ? parentwhentargetnotdir
3085 : targetptr), volptr, 0);
3087 /* convert the write lock to a read lock before breaking callbacks */
3088 VVnodeWriteToRead(&errorCode, targetptr);
3089 osi_Assert(!errorCode || errorCode == VSALVAGE);
3091 /* Break call backs on Fid */
3092 BreakCallBack(client->host, Fid, 0);
3094 /* Return the updated status back to caller */
3095 GetStatus(targetptr, OutStatus, rights, anyrights,
3096 parentwhentargetnotdir);
3099 /* Update and store volume/vnode and parent vnodes back */
3100 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3102 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3105 } /*SAFSS_StoreStatus */
3109 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3110 struct AFSStoreStatus * InStatus,
3111 struct AFSFetchStatus * OutStatus,
3112 struct AFSVolSync * Sync)
3115 struct rx_connection *tcon;
3117 struct client *t_client = NULL; /* tmp ptr to client data */
3118 struct fsstats fsstats;
3120 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3122 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3123 goto Bad_StoreStatus;
3125 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3128 code = CallPostamble(tcon, code, thost);
3130 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3132 fsstats_FinishOp(&fsstats, code);
3134 osi_auditU(acall, StoreStatusEvent, code,
3135 AUD_ID, t_client ? t_client->ViceId : 0,
3136 AUD_FID, Fid, AUD_END);
3139 } /*SRXAFS_StoreStatus */
3143 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3144 * merged in when possible.
3147 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3148 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3150 Vnode *parentptr = 0; /* vnode of input Directory */
3151 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3152 Vnode *targetptr = 0; /* file to be deleted */
3153 Volume *volptr = 0; /* pointer to the volume header */
3154 AFSFid fileFid; /* area for Fid from the directory */
3155 Error errorCode = 0; /* error code */
3156 DirHandle dir; /* Handle for dir package I/O */
3157 struct client *client = 0; /* pointer to client structure */
3158 afs_int32 rights, anyrights; /* rights for this and any user */
3159 struct client *t_client; /* tmp ptr to client data */
3160 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3161 struct rx_connection *tcon = rx_ConnectionOf(acall);
3164 /* Get ptr to client data for user Id for logging */
3165 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3166 logHostAddr.s_addr = rxr_HostOf(tcon);
3168 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3169 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3170 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3172 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3175 * Get volume/vnode for the parent dir; caller's access rights are
3179 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3180 &parentwhentargetnotdir, &client, WRITE_LOCK,
3181 &rights, &anyrights))) {
3182 goto Bad_RemoveFile;
3184 /* set volume synchronization information */
3185 SetVolumeSync(Sync, volptr);
3187 /* Does the caller has delete (& write) access to the parent directory? */
3188 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3189 goto Bad_RemoveFile;
3192 /* Actually delete the desired file */
3194 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3196 goto Bad_RemoveFile;
3199 /* Update the vnode status of the parent dir */
3200 #if FS_STATS_DETAILED
3201 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3202 parentptr->disk.linkCount,
3203 client->InSameNetwork);
3205 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3206 parentptr->disk.linkCount);
3207 #endif /* FS_STATS_DETAILED */
3209 /* Return the updated parent dir's status back to caller */
3210 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3212 /* Handle internal callback state for the parent and the deleted file */
3213 if (targetptr->disk.linkCount == 0) {
3214 /* no references left, discard entry */
3215 DeleteFileCallBacks(&fileFid);
3216 /* convert the parent lock to a read lock before breaking callbacks */
3217 VVnodeWriteToRead(&errorCode, parentptr);
3218 osi_Assert(!errorCode || errorCode == VSALVAGE);
3220 /* convert the parent lock to a read lock before breaking callbacks */
3221 VVnodeWriteToRead(&errorCode, parentptr);
3222 osi_Assert(!errorCode || errorCode == VSALVAGE);
3223 /* convert the target lock to a read lock before breaking callbacks */
3224 VVnodeWriteToRead(&errorCode, targetptr);
3225 osi_Assert(!errorCode || errorCode == VSALVAGE);
3226 /* tell all the file has changed */
3227 BreakCallBack(client->host, &fileFid, 1);
3230 /* break call back on the directory */
3231 BreakCallBack(client->host, DirFid, 0);
3234 /* Update and store volume/vnode and parent vnodes back */
3235 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3238 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3241 } /*SAFSS_RemoveFile */
3245 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3246 struct AFSFetchStatus * OutDirStatus,
3247 struct AFSVolSync * Sync)
3250 struct rx_connection *tcon;
3252 struct client *t_client = NULL; /* tmp ptr to client data */
3253 struct fsstats fsstats;
3255 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3257 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3258 goto Bad_RemoveFile;
3260 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3263 code = CallPostamble(tcon, code, thost);
3265 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3267 fsstats_FinishOp(&fsstats, code);
3269 osi_auditU(acall, RemoveFileEvent, code,
3270 AUD_ID, t_client ? t_client->ViceId : 0,
3271 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3274 } /*SRXAFS_RemoveFile */
3278 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3279 * be merged in when possible.
3282 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3283 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3284 struct AFSFetchStatus *OutFidStatus,
3285 struct AFSFetchStatus *OutDirStatus,
3286 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3288 Vnode *parentptr = 0; /* vnode of input Directory */
3289 Vnode *targetptr = 0; /* vnode of the new file */
3290 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3291 Volume *volptr = 0; /* pointer to the volume header */
3292 Error errorCode = 0; /* error code */
3293 DirHandle dir; /* Handle for dir package I/O */
3294 struct client *client = 0; /* pointer to client structure */
3295 afs_int32 rights, anyrights; /* rights for this and any user */
3296 struct client *t_client; /* tmp ptr to client data */
3297 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3298 struct rx_connection *tcon = rx_ConnectionOf(acall);
3302 /* Get ptr to client data for user Id for logging */
3303 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3304 logHostAddr.s_addr = rxr_HostOf(tcon);
3306 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3307 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3308 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3310 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3312 if (!FileNameOK(Name)) {
3314 goto Bad_CreateFile;
3318 * Get associated volume/vnode for the parent dir; caller long are
3322 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3323 &parentwhentargetnotdir, &client, WRITE_LOCK,
3324 &rights, &anyrights))) {
3325 goto Bad_CreateFile;
3328 /* set volume synchronization information */
3329 SetVolumeSync(Sync, volptr);
3331 /* Can we write (and insert) onto the parent directory? */
3332 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3333 goto Bad_CreateFile;
3335 /* get a new vnode for the file to be created and set it up */
3337 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3338 vFile, nBlocks(0)))) {
3339 goto Bad_CreateFile;
3342 /* update the status of the parent vnode */
3343 #if FS_STATS_DETAILED
3344 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3345 parentptr->disk.linkCount,
3346 client->InSameNetwork);
3348 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3349 parentptr->disk.linkCount);
3350 #endif /* FS_STATS_DETAILED */
3352 /* update the status of the new file's vnode */
3353 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3354 parentptr, volptr, 0);
3356 /* 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 */
3357 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3358 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3360 /* convert the write lock to a read lock before breaking callbacks */
3361 VVnodeWriteToRead(&errorCode, parentptr);
3362 osi_Assert(!errorCode || errorCode == VSALVAGE);
3364 /* break call back on parent dir */
3365 BreakCallBack(client->host, DirFid, 0);
3367 /* Return a callback promise for the newly created file to the caller */
3368 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3371 /* Update and store volume/vnode and parent vnodes back */
3372 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3375 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3378 } /*SAFSS_CreateFile */
3382 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3383 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3384 struct AFSFetchStatus * OutFidStatus,
3385 struct AFSFetchStatus * OutDirStatus,
3386 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3389 struct rx_connection *tcon;
3391 struct client *t_client = NULL; /* tmp ptr to client data */
3392 struct fsstats fsstats;
3394 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CREATEFILE);
3396 memset(OutFid, 0, sizeof(struct AFSFid));
3398 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3399 goto Bad_CreateFile;
3402 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3403 OutDirStatus, CallBack, Sync);
3406 code = CallPostamble(tcon, code, thost);
3408 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3410 fsstats_FinishOp(&fsstats, code);
3412 osi_auditU(acall, CreateFileEvent, code,
3413 AUD_ID, t_client ? t_client->ViceId : 0,
3414 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3417 } /*SRXAFS_CreateFile */
3421 * This routine is called exclusively from SRXAFS_Rename(), and should be
3422 * merged in when possible.
3425 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3426 struct AFSFid *NewDirFid, char *NewName,
3427 struct AFSFetchStatus *OutOldDirStatus,
3428 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3430 Vnode *oldvptr = 0; /* vnode of the old Directory */
3431 Vnode *newvptr = 0; /* vnode of the new Directory */
3432 Vnode *fileptr = 0; /* vnode of the file to move */
3433 Vnode *newfileptr = 0; /* vnode of the file to delete */
3434 Vnode *testvptr = 0; /* used in directory tree walk */
3435 Vnode *parent = 0; /* parent for use in SetAccessList */
3436 Error errorCode = 0; /* error code */
3437 Error fileCode = 0; /* used when writing Vnodes */
3438 VnodeId testnode; /* used in directory tree walk */
3439 AFSFid fileFid; /* Fid of file to move */
3440 AFSFid newFileFid; /* Fid of new file */
3441 DirHandle olddir; /* Handle for dir package I/O */
3442 DirHandle newdir; /* Handle for dir package I/O */
3443 DirHandle filedir; /* Handle for dir package I/O */
3444 DirHandle newfiledir; /* Handle for dir package I/O */
3445 Volume *volptr = 0; /* pointer to the volume header */
3446 struct client *client = 0; /* pointer to client structure */
3447 afs_int32 rights, anyrights; /* rights for this and any user */
3448 afs_int32 newrights; /* rights for this user */
3449 afs_int32 newanyrights; /* rights for any user */
3450 int doDelete; /* deleted the rename target (ref count now 0) */
3452 int updatefile = 0; /* are we changing the renamed file? (we do this
3453 * if we need to update .. on a renamed dir) */
3454 struct client *t_client; /* tmp ptr to client data */
3455 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3456 struct rx_connection *tcon = rx_ConnectionOf(acall);
3462 FidZero(&newfiledir);
3464 /* Get ptr to client data for user Id for logging */
3465 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3466 logHostAddr.s_addr = rxr_HostOf(tcon);
3468 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3469 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3470 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3471 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3473 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3475 if (!FileNameOK(NewName)) {
3479 if (OldDirFid->Volume != NewDirFid->Volume) {
3484 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3485 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3486 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3492 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3494 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3495 &parent, &client, WRITE_LOCK, &rights,
3500 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3502 newrights = rights, newanyrights = anyrights;
3505 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3506 MustBeDIR, &parent, &client, WRITE_LOCK,
3507 &newrights, &newanyrights))) {
3513 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3514 &parent, &client, WRITE_LOCK, &newrights,
3520 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3521 &parent, &client, WRITE_LOCK, &rights,
3528 /* set volume synchronization information */
3529 SetVolumeSync(Sync, volptr);
3531 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3534 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3538 if (CheckLength(volptr, oldvptr, -1) ||
3539 CheckLength(volptr, newvptr, -1)) {
3540 VTakeOffline(volptr);
3541 errorCode = VSALVAGE;
3545 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3546 * call to CopyOnWrite returns error, it is not necessary to revert back
3547 * the effects of the first call because the contents of the volume is
3548 * not modified, it is only replicated.
3550 if (oldvptr->disk.cloned) {
3551 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3552 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3555 SetDirHandle(&olddir, oldvptr);
3556 if (newvptr->disk.cloned) {
3557 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3558 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3562 SetDirHandle(&newdir, newvptr);
3564 /* Lookup the file to delete its vnode */
3565 if (afs_dir_Lookup(&olddir, OldName, &fileFid)) {
3569 if (fileFid.Vnode == oldvptr->vnodeNumber
3570 || fileFid.Vnode == newvptr->vnodeNumber) {
3571 errorCode = FSERR_ELOOP;
3574 fileFid.Volume = V_id(volptr);
3575 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3576 if (errorCode != 0) {
3578 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3579 OldName, errorCode));
3580 VTakeOffline(volptr);
3583 if (fileptr->disk.uniquifier != fileFid.Unique) {
3585 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3587 VTakeOffline(volptr);
3592 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3593 && fileptr->disk.linkCount != 1) {
3595 * Hard links exist to this file - cannot move one of the links to
3596 * a new directory because of AFS restrictions (this is the same
3597 * reason that links cannot be made across directories, i.e.
3604 /* Lookup the new file */
3605 if (!(afs_dir_Lookup(&newdir, NewName, &newFileFid))) {
3606 if (readonlyServer) {
3607 errorCode = VREADONLY;
3610 if (!(newrights & PRSFS_DELETE)) {
3614 if (newFileFid.Vnode == oldvptr->vnodeNumber
3615 || newFileFid.Vnode == newvptr->vnodeNumber
3616 || newFileFid.Vnode == fileFid.Vnode) {
3620 newFileFid.Volume = V_id(volptr);
3622 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3623 if (errorCode != 0) {
3625 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3626 NewName, errorCode));
3627 VTakeOffline(volptr);
3630 if (fileptr->disk.uniquifier != fileFid.Unique) {
3632 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3634 VTakeOffline(volptr);
3638 SetDirHandle(&newfiledir, newfileptr);
3639 /* Now check that we're moving directories over directories properly, etc.
3640 * return proper POSIX error codes:
3641 * if fileptr is a file and new is a dir: EISDIR.
3642 * if fileptr is a dir and new is a file: ENOTDIR.
3643 * Also, dir to be removed must be empty, of course.
3645 if (newfileptr->disk.type == vDirectory) {
3646 if (fileptr->disk.type != vDirectory) {
3650 if ((afs_dir_IsEmpty(&newfiledir))) {
3655 if (fileptr->disk.type == vDirectory) {
3656 errorCode = ENOTDIR;
3663 * ok - now we check that the old name is not above new name in the
3664 * directory structure. This is to prevent removing a subtree alltogether
3666 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3667 afs_int32 forpass = 0, vnum = 0, top = 0;
3668 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3669 if (testnode > vnum) vnum = testnode;
3670 if (forpass > vnum) {
3671 errorCode = FSERR_ELOOP;
3674 if (testnode == oldvptr->vnodeNumber) {
3675 testnode = oldvptr->disk.parent;
3678 if ((testnode == fileptr->vnodeNumber)
3679 || (testnode == newvptr->vnodeNumber)) {
3680 errorCode = FSERR_ELOOP;
3683 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3684 errorCode = FSERR_ELOOP;
3687 if (testnode == 1) top = 1;
3688 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3689 osi_Assert(errorCode == 0);
3690 testnode = testvptr->disk.parent;
3691 VPutVnode(&errorCode, testvptr);
3692 if ((top == 1) && (testnode != 0)) {
3693 VTakeOffline(volptr);
3695 ("Volume %u now offline, must be salvaged.\n",
3700 osi_Assert(errorCode == 0);
3704 if (fileptr->disk.type == vDirectory) {
3705 SetDirHandle(&filedir, fileptr);
3706 if (oldvptr != newvptr) {
3707 /* we always need to update .. if we've moving fileptr to a
3708 * different directory */
3711 struct AFSFid unused;
3713 code = afs_dir_Lookup(&filedir, "..", &unused);
3714 if (code == ENOENT) {
3715 /* only update .. if it doesn't already exist */
3721 /* Do the CopyonWrite first before modifying anything else. Copying is
3722 * required when we have to change entries for ..
3724 if (updatefile && (fileptr->disk.cloned)) {
3725 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3726 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
3728 /* since copyonwrite would mean fileptr has a new handle, do it here */
3730 SetDirHandle(&filedir, fileptr);
3733 /* If the new name exists already, delete it and the file it points to */
3736 /* Delete NewName from its directory */
3737 code = afs_dir_Delete(&newdir, NewName);
3738 osi_Assert(code == 0);
3740 /* Drop the link count */
3741 newfileptr->disk.linkCount--;
3742 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
3743 afs_fsize_t newSize;
3744 VN_GET_LEN(newSize, newfileptr);
3745 VAdjustDiskUsage((Error *) & errorCode, volptr,
3746 (afs_sfsize_t) - nBlocks(newSize), 0);
3747 if (VN_GET_INO(newfileptr)) {
3748 IH_REALLYCLOSE(newfileptr->handle);
3750 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
3751 V_parentId(volptr));
3752 IH_RELEASE(newfileptr->handle);
3753 if (errorCode == -1) {
3755 ("Del: inode=%s, name=%s, errno=%d\n",
3756 PrintInode(stmp, VN_GET_INO(newfileptr)),
3758 if ((errno != ENOENT) && (errno != EIO)
3759 && (errno != ENXIO))
3760 ViceLog(0, ("Do we need to fsck?"));
3763 VN_SET_INO(newfileptr, (Inode) 0);
3764 newfileptr->delete = 1; /* Mark NewName vnode to delete */
3767 /* Link count did not drop to zero.
3768 * Mark NewName vnode as changed - updates stime.
3770 newfileptr->changed_newTime = 1;
3775 * If the create below fails, and the delete above worked, we have
3776 * removed the new name and not replaced it. This is not very likely,
3777 * but possible. We could try to put the old file back, but it is
3778 * highly unlikely that it would work since it would involve issuing
3781 if ((errorCode = afs_dir_Create(&newdir, NewName, &fileFid)))
3784 /* Delete the old name */
3785 osi_Assert(afs_dir_Delete(&olddir, OldName) == 0);
3787 /* if the directory length changes, reflect it in the statistics */
3788 #if FS_STATS_DETAILED
3789 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
3790 oldvptr->disk.linkCount, client->InSameNetwork);
3791 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
3792 newvptr->disk.linkCount, client->InSameNetwork);
3794 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
3795 oldvptr->disk.linkCount);
3796 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
3797 newvptr->disk.linkCount);
3798 #endif /* FS_STATS_DETAILED */
3800 if (oldvptr == newvptr)
3801 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
3803 if (fileptr->disk.parent != newvptr->vnodeNumber) {
3804 fileptr->disk.parent = newvptr->vnodeNumber;
3805 fileptr->changed_newTime = 1;
3808 /* if we are dealing with a rename of a directory, and we need to
3809 * update the .. entry of that directory */
3811 osi_Assert(!fileptr->disk.cloned);
3813 fileptr->changed_newTime = 1; /* status change of moved file */
3815 /* fix .. to point to the correct place */
3816 afs_dir_Delete(&filedir, ".."); /* No assert--some directories may be bad */
3817 osi_Assert(afs_dir_Create(&filedir, "..", NewDirFid) == 0);
3818 fileptr->disk.dataVersion++;
3820 /* if the parent directories are different the link counts have to be */
3821 /* changed due to .. in the renamed directory */
3822 if (oldvptr != newvptr) {
3823 oldvptr->disk.linkCount--;
3824 newvptr->disk.linkCount++;
3828 /* set up return status */
3829 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
3830 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
3831 if (newfileptr && doDelete) {
3832 DeleteFileCallBacks(&newFileFid); /* no other references */
3837 /* convert the write locks to a read locks before breaking callbacks */
3838 VVnodeWriteToRead(&errorCode, newvptr);
3839 osi_Assert(!errorCode || errorCode == VSALVAGE);
3840 if (oldvptr != newvptr) {
3841 VVnodeWriteToRead(&errorCode, oldvptr);
3842 osi_Assert(!errorCode || errorCode == VSALVAGE);
3844 if (newfileptr && !doDelete) {
3845 /* convert the write lock to a read lock before breaking callbacks */
3846 VVnodeWriteToRead(&errorCode, newfileptr);
3847 osi_Assert(!errorCode || errorCode == VSALVAGE);
3850 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
3851 BreakCallBack(client->host, NewDirFid, 0);
3852 if (oldvptr != newvptr) {
3853 BreakCallBack(client->host, OldDirFid, 0);
3856 /* if a dir moved, .. changed */
3857 /* we do not give an AFSFetchStatus structure back to the
3858 * originating client, and the file's status has changed, so be
3859 * sure to send a callback break. In theory the client knows
3860 * enough to know that the callback could be broken implicitly,
3861 * but that may not be clear, and some client implementations
3862 * may not know to. */
3863 BreakCallBack(client->host, &fileFid, 1);
3866 /* Note: it is not necessary to break the callback */
3868 DeleteFileCallBacks(&newFileFid); /* no other references */
3870 /* other's still exist (with wrong link count) */
3871 BreakCallBack(client->host, &newFileFid, 1);
3876 VPutVnode(&fileCode, newfileptr);
3877 osi_Assert(fileCode == 0);
3879 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
3880 newvptr : 0), oldvptr, volptr, &client);
3884 FidZap(&newfiledir);
3885 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
3892 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
3893 char *OldName, struct AFSFid * NewDirFid, char *NewName,
3894 struct AFSFetchStatus * OutOldDirStatus,
3895 struct AFSFetchStatus * OutNewDirStatus,
3896 struct AFSVolSync * Sync)
3899 struct rx_connection *tcon;
3901 struct client *t_client = NULL; /* tmp ptr to client data */
3902 struct fsstats fsstats;
3904 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RENAME);
3906 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3910 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
3911 OutOldDirStatus, OutNewDirStatus, Sync);
3914 code = CallPostamble(tcon, code, thost);
3916 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3918 fsstats_FinishOp(&fsstats, code);
3920 osi_auditU(acall, RenameFileEvent, code,
3921 AUD_ID, t_client ? t_client->ViceId : 0,
3922 AUD_FID, OldDirFid, AUD_STR, OldName,
3923 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
3926 } /*SRXAFS_Rename */
3930 * This routine is called exclusively by SRXAFS_Symlink(), and should be
3931 * merged into it when possible.
3934 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3935 char *LinkContents, struct AFSStoreStatus *InStatus,
3936 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
3937 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3939 Vnode *parentptr = 0; /* vnode of input Directory */
3940 Vnode *targetptr = 0; /* vnode of the new link */
3941 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3942 Error errorCode = 0; /* error code */
3945 DirHandle dir; /* Handle for dir package I/O */
3946 Volume *volptr = 0; /* pointer to the volume header */
3947 struct client *client = 0; /* pointer to client structure */
3948 afs_int32 rights, anyrights; /* rights for this and any user */
3949 struct client *t_client; /* tmp ptr to client data */
3950 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3952 struct rx_connection *tcon = rx_ConnectionOf(acall);
3956 /* Get ptr to client data for user Id for logging */
3957 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3958 logHostAddr.s_addr = rxr_HostOf(tcon);
3960 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3961 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3962 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3964 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
3966 if (!FileNameOK(Name)) {
3972 * Get the vnode and volume for the parent dir along with the caller's
3976 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3977 &parentwhentargetnotdir, &client, WRITE_LOCK,
3978 &rights, &anyrights))) {
3982 /* set volume synchronization information */
3983 SetVolumeSync(Sync, volptr);
3985 /* Does the caller has insert (and write) access to the parent directory? */
3986 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3991 * If we're creating a mount point (any x bits clear), we must have
3992 * administer access to the directory, too. Always allow sysadmins
3995 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
3996 if (readonlyServer) {
3997 errorCode = VREADONLY;
4001 * We have a mountpoint, 'cause we're trying to set the Unix mode
4002 * bits to something with some x bits missing (default mode bits
4003 * if AFS_SETMODE is false is 0777)
4005 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4011 /* get a new vnode for the symlink and set it up */
4013 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4014 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4018 /* update the status of the parent vnode */
4019 #if FS_STATS_DETAILED
4020 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4021 parentptr->disk.linkCount,
4022 client->InSameNetwork);
4024 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4025 parentptr->disk.linkCount);
4026 #endif /* FS_STATS_DETAILED */
4028 /* update the status of the new symbolic link file vnode */
4029 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4030 parentptr, volptr, strlen((char *)LinkContents));
4032 /* Write the contents of the symbolic link name into the target inode */
4033 fdP = IH_OPEN(targetptr->handle);
4035 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4037 VTakeOffline(volptr);
4038 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4042 len = strlen((char *) LinkContents);
4043 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4045 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4048 * Set up and return modified status for the parent dir and new symlink
4051 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4052 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4054 /* convert the write lock to a read lock before breaking callbacks */
4055 VVnodeWriteToRead(&errorCode, parentptr);
4056 osi_Assert(!errorCode || errorCode == VSALVAGE);
4058 /* break call back on the parent dir */
4059 BreakCallBack(client->host, DirFid, 0);
4062 /* Write the all modified vnodes (parent, new files) and volume back */
4063 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4066 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4067 return ( errorCode ? errorCode : code );
4069 } /*SAFSS_Symlink */
4073 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4074 struct AFSFid *DirFid, /* Parent dir's fid */
4075 char *Name, /* File name to create */
4076 char *LinkContents, /* Contents of the new created file */
4077 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4078 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4079 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4080 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4081 struct AFSVolSync *Sync)
4084 struct rx_connection *tcon;
4086 struct client *t_client = NULL; /* tmp ptr to client data */
4087 struct fsstats fsstats;
4089 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SYMLINK);
4091 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4095 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4096 OutFidStatus, OutDirStatus, Sync);
4099 code = CallPostamble(tcon, code, thost);
4101 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4103 fsstats_FinishOp(&fsstats, code);
4105 osi_auditU(acall, SymlinkEvent, code,
4106 AUD_ID, t_client ? t_client->ViceId : 0,
4107 AUD_FID, DirFid, AUD_STR, Name,
4108 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4111 } /*SRXAFS_Symlink */
4115 * This routine is called exclusively by SRXAFS_Link(), and should be
4116 * merged into it when possible.
4119 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4120 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4121 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4123 Vnode *parentptr = 0; /* vnode of input Directory */
4124 Vnode *targetptr = 0; /* vnode of the new file */
4125 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4126 Volume *volptr = 0; /* pointer to the volume header */
4127 Error errorCode = 0; /* error code */
4128 DirHandle dir; /* Handle for dir package I/O */
4129 struct client *client = 0; /* pointer to client structure */
4130 afs_int32 rights, anyrights; /* rights for this and any user */
4131 struct client *t_client; /* tmp ptr to client data */
4132 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4133 struct rx_connection *tcon = rx_ConnectionOf(acall);
4137 /* Get ptr to client data for user Id for logging */
4138 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4139 logHostAddr.s_addr = rxr_HostOf(tcon);
4141 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4142 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4143 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4144 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4146 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4148 if (DirFid->Volume != ExistingFid->Volume) {
4152 if (!FileNameOK(Name)) {
4158 * Get the vnode and volume for the parent dir along with the caller's
4162 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4163 &parentwhentargetnotdir, &client, WRITE_LOCK,
4164 &rights, &anyrights))) {
4168 /* set volume synchronization information */
4169 SetVolumeSync(Sync, volptr);
4171 /* Can the caller insert into the parent directory? */
4172 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4176 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4177 /* AFS fileservers always have directory vnodes that are odd. */
4182 if (CheckLength(volptr, parentptr, -1)) {
4183 VTakeOffline(volptr);
4184 errorCode = VSALVAGE;
4188 /* get the file vnode */
4190 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4193 if (targetptr->disk.type != vFile) {
4197 if (targetptr->disk.parent != DirFid->Vnode) {
4201 if (parentptr->disk.cloned) {
4202 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4203 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4204 goto Bad_Link; /* disk full error */
4207 /* add the name to the directory */
4208 SetDirHandle(&dir, parentptr);
4209 if ((errorCode = afs_dir_Create(&dir, Name, ExistingFid)))
4213 /* update the status in the parent vnode */
4214 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4215 #if FS_STATS_DETAILED
4216 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4217 parentptr->disk.linkCount,
4218 client->InSameNetwork);
4220 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4221 parentptr->disk.linkCount);
4222 #endif /* FS_STATS_DETAILED */
4224 targetptr->disk.linkCount++;
4225 targetptr->disk.author = client->ViceId;
4226 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4228 /* set up return status */
4229 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4230 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4232 /* convert the write locks to read locks before breaking callbacks */
4233 VVnodeWriteToRead(&errorCode, targetptr);
4234 osi_Assert(!errorCode || errorCode == VSALVAGE);
4235 VVnodeWriteToRead(&errorCode, parentptr);
4236 osi_Assert(!errorCode || errorCode == VSALVAGE);
4238 /* break call back on DirFid */
4239 BreakCallBack(client->host, DirFid, 0);
4241 * We also need to break the callback for the file that is hard-linked since part
4242 * of its status (like linkcount) is changed
4244 BreakCallBack(client->host, ExistingFid, 0);
4247 /* Write the all modified vnodes (parent, new files) and volume back */
4248 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4251 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4258 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4259 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4260 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4263 struct rx_connection *tcon;
4265 struct client *t_client = NULL; /* tmp ptr to client data */
4266 struct fsstats fsstats;
4268 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_LINK);
4270 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4274 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4275 OutDirStatus, Sync);
4278 code = CallPostamble(tcon, code, thost);
4280 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4282 fsstats_FinishOp(&fsstats, code);
4284 osi_auditU(acall, LinkEvent, code,
4285 AUD_ID, t_client ? t_client->ViceId : 0,
4286 AUD_FID, DirFid, AUD_STR, Name,
4287 AUD_FID, ExistingFid, AUD_END);
4294 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4295 * merged into it when possible.
4298 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4299 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4300 struct AFSFetchStatus *OutFidStatus,
4301 struct AFSFetchStatus *OutDirStatus,
4302 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4304 Vnode *parentptr = 0; /* vnode of input Directory */
4305 Vnode *targetptr = 0; /* vnode of the new file */
4306 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4307 Volume *volptr = 0; /* pointer to the volume header */
4308 Error errorCode = 0; /* error code */
4309 struct acl_accessList *newACL; /* Access list */
4310 int newACLSize; /* Size of access list */
4311 DirHandle dir; /* Handle for dir package I/O */
4312 DirHandle parentdir; /* Handle for dir package I/O */
4313 struct client *client = 0; /* pointer to client structure */
4314 afs_int32 rights, anyrights; /* rights for this and any user */
4315 struct client *t_client; /* tmp ptr to client data */
4316 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4317 struct rx_connection *tcon = rx_ConnectionOf(acall);
4320 FidZero(&parentdir);
4322 /* Get ptr to client data for user Id for logging */
4323 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4324 logHostAddr.s_addr = rxr_HostOf(tcon);
4326 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4327 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4328 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4330 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4332 if (!FileNameOK(Name)) {
4338 * Get the vnode and volume for the parent dir along with the caller's
4342 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4343 &parentwhentargetnotdir, &client, WRITE_LOCK,
4344 &rights, &anyrights))) {
4348 /* set volume synchronization information */
4349 SetVolumeSync(Sync, volptr);
4351 /* Write access to the parent directory? */
4352 #ifdef DIRCREATE_NEED_WRITE
4354 * requires w access for the user to create a directory. this
4355 * closes a loophole in the current security arrangement, since a
4356 * user with i access only can create a directory and get the
4357 * implcit a access that goes with dir ownership, and proceed to
4358 * subvert quota in the volume.
4360 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4361 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4363 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4364 #endif /* DIRCREATE_NEED_WRITE */
4367 #define EMPTYDIRBLOCKS 2
4368 /* get a new vnode and set it up */
4370 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4371 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4375 /* Update the status for the parent dir */
4376 #if FS_STATS_DETAILED
4377 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4378 parentptr->disk.linkCount + 1,
4379 client->InSameNetwork);
4381 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4382 parentptr->disk.linkCount + 1);
4383 #endif /* FS_STATS_DETAILED */
4385 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4386 osi_Assert((SetAccessList
4387 (&targetptr, &volptr, &newACL, &newACLSize,
4388 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4389 osi_Assert(parentwhentargetnotdir == 0);
4390 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4392 /* update the status for the target vnode */
4393 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4394 parentptr, volptr, 0);
4396 /* Actually create the New directory in the directory package */
4397 SetDirHandle(&dir, targetptr);
4398 osi_Assert(!(afs_dir_MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4400 VN_SET_LEN(targetptr, (afs_fsize_t) afs_dir_Length(&dir));
4402 /* set up return status */
4403 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4404 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4406 /* convert the write lock to a read lock before breaking callbacks */
4407 VVnodeWriteToRead(&errorCode, parentptr);
4408 osi_Assert(!errorCode || errorCode == VSALVAGE);
4410 /* break call back on DirFid */
4411 BreakCallBack(client->host, DirFid, 0);
4413 /* Return a callback promise to caller */
4414 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4417 /* Write the all modified vnodes (parent, new files) and volume back */
4418 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4422 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4425 } /*SAFSS_MakeDir */
4429 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4430 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4431 struct AFSFetchStatus * OutFidStatus,
4432 struct AFSFetchStatus * OutDirStatus,
4433 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4436 struct rx_connection *tcon;
4438 struct client *t_client = NULL; /* tmp ptr to client data */
4439 struct fsstats fsstats;
4441 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_MAKEDIR);
4443 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4447 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4448 OutDirStatus, CallBack, Sync);
4451 code = CallPostamble(tcon, code, thost);
4453 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4455 fsstats_FinishOp(&fsstats, code);
4457 osi_auditU(acall, MakeDirEvent, code,
4458 AUD_ID, t_client ? t_client->ViceId : 0,
4459 AUD_FID, DirFid, AUD_STR, Name,
4460 AUD_FID, OutFid, AUD_END);
4463 } /*SRXAFS_MakeDir */
4467 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4468 * merged into it when possible.
4471 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4472 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4474 Vnode *parentptr = 0; /* vnode of input Directory */
4475 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4476 Vnode *targetptr = 0; /* file to be deleted */
4477 AFSFid fileFid; /* area for Fid from the directory */
4478 Error errorCode = 0; /* error code */
4479 DirHandle dir; /* Handle for dir package I/O */
4480 Volume *volptr = 0; /* pointer to the volume header */
4481 struct client *client = 0; /* pointer to client structure */
4482 afs_int32 rights, anyrights; /* rights for this and any user */
4483 struct client *t_client; /* tmp ptr to client data */
4484 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4485 struct rx_connection *tcon = rx_ConnectionOf(acall);
4489 /* Get ptr to client data for user Id for logging */
4490 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4491 logHostAddr.s_addr = rxr_HostOf(tcon);
4493 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4494 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4495 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4497 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4500 * Get the vnode and volume for the parent dir along with the caller's
4504 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4505 &parentwhentargetnotdir, &client, WRITE_LOCK,
4506 &rights, &anyrights))) {
4510 /* set volume synchronization information */
4511 SetVolumeSync(Sync, volptr);
4513 /* Does the caller has delete (&write) access to the parent dir? */
4514 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4518 /* Do the actual delete of the desired (empty) directory, Name */
4520 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4525 /* Update the status for the parent dir; link count is also adjusted */
4526 #if FS_STATS_DETAILED
4527 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4528 parentptr->disk.linkCount - 1,
4529 client->InSameNetwork);
4531 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4532 parentptr->disk.linkCount - 1);
4533 #endif /* FS_STATS_DETAILED */
4535 /* Return to the caller the updated parent dir status */
4536 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4539 * Note: it is not necessary to break the callback on fileFid, since
4540 * refcount is now 0, so no one should be able to refer to the dir
4543 DeleteFileCallBacks(&fileFid);
4545 /* convert the write lock to a read lock before breaking callbacks */
4546 VVnodeWriteToRead(&errorCode, parentptr);
4547 osi_Assert(!errorCode || errorCode == VSALVAGE);
4549 /* break call back on DirFid and fileFid */
4550 BreakCallBack(client->host, DirFid, 0);
4553 /* Write the all modified vnodes (parent, new files) and volume back */
4554 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4557 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4560 } /*SAFSS_RemoveDir */
4564 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4565 struct AFSFetchStatus * OutDirStatus,
4566 struct AFSVolSync * Sync)
4569 struct rx_connection *tcon;
4571 struct client *t_client = NULL; /* tmp ptr to client data */
4572 struct fsstats fsstats;
4574 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEDIR);
4576 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4579 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4582 code = CallPostamble(tcon, code, thost);
4584 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4586 fsstats_FinishOp(&fsstats, code);
4588 osi_auditU(acall, RemoveDirEvent, code,
4589 AUD_ID, t_client ? t_client->ViceId : 0,
4590 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4593 } /*SRXAFS_RemoveDir */
4597 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4598 * merged into it when possible.
4601 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4602 struct AFSVolSync *Sync)
4604 Vnode *targetptr = 0; /* vnode of input file */
4605 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4606 Error errorCode = 0; /* error code */
4607 Volume *volptr = 0; /* pointer to the volume header */
4608 struct client *client = 0; /* pointer to client structure */
4609 afs_int32 rights, anyrights; /* rights for this and any user */
4610 struct client *t_client; /* tmp ptr to client data */
4611 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4612 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
4613 struct rx_connection *tcon = rx_ConnectionOf(acall);
4615 if (type != LockRead && type != LockWrite) {
4619 /* Get ptr to client data for user Id for logging */
4620 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4621 logHostAddr.s_addr = rxr_HostOf(tcon);
4623 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4624 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4625 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4627 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4630 * Get the vnode and volume for the desired file along with the caller's
4634 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
4635 &parentwhentargetnotdir, &client, WRITE_LOCK,
4636 &rights, &anyrights))) {
4640 /* set volume synchronization information */
4641 SetVolumeSync(Sync, volptr);
4643 /* Handle the particular type of set locking, type */
4644 errorCode = HandleLocking(targetptr, client, rights, type);
4647 /* Write the all modified vnodes (parent, new files) and volume back */
4648 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
4651 if ((errorCode == VREADONLY) && (type == LockRead))
4652 errorCode = 0; /* allow read locks on RO volumes without saving state */
4654 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
4657 } /*SAFSS_SetLock */
4661 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
4662 ViceLockType type, struct AFSVolSync * Sync)
4664 return SRXAFS_SetLock(acall, Fid, type, Sync);
4665 } /*SRXAFS_OldSetLock */
4669 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
4670 struct AFSVolSync * Sync)
4673 struct rx_connection *tcon;
4675 struct client *t_client = NULL; /* tmp ptr to client data */
4676 struct fsstats fsstats;
4678 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETLOCK);
4680 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4683 code = SAFSS_SetLock(acall, Fid, type, Sync);
4686 code = CallPostamble(tcon, code, thost);
4688 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4690 fsstats_FinishOp(&fsstats, code);
4692 osi_auditU(acall, SetLockEvent, code,
4693 AUD_ID, t_client ? t_client->ViceId : 0,
4694 AUD_FID, Fid, AUD_LONG, type, AUD_END);
4696 } /*SRXAFS_SetLock */
4700 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
4701 * merged into it when possible.
4704 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
4705 struct AFSVolSync *Sync)
4707 Vnode *targetptr = 0; /* vnode of input file */
4708 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4709 Error errorCode = 0; /* error code */
4710 Volume *volptr = 0; /* pointer to the volume header */
4711 struct client *client = 0; /* pointer to client structure */
4712 afs_int32 rights, anyrights; /* rights for this and any user */
4713 struct client *t_client; /* tmp ptr to client data */
4714 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4715 struct rx_connection *tcon = rx_ConnectionOf(acall);
4717 /* Get ptr to client data for user Id for logging */
4718 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4719 logHostAddr.s_addr = rxr_HostOf(tcon);
4721 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4722 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4723 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4725 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
4728 * Get the vnode and volume for the desired file along with the caller's
4732 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
4733 &parentwhentargetnotdir, &client, WRITE_LOCK,
4734 &rights, &anyrights))) {
4735 goto Bad_ExtendLock;
4738 /* set volume synchronization information */
4739 SetVolumeSync(Sync, volptr);
4741 /* Handle the actual lock extension */
4742 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
4745 /* Put back file's vnode and volume */
4746 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
4749 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
4750 errorCode = 0; /* under our generous policy re RO vols */
4752 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
4755 } /*SAFSS_ExtendLock */
4759 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4760 struct AFSVolSync * Sync)
4762 return SRXAFS_ExtendLock(acall, Fid, Sync);
4763 } /*SRXAFS_OldExtendLock */
4767 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4768 struct AFSVolSync * Sync)
4771 struct rx_connection *tcon;
4773 struct client *t_client = NULL; /* tmp ptr to client data */
4774 struct fsstats fsstats;
4776 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_EXTENDLOCK);
4778 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4779 goto Bad_ExtendLock;
4781 code = SAFSS_ExtendLock(acall, Fid, Sync);
4784 code = CallPostamble(tcon, code, thost);
4786 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4788 fsstats_FinishOp(&fsstats, code);
4790 osi_auditU(acall, ExtendLockEvent, code,
4791 AUD_ID, t_client ? t_client->ViceId : 0,
4792 AUD_FID, Fid, AUD_END);
4795 } /*SRXAFS_ExtendLock */
4799 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
4800 * merged into it when possible.
4803 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
4804 struct AFSVolSync *Sync)
4806 Vnode *targetptr = 0; /* vnode of input file */
4807 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4808 Error errorCode = 0; /* error code */
4809 Volume *volptr = 0; /* pointer to the volume header */
4810 struct client *client = 0; /* pointer to client structure */
4811 afs_int32 rights, anyrights; /* rights for this and any user */
4812 struct client *t_client; /* tmp ptr to client data */
4813 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4814 struct rx_connection *tcon = rx_ConnectionOf(acall);
4816 /* Get ptr to client data for user Id for logging */
4817 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4818 logHostAddr.s_addr = rxr_HostOf(tcon);
4820 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4821 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4822 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4824 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
4827 * Get the vnode and volume for the desired file along with the caller's
4831 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
4832 &parentwhentargetnotdir, &client, WRITE_LOCK,
4833 &rights, &anyrights))) {
4834 goto Bad_ReleaseLock;
4837 /* set volume synchronization information */
4838 SetVolumeSync(Sync, volptr);
4840 /* Handle the actual lock release */
4841 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
4842 goto Bad_ReleaseLock;
4844 /* if no more locks left, a callback would be triggered here */
4845 if (targetptr->disk.lock.lockCount <= 0) {
4846 /* convert the write lock to a read lock before breaking callbacks */
4847 VVnodeWriteToRead(&errorCode, targetptr);
4848 osi_Assert(!errorCode || errorCode == VSALVAGE);
4849 BreakCallBack(client->host, Fid, 0);
4853 /* Put back file's vnode and volume */
4854 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
4857 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
4858 errorCode = 0; /* under our generous policy re RO vols */
4860 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
4863 } /*SAFSS_ReleaseLock */
4867 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4868 struct AFSVolSync * Sync)
4870 return SRXAFS_ReleaseLock(acall, Fid, Sync);
4871 } /*SRXAFS_OldReleaseLock */
4875 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4876 struct AFSVolSync * Sync)
4879 struct rx_connection *tcon;
4881 struct client *t_client = NULL; /* tmp ptr to client data */
4882 struct fsstats fsstats;
4884 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RELEASELOCK);
4886 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4887 goto Bad_ReleaseLock;
4889 code = SAFSS_ReleaseLock(acall, Fid, Sync);
4892 code = CallPostamble(tcon, code, thost);
4894 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4896 fsstats_FinishOp(&fsstats, code);
4898 osi_auditU(acall, ReleaseLockEvent, code,
4899 AUD_ID, t_client ? t_client->ViceId : 0,
4900 AUD_FID, Fid, AUD_END);
4903 } /*SRXAFS_ReleaseLock */
4907 SetSystemStats(struct AFSStatistics *stats)
4909 /* Fix this sometime soon.. */
4910 /* Because hey, it's not like we have a network monitoring protocol... */
4911 struct timeval time;
4913 /* this works on all system types */
4914 FT_GetTimeOfDay(&time, 0);
4915 stats->CurrentTime = time.tv_sec;
4916 } /*SetSystemStats */
4919 SetAFSStats(struct AFSStatistics *stats)
4921 extern afs_int32 StartTime, CurrentConnections;
4925 stats->CurrentMsgNumber = 0;
4926 stats->OldestMsgNumber = 0;
4927 stats->StartTime = StartTime;
4928 stats->CurrentConnections = CurrentConnections;
4929 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
4930 stats->TotalFetchs =
4931 AFSCallStats.FetchData + AFSCallStats.FetchACL +
4932 AFSCallStats.FetchStatus;
4933 stats->FetchDatas = AFSCallStats.FetchData;
4934 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
4935 seconds = AFSCallStats.AccumFetchTime / 1000;
4938 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
4939 stats->TotalStores =
4940 AFSCallStats.StoreData + AFSCallStats.StoreACL +
4941 AFSCallStats.StoreStatus;
4942 stats->StoreDatas = AFSCallStats.StoreData;
4943 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
4944 seconds = AFSCallStats.AccumStoreTime / 1000;
4947 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
4949 stats->ProcessSize = -1; /* TODO: */
4951 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
4954 h_GetWorkStats((int *)&(stats->WorkStations),
4955 (int *)&(stats->ActiveWorkStations), (int *)0,
4956 (afs_int32) (FT_ApproxTime()) - (15 * 60));
4960 /* Get disk related information from all AFS partitions. */
4963 SetVolumeStats(struct AFSStatistics *stats)
4965 struct DiskPartition64 *part;
4968 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
4969 part = part->next) {
4970 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
4971 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
4972 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
4973 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
4976 while (i < AFS_MSTATDISKS) {
4977 stats->Disks[i].TotalBlocks = -1;
4980 } /*SetVolumeStats */
4983 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
4986 struct rx_connection *tcon = rx_ConnectionOf(acall);
4988 struct client *t_client = NULL; /* tmp ptr to client data */
4989 struct fsstats fsstats;
4991 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
4993 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
4994 goto Bad_GetStatistics;
4996 ViceLog(1, ("SAFS_GetStatistics Received\n"));
4998 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5000 memset(Statistics, 0, sizeof(*Statistics));
5001 SetAFSStats((struct AFSStatistics *)Statistics);
5002 SetVolumeStats((struct AFSStatistics *)Statistics);
5003 SetSystemStats((struct AFSStatistics *)Statistics);
5006 code = CallPostamble(tcon, code, thost);
5008 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5010 fsstats_FinishOp(&fsstats, code);
5012 osi_auditU(acall, GetStatisticsEvent, code,
5013 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5015 } /*SRXAFS_GetStatistics */
5019 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5021 extern afs_int32 StartTime, CurrentConnections;
5024 struct rx_connection *tcon = rx_ConnectionOf(acall);
5026 struct client *t_client = NULL; /* tmp ptr to client data */
5027 struct timeval time;
5028 struct fsstats fsstats;
5030 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5032 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5033 goto Bad_GetStatistics64;
5035 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5036 Statistics->ViceStatistics64_val =
5037 malloc(statsVersion*sizeof(afs_int64));
5038 Statistics->ViceStatistics64_len = statsVersion;
5040 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5041 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5042 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5044 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5045 AFSCallStats.TotalCalls;
5046 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5047 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5048 AFSCallStats.FetchStatus;
5049 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5050 AFSCallStats.FetchData;
5051 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5052 AFSCallStats.TotalFetchedBytes;
5053 seconds = AFSCallStats.AccumFetchTime / 1000;
5056 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5057 AFSCallStats.TotalFetchedBytes / seconds;
5058 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5059 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5060 AFSCallStats.StoreStatus;
5061 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5062 AFSCallStats.StoreData;
5063 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5064 AFSCallStats.TotalStoredBytes;
5065 seconds = AFSCallStats.AccumStoreTime / 1000;
5068 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5069 AFSCallStats.TotalStoredBytes / seconds;
5071 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5073 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5074 (afs_int32) ((long)sbrk(0) >> 10);
5077 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5078 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5080 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5084 /* this works on all system types */
5085 FT_GetTimeOfDay(&time, 0);
5086 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5088 Bad_GetStatistics64:
5089 code = CallPostamble(tcon, code, thost);
5091 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5093 fsstats_FinishOp(&fsstats, code);
5095 osi_auditU(acall, GetStatisticsEvent, code,
5096 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5098 } /*SRXAFS_GetStatistics */
5101 /*------------------------------------------------------------------------
5102 * EXPORTED SRXAFS_XStatsVersion
5105 * Routine called by the server-side RPC interface to implement
5106 * pulling out the xstat version number for the File Server.
5109 * a_versionP : Ptr to the version number variable to set.
5115 * Nothing interesting.
5119 *------------------------------------------------------------------------*/
5122 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5123 { /*SRXAFS_XStatsVersion */
5125 struct client *t_client = NULL; /* tmp ptr to client data */
5126 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5127 struct fsstats fsstats;
5129 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_XSTATSVERSION);
5131 *a_versionP = AFS_XSTAT_VERSION;
5133 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5135 fsstats_FinishOp(&fsstats, 0);
5137 osi_auditU(a_call, XStatsVersionEvent, 0,
5138 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5140 } /*SRXAFS_XStatsVersion */
5143 /*------------------------------------------------------------------------
5144 * PRIVATE FillPerfValues
5147 * Routine called to fill a regular performance data structure.
5150 * a_perfP : Ptr to perf structure to fill
5156 * Various collections need this info, so the guts were put in
5157 * this separate routine.
5161 *------------------------------------------------------------------------*/
5164 FillPerfValues(struct afs_PerfStats *a_perfP)
5165 { /*FillPerfValues */
5166 int dir_Buffers; /*# buffers in use by dir package */
5167 int dir_Calls; /*# read calls in dir package */
5168 int dir_IOs; /*# I/O ops in dir package */
5169 struct rx_statistics *stats;
5172 * Vnode cache section.
5174 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5175 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5176 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5177 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5178 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5179 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5180 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5181 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5182 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5183 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5184 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5185 a_perfP->vcache_H_Gets = (int)VStats.hdr_gets;
5186 a_perfP->vcache_H_Replacements = (int)VStats.hdr_loads;
5189 * Directory section.
5191 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5192 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5193 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5194 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5199 stats = rx_GetStatistics();
5201 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5202 a_perfP->rx_noPackets_RcvClass =
5203 (afs_int32) stats->receivePktAllocFailures;
5204 a_perfP->rx_noPackets_SendClass =
5205 (afs_int32) stats->sendPktAllocFailures;
5206 a_perfP->rx_noPackets_SpecialClass =
5207 (afs_int32) stats->specialPktAllocFailures;
5208 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5209 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5210 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5211 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5212 a_perfP->rx_noPacketBuffersOnRead =
5213 (afs_int32) stats->noPacketBuffersOnRead;
5214 a_perfP->rx_selects = (afs_int32) stats->selects;
5215 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5216 a_perfP->rx_packetsRead_RcvClass =
5217 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5218 a_perfP->rx_packetsRead_SendClass =
5219 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5220 a_perfP->rx_packetsRead_SpecialClass =
5221 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5222 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5223 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5224 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5225 a_perfP->rx_spuriousPacketsRead =
5226 (afs_int32) stats->spuriousPacketsRead;
5227 a_perfP->rx_packetsSent_RcvClass =
5228 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5229 a_perfP->rx_packetsSent_SendClass =
5230 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5231 a_perfP->rx_packetsSent_SpecialClass =
5232 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5233 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5234 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5235 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
5236 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
5237 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
5238 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
5239 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
5240 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
5241 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
5242 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
5243 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
5244 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
5245 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
5246 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
5247 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
5248 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
5249 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
5250 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
5251 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
5252 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
5254 a_perfP->host_NumHostEntries = HTs;
5255 a_perfP->host_HostBlocks = HTBlocks;
5256 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5257 &(a_perfP->host_HostsInSameNetOrSubnet),
5258 &(a_perfP->host_HostsInDiffSubnet),
5259 &(a_perfP->host_HostsInDiffNetwork));
5260 a_perfP->host_NumClients = CEs;
5261 a_perfP->host_ClientBlocks = CEBlocks;
5263 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5264 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
5265 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5266 rx_FreeStatistics(&stats);
5267 } /*FillPerfValues */
5270 /*------------------------------------------------------------------------
5271 * EXPORTED SRXAFS_GetXStats
5274 * Routine called by the server-side callback RPC interface to
5275 * implement getting the given data collection from the extended
5276 * File Server statistics.
5279 * a_call : Ptr to Rx call on which this request came in.
5280 * a_clientVersionNum : Client version number.
5281 * a_opCode : Desired operation.
5282 * a_serverVersionNumP : Ptr to version number to set.
5283 * a_timeP : Ptr to time value (seconds) to set.
5284 * a_dataP : Ptr to variable array structure to return
5291 * Nothing interesting.
5295 *------------------------------------------------------------------------*/
5298 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5299 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5300 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5301 { /*SRXAFS_GetXStats */
5303 int code; /*Return value */
5304 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5305 afs_int32 dataBytes; /*Bytes in data buffer */
5306 struct fsstats fsstats;
5308 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETXSTATS);
5311 * Record the time of day and the server version number.
5313 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5314 *a_timeP = FT_ApproxTime();
5317 * Stuff the appropriate data in there (assume victory)
5322 ("Received GetXStats call for collection %d\n",
5323 a_collectionNumber));
5327 * We're not keeping stats, so just return successfully with
5330 a_dataP->AFS_CollData_len = 0;
5331 a_dataP->AFS_CollData_val = NULL;
5334 switch (a_collectionNumber) {
5335 case AFS_XSTATSCOLL_CALL_INFO:
5337 * Pass back all the call-count-related data.
5339 * >>> We are forced to allocate a separate area in which to
5340 * >>> put this stuff in by the RPC stub generator, since it
5341 * >>> will be freed at the tail end of the server stub code.
5345 * I don't think call-level stats are being collected yet
5346 * for the File Server.
5348 dataBytes = sizeof(struct afs_Stats);
5349 dataBuffP = (afs_int32 *) malloc(dataBytes);
5350 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5351 a_dataP->AFS_CollData_len = dataBytes >> 2;
5352 a_dataP->AFS_CollData_val = dataBuffP;
5354 a_dataP->AFS_CollData_len = 0;
5355 a_dataP->AFS_CollData_val = NULL;
5359 case AFS_XSTATSCOLL_PERF_INFO:
5361 * Pass back all the regular performance-related data.
5363 * >>> We are forced to allocate a separate area in which to
5364 * >>> put this stuff in by the RPC stub generator, since it
5365 * >>> will be freed at the tail end of the server stub code.
5368 afs_perfstats.numPerfCalls++;
5369 FillPerfValues(&afs_perfstats);
5372 * Don't overwrite the spares at the end.
5375 dataBytes = sizeof(struct afs_PerfStats);
5376 dataBuffP = (afs_int32 *) malloc(dataBytes);
5377 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5378 a_dataP->AFS_CollData_len = dataBytes >> 2;
5379 a_dataP->AFS_CollData_val = dataBuffP;
5382 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5384 * Pass back the full collection of performance-related data.
5385 * We have to stuff the basic, overall numbers in, but the
5386 * detailed numbers are kept in the structure already.
5388 * >>> We are forced to allocate a separate area in which to
5389 * >>> put this stuff in by the RPC stub generator, since it
5390 * >>> will be freed at the tail end of the server stub code.
5393 afs_perfstats.numPerfCalls++;
5394 #if FS_STATS_DETAILED
5395 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5396 FillPerfValues(&afs_FullPerfStats.overall);
5399 * Don't overwrite the spares at the end.
5402 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5403 dataBuffP = (afs_int32 *) malloc(dataBytes);
5404 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5405 a_dataP->AFS_CollData_len = dataBytes >> 2;
5406 a_dataP->AFS_CollData_val = dataBuffP;
5410 case AFS_XSTATSCOLL_CBSTATS:
5411 afs_perfstats.numPerfCalls++;
5413 dataBytes = sizeof(struct cbcounters);
5414 dataBuffP = (afs_int32 *) malloc(dataBytes);
5416 extern struct cbcounters cbstuff;
5417 dataBuffP[0]=cbstuff.DeleteFiles;
5418 dataBuffP[1]=cbstuff.DeleteCallBacks;
5419 dataBuffP[2]=cbstuff.BreakCallBacks;
5420 dataBuffP[3]=cbstuff.AddCallBacks;
5421 dataBuffP[4]=cbstuff.GotSomeSpaces;
5422 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
5423 dataBuffP[6]=cbstuff.nFEs;
5424 dataBuffP[7]=cbstuff.nCBs;
5425 dataBuffP[8]=cbstuff.nblks;
5426 dataBuffP[9]=cbstuff.CBsTimedOut;
5427 dataBuffP[10]=cbstuff.nbreakers;
5428 dataBuffP[11]=cbstuff.GSS1;
5429 dataBuffP[12]=cbstuff.GSS2;
5430 dataBuffP[13]=cbstuff.GSS3;
5431 dataBuffP[14]=cbstuff.GSS4;
5432 dataBuffP[15]=cbstuff.GSS5;
5435 a_dataP->AFS_CollData_len = dataBytes >> 2;
5436 a_dataP->AFS_CollData_val = dataBuffP;
5442 * Illegal collection number.
5444 a_dataP->AFS_CollData_len = 0;
5445 a_dataP->AFS_CollData_val = NULL;
5447 } /*Switch on collection number */
5449 fsstats_FinishOp(&fsstats, code);
5453 } /*SRXAFS_GetXStats */
5457 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5458 struct AFSCBs *CallBackArray)
5460 afs_int32 errorCode = 0;
5462 struct client *client = 0;
5463 struct rx_connection *tcon;
5465 struct fsstats fsstats;
5467 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GIVEUPCALLBACKS);
5471 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5472 FidArray->AFSCBFids_len));
5475 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5477 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5478 goto Bad_GiveUpCallBacks;
5480 if (!FidArray && !CallBackArray) {
5482 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5483 (tcon->peer ? tcon->peer->host : 0)));
5484 errorCode = GetClient(tcon, &client);
5487 DeleteAllCallBacks_r(client->host, 1);
5492 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5494 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5495 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5496 (tcon->peer ? tcon->peer->host : 0)));
5498 goto Bad_GiveUpCallBacks;
5501 errorCode = GetClient(tcon, &client);
5503 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5504 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5505 DeleteCallBack(client->host, fid);
5511 Bad_GiveUpCallBacks:
5512 errorCode = CallPostamble(tcon, errorCode, thost);
5514 fsstats_FinishOp(&fsstats, errorCode);
5518 } /*common_GiveUpCallBacks */
5522 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5523 struct AFSCBs * CallBackArray)
5525 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5526 } /*SRXAFS_GiveUpCallBacks */
5529 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
5531 return common_GiveUpCallBacks(acall, 0, 0);
5532 } /*SRXAFS_GiveUpAllCallBacks */
5536 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
5537 struct AFSVolumeInfo * avolinfo)
5539 return (VNOVOL); /* XXX Obsolete routine XXX */
5541 } /*SRXAFS_NGetVolumeInfo */
5545 * Dummy routine. Should never be called (the cache manager should only
5546 * invoke this interface when communicating with a AFS/DFS Protocol
5550 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
5551 char *afs_name_p, struct AFSFid * afs_fid_p,
5552 struct AFSFetchStatus * afs_status_p,
5553 struct AFSFetchStatus * afs_dir_status_p,
5554 struct AFSCallBack * afs_callback_p,
5555 struct AFSVolSync * afs_sync_p)
5562 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
5565 struct rx_connection *tcon;
5567 afs_uint32 *dataBuffP;
5568 afs_int32 dataBytes;
5571 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
5572 afs_FullPerfStats.overall.fs_nGetCaps++;
5574 ViceLog(2, ("SAFS_GetCapabilties\n"));
5576 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5579 dataBytes = 1 * sizeof(afs_int32);
5580 dataBuffP = (afs_uint32 *) malloc(dataBytes);
5581 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
5582 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
5584 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
5586 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
5587 capabilities->Capabilities_val = dataBuffP;
5590 code = CallPostamble(tcon, code, thost);
5597 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
5598 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
5602 afs_int32 nids, naddrs;
5603 afs_int32 *vd, *addr;
5604 Error errorCode = 0; /* return code to caller */
5605 struct client *client = 0;
5607 ViceLog(1, ("SRXAFS_FlushCPS\n"));
5609 AFSCallStats.TotalCalls++;
5611 nids = vids->ViceIds_len; /* # of users in here */
5612 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
5613 if (nids < 0 || naddrs < 0) {
5618 vd = vids->ViceIds_val;
5619 for (i = 0; i < nids; i++, vd++) {
5622 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
5626 client->prfail = 2; /* Means re-eval client's cps */
5629 rx_SetRock(((struct rx_connection *)client->tcon), 0);
5632 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
5633 free(client->CPS.prlist_val);
5634 client->CPS.prlist_val = NULL;
5635 client->CPS.prlist_len = 0;
5637 ReleaseWriteLock(&client->lock);
5641 addr = addrs->IPAddrs_val;
5642 for (i = 0; i < naddrs; i++, addr++) {
5644 h_flushhostcps(*addr, htons(7001));
5648 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
5650 } /*SRXAFS_FlushCPS */
5652 /* worthless hack to let CS keep running ancient software */
5654 afs_vtoi(char *aname)
5660 while ((tc = *aname++)) {
5661 if (tc > '9' || tc < '0')
5662 return 0; /* invalid name */
5670 * may get name or #, but must handle all weird cases (recognize readonly
5671 * or backup volumes by name or #
5674 CopyVolumeEntry(char *aname, struct vldbentry *ave,
5675 struct VolumeInfo *av)
5678 afs_int32 mask, whichType;
5679 afs_uint32 *serverHost, *typePtr;
5681 /* figure out what type we want if by name */
5683 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
5684 whichType = BACKVOL;
5685 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
5690 vol = afs_vtoi(aname);
5692 vol = ave->volumeId[whichType];
5695 * Now vol has volume # we're interested in. Next, figure out the type
5696 * of the volume by looking finding it in the vldb entry
5698 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
5701 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
5704 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
5705 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
5706 whichType = BACKVOL;
5708 return EINVAL; /* error: can't find volume in vldb entry */
5710 typePtr = &av->Type0;
5711 serverHost = &av->Server0;
5713 av->Type = whichType;
5714 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
5715 if (ave->flags & VLF_RWEXISTS)
5716 typePtr[RWVOL] = ave->volumeId[RWVOL];
5717 if (ave->flags & VLF_ROEXISTS)
5718 typePtr[ROVOL] = ave->volumeId[ROVOL];
5719 if (ave->flags & VLF_BACKEXISTS)
5720 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
5722 for (i = 0, j = 0; i < ave->nServers; i++) {
5723 if ((ave->serverFlags[i] & mask) == 0)
5724 continue; /* wrong volume */
5725 serverHost[j] = ave->serverNumber[i];
5728 av->ServerCount = j;
5730 serverHost[j++] = 0; /* bogus 8, but compat only now */
5735 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
5737 static struct rx_connection *vlConn = 0;
5738 static int down = 0;
5739 static afs_int32 lastDownTime = 0;
5740 struct vldbentry tve;
5741 struct rx_securityClass *vlSec;
5745 vlSec = rxnull_NewClientSecurityObject();
5747 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
5748 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
5750 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
5751 return 1; /* failure */
5754 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
5756 down = 0; /* call worked */
5759 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
5765 /* otherwise convert to old format vldb entry */
5766 code = CopyVolumeEntry(avolid, &tve, avolinfo);
5776 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
5777 struct VolumeInfo * avolinfo)
5780 struct rx_connection *tcon;
5782 struct fsstats fsstats;
5784 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMEINFO);
5786 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5787 goto Bad_GetVolumeInfo;
5790 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
5792 code = TryLocalVLServer(avolid, avolinfo);
5794 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
5795 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
5796 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
5797 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
5800 code = CallPostamble(tcon, code, thost);
5802 fsstats_FinishOp(&fsstats, code);
5806 } /*SRXAFS_GetVolumeInfo */
5810 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5811 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
5812 char **OfflineMsg, char **Motd)
5814 Vnode *targetptr = 0; /* vnode of the new file */
5815 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5816 Error errorCode = 0; /* error code */
5817 Volume *volptr = 0; /* pointer to the volume header */
5818 struct client *client = 0; /* pointer to client entry */
5819 afs_int32 rights, anyrights; /* rights for this and any user */
5821 struct rx_connection *tcon;
5823 struct client *t_client = NULL; /* tmp ptr to client data */
5824 struct fsstats fsstats;
5826 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMESTATUS);
5828 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
5829 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5830 goto Bad_GetVolumeStatus;
5833 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
5837 goto Bad_GetVolumeStatus;
5839 dummyFid.Volume = avolid, dummyFid.Vnode =
5840 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5843 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
5844 &parentwhentargetnotdir, &client, READ_LOCK,
5845 &rights, &anyrights)))
5846 goto Bad_GetVolumeStatus;
5848 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
5850 goto Bad_GetVolumeStatus;
5852 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
5854 Bad_GetVolumeStatus:
5855 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5857 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
5858 /* next is to guarantee out strings exist for stub */
5860 *Name = (char *)malloc(1);
5864 *Motd = (char *)malloc(1);
5867 if (*OfflineMsg == 0) {
5868 *OfflineMsg = (char *)malloc(1);
5871 errorCode = CallPostamble(tcon, errorCode, thost);
5873 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5875 fsstats_FinishOp(&fsstats, errorCode);
5877 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
5878 AUD_ID, t_client ? t_client->ViceId : 0,
5879 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
5882 } /*SRXAFS_GetVolumeStatus */
5886 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5887 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
5888 char *OfflineMsg, char *Motd)
5890 Vnode *targetptr = 0; /* vnode of the new file */
5891 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5892 Error errorCode = 0; /* error code */
5893 Volume *volptr = 0; /* pointer to the volume header */
5894 struct client *client = 0; /* pointer to client entry */
5895 afs_int32 rights, anyrights; /* rights for this and any user */
5897 struct rx_connection *tcon = rx_ConnectionOf(acall);
5899 struct client *t_client = NULL; /* tmp ptr to client data */
5900 struct fsstats fsstats;
5902 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETVOLUMESTATUS);
5904 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
5905 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5906 goto Bad_SetVolumeStatus;
5909 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
5913 goto Bad_SetVolumeStatus;
5915 dummyFid.Volume = avolid, dummyFid.Vnode =
5916 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5919 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
5920 &parentwhentargetnotdir, &client, READ_LOCK,
5921 &rights, &anyrights)))
5922 goto Bad_SetVolumeStatus;
5924 if (readonlyServer) {
5925 errorCode = VREADONLY;
5926 goto Bad_SetVolumeStatus;
5928 if (VanillaUser(client)) {
5930 goto Bad_SetVolumeStatus;
5934 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
5936 Bad_SetVolumeStatus:
5937 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5939 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
5940 errorCode = CallPostamble(tcon, errorCode, thost);
5942 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5944 fsstats_FinishOp(&fsstats, errorCode);
5946 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
5947 AUD_ID, t_client ? t_client->ViceId : 0,
5948 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
5950 } /*SRXAFS_SetVolumeStatus */
5952 #define DEFAULTVOLUME "root.afs"
5955 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
5961 struct rx_connection *tcon;
5963 Error errorCode = 0;
5965 struct fsstats fsstats;
5967 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETROOTVOLUME);
5969 return FSERR_EOPNOTSUPP;
5972 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
5973 goto Bad_GetRootVolume;
5975 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
5978 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
5980 strcpy(temp, DEFAULTVOLUME);
5982 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
5983 lockf(fd, F_LOCK, 0);
5987 len = read(fd, temp, 256);
5988 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
5989 lockf(fd, F_ULOCK, 0);
5994 if (temp[len - 1] == '\n')
5998 *VolumeName = temp; /* freed by rx server-side stub */
6001 errorCode = CallPostamble(tcon, errorCode, thost);
6003 fsstats_FinishOp(&fsstats, errorCode);
6008 } /*SRXAFS_GetRootVolume */
6011 /* still works because a struct CBS is the same as a struct AFSOpaque */
6013 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6014 struct AFSOpaque * Token)
6017 struct rx_connection *tcon;
6019 struct fsstats fsstats;
6021 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CHECKTOKEN);
6023 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6024 goto Bad_CheckToken;
6026 code = FSERR_ECONNREFUSED;
6029 code = CallPostamble(tcon, code, thost);
6031 fsstats_FinishOp(&fsstats, code);
6035 } /*SRXAFS_CheckToken */
6038 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6039 afs_uint32 * USeconds)
6042 struct rx_connection *tcon;
6045 struct fsstats fsstats;
6047 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETTIME);
6049 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6053 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6055 FT_GetTimeOfDay(&tpl, 0);
6056 *Seconds = tpl.tv_sec;
6057 *USeconds = tpl.tv_usec;
6059 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6062 code = CallPostamble(tcon, code, thost);
6064 fsstats_FinishOp(&fsstats, code);
6068 } /*SRXAFS_GetTime */
6075 * Implement a client's data fetch using Rx.
6078 * volptr : Ptr to the given volume's info.
6079 * targetptr : Pointer to the vnode involved.
6080 * Call : Ptr to the Rx call involved.
6081 * Pos : Offset within the file.
6082 * Len : Length in bytes to read; this value is bogus!
6083 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6085 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6090 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6091 struct rx_call * Call, afs_sfsize_t Pos,
6092 afs_sfsize_t Len, afs_int32 Int64Mode,
6093 afs_sfsize_t * a_bytesToFetchP,
6094 afs_sfsize_t * a_bytesFetchedP)
6096 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6101 #else /* HAVE_PIOV */
6102 struct iovec tiov[RX_MAXIOVECS];
6104 #endif /* HAVE_PIOV */
6109 * Initialize the byte count arguments.
6111 (*a_bytesToFetchP) = 0;
6112 (*a_bytesFetchedP) = 0;
6115 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6116 (afs_uintmax_t) Len));
6118 if (!VN_GET_INO(targetptr)) {
6119 afs_int32 zero = htonl(0);
6121 * This is used for newly created files; we simply send 0 bytes
6122 * back to make the cache manager happy...
6125 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6126 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6129 FT_GetTimeOfDay(&StartTime, 0);
6130 ihP = targetptr->handle;
6133 VTakeOffline(volptr);
6134 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6138 optSize = sendBufSize;
6139 tlen = FDH_SIZE(fdP);
6141 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6144 VTakeOffline(volptr);
6145 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6149 if (CheckLength(volptr, targetptr, tlen)) {
6151 VTakeOffline(volptr);
6158 if (Pos + Len > tlen) /* get length we should send */
6159 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
6162 afs_int32 high, low;
6163 SplitOffsetOrSize(Len, high, low);
6164 osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6167 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6170 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6172 (*a_bytesToFetchP) = Len;
6174 tbuffer = AllocSendBuffer();
6175 #endif /* HAVE_PIOV */
6184 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
6185 if (nBytes != wlen) {
6187 FreeSendBuffer((struct afs_buffer *)tbuffer);
6188 VTakeOffline(volptr);
6189 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6193 nBytes = rx_Write(Call, tbuffer, wlen);
6194 #else /* HAVE_PIOV */
6195 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6201 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
6202 if (nBytes != wlen) {
6204 VTakeOffline(volptr);
6205 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6209 nBytes = rx_Writev(Call, tiov, tnio, wlen);
6210 #endif /* HAVE_PIOV */
6213 * Bump the number of bytes actually sent by the number from this
6216 (*a_bytesFetchedP) += nBytes;
6217 if (nBytes != wlen) {
6221 FreeSendBuffer((struct afs_buffer *)tbuffer);
6222 #endif /* HAVE_PIOV */
6223 err = VIsGoingOffline(volptr);
6232 FreeSendBuffer((struct afs_buffer *)tbuffer);
6233 #endif /* HAVE_PIOV */
6235 FT_GetTimeOfDay(&StopTime, 0);
6237 /* Adjust all Fetch Data related stats */
6239 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6240 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6241 AFSCallStats.AccumFetchTime +=
6242 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6243 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6245 afs_fsize_t targLen;
6246 VN_GET_LEN(targLen, targetptr);
6247 AFSCallStats.TotalFetchedBytes += targLen;
6248 AFSCallStats.FetchSize1++;
6249 if (targLen < SIZE2)
6250 AFSCallStats.FetchSize2++;
6251 else if (targLen < SIZE3)
6252 AFSCallStats.FetchSize3++;
6253 else if (targLen < SIZE4)
6254 AFSCallStats.FetchSize4++;
6256 AFSCallStats.FetchSize5++;
6261 } /*FetchData_RXStyle */
6264 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6265 afs_sfsize_t * size)
6267 #ifdef AFS_NAMEI_ENV
6269 lhp = IH_OPEN(V_linkHandle(vp));
6272 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
6276 *size = OS_SIZE(fdP->fd_fd);
6277 return (*size == -1) ? -1 : 0;
6279 struct afs_stat status;
6281 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6285 *lc = GetLinkCount(vp, &status);
6286 *size = status.st_size;
6295 * Implement a client's data store using Rx.
6298 * volptr : Ptr to the given volume's info.
6299 * targetptr : Pointer to the vnode involved.
6300 * Call : Ptr to the Rx call involved.
6301 * Pos : Offset within the file.
6302 * Len : Length in bytes to store; this value is bogus!
6303 * a_bytesToStoreP : Set to the number of bytes to be stored to
6305 * a_bytesStoredP : Set to the actual number of bytes stored to
6309 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6310 struct client * client, struct rx_call * Call,
6311 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6313 afs_sfsize_t * a_bytesToStoreP,
6314 afs_sfsize_t * a_bytesStoredP)
6316 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6317 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6318 Error errorCode = 0; /* Returned error code to caller */
6320 char *tbuffer; /* data copying buffer */
6321 #else /* HAVE_PIOV */
6322 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6323 int tnio; /* temp for iovec size */
6324 #endif /* HAVE_PIOV */
6325 afs_sfsize_t tlen; /* temp for xfr length */
6326 Inode tinode; /* inode for I/O */
6327 afs_int32 optSize; /* optimal transfer size */
6328 afs_sfsize_t DataLength = 0; /* size of inode */
6329 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6330 afs_fsize_t NewLength; /* size after this store completes */
6331 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6332 int linkCount = 0; /* link count on inode */
6335 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6339 * Initialize the byte count arguments.
6341 (*a_bytesToStoreP) = 0;
6342 (*a_bytesStoredP) = 0;
6345 * We break the callbacks here so that the following signal will not
6348 BreakCallBack(client->host, Fid, 0);
6350 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6351 /* the inode should have been created in Alloc_NewVnode */
6352 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
6354 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
6355 Fid->Volume, Fid->Vnode, Fid->Unique,
6356 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
6357 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
6358 return ENOENT; /* is this proper error code? */
6361 * See if the file has several links (from other volumes). If it
6362 * does, then we have to make a copy before changing it to avoid
6363 *changing read-only clones of this dude
6366 ("StoreData_RXStyle : Opening inode %s\n",
6367 PrintInode(stmp, VN_GET_INO(targetptr))));
6368 fdP = IH_OPEN(targetptr->handle);
6371 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
6373 VTakeOffline(volptr);
6374 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6378 if (CheckLength(volptr, targetptr, DataLength)) {
6380 VTakeOffline(volptr);
6384 if (linkCount != 1) {
6387 ("StoreData_RXStyle : inode %s has more than onelink\n",
6388 PrintInode(stmp, VN_GET_INO(targetptr))));
6389 /* other volumes share this data, better copy it first */
6391 /* Adjust the disk block count by the creation of the new inode.
6392 * We call the special VDiskUsage so we don't adjust the volume's
6393 * quota since we don't want to penalyze the user for afs's internal
6394 * mechanisms (i.e. copy on write overhead.) Also the right size
6395 * of the disk will be recorded...
6398 VN_GET_LEN(size, targetptr);
6399 volptr->partition->flags &= ~PART_DONTUPDATE;
6400 VSetPartitionDiskUsage(volptr->partition);
6401 volptr->partition->flags |= PART_DONTUPDATE;
6402 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6403 volptr->partition->flags &= ~PART_DONTUPDATE;
6407 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6408 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, MAXFSIZE))) {
6409 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6410 volptr->partition->flags &= ~PART_DONTUPDATE;
6413 volptr->partition->flags &= ~PART_DONTUPDATE;
6414 VSetPartitionDiskUsage(volptr->partition);
6415 fdP = IH_OPEN(targetptr->handle);
6418 ("StoreData : Reopen after CopyOnWrite failed\n"));
6422 tinode = VN_GET_INO(targetptr);
6424 if (!VALID_INO(tinode)) {
6425 VTakeOffline(volptr);
6426 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
6431 /* compute new file length */
6432 NewLength = DataLength;
6433 if (FileLength < NewLength)
6434 /* simulate truncate */
6435 NewLength = FileLength;
6436 TruncatedLength = NewLength; /* remember length after possible ftruncate */
6437 if (Pos + Length > NewLength)
6438 NewLength = Pos + Length; /* and write */
6440 /* adjust the disk block count by the difference in the files */
6442 afs_fsize_t targSize;
6443 VN_GET_LEN(targSize, targetptr);
6444 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
6447 AdjustDiskUsage(volptr, adjustSize,
6448 adjustSize - SpareComp(volptr)))) {
6453 /* can signal cache manager to proceed from close now */
6454 /* this bit means that the locks are set and protections are OK */
6455 rx_SetLocalStatus(Call, 1);
6457 FT_GetTimeOfDay(&StartTime, 0);
6459 optSize = sendBufSize;
6461 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
6462 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
6463 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
6465 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
6466 if (FileLength < DataLength)
6467 FDH_TRUNC(fdP, FileLength);
6468 bytesTransfered = 0;
6470 tbuffer = AllocSendBuffer();
6471 #endif /* HAVE_PIOV */
6472 /* if length == 0, the loop below isn't going to do anything, including
6473 * extend the length of the inode, which it must do, since the file system
6474 * assumes that the inode length == vnode's file length. So, we extend
6475 * the file length manually if need be. Note that if file is bigger than
6476 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
6477 * do what we're going to do below.
6479 if (Length == 0 && Pos > TruncatedLength) {
6480 /* Set the file's length; we've already done an lseek to the right
6483 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
6488 errorCode = FDH_TRUNC(fdP, Pos);
6490 /* have some data to copy */
6491 (*a_bytesToStoreP) = Length;
6494 if (bytesTransfered >= Length) {
6498 tlen = Length - bytesTransfered; /* how much more to do */
6500 rlen = optSize; /* bound by buffer size */
6504 errorCode = rx_Read(Call, tbuffer, rlen);
6505 #else /* HAVE_PIOV */
6506 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
6507 #endif /* HAVE_PIOV */
6508 if (errorCode <= 0) {
6512 (*a_bytesStoredP) += errorCode;
6515 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
6516 #else /* HAVE_PIOV */
6517 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
6518 #endif /* HAVE_PIOV */
6519 if (nBytes != rlen) {
6520 errorCode = VDISKFULL;
6523 bytesTransfered += rlen;
6529 FreeSendBuffer((struct afs_buffer *)tbuffer);
6530 #endif /* HAVE_PIOV */
6535 Error tmp_errorCode = 0;
6536 afs_sfsize_t nfSize = FDH_SIZE(fdP);
6537 osi_Assert(nfSize >= 0);
6538 /* something went wrong: adjust size and return */
6539 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
6540 /* changed_newTime is tested in StoreData to detemine if we
6541 * need to update the target vnode.
6543 targetptr->changed_newTime = 1;
6545 /* set disk usage to be correct */
6546 VAdjustDiskUsage(&tmp_errorCode, volptr,
6547 (afs_sfsize_t) (nBlocks(nfSize) -
6548 nBlocks(NewLength)), 0);
6549 if (tmp_errorCode) {
6550 errorCode = tmp_errorCode;
6556 FT_GetTimeOfDay(&StopTime, 0);
6558 VN_SET_LEN(targetptr, NewLength);
6560 /* Update all StoreData related stats */
6562 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
6563 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
6564 AFSCallStats.StoreSize1++; /* Piggybacked data */
6566 afs_fsize_t targLen;
6567 VN_GET_LEN(targLen, targetptr);
6568 if (targLen < SIZE2)
6569 AFSCallStats.StoreSize2++;
6570 else if (targLen < SIZE3)
6571 AFSCallStats.StoreSize3++;
6572 else if (targLen < SIZE4)
6573 AFSCallStats.StoreSize4++;
6575 AFSCallStats.StoreSize5++;
6580 } /*StoreData_RXStyle */
6582 static int sys2et[512];
6585 init_sys_error_to_et(void)
6587 memset(&sys2et, 0, sizeof(sys2et));
6588 sys2et[EPERM] = UAEPERM;
6589 sys2et[ENOENT] = UAENOENT;
6590 sys2et[ESRCH] = UAESRCH;
6591 sys2et[EINTR] = UAEINTR;
6592 sys2et[EIO] = UAEIO;
6593 sys2et[ENXIO] = UAENXIO;
6594 sys2et[E2BIG] = UAE2BIG;
6595 sys2et[ENOEXEC] = UAENOEXEC;
6596 sys2et[EBADF] = UAEBADF;
6597 sys2et[ECHILD] = UAECHILD;
6598 sys2et[EAGAIN] = UAEAGAIN;
6599 sys2et[ENOMEM] = UAENOMEM;
6600 sys2et[EACCES] = UAEACCES;
6601 sys2et[EFAULT] = UAEFAULT;
6602 sys2et[ENOTBLK] = UAENOTBLK;
6603 sys2et[EBUSY] = UAEBUSY;
6604 sys2et[EEXIST] = UAEEXIST;
6605 sys2et[EXDEV] = UAEXDEV;
6606 sys2et[ENODEV] = UAENODEV;
6607 sys2et[ENOTDIR] = UAENOTDIR;
6608 sys2et[EISDIR] = UAEISDIR;
6609 sys2et[EINVAL] = UAEINVAL;
6610 sys2et[ENFILE] = UAENFILE;
6611 sys2et[EMFILE] = UAEMFILE;
6612 sys2et[ENOTTY] = UAENOTTY;
6613 sys2et[ETXTBSY] = UAETXTBSY;
6614 sys2et[EFBIG] = UAEFBIG;
6615 sys2et[ENOSPC] = UAENOSPC;
6616 sys2et[ESPIPE] = UAESPIPE;
6617 sys2et[EROFS] = UAEROFS;
6618 sys2et[EMLINK] = UAEMLINK;
6619 sys2et[EPIPE] = UAEPIPE;
6620 sys2et[EDOM] = UAEDOM;
6621 sys2et[ERANGE] = UAERANGE;
6622 sys2et[EDEADLK] = UAEDEADLK;
6623 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
6624 sys2et[ENOLCK] = UAENOLCK;
6625 sys2et[ENOSYS] = UAENOSYS;
6626 #if (ENOTEMPTY != EEXIST)
6627 sys2et[ENOTEMPTY] = UAENOTEMPTY;
6629 sys2et[ELOOP] = UAELOOP;
6630 #if (EWOULDBLOCK != EAGAIN)
6631 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
6633 sys2et[ENOMSG] = UAENOMSG;
6634 sys2et[EIDRM] = UAEIDRM;
6635 sys2et[ECHRNG] = UAECHRNG;
6636 sys2et[EL2NSYNC] = UAEL2NSYNC;
6637 sys2et[EL3HLT] = UAEL3HLT;
6638 sys2et[EL3RST] = UAEL3RST;
6639 sys2et[ELNRNG] = UAELNRNG;
6640 sys2et[EUNATCH] = UAEUNATCH;
6641 sys2et[ENOCSI] = UAENOCSI;
6642 sys2et[EL2HLT] = UAEL2HLT;
6643 sys2et[EBADE] = UAEBADE;
6644 sys2et[EBADR] = UAEBADR;
6645 sys2et[EXFULL] = UAEXFULL;
6646 sys2et[ENOANO] = UAENOANO;
6647 sys2et[EBADRQC] = UAEBADRQC;
6648 sys2et[EBADSLT] = UAEBADSLT;
6649 sys2et[EDEADLK] = UAEDEADLK;
6650 sys2et[EBFONT] = UAEBFONT;
6651 sys2et[ENOSTR] = UAENOSTR;
6652 sys2et[ENODATA] = UAENODATA;
6653 sys2et[ETIME] = UAETIME;
6654 sys2et[ENOSR] = UAENOSR;
6655 sys2et[ENONET] = UAENONET;
6656 sys2et[ENOPKG] = UAENOPKG;
6657 sys2et[EREMOTE] = UAEREMOTE;
6658 sys2et[ENOLINK] = UAENOLINK;
6659 sys2et[EADV] = UAEADV;
6660 sys2et[ESRMNT] = UAESRMNT;
6661 sys2et[ECOMM] = UAECOMM;
6662 sys2et[EPROTO] = UAEPROTO;
6663 sys2et[EMULTIHOP] = UAEMULTIHOP;
6664 sys2et[EDOTDOT] = UAEDOTDOT;
6665 sys2et[EBADMSG] = UAEBADMSG;
6666 sys2et[EOVERFLOW] = UAEOVERFLOW;
6667 sys2et[ENOTUNIQ] = UAENOTUNIQ;
6668 sys2et[EBADFD] = UAEBADFD;
6669 sys2et[EREMCHG] = UAEREMCHG;
6670 sys2et[ELIBACC] = UAELIBACC;
6671 sys2et[ELIBBAD] = UAELIBBAD;
6672 sys2et[ELIBSCN] = UAELIBSCN;
6673 sys2et[ELIBMAX] = UAELIBMAX;
6674 sys2et[ELIBEXEC] = UAELIBEXEC;
6675 sys2et[EILSEQ] = UAEILSEQ;
6676 sys2et[ERESTART] = UAERESTART;
6677 sys2et[ESTRPIPE] = UAESTRPIPE;
6678 sys2et[EUSERS] = UAEUSERS;
6679 sys2et[ENOTSOCK] = UAENOTSOCK;
6680 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
6681 sys2et[EMSGSIZE] = UAEMSGSIZE;
6682 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
6683 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
6684 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
6685 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
6686 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
6687 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
6688 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
6689 sys2et[EADDRINUSE] = UAEADDRINUSE;
6690 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
6691 sys2et[ENETDOWN] = UAENETDOWN;
6692 sys2et[ENETUNREACH] = UAENETUNREACH;
6693 sys2et[ENETRESET] = UAENETRESET;
6694 sys2et[ECONNABORTED] = UAECONNABORTED;
6695 sys2et[ECONNRESET] = UAECONNRESET;
6696 sys2et[ENOBUFS] = UAENOBUFS;
6697 sys2et[EISCONN] = UAEISCONN;
6698 sys2et[ENOTCONN] = UAENOTCONN;
6699 sys2et[ESHUTDOWN] = UAESHUTDOWN;
6700 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
6701 sys2et[ETIMEDOUT] = UAETIMEDOUT;
6702 sys2et[ECONNREFUSED] = UAECONNREFUSED;
6703 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
6704 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
6705 sys2et[EALREADY] = UAEALREADY;
6706 sys2et[EINPROGRESS] = UAEINPROGRESS;
6707 sys2et[ESTALE] = UAESTALE;
6708 sys2et[EUCLEAN] = UAEUCLEAN;
6709 sys2et[ENOTNAM] = UAENOTNAM;
6710 sys2et[ENAVAIL] = UAENAVAIL;
6711 sys2et[EISNAM] = UAEISNAM;
6712 sys2et[EREMOTEIO] = UAEREMOTEIO;
6713 sys2et[EDQUOT] = UAEDQUOT;
6714 sys2et[ENOMEDIUM] = UAENOMEDIUM;
6715 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
6717 sys2et[EIO] = UAEIO;
6721 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
6722 * - pass back the connection, client, and host from CallPreamble
6723 * - keep a ref on the client, which we don't now
6724 * - keep a hold on the host, which we already do
6725 * - pass the connection, client, and host down into SAFSS_*, and use
6726 * them instead of independently discovering them via rx_ConnectionOf
6727 * (safe) and rx_GetSpecific (not so safe)
6728 * The idea being that we decide what client and host we're going to use
6729 * when CallPreamble is called, and stay consistent throughout the call.
6730 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
6734 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
6736 Error errorCode = 0;
6737 struct rx_connection *tcon;
6738 struct host *tcallhost;
6739 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6741 struct client *tclient;
6742 static struct rx_securityClass *sc = 0;
6744 struct rx_connection *conn;
6747 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
6748 goto Bad_CallBackRxConnAddr1;
6750 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6754 tclient = h_FindClient_r(tcon);
6757 goto Bad_CallBackRxConnAddr;
6759 thost = tclient->host;
6761 /* nothing more can be done */
6762 if ( !thost->interface )
6763 goto Bad_CallBackRxConnAddr;
6765 /* the only address is the primary interface */
6766 /* can't change when there's only 1 address, anyway */
6767 if ( thost->interface->numberOfInterfaces <= 1 )
6768 goto Bad_CallBackRxConnAddr;
6770 /* initialise a security object only once */
6772 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
6774 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
6776 if ( *addr == thost->interface->addr[i] ) {
6781 if ( *addr != thost->interface->addr[i] )
6782 goto Bad_CallBackRxConnAddr;
6784 conn = rx_NewConnection (thost->interface->addr[i],
6785 thost->port, 1, sc, 0);
6786 rx_SetConnDeadTime(conn, 2);
6787 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
6789 errorCode = RXAFSCB_Probe(conn);
6792 if ( thost->callback_rxcon )
6793 rx_DestroyConnection(thost->callback_rxcon);
6794 thost->callback_rxcon = conn;
6796 rx_SetConnDeadTime(thost->callback_rxcon, 50);
6797 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
6798 h_ReleaseClient_r(tclient);
6799 /* The hold on thost will be released by CallPostamble */
6801 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6804 rx_DestroyConnection(conn);
6806 Bad_CallBackRxConnAddr:
6807 h_ReleaseClient_r(tclient);
6808 /* The hold on thost will be released by CallPostamble */
6812 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6813 Bad_CallBackRxConnAddr1:
6814 return errorCode; /* failure */
6818 sys_error_to_et(afs_int32 in)
6822 if (in < 0 || in > 511)
6824 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
6826 if (sys2et[in] != 0)