#include "afs/afs_osidnlc.h"
#include "afs/unified_afs.h"
-#ifndef OFFSET_MAX
-#define OFFSET_MAX 0x7fffffffffffffff
-#endif
+
+
+
/* Static prototypes */
static int HandleGetLock(register struct vcache *avc,
94.04.13 add "force" parameter. If a child explicitly unlocks a
file, I guess we'll permit it. however, we don't want simple,
innocent closes by children to unlock files in the parent process.
+
+ If called when disconnected support is unabled, the discon_lock must
+ be held
*/
/* 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 afs_conn *tc;
struct SimpleLocks *slp, *tlp, **slpp;
afs_int32 code;
struct AFSVolSync tsync;
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);
- RX_AFS_GUNLOCK();
- code = RXAFS_ReleaseLock(tc->id, (struct AFSFid *)
- &avc->fid.Fid, &tsync);
- RX_AFS_GLOCK();
- XSTATS_END_TIME;
- } else
+ if (!AFS_IS_DISCONNECTED) {
+ do {
+ tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
+ if (tc) {
+ XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK);
+ RX_AFS_GUNLOCK();
+ code = RXAFS_ReleaseLock(tc->id, (struct AFSFid *)
+ &avc->f.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, NULL));
+ } while (afs_Analyze
+ (tc, code, &avc->f.fid, areq,
+ AFS_STATS_FS_RPCIDX_RELEASELOCK, SHARED_LOCK, NULL));
+ } else {
+ /*printf("Network is dooooooowwwwwwwnnnnnnn\n");*/
+ code = ENETDOWN;
+ }
}
} else {
while (1) { /* set a new lock */
}
}
if (!code && avc->flockCount == 0) {
- do {
- tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
- if (tc) {
- 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,
- NULL));
+ if (!AFS_IS_DISCONNECTED) {
+ do {
+ tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
+ if (tc) {
+ XSTATS_START_TIME
+ (AFS_STATS_FS_RPCIDX_RELEASELOCK);
+ RX_AFS_GUNLOCK();
+ code =
+ RXAFS_ReleaseLock(tc->id,
+ (struct AFSFid *)&avc->
+ f.fid.Fid, &tsync);
+ RX_AFS_GLOCK();
+ XSTATS_END_TIME;
+ } else
+ code = -1;
+ } while (afs_Analyze
+ (tc, code, &avc->f.fid, areq,
+ AFS_STATS_FS_RPCIDX_RELEASELOCK, SHARED_LOCK,
+ NULL));
+ }
}
} else if (avc->flockCount == -1 && (acom & LOCK_EX)) {
if (lockIdcmp2(&flock, avc, NULL, 1, clid)) {
if (avc->flockCount == 0) {
/* we're the first on our block, send the call through */
lockType = ((acom & LOCK_EX) ? LockWrite : LockRead);
- do {
- tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
- if (tc) {
- XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETLOCK);
- RX_AFS_GUNLOCK();
- code = RXAFS_SetLock(tc->id, (struct AFSFid *)
- &avc->fid.Fid, lockType,
- &tsync);
- RX_AFS_GLOCK();
- XSTATS_END_TIME;
- } else
- code = -1;
- } while (afs_Analyze
- (tc, code, &avc->fid, areq,
- AFS_STATS_FS_RPCIDX_SETLOCK, SHARED_LOCK,
- NULL));
+ if (!AFS_IS_DISCONNECTED) {
+ do {
+ tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
+ if (tc) {
+ XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETLOCK);
+ RX_AFS_GUNLOCK();
+ code = RXAFS_SetLock(tc->id, (struct AFSFid *)
+ &avc->f.fid.Fid, lockType,
+ &tsync);
+ RX_AFS_GLOCK();
+ XSTATS_END_TIME;
+ } else
+ code = -1;
+ } while (afs_Analyze
+ (tc, code, &avc->f.fid, areq,
+ AFS_STATS_FS_RPCIDX_SETLOCK, SHARED_LOCK,
+ NULL));
+ } else
+ /* XXX - Should probably try and log this when we're
+ * XXX - running with logging enabled. But it's horrid
+ */
+ code = 0; /* pretend we worked - ick!!! */
} else
code = 0; /* otherwise, pretend things worked */
}
if ((code = afs_InitReq(&treq, acred)))
return code;
afs_InitFakeStat(&fakestate);
+
+ AFS_DISCON_LOCK();
+
code = afs_EvalFakeStat(&avc, &fakestate, &treq);
if (code) {
- afs_PutFakeStat(&fakestate);
- return code;
+ goto done;
}
#ifdef AFS_OSF_ENV
if (flag & VNOFLCK) {
- afs_PutFakeStat(&fakestate);
- return 0;
+ code = 0;
+ goto done;
}
if (flag & CLNFLCK) {
acmd = LOCK_UN;
if (acmd == F_GETLK) {
#endif
if (af->l_type == F_UNLCK) {
- afs_PutFakeStat(&fakestate);
- return 0;
+ code = 0;
+ goto done;
}
#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;
+ goto done;
} else if ((acmd == F_SETLK) || (acmd == F_SETLKW)
#if (defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)) && !defined(AFS_SUN58_ENV)
|| (acmd == F_RSETLK) || (acmd == F_RSETLKW)) {
#endif
/* Java VMs ask for l_len=(long)-1 regardless of OS/CPU; bottom 32 bits
* sometimes get masked off by OS */
- if (af->l_len == OFFSET_MAX-1)
+ if ((sizeof(af->l_len) == 8) && (af->l_len == 0x7ffffffffffffffeLL))
af->l_len = 0;
/* 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;
+ code = 0;
+ goto done;
}
/* otherwise we can turn this into a whole-file flock */
if (af->l_type == F_RDLCK)
code = HandleFlock(avc, code, &treq, 0, 0 /*!onlymine */ );
#endif
code = afs_CheckCode(code, &treq, 3); /* defeat AIX -O bug */
- afs_PutFakeStat(&fakestate);
- return code;
+ goto done;
}
+ code = EINVAL;
+done:
afs_PutFakeStat(&fakestate);
- return EINVAL;
+ AFS_DISCON_UNLOCK();
+ return code;
}
static int
GetFlockCount(struct vcache *avc, struct vrequest *areq)
{
- register struct conn *tc;
+ register struct afs_conn *tc;
register afs_int32 code;
struct AFSFetchStatus OutStatus;
struct AFSCallBack CallBack;
temp = areq->flags & O_NONBLOCK;
areq->flags |= O_NONBLOCK;
+ /* If we're disconnected, lie and say that we've got no locks. Ick */
+ if (AFS_IS_DISCONNECTED)
+ return 0;
+
do {
- tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
+ tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
if (tc) {
XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
RX_AFS_GUNLOCK();
code =
- RXAFS_FetchStatus(tc->id, (struct AFSFid *)&avc->fid.Fid,
+ RXAFS_FetchStatus(tc->id, (struct AFSFid *)&avc->f.fid.Fid,
&OutStatus, &CallBack, &tsync);
RX_AFS_GLOCK();
XSTATS_END_TIME;
} else
code = -1;
} while (afs_Analyze
- (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
+ (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
SHARED_LOCK, NULL));
if (temp)
afs_PutFakeStat(&fakestate);
return flockDone;
}
+
+ AFS_DISCON_LOCK();
+
/* 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 */
/* This is an AFS vnode, so do the work */
code = afs_EvalFakeStat(&tvc, &fakestate, &treq);
if (code) {
+ AFS_DISCON_UNLOCK();
afs_PutFakeStat(&fakestate);
return code;
}
#else
FP_UNREF(fd);
#endif
+ AFS_DISCON_UNLOCK();
afs_PutFakeStat(&fakestate);
return code;
#else /* AFS_OSF_ENV */
#else
flock();
#endif
+ AFS_DISCON_UNLOCK();
afs_PutFakeStat(&fakestate);
return;
#endif