-/* Copyright (C) 1995, 1989, 1998 Transarc Corporation - All rights reserved */
/*
- * For copyright information, see IPL which you accepted in order to
- * download this software.
- *
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ *
+ * This software has been released under the terms of the IBM Public
+ * License. For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
*/
/*
- * afs_vnop_flock.c
- *
* Implements:
*
*/
-#include "../afs/param.h" /* Should be always first */
-#include "../afs/sysincludes.h" /* Standard vendor system headers */
-#include "../afs/afsincludes.h" /* Afs-based standard headers */
-#include "../afs/afs_stats.h" /* statistics */
-#include "../afs/afs_cbqueue.h"
-#include "../afs/nfsclient.h"
-#include "../afs/afs_osidnlc.h"
+#include <afsconfig.h>
+#include "afs/param.h"
-#if defined(AFS_HPUX102_ENV)
-#define AFS_FLOCK k_flock
-#else
-#if defined(AFS_SUN56_ENV)
-#define AFS_FLOCK flock64
-#else
-#define AFS_FLOCK flock
-#endif /* AFS_SUN65_ENV */
-#endif /* AFS_HPUX102_ENV */
+RCSID("$Header$");
+#include "afs/sysincludes.h" /* Standard vendor system headers */
+#include "afsincludes.h" /* Afs-based standard headers */
+#include "afs/afs_stats.h" /* statistics */
+#include "afs/afs_cbqueue.h"
+#include "afs/nfsclient.h"
+#include "afs/afs_osidnlc.h"
+
+/* Static prototypes */
+static int HandleGetLock(register struct vcache *avc,
+ register struct AFS_FLOCK *af, register struct vrequest *areq, int clid);
static int GetFlockCount(struct vcache *avc, struct vrequest *areq);
+static int lockIdcmp2(struct AFS_FLOCK *flock1, struct vcache *vp,
+ register struct SimpleLocks *alp, int onlymine, int clid);
+static void DoLockWarning(void);
-void lockIdSet(flock, slp, clid)
- int clid; /* non-zero on SGI, OSF, SunOS */
- struct SimpleLocks *slp;
- struct AFS_FLOCK *flock;
+/* int clid; * non-zero on SGI, OSF, SunOS, Darwin, xBSD ** XXX ptr type */
+void lockIdSet(struct AFS_FLOCK *flock, struct SimpleLocks *slp, int clid)
{
#if defined(AFS_SUN5_ENV)
register proc_t *procp = ttoproc(curthread);
#else
-#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV)
+#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
#ifdef AFS_SGI_ENV
struct proc *procp = OSI_GET_CURRENT_PROCP();
#else
#endif
slp->pid = clid;
#else
-#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV)
+#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
slp->pid = clid;
#else
#if defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV)
#endif
flock->l_pid = clid;
#else
-#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV)
+#if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
flock->l_pid = clid;
#else
#if defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV)
* to p_ppid? Especially in the context of the lower loop, where
* the repeated comparison doesn't make much sense...
*/
-static int lockIdcmp2(flock1, vp, alp, onlymine, clid)
- struct AFS_FLOCK *flock1;
- struct vcache *vp;
- register struct SimpleLocks *alp;
- int onlymine; /* don't match any locks which are held by my */
- /* parent */
- int clid; /* Only Irix 6.5 for now. */
+/* onlymine - don't match any locks which are held by my parent */
+/* clid - only irix 6.5 */
+
+static int lockIdcmp2(struct AFS_FLOCK *flock1, struct vcache *vp,
+ register struct SimpleLocks *alp, int onlymine, int clid)
{
register struct SimpleLocks *slp;
#if defined(AFS_SUN5_ENV)
register proc_t *procp = ttoproc(curthread);
#else
-#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV)
+#if !defined(AFS_AIX41_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_SGI65_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
#ifdef AFS_SGI64_ENV
struct proc *procp = curprocp;
#else /* AFS_SGI64_ENV */
#endif /* AFS_SGI64_ENV */
#endif
#endif
- int code = 0;
if (alp) {
#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
#if defined(AFS_AIX41_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_HPUX_ENV)
(!onlymine && (flock1->l_pid == getppid()))
#else
-#if defined(AFS_SGI65_ENV)
+#if defined(AFS_SGI65_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+ /* XXX check this. used to be *only* irix for some reason. */
(!onlymine && (flock1->l_pid == clid))
#else
(!onlymine && (flock1->l_pid == procp->p_ppid))
}
for (slp = vp->slocks; slp; slp = slp->next) {
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
if (flock1->l_sysid != slp->sysid) {
continue;
}
file, I guess we'll permit it. however, we don't want simple,
innocent closes by children to unlock files in the parent process.
*/
-HandleFlock(avc, acom, areq, clid, onlymine)
- pid_t clid; /* non-zero on SGI, SunOS, OSF1 only */
- register struct vcache *avc;
- struct vrequest *areq;
- int onlymine;
- int acom; {
+/* clid - nonzero on sgi sunos osf1 only */
+int HandleFlock(register struct vcache *avc, int acom,
+ struct vrequest *areq, pid_t clid, int onlymine)
+{
struct conn *tc;
struct SimpleLocks *slp, *tlp, **slpp;
afs_int32 code;
AFS_STATCNT(HandleFlock);
code = 0; /* default when we don't make any network calls */
- lockIdSet(&flock, (struct SimpleLocks *)0, clid);
+ lockIdSet(&flock, NULL, clid);
#if defined(AFS_SGI_ENV)
osi_Assert(valusema(&avc->vc_rwlock) <= 0);
*/
if ((avc->flockCount < 0) && (getpid() != avc->ownslock)) {
#ifdef AFS_AIX41_ENV
- if (onlymine || (getppid() != avc->ownslock)) {
+ if (onlymine || (getppid() != avc->ownslock)) {
#else
- if (onlymine || (u.u_procp->p_ppid != avc->ownslock)) {
+ if (onlymine || (u.u_procp->p_ppid != avc->ownslock)) {
#endif
- ReleaseWriteLock(&avc->lock);
- return 0;
- }
+ ReleaseWriteLock(&avc->lock);
+ return 0;
+ }
}
#endif
- if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, onlymine, clid)) {
- ReleaseWriteLock(&avc->lock);
- return 0;
+ if (lockIdcmp2(&flock, avc, NULL, onlymine, clid)) {
+ ReleaseWriteLock(&avc->lock);
+ return 0;
}
#ifdef AFS_AIX_ENV
avc->ownslock = 0;
#endif
if (avc->flockCount == 0) {
- ReleaseWriteLock(&avc->lock);
- return 0 /*ENOTTY*/;
- /* no lock held */
+ ReleaseWriteLock(&avc->lock);
+ return 0 /*ENOTTY*/;
+ /* no lock held */
}
/* unlock the lock */
if (avc->flockCount > 0) {
- slpp = &avc->slocks;
- for (slp = *slpp; slp;) {
- if (!lockIdcmp2(&flock, avc, slp, onlymine, clid)) {
- avc->flockCount--;
- tlp = *slpp = slp->next;
- osi_FreeSmallSpace(slp);
- slp = tlp;
- } else {
- slpp = &slp->next;
- slp = *slpp;
+ slpp = &avc->slocks;
+ for (slp = *slpp; slp;) {
+ if (!lockIdcmp2(&flock, avc, slp, onlymine, clid)) {
+ avc->flockCount--;
+ tlp = *slpp = slp->next;
+ osi_FreeSmallSpace(slp);
+ slp = tlp;
+ } else {
+ slpp = &slp->next;
+ slp = *slpp;
+ }
}
- }
}
else if (avc->flockCount == -1) {
- afs_StoreAllSegments(avc, areq, AFS_ASYNC); /* fsync file early */
- avc->flockCount = 0;
- /* And remove the (only) exclusive lock entry from the list... */
- osi_FreeSmallSpace(avc->slocks);
- avc->slocks = 0;
+ afs_StoreAllSegments(avc, areq, AFS_ASYNC); /* fsync file early */
+ avc->flockCount = 0;
+ /* And remove the (only) exclusive lock entry from the list... */
+ osi_FreeSmallSpace(avc->slocks);
+ avc->slocks = 0;
}
if (avc->flockCount == 0) {
do {
tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
if (tc) {
- XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK);
-#ifdef RX_ENABLE_LOCKS
- AFS_GUNLOCK();
-#endif /* RX_ENABLE_LOCKS */
- code = RXAFS_ReleaseLock(tc->id, (struct AFSFid *)
- &avc->fid.Fid, &tsync);
-#ifdef RX_ENABLE_LOCKS
- AFS_GLOCK();
-#endif /* RX_ENABLE_LOCKS */
- XSTATS_END_TIME;
+ XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK);
+ RX_AFS_GUNLOCK();
+ code = RXAFS_ReleaseLock(tc->id, (struct AFSFid *)
+ &avc->fid.Fid, &tsync);
+ RX_AFS_GLOCK();
+ XSTATS_END_TIME;
}
else code = -1;
} while
- (afs_Analyze(tc, code, &avc->fid, areq,
- AFS_STATS_FS_RPCIDX_RELEASELOCK,
- SHARED_LOCK, (struct cell *)0));
+ (afs_Analyze(tc, code, &avc->fid, areq,
+ AFS_STATS_FS_RPCIDX_RELEASELOCK,
+ SHARED_LOCK, NULL));
}
}
else {
tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
if (tc) {
XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK);
-#ifdef RX_ENABLE_LOCKS
- AFS_GUNLOCK();
-#endif /* RX_ENABLE_LOCKS */
+ RX_AFS_GUNLOCK();
code = RXAFS_ReleaseLock(tc->id,
(struct AFSFid *) &avc->fid.Fid,
&tsync);
-#ifdef RX_ENABLE_LOCKS
- AFS_GLOCK();
-#endif /* RX_ENABLE_LOCKS */
+ RX_AFS_GLOCK();
XSTATS_END_TIME;
}
else code = -1;
} while
(afs_Analyze(tc, code, &avc->fid, areq,
AFS_STATS_FS_RPCIDX_RELEASELOCK,
- SHARED_LOCK, (struct cell *)0));
+ SHARED_LOCK, NULL));
}
} else if (avc->flockCount == -1 && (acom & LOCK_EX)) {
- if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) {
+ if (lockIdcmp2(&flock, avc, NULL, 1, clid)) {
code = EWOULDBLOCK;
} else
code = 0;
tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
if (tc) {
XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETLOCK);
-#ifdef RX_ENABLE_LOCKS
- AFS_GUNLOCK();
-#endif /* RX_ENABLE_LOCKS */
+ RX_AFS_GUNLOCK();
code = RXAFS_SetLock(tc->id, (struct AFSFid *)
&avc->fid.Fid, lockType, &tsync);
-#ifdef RX_ENABLE_LOCKS
- AFS_GLOCK();
-#endif /* RX_ENABLE_LOCKS */
+ RX_AFS_GLOCK();
XSTATS_END_TIME;
}
else code = -1;
} while
(afs_Analyze(tc, code, &avc->fid, areq,
AFS_STATS_FS_RPCIDX_SETLOCK,
- SHARED_LOCK, (struct cell *)0));
+ SHARED_LOCK, NULL));
}
else code = 0; /* otherwise, pretend things worked */
}
#endif
slp->type = LockWrite;
- slp->next = (struct SimpleLocks *)0;
+ slp->next = NULL;
avc->slocks = slp;
avc->flockCount = -1;
} else {
/* warn a user that a lock has been ignored */
-afs_int32 lastWarnTime = 0;
-static void DoLockWarning() {
+afs_int32 lastWarnTime = 0; /* this is used elsewhere */
+static void DoLockWarning(void)
+{
register afs_int32 now;
now = osi_Time();
#ifdef AFS_OSF_ENV
-afs_lockctl(avc, af, flag, acred, clid, offset)
-struct eflock *af;
-int flag;
-pid_t clid;
-off_t offset;
+afs_lockctl(struct vcache *avc, struct eflock *af, int flag,
+ struct AFS_UCRED *acred, pid_t clid, off_t offset)
#else
-#if defined(AFS_SGI_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
-afs_lockctl(avc, af, acmd, acred, clid)
-pid_t clid;
+#if defined(AFS_SGI_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+afs_lockctl(struct vcache *avc, struct AFS_FLOCK *af, int acmd, struct AFS_UCRED *acred, pid_t clid)
#else
u_int clid=0;
-afs_lockctl(avc, af, acmd, acred)
+afs_lockctl(struct vcache *avc, struct AFS_FLOCK *af, int acmd, struct AFS_UCRED *acred)
#endif
-struct AFS_FLOCK *af;
-int acmd;
#endif
-struct vcache *avc;
-struct AFS_UCRED *acred; {
+{
struct vrequest treq;
afs_int32 code;
#ifdef AFS_OSF_ENV
int acmd = 0;
#endif
+ struct afs_fakestat_state fakestate;
AFS_STATCNT(afs_lockctl);
- if (code = afs_InitReq(&treq, acred)) return code;
+ if ((code = afs_InitReq(&treq, acred))) return code;
+ afs_InitFakeStat(&fakestate);
+ code = afs_EvalFakeStat(&avc, &fakestate, &treq);
+ if (code) {
+ afs_PutFakeStat(&fakestate);
+ return code;
+ }
#ifdef AFS_OSF_ENV
- if (flag & VNOFLCK) return 0;
+ if (flag & VNOFLCK) {
+ afs_PutFakeStat(&fakestate);
+ return 0;
+ }
if (flag & CLNFLCK) {
acmd = LOCK_UN;
} else if ((flag & GETFLCK) || (flag & RGETFLCK)) {
acmd = F_SETLK;
}
#endif
-#if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
+#if (defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)) && !defined(AFS_SUN58_ENV)
if ((acmd == F_GETLK) || (acmd == F_RGETLK)) {
#else
if (acmd == F_GETLK) {
#endif
- if (af->l_type == F_UNLCK)
+ if (af->l_type == F_UNLCK) {
+ afs_PutFakeStat(&fakestate);
return 0;
+ }
#ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */
code = HandleGetLock(avc, af, &treq, clid);
#endif
code = afs_CheckCode(code, &treq, 2); /* defeat buggy AIX optimz */
+ afs_PutFakeStat(&fakestate);
return code;
}
else if ((acmd == F_SETLK) || (acmd == F_SETLKW)
-#if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
+#if (defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)) && !defined(AFS_SUN58_ENV)
|| (acmd == F_RSETLK)|| (acmd == F_RSETLKW)) {
#else
) {
with it in. However, they fail in race conditions. The question is
what to do for people who don't have source to their application;
this way at least, they can get work done */
+#ifdef AFS_LINUX24_ENV
+ if (af->l_len == OFFSET_MAX)
+ af->l_len = 0; /* since some systems indicate it as EOF */
+#else
if (af->l_len == 0x7fffffff)
af->l_len = 0; /* since some systems indicate it as EOF */
+#ifdef AFS_LINUX_64BIT_KERNEL
+ if (af->l_len == LONG_MAX)
+ af->l_len = 0; /* since some systems indicate it as EOF */
+#endif
+#endif
/* next line makes byte range locks always succeed,
even when they should block */
if (af->l_whence != 0 || af->l_start != 0 || af->l_len != 0) {
DoLockWarning();
+ afs_PutFakeStat(&fakestate);
return 0;
}
/* otherwise we can turn this into a whole-file flock */
if (af->l_type == F_RDLCK) code = LOCK_SH;
else if (af->l_type == F_WRLCK) code = LOCK_EX;
else if (af->l_type == F_UNLCK) code = LOCK_UN;
- else return EINVAL; /* unknown lock type */
+ else {
+ afs_PutFakeStat(&fakestate);
+ return EINVAL; /* unknown lock type */
+ }
if (((acmd == F_SETLK)
-#if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV)
+#if (defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV)) && !defined(AFS_SUN58_ENV)
|| (acmd == F_RSETLK)
#endif
) && code != LOCK_UN)
#endif
#endif
code = afs_CheckCode(code, &treq, 3); /* defeat AIX -O bug */
+ afs_PutFakeStat(&fakestate);
return code;
}
+ afs_PutFakeStat(&fakestate);
return EINVAL;
}
* PID has the file read locked.
*/
#ifndef AFS_OSF_ENV /* getlock is a no-op for osf (for now) */
-HandleGetLock(avc, af, areq, clid)
- int clid; /* not used by some OSes */
- register struct vcache *avc;
- register struct vrequest *areq;
- register struct AFS_FLOCK *af;
+static int HandleGetLock(register struct vcache *avc,
+ register struct AFS_FLOCK *af, register struct vrequest *areq, int clid)
{
register afs_int32 code;
struct AFS_FLOCK flock;
- lockIdSet(&flock, (struct SimpleLocks *)0, clid);
+ lockIdSet(&flock, NULL, clid);
ObtainWriteLock(&avc->lock,122);
if (avc->flockCount == 0) {
af->l_type = F_WRLCK;
af->l_pid = 0;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = 0;
#endif
goto done;
* write lock, say it is unlocked.
*/
if (avc->flockCount > 0 || /* only read locks */
- !lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) {
+ !lockIdcmp2(&flock, avc, NULL, 1, clid)) {
af->l_type = F_UNLCK;
goto unlck_leave;
}
af->l_type = F_WRLCK; /* not us, so lock would block */
if (avc->slocks) { /* we know who, so tell */
af->l_pid = avc->slocks->pid;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = avc->slocks->sysid;
#endif
} else {
af->l_pid = 0; /* XXX can't happen?? */
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = 0;
#endif
}
* already, and it is not this process, we fail.
*/
if (avc->flockCount < 0) {
- if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) {
+ if (lockIdcmp2(&flock, avc, NULL, 1, clid)) {
af->l_type = F_WRLCK;
if (avc->slocks) {
af->l_pid = avc->slocks->pid;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = avc->slocks->sysid;
#endif
} else {
af->l_pid = 0; /* XXX can't happen?? */
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = 0;
#endif
}
* If there is more than one, or it isn't us, we cannot lock.
*/
if ((avc->flockCount > 1)
- || lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) {
+ || lockIdcmp2(&flock, avc, NULL, 1, clid)) {
struct SimpleLocks *slp;
af->l_type = F_RDLCK;
af->l_pid = 0;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = 0;
#endif
/* find a pid that isn't our own */
for (slp = avc->slocks; slp; slp = slp->next) {
- if (lockIdcmp2(&flock, (struct vcache *)0, slp, 1, clid)) {
+ if (lockIdcmp2(&flock, NULL, slp, 1, clid)) {
af->l_pid = slp->pid;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = avc->slocks->sysid;
#endif
break;
* already, and it is not this process, we fail.
*/
if (avc->flockCount < 0) {
- if (lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) {
+ if (lockIdcmp2(&flock, avc, NULL, 1, clid)) {
af->l_type = F_WRLCK;
if (avc->slocks) {
af->l_pid = avc->slocks->pid;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = avc->slocks->sysid;
#endif
} else {
af->l_pid = 0; /* XXX can't happen?? */
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = 0;
#endif
}
* If there is more than one, or it isn't us, we cannot lock.
*/
if ((avc->flockCount > 1)
- || lockIdcmp2(&flock, avc, (struct SimpleLocks *)0, 1, clid)) {
+ || lockIdcmp2(&flock, avc, NULL, 1, clid)) {
struct SimpleLocks *slp;
af->l_type = F_RDLCK;
af->l_pid = 0;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = 0;
#endif
/* find a pid that isn't our own */
for (slp = avc->slocks; slp; slp = slp->next) {
- if (lockIdcmp2(&flock, (struct vcache *)0, slp, 1, clid)) {
+ if (lockIdcmp2(&flock, NULL, slp, 1, clid)) {
af->l_pid = slp->pid;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = avc->slocks->sysid;
#endif
break;
else
af->l_type = F_WRLCK;
af->l_pid = 0;
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
+#if defined(AFS_HAVE_FLOCK_SYSID)
af->l_sysid = 0;
#endif
tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
if (tc){
XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
-#ifdef RX_ENABLE_LOCKS
- AFS_GUNLOCK();
-#endif /* RX_ENABLE_LOCKS */
+ RX_AFS_GUNLOCK();
code = RXAFS_FetchStatus(tc->id, (struct AFSFid *) &avc->fid.Fid,
&OutStatus, &CallBack, &tsync);
-#ifdef RX_ENABLE_LOCKS
- AFS_GLOCK();
-#endif /* RX_ENABLE_LOCKS */
+ RX_AFS_GLOCK();
XSTATS_END_TIME;
} else code = -1;
} while
(afs_Analyze(tc, code, &avc->fid, areq,
AFS_STATS_FS_RPCIDX_FETCHSTATUS,
- SHARED_LOCK, (struct cell *)0));
+ SHARED_LOCK, NULL));
if (temp)
areq->flags &= ~O_NONBLOCK;
if (code) {
return(0); /* failed, say it is 'unlocked' */
} else {
- return((int)OutStatus.spare2);
+ return((int)OutStatus.lockCount);
}
}
#endif
-#if !defined(AFS_AIX_ENV) && !defined(AFS_HPUX_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_SGI_ENV) && !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
+#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)
/* Flock not support on System V systems */
#ifdef AFS_OSF_ENV
extern struct fileops afs_fileops;
-afs_xflock (p, args, retval)
- struct proc *p;
- void *args;
- int *retval;
-{
+
+int afs_xflock (struct proc *p, void *args, int *retval)
#else /* AFS_OSF_ENV */
-afs_xflock () {
+int afs_xflock (void)
#endif
+{
int code = 0;
struct a {
int fd;
struct vrequest treq;
struct vcache *tvc;
int flockDone;
+ struct afs_fakestat_state fakestate;
+ afs_InitFakeStat(&fakestate);
AFS_STATCNT(afs_xflock);
flockDone = 0;
#ifdef AFS_OSF_ENV
uap = (struct a *)u.u_ap;
fd = getf(uap->fd);
#endif
- if (!fd) return;
+ if (!fd) {
+ afs_PutFakeStat(&fakestate);
+ return;
+ }
- if (flockDone = afs_InitReq(&treq, u.u_cred)) return flockDone;
+ if (flockDone = afs_InitReq(&treq, u.u_cred)) {
+ afs_PutFakeStat(&fakestate);
+ return flockDone;
+ }
/* first determine whether this is any sort of vnode */
if (fd->f_type == DTYPE_VNODE) {
/* good, this is a vnode; next see if it is an AFS vnode */
- tvc = (struct vcache *) fd->f_data; /* valid, given a vnode */
- if (IsAfsVnode((struct vnode *)tvc)) {
+ tvc = VTOAFS(fd->f_data); /* valid, given a vnode */
+ if (IsAfsVnode(AFSTOV(tvc))) {
/* This is an AFS vnode, so do the work */
#ifdef AFS_DEC_ENV
/* find real vcache entry; shouldn't be null if gnode ref count
* is greater than 0.
*/
- tvc = (struct vcache *) afs_gntovn(tvc);
+ tvc = VTOAFS(afs_gntovn)(tvc);
if (!tvc) {
u.u_error = ENOENT;
+ afs_PutFakeStat(&fakestate);
return;
}
#endif
+ code = afs_EvalFakeStat(&tvc, &fakestate, &treq);
+ if (code) {
+ afs_PutFakeStat(&fakestate);
+ return code;
+ }
if ((fd->f_flag & (FEXLOCK | FSHLOCK)) && !(uap->com & LOCK_UN)) {
/* First, if fd already has lock, release it for relock path */
#if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV))
#else
FP_UNREF(fd);
#endif
+ afs_PutFakeStat(&fakestate);
return code;
#else /* AFS_OSF_ENV */
if (!flockDone)
#else
flock();
#endif
+ afs_PutFakeStat(&fakestate);
return;
#endif
}