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>
36 #undef SHARED /* XXX */
41 #include <sys/param.h>
43 #include <sys/ioctl.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
50 #ifndef AFS_LINUX20_ENV
52 #ifndef AFS_ARM_DARWIN_ENV
53 #include <netinet/if_ether.h>
58 /* included early because of name conflict on IOPEN */
59 #include <sys/inode.h>
63 #endif /* AFS_HPUX_ENV */
67 #include <afs/afs_assert.h>
70 #include <afs/afsint.h>
71 #include <afs/vldbint.h>
72 #include <afs/errors.h>
73 #include <afs/ihandle.h>
74 #include <afs/vnode.h>
75 #include <afs/volume.h>
76 #include <afs/ptclient.h>
77 #include <afs/ptuser.h>
78 #include <afs/prs_fs.h>
81 #include <rx/rx_globals.h>
83 #if ! defined(AFS_SGI_ENV) && ! defined(AFS_AIX32_ENV) && ! defined(AFS_NT40_ENV) && ! defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
86 #if !defined(AFS_NT40_ENV)
89 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
91 #include <sys/statfs.h>
92 #include <sys/lockf.h>
94 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
99 #include <afs/cellconfig.h>
100 #include <afs/keys.h>
103 #include <afs/partition.h>
104 #include "viced_prototypes.h"
107 #include "callback.h"
108 #include <afs/unified_afs.h>
109 #include <afs/audit.h>
110 #include <afs/afsutil.h>
113 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
114 extern void FidZap(DirHandle * file);
115 extern void FidZero(DirHandle * file);
117 #ifdef AFS_PTHREAD_ENV
118 pthread_mutex_t fileproc_glock_mutex;
119 #endif /* AFS_PTHREAD_ENV */
122 #define afs_stat stat64
123 #define afs_fstat fstat64
124 #define afs_open open64
125 #else /* !O_LARGEFILE */
126 #define afs_stat stat
127 #define afs_fstat fstat
128 #define afs_open open
129 #endif /* !O_LARGEFILE */
132 /* Useful local defines used by this module */
135 #define MustNOTBeDIR 1
139 #define TVS_SSTATUS 2
142 #define TVS_MKDIR 0x10
144 #define CHK_FETCH 0x10
145 #define CHK_FETCHDATA 0x10
146 #define CHK_FETCHACL 0x11
147 #define CHK_FETCHSTATUS 0x12
148 #define CHK_STOREDATA 0x00
149 #define CHK_STOREACL 0x01
150 #define CHK_STORESTATUS 0x02
152 #define OWNERREAD 0400
153 #define OWNERWRITE 0200
154 #define OWNEREXEC 0100
155 #ifdef USE_GROUP_PERMS
156 #define GROUPREAD 0040
157 #define GROUPWRITE 0020
158 #define GROUPREXEC 0010
161 /* The following errors were not defined in NT. They are given unique
162 * names here to avoid any potential collision.
164 #define FSERR_ELOOP 90
165 #define FSERR_EOPNOTSUPP 122
166 #define FSERR_ECONNREFUSED 130
168 #define NOTACTIVECALL 0
171 #define CREATE_SGUID_ADMIN_ONLY 1
173 extern struct afsconf_dir *confDir;
174 extern afs_int32 dataVersionHigh;
177 static struct AFSCallStatistics AFSCallStats;
178 #if FS_STATS_DETAILED
179 struct fs_stats_FullPerfStats afs_FullPerfStats;
180 extern int AnonymousID;
181 #endif /* FS_STATS_DETAILED */
182 #if OPENAFS_VOL_STATS
183 static const char nullString[] = "";
184 #endif /* OPENAFS_VOL_STATS */
187 afs_int32 NothingYet;
190 struct afs_FSStats afs_fsstats;
195 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
197 extern afs_int32 implicitAdminRights;
198 extern afs_int32 readonlyServer;
199 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
200 extern afs_fsize_t CopyOnWrite_maxsize;
203 * Externals used by the xstat code.
205 extern VolPkgStats VStats;
206 extern int CEs, CEBlocks;
208 extern int HTs, HTBlocks;
210 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
211 struct rx_call *Call, afs_sfsize_t Pos,
212 afs_sfsize_t Len, afs_int32 Int64Mode,
213 #if FS_STATS_DETAILED
214 afs_sfsize_t * a_bytesToFetchP,
215 afs_sfsize_t * a_bytesFetchedP
216 #endif /* FS_STATS_DETAILED */
219 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
220 struct AFSFid *Fid, struct client *client,
221 struct rx_call *Call, afs_fsize_t Pos,
222 afs_fsize_t Length, afs_fsize_t FileLength,
224 #if FS_STATS_DETAILED
225 afs_sfsize_t * a_bytesToStoreP,
226 afs_sfsize_t * a_bytesStoredP
227 #endif /* FS_STATS_DETAILED */
230 #ifdef AFS_SGI_XFS_IOPS_ENV
231 #include <afs/xfsattrs.h>
233 GetLinkCount(Volume * avp, struct stat *astat)
235 if (!strcmp("xfs", astat->st_fstype)) {
236 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
238 return astat->st_nlink;
241 #define GetLinkCount(V, S) (S)->st_nlink
245 SpareComp(Volume * avolp)
251 temp = V_maxquota(avolp);
253 /* no matter; doesn't check in this case */
257 temp = (temp * PctSpare) / 100;
268 * Set the volume synchronization parameter for this volume. If it changes,
269 * the Cache Manager knows that the volume must be purged from the stat cache.
272 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
275 /* date volume instance was created */
278 async->spare1 = avol->header->diskstuff.creationDate;
291 * Note that this function always returns a held host, so
292 * that CallPostamble can block without the host's disappearing.
293 * Call returns rx connection in passed in *tconn
296 CallPreamble(struct rx_call *acall, int activecall,
297 struct rx_connection **tconn, struct host **ahostp)
300 struct client *tclient;
303 char hoststr[16], hoststr2[16];
304 #ifdef AFS_PTHREAD_ENV
305 struct ubik_client *uclient;
310 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
313 *tconn = rx_ConnectionOf(acall);
317 tclient = h_FindClient_r(*tconn);
319 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
323 thost = tclient->host;
324 if (tclient->prfail == 1) { /* couldn't get the CPS */
326 h_ReleaseClient_r(tclient);
328 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
332 retry_flag = 0; /* Retry once */
334 /* Take down the old connection and re-read the key file */
336 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
337 #ifdef AFS_PTHREAD_ENV
338 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
340 /* Is it still necessary to drop this? We hit the net, we should... */
346 code = hpr_Initialize(&uclient);
349 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
352 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
355 h_ReleaseClient_r(tclient);
358 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
362 tclient->prfail = 2; /* Means re-eval client's cps */
363 h_ReleaseClient_r(tclient);
368 tclient->LastCall = thost->LastCall = FT_ApproxTime();
369 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
370 thost->ActiveCall = thost->LastCall;
373 if (thost->hostFlags & HOSTDELETED) {
375 ("Discarded a packet for deleted host %s:%d\n",
376 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
377 code = VBUSY; /* raced, so retry */
378 } else if ((thost->hostFlags & VENUSDOWN)
379 || (thost->hostFlags & HFE_LATER)) {
380 if (BreakDelayedCallBacks_r(thost)) {
382 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
383 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
384 ntohs(rxr_PortOf(*tconn))));
385 if (MultiProbeAlternateAddress_r(thost)) {
387 ("MultiProbe failed to find new address for host %s:%d\n",
388 afs_inet_ntoa_r(thost->host, hoststr),
389 ntohs(thost->port)));
393 ("MultiProbe found new address for host %s:%d\n",
394 afs_inet_ntoa_r(thost->host, hoststr),
395 ntohs(thost->port)));
396 if (BreakDelayedCallBacks_r(thost)) {
398 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
399 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
400 ntohs(rxr_PortOf(*tconn))));
409 h_ReleaseClient_r(tclient);
419 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
423 struct client *tclient;
427 tclient = h_FindClient_r(aconn);
430 thost = tclient->host;
431 if (thost->hostFlags & HERRORTRANS)
433 h_ReleaseClient_r(tclient);
436 if (ahost != thost) {
437 /* host/client recycle */
438 char hoststr[16], hoststr2[16];
439 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
441 afs_inet_ntoa_r(ahost->host, hoststr),
444 afs_inet_ntoa_r(thost->host, hoststr2),
448 /* return the reference taken in CallPreamble */
452 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
453 afs_inet_ntoa_r(thost->host, hoststr),
458 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
459 * does not decrement refcount on client->host */
464 return (translate ? sys_error_to_et(ret) : ret);
468 * Returns the volume and vnode pointers associated with file Fid; the lock
469 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
470 * are incremented and they must be eventualy released.
473 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
476 Error local_errorCode, errorCode = -1;
477 static struct timeval restartedat = { 0, 0 };
479 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
481 if ((*volptr) == 0) {
486 #ifdef AFS_DEMAND_ATTACH_FS
492 #ifdef AFS_PTHREAD_ENV
493 static const struct timespec timeout_ts = { 0, 0 };
494 static const struct timespec * const ts = &timeout_ts;
496 static const struct timespec * const ts = NULL;
500 *volptr = VGetVolumeTimed(&local_errorCode, &errorCode, (afs_int32) fid->Volume, ts);
505 if ((errorCode == VOFFLINE) && (VInit < 2)) {
506 /* The volume we want may not be attached yet because
507 * the volume initialization is not yet complete.
508 * We can do several things:
509 * 1. return -1, which will cause users to see
510 * "connection timed out". This is more or
511 * less the same as always, except that the servers
512 * may appear to bounce up and down while they
513 * are actually restarting.
514 * 2. return VBUSY which will cause clients to
515 * sleep and retry for 6.5 - 15 minutes, depending
516 * on what version of the CM they are running. If
517 * the file server takes longer than that interval
518 * to attach the desired volume, then the application
519 * will see an ENODEV or EIO. This approach has
520 * the advantage that volumes which have been attached
521 * are immediately available, it keeps the server's
522 * immediate backlog low, and the call is interruptible
523 * by the user. Users see "waiting for busy volume."
524 * 3. sleep here and retry. Some people like this approach
525 * because there is no danger of seeing errors. However,
526 * this approach only works with a bounded number of
527 * clients, since the pending queues will grow without
528 * stopping. It might be better to find a way to take
529 * this call and stick it back on a queue in order to
530 * recycle this thread for a different request.
531 * 4. Return a new error code, which new cache managers will
532 * know enough to interpret as "sleep and retry", without
533 * the upper bound of 6-15 minutes that is imposed by the
534 * VBUSY handling. Users will see "waiting for
535 * busy volume," so they know that something is
536 * happening. Old cache managers must be able to do
537 * something reasonable with this, for instance, mark the
538 * server down. Fortunately, any error code < 0
539 * will elicit that behavior. See #1.
540 * 5. Some combination of the above. I like doing #2 for 10
541 * minutes, followed by #4. 3.1b and 3.2 cache managers
542 * will be fine as long as the restart period is
543 * not longer than 6.5 minutes, otherwise they may
544 * return ENODEV to users. 3.3 cache managers will be
545 * fine for 10 minutes, then will return
546 * ETIMEDOUT. 3.4 cache managers will just wait
547 * until the call works or fails definitively.
548 * NB. The problem with 2,3,4,5 is that old clients won't
549 * fail over to an alternate read-only replica while this
550 * server is restarting. 3.4 clients will fail over right away.
552 if (restartedat.tv_sec == 0) {
553 /* I'm not really worried about when we restarted, I'm */
554 /* just worried about when the first VBUSY was returned. */
555 FT_GetTimeOfDay(&restartedat, 0);
558 afs_perfstats.fs_nBusies++;
561 return (busyonrst ? VBUSY : restarting);
564 FT_GetTimeOfDay(&now, 0);
565 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
568 afs_perfstats.fs_nBusies++;
571 return (busyonrst ? VBUSY : restarting);
577 /* allow read operations on busy volume.
578 * must check local_errorCode because demand attach fs
579 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
580 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
581 #ifdef AFS_DEMAND_ATTACH_FS
582 /* DAFS case is complicated by the fact that local_errorCode can
583 * be VBUSY in cases where the volume is truly offline */
585 /* volume is in VOL_STATE_UNATTACHED */
588 #endif /* AFS_DEMAND_ATTACH_FS */
591 } else if (errorCode)
598 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
601 if ((*vptr)->disk.uniquifier != fid->Unique) {
602 VPutVnode(&fileCode, *vptr);
603 osi_Assert(fileCode == 0);
605 return (VNOVNODE); /* return the right error code, at least */
611 * This routine returns the ACL associated with the targetptr. If the
612 * targetptr isn't a directory, we access its parent dir and get the ACL
613 * thru the parent; in such case the parent's vnode is returned in
617 SetAccessList(Vnode ** targetptr, Volume ** volume,
618 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
619 AFSFid * Fid, int Lock)
621 if ((*targetptr)->disk.type == vDirectory) {
623 *ACL = VVnodeACL(*targetptr);
624 *ACLSize = VAclSize(*targetptr);
627 osi_Assert(Fid != 0);
632 parentvnode = (*targetptr)->disk.parent;
633 VPutVnode(&errorCode, *targetptr);
637 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
640 *ACL = VVnodeACL(*parent);
641 *ACLSize = VAclSize(*parent);
642 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
644 if ((*targetptr)->disk.parent != parentvnode) {
645 VPutVnode(&errorCode, *parent);
656 /* Must not be called with H_LOCK held */
658 client_CheckRights(struct client *client, struct acl_accessList *ACL,
662 ObtainReadLock(&client->lock);
663 if (client->CPS.prlist_len > 0 && !client->deleted &&
664 client->host && !(client->host->hostFlags & HOSTDELETED))
665 acl_CheckRights(ACL, &client->CPS, rights);
666 ReleaseReadLock(&client->lock);
669 /* Must not be called with H_LOCK held */
671 client_HasAsMember(struct client *client, afs_int32 id)
675 ObtainReadLock(&client->lock);
676 if (client->CPS.prlist_len > 0 && !client->deleted &&
677 client->host && !(client->host->hostFlags & HOSTDELETED))
678 code = acl_IsAMember(id, &client->CPS);
679 ReleaseReadLock(&client->lock);
684 * Compare the directory's ACL with the user's access rights in the client
685 * connection and return the user's and everybody else's access permissions
686 * in rights and anyrights, respectively
689 GetRights(struct client *client, struct acl_accessList *ACL,
690 afs_int32 * rights, afs_int32 * anyrights)
692 extern prlist SystemAnyUserCPS;
693 afs_int32 hrights = 0;
694 #ifndef AFS_PTHREAD_ENV
698 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
699 ViceLog(0, ("CheckRights failed\n"));
704 client_CheckRights(client, ACL, rights);
706 /* wait if somebody else is already doing the getCPS call */
708 while (client->host->hostFlags & HCPS_INPROGRESS) {
709 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
710 #ifdef AFS_PTHREAD_ENV
711 CV_WAIT(&client->host->cond, &host_glock_mutex);
712 #else /* AFS_PTHREAD_ENV */
714 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
715 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
716 #endif /* AFS_PTHREAD_ENV */
719 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
722 ("CheckRights: len=%u, for host=%s:%d\n",
723 client->host->hcps.prlist_len,
724 afs_inet_ntoa_r(client->host->host, hoststr),
725 ntohs(client->host->port)));
727 acl_CheckRights(ACL, &client->host->hcps, &hrights);
729 /* Allow system:admin the rights given with the -implicit option */
730 if (client_HasAsMember(client, SystemId))
731 *rights |= implicitAdminRights;
734 *anyrights |= hrights;
741 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
742 * a System:Administrator)
745 VanillaUser(struct client *client)
747 if (client_HasAsMember(client, SystemId))
748 return (0); /* not a system administrator, then you're "vanilla" */
755 * This unusual afs_int32-parameter routine encapsulates all volume package related
756 * operations together in a single function; it's called by almost all AFS
760 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
761 Vnode ** targetptr, int chkforDir, Vnode ** parent,
762 struct client **client, int locktype, afs_int32 * rights,
763 afs_int32 * anyrights)
765 struct acl_accessList *aCL; /* Internal access List */
766 int aCLSize; /* size of the access list */
767 Error errorCode = 0; /* return code to caller */
769 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
772 if (chkforDir == MustNOTBeDIR
773 && ((*targetptr)->disk.type == vDirectory))
775 else if (chkforDir == MustBeDIR
776 && ((*targetptr)->disk.type != vDirectory))
780 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
781 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
782 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
784 if (chkforDir == MustBeDIR)
785 osi_Assert((*parent) == 0);
787 if ((errorCode = GetClient(tcon, client)) != 0)
792 GetRights(*client, aCL, rights, anyrights);
793 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
794 if ((*targetptr)->disk.type != vDirectory) {
795 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
796 if ((*targetptr)->disk.owner == (*client)->ViceId)
797 (*rights) |= PRSFS_ADMINISTER;
799 (*rights) &= ~PRSFS_ADMINISTER;
801 #ifdef ADMIN_IMPLICIT_LOOKUP
802 /* admins get automatic lookup on everything */
803 if (!VanillaUser(*client))
804 (*rights) |= PRSFS_LOOKUP;
805 #endif /* ADMIN_IMPLICIT_LOOKUP */
808 } /*GetVolumePackage */
812 * This is the opposite of GetVolumePackage(), and is always used at the end of
813 * AFS calls to put back all used vnodes and the volume in the proper order!
816 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
817 Vnode * parentptr, Volume * volptr, struct client **client)
819 Error fileCode = 0; /* Error code returned by the volume package */
821 if (parentwhentargetnotdir) {
822 VPutVnode(&fileCode, parentwhentargetnotdir);
823 osi_Assert(!fileCode || (fileCode == VSALVAGE));
826 VPutVnode(&fileCode, targetptr);
827 osi_Assert(!fileCode || (fileCode == VSALVAGE));
830 VPutVnode(&fileCode, parentptr);
831 osi_Assert(!fileCode || (fileCode == VSALVAGE));
839 } /*PutVolumePackage */
842 VolumeOwner(struct client *client, Vnode * targetptr)
844 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
847 return (client->ViceId == owner);
850 * We don't have to check for host's cps since only regular
851 * viceid are volume owners.
853 return (client_HasAsMember(client, owner));
859 VolumeRootVnode(Vnode * targetptr)
861 return ((targetptr->vnodeNumber == ROOTVNODE)
862 && (targetptr->disk.uniquifier == 1));
864 } /*VolumeRootVnode */
867 * Check if target file has the proper access permissions for the Fetch
868 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
869 * StoreStatus) related calls
871 /* this code should probably just set a "priv" flag where all the audit events
872 * are now, and only generate the audit event once at the end of the routine,
873 * thus only generating the event if all the checks succeed, but only because
874 * of the privilege XXX
877 Check_PermissionRights(Vnode * targetptr, struct client *client,
878 afs_int32 rights, int CallingRoutine,
879 AFSStoreStatus * InStatus)
882 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
883 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
884 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
886 if (CallingRoutine & CHK_FETCH) {
887 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
888 if (targetptr->disk.type == vDirectory
889 || targetptr->disk.type == vSymlink) {
890 if (!(rights & PRSFS_LOOKUP)
891 #ifdef ADMIN_IMPLICIT_LOOKUP
892 /* grant admins fetch on all directories */
893 && VanillaUser(client)
894 #endif /* ADMIN_IMPLICIT_LOOKUP */
895 && !VolumeOwner(client, targetptr))
898 /* must have read access, or be owner and have insert access */
899 if (!(rights & PRSFS_READ)
900 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
903 if (CallingRoutine == CHK_FETCHDATA
904 && targetptr->disk.type == vFile)
905 #ifdef USE_GROUP_PERMS
906 if (!OWNSp(client, targetptr)
907 && !client_HasAsMember(client, targetptr->disk.owner)) {
909 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
913 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
918 * The check with the ownership below is a kludge to allow
919 * reading of files created with no read permission. The owner
920 * of the file is always allowed to read it.
922 if ((client->ViceId != targetptr->disk.owner)
923 && VanillaUser(client))
925 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
926 modeBits) ? 0 : EACCES);
928 } else { /* !VanillaUser(client) && !FetchData */
930 osi_audit(PrivilegeEvent, 0, AUD_ID,
931 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
934 } else { /* a store operation */
935 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
936 && (CallingRoutine != CHK_STOREACL)
937 && (targetptr->disk.type == vFile)) {
938 /* bypass protection checks on first store after a create
939 * for the creator; also prevent chowns during this time
940 * unless you are a system administrator */
941 /****** InStatus->Owner && UnixModeBits better be SET!! */
942 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
945 else if (VanillaUser(client))
946 return (EPERM); /* Was EACCES */
948 osi_audit(PrivilegeEvent, 0, AUD_ID,
949 (client ? client->ViceId : 0), AUD_INT,
950 CallingRoutine, AUD_END);
953 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
954 osi_audit(PrivilegeEvent, 0, AUD_ID,
955 (client ? client->ViceId : 0), AUD_INT,
956 CallingRoutine, AUD_END);
958 if (readonlyServer) {
961 if (CallingRoutine == CHK_STOREACL) {
962 if (!(rights & PRSFS_ADMINISTER)
963 && !VolumeOwner(client, targetptr))
965 } else { /* store data or status */
966 /* watch for chowns and chgrps */
967 if (CHOWN(InStatus, targetptr)
968 || CHGRP(InStatus, targetptr)) {
971 else if (VanillaUser(client))
972 return (EPERM); /* Was EACCES */
974 osi_audit(PrivilegeEvent, 0, AUD_ID,
975 (client ? client->ViceId : 0), AUD_INT,
976 CallingRoutine, AUD_END);
978 /* must be sysadmin to set suid/sgid bits */
979 if ((InStatus->Mask & AFS_SETMODE) &&
981 (InStatus->UnixModeBits & 0xc00) != 0) {
983 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
987 if (VanillaUser(client))
990 osi_audit(PrivSetID, 0, AUD_ID,
991 (client ? client->ViceId : 0), AUD_INT,
992 CallingRoutine, AUD_END);
994 if (CallingRoutine == CHK_STOREDATA) {
997 if (!(rights & PRSFS_WRITE))
999 /* Next thing is tricky. We want to prevent people
1000 * from writing files sans 0200 bit, but we want
1001 * creating new files with 0444 mode to work. We
1002 * don't check the 0200 bit in the "you are the owner"
1003 * path above, but here we check the bit. However, if
1004 * you're a system administrator, we ignore the 0200
1005 * bit anyway, since you may have fchowned the file,
1007 #ifdef USE_GROUP_PERMS
1008 if ((targetptr->disk.type == vFile)
1009 && VanillaUser(client)) {
1010 if (!OWNSp(client, targetptr)
1011 && !client_HasAsMember(client, targetptr->disk.owner)) {
1013 ((GROUPWRITE & targetptr->disk.modeBits)
1017 ((OWNERWRITE & targetptr->disk.modeBits)
1022 if ((targetptr->disk.type != vDirectory)
1023 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1026 if (VanillaUser(client))
1029 osi_audit(PrivilegeEvent, 0, AUD_ID,
1030 (client ? client->ViceId : 0),
1031 AUD_INT, CallingRoutine, AUD_END);
1033 } else { /* a status store */
1036 if (targetptr->disk.type == vDirectory) {
1037 if (!(rights & PRSFS_DELETE)
1038 && !(rights & PRSFS_INSERT))
1040 } else { /* a file or symlink */
1041 if (!(rights & PRSFS_WRITE))
1051 } /*Check_PermissionRights */
1055 * The Access List information is converted from its internal form in the
1056 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1057 * external form and returned back to the caller, via the AccessList
1061 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1062 struct AFSOpaque *AccessList)
1064 char *eACL; /* External access list placeholder */
1066 if (acl_Externalize_pr
1067 (hpr_IdToName, (targetptr->disk.type ==
1068 vDirectory ? VVnodeACL(targetptr) :
1069 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1072 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1073 acl_FreeExternalACL(&eACL);
1076 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1077 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1079 acl_FreeExternalACL(&eACL);
1082 } /*RXFetch_AccessList */
1086 * The Access List information is converted from its external form in the
1087 * input AccessList structure to the internal representation and copied into
1088 * the target dir's vnode storage.
1091 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1093 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1095 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1098 if ((newACL->size + 4) > VAclSize(targetptr))
1100 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1101 acl_FreeACL(&newACL);
1104 } /*RXStore_AccessList */
1107 /* In our current implementation, each successive data store (new file
1108 * data version) creates a new inode. This function creates the new
1109 * inode, copies the old inode's contents to the new one, remove the old
1110 * inode (i.e. decrement inode count -- if it's currently used the delete
1111 * will be delayed), and modify some fields (i.e. vnode's
1112 * disk.inodeNumber and cloned)
1114 #define COPYBUFFSIZE 8192
1115 #define MAXFSIZE (~(afs_fsize_t) 0)
1117 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1119 Inode ino, nearInode;
1126 int rc; /* return code */
1127 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1128 FdHandle_t *targFdP; /* Source Inode file handle */
1129 FdHandle_t *newFdP; /* Dest Inode file handle */
1131 if (targetptr->disk.type == vDirectory)
1132 DFlush(); /* just in case? */
1134 VN_GET_LEN(size, targetptr);
1142 buff = (char *)malloc(COPYBUFFSIZE);
1147 ino = VN_GET_INO(targetptr);
1148 if (!VALID_INO(ino)) {
1150 VTakeOffline(volptr);
1151 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1155 targFdP = IH_OPEN(targetptr->handle);
1156 if (targFdP == NULL) {
1159 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1160 targetptr->vnodeNumber, V_id(volptr), rc));
1162 VTakeOffline(volptr);
1166 nearInode = VN_GET_INO(targetptr);
1168 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1169 VPartitionPath(V_partition(volptr)), nearInode,
1170 V_id(volptr), targetptr->vnodeNumber,
1171 targetptr->disk.uniquifier,
1172 (int)targetptr->disk.dataVersion);
1173 if (!VALID_INO(ino)) {
1175 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1176 volptr->partition->name, V_id(volptr), errno));
1181 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1182 newFdP = IH_OPEN(newH);
1183 osi_Assert(newFdP != NULL);
1187 if (size > COPYBUFFSIZE) { /* more than a buffer */
1188 length = COPYBUFFSIZE;
1189 size -= COPYBUFFSIZE;
1194 rdlen = FDH_PREAD(targFdP, buff, length, done);
1195 if (rdlen == length) {
1196 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1200 /* Callers of this function are not prepared to recover
1201 * from error that put the filesystem in an inconsistent
1202 * state. Make sure that we force the volume off-line if
1203 * we some error other than ENOSPC - 4.29.99)
1205 * In case we are unable to write the required bytes, and the
1206 * error code indicates that the disk is full, we roll-back to
1207 * the initial state.
1209 if ((rdlen != length) || (wrlen != length)) {
1210 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1212 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1213 volptr->partition->name, V_id(volptr)));
1214 /* remove destination inode which was partially copied till now */
1215 FDH_REALLYCLOSE(newFdP);
1217 FDH_REALLYCLOSE(targFdP);
1218 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1221 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1222 rc, V_id(volptr), volptr->partition->name));
1223 VTakeOffline(volptr);
1228 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1229 * since we never do any I/O anywhere near 2^32 bytes at a
1230 * time, just case to an unsigned int for printing */
1233 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1234 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1235 (unsigned)wrlen, errno));
1236 #if defined(AFS_DEMAND_ATTACH_FS)
1237 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1239 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1241 /* Decrement this inode so salvager doesn't find it. */
1242 FDH_REALLYCLOSE(newFdP);
1244 FDH_REALLYCLOSE(targFdP);
1245 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1247 VTakeOffline(volptr);
1251 #ifndef AFS_PTHREAD_ENV
1253 #endif /* !AFS_PTHREAD_ENV */
1255 FDH_REALLYCLOSE(targFdP);
1256 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1257 V_parentId(volptr));
1259 IH_RELEASE(targetptr->handle);
1261 rc = FDH_SYNC(newFdP);
1262 osi_Assert(rc == 0);
1264 targetptr->handle = newH;
1265 VN_SET_INO(targetptr, ino);
1266 targetptr->disk.cloned = 0;
1267 /* Internal change to vnode, no user level change to volume - def 5445 */
1268 targetptr->changed_oldTime = 1;
1270 return 0; /* success */
1274 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1277 char *buff = malloc(COPYBUFFSIZE);
1282 afs_foff_t done = off;
1284 if (size > FDH_SIZE(targFdP) - off)
1285 size = FDH_SIZE(targFdP) - off;
1288 if (size > COPYBUFFSIZE) { /* more than a buffer */
1289 length = COPYBUFFSIZE;
1290 size -= COPYBUFFSIZE;
1295 rdlen = FDH_PREAD(targFdP, buff, length, done);
1296 if (rdlen == length) {
1297 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1303 if ((rdlen != length) || (wrlen != length)) {
1304 /* no error recovery, at the worst we'll have a "hole"
1316 * Common code to handle with removing the Name (file when it's called from
1317 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1318 * given directory, parentptr.
1320 int DT1 = 0, DT0 = 0;
1322 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1323 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1325 DirHandle childdir; /* Handle for dir package I/O */
1326 Error errorCode = 0;
1330 /* watch for invalid names */
1331 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1333 if (parentptr->disk.cloned) {
1334 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1335 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1337 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1343 /* check that the file is in the directory */
1344 SetDirHandle(dir, parentptr);
1345 if (Lookup(dir, Name, fileFid))
1347 fileFid->Volume = V_id(volptr);
1349 /* just-in-case check for something causing deadlock */
1350 if (fileFid->Vnode == parentptr->vnodeNumber)
1353 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1357 if (ChkForDir == MustBeDIR) {
1358 if ((*targetptr)->disk.type != vDirectory)
1360 } else if ((*targetptr)->disk.type == vDirectory)
1363 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1365 * If the uniquifiers dont match then instead of asserting
1366 * take the volume offline and return VSALVAGE
1368 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1369 VTakeOffline(volptr);
1371 ("Volume %u now offline, must be salvaged.\n",
1373 errorCode = VSALVAGE;
1377 if (ChkForDir == MustBeDIR) {
1378 SetDirHandle(&childdir, *targetptr);
1379 if (IsEmpty(&childdir) != 0)
1381 DZap((afs_int32 *) &childdir);
1383 (*targetptr)->delete = 1;
1384 } else if ((--(*targetptr)->disk.linkCount) == 0)
1385 (*targetptr)->delete = 1;
1386 if ((*targetptr)->delete) {
1387 if (VN_GET_INO(*targetptr)) {
1389 IH_REALLYCLOSE((*targetptr)->handle);
1391 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1392 V_parentId(volptr));
1393 IH_RELEASE((*targetptr)->handle);
1394 if (errorCode == -1) {
1396 ("DT: inode=%s, name=%s, errno=%d\n",
1397 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1399 if (errno != ENOENT)
1401 VTakeOffline(volptr);
1403 ("Volume %u now offline, must be salvaged.\n",
1411 VN_SET_INO(*targetptr, (Inode) 0);
1413 afs_fsize_t adjLength;
1414 VN_GET_LEN(adjLength, *targetptr);
1415 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1419 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1421 code = Delete(dir, (char *)Name);
1424 ("Error %d deleting %s\n", code,
1425 (((*targetptr)->disk.type ==
1426 Directory) ? "directory" : "file")));
1427 VTakeOffline(volptr);
1429 ("Volume %u now offline, must be salvaged.\n",
1442 * This routine updates the parent directory's status block after the
1443 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1444 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1448 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1449 int author, int linkcount,
1450 #if FS_STATS_DETAILED
1451 char a_inSameNetwork
1452 #endif /* FS_STATS_DETAILED */
1455 afs_fsize_t newlength; /* Holds new directory length */
1456 afs_fsize_t parentLength;
1458 #if FS_STATS_DETAILED
1459 Date currDate; /*Current date */
1460 int writeIdx; /*Write index to bump */
1461 int timeIdx; /*Authorship time index to bump */
1462 #endif /* FS_STATS_DETAILED */
1464 parentptr->disk.dataVersion++;
1465 newlength = (afs_fsize_t) Length(dir);
1467 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1468 * (create, symlink, link, makedir) so we need to check if we have enough space
1469 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1470 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1472 VN_GET_LEN(parentLength, parentptr);
1473 if (nBlocks(newlength) != nBlocks(parentLength)) {
1474 VAdjustDiskUsage(&errorCode, volptr,
1475 (nBlocks(newlength) - nBlocks(parentLength)),
1476 (nBlocks(newlength) - nBlocks(parentLength)));
1478 VN_SET_LEN(parentptr, newlength);
1480 #if FS_STATS_DETAILED
1482 * Update directory write stats for this volume. Note that the auth
1483 * counter is located immediately after its associated ``distance''
1486 if (a_inSameNetwork)
1487 writeIdx = VOL_STATS_SAME_NET;
1489 writeIdx = VOL_STATS_DIFF_NET;
1490 V_stat_writes(volptr, writeIdx)++;
1491 if (author != AnonymousID) {
1492 V_stat_writes(volptr, writeIdx + 1)++;
1496 * Update the volume's authorship information in response to this
1497 * directory operation. Get the current time, decide to which time
1498 * slot this operation belongs, and bump the appropriate slot.
1500 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1502 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1503 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1504 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1505 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1506 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1507 if (parentptr->disk.author == author) {
1508 V_stat_dirSameAuthor(volptr, timeIdx)++;
1510 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1512 #endif /* FS_STATS_DETAILED */
1514 parentptr->disk.author = author;
1515 parentptr->disk.linkCount = linkcount;
1516 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1517 parentptr->disk.serverModifyTime = FT_ApproxTime();
1518 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1523 * Update the target file's (or dir's) status block after the specified
1524 * operation is complete. Note that some other fields maybe updated by
1525 * the individual module.
1528 /* XXX INCOMPLETE - More attention is needed here! */
1530 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1531 struct client *client, AFSStoreStatus * InStatus,
1532 Vnode * parentptr, Volume * volptr,
1535 #if FS_STATS_DETAILED
1536 Date currDate; /*Current date */
1537 int writeIdx; /*Write index to bump */
1538 int timeIdx; /*Authorship time index to bump */
1539 #endif /* FS_STATS_DETAILED */
1541 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1542 targetptr->disk.parent = parentptr->vnodeNumber;
1543 VN_SET_LEN(targetptr, length);
1544 /* targetptr->disk.group = 0; save some cycles */
1545 targetptr->disk.modeBits = 0777;
1546 targetptr->disk.owner = client->ViceId;
1547 targetptr->disk.dataVersion = 0; /* consistent with the client */
1548 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1549 /* the inode was created in Alloc_NewVnode() */
1551 #if FS_STATS_DETAILED
1553 * Update file write stats for this volume. Note that the auth
1554 * counter is located immediately after its associated ``distance''
1557 if (client->InSameNetwork)
1558 writeIdx = VOL_STATS_SAME_NET;
1560 writeIdx = VOL_STATS_DIFF_NET;
1561 V_stat_writes(volptr, writeIdx)++;
1562 if (client->ViceId != AnonymousID) {
1563 V_stat_writes(volptr, writeIdx + 1)++;
1567 * We only count operations that DON'T involve creating new objects
1568 * (files, symlinks, directories) or simply setting status as
1569 * authorship-change operations.
1571 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1573 * Update the volume's authorship information in response to this
1574 * file operation. Get the current time, decide to which time
1575 * slot this operation belongs, and bump the appropriate slot.
1577 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1580 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1581 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1582 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1583 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1584 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1585 VOL_STATS_TIME_IDX_5);
1586 if (targetptr->disk.author == client->ViceId) {
1587 V_stat_fileSameAuthor(volptr, timeIdx)++;
1589 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1592 #endif /* FS_STATS_DETAILED */
1594 if (!(Caller & TVS_SSTATUS))
1595 targetptr->disk.author = client->ViceId;
1596 if (Caller & TVS_SDATA) {
1597 targetptr->disk.dataVersion++;
1598 if (VanillaUser(client)) {
1599 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1600 #ifdef CREATE_SGUID_ADMIN_ONLY
1601 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1605 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1606 /* store status, must explicitly request to change the date */
1607 if (InStatus->Mask & AFS_SETMODTIME)
1608 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1609 } else { /* other: date always changes, but perhaps to what is specified by caller */
1610 targetptr->disk.unixModifyTime =
1611 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1612 ClientModTime : FT_ApproxTime());
1614 if (InStatus->Mask & AFS_SETOWNER) {
1615 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1616 if (VanillaUser(client)) {
1617 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1618 #ifdef CREATE_SGUID_ADMIN_ONLY
1619 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1622 targetptr->disk.owner = InStatus->Owner;
1623 if (VolumeRootVnode(targetptr)) {
1624 Error errorCode = 0; /* what should be done with this? */
1626 V_owner(targetptr->volumePtr) = InStatus->Owner;
1627 VUpdateVolume(&errorCode, targetptr->volumePtr);
1630 if (InStatus->Mask & AFS_SETMODE) {
1631 int modebits = InStatus->UnixModeBits;
1632 #define CREATE_SGUID_ADMIN_ONLY 1
1633 #ifdef CREATE_SGUID_ADMIN_ONLY
1634 if (VanillaUser(client))
1635 modebits = modebits & 0777;
1637 if (VanillaUser(client)) {
1638 targetptr->disk.modeBits = modebits;
1640 targetptr->disk.modeBits = modebits;
1643 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1644 CHK_STOREDATA, AUD_END);
1648 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1649 CHK_STORESTATUS, AUD_END);
1656 targetptr->disk.serverModifyTime = FT_ApproxTime();
1657 if (InStatus->Mask & AFS_SETGROUP)
1658 targetptr->disk.group = InStatus->Group;
1659 /* vnode changed : to be written back by VPutVnode */
1660 targetptr->changed_newTime = 1;
1662 } /*Update_TargetVnodeStatus */
1666 * Fills the CallBack structure with the expiration time and type of callback
1667 * structure. Warning: this function is currently incomplete.
1670 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1672 /* CallBackTime could not be 0 */
1673 if (CallBackTime == 0) {
1674 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1675 CallBack->ExpirationTime = 0;
1677 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1678 CallBack->CallBackVersion = CALLBACK_VERSION;
1679 CallBack->CallBackType = CB_SHARED; /* The default for now */
1681 } /*SetCallBackStruct */
1685 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1686 * allocation; if some error occured (exceeded volume quota or partition
1687 * was full, or whatever), it frees the space back and returns the code.
1688 * We usually pre-adjust the volume space to make sure that there's
1689 * enough space before consuming some.
1692 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1693 afs_sfsize_t checkLength)
1698 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1700 VAdjustDiskUsage(&nc, volptr, -length, 0);
1701 if (rc == VOVERQUOTA) {
1703 ("Volume %u (%s) is full\n", V_id(volptr),
1707 if (rc == VDISKFULL) {
1709 ("Partition %s that contains volume %u is full\n",
1710 volptr->partition->name, V_id(volptr)));
1713 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1718 } /*AdjustDiskUsage */
1721 * Common code that handles the creation of a new file (SAFS_CreateFile and
1722 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1725 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1726 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1727 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1729 Error errorCode = 0; /* Error code returned back */
1732 Inode nearInode; /* hint for inode allocation in solaris */
1736 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1737 BlocksPreallocatedForVnode))) {
1739 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1740 (afs_intmax_t) BlocksPreallocatedForVnode));
1744 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1745 if (errorCode != 0) {
1746 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1749 OutFid->Volume = V_id(volptr);
1750 OutFid->Vnode = (*targetptr)->vnodeNumber;
1751 OutFid->Unique = (*targetptr)->disk.uniquifier;
1753 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1755 /* create the inode now itself */
1757 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1758 VPartitionPath(V_partition(volptr)), nearInode,
1759 V_id(volptr), (*targetptr)->vnodeNumber,
1760 (*targetptr)->disk.uniquifier, 1);
1762 /* error in creating inode */
1763 if (!VALID_INO(inode)) {
1765 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1766 (*targetptr)->volumePtr->header->diskstuff.id,
1767 (*targetptr)->vnodeNumber, errno));
1768 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1769 (*targetptr)->delete = 1; /* delete vnode */
1772 VN_SET_INO(*targetptr, inode);
1773 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1775 /* copy group from parent dir */
1776 (*targetptr)->disk.group = parentptr->disk.group;
1778 if (parentptr->disk.cloned) {
1779 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1780 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1781 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1782 /* delete the vnode previously allocated */
1783 (*targetptr)->delete = 1;
1784 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1785 IH_REALLYCLOSE((*targetptr)->handle);
1786 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1788 ("Alloc_NewVnode: partition %s idec %s failed\n",
1789 volptr->partition->name, PrintInode(stmp, inode)));
1790 IH_RELEASE((*targetptr)->handle);
1796 /* add the name to the directory */
1797 SetDirHandle(dir, parentptr);
1798 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1799 (*targetptr)->delete = 1;
1800 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1801 IH_REALLYCLOSE((*targetptr)->handle);
1802 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1804 ("Alloc_NewVnode: partition %s idec %s failed\n",
1805 volptr->partition->name, PrintInode(stmp, inode)));
1806 IH_RELEASE((*targetptr)->handle);
1812 } /*Alloc_NewVnode */
1816 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1820 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1822 int Time; /* Used for time */
1823 int writeVnode = targetptr->changed_oldTime; /* save original status */
1825 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1826 Time = FT_ApproxTime();
1827 switch (LockingType) {
1830 if (Time > targetptr->disk.lock.lockTime)
1831 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1833 Time += AFS_LOCKWAIT;
1834 if (LockingType == LockRead) {
1835 if ( !(rights & PRSFS_LOCK) &&
1836 !(rights & PRSFS_WRITE) &&
1837 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1840 if (targetptr->disk.lock.lockCount >= 0) {
1841 ++(targetptr->disk.lock.lockCount);
1842 targetptr->disk.lock.lockTime = Time;
1845 } else if (LockingType == LockWrite) {
1846 if ( !(rights & PRSFS_WRITE) &&
1847 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1850 if (targetptr->disk.lock.lockCount == 0) {
1851 targetptr->disk.lock.lockCount = -1;
1852 targetptr->disk.lock.lockTime = Time;
1858 Time += AFS_LOCKWAIT;
1859 if (targetptr->disk.lock.lockCount != 0)
1860 targetptr->disk.lock.lockTime = Time;
1865 if ((--targetptr->disk.lock.lockCount) <= 0)
1866 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1870 targetptr->changed_oldTime = writeVnode; /* restore old status */
1871 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1874 } /*HandleLocking */
1876 /* 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. */
1879 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1883 if (!(rights & Prfs_Mode))
1885 if ((targetptr->disk.type != vDirectory)
1886 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1892 * If some flags (i.e. min or max quota) are set, the volume's in disk
1893 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1894 * update, if applicable.
1897 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1898 char *Name, char *OfflineMsg, char *Motd)
1900 Error errorCode = 0;
1902 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1903 V_minquota(volptr) = StoreVolStatus->MinQuota;
1904 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1905 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1906 if (strlen(OfflineMsg) > 0) {
1907 strcpy(V_offlineMessage(volptr), OfflineMsg);
1909 if (strlen(Name) > 0) {
1910 strcpy(V_name(volptr), Name);
1912 #if OPENAFS_VOL_STATS
1914 * We don't overwrite the motd field, since it's now being used
1918 if (strlen(Motd) > 0) {
1919 strcpy(V_motd(volptr), Motd);
1921 #endif /* FS_STATS_DETAILED */
1922 VUpdateVolume(&errorCode, volptr);
1925 } /*RXUpdate_VolumeStatus */
1929 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1930 char **motd, Volume * volptr)
1934 status->Vid = V_id(volptr);
1935 status->ParentId = V_parentId(volptr);
1936 status->Online = V_inUse(volptr);
1937 status->InService = V_inService(volptr);
1938 status->Blessed = V_blessed(volptr);
1939 status->NeedsSalvage = V_needsSalvaged(volptr);
1940 if (VolumeWriteable(volptr))
1941 status->Type = ReadWrite;
1943 status->Type = ReadOnly;
1944 status->MinQuota = V_minquota(volptr);
1945 status->MaxQuota = V_maxquota(volptr);
1946 status->BlocksInUse = V_diskused(volptr);
1947 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1948 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1950 /* now allocate and copy these things; they're freed by the RXGEN stub */
1951 temp = strlen(V_name(volptr)) + 1;
1952 *name = malloc(temp);
1954 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1955 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1957 strcpy(*name, V_name(volptr));
1958 temp = strlen(V_offlineMessage(volptr)) + 1;
1959 *offMsg = malloc(temp);
1961 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1962 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1964 strcpy(*offMsg, V_offlineMessage(volptr));
1965 #if OPENAFS_VOL_STATS
1968 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1969 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1971 strcpy(*motd, nullString);
1973 temp = strlen(V_motd(volptr)) + 1;
1974 *motd = malloc(temp);
1976 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1977 osi_Panic("Failed malloc in RXGetVolumeStatus\n");
1979 strcpy(*motd, V_motd(volptr));
1980 #endif /* FS_STATS_DETAILED */
1982 } /*RXGetVolumeStatus */
1986 FileNameOK(char *aname)
1991 /* watch for @sys on the right */
1992 if (strcmp(aname + i - 4, "@sys") == 0)
1995 while ((tc = *aname++)) {
1997 return 0; /* very bad character to encounter */
1999 return 1; /* file name is ok */
2005 * This variant of symlink is expressly to support the AFS/DFS translator
2006 * and is not supported by the AFS fileserver. We just return EINVAL.
2007 * The cache manager should not generate this call to an AFS cache manager.
2010 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2011 char *LinkContents, struct AFSStoreStatus *InStatus,
2012 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2013 struct AFSFetchStatus *OutDirStatus,
2014 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2020 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2021 struct FsCmdInputs * Inputs,
2022 struct FsCmdOutputs * Outputs)
2026 switch (Inputs->command) {
2030 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2031 Inputs->command, Outputs->code));
2036 static struct afs_buffer {
2037 struct afs_buffer *next;
2038 } *freeBufferList = 0;
2039 static int afs_buffersAlloced = 0;
2042 FreeSendBuffer(struct afs_buffer *adata)
2045 afs_buffersAlloced--;
2046 adata->next = freeBufferList;
2047 freeBufferList = adata;
2051 } /*FreeSendBuffer */
2053 /* allocate space for sender */
2055 AllocSendBuffer(void)
2057 struct afs_buffer *tp;
2060 afs_buffersAlloced++;
2061 if (!freeBufferList) {
2064 tmp = malloc(sendBufSize);
2066 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2067 osi_Panic("Failed malloc in AllocSendBuffer\n");
2071 tp = freeBufferList;
2072 freeBufferList = tp->next;
2076 } /*AllocSendBuffer */
2077 #endif /* HAVE_PIOV */
2080 * This routine returns the status info associated with the targetptr vnode
2081 * in the AFSFetchStatus structure. Some of the newer fields, such as
2082 * SegSize and Group are not yet implemented
2086 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2087 afs_int32 anyrights, Vnode * parentptr)
2089 /* initialize return status from a vnode */
2090 status->InterfaceVersion = 1;
2091 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2092 status->errorCode = 0;
2093 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2094 if (targetptr->disk.type == vFile)
2095 status->FileType = File;
2096 else if (targetptr->disk.type == vDirectory)
2097 status->FileType = Directory;
2098 else if (targetptr->disk.type == vSymlink)
2099 status->FileType = SymbolicLink;
2101 status->FileType = Invalid; /*invalid type field */
2102 status->LinkCount = targetptr->disk.linkCount;
2104 afs_fsize_t targetLen;
2105 VN_GET_LEN(targetLen, targetptr);
2106 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2108 status->DataVersion = targetptr->disk.dataVersion;
2109 status->Author = targetptr->disk.author;
2110 status->Owner = targetptr->disk.owner;
2111 status->CallerAccess = rights;
2112 status->AnonymousAccess = anyrights;
2113 status->UnixModeBits = targetptr->disk.modeBits;
2114 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2115 status->ParentVnode =
2116 (status->FileType ==
2117 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2118 status->ParentUnique =
2119 (status->FileType ==
2120 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2121 status->ServerModTime = targetptr->disk.serverModifyTime;
2122 status->Group = targetptr->disk.group;
2123 status->lockCount = targetptr->disk.lock.lockCount;
2124 status->errorCode = 0;
2130 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2131 afs_sfsize_t Pos, afs_sfsize_t Len,
2132 struct AFSFetchStatus *OutStatus,
2133 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2136 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2137 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2138 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2139 Error errorCode = 0; /* return code to caller */
2140 Error fileCode = 0; /* return code from vol package */
2141 Volume *volptr = 0; /* pointer to the volume */
2142 struct client *client = 0; /* pointer to the client data */
2143 struct rx_connection *tcon; /* the connection we're part of */
2145 afs_int32 rights, anyrights; /* rights for this and any user */
2146 struct client *t_client = NULL; /* tmp ptr to client data */
2147 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2148 #if FS_STATS_DETAILED
2149 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2150 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2151 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2152 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2153 struct timeval elapsedTime; /* Transfer time */
2154 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2155 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2156 int readIdx; /* Index of read stats array to bump */
2157 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2160 * Set our stats pointers, remember when the RPC operation started, and
2161 * tally the operation.
2163 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2164 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2168 FT_GetTimeOfDay(&opStartTime, 0);
2169 #endif /* FS_STATS_DETAILED */
2172 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2175 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2177 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2180 /* Get ptr to client data for user Id for logging */
2181 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2182 logHostAddr.s_addr = rxr_HostOf(tcon);
2184 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2185 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2186 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2188 * Get volume/vnode for the fetched file; caller's access rights to
2189 * it are also returned
2192 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2193 &parentwhentargetnotdir, &client, READ_LOCK,
2194 &rights, &anyrights)))
2197 SetVolumeSync(Sync, volptr);
2199 #if FS_STATS_DETAILED
2201 * Remember that another read operation was performed.
2204 if (client->InSameNetwork)
2205 readIdx = VOL_STATS_SAME_NET;
2207 readIdx = VOL_STATS_DIFF_NET;
2208 V_stat_reads(volptr, readIdx)++;
2209 if (client->ViceId != AnonymousID) {
2210 V_stat_reads(volptr, readIdx + 1)++;
2213 #endif /* FS_STATS_DETAILED */
2214 /* Check whether the caller has permission access to fetch the data */
2216 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2220 * Drop the read lock on the parent directory after saving the parent
2221 * vnode information we need to pass to GetStatus
2223 if (parentwhentargetnotdir != NULL) {
2224 tparentwhentargetnotdir = *parentwhentargetnotdir;
2225 VPutVnode(&fileCode, parentwhentargetnotdir);
2226 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2227 parentwhentargetnotdir = NULL;
2229 #if FS_STATS_DETAILED
2231 * Remember when the data transfer started.
2233 FT_GetTimeOfDay(&xferStartTime, 0);
2234 #endif /* FS_STATS_DETAILED */
2236 /* actually do the data transfer */
2237 #if FS_STATS_DETAILED
2239 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2240 &bytesToXfer, &bytesXferred);
2243 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2245 #endif /* FS_STATS_DETAILED */
2247 #if FS_STATS_DETAILED
2249 * At this point, the data transfer is done, for good or ill. Remember
2250 * when the transfer ended, bump the number of successes/failures, and
2251 * integrate the transfer size and elapsed time into the stats. If the
2252 * operation failed, we jump to the appropriate point.
2254 FT_GetTimeOfDay(&xferStopTime, 0);
2256 (xferP->numXfers)++;
2258 (xferP->numSuccesses)++;
2261 * Bump the xfer sum by the number of bytes actually sent, NOT the
2264 tot_bytesXferred += bytesXferred;
2265 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2266 tot_bytesXferred &= 0x3FF;
2267 if (bytesXferred < xferP->minBytes)
2268 xferP->minBytes = bytesXferred;
2269 if (bytesXferred > xferP->maxBytes)
2270 xferP->maxBytes = bytesXferred;
2273 * Tally the size of the object. Note: we tally the actual size,
2274 * NOT the number of bytes that made it out over the wire.
2276 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2277 (xferP->count[0])++;
2278 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2279 (xferP->count[1])++;
2280 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2281 (xferP->count[2])++;
2282 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2283 (xferP->count[3])++;
2284 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2285 (xferP->count[4])++;
2286 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2287 (xferP->count[5])++;
2288 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2289 (xferP->count[6])++;
2290 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2291 (xferP->count[7])++;
2293 (xferP->count[8])++;
2295 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2296 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2297 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2298 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2299 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2301 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2302 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2307 * Finally, go off to tell our caller the bad news in case the
2312 #endif /* FS_STATS_DETAILED */
2314 /* write back the OutStatus from the target vnode */
2315 GetStatus(targetptr, OutStatus, rights, anyrights,
2316 &tparentwhentargetnotdir);
2318 /* if a r/w volume, promise a callback to the caller */
2319 if (VolumeWriteable(volptr))
2320 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2322 struct AFSFid myFid;
2323 memset(&myFid, 0, sizeof(struct AFSFid));
2324 myFid.Volume = Fid->Volume;
2325 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2329 /* Update and store volume/vnode and parent vnodes back */
2330 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2332 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2333 errorCode = CallPostamble(tcon, errorCode, thost);
2335 #if FS_STATS_DETAILED
2336 FT_GetTimeOfDay(&opStopTime, 0);
2337 if (errorCode == 0) {
2339 (opP->numSuccesses)++;
2340 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2341 fs_stats_AddTo((opP->sumTime), elapsedTime);
2342 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2343 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2344 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2346 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2347 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2351 #endif /* FS_STATS_DETAILED */
2353 osi_auditU(acall, FetchDataEvent, errorCode,
2354 AUD_ID, t_client ? t_client->ViceId : 0,
2355 AUD_FID, Fid, AUD_END);
2358 } /*SRXAFS_FetchData */
2361 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2362 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2363 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2365 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2370 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2371 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2372 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2375 afs_sfsize_t tPos, tLen;
2377 tPos = (afs_sfsize_t) Pos;
2378 tLen = (afs_sfsize_t) Len;
2381 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2387 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2388 struct AFSOpaque * AccessList,
2389 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2391 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2392 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2393 Error errorCode = 0; /* return error code to caller */
2394 Volume *volptr = 0; /* pointer to the volume */
2395 struct client *client = 0; /* pointer to the client data */
2396 afs_int32 rights, anyrights; /* rights for this and any user */
2397 struct rx_connection *tcon = rx_ConnectionOf(acall);
2399 struct client *t_client = NULL; /* tmp ptr to client data */
2400 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2401 #if FS_STATS_DETAILED
2402 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2403 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2404 struct timeval elapsedTime; /* Transfer time */
2407 * Set our stats pointer, remember when the RPC operation started, and
2408 * tally the operation.
2410 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2414 FT_GetTimeOfDay(&opStartTime, 0);
2415 #endif /* FS_STATS_DETAILED */
2418 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2421 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2423 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2426 /* Get ptr to client data for user Id for logging */
2427 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2428 logHostAddr.s_addr = rxr_HostOf(tcon);
2430 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2431 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2432 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2434 AccessList->AFSOpaque_len = 0;
2435 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2436 if (!AccessList->AFSOpaque_val) {
2437 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2438 osi_Panic("Failed malloc in SRXAFS_FetchACL\n");
2442 * Get volume/vnode for the fetched file; caller's access rights to it
2446 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2447 &parentwhentargetnotdir, &client, READ_LOCK,
2448 &rights, &anyrights)))
2451 SetVolumeSync(Sync, volptr);
2453 /* Check whether we have permission to fetch the ACL */
2455 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2458 /* Get the Access List from the dir's vnode */
2460 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2463 /* Get OutStatus back From the target Vnode */
2464 GetStatus(targetptr, OutStatus, rights, anyrights,
2465 parentwhentargetnotdir);
2468 /* Update and store volume/vnode and parent vnodes back */
2469 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2472 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2473 AccessList->AFSOpaque_val));
2474 errorCode = CallPostamble(tcon, errorCode, thost);
2476 #if FS_STATS_DETAILED
2477 FT_GetTimeOfDay(&opStopTime, 0);
2478 if (errorCode == 0) {
2480 (opP->numSuccesses)++;
2481 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2482 fs_stats_AddTo((opP->sumTime), elapsedTime);
2483 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2484 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2485 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2487 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2488 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2492 #endif /* FS_STATS_DETAILED */
2494 osi_auditU(acall, FetchACLEvent, errorCode,
2495 AUD_ID, t_client ? t_client->ViceId : 0,
2497 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2499 } /*SRXAFS_FetchACL */
2503 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2504 * merged into it when possible.
2508 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2509 struct AFSFetchStatus *OutStatus,
2510 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2512 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2513 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2514 Error errorCode = 0; /* return code to caller */
2515 Volume *volptr = 0; /* pointer to the volume */
2516 struct client *client = 0; /* pointer to the client data */
2517 afs_int32 rights, anyrights; /* rights for this and any user */
2518 struct client *t_client = NULL; /* tmp ptr to client data */
2519 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2520 struct rx_connection *tcon = rx_ConnectionOf(acall);
2522 /* Get ptr to client data for user Id for logging */
2523 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2524 logHostAddr.s_addr = rxr_HostOf(tcon);
2526 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2527 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2528 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2530 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2533 * Get volume/vnode for the fetched file; caller's rights to it are
2537 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2538 &parentwhentargetnotdir, &client, READ_LOCK,
2539 &rights, &anyrights)))
2540 goto Bad_FetchStatus;
2542 /* set volume synchronization information */
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_FetchStatus;
2556 /* set OutStatus From the Fid */
2557 GetStatus(targetptr, OutStatus, rights, anyrights,
2558 parentwhentargetnotdir);
2560 /* If a r/w volume, also set the CallBack state */
2561 if (VolumeWriteable(volptr))
2562 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2564 struct AFSFid myFid;
2565 memset(&myFid, 0, sizeof(struct AFSFid));
2566 myFid.Volume = Fid->Volume;
2567 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2571 /* Update and store volume/vnode and parent vnodes back */
2572 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2574 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2577 } /*SAFSS_FetchStatus */
2581 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2582 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2583 struct AFSVolSync * Sync)
2587 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2588 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2589 Error errorCode = 0; /* return code to caller */
2590 Volume *volptr = 0; /* pointer to the volume */
2591 struct client *client = 0; /* pointer to the client data */
2592 afs_int32 rights, anyrights; /* rights for this and any user */
2593 struct AFSFid *tfid; /* file id we're dealing with now */
2594 struct rx_connection *tcon = rx_ConnectionOf(acall);
2596 struct client *t_client = NULL; /* tmp pointer to the client data */
2597 #if FS_STATS_DETAILED
2598 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2599 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2600 struct timeval elapsedTime; /* Transfer time */
2603 * Set our stats pointer, remember when the RPC operation started, and
2604 * tally the operation.
2606 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2610 FT_GetTimeOfDay(&opStartTime, 0);
2611 #endif /* FS_STATS_DETAILED */
2613 ViceLog(1, ("SAFS_BulkStatus\n"));
2615 AFSCallStats.TotalCalls++;
2617 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2618 if (nfiles <= 0) { /* Sanity check */
2620 goto Audit_and_Return;
2623 /* allocate space for return output parameters */
2624 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2625 malloc(nfiles * sizeof(struct AFSFetchStatus));
2626 if (!OutStats->AFSBulkStats_val) {
2627 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2628 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2630 OutStats->AFSBulkStats_len = nfiles;
2631 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2632 malloc(nfiles * sizeof(struct AFSCallBack));
2633 if (!CallBacks->AFSCBs_val) {
2634 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2635 osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
2637 CallBacks->AFSCBs_len = nfiles;
2639 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2640 goto Bad_BulkStatus;
2642 tfid = Fids->AFSCBFids_val;
2643 for (i = 0; i < nfiles; i++, tfid++) {
2645 * Get volume/vnode for the fetched file; caller's rights to it
2649 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2650 &parentwhentargetnotdir, &client, READ_LOCK,
2651 &rights, &anyrights)))
2652 goto Bad_BulkStatus;
2653 /* set volume synchronization information, but only once per call */
2655 SetVolumeSync(Sync, volptr);
2657 /* Are we allowed to fetch Fid's status? */
2658 if (targetptr->disk.type != vDirectory) {
2660 Check_PermissionRights(targetptr, client, rights,
2661 CHK_FETCHSTATUS, 0))) {
2662 if (rx_GetCallAbortCode(acall) == errorCode)
2663 rx_SetCallAbortCode(acall, 0);
2664 goto Bad_BulkStatus;
2668 /* set OutStatus From the Fid */
2669 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2670 anyrights, parentwhentargetnotdir);
2672 /* If a r/w volume, also set the CallBack state */
2673 if (VolumeWriteable(volptr))
2674 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2675 &CallBacks->AFSCBs_val[i]);
2677 struct AFSFid myFid;
2678 memset(&myFid, 0, sizeof(struct AFSFid));
2679 myFid.Volume = tfid->Volume;
2680 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2681 &CallBacks->AFSCBs_val[i]);
2684 /* put back the file ID and volume */
2685 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2687 parentwhentargetnotdir = (Vnode *) 0;
2688 targetptr = (Vnode *) 0;
2689 volptr = (Volume *) 0;
2690 client = (struct client *)0;
2694 /* Update and store volume/vnode and parent vnodes back */
2695 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2697 errorCode = CallPostamble(tcon, errorCode, thost);
2699 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2701 #if FS_STATS_DETAILED
2702 FT_GetTimeOfDay(&opStopTime, 0);
2703 if (errorCode == 0) {
2705 (opP->numSuccesses)++;
2706 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2707 fs_stats_AddTo((opP->sumTime), elapsedTime);
2708 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2709 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2710 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2712 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2713 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2717 #endif /* FS_STATS_DETAILED */
2720 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2721 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2722 AUD_ID, t_client ? t_client->ViceId : 0,
2723 AUD_FIDS, Fids, AUD_END);
2726 } /*SRXAFS_BulkStatus */
2730 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2731 struct AFSBulkStats * OutStats,
2732 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2736 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2737 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2738 Error errorCode = 0; /* return code to caller */
2739 Volume *volptr = 0; /* pointer to the volume */
2740 struct client *client = 0; /* pointer to the client data */
2741 afs_int32 rights, anyrights; /* rights for this and any user */
2742 struct AFSFid *tfid; /* file id we're dealing with now */
2743 struct rx_connection *tcon;
2745 struct client *t_client = NULL; /* tmp ptr to client data */
2746 AFSFetchStatus *tstatus;
2747 int VolSync_set = 0;
2748 #if FS_STATS_DETAILED
2749 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2750 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2751 struct timeval elapsedTime; /* Transfer time */
2754 * Set our stats pointer, remember when the RPC operation started, and
2755 * tally the operation.
2757 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2761 FT_GetTimeOfDay(&opStartTime, 0);
2762 #endif /* FS_STATS_DETAILED */
2764 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2766 AFSCallStats.TotalCalls++;
2768 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2769 if (nfiles <= 0) { /* Sanity check */
2771 goto Audit_and_Return;
2774 /* allocate space for return output parameters */
2775 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2776 malloc(nfiles * sizeof(struct AFSFetchStatus));
2777 if (!OutStats->AFSBulkStats_val) {
2778 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2779 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2781 OutStats->AFSBulkStats_len = nfiles;
2782 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2783 malloc(nfiles * sizeof(struct AFSCallBack));
2784 if (!CallBacks->AFSCBs_val) {
2785 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2786 osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
2788 CallBacks->AFSCBs_len = nfiles;
2790 /* Zero out return values to avoid leaking information on partial succes */
2791 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2792 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2793 memset(Sync, 0, sizeof(*Sync));
2795 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2796 goto Bad_InlineBulkStatus;
2799 tfid = Fids->AFSCBFids_val;
2800 for (i = 0; i < nfiles; i++, tfid++) {
2802 * Get volume/vnode for the fetched file; caller's rights to it
2806 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2807 &parentwhentargetnotdir, &client, READ_LOCK,
2808 &rights, &anyrights))) {
2809 tstatus = &OutStats->AFSBulkStats_val[i];
2810 tstatus->errorCode = errorCode;
2811 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2813 parentwhentargetnotdir = (Vnode *) 0;
2814 targetptr = (Vnode *) 0;
2815 volptr = (Volume *) 0;
2816 client = (struct client *)0;
2820 /* set volume synchronization information, but only once per call */
2822 SetVolumeSync(Sync, volptr);
2826 /* Are we allowed to fetch Fid's status? */
2827 if (targetptr->disk.type != vDirectory) {
2829 Check_PermissionRights(targetptr, client, rights,
2830 CHK_FETCHSTATUS, 0))) {
2831 tstatus = &OutStats->AFSBulkStats_val[i];
2832 tstatus->errorCode = errorCode;
2833 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2834 (Vnode *) 0, volptr, &client);
2835 parentwhentargetnotdir = (Vnode *) 0;
2836 targetptr = (Vnode *) 0;
2837 volptr = (Volume *) 0;
2838 client = (struct client *)0;
2843 /* set OutStatus From the Fid */
2844 GetStatus(targetptr,
2845 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2846 rights, anyrights, parentwhentargetnotdir);
2848 /* If a r/w volume, also set the CallBack state */
2849 if (VolumeWriteable(volptr))
2850 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2851 &CallBacks->AFSCBs_val[i]);
2853 struct AFSFid myFid;
2854 memset(&myFid, 0, sizeof(struct AFSFid));
2855 myFid.Volume = tfid->Volume;
2856 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2857 &CallBacks->AFSCBs_val[i]);
2860 /* put back the file ID and volume */
2861 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2863 parentwhentargetnotdir = (Vnode *) 0;
2864 targetptr = (Vnode *) 0;
2865 volptr = (Volume *) 0;
2866 client = (struct client *)0;
2869 Bad_InlineBulkStatus:
2870 /* Update and store volume/vnode and parent vnodes back */
2871 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2873 errorCode = CallPostamble(tcon, errorCode, thost);
2875 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2877 #if FS_STATS_DETAILED
2878 FT_GetTimeOfDay(&opStopTime, 0);
2879 if (errorCode == 0) {
2881 (opP->numSuccesses)++;
2882 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2883 fs_stats_AddTo((opP->sumTime), elapsedTime);
2884 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2885 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2886 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2888 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2889 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2893 #endif /* FS_STATS_DETAILED */
2896 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2897 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2898 AUD_ID, t_client ? t_client->ViceId : 0,
2899 AUD_FIDS, Fids, AUD_END);
2902 } /*SRXAFS_InlineBulkStatus */
2906 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2907 struct AFSFetchStatus * OutStatus,
2908 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2911 struct rx_connection *tcon;
2913 struct client *t_client = NULL; /* tmp ptr to client data */
2914 #if FS_STATS_DETAILED
2915 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2916 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2917 struct timeval elapsedTime; /* Transfer time */
2920 * Set our stats pointer, remember when the RPC operation started, and
2921 * tally the operation.
2923 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2927 FT_GetTimeOfDay(&opStartTime, 0);
2928 #endif /* FS_STATS_DETAILED */
2930 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2931 goto Bad_FetchStatus;
2933 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2936 code = CallPostamble(tcon, code, thost);
2938 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2940 #if FS_STATS_DETAILED
2941 FT_GetTimeOfDay(&opStopTime, 0);
2944 (opP->numSuccesses)++;
2945 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2946 fs_stats_AddTo((opP->sumTime), elapsedTime);
2947 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2948 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2949 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2951 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2952 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2956 #endif /* FS_STATS_DETAILED */
2958 osi_auditU(acall, FetchStatusEvent, code,
2959 AUD_ID, t_client ? t_client->ViceId : 0,
2960 AUD_FID, Fid, AUD_END);
2963 } /*SRXAFS_FetchStatus */
2967 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2968 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2969 afs_fsize_t Length, afs_fsize_t FileLength,
2970 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2972 Vnode *targetptr = 0; /* pointer to input fid */
2973 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2974 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2975 Error errorCode = 0; /* return code for caller */
2976 Error fileCode = 0; /* return code from vol package */
2977 Volume *volptr = 0; /* pointer to the volume header */
2978 struct client *client = 0; /* pointer to client structure */
2979 afs_int32 rights, anyrights; /* rights for this and any user */
2980 struct client *t_client = NULL; /* tmp ptr to client data */
2981 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2982 struct rx_connection *tcon;
2984 #if FS_STATS_DETAILED
2985 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2986 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2987 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2988 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2989 struct timeval elapsedTime; /* Transfer time */
2990 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2991 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2992 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2995 * Set our stats pointers, remember when the RPC operation started, and
2996 * tally the operation.
2998 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2999 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
3004 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3006 FT_GetTimeOfDay(&opStartTime, 0);
3007 #endif /* FS_STATS_DETAILED */
3010 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3012 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3015 /* Get ptr to client data for user Id for logging */
3016 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3017 logHostAddr.s_addr = rxr_HostOf(tcon);
3019 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3020 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3021 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3024 * Get associated volume/vnode for the stored file; caller's rights
3028 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3029 &parentwhentargetnotdir, &client, WRITE_LOCK,
3030 &rights, &anyrights))) {
3034 /* set volume synchronization information */
3035 SetVolumeSync(Sync, volptr);
3037 if ((targetptr->disk.type == vSymlink)) {
3038 /* Should we return a better error code here??? */
3043 /* Check if we're allowed to store the data */
3045 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3051 * Drop the read lock on the parent directory after saving the parent
3052 * vnode information we need to pass to GetStatus
3054 if (parentwhentargetnotdir != NULL) {
3055 tparentwhentargetnotdir = *parentwhentargetnotdir;
3056 VPutVnode(&fileCode, parentwhentargetnotdir);
3057 osi_Assert(!fileCode || (fileCode == VSALVAGE));
3058 parentwhentargetnotdir = NULL;
3060 #if FS_STATS_DETAILED
3062 * Remember when the data transfer started.
3064 FT_GetTimeOfDay(&xferStartTime, 0);
3065 #endif /* FS_STATS_DETAILED */
3067 /* Do the actual storing of the data */
3068 #if FS_STATS_DETAILED
3070 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3071 FileLength, (InStatus->Mask & AFS_FSYNC),
3072 &bytesToXfer, &bytesXferred);
3075 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3076 FileLength, (InStatus->Mask & AFS_FSYNC));
3077 if (errorCode && (!targetptr->changed_newTime))
3079 #endif /* FS_STATS_DETAILED */
3080 #if FS_STATS_DETAILED
3082 * At this point, the data transfer is done, for good or ill. Remember
3083 * when the transfer ended, bump the number of successes/failures, and
3084 * integrate the transfer size and elapsed time into the stats. If the
3085 * operation failed, we jump to the appropriate point.
3087 FT_GetTimeOfDay(&xferStopTime, 0);
3089 (xferP->numXfers)++;
3091 (xferP->numSuccesses)++;
3094 * Bump the xfer sum by the number of bytes actually sent, NOT the
3097 tot_bytesXferred += bytesXferred;
3098 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3099 tot_bytesXferred &= 0x3FF;
3100 if (bytesXferred < xferP->minBytes)
3101 xferP->minBytes = bytesXferred;
3102 if (bytesXferred > xferP->maxBytes)
3103 xferP->maxBytes = bytesXferred;
3106 * Tally the size of the object. Note: we tally the actual size,
3107 * NOT the number of bytes that made it out over the wire.
3109 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3110 (xferP->count[0])++;
3111 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3112 (xferP->count[1])++;
3113 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3114 (xferP->count[2])++;
3115 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3116 (xferP->count[3])++;
3117 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3118 (xferP->count[4])++;
3119 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3120 (xferP->count[5])++;
3121 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3122 (xferP->count[6])++;
3123 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3124 (xferP->count[7])++;
3126 (xferP->count[8])++;
3128 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3129 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3130 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3131 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3132 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3134 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3135 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3140 * Finally, go off to tell our caller the bad news in case the
3143 if (errorCode && (!targetptr->changed_newTime))
3145 #endif /* FS_STATS_DETAILED */
3147 /* Update the status of the target's vnode */
3148 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3149 targetptr, volptr, 0);
3151 /* Get the updated File's status back to the caller */
3152 GetStatus(targetptr, OutStatus, rights, anyrights,
3153 &tparentwhentargetnotdir);
3156 /* Update and store volume/vnode and parent vnodes back */
3157 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3159 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3161 errorCode = CallPostamble(tcon, errorCode, thost);
3163 #if FS_STATS_DETAILED
3164 FT_GetTimeOfDay(&opStopTime, 0);
3165 if (errorCode == 0) {
3167 (opP->numSuccesses)++;
3168 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3169 fs_stats_AddTo((opP->sumTime), elapsedTime);
3170 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3171 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3172 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3174 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3175 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3179 #endif /* FS_STATS_DETAILED */
3180 osi_auditU(acall, StoreDataEvent, errorCode,
3181 AUD_ID, t_client ? t_client->ViceId : 0,
3182 AUD_FID, Fid, AUD_END);
3184 } /*common_StoreData64 */
3187 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3188 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3189 afs_uint32 Length, afs_uint32 FileLength,
3190 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3192 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3193 (0x7fffffff - Pos) < Length)
3196 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3198 } /*SRXAFS_StoreData */
3201 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3202 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3203 afs_uint64 Length, afs_uint64 FileLength,
3204 struct AFSFetchStatus * OutStatus,
3205 struct AFSVolSync * Sync)
3209 afs_fsize_t tLength;
3210 afs_fsize_t tFileLength;
3212 tPos = (afs_fsize_t) Pos;
3213 tLength = (afs_fsize_t) Length;
3214 tFileLength = (afs_fsize_t) FileLength;
3217 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3223 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3224 struct AFSOpaque * AccessList,
3225 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3227 Vnode *targetptr = 0; /* pointer to input fid */
3228 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3229 Error errorCode = 0; /* return code for caller */
3230 struct AFSStoreStatus InStatus; /* Input status for fid */
3231 Volume *volptr = 0; /* pointer to the volume header */
3232 struct client *client = 0; /* pointer to client structure */
3233 afs_int32 rights, anyrights; /* rights for this and any user */
3234 struct rx_connection *tcon;
3236 struct client *t_client = NULL; /* tmp ptr to client data */
3237 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3238 #if FS_STATS_DETAILED
3239 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3240 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3241 struct timeval elapsedTime; /* Transfer time */
3244 * Set our stats pointer, remember when the RPC operation started, and
3245 * tally the operation.
3247 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3251 FT_GetTimeOfDay(&opStartTime, 0);
3252 #endif /* FS_STATS_DETAILED */
3253 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3256 /* Get ptr to client data for user Id for logging */
3257 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3258 logHostAddr.s_addr = rxr_HostOf(tcon);
3260 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3261 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3262 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3264 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3266 InStatus.Mask = 0; /* not storing any status */
3269 * Get associated volume/vnode for the target dir; caller's rights
3270 * are also returned.
3273 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3274 &parentwhentargetnotdir, &client, WRITE_LOCK,
3275 &rights, &anyrights))) {
3279 /* set volume synchronization information */
3280 SetVolumeSync(Sync, volptr);
3282 /* Check if we have permission to change the dir's ACL */
3284 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3289 /* Build and store the new Access List for the dir */
3290 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3294 targetptr->changed_newTime = 1; /* status change of directory */
3296 /* convert the write lock to a read lock before breaking callbacks */
3297 VVnodeWriteToRead(&errorCode, targetptr);
3298 osi_Assert(!errorCode || errorCode == VSALVAGE);
3300 /* break call backs on the directory */
3301 BreakCallBack(client->host, Fid, 0);
3303 /* Get the updated dir's status back to the caller */
3304 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3307 /* Update and store volume/vnode and parent vnodes back */
3308 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3310 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3311 errorCode = CallPostamble(tcon, errorCode, thost);
3313 #if FS_STATS_DETAILED
3314 FT_GetTimeOfDay(&opStopTime, 0);
3315 if (errorCode == 0) {
3317 (opP->numSuccesses)++;
3318 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3319 fs_stats_AddTo((opP->sumTime), elapsedTime);
3320 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3321 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3322 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3324 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3325 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3329 #endif /* FS_STATS_DETAILED */
3331 osi_auditU(acall, StoreACLEvent, errorCode,
3332 AUD_ID, t_client ? t_client->ViceId : 0,
3333 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3336 } /*SRXAFS_StoreACL */
3340 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3341 * should be merged when possible.
3344 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3345 struct AFSStoreStatus *InStatus,
3346 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3348 Vnode *targetptr = 0; /* pointer to input fid */
3349 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3350 Error errorCode = 0; /* return code for caller */
3351 Volume *volptr = 0; /* pointer to the volume header */
3352 struct client *client = 0; /* pointer to client structure */
3353 afs_int32 rights, anyrights; /* rights for this and any user */
3354 struct client *t_client = NULL; /* tmp ptr to client data */
3355 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3356 struct rx_connection *tcon = rx_ConnectionOf(acall);
3358 /* Get ptr to client data for user Id for logging */
3359 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3360 logHostAddr.s_addr = rxr_HostOf(tcon);
3362 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3363 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3364 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3366 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3369 * Get volume/vnode for the target file; caller's rights to it are
3373 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3374 &parentwhentargetnotdir, &client, WRITE_LOCK,
3375 &rights, &anyrights))) {
3376 goto Bad_StoreStatus;
3379 /* set volume synchronization information */
3380 SetVolumeSync(Sync, volptr);
3382 /* Check if the caller has proper permissions to store status to Fid */
3384 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3386 goto Bad_StoreStatus;
3389 * Check for a symbolic link; we can't chmod these (otherwise could
3390 * change a symlink to a mt pt or vice versa)
3392 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3394 goto Bad_StoreStatus;
3397 /* Update the status of the target's vnode */
3398 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3399 (parentwhentargetnotdir ? parentwhentargetnotdir
3400 : targetptr), volptr, 0);
3402 /* convert the write lock to a read lock before breaking callbacks */
3403 VVnodeWriteToRead(&errorCode, targetptr);
3404 osi_Assert(!errorCode || errorCode == VSALVAGE);
3406 /* Break call backs on Fid */
3407 BreakCallBack(client->host, Fid, 0);
3409 /* Return the updated status back to caller */
3410 GetStatus(targetptr, OutStatus, rights, anyrights,
3411 parentwhentargetnotdir);
3414 /* Update and store volume/vnode and parent vnodes back */
3415 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3417 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3420 } /*SAFSS_StoreStatus */
3424 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3425 struct AFSStoreStatus * InStatus,
3426 struct AFSFetchStatus * OutStatus,
3427 struct AFSVolSync * Sync)
3430 struct rx_connection *tcon;
3432 struct client *t_client = NULL; /* tmp ptr to client data */
3433 #if FS_STATS_DETAILED
3434 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3435 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3436 struct timeval elapsedTime; /* Transfer time */
3439 * Set our stats pointer, remember when the RPC operation started, and
3440 * tally the operation.
3442 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3446 FT_GetTimeOfDay(&opStartTime, 0);
3447 #endif /* FS_STATS_DETAILED */
3449 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3450 goto Bad_StoreStatus;
3452 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3455 code = CallPostamble(tcon, code, thost);
3457 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3459 #if FS_STATS_DETAILED
3460 FT_GetTimeOfDay(&opStopTime, 0);
3463 (opP->numSuccesses)++;
3464 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3465 fs_stats_AddTo((opP->sumTime), elapsedTime);
3466 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3467 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3468 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3470 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3471 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3475 #endif /* FS_STATS_DETAILED */
3477 osi_auditU(acall, StoreStatusEvent, code,
3478 AUD_ID, t_client ? t_client->ViceId : 0,
3479 AUD_FID, Fid, AUD_END);
3482 } /*SRXAFS_StoreStatus */
3486 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3487 * merged in when possible.
3490 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3491 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3493 Vnode *parentptr = 0; /* vnode of input Directory */
3494 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3495 Vnode *targetptr = 0; /* file to be deleted */
3496 Volume *volptr = 0; /* pointer to the volume header */
3497 AFSFid fileFid; /* area for Fid from the directory */
3498 Error errorCode = 0; /* error code */
3499 DirHandle dir; /* Handle for dir package I/O */
3500 struct client *client = 0; /* pointer to client structure */
3501 afs_int32 rights, anyrights; /* rights for this and any user */
3502 struct client *t_client; /* tmp ptr to client data */
3503 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3504 struct rx_connection *tcon = rx_ConnectionOf(acall);
3507 /* Get ptr to client data for user Id for logging */
3508 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3509 logHostAddr.s_addr = rxr_HostOf(tcon);
3511 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3512 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3513 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3515 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3518 * Get volume/vnode for the parent dir; caller's access rights are
3522 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3523 &parentwhentargetnotdir, &client, WRITE_LOCK,
3524 &rights, &anyrights))) {
3525 goto Bad_RemoveFile;
3527 /* set volume synchronization information */
3528 SetVolumeSync(Sync, volptr);
3530 /* Does the caller has delete (& write) access to the parent directory? */
3531 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3532 goto Bad_RemoveFile;
3535 /* Actually delete the desired file */
3537 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3539 goto Bad_RemoveFile;
3542 /* Update the vnode status of the parent dir */
3543 #if FS_STATS_DETAILED
3544 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3545 parentptr->disk.linkCount,
3546 client->InSameNetwork);
3548 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3549 parentptr->disk.linkCount);
3550 #endif /* FS_STATS_DETAILED */
3552 /* Return the updated parent dir's status back to caller */
3553 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3555 /* Handle internal callback state for the parent and the deleted file */
3556 if (targetptr->disk.linkCount == 0) {
3557 /* no references left, discard entry */
3558 DeleteFileCallBacks(&fileFid);
3559 /* convert the parent lock to a read lock before breaking callbacks */
3560 VVnodeWriteToRead(&errorCode, parentptr);
3561 osi_Assert(!errorCode || errorCode == VSALVAGE);
3563 /* convert the parent lock to a read lock before breaking callbacks */
3564 VVnodeWriteToRead(&errorCode, parentptr);
3565 osi_Assert(!errorCode || errorCode == VSALVAGE);
3566 /* convert the target lock to a read lock before breaking callbacks */
3567 VVnodeWriteToRead(&errorCode, targetptr);
3568 osi_Assert(!errorCode || errorCode == VSALVAGE);
3569 /* tell all the file has changed */
3570 BreakCallBack(client->host, &fileFid, 1);
3573 /* break call back on the directory */
3574 BreakCallBack(client->host, DirFid, 0);
3577 /* Update and store volume/vnode and parent vnodes back */
3578 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3581 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3584 } /*SAFSS_RemoveFile */
3588 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3589 struct AFSFetchStatus * OutDirStatus,
3590 struct AFSVolSync * Sync)
3593 struct rx_connection *tcon;
3595 struct client *t_client = NULL; /* tmp ptr to client data */
3596 #if FS_STATS_DETAILED
3597 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3598 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3599 struct timeval elapsedTime; /* Transfer time */
3602 * Set our stats pointer, remember when the RPC operation started, and
3603 * tally the operation.
3605 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3609 FT_GetTimeOfDay(&opStartTime, 0);
3610 #endif /* FS_STATS_DETAILED */
3612 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3613 goto Bad_RemoveFile;
3615 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3618 code = CallPostamble(tcon, code, thost);
3620 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3622 #if FS_STATS_DETAILED
3623 FT_GetTimeOfDay(&opStopTime, 0);
3626 (opP->numSuccesses)++;
3627 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3628 fs_stats_AddTo((opP->sumTime), elapsedTime);
3629 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3630 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3631 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3633 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3634 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3638 #endif /* FS_STATS_DETAILED */
3640 osi_auditU(acall, RemoveFileEvent, code,
3641 AUD_ID, t_client ? t_client->ViceId : 0,
3642 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3645 } /*SRXAFS_RemoveFile */
3649 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3650 * be merged in when possible.
3653 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3654 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3655 struct AFSFetchStatus *OutFidStatus,
3656 struct AFSFetchStatus *OutDirStatus,
3657 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3659 Vnode *parentptr = 0; /* vnode of input Directory */
3660 Vnode *targetptr = 0; /* vnode of the new file */
3661 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3662 Volume *volptr = 0; /* pointer to the volume header */
3663 Error errorCode = 0; /* error code */
3664 DirHandle dir; /* Handle for dir package I/O */
3665 struct client *client = 0; /* pointer to client structure */
3666 afs_int32 rights, anyrights; /* rights for this and any user */
3667 struct client *t_client; /* tmp ptr to client data */
3668 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3669 struct rx_connection *tcon = rx_ConnectionOf(acall);
3673 /* Get ptr to client data for user Id for logging */
3674 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3675 logHostAddr.s_addr = rxr_HostOf(tcon);
3677 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3678 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3679 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3681 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3683 if (!FileNameOK(Name)) {
3685 goto Bad_CreateFile;
3689 * Get associated volume/vnode for the parent dir; caller long are
3693 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3694 &parentwhentargetnotdir, &client, WRITE_LOCK,
3695 &rights, &anyrights))) {
3696 goto Bad_CreateFile;
3699 /* set volume synchronization information */
3700 SetVolumeSync(Sync, volptr);
3702 /* Can we write (and insert) onto the parent directory? */
3703 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3704 goto Bad_CreateFile;
3706 /* get a new vnode for the file to be created and set it up */
3708 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3709 vFile, nBlocks(0)))) {
3710 goto Bad_CreateFile;
3713 /* update the status of the parent vnode */
3714 #if FS_STATS_DETAILED
3715 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3716 parentptr->disk.linkCount,
3717 client->InSameNetwork);
3719 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3720 parentptr->disk.linkCount);
3721 #endif /* FS_STATS_DETAILED */
3723 /* update the status of the new file's vnode */
3724 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3725 parentptr, volptr, 0);
3727 /* 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 */
3728 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3729 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3731 /* convert the write lock to a read lock before breaking callbacks */
3732 VVnodeWriteToRead(&errorCode, parentptr);
3733 osi_Assert(!errorCode || errorCode == VSALVAGE);
3735 /* break call back on parent dir */
3736 BreakCallBack(client->host, DirFid, 0);
3738 /* Return a callback promise for the newly created file to the caller */
3739 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3742 /* Update and store volume/vnode and parent vnodes back */
3743 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3746 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3749 } /*SAFSS_CreateFile */
3753 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3754 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3755 struct AFSFetchStatus * OutFidStatus,
3756 struct AFSFetchStatus * OutDirStatus,
3757 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3760 struct rx_connection *tcon;
3762 struct client *t_client = NULL; /* tmp ptr to client data */
3763 #if FS_STATS_DETAILED
3764 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3765 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3766 struct timeval elapsedTime; /* Transfer time */
3769 * Set our stats pointer, remember when the RPC operation started, and
3770 * tally the operation.
3772 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3776 FT_GetTimeOfDay(&opStartTime, 0);
3777 #endif /* FS_STATS_DETAILED */
3779 memset(OutFid, 0, sizeof(struct AFSFid));
3781 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3782 goto Bad_CreateFile;
3785 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3786 OutDirStatus, CallBack, Sync);
3789 code = CallPostamble(tcon, code, thost);
3791 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3793 #if FS_STATS_DETAILED
3794 FT_GetTimeOfDay(&opStopTime, 0);
3797 (opP->numSuccesses)++;
3798 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3799 fs_stats_AddTo((opP->sumTime), elapsedTime);
3800 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3801 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3802 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3804 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3805 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3809 #endif /* FS_STATS_DETAILED */
3811 osi_auditU(acall, CreateFileEvent, code,
3812 AUD_ID, t_client ? t_client->ViceId : 0,
3813 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3816 } /*SRXAFS_CreateFile */
3820 * This routine is called exclusively from SRXAFS_Rename(), and should be
3821 * merged in when possible.
3824 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3825 struct AFSFid *NewDirFid, char *NewName,
3826 struct AFSFetchStatus *OutOldDirStatus,
3827 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3829 Vnode *oldvptr = 0; /* vnode of the old Directory */
3830 Vnode *newvptr = 0; /* vnode of the new Directory */
3831 Vnode *fileptr = 0; /* vnode of the file to move */
3832 Vnode *newfileptr = 0; /* vnode of the file to delete */
3833 Vnode *testvptr = 0; /* used in directory tree walk */
3834 Vnode *parent = 0; /* parent for use in SetAccessList */
3835 Error errorCode = 0; /* error code */
3836 Error fileCode = 0; /* used when writing Vnodes */
3837 VnodeId testnode; /* used in directory tree walk */
3838 AFSFid fileFid; /* Fid of file to move */
3839 AFSFid newFileFid; /* Fid of new file */
3840 DirHandle olddir; /* Handle for dir package I/O */
3841 DirHandle newdir; /* Handle for dir package I/O */
3842 DirHandle filedir; /* Handle for dir package I/O */
3843 DirHandle newfiledir; /* Handle for dir package I/O */
3844 Volume *volptr = 0; /* pointer to the volume header */
3845 struct client *client = 0; /* pointer to client structure */
3846 afs_int32 rights, anyrights; /* rights for this and any user */
3847 afs_int32 newrights; /* rights for this user */
3848 afs_int32 newanyrights; /* rights for any user */
3849 int doDelete; /* deleted the rename target (ref count now 0) */
3851 int updatefile = 0; /* are we changing the renamed file? (we do this
3852 * if we need to update .. on a renamed dir) */
3853 struct client *t_client; /* tmp ptr to client data */
3854 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3855 struct rx_connection *tcon = rx_ConnectionOf(acall);
3861 FidZero(&newfiledir);
3863 /* Get ptr to client data for user Id for logging */
3864 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3865 logHostAddr.s_addr = rxr_HostOf(tcon);
3867 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3868 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3869 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3870 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3872 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3874 if (!FileNameOK(NewName)) {
3878 if (OldDirFid->Volume != NewDirFid->Volume) {
3883 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3884 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3885 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3891 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3893 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3894 &parent, &client, WRITE_LOCK, &rights,
3899 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3901 newrights = rights, newanyrights = anyrights;
3904 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3905 MustBeDIR, &parent, &client, WRITE_LOCK,
3906 &newrights, &newanyrights))) {
3912 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3913 &parent, &client, WRITE_LOCK, &newrights,
3919 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3920 &parent, &client, WRITE_LOCK, &rights,
3927 /* set volume synchronization information */
3928 SetVolumeSync(Sync, volptr);
3930 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3933 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3937 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3938 * call to CopyOnWrite returns error, it is not necessary to revert back
3939 * the effects of the first call because the contents of the volume is
3940 * not modified, it is only replicated.
3942 if (oldvptr->disk.cloned) {
3943 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3944 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3947 SetDirHandle(&olddir, oldvptr);
3948 if (newvptr->disk.cloned) {
3949 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3950 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3954 SetDirHandle(&newdir, newvptr);
3956 /* Lookup the file to delete its vnode */
3957 if (Lookup(&olddir, OldName, &fileFid)) {
3961 if (fileFid.Vnode == oldvptr->vnodeNumber
3962 || fileFid.Vnode == newvptr->vnodeNumber) {
3963 errorCode = FSERR_ELOOP;
3966 fileFid.Volume = V_id(volptr);
3967 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3968 if (errorCode != 0) {
3970 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3971 OldName, errorCode));
3972 VTakeOffline(volptr);
3975 if (fileptr->disk.uniquifier != fileFid.Unique) {
3977 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3979 VTakeOffline(volptr);
3984 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3985 && fileptr->disk.linkCount != 1) {
3987 * Hard links exist to this file - cannot move one of the links to
3988 * a new directory because of AFS restrictions (this is the same
3989 * reason that links cannot be made across directories, i.e.
3996 /* Lookup the new file */
3997 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3998 if (readonlyServer) {
3999 errorCode = VREADONLY;
4002 if (!(newrights & PRSFS_DELETE)) {
4006 if (newFileFid.Vnode == oldvptr->vnodeNumber
4007 || newFileFid.Vnode == newvptr->vnodeNumber
4008 || newFileFid.Vnode == fileFid.Vnode) {
4012 newFileFid.Volume = V_id(volptr);
4014 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4015 if (errorCode != 0) {
4017 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4018 NewName, errorCode));
4019 VTakeOffline(volptr);
4022 if (fileptr->disk.uniquifier != fileFid.Unique) {
4024 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4026 VTakeOffline(volptr);
4030 SetDirHandle(&newfiledir, newfileptr);
4031 /* Now check that we're moving directories over directories properly, etc.
4032 * return proper POSIX error codes:
4033 * if fileptr is a file and new is a dir: EISDIR.
4034 * if fileptr is a dir and new is a file: ENOTDIR.
4035 * Also, dir to be removed must be empty, of course.
4037 if (newfileptr->disk.type == vDirectory) {
4038 if (fileptr->disk.type != vDirectory) {
4042 if ((IsEmpty(&newfiledir))) {
4047 if (fileptr->disk.type == vDirectory) {
4048 errorCode = ENOTDIR;