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
15 #include <afsconfig.h>
16 #include "afs/param.h"
21 #include "afs/sysincludes.h" /* Standard vendor system headers */
22 #include "afsincludes.h" /* Afs-based standard headers */
23 #include "afs/afs_stats.h" /* statistics */
24 #include "afs/afs_cbqueue.h"
25 #include "afs/nfsclient.h"
26 #include "afs/afs_osidnlc.h"
27 #include "afs/unified_afs.h"
29 /* Static prototypes */
30 static int HandleGetLock(register struct vcache *avc,
31 register struct AFS_FLOCK *af,
32 register struct vrequest *areq, int clid);
33 static int GetFlockCount(struct vcache *avc, struct vrequest *areq);
34 static int lockIdcmp2(struct AFS_FLOCK *flock1, struct vcache *vp,
35 register struct SimpleLocks *alp, int onlymine,
37 static void DoLockWarning(void);
39 /* int clid; * non-zero on SGI, OSF, SunOS, Darwin, xBSD ** XXX ptr type */
41 lockIdSet(struct AFS_FLOCK *flock, struct SimpleLocks *slp, int clid)
43 #if defined(AFS_SUN5_ENV)
44 register proc_t *procp = ttoproc(curthread);
46 #if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
48 struct proc *procp = OSI_GET_CURRENT_PROCP();
50 struct proc *procp = u.u_procp;
51 #endif /* AFS_SGI_ENV */
54 #if defined(AFS_SGI65_ENV)
56 get_current_flid(&flid);
65 slp->sysid = u.u_sysid;
69 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
72 slp->pid = procp->p_pid;
74 slp->sysid = procp->p_sysid;
75 slp->pid = procp->p_epid;
78 #if defined(AFS_SGI_ENV)
80 slp->sysid = flid.fl_sysid;
82 slp->sysid = OSI_GET_CURRENT_SYSID();
86 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
89 #if defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV)
92 slp->pid = u.u_procp->p_pid;
95 #endif /* AFS_AIX_ENV */
96 #endif /* AFS_AIX32_ENV */
99 #if defined(AFS_AIX32_ENV)
102 flock->l_pid = getpid();
104 flock->l_sysid = u.u_sysid;
105 flock->l_pid = u.u_epid;
108 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
111 flock->l_pid = procp->p_pid;
113 flock->l_sysid = procp->p_sysid;
114 flock->l_pid = procp->p_epid;
117 #if defined(AFS_SGI_ENV)
119 flock->l_sysid = flid.fl_sysid;
121 flock->l_sysid = OSI_GET_CURRENT_SYSID();
125 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
128 #if defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV)
129 flock->l_pid = getpid();
131 flock->l_pid = u.u_procp->p_pid;
135 #endif /* AFS_AIX_ENV */
136 #endif /* AFS_AIX32_ENV */
140 /* return 1 (true) if specified flock does not match alp (if
141 * specified), or any of the slp structs (if alp == 0)
143 /* I'm not sure that the comparsion of flock->pid to p_ppid
144 * is correct. Should that be a comparision of alp (or slp) ->pid
145 * to p_ppid? Especially in the context of the lower loop, where
146 * the repeated comparison doesn't make much sense...
148 /* onlymine - don't match any locks which are held by my parent */
149 /* clid - only irix 6.5 */
152 lockIdcmp2(struct AFS_FLOCK *flock1, struct vcache *vp,
153 register struct SimpleLocks *alp, int onlymine, int clid)
155 register struct SimpleLocks *slp;
156 #if defined(AFS_SUN5_ENV)
157 register proc_t *procp = ttoproc(curthread);
159 #if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
161 struct proc *procp = curprocp;
162 #else /* AFS_SGI64_ENV */
163 struct proc *procp = u.u_procp;
164 #endif /* AFS_SGI64_ENV */
169 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
170 if (flock1->l_sysid != alp->sysid) {
174 if ((flock1->l_pid == alp->pid) ||
175 #if defined(AFS_AIX41_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV)
176 (!onlymine && (flock1->l_pid == getppid()))
178 #if defined(AFS_SGI65_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
179 /* XXX check this. used to be *only* irix for some reason. */
180 (!onlymine && (flock1->l_pid == clid))
182 (!onlymine && (flock1->l_pid == procp->p_ppid))
191 for (slp = vp->slocks; slp; slp = slp->next) {
192 #if defined(AFS_HAVE_FLOCK_SYSID)
193 if (flock1->l_sysid != slp->sysid) {
197 if (flock1->l_pid == slp->pid) {
201 return (1); /* failure */
205 /* we don't send multiple read flocks to the server, but rather just count
206 them up ourselves. Of course, multiple write locks are incompatible.
208 Note that we should always try to release a lock, even if we have
209 a network problem sending the release command through, since often
210 a lock is released on a close call, when the user can't retry anyway.
212 After we remove it from our structure, the lock will no longer be
213 kept alive, and the server should time it out within a few minutes.
215 94.04.13 add "force" parameter. If a child explicitly unlocks a
216 file, I guess we'll permit it. however, we don't want simple,
217 innocent closes by children to unlock files in the parent process.
219 /* clid - nonzero on sgi sunos osf1 only */
221 HandleFlock(register struct vcache *avc, int acom, struct vrequest *areq,
222 pid_t clid, int onlymine)
225 struct SimpleLocks *slp, *tlp, **slpp;
227 struct AFSVolSync tsync;
229 struct AFS_FLOCK flock;
231 AFS_STATCNT(HandleFlock);
232 code = 0; /* default when we don't make any network calls */
233 lockIdSet(&flock, NULL, clid);
235 #if defined(AFS_SGI_ENV)
236 osi_Assert(valusema(&avc->vc_rwlock) <= 0);
237 osi_Assert(OSI_GET_LOCKID() == avc->vc_rwlockid);
239 ObtainWriteLock(&avc->lock, 118);
240 if (acom & LOCK_UN) {
245 /* If the lock is held exclusive, then only the owning process
246 * or a child can unlock it. Use pid and ppid because they are
247 * unique identifiers.
249 if ((avc->flockCount < 0) && (getpid() != avc->ownslock)) {
251 if (onlymine || (getppid() != avc->ownslock)) {
253 if (onlymine || (u.u_procp->p_ppid != avc->ownslock)) {
255 ReleaseWriteLock(&avc->lock);
260 if (lockIdcmp2(&flock, avc, NULL, onlymine, clid)) {
261 ReleaseWriteLock(&avc->lock);
267 if (avc->flockCount == 0) {
268 ReleaseWriteLock(&avc->lock);
272 /* unlock the lock */
273 if (avc->flockCount > 0) {
275 for (slp = *slpp; slp;) {
276 if (!lockIdcmp2(&flock, avc, slp, onlymine, clid)) {
278 tlp = *slpp = slp->next;
279 osi_FreeSmallSpace(slp);
286 } else if (avc->flockCount == -1) {
287 afs_StoreAllSegments(avc, areq, AFS_ASYNC); /* fsync file early */
289 /* And remove the (only) exclusive lock entry from the list... */
290 osi_FreeSmallSpace(avc->slocks);
293 if (avc->flockCount == 0) {
295 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
297 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK);
299 code = RXAFS_ReleaseLock(tc->id, (struct AFSFid *)
300 &avc->fid.Fid, &tsync);
306 (tc, code, &avc->fid, areq,
307 AFS_STATS_FS_RPCIDX_RELEASELOCK, SHARED_LOCK, NULL));
310 while (1) { /* set a new lock */
312 * Upgrading from shared locks to Exclusive and vice versa
313 * is a bit tricky and we don't really support it yet. But
314 * we try to support the common used one which is upgrade
315 * a shared lock to an exclusive for the same process...
317 if ((avc->flockCount > 0 && (acom & LOCK_EX))
318 || (avc->flockCount == -1 && (acom & LOCK_SH))) {
320 * Upgrading from shared locks to an exclusive one:
321 * For now if all the shared locks belong to the
322 * same process then we unlock them on the server
323 * and proceed with the upgrade. Unless we change the
324 * server's locking interface impl we prohibit from
325 * unlocking other processes's shared locks...
326 * Upgrading from an exclusive lock to a shared one:
327 * Again only allowed to be done by the same process.
330 for (slp = *slpp; slp;) {
332 (&flock, avc, slp, 1 /*!onlymine */ , clid)) {
337 tlp = *slpp = slp->next;
338 osi_FreeSmallSpace(slp);
346 if (!code && avc->flockCount == 0) {
348 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
351 (AFS_STATS_FS_RPCIDX_RELEASELOCK);
354 RXAFS_ReleaseLock(tc->id,
355 (struct AFSFid *)&avc->fid.
362 (tc, code, &avc->fid, areq,
363 AFS_STATS_FS_RPCIDX_RELEASELOCK, SHARED_LOCK,
366 } else if (avc->flockCount == -1 && (acom & LOCK_EX)) {
367 if (lockIdcmp2(&flock, avc, NULL, 1, clid)) {
373 /* compatible here, decide if needs to go to file server. If
374 * we've already got the file locked (and thus read-locked, since
375 * we've already checked for compatibility), we shouldn't send
376 * the call through to the server again */
377 if (avc->flockCount == 0) {
378 /* we're the first on our block, send the call through */
379 lockType = ((acom & LOCK_EX) ? LockWrite : LockRead);
381 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
383 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETLOCK);
385 code = RXAFS_SetLock(tc->id, (struct AFSFid *)
386 &avc->fid.Fid, lockType,
393 (tc, code, &avc->fid, areq,
394 AFS_STATS_FS_RPCIDX_SETLOCK, SHARED_LOCK,
397 code = 0; /* otherwise, pretend things worked */
400 slp = (struct SimpleLocks *)
401 osi_AllocSmallSpace(sizeof(struct SimpleLocks));
402 if (acom & LOCK_EX) {
407 /* Record unique id of process owning exclusive lock. */
408 avc->ownslock = getpid();
411 slp->type = LockWrite;
414 avc->flockCount = -1;
416 slp->type = LockRead;
417 slp->next = avc->slocks;
422 lockIdSet(&flock, slp, clid);
425 /* now, if we got EWOULDBLOCK, and we're supposed to wait, we do */
426 if (((code == EWOULDBLOCK) || (code == EAGAIN) ||
427 (code == UAEWOULDBLOCK) || (code == UAEAGAIN))
428 && !(acom & LOCK_NB)) {
429 /* sleep for a second, allowing interrupts */
430 ReleaseWriteLock(&avc->lock);
431 #if defined(AFS_SGI_ENV)
432 AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE);
434 code = afs_osi_Wait(1000, NULL, 1);
435 #if defined(AFS_SGI_ENV)
436 AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE);
438 ObtainWriteLock(&avc->lock, 120);
440 code = EINTR; /* return this if ^C typed */
447 ReleaseWriteLock(&avc->lock);
448 code = afs_CheckCode(code, areq, 1); /* defeat a buggy AIX optimization */
453 /* warn a user that a lock has been ignored */
454 afs_int32 lastWarnTime = 0; /* this is used elsewhere */
458 register afs_int32 now;
461 AFS_STATCNT(DoLockWarning);
462 /* check if we've already warned someone recently */
463 if (now < lastWarnTime + 120)
466 /* otherwise, it is time to nag the user */
469 ("afs: byte-range lock/unlock ignored; make sure no one else is running this program.\n");
474 int afs_lockctl(struct vcache * avc, struct eflock * af, int flag,
475 struct AFS_UCRED * acred, pid_t clid, off_t offset)
476 #elif defined(AFS_SGI_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
477 int afs_lockctl(struct vcache * avc, struct AFS_FLOCK * af, int acmd,
478 struct AFS_UCRED * acred, pid_t clid)
481 int afs_lockctl(struct vcache * avc, struct AFS_FLOCK * af, int acmd,
482 struct AFS_UCRED * acred)
485 struct vrequest treq;
490 struct afs_fakestat_state fakestate;
492 AFS_STATCNT(afs_lockctl);
493 if ((code = afs_InitReq(&treq, acred)))
495 afs_InitFakeStat(&fakestate);
496 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
498 afs_PutFakeStat(&fakestate);
502 if (flag & VNOFLCK) {
503 afs_PutFakeStat(&fakestate);
506 if (flag & CLNFLCK) {
508 } else if ((flag & GETFLCK) || (flag & RGETFLCK)) {
510 } else if ((flag & SETFLCK) || (flag & RSETFLCK)) {
514 #if (defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)) && !defined(AFS_SUN58_ENV)
515 if ((acmd == F_GETLK) || (acmd == F_RGETLK)) {
517 if (acmd == F_GETLK) {
519 if (af->l_type == F_UNLCK) {
520 afs_PutFakeStat(&fakestate);
523 #ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */
524 code = HandleGetLock(avc, af, &treq, clid);
526 code = afs_CheckCode(code, &treq, 2); /* defeat buggy AIX optimz */
527 afs_PutFakeStat(&fakestate);
529 } else if ((acmd == F_SETLK) || (acmd == F_SETLKW)
530 #if (defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)) && !defined(AFS_SUN58_ENV)
531 || (acmd == F_RSETLK) || (acmd == F_RSETLKW)) {
535 /* this next check is safer when left out, but more applications work
536 * with it in. However, they fail in race conditions. The question is
537 * what to do for people who don't have source to their application;
538 * this way at least, they can get work done */
539 #ifdef AFS_LINUX24_ENV
540 if (af->l_len == OFFSET_MAX)
541 af->l_len = 0; /* since some systems indicate it as EOF */
543 if (af->l_len == 0x7fffffff)
544 af->l_len = 0; /* since some systems indicate it as EOF */
545 #ifdef AFS_LINUX_64BIT_KERNEL
546 if (af->l_len == LONG_MAX)
547 af->l_len = 0; /* since some systems indicate it as EOF */
550 /* next line makes byte range locks always succeed,
551 * even when they should block */
552 if (af->l_whence != 0 || af->l_start != 0 || af->l_len != 0) {
554 afs_PutFakeStat(&fakestate);
557 /* otherwise we can turn this into a whole-file flock */
558 if (af->l_type == F_RDLCK)
560 else if (af->l_type == F_WRLCK)
562 else if (af->l_type == F_UNLCK)
565 afs_PutFakeStat(&fakestate);
566 return EINVAL; /* unknown lock type */
568 if (((acmd == F_SETLK)
569 #if (defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)) && !defined(AFS_SUN58_ENV)
570 || (acmd == F_RSETLK)
572 ) && code != LOCK_UN)
573 code |= LOCK_NB; /* non-blocking, s.v.p. */
574 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
575 code = HandleFlock(avc, code, &treq, clid, 0 /*!onlymine */ );
576 #elif defined(AFS_SGI_ENV)
577 AFS_RWLOCK((vnode_t *) avc, VRWLOCK_WRITE);
578 code = HandleFlock(avc, code, &treq, clid, 0 /*!onlymine */ );
579 AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE);
581 code = HandleFlock(avc, code, &treq, 0, 0 /*!onlymine */ );
583 code = afs_CheckCode(code, &treq, 3); /* defeat AIX -O bug */
584 afs_PutFakeStat(&fakestate);
587 afs_PutFakeStat(&fakestate);
593 * Get a description of the first lock which would
594 * block the lock specified. If the specified lock
595 * would succeed, fill in the lock structure with 'F_UNLCK'.
597 * To do that, we have to ask the server for the lock
599 * 1. The file is not locked by this machine.
600 * 2. Asking for write lock, and only the current
601 * PID has the file read locked.
603 #ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */
605 HandleGetLock(register struct vcache *avc, register struct AFS_FLOCK *af,
606 register struct vrequest *areq, int clid)
608 register afs_int32 code;
609 struct AFS_FLOCK flock;
611 lockIdSet(&flock, NULL, clid);
613 ObtainWriteLock(&avc->lock, 122);
614 if (avc->flockCount == 0) {
616 * We don't know ourselves, so ask the server. Unfortunately, we
617 * don't know the pid. Not even the server knows the pid. Besides,
618 * the process with the lock is on another machine
620 code = GetFlockCount(avc, areq);
621 if (code == 0 || (af->l_type == F_RDLCK && code > 0)) {
622 af->l_type = F_UNLCK;
626 af->l_type = F_RDLCK;
628 af->l_type = F_WRLCK;
631 #if defined(AFS_HAVE_FLOCK_SYSID)
637 if (af->l_type == F_RDLCK) {
639 * We want a read lock. If there are only
640 * read locks, or we are the one with the
641 * write lock, say it is unlocked.
643 if (avc->flockCount > 0 || /* only read locks */
644 !lockIdcmp2(&flock, avc, NULL, 1, clid)) {
645 af->l_type = F_UNLCK;
649 /* one write lock, but who? */
650 af->l_type = F_WRLCK; /* not us, so lock would block */
651 if (avc->slocks) { /* we know who, so tell */
652 af->l_pid = avc->slocks->pid;
653 #if defined(AFS_HAVE_FLOCK_SYSID)
654 af->l_sysid = avc->slocks->sysid;
657 af->l_pid = 0; /* XXX can't happen?? */
658 #if defined(AFS_HAVE_FLOCK_SYSID)
666 * Ok, we want a write lock. If there is a write lock
667 * already, and it is not this process, we fail.
669 if (avc->flockCount < 0) {
670 if (lockIdcmp2(&flock, avc, NULL, 1, clid)) {
671 af->l_type = F_WRLCK;
673 af->l_pid = avc->slocks->pid;
674 #if defined(AFS_HAVE_FLOCK_SYSID)
675 af->l_sysid = avc->slocks->sysid;
678 af->l_pid = 0; /* XXX can't happen?? */
679 #if defined(AFS_HAVE_FLOCK_SYSID)
685 /* we are the one with the write lock */
686 af->l_type = F_UNLCK;
691 * Want a write lock, and we know there are read locks.
692 * If there is more than one, or it isn't us, we cannot lock.
694 if ((avc->flockCount > 1)
695 || lockIdcmp2(&flock, avc, NULL, 1, clid)) {
696 struct SimpleLocks *slp;
698 af->l_type = F_RDLCK;
700 #if defined(AFS_HAVE_FLOCK_SYSID)
703 /* find a pid that isn't our own */
704 for (slp = avc->slocks; slp; slp = slp->next) {
705 if (lockIdcmp2(&flock, NULL, slp, 1, clid)) {
706 af->l_pid = slp->pid;
707 #if defined(AFS_HAVE_FLOCK_SYSID)
708 af->l_sysid = avc->slocks->sysid;
717 * Ok, we want a write lock. If there is a write lock
718 * already, and it is not this process, we fail.
720 if (avc->flockCount < 0) {
721 if (lockIdcmp2(&flock, avc, NULL, 1, clid)) {
722 af->l_type = F_WRLCK;
724 af->l_pid = avc->slocks->pid;
725 #if defined(AFS_HAVE_FLOCK_SYSID)
726 af->l_sysid = avc->slocks->sysid;
729 af->l_pid = 0; /* XXX can't happen?? */
730 #if defined(AFS_HAVE_FLOCK_SYSID)
736 /* we are the one with the write lock */
737 af->l_type = F_UNLCK;
742 * Want a write lock, and we know there are read locks.
743 * If there is more than one, or it isn't us, we cannot lock.
745 if ((avc->flockCount > 1)
746 || lockIdcmp2(&flock, avc, NULL, 1, clid)) {
747 struct SimpleLocks *slp;
748 af->l_type = F_RDLCK;
750 #if defined(AFS_HAVE_FLOCK_SYSID)
753 /* find a pid that isn't our own */
754 for (slp = avc->slocks; slp; slp = slp->next) {
755 if (lockIdcmp2(&flock, NULL, slp, 1, clid)) {
756 af->l_pid = slp->pid;
757 #if defined(AFS_HAVE_FLOCK_SYSID)
758 af->l_sysid = avc->slocks->sysid;
767 * Want a write lock, and there is just one read lock, and it
768 * is this process with a read lock. Ask the server if there
769 * are any more processes with the file locked.
771 code = GetFlockCount(avc, areq);
772 if (code == 0 || code == 1) {
773 af->l_type = F_UNLCK;
777 af->l_type = F_RDLCK;
779 af->l_type = F_WRLCK;
781 #if defined(AFS_HAVE_FLOCK_SYSID)
788 af->l_len = 0; /* to end of file */
791 ReleaseWriteLock(&avc->lock);
795 /* Get the 'flock' count from the server. This comes back in a 'spare'
796 * field from a GetStatus RPC. If we have any problems with the RPC,
797 * we lie and say the file is unlocked. If we ask any 'old' fileservers,
798 * the spare field will be a zero, saying the file is unlocked. This is
799 * OK, as a further 'lock' request will do the right thing.
802 GetFlockCount(struct vcache *avc, struct vrequest *areq)
804 register struct conn *tc;
805 register afs_int32 code;
806 struct AFSFetchStatus OutStatus;
807 struct AFSCallBack CallBack;
808 struct AFSVolSync tsync;
811 temp = areq->flags & O_NONBLOCK;
812 areq->flags |= O_NONBLOCK;
815 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
817 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
820 RXAFS_FetchStatus(tc->id, (struct AFSFid *)&avc->fid.Fid,
821 &OutStatus, &CallBack, &tsync);
827 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
831 areq->flags &= ~O_NONBLOCK;
834 return (0); /* failed, say it is 'unlocked' */
836 return ((int)OutStatus.lockCount);
842 #if !defined(AFS_AIX_ENV) && !defined(AFS_HPUX_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) && !defined(UKERNEL) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
843 /* Flock not support on System V systems */
845 extern struct fileops afs_fileops;
848 afs_xflock(struct proc *p, void *args, int *retval)
849 #else /* AFS_OSF_ENV */
860 struct vrequest treq;
863 struct afs_fakestat_state fakestate;
865 afs_InitFakeStat(&fakestate);
866 AFS_STATCNT(afs_xflock);
869 uap = (struct a *)args;
870 getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state);
871 #else /* AFS_OSF_ENV */
872 uap = (struct a *)u.u_ap;
876 afs_PutFakeStat(&fakestate);
880 if (flockDone = afs_InitReq(&treq, u.u_cred)) {
881 afs_PutFakeStat(&fakestate);
884 /* first determine whether this is any sort of vnode */
885 if (fd->f_type == DTYPE_VNODE) {
886 /* good, this is a vnode; next see if it is an AFS vnode */
887 tvc = VTOAFS(fd->f_data); /* valid, given a vnode */
888 if (IsAfsVnode(AFSTOV(tvc))) {
889 /* This is an AFS vnode, so do the work */
890 code = afs_EvalFakeStat(&tvc, &fakestate, &treq);
892 afs_PutFakeStat(&fakestate);
895 if ((fd->f_flag & (FEXLOCK | FSHLOCK)) && !(uap->com & LOCK_UN)) {
896 /* First, if fd already has lock, release it for relock path */
897 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV)
898 HandleFlock(tvc, LOCK_UN, &treq, u.u_procp->p_pid,
901 HandleFlock(tvc, LOCK_UN, &treq, 0, 0 /*!onlymine */ );
903 fd->f_flag &= ~(FEXLOCK | FSHLOCK);
905 /* now try the requested operation */
907 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV)
909 HandleFlock(tvc, uap->com, &treq, u.u_procp->p_pid,
912 code = HandleFlock(tvc, uap->com, &treq, 0, 0 /*!onlymine */ );
918 if (uap->com & LOCK_UN) {
920 fd->f_flag &= ~(FEXLOCK | FSHLOCK);
924 #else /* AFS_OSF_ENV */
927 if (uap->com & LOCK_SH)
928 fd->f_flag |= FSHLOCK;
929 else if (uap->com & LOCK_EX)
930 fd->f_flag |= FEXLOCK;
934 fd->f_ops = &afs_fileops;
939 code = flock(p, args, retval);
945 afs_PutFakeStat(&fakestate);
947 #else /* AFS_OSF_ENV */
950 (*afs_longcall_procs.LC_flock) ();
954 afs_PutFakeStat(&fakestate);
958 #endif /* !defined(AFS_AIX_ENV) && !defined(AFS_HPUX_ENV) && !defined(AFS_SUN5_ENV) && !defined(UKERNEL) && !defined(AFS_LINUX20_ENV) */