[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Sat May 21 03:02:03 UTC 2016


The branch, master has been updated
       via  2eb824f s3:rpcclient: make use of SMB_SIGNING_IPC_DEFAULT
       via  f4b5e9d Revert "s3:rpcclient add -m option"
       via  7d0def3 s3: wscript: Add checks for open file description locks.
       via  e39436e s3: VFS: Map process-associated lock operation to open file description lock operation.
       via  5985383 s3: lib: util: Add map_process_lock_to_ofd_lock() utility function.
       via  da9b705 s3: VFS: Add bool use_ofd_locks member to struct files_struct.
       via  bb93b24 s3: lib: Add 'int op' parameter to fcntl_getlock().
       via  1863e6d s3: torture: Add POSIX-OFD-LOCK test.
       via  66b8ee1 s3: locking: Convert on the wire behavior of POSIX (UNIX extensions) locks from process-associated locks to open file description locks.
       via  a3cb0a4 s3: locking: Add a const struct lock_context * paramter to set_posix_lock_posix_flavour()
       via  a3df904 s3: locking: Add some const.
       via  4146fb9 s3: locking: Rename xxx_windows_lock_ref_count to xxx_lock_ref_count.
      from  02c2958 ctdb-scripts: Drop unnecessary detect_init_style() call

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


- Log -----------------------------------------------------------------
commit 2eb824fbaf61dfc5e9c735589c80c41379dabe86
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu May 19 11:47:18 2016 +0200

    s3:rpcclient: make use of SMB_SIGNING_IPC_DEFAULT
    
    This means we'll use the "client ipc min protocol", "client ipc max protocol"
    and "client ipc signing" options. But "--signing=no" or "--signing=required"
    still overwrite "client ipc signing".
    
    The following can be used to alter the max protocol
    
    rpcclient --option="client ipc max protocol=SMB2_10" 172.31.9.163 -Uadministrator%A1b2C3d4 -c "getusername"
    Account Name: Administrator, Authority Name: W4EDOM-L4
    
    rpcclient --option="client ipc max protocol=NT1" 172.31.9.163 -Uadministrator%A1b2C3d4 -c "getusername"
    Account Name: Administrator, Authority Name: W4EDOM-L4
    
    rpcclient 172.31.9.163 -Uadministrator%A1b2C3d4 -c "getusername"
    Account Name: Administrator, Authority Name: W4EDOM-L4
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=11927
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Sat May 21 05:01:15 CEST 2016 on sn-devel-144

commit f4b5e9d44d32a26d47fa8e465047be4355d4c30f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu May 19 11:47:29 2016 +0200

    Revert "s3:rpcclient add -m option"
    
    This reverts commit a55ac51f5f67c61bda1fee7067ad7d09a0c1efdf.
    
    This will be implemented in a more common way using the
    "client ipc max protocol" option.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=11927
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7d0def3056925118f3f47ff721939c0f5a42db57
Author: Jeremy Allison <jra at samba.org>
Date:   Thu May 12 21:46:50 2016 +0200

    s3: wscript: Add checks for open file description locks.
    
    Compiles and runs code that checks for working
    F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW.
    
    We now use these if available.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit e39436e770b5f6fe9e6615bc70bda627a3a1bd58
Author: Jeremy Allison <jra at samba.org>
Date:   Thu May 12 21:17:21 2016 +0200

    s3: VFS: Map process-associated lock operation to open file description lock operation.
    
    Only in the default VFS. Gpfs, Ceph, Gluster and other modern
    backend VFS filesystems might want to do the same.
    
    Allow tuneable "smbd:force process locks = true" to turn
    off OFD locks if in use and the kernel doesn't support them.
    
    Display debug message showing admins what to do in this case.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit 598538316786188f2d91c6e2c343c8051e27fd68
Author: Jeremy Allison <jra at samba.org>
Date:   Thu May 12 21:14:28 2016 +0200

    s3: lib: util: Add map_process_lock_to_ofd_lock() utility function.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit da9b7056fcd6f68795db3a28564fca8bd8eb8605
Author: Jeremy Allison <jra at samba.org>
Date:   Thu May 12 21:03:57 2016 +0200

    s3: VFS: Add bool use_ofd_locks member to struct files_struct.
    
    Not yet used. We will set this if we translate a process-associated
    lock operation to a open file description lock operation.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit bb93b24b18f02507f7a8714bb7a79b2a763aaa1a
Author: Jeremy Allison <jra at samba.org>
Date:   Thu May 12 20:57:36 2016 +0200

    s3: lib: Add 'int op' parameter to fcntl_getlock().
    
    Will allow us to move to open file description locks
    from process-associated locks.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit 1863e6da0aeb9218394cabccf9c7a0e4507edaec
Author: Jeremy Allison <jra at samba.org>
Date:   Fri May 13 15:09:54 2016 +0100

    s3: torture: Add POSIX-OFD-LOCK test.
    
    Ensures that we *always* expose ofd-lock behavior to clients.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit 66b8ee1e6419f8203aada3ff87e0da3d2f3639a1
Author: Jeremy Allison <jra at samba.org>
Date:   Mon May 16 16:59:30 2016 -0700

    s3: locking: Convert on the wire behavior of POSIX (UNIX extensions) locks from process-associated locks to open file description locks.
    
    This means locks are associated with the SMB handle
    they were created on, not the inode. In all other ways
    they behave like UNIX extensions fcntl (process-associated)
    locks. Torture test to follow.
    
    When a handle is closed all locks attached to that handle
    are closed, not all locks on the underlying inode. In
    this respect they now behave like Windows locks.
    
    The key to this in the UNIX extensions locking codepath is modifying
    the reference count only when a new locking context is seen
    on any lock request, and decrementing the reference count
    when the last instance of a locking context is seen on any
    unlock request. For SMB2+ the persistent part of a file handle
    is used as the locking context so this behavior becomes
    natural.
    
    This is a behavior change but after consultation with
    Jeff Layton and Steve French the only client that implements
    UNIX extensions POSIX locks - the cifsfs client - already
    expects these locks to behave like open file description
    (ofd) locks. With our previous behavior Linux ofd-locks
    fail against smbd.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit a3cb0a4c2788a594f080082a6d8973db86950879
Author: Jeremy Allison <jra at samba.org>
Date:   Tue May 17 12:49:36 2016 -0700

    s3: locking: Add a const struct lock_context * paramter to set_posix_lock_posix_flavour()
    
    We will need this to implement open file description record locks.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit a3df904a7a4825ab83ffc6207e88622e79b2765b
Author: Jeremy Allison <jra at samba.org>
Date:   Mon May 16 16:37:47 2016 -0700

    s3: locking: Add some const.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

commit 4146fb94fe5e65001310dffc85ef22e930ee2e6e
Author: Jeremy Allison <jra at samba.org>
Date:   Mon May 16 16:17:12 2016 -0700

    s3: locking: Rename xxx_windows_lock_ref_count to xxx_lock_ref_count.
    
    We will be using this to also ref count a posix lock applied
    to a file handle when changing to open file description lock
    semantics.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Jeff Layton <jlayton at samba.org>

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

Summary of changes:
 docs-xml/manpages/rpcclient.1.xml |  14 ----
 selftest/knownfail                |   1 +
 source3/include/proto.h           |   3 +-
 source3/include/vfs.h             |   2 +
 source3/lib/util.c                |  39 ++++++++-
 source3/locking/brlock.c          |   1 +
 source3/locking/posix.c           | 165 ++++++++++++++++++++++++++++++--------
 source3/locking/proto.h           |   3 +-
 source3/modules/vfs_default.c     |  19 ++++-
 source3/rpcclient/rpcclient.c     |  18 +++--
 source3/selftest/tests.py         |   2 +-
 source3/torture/torture.c         | 120 +++++++++++++++++++++++++++
 source3/wscript                   |  60 ++++++++++++++
 13 files changed, 385 insertions(+), 62 deletions(-)


Changeset truncated at 500 lines:

diff --git a/docs-xml/manpages/rpcclient.1.xml b/docs-xml/manpages/rpcclient.1.xml
index 2ce1443..fcdd0c6 100644
--- a/docs-xml/manpages/rpcclient.1.xml
+++ b/docs-xml/manpages/rpcclient.1.xml
@@ -24,7 +24,6 @@
 		<arg choice="opt">-c <command string></arg>
 		<arg choice="opt">-d debuglevel</arg>
 		<arg choice="opt">-l logdir</arg>
-		<arg choice="opt">-m maxprotocol</arg>
 		<arg choice="opt">-N</arg>
 		<arg choice="opt">-s <smb config file></arg>
 		<arg choice="opt">-U username[%password]</arg>
@@ -87,19 +86,6 @@
 		</varlistentry>
 
 		<varlistentry>
-		<term>-m|--max-protocol protocol</term>
-		<listitem><para>This allows the user to select the
-		highest SMB protocol level that rpcclient will use to
-		connect to the server. By default this is set to
-		NT1, which is the highest available SMB1 protocol.
-		To connect using SMB2 or SMB3 protocol, use the
-		strings SMB2 or SMB3 respectively. Note that to connect
-		to a Windows 2012 server with encrypted transport selecting
-		a max-protocol of SMB3 is required.
-		</para></listitem>
-		</varlistentry>
-
-		<varlistentry>
 		<term>-p|--port port</term>
 		<listitem><para>This number is the TCP port number that will be used
 		when making connections to the server. The standard (well-known)
diff --git a/selftest/knownfail b/selftest/knownfail
index c9f4fb0..59aba84 100644
--- a/selftest/knownfail
+++ b/selftest/knownfail
@@ -18,6 +18,7 @@
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-APPEND # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-SYMLINK-ACL # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-SYMLINK-EA # Fails against the s4 ntvfs server
+^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-OFD-LOCK # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).NTTRANS-FSCTL # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).SMB2-NEGPROT # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).BAD-NBT-SESSION # Fails against the s4 ntvfs server
diff --git a/source3/include/proto.h b/source3/include/proto.h
index c032b9e..36a5499 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -385,7 +385,8 @@ bool is_in_path(const char *name, name_compare_entry *namelist, bool case_sensit
 void set_namearray(name_compare_entry **ppname_array, const char *namelist);
 void free_namearray(name_compare_entry *name_array);
 bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type);
-bool fcntl_getlock(int fd, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid);
+bool fcntl_getlock(int fd, int op, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid);
+int map_process_lock_to_ofd_lock(int op, bool *use_ofd_locks);
 bool is_myname(const char *s);
 void ra_lanman_string( const char *native_lanman );
 const char *get_remote_arch_str(void);
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index a849443..dca6cef 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -192,6 +192,7 @@
 		const struct smb_filename * */
 /* Version 35 - Add uint32_t flags to struct smb_filename */
 /* Version 35 - Add get/set/fget/fset dos attribute functions. */
+/* Version 35 - Add bool use_ofd_locks to struct files_struct */
 
 #define SMB_VFS_INTERFACE_VERSION 35
 
@@ -287,6 +288,7 @@ typedef struct files_struct {
 	bool backup_intent; /* Handle was successfully opened with backup intent
 				and opener has privilege to do so. */
 	bool aapl_copyfile_supported;
+	bool use_ofd_locks; /* Are we using open file description locks ? */
 	struct smb_filename *fsp_name;
 	uint32_t name_hash;		/* Jenkins hash of full pathname. */
 	uint64_t mid;			/* Mid of the operation that created us. */
diff --git a/source3/lib/util.c b/source3/lib/util.c
index f64f6b5..ad33624 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1150,13 +1150,13 @@ void set_namearray(name_compare_entry **ppname_array, const char *namelist_in)
  F_UNLCK in *ptype if the region is unlocked). False if the call failed.
 ****************************************************************************/
 
-bool fcntl_getlock(int fd, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
+bool fcntl_getlock(int fd, int op, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
 {
 	struct flock lock;
 	int ret;
 
-	DEBUG(8,("fcntl_getlock fd=%d offset=%.0f count=%.0f type=%d\n",
-		    fd,(double)*poffset,(double)*pcount,*ptype));
+	DEBUG(8,("fcntl_getlock fd=%d op=%d offset=%.0f count=%.0f type=%d\n",
+		    fd,op,(double)*poffset,(double)*pcount,*ptype));
 
 	lock.l_type = *ptype;
 	lock.l_whence = SEEK_SET;
@@ -1164,7 +1164,7 @@ bool fcntl_getlock(int fd, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppi
 	lock.l_len = *pcount;
 	lock.l_pid = 0;
 
-	ret = sys_fcntl_ptr(fd,F_GETLK,&lock);
+	ret = sys_fcntl_ptr(fd,op,&lock);
 
 	if (ret == -1) {
 		int sav = errno;
@@ -1184,6 +1184,37 @@ bool fcntl_getlock(int fd, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppi
 	return True;
 }
 
+#if defined(HAVE_OFD_LOCKS)
+int map_process_lock_to_ofd_lock(int op, bool *use_ofd_locks)
+{
+	switch (op) {
+	case F_GETLK:
+	case F_OFD_GETLK:
+		op = F_OFD_GETLK;
+		break;
+	case F_SETLK:
+	case F_OFD_SETLK:
+		op = F_OFD_SETLK;
+		break;
+	case F_SETLKW:
+	case F_OFD_SETLKW:
+		op = F_OFD_SETLKW;
+		break;
+	default:
+		*use_ofd_locks = false;
+		return -1;
+	}
+	*use_ofd_locks = true;
+	return op;
+}
+#else /* HAVE_OFD_LOCKS */
+int map_process_lock_to_ofd_lock(int op, bool *use_ofd_locks)
+{
+	*use_ofd_locks = false;
+	return op;
+}
+#endif /* HAVE_OFD_LOCKS */
+
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_ALL
 
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index e8c8d89..70096d6 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -923,6 +923,7 @@ static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
 				plock->start,
 				plock->size,
 				plock->lock_type,
+				&plock->context,
 				&errno_ret)) {
 
 			/* We don't know who blocked us. */
diff --git a/source3/locking/posix.c b/source3/locking/posix.c
index ea42159..432637a 100644
--- a/source3/locking/posix.c
+++ b/source3/locking/posix.c
@@ -198,12 +198,22 @@ static bool posix_fcntl_lock(files_struct *fsp, int op, off_t offset, off_t coun
 
 	if (!ret && ((errno == EFBIG) || (errno == ENOLCK) || (errno ==  EINVAL))) {
 
-		DEBUG(0, ("posix_fcntl_lock: WARNING: lock request at offset "
+		if ((errno == EINVAL) &&
+				(op != F_GETLK &&
+				 op != F_SETLK &&
+				 op != F_SETLKW)) {
+			DEBUG(0,("WARNING: OFD locks in use and no kernel "
+				"support. Try setting "
+				"'smbd:force process locks = true' "
+				"in smb.conf\n"));
+		} else {
+			DEBUG(0, ("WARNING: lock request at offset "
 			  "%ju, length %ju returned\n",
 			  (uintmax_t)offset, (uintmax_t)count));
-		DEBUGADD(0, ("an %s error. This can happen when using 64 bit "
+			DEBUGADD(0, ("an %s error. This can happen when using 64 bit "
 			     "lock offsets\n", strerror(errno)));
-		DEBUGADD(0, ("on 32 bit NFS mounted file systems.\n"));
+			DEBUGADD(0, ("on 32 bit NFS mounted file systems.\n"));
+		}
 
 		/*
 		 * If the offset is > 0x7FFFFFFF then this will cause problems on
@@ -346,7 +356,7 @@ struct lock_ref_count_key {
  Form a static locking key for a dev/inode pair for the lock ref count
 ******************************************************************/
 
-static TDB_DATA locking_ref_count_key_fsp(files_struct *fsp,
+static TDB_DATA locking_ref_count_key_fsp(const files_struct *fsp,
 					  struct lock_ref_count_key *tmp)
 {
 	ZERO_STRUCTP(tmp);
@@ -359,9 +369,9 @@ static TDB_DATA locking_ref_count_key_fsp(files_struct *fsp,
  Convenience function to get an fd_array key from an fsp.
 ******************************************************************/
 
-static TDB_DATA fd_array_key_fsp(files_struct *fsp)
+static TDB_DATA fd_array_key_fsp(const files_struct *fsp)
 {
-	return make_tdb_data((uint8_t *)&fsp->file_id, sizeof(fsp->file_id));
+	return make_tdb_data((const uint8_t *)&fsp->file_id, sizeof(fsp->file_id));
 }
 
 /*******************************************************************
@@ -410,11 +420,11 @@ bool posix_locking_end(void)
 ****************************************************************************/
 
 /****************************************************************************
- Keep a reference count of the number of Windows locks open on this dev/ino
+ Keep a reference count of the number of locks open on this dev/ino
  pair. Creates entry if it doesn't exist.
 ****************************************************************************/
 
-static void increment_windows_lock_ref_count(files_struct *fsp)
+static void increment_lock_ref_count(const files_struct *fsp)
 {
 	struct lock_ref_count_key tmp;
 	int32_t lock_ref_count = 0;
@@ -427,15 +437,11 @@ static void increment_windows_lock_ref_count(files_struct *fsp)
 	SMB_ASSERT(NT_STATUS_IS_OK(status));
 	SMB_ASSERT(lock_ref_count < INT32_MAX);
 
-	DEBUG(10,("increment_windows_lock_ref_count for file now %s = %d\n",
+	DEBUG(10,("lock_ref_count for file %s = %d\n",
 		  fsp_str_dbg(fsp), (int)lock_ref_count));
 }
 
-/****************************************************************************
- Bulk delete - subtract as many locks as we've just deleted.
-****************************************************************************/
-
-static void decrement_windows_lock_ref_count(files_struct *fsp)
+static void decrement_lock_ref_count(const files_struct *fsp)
 {
 	struct lock_ref_count_key tmp;
 	int32_t lock_ref_count = 0;
@@ -448,7 +454,7 @@ static void decrement_windows_lock_ref_count(files_struct *fsp)
 	SMB_ASSERT(NT_STATUS_IS_OK(status));
 	SMB_ASSERT(lock_ref_count >= 0);
 
-	DEBUG(10,("reduce_windows_lock_ref_count for file now %s = %d\n",
+	DEBUG(10,("lock_ref_count for file %s = %d\n",
 		  fsp_str_dbg(fsp), (int)lock_ref_count));
 }
 
@@ -456,7 +462,7 @@ static void decrement_windows_lock_ref_count(files_struct *fsp)
  Fetch the lock ref count.
 ****************************************************************************/
 
-static int32_t get_windows_lock_ref_count(files_struct *fsp)
+static int32_t get_lock_ref_count(const files_struct *fsp)
 {
 	struct lock_ref_count_key tmp;
 	NTSTATUS status;
@@ -468,7 +474,7 @@ static int32_t get_windows_lock_ref_count(files_struct *fsp)
 
 	if (!NT_STATUS_IS_OK(status) &&
 	    !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
-		DEBUG(0, ("get_windows_lock_ref_count: Error fetching "
+		DEBUG(0, ("Error fetching "
 			  "lock ref count for file %s: %s\n",
 			  fsp_str_dbg(fsp), nt_errstr(status)));
 	}
@@ -479,7 +485,7 @@ static int32_t get_windows_lock_ref_count(files_struct *fsp)
  Delete a lock_ref_count entry.
 ****************************************************************************/
 
-static void delete_windows_lock_ref_count(files_struct *fsp)
+static void delete_lock_ref_count(const files_struct *fsp)
 {
 	struct lock_ref_count_key tmp;
 
@@ -488,7 +494,7 @@ static void delete_windows_lock_ref_count(files_struct *fsp)
 	dbwrap_delete(posix_pending_close_db,
 		      locking_ref_count_key_fsp(fsp, &tmp));
 
-	DEBUG(10,("delete_windows_lock_ref_count for file %s\n",
+	DEBUG(10,("delete_lock_ref_count for file %s\n",
 		  fsp_str_dbg(fsp)));
 }
 
@@ -496,7 +502,7 @@ static void delete_windows_lock_ref_count(files_struct *fsp)
  Add an fd to the pending close tdb.
 ****************************************************************************/
 
-static void add_fd_to_close_entry(files_struct *fsp)
+static void add_fd_to_close_entry(const files_struct *fsp)
 {
 	struct db_record *rec;
 	int *fds;
@@ -536,7 +542,7 @@ static void add_fd_to_close_entry(files_struct *fsp)
  Remove all fd entries for a specific dev/inode pair from the tdb.
 ****************************************************************************/
 
-static void delete_close_entries(files_struct *fsp)
+static void delete_close_entries(const files_struct *fsp)
 {
 	struct db_record *rec;
 
@@ -555,7 +561,8 @@ static void delete_close_entries(files_struct *fsp)
 ****************************************************************************/
 
 static size_t get_posix_pending_close_entries(TALLOC_CTX *mem_ctx,
-					      files_struct *fsp, int **entries)
+					const files_struct *fsp,
+					int **entries)
 {
 	TDB_DATA dbuf;
 	NTSTATUS status;
@@ -586,7 +593,7 @@ static size_t get_posix_pending_close_entries(TALLOC_CTX *mem_ctx,
  to delete all locks on this fsp before this function is called.
 ****************************************************************************/
 
-int fd_close_posix(struct files_struct *fsp)
+int fd_close_posix(const struct files_struct *fsp)
 {
 	int saved_errno = 0;
 	int ret;
@@ -594,17 +601,18 @@ int fd_close_posix(struct files_struct *fsp)
 	size_t count, i;
 
 	if (!lp_locking(fsp->conn->params) ||
-	    !lp_posix_locking(fsp->conn->params))
+	    !lp_posix_locking(fsp->conn->params) ||
+	    fsp->use_ofd_locks)
 	{
 		/*
-		 * No locking or POSIX to worry about or we want POSIX semantics
-		 * which will lose all locks on all fd's open on this dev/inode,
-		 * just close.
+		 * No locking or POSIX to worry about or we are using POSIX
+		 * open file description lock semantics which only removes
+		 * locks on the file descriptor we're closing. Just close.
 		 */
 		return close(fsp->fh->fd);
 	}
 
-	if (get_windows_lock_ref_count(fsp)) {
+	if (get_lock_ref_count(fsp)) {
 
 		/*
 		 * There are outstanding locks on this dev/inode pair on
@@ -644,7 +652,7 @@ int fd_close_posix(struct files_struct *fsp)
 	TALLOC_FREE(fd_array);
 
 	/* Don't need a lock ref count on this dev/ino anymore. */
-	delete_windows_lock_ref_count(fsp);
+	delete_lock_ref_count(fsp);
 
 	/*
 	 * Finally close the fd associated with this fsp.
@@ -948,7 +956,7 @@ bool set_posix_lock_windows_flavour(files_struct *fsp,
 	 */
 
 	if(!posix_lock_in_range(&offset, &count, u_offset, u_count)) {
-		increment_windows_lock_ref_count(fsp);
+		increment_lock_ref_count(fsp);
 		return True;
 	}
 
@@ -1053,8 +1061,8 @@ bool set_posix_lock_windows_flavour(files_struct *fsp,
 			posix_fcntl_lock(fsp,F_SETLK,offset,count,F_UNLCK);
 		}
 	} else {
-		/* Remember the number of Windows locks we have on this dev/ino pair. */
-		increment_windows_lock_ref_count(fsp);
+		/* Remember the number of locks we have on this dev/ino pair. */
+		increment_lock_ref_count(fsp);
 	}
 
 	talloc_destroy(l_ctx);
@@ -1085,8 +1093,8 @@ bool release_posix_lock_windows_flavour(files_struct *fsp,
 		  "count = %ju\n", fsp_str_dbg(fsp),
 		  (uintmax_t)u_offset, (uintmax_t)u_count));
 
-	/* Remember the number of Windows locks we have on this dev/ino pair. */
-	decrement_windows_lock_ref_count(fsp);
+	/* Remember the number of locks we have on this dev/ino pair. */
+	decrement_lock_ref_count(fsp);
 
 	/*
 	 * If the requested lock won't fit in the POSIX range, we will
@@ -1183,6 +1191,86 @@ bool release_posix_lock_windows_flavour(files_struct *fsp,
 ****************************************************************************/
 
 /****************************************************************************
+ We only increment the lock ref count when we see a POSIX lock on a context
+ that doesn't already have them.
+****************************************************************************/
+
+static void increment_posix_lock_count(const files_struct *fsp,
+					uint64_t smblctx)
+{
+	NTSTATUS status;
+	TDB_DATA ctx_key;
+	TDB_DATA val = { 0 };
+
+	ctx_key.dptr = (uint8_t *)&smblctx;
+	ctx_key.dsize = sizeof(smblctx);
+
+	/*
+	 * Don't increment if we already have any POSIX flavor
+	 * locks on this context.
+	 */
+	if (dbwrap_exists(posix_pending_close_db, ctx_key)) {
+		return;
+	}
+
+	/* Remember that we have POSIX flavor locks on this context. */
+	status = dbwrap_store(posix_pending_close_db, ctx_key, val, 0);
+	SMB_ASSERT(NT_STATUS_IS_OK(status));
+
+	increment_lock_ref_count(fsp);
+
+	DEBUG(10,("posix_locks set for file %s\n",
+		fsp_str_dbg(fsp)));
+}
+
+static void decrement_posix_lock_count(const files_struct *fsp, uint64_t smblctx)
+{
+	NTSTATUS status;
+	TDB_DATA ctx_key;
+
+	ctx_key.dptr = (uint8_t *)&smblctx;
+	ctx_key.dsize = sizeof(smblctx);
+
+	status = dbwrap_delete(posix_pending_close_db, ctx_key);
+	SMB_ASSERT(NT_STATUS_IS_OK(status));
+
+	decrement_lock_ref_count(fsp);
+
+	DEBUG(10,("posix_locks deleted for file %s\n",
+		fsp_str_dbg(fsp)));
+}
+
+/****************************************************************************
+ Return true if any locks exist on the given lock context.
+****************************************************************************/
+
+static bool locks_exist_on_context(const struct lock_struct *plocks,
+				int num_locks,
+				const struct lock_context *lock_ctx)
+{
+	int i;
+
+	for (i=0; i < num_locks; i++) {
+		const struct lock_struct *lock = &plocks[i];
+
+		/* Ignore all but read/write locks. */
+		if (lock->lock_type != READ_LOCK && lock->lock_type != WRITE_LOCK) {
+			continue;
+		}
+
+		/* Ignore locks not owned by this process. */
+		if (!serverid_equal(&lock->context.pid, &lock_ctx->pid)) {
+			continue;
+		}
+
+		if (lock_ctx->smblctx == lock->context.smblctx) {
+			return true;
+		}
+	}
+	return false;
+}
+
+/****************************************************************************
  POSIX function to acquire a lock. Returns True if the
  lock could be granted, False if not.
  As POSIX locks don't stack or conflict (they just overwrite)
@@ -1195,6 +1283,7 @@ bool set_posix_lock_posix_flavour(files_struct *fsp,
 			uint64_t u_offset,
 			uint64_t u_count,
 			enum brl_type lock_type,
+			const struct lock_context *lock_ctx,
 			int *errno_ret)
 {
 	off_t offset;
@@ -1212,6 +1301,7 @@ bool set_posix_lock_posix_flavour(files_struct *fsp,
 	 */
 
 	if(!posix_lock_in_range(&offset, &count, u_offset, u_count)) {
+		increment_posix_lock_count(fsp, lock_ctx->smblctx);
 		return True;
 	}
 
@@ -1221,6 +1311,7 @@ bool set_posix_lock_posix_flavour(files_struct *fsp,
 			posix_lock_type_name(posix_lock_type), (intmax_t)offset, (intmax_t)count, strerror(errno) ));
 		return False;
 	}
+	increment_posix_lock_count(fsp, lock_ctx->smblctx);
 	return True;
 }
 
@@ -1257,6 +1348,9 @@ bool release_posix_lock_posix_flavour(files_struct *fsp,
 	 */


-- 
Samba Shared Repository



More information about the samba-cvs mailing list