r21724: Optimization pointed out by Volker. If we don't
authorJeremy Allison <jra@samba.org>
Tue, 6 Mar 2007 21:59:51 +0000 (21:59 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:18:26 +0000 (12:18 -0500)
have any outstanding locks or blocking locks then
we don't need to read the lock db. on close.
Jeremy.
(This used to be commit 1b063496f93f78347a6e67549bde54c845499a7d)

source3/include/smb.h
source3/locking/locking.c

index 1e31d8545d4c602dff30988a1c09e1e6c94a2fba..a54cebac103f831c106f8ad2d38aaec46eda4d71 100644 (file)
@@ -501,6 +501,7 @@ typedef struct files_struct {
        int sent_oplock_break;
        struct timed_event *oplock_timeout;
        struct lock_struct last_lock_failure;
+       int current_lock_count; /* Count the number of outstanding locks and pending locks. */
 
        struct share_mode_entry *pending_break_messages;
        int num_pending_break_messages;
index 6c4e896a2a98fd9573c2f2c6a3170a42fcd3af51..304932cf3260dab5ecd81cc46d6b0d08ef0bf193 100644 (file)
@@ -222,6 +222,12 @@ struct byte_range_lock *do_lock(files_struct *fsp,
                        lock_flav,
                        blocking_lock);
 
+       /* blocking ie. pending, locks also count here,
+        * as this is an efficiency counter to avoid checking
+        * the lock db. on close. JRA. */
+
+       fsp->current_lock_count++;
+
        return br_lck;
 }
 
@@ -268,6 +274,9 @@ NTSTATUS do_unlock(files_struct *fsp,
                return NT_STATUS_RANGE_NOT_LOCKED;
        }
 
+       SMB_ASSERT(fsp->current_lock_count > 0);
+       fsp->current_lock_count--;
+
        return NT_STATUS_OK;
 }
 
@@ -315,6 +324,9 @@ NTSTATUS do_lock_cancel(files_struct *fsp,
                return NT_STATUS_DOS(ERRDOS, ERRcancelviolation);
        }
 
+       SMB_ASSERT(fsp->current_lock_count > 0);
+       fsp->current_lock_count++;
+
        return NT_STATUS_OK;
 }
 
@@ -330,6 +342,14 @@ void locking_close_file(files_struct *fsp)
                return;
        }
 
+       /* If we have not outstanding locks or pending
+        * locks then we don't need to look in the lock db.
+        */
+
+       if (fsp->current_lock_count == 0) {
+               return;
+       }
+
        br_lck = brl_get_locks(NULL,fsp);
 
        if (br_lck) {