Author: jra
Date: 2006-07-31 20:58:02 +0000 (Mon, 31 Jul 2006)
New Revision: 17346

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17346

Log:
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.

Modified:
   branches/SAMBA_3_0/source/include/locking.h
   branches/SAMBA_3_0/source/locking/brlock.c
   branches/SAMBA_3_0/source/locking/locking.c
   branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c


Changeset:
Modified: branches/SAMBA_3_0/source/include/locking.h
===================================================================
--- branches/SAMBA_3_0/source/include/locking.h 2006-07-31 20:51:55 UTC (rev 
17345)
+++ branches/SAMBA_3_0/source/include/locking.h 2006-07-31 20:58:02 UTC (rev 
17346)
@@ -55,6 +55,7 @@
        struct files_struct *fsp;
        unsigned int num_locks;
        BOOL modified;
+       BOOL read_only;
        struct lock_key key;
        void *lock_data;
 };

Modified: branches/SAMBA_3_0/source/locking/brlock.c
===================================================================
--- branches/SAMBA_3_0/source/locking/brlock.c  2006-07-31 20:51:55 UTC (rev 
17345)
+++ branches/SAMBA_3_0/source/locking/brlock.c  2006-07-31 20:58:02 UTC (rev 
17346)
@@ -1500,6 +1500,10 @@
        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 @@
 
  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 @@
  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,12 +1559,23 @@
        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);
 
        data = tdb_fetch(tdb, key);
@@ -1594,7 +1611,7 @@
        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 @@
        }
        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);
+}

Modified: branches/SAMBA_3_0/source/locking/locking.c
===================================================================
--- branches/SAMBA_3_0/source/locking/locking.c 2006-07-31 20:51:55 UTC (rev 
17345)
+++ branches/SAMBA_3_0/source/locking/locking.c 2006-07-31 20:58:02 UTC (rev 
17346)
@@ -102,7 +102,7 @@
                        DEBUG(10,("is_locked: optimisation - level II oplock on 
file %s\n", fsp->fsp_name ));
                        ret = False;
                } else {
-                       struct byte_range_lock *br_lck = brl_get_locks(NULL, 
fsp);
+                       struct byte_range_lock *br_lck = 
brl_get_locks_readonly(NULL, fsp);
                        if (!br_lck) {
                                return False;
                        }
@@ -116,7 +116,7 @@
                        TALLOC_FREE(br_lck);
                }
        } else {
-               struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+               struct byte_range_lock *br_lck = brl_get_locks_readonly(NULL, 
fsp);
                if (!br_lck) {
                        return False;
                }
@@ -160,7 +160,7 @@
                return NT_STATUS_OK;
        }
 
-       br_lck = brl_get_locks(NULL, fsp);
+       br_lck = brl_get_locks_readonly(NULL, fsp);
        if (!br_lck) {
                return NT_STATUS_NO_MEMORY;
        }

Modified: branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c
===================================================================
--- branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c        2006-07-31 
20:51:55 UTC (rev 17345)
+++ branches/SAMBA_3_0/source/rpc_server/srv_srvsvc_nt.c        2006-07-31 
20:58:02 UTC (rev 17346)
@@ -152,7 +152,7 @@
                fsp.dev   = e->dev;
                fsp.inode = e->inode;
                
-               if ( (brl = brl_get_locks(NULL,&fsp)) != NULL ) {
+               if ( (brl = brl_get_locks_readonly(NULL,&fsp)) != NULL ) {
                        num_locks = brl->num_locks;
                        TALLOC_FREE( brl );
                }

Reply via email to