diff options
author | Andrew Tridgell <tridge@samba.org> | 2000-01-14 04:32:57 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2000-01-14 04:32:57 +0000 |
commit | 82af221e4a7e456f580f16bc5d2fd904fc018c96 (patch) | |
tree | 1b0818867ea76a25e578345364186566c4f167c4 /source3/locking/brlock.c | |
parent | 7cd74b07ef283a4ce2e6f6c98cc7096189a74f20 (diff) | |
download | samba-82af221e4a7e456f580f16bc5d2fd904fc018c96.tar.gz samba-82af221e4a7e456f580f16bc5d2fd904fc018c96.tar.xz samba-82af221e4a7e456f580f16bc5d2fd904fc018c96.zip |
we now pass all byte range locking tests
the last piece was to use a smb timeout slightly larger than the
locking timeout in bloking locks to prevent a race
(This used to be commit 1b54cb4a33a65e62c2e3189b78ef073869a60c75)
Diffstat (limited to 'source3/locking/brlock.c')
-rw-r--r-- | source3/locking/brlock.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index 5d928daa580..653a40728bd 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -43,6 +43,7 @@ struct lock_struct { struct lock_context context; br_off start; br_off size; + int fnum; enum lock_type lock_type; }; @@ -102,7 +103,7 @@ void brl_init(void) /**************************************************************************** lock a range of bytes ****************************************************************************/ -BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, +BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, uint16 smbpid, pid_t pid, uint16 tid, br_off start, br_off size, enum lock_type lock_type) @@ -127,6 +128,7 @@ BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, lock.context.tid = tid; lock.start = start; lock.size = size; + lock.fnum = fnum; lock.lock_type = lock_type; if (dbuf.dptr) { @@ -161,7 +163,7 @@ BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, /**************************************************************************** unlock a range of bytes ****************************************************************************/ -BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, +BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, uint16 smbpid, pid_t pid, uint16 tid, br_off start, br_off size) { @@ -192,6 +194,7 @@ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, count = dbuf.dsize / sizeof(*locks); for (i=0; i<count; i++) { if (brl_same_context(&locks[i].context, &context) && + locks[i].fnum == fnum && locks[i].start == start && locks[i].size == size) { /* found it - delete it */ @@ -273,3 +276,55 @@ BOOL brl_locktest(SMB_DEV_T dev, SMB_INO_T ino, tdb_unlockchain(tdb, kbuf); return False; } + + +/**************************************************************************** +remove any locks associated with a open file +****************************************************************************/ +void brl_close(SMB_DEV_T dev, SMB_INO_T ino, pid_t pid, int tid, int fnum) +{ + struct lock_key key; + TDB_DATA kbuf, dbuf; + int count, i; + struct lock_struct *locks; + + key.device = dev; + key.inode = ino; + kbuf.dptr = (char *)&key; + kbuf.dsize = sizeof(key); + + dbuf.dptr = NULL; + + tdb_lockchain(tdb, kbuf); + dbuf = tdb_fetch(tdb, kbuf); + + if (!dbuf.dptr) goto fail; + + /* there are existing locks - remove any for this fnum */ + locks = (struct lock_struct *)dbuf.dptr; + count = dbuf.dsize / sizeof(*locks); + for (i=0; i<count; i++) { + if (locks[i].context.tid == tid && + locks[i].context.pid == pid && + locks[i].fnum == fnum) { + /* found it - delete it */ + if (count > 1 && i < count-1) { + memmove(&locks[i], &locks[i+1], + sizeof(*locks)*((count-1) - i)); + } + count--; + i--; + } + } + + if (count == 0) { + tdb_delete(tdb, kbuf); + } else if (count < (dbuf.dsize / sizeof(*locks))) { + tdb_store(tdb, kbuf, dbuf, TDB_REPLACE); + } + + /* we didn't find it */ + fail: + if (dbuf.dptr) free(dbuf.dptr); + tdb_unlockchain(tdb, kbuf); +} |