[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha6-864-g7d73130

Jeremy Allison jra at samba.org
Fri Feb 13 19:32:31 GMT 2009


The branch, master has been updated
       via  7d73130125723425e8884b00ca20ab77788f39d8 (commit)
       via  a3531314dd6c7da05e4b35cc84a8c3a0addaa0a4 (commit)
       via  813273c87e4f48d7d8415c8ee9a1a553ed369429 (commit)
       via  eb3d964f20f44deaf2b4f07adba64785875710e0 (commit)
      from  f3262027a3314edda8c0659f7d7b27dbdbea0203 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7d73130125723425e8884b00ca20ab77788f39d8
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Feb 13 10:36:11 2009 -0800

    Fix the build. When you do "make distclean; ./autogen; ./configure; make" and it still doesn't build you know it's messed up.
    Jeremy.

commit a3531314dd6c7da05e4b35cc84a8c3a0addaa0a4
Author: Zack Kirsch <zack.kirsch at isilon.com>
Date:   Mon Feb 9 21:54:51 2009 -0800

    OneFS implementation of BRL VFS ops:
    
    * Much of the beginning should look familiar, as I re-used the OneFS oplock
      callback record concept. This was necessary to keep our own state around - it
      really only consists of a lock state, per asynchronous lock that is currently
      unsatisfied.  The onefs_cbrl_callback_records map to BLRs by the id.
    * There are 4 states an async lock can be in. NONE means there is no async
      currently out for the lock, as opposed to ASYNC. DONE means we've locked
      *every* lock (keep in mind a request can ask for multiple locks at a time.)
      ERROR is an error.
    * onefs_cbrl_async_success: The lock_num is incremented, and the state changed,
      so that when process_blocking_lock_queue is run, we will try the *next* lock,
      rather than the same one again.
    * onefs_brl_lock_windows() has some complicated logic:
        * We do a no-op if we're passed a BLR and the matching state is ASYNC --
          this means Samba is trying to get the same lock twice, and we just need
          to wait longer, so we return an error.
        * PENDING lock calls happen when the lock is being queued on the BLQ -- we
          do async in this case.
        * We also do async in the case that we're passed a BLR, but the lock is not
          pending. This is an async lock being probed by process_blocking_lock_queue.
        * We do a sync lock for any normal first request of a lock.
        * Failure is returned, but it doesn't go to the client unless the lock has
          actually timed out.

commit 813273c87e4f48d7d8415c8ee9a1a553ed369429
Author: Zack Kirsch <zack.kirsch at isilon.com>
Date:   Mon Feb 9 21:51:29 2009 -0800

    Add VFS ops for Windows BRL: Lock, Unlock and Cancel:
    
    This patch adds 3 new VFS OPs for Windows byte range locking: BRL_LOCK_WINDOWS,
    BRL_UNLOCK_WINDOWS and BRL_CANCEL_WINDOWS. Specifically:
    
    * I renamed brl_lock_windows, brl_unlock_windows and brl_lock_cancel to
      *_default as the default implementations of the VFS ops.
    * The blocking_lock_record (BLR) is now passed into the brl_lock_windows and
      brl_cancel_windows paths. The Onefs implementation uses it - future
      implementations may find it useful too.
    * Created brl_lock_cancel to do what brl_lock/brl_unlock do: set up a
      lock_struct and call either the Posix or Windows lock function. These happen
      to be the same for the default implementation.
    * Added helper functions: increment_current_lock_count() and
      decrement_current_lock_count().
    * Minor spelling correction in brl_timeout_fn: brl -> blr.
    * Changed blocking_lock_cancel() to return the BLR that it has cancelled. This
      allows us to assert its the lock that we wanted to cancel. If this assert ever
      fires, this path will need to take in the BLR to cancel, rather than choosing
      on its own.
    * Adds a small helper function: find_blocking_lock_record_by_id(). Used by the
      OneFS implementation, but could be useful for others.

commit eb3d964f20f44deaf2b4f07adba64785875710e0
Author: Zack Kirsch <zack.kirsch at isilon.com>
Date:   Wed Feb 11 22:13:26 2009 -0800

    Remove typedef struct blocking_lock_record and move references to struct blocking_lock_record.

-----------------------------------------------------------------------

Summary of changes:
 source3/Makefile.in              |    3 +-
 source3/configure.in             |    2 +-
 source3/include/includes.h       |    2 +
 source3/include/locking.h        |   20 ++
 source3/include/proto.h          |   26 ++-
 source3/include/vfs.h            |   24 ++
 source3/include/vfs_macros.h     |    9 +
 source3/locking/brlock.c         |   66 ++++--
 source3/locking/locking.c        |   81 ++++---
 source3/modules/onefs.h          |   19 ++-
 source3/modules/onefs_cbrl.c     |  453 ++++++++++++++++++++++++++++++++++++++
 source3/modules/vfs_default.c    |   41 ++++
 source3/modules/vfs_full_audit.c |   73 ++++++
 source3/modules/vfs_onefs.c      |    6 +
 source3/smbd/blocking.c          |  139 +++++++------
 source3/smbd/reply.c             |   18 ++-
 source3/smbd/trans2.c            |    3 +-
 source4/include/includes.h       |    4 +
 18 files changed, 859 insertions(+), 130 deletions(-)
 create mode 100644 source3/modules/onefs_cbrl.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index e11633f..144c81a 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -665,7 +665,8 @@ VFS_ACL_XATTR_OBJ = modules/vfs_acl_xattr.o
 VFS_ACL_TDB_OBJ = modules/vfs_acl_tdb.o
 VFS_SMB_TRAFFIC_ANALYZER_OBJ = modules/vfs_smb_traffic_analyzer.o
 VFS_ONEFS_OBJ = modules/vfs_onefs.o modules/onefs_acl.o modules/onefs_system.o \
-		modules/onefs_open.o modules/onefs_streams.o modules/onefs_dir.c
+		modules/onefs_open.o modules/onefs_streams.o modules/onefs_dir.c \
+		modules/onefs_cbrl.o
 PERFCOUNT_ONEFS_OBJ = modules/perfcount_onefs.o
 
 PLAINTEXT_AUTH_OBJ = auth/pampass.o auth/pass_check.o
diff --git a/source3/configure.in b/source3/configure.in
index d11ece1..4ff4c7b 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -1085,7 +1085,7 @@ echo $samba_cv_HAVE_ONEFS
 if test x"$samba_cv_HAVE_ONEFS" = x"yes"; then
     AC_DEFINE(HAVE_ONEFS,1,[Whether building on Isilon OneFS])
     default_shared_modules="$default_shared_modules vfs_onefs perfcount_onefs"
-    ONEFS_LIBS="-lisi_acl"
+    ONEFS_LIBS="-lisi_acl -lisi_ecs -lisi_event -lisi_util"
     # Need to also add general libs for oplocks support
     save_LIBS="$save_LIBS -lisi_ecs -lisi_event -lisi_util -ldevstat"
 fi
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 2c033e8..a9f813b 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -1049,7 +1049,9 @@ ssize_t readahead(int fd, off64_t offset, size_t count);
 #undef HAVE_MMAP
 #endif
 
+#ifndef CONST_DISCARD
 #define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
+#endif
 
 void smb_panic( const char *why ) _NORETURN_;
 void dump_core(void) _NORETURN_;
diff --git a/source3/include/locking.h b/source3/include/locking.h
index b2b7236..3fd5b94 100644
--- a/source3/include/locking.h
+++ b/source3/include/locking.h
@@ -75,4 +75,24 @@ struct lock_struct {
 	enum brl_flavour lock_flav;
 };
 
+/****************************************************************************
+ This is the structure to queue to implement blocking locks.
+*****************************************************************************/
+
+struct blocking_lock_record {
+	struct blocking_lock_record *next;
+	struct blocking_lock_record *prev;
+	struct files_struct *fsp;
+	struct timeval expire_time;
+	int lock_num;
+	uint64_t offset;
+	uint64_t count;
+	uint32_t lock_pid;
+	uint32_t blocking_pid; /* PID that blocks us. */
+	enum brl_flavour lock_flav;
+	enum brl_type lock_type;
+	struct smb_request *req;
+	void *blr_private; /* Implementation specific. */
+};
+
 #endif /* _LOCKING_H_ */
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 3410472..ed2c50a 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -3379,8 +3379,14 @@ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id,
 
 bool brl_same_context(const struct lock_context *ctx1, 
 			     const struct lock_context *ctx2);
+NTSTATUS brl_lock_failed(files_struct *fsp, const struct lock_struct *lock, bool blocking_lock);
 void brl_init(bool read_only);
 void brl_shutdown(void);
+
+NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
+		struct lock_struct *plock,
+		bool blocking_lock);
+
 NTSTATUS brl_lock(struct messaging_context *msg_ctx,
 		struct byte_range_lock *br_lck,
 		uint32 smbpid,
@@ -3390,7 +3396,8 @@ NTSTATUS brl_lock(struct messaging_context *msg_ctx,
 		enum brl_type lock_type,
 		enum brl_flavour lock_flav,
 		bool blocking_lock,
-		uint32 *psmbpid);
+		uint32 *psmbpid,
+		struct blocking_lock_record *blr);
 bool brl_unlock(struct messaging_context *msg_ctx,
 		struct byte_range_lock *br_lck,
 		uint32 smbpid,
@@ -3398,6 +3405,9 @@ bool brl_unlock(struct messaging_context *msg_ctx,
 		br_off start,
 		br_off size,
 		enum brl_flavour lock_flav);
+bool brl_unlock_windows_default(struct messaging_context *msg_ctx,
+			       struct byte_range_lock *br_lck,
+			       const struct lock_struct *plock);
 bool brl_locktest(struct byte_range_lock *br_lck,
 		uint32 smbpid,
 		struct server_id pid,
@@ -3417,7 +3427,10 @@ bool brl_lock_cancel(struct byte_range_lock *br_lck,
 		struct server_id pid,
 		br_off start,
 		br_off size,
-		enum brl_flavour lock_flav);
+		enum brl_flavour lock_flav,
+		struct blocking_lock_record *blr);
+bool brl_lock_cancel_default(struct byte_range_lock *br_lck,
+		struct lock_struct *plock);
 void brl_close_fnum(struct messaging_context *msg_ctx,
 		    struct byte_range_lock *br_lck);
 int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
@@ -3456,7 +3469,8 @@ struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
 			enum brl_flavour lock_flav,
 			bool blocking_lock,
 			NTSTATUS *perr,
-			uint32 *plock_pid);
+			uint32 *plock_pid,
+			struct blocking_lock_record *blr);
 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
 			files_struct *fsp,
 			uint32 lock_pid,
@@ -3467,7 +3481,8 @@ NTSTATUS do_lock_cancel(files_struct *fsp,
 			uint32 lock_pid,
 			uint64_t count,
 			uint64_t offset,
-			enum brl_flavour lock_flav);
+			enum brl_flavour lock_flav,
+			struct blocking_lock_record *blr);
 void locking_close_file(struct messaging_context *msg_ctx,
 			files_struct *fsp);
 bool locking_init(void);
@@ -6342,6 +6357,7 @@ void smbd_aio_complete_mid(unsigned int mid);
 
 /* The following definitions come from smbd/blocking.c  */
 
+void process_blocking_lock_queue(void);
 bool push_blocking_lock_request( struct byte_range_lock *br_lck,
 		struct smb_request *req,
 		files_struct *fsp,
@@ -6356,7 +6372,7 @@ bool push_blocking_lock_request( struct byte_range_lock *br_lck,
 void cancel_pending_lock_requests_by_fid(files_struct *fsp, struct byte_range_lock *br_lck);
 void remove_pending_lock_requests_by_mid(int mid);
 bool blocking_lock_was_deferred(int mid);
-bool blocking_lock_cancel(files_struct *fsp,
+struct blocking_lock_record *blocking_lock_cancel(files_struct *fsp,
 			uint32 lock_pid,
 			uint64_t offset,
 			uint64_t count,
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index f944c89..ffa1a95 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -115,6 +115,7 @@
 /* Leave at 25 - not yet released. Add get_alloc_size call. -- tprouty. */
 /* Leave at 25 - not yet released. Add SMB_STRUCT_STAT to readdir. - sdann */
 /* Leave at 25 - not yet released. Add init_search_op call. - sdann */
+/* Leave at 25 - not yet released. Add locking calls. -- zkirsch. */
 
 #define SMB_VFS_INTERFACE_VERSION 25
 
@@ -142,6 +143,7 @@ struct vfs_statvfs_struct;
 struct smb_request;
 struct ea_list;
 struct smb_file_time;
+struct blocking_lock_record;
 
 /*
     Available VFS operations. These values must be in sync with vfs_ops struct
@@ -218,6 +220,9 @@ typedef enum _vfs_op_type {
 	SMB_VFS_OP_FILE_ID_CREATE,
 	SMB_VFS_OP_STREAMINFO,
 	SMB_VFS_OP_GET_REAL_FILENAME,
+	SMB_VFS_OP_BRL_LOCK_WINDOWS,
+	SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
+	SMB_VFS_OP_BRL_CANCEL_WINDOWS,
 
 	/* NT ACL operations. */
 
@@ -393,6 +398,22 @@ struct vfs_ops {
 					 TALLOC_CTX *mem_ctx,
 					 char **found_name);
 
+		NTSTATUS (*brl_lock_windows)(struct vfs_handle_struct *handle,
+					     struct byte_range_lock *br_lck,
+					     struct lock_struct *plock,
+					     bool blocking_lock,
+					     struct blocking_lock_record *blr);
+
+		bool (*brl_unlock_windows)(struct vfs_handle_struct *handle,
+					   struct messaging_context *msg_ctx,
+					   struct byte_range_lock *br_lck,
+					   const struct lock_struct *plock);
+
+		bool (*brl_cancel_windows)(struct vfs_handle_struct *handle,
+					   struct byte_range_lock *br_lck,
+					   struct lock_struct *plock,
+					   struct blocking_lock_record *blr);
+
 		/* NT ACL operations. */
 
 		NTSTATUS (*fget_nt_acl)(struct vfs_handle_struct *handle,
@@ -531,6 +552,9 @@ struct vfs_ops {
 		struct vfs_handle_struct *file_id_create;
 		struct vfs_handle_struct *streaminfo;
 		struct vfs_handle_struct *get_real_filename;
+		struct vfs_handle_struct *brl_lock_windows;
+		struct vfs_handle_struct *brl_unlock_windows;
+		struct vfs_handle_struct *brl_cancel_windows;
 
 		/* NT ACL operations. */
 
diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h
index e57cbd2..dcef63d 100644
--- a/source3/include/vfs_macros.h
+++ b/source3/include/vfs_macros.h
@@ -88,6 +88,9 @@
 #define SMB_VFS_FILE_ID_CREATE(conn, dev, inode) ((conn)->vfs.ops.file_id_create((conn)->vfs.handles.file_id_create, (dev), (inode)))
 #define SMB_VFS_STREAMINFO(conn, fsp, fname, mem_ctx, num_streams, streams) ((conn)->vfs.ops.streaminfo((conn)->vfs.handles.streaminfo, (fsp), (fname), (mem_ctx), (num_streams), (streams)))
 #define SMB_VFS_GET_REAL_FILENAME(conn, path, name, mem_ctx, found_name) ((conn)->vfs.ops.get_real_filename((conn)->vfs.handles.get_real_filename, (path), (name), (mem_ctx), (found_name)))
+#define SMB_VFS_BRL_LOCK_WINDOWS(conn, br_lck, plock, blocking_lock, blr) ((conn)->vfs.ops.brl_lock_windows((conn)->vfs.handles.brl_lock_windows, (br_lck), (plock), (blocking_lock), (blr)))
+#define SMB_VFS_BRL_UNLOCK_WINDOWS(conn, msg_ctx, br_lck, plock) ((conn)->vfs.ops.brl_unlock_windows((conn)->vfs.handles.brl_unlock_windows, (msg_ctx), (br_lck), (plock)))
+#define SMB_VFS_BRL_CANCEL_WINDOWS(conn, br_lck, plock, blr) ((conn)->vfs.ops.brl_cancel_windows((conn)->vfs.handles.brl_cancel_windows, (br_lck), (plock), (blr)))
 
 /* NT ACL operations. */
 #define SMB_VFS_FGET_NT_ACL(fsp, security_info, ppdesc) ((fsp)->conn->vfs.ops.fget_nt_acl((fsp)->conn->vfs.handles.fget_nt_acl, (fsp), (security_info), (ppdesc)))
@@ -217,6 +220,9 @@
 #define SMB_VFS_OPAQUE_FILE_ID_CREATE(conn, dev, inode) ((conn)->vfs.ops_opaque.file_id_create((conn)->vfs_opaque.handles.file_id_create, (dev), (inode)))
 #define SMB_VFS_OPAQUE_STREAMINFO(conn, fsp, fname, mem_ctx, num_streams, streams) ((conn)->vfs_opaque.ops.streaminfo((conn)->vfs_opaque.handles.streaminfo, (fsp), (fname), (mem_ctx), (num_streams), (streams)))
 #define SMB_VFS_OPAQUE_GET_REAL_FILENAME(conn, path, name, mem_ctx, found_name) ((conn)->vfs_opaque.ops.get_real_filename((conn)->vfs_opaque.handles.get_real_filename, (path), (name), (mem_ctx), (found_name)))
+#define SMB_VFS_OPAQUE_BRL_LOCK_WINDOWS(conn, br_lck, plock, blocking_lock, blr) ((conn)->vfs_opaque.ops.brl_lock_windows((conn)->vfs_opaque.handles.brl_lock_windows, (br_lck), (plock), (blocking_lock), (blr)))
+#define SMB_VFS_OPAQUE_BRL_UNLOCK_WINDOWS(conn, msg_ctx, br_lck, plock) ((conn)->vfs_opaque.ops.brl_unlock_windows((conn)->vfs_opaque.handles.brl_unlock_windows, (msg_ctx), (br_lck), (plock)))
+#define SMB_VFS_OPAQUE_BRL_CANCEL_WINDOWS(conn, br_lck, plock, blr) ((conn)->vfs_opaque.ops.brl_cancel_windows((conn)->vfs_opaque.handles.brl_cancel_windows, (br_lck), (plock), (blr)))
 
 /* NT ACL operations. */
 #define SMB_VFS_OPAQUE_FGET_NT_ACL(fsp, security_info, ppdesc) ((fsp)->conn->vfs_opaque.ops.fget_nt_acl((fsp)->conn->vfs_opaque.handles.fget_nt_acl, (fsp), (security_info), (ppdesc)))
@@ -347,6 +353,9 @@
 #define SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode) ((handle)->vfs_next.ops.file_id_create((handle)->vfs_next.handles.file_id_create, (dev), (inode)))
 #define SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx, num_streams, streams) ((handle)->vfs_next.ops.streaminfo((handle)->vfs_next.handles.streaminfo, (fsp), (fname), (mem_ctx), (num_streams), (streams)))
 #define SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx, found_name) ((handle)->vfs_next.ops.get_real_filename((handle)->vfs_next.handles.get_real_filename, (path), (name), (mem_ctx), (found_name)))
+#define SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock, blocking_lock, blr) ((handle)->vfs_next.ops.brl_lock_windows((handle)->vfs_next.handles.brl_lock_windows, (br_lck), (plock), (blocking_lock), (blr)))
+#define SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck, plock) ((handle)->vfs_next.ops.brl_unlock_windows((handle)->vfs_next.handles.brl_unlock_windows, (msg_ctx), (br_lck), (plock)))
+#define SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr) ((handle)->vfs_next.ops.brl_cancel_windows((handle)->vfs_next.handles.brl_cancel_windows, (br_lck), (plock), (blr)))
 
 /* NT ACL operations. */
 #define SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc) ((handle)->vfs_next.ops.fget_nt_acl((handle)->vfs_next.handles.fget_nt_acl, (fsp), (security_info), (ppdesc)))
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index edba4ed..d12c4af 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -228,7 +228,7 @@ static bool brl_pending_overlap(const struct lock_struct *lock, const struct loc
  app depends on this ?
 ****************************************************************************/
 
-static NTSTATUS brl_lock_failed(files_struct *fsp, const struct lock_struct *lock, bool blocking_lock)
+NTSTATUS brl_lock_failed(files_struct *fsp, const struct lock_struct *lock, bool blocking_lock)
 {
 	if (lock->start >= 0xEF000000 && (lock->start >> 63) == 0) {
 		/* amazing the little things you learn with a test
@@ -305,14 +305,16 @@ static int lock_compare(const struct lock_struct *lck1,
  Lock a range of bytes - Windows lock semantics.
 ****************************************************************************/
 
-static NTSTATUS brl_lock_windows(struct byte_range_lock *br_lck,
-			struct lock_struct *plock, bool blocking_lock)
+NTSTATUS brl_lock_windows_default(struct byte_range_lock *br_lck,
+    struct lock_struct *plock, bool blocking_lock)
 {
 	unsigned int i;
 	files_struct *fsp = br_lck->fsp;
 	struct lock_struct *locks = br_lck->lock_data;
 	NTSTATUS status;
 
+	SMB_ASSERT(plock->lock_type != UNLOCK_LOCK);
+
 	for (i=0; i < br_lck->num_locks; i++) {
 		/* Do any Windows or POSIX locks conflict ? */
 		if (brl_conflict(&locks[i], plock)) {
@@ -781,7 +783,8 @@ NTSTATUS brl_lock(struct messaging_context *msg_ctx,
 		enum brl_type lock_type,
 		enum brl_flavour lock_flav,
 		bool blocking_lock,
-		uint32 *psmbpid)
+		uint32 *psmbpid,
+		struct blocking_lock_record *blr)
 {
 	NTSTATUS ret;
 	struct lock_struct lock;
@@ -807,7 +810,8 @@ NTSTATUS brl_lock(struct messaging_context *msg_ctx,
 	lock.lock_flav = lock_flav;
 
 	if (lock_flav == WINDOWS_LOCK) {
-		ret = brl_lock_windows(br_lck, &lock, blocking_lock);
+		ret = SMB_VFS_BRL_LOCK_WINDOWS(br_lck->fsp->conn, br_lck,
+		    &lock, blocking_lock, blr);
 	} else {
 		ret = brl_lock_posix(msg_ctx, br_lck, &lock);
 	}
@@ -828,7 +832,7 @@ NTSTATUS brl_lock(struct messaging_context *msg_ctx,
  Unlock a range of bytes - Windows semantics.
 ****************************************************************************/
 
-static bool brl_unlock_windows(struct messaging_context *msg_ctx,
+bool brl_unlock_windows_default(struct messaging_context *msg_ctx,
 			       struct byte_range_lock *br_lck,
 			       const struct lock_struct *plock)
 {
@@ -836,6 +840,8 @@ static bool brl_unlock_windows(struct messaging_context *msg_ctx,
 	struct lock_struct *locks = br_lck->lock_data;
 	enum brl_type deleted_lock_type = READ_LOCK; /* shut the compiler up.... */
 
+	SMB_ASSERT(plock->lock_type == UNLOCK_LOCK);
+
 #if ZERO_ZERO
 	/* Delete write locks by preference... The lock list
 	   is sorted in the zero zero case. */
@@ -1130,7 +1136,8 @@ bool brl_unlock(struct messaging_context *msg_ctx,
 	lock.lock_flav = lock_flav;
 
 	if (lock_flav == WINDOWS_LOCK) {
-		return brl_unlock_windows(msg_ctx, br_lck, &lock);
+		return SMB_VFS_BRL_UNLOCK_WINDOWS(br_lck->fsp->conn, msg_ctx,
+		    br_lck, &lock);
 	} else {
 		return brl_unlock_posix(msg_ctx, br_lck, &lock);
 	}
@@ -1266,32 +1273,54 @@ NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
 /****************************************************************************
  Remove a particular pending lock.
 ****************************************************************************/
-
 bool brl_lock_cancel(struct byte_range_lock *br_lck,
 		uint32 smbpid,
 		struct server_id pid,
 		br_off start,
 		br_off size,
-		enum brl_flavour lock_flav)
+		enum brl_flavour lock_flav,
+		struct blocking_lock_record *blr)
+{
+	bool ret;
+	struct lock_struct lock;
+
+	lock.context.smbpid = smbpid;
+	lock.context.pid = pid;
+	lock.context.tid = br_lck->fsp->conn->cnum;
+	lock.start = start;
+	lock.size = size;
+	lock.fnum = br_lck->fsp->fnum;
+	lock.lock_flav = lock_flav;
+	/* lock.lock_type doesn't matter */
+
+	if (lock_flav == WINDOWS_LOCK) {
+		ret = SMB_VFS_BRL_CANCEL_WINDOWS(br_lck->fsp->conn, br_lck,
+		    &lock, blr);
+	} else {
+		ret = brl_lock_cancel_default(br_lck, &lock);
+	}
+
+	return ret;
+}
+
+bool brl_lock_cancel_default(struct byte_range_lock *br_lck,
+		struct lock_struct *plock)
 {
 	unsigned int i;
 	struct lock_struct *locks = br_lck->lock_data;
-	struct lock_context context;
 
-	context.smbpid = smbpid;
-	context.pid = pid;
-	context.tid = br_lck->fsp->conn->cnum;
+	SMB_ASSERT(plock);
 
 	for (i = 0; i < br_lck->num_locks; i++) {
 		struct lock_struct *lock = &locks[i];
 
 		/* For pending locks we *always* care about the fnum. */
-		if (brl_same_context(&lock->context, &context) &&
-				lock->fnum == br_lck->fsp->fnum &&
+		if (brl_same_context(&lock->context, &plock->context) &&
+				lock->fnum == plock->fnum &&
 				IS_PENDING_LOCK(lock->lock_type) &&
-				lock->lock_flav == lock_flav &&
-				lock->start == start &&
-				lock->size == size) {
+				lock->lock_flav == plock->lock_flav &&
+				lock->start == plock->start &&
+				lock->size == plock->size) {
 			break;
 		}
 	}
@@ -1460,7 +1489,6 @@ void brl_close_fnum(struct messaging_context *msg_ctx,
 /****************************************************************************
  Ensure this set of lock entries is valid.
 ****************************************************************************/
-
 static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct **pplocks)
 {
 	unsigned int i;
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index b342fa9..902b230 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -177,6 +177,34 @@ NTSTATUS query_lock(files_struct *fsp,
 	return status;
 }
 
+static void increment_current_lock_count(files_struct *fsp,
+    enum brl_flavour lock_flav)
+{
+	if (lock_flav == WINDOWS_LOCK &&
+	    fsp->current_lock_count != NO_LOCKING_COUNT) {
+		/* 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++;
+	} else {
+		/* Notice that this has had a POSIX lock request.
+		 * We can't count locks after this so forget them.
+		 */
+		fsp->current_lock_count = NO_LOCKING_COUNT;
+	}
+}
+
+static void decrement_current_lock_count(files_struct *fsp,
+    enum brl_flavour lock_flav)
+{
+	if (lock_flav == WINDOWS_LOCK &&
+	    fsp->current_lock_count != NO_LOCKING_COUNT) {
+		SMB_ASSERT(fsp->current_lock_count > 0);
+		fsp->current_lock_count--;
+	}
+}
+
 /****************************************************************************
  Utility function called by locking requests.
 ****************************************************************************/
@@ -190,7 +218,8 @@ struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
 			enum brl_flavour lock_flav,
 			bool blocking_lock,
 			NTSTATUS *perr,
-			uint32 *plock_pid)
+			uint32 *plock_pid,
+			struct blocking_lock_record *blr)
 {
 	struct byte_range_lock *br_lck = NULL;
 
@@ -206,9 +235,11 @@ struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
 
 	/* NOTE! 0 byte long ranges ARE allowed and should be stored  */
 
-	DEBUG(10,("do_lock: lock flavour %s lock type %s start=%.0f len=%.0f requested for fnum %d file %s\n",
+	DEBUG(10,("do_lock: lock flavour %s lock type %s start=%.0f len=%.0f "
+		"blocking_lock=%s requested for fnum %d file %s\n",
 		lock_flav_name(lock_flav), lock_type_name(lock_type),
-		(double)offset, (double)count, fsp->fnum, fsp->fsp_name ));
+		(double)offset, (double)count, blocking_lock ? "true" :
+		"false", fsp->fnum, fsp->fsp_name));
 
 	br_lck = brl_get_locks(talloc_tos(), fsp);
 	if (!br_lck) {
@@ -225,22 +256,12 @@ struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
 			lock_type,
 			lock_flav,
 			blocking_lock,
-			plock_pid);
+			plock_pid,
+			blr);
 
-	if (lock_flav == WINDOWS_LOCK &&
-			fsp->current_lock_count != NO_LOCKING_COUNT) {
-		/* 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++;
-	} else {
-		/* Notice that this has had a POSIX lock request.
-		 * We can't count locks after this so forget them.
-		 */
-		fsp->current_lock_count = NO_LOCKING_COUNT;
-	}
+	DEBUG(10, ("do_lock: returning status=%s\n", nt_errstr(*perr)));
 
+	increment_current_lock_count(fsp, lock_flav);
 	return br_lck;
 }
 
@@ -289,12 +310,7 @@ NTSTATUS do_unlock(struct messaging_context *msg_ctx,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list