svn commit: samba r16885 - in trunk/source: include locking

jra at samba.org jra at samba.org
Sun Jul 9 00:52:22 GMT 2006


Author: jra
Date: 2006-07-09 00:52:21 +0000 (Sun, 09 Jul 2006)
New Revision: 16885

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

Log:
Move locking definitions into their own header file locking.h
Pass down the upper level locking data to the system layer,
will avoid having to re-walk the lock list (which the upper
layer has already done).
Jeremy.

Added:
   trunk/source/include/locking.h
Modified:
   trunk/source/include/smb.h
   trunk/source/locking/brlock.c
   trunk/source/locking/posix.c


Changeset:
Added: trunk/source/include/locking.h
===================================================================
--- trunk/source/include/locking.h	2006-07-08 20:49:00 UTC (rev 16884)
+++ trunk/source/include/locking.h	2006-07-09 00:52:21 UTC (rev 16885)
@@ -0,0 +1,88 @@
+/* 
+   Unix SMB/CIFS implementation.
+   SMB parameters and setup, plus a whole lot more.
+   
+   Copyright (C) Jeremy Allison   2006
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef _LOCKING_H
+#define _LOCKING_H
+
+/* passed to br lock code - the UNLOCK_LOCK should never be stored into the tdb
+   and is used in calculating POSIX unlock ranges only. */
+
+enum brl_type {READ_LOCK, WRITE_LOCK, PENDING_LOCK, UNLOCK_LOCK};
+enum brl_flavour {WINDOWS_LOCK = 0, POSIX_LOCK = 1};
+
+/* This contains elements that differentiate locks. The smbpid is a
+   client supplied pid, and is essentially the locking context for
+   this client */
+
+struct lock_context {
+        uint16 smbpid;
+        uint16 tid;
+        struct process_id pid;
+};
+
+/* The key used in the brlock database. */
+
+struct lock_key {
+	SMB_DEV_T device;
+	SMB_INO_T inode;
+};
+
+struct byte_range_lock {
+	files_struct *fsp;
+	unsigned int num_locks;
+	BOOL modified;
+	struct lock_key key;
+	void *lock_data;
+};
+
+#define BRLOCK_FN_CAST() \
+	void (*)(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, \
+				 enum brl_type lock_type, \
+				 enum brl_flavour lock_flav, \
+				 br_off start, br_off size)
+
+#define BRLOCK_FN(fn) \
+	void (*fn)(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, \
+				 enum brl_type lock_type, \
+				 enum brl_flavour lock_flav, \
+				 br_off start, br_off size)
+
+#define LOCKING_FN_CAST() \
+	void (*)(struct share_mode_entry *, const char *, const char *)
+
+#define LOCKING_FN(fn) \
+	void (*fn)(struct share_mode_entry *, const char *, const char *)
+
+/* Internal structure in brlock.tdb. 
+   The data in brlock records is an unsorted linear array of these
+   records.  It is unnecessary to store the count as tdb provides the
+   size of the record */
+
+struct lock_struct {
+	struct lock_context context;
+	br_off start;
+	br_off size;
+	int fnum;
+	enum brl_type lock_type;
+	enum brl_flavour lock_flav;
+};
+
+#endif /* _LOCKING_H_ */

Modified: trunk/source/include/smb.h
===================================================================
--- trunk/source/include/smb.h	2006-07-08 20:49:00 UTC (rev 16884)
+++ trunk/source/include/smb.h	2006-07-09 00:52:21 UTC (rev 16885)
@@ -853,64 +853,13 @@
 #define FLAG_HIDE  	0x2000 /* options that should be hidden in SWAT */
 #define FLAG_DOS_STRING 0x4000 /* convert from UNIX to DOS codepage when reading this string. */
 
-/* passed to br lock code - the UNLOCK_LOCK should never be stored into the tdb
-   and is used in calculating POSIX unlock ranges only. */
+#include "locking.h"
 
-enum brl_type {READ_LOCK, WRITE_LOCK, PENDING_LOCK, UNLOCK_LOCK};
-enum brl_flavour {WINDOWS_LOCK = 0, POSIX_LOCK = 1};
-
-/* This contains elements that differentiate locks. The smbpid is a
-   client supplied pid, and is essentially the locking context for
-   this client */
-
-struct lock_context {
-        uint16 smbpid;
-        uint16 tid;
-        struct process_id pid;
-};
-
-/* The key used in the brlock database. */
-
-struct lock_key {
-	SMB_DEV_T device;
-	SMB_INO_T inode;
-};
-
-struct byte_range_lock {
-	files_struct *fsp;
-	unsigned int num_locks;
-	BOOL modified;
-	struct lock_key key;
-	void *lock_data;
-};
-
-#define BRLOCK_FN_CAST() \
-	void (*)(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, \
-				 enum brl_type lock_type, \
-				 enum brl_flavour lock_flav, \
-				 br_off start, br_off size)
-
-#define BRLOCK_FN(fn) \
-	void (*fn)(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, \
-				 enum brl_type lock_type, \
-				 enum brl_flavour lock_flav, \
-				 br_off start, br_off size)
-
-#define LOCKING_FN_CAST() \
-	void (*)(struct share_mode_entry *, const char *, const char *)
-
-#define LOCKING_FN(fn) \
-	void (*fn)(struct share_mode_entry *, const char *, const char *)
-
 struct bitmap {
 	uint32 *b;
 	unsigned int n;
 };
 
-#ifndef LOCKING_VERSION
-#define LOCKING_VERSION 4
-#endif /* LOCKING_VERSION */
-
 /* the basic packet size, assuming no words or bytes */
 #define smb_size 39
 

Modified: trunk/source/locking/brlock.c
===================================================================
--- trunk/source/locking/brlock.c	2006-07-08 20:49:00 UTC (rev 16884)
+++ trunk/source/locking/brlock.c	2006-07-09 00:52:21 UTC (rev 16885)
@@ -32,19 +32,6 @@
 
 #define ZERO_ZERO 0
 
-/* The data in brlock records is an unsorted linear array of these
-   records.  It is unnecessary to store the count as tdb provides the
-   size of the record */
-
-struct lock_struct {
-	struct lock_context context;
-	br_off start;
-	br_off size;
-	int fnum;
-	enum brl_type lock_type;
-	enum brl_flavour lock_flav;
-};
-
 /* The open brlock.tdb database. */
 
 static TDB_CONTEXT *tdb;
@@ -640,6 +627,11 @@
 		}
 	}
 
+	if (!lock_was_added) {
+		memcpy(&tp[count], plock, sizeof(struct lock_struct));
+		count++;
+	}
+
 	/* We can get the POSIX lock, now see if it needs to
 	   be mapped into a lower level POSIX one, and if so can
 	   we get it ? */
@@ -647,11 +639,19 @@
 	if ((plock->lock_type != PENDING_LOCK) && lp_posix_locking(SNUM(fsp->conn))) {
 		int errno_ret;
 
+		/* We pass in the entire new lock array to
+		   allow the lower layer to pick out the POSIX
+		   locks with the same PID. This allows the system
+		   layer to avoid walking the lock list doing the same
+		   split/merge game we've just done. */
+
 		if (!set_posix_lock_posix_flavour(fsp,
 				plock->start,
 				plock->size,
 				plock->lock_type,
 				&plock->context,
+				tp,
+				count,
 				&errno_ret)) {
 			if (errno_ret == EACCES || errno_ret == EAGAIN) {
 				SAFE_FREE(tp);
@@ -663,11 +663,6 @@
 		}
 	}
 
-	if (!lock_was_added) {
-		memcpy(&tp[count], plock, sizeof(struct lock_struct));
-		count++;
-	}
-
 	/* Realloc so we don't leak entries per lock call. */
 	tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks));
 	if (!tp) {

Modified: trunk/source/locking/posix.c
===================================================================
--- trunk/source/locking/posix.c	2006-07-08 20:49:00 UTC (rev 16884)
+++ trunk/source/locking/posix.c	2006-07-09 00:52:21 UTC (rev 16885)
@@ -1445,6 +1445,8 @@
 			SMB_BIG_UINT u_count,
 			enum brl_type lock_type,
 			const struct lock_context *plock_ctx,
+			const struct lock_struct *locks,
+			int count,
 			int *errno_ret)
 {
 	return True;



More information about the samba-cvs mailing list