summaryrefslogtreecommitdiffstats
path: root/source3/locking/brlock.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-07-31 20:58:02 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:38:27 -0500
commit49001a5b1b07e9a24e5f7efa0dfd880772bdb435 (patch)
treee53c1521682d856eb44791dd5be2eaeae98ae9fa /source3/locking/brlock.c
parentfd8bae8b1660acefd327121ef3d8a356cb0c09fa (diff)
downloadsamba-49001a5b1b07e9a24e5f7efa0dfd880772bdb435.tar.gz
samba-49001a5b1b07e9a24e5f7efa0dfd880772bdb435.tar.xz
samba-49001a5b1b07e9a24e5f7efa0dfd880772bdb435.zip
r17346: Add optimisation vl needs for the cluster code where
we don't get the chainlock when getting the byte range lock record read-only. Jeremy. (This used to be commit fcd798ca0c1b76adb2bcda4a99c40c7aacb0addb)
Diffstat (limited to 'source3/locking/brlock.c')
-rw-r--r--source3/locking/brlock.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 568c80f3eef..fd41f75e625 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -1500,6 +1500,10 @@ static int byte_range_lock_destructor(void *p)
key.dptr = (char *)&br_lck->key;
key.dsize = sizeof(struct lock_key);
+ if (br_lck->read_only) {
+ SMB_ASSERT(!br_lck->modified);
+ }
+
if (!br_lck->modified) {
goto done;
}
@@ -1521,7 +1525,9 @@ static int byte_range_lock_destructor(void *p)
done:
- tdb_chainunlock(tdb, key);
+ if (!br_lck->read_only) {
+ tdb_chainunlock(tdb, key);
+ }
SAFE_FREE(br_lck->lock_data);
return 0;
}
@@ -1532,8 +1538,8 @@ static int byte_range_lock_destructor(void *p)
TALLOC_FREE(brl) will release the lock in the destructor.
********************************************************************/
-struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
- files_struct *fsp)
+static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
+ files_struct *fsp, BOOL read_only)
{
TDB_DATA key;
TDB_DATA data;
@@ -1553,10 +1559,21 @@ struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
key.dptr = (char *)&br_lck->key;
key.dsize = sizeof(struct lock_key);
- if (tdb_chainlock(tdb, key) != 0) {
- DEBUG(3, ("Could not lock byte range lock entry\n"));
- TALLOC_FREE(br_lck);
- return NULL;
+ if (!fsp->lockdb_clean) {
+ /* We must be read/write to clean
+ the dead entries. */
+ read_only = False;
+ }
+
+ if (read_only) {
+ br_lck->read_only = True;
+ } else {
+ if (tdb_chainlock(tdb, key) != 0) {
+ DEBUG(3, ("Could not lock byte range lock entry\n"));
+ TALLOC_FREE(br_lck);
+ return NULL;
+ }
+ br_lck->read_only = False;
}
talloc_set_destructor(br_lck, byte_range_lock_destructor);
@@ -1594,7 +1611,7 @@ struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
if (DEBUGLEVEL >= 10) {
unsigned int i;
struct lock_struct *locks = (struct lock_struct *)br_lck->lock_data;
- DEBUG(10,("brl_get_locks: %u current locks on dev=%.0f, inode=%.0f\n",
+ DEBUG(10,("brl_get_locks_internal: %u current locks on dev=%.0f, inode=%.0f\n",
br_lck->num_locks,
(double)fsp->dev, (double)fsp->inode ));
for( i = 0; i < br_lck->num_locks; i++) {
@@ -1603,3 +1620,15 @@ struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
}
return br_lck;
}
+
+struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
+ files_struct *fsp)
+{
+ return brl_get_locks_internal(mem_ctx, fsp, False);
+}
+
+struct byte_range_lock *brl_get_locks_readonly(TALLOC_CTX *mem_ctx,
+ files_struct *fsp)
+{
+ return brl_get_locks_internal(mem_ctx, fsp, True);
+}