[SCM] Samba Shared Repository - branch v4-0-test updated

Karolin Seeger kseeger at samba.org
Tue Jul 2 04:46:05 MDT 2013


The branch, v4-0-test has been updated
       via  9f7cbc7 s3:smbd:smb2: fix setting of scavenge timeout when reconnecting durable handles
       via  e309d2e s3:smbd: call scavenger_schedule_disconnected() from close normal file for durable handles
       via  f688ed3 s3:smbd: add a scavenger process for disconnected durable handles
       via  888694d s3:locking: add function share_mode_cleanup_disconnected()
       via  4e423bc s3:locking: improve debug output of parse_share_modes()
       via  73f7c56 s3:locking: no need to make a file_id passed by value a constant
       via  1446ff4 s3:locking:brlock: add function brl_cleanup_disconnected()
       via  66eedcd s3:locking:brlock: explain the lockdb_clean semantic better in brl_reconnect_disconnected()
       via  b25d4ae s3:locking:brlock: let validate_lock_entries keep entries for disconnected servers in traverses
       via  383e20d s3:locking:brlock: improve the comment for the brl self cleaning code
       via  ff5e657 s3:locking:brlock: use serverids_exist to validate_lock_entries
       via  9fa4365 s3:smbXsrv_open: add function smbXsrv_open_cleanup()
       via  db0325f s3:smbXsrv_open: factor out smbXsrv_open_global_parse_record
       via  17106d7 s3:smbXsrv_open: add smbXsrv_open_global_traverse()
       via  e5c3875 lib: Add prctl_set_comment to utils.
       via  5eccfbf s3:smbd:smb2: fix segfault (access after free) in durable disconnect code
       via  af17545 s3:smbd: add debugging to close code (regarding disconnect of a durable)
       via  6a8cd1c s3:smbd: use smbXsrv_open_close() instead of smbXsrv_open_update()
      from  5c8e5ba VERSION: Bump version number up to 4.0.8...

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit 9f7cbc7e8916268da7fa6e2e7bd4e1a1154ab1ab
Author: Michael Adam <obnox at samba.org>
Date:   Thu Apr 18 13:11:03 2013 +0200

    s3:smbd:smb2: fix setting of scavenge timeout when reconnecting durable handles
    
    The bug fixed with this commit led to reconnected durable handles
    having a disconnect timeout of 0 msec. This fix re-establishes the
    original timeout for the reconnected handle.
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Signed-off-by: Michael Adam <obnox at samba.org>
    (cherry picked from commit beb9a27180e5570337381d03fac55bbe6d1637e0)
    
    The last 18 patches address bug #9930 - smbd did not cleanup disonnected durable
    handles.
    
    Autobuild-User(v4-0-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-0-test): Tue Jul  2 12:45:17 CEST 2013 on sn-devel-104

commit e309d2e3cf1e32b1302a38915fc5e3165626e9f3
Author: Gregor Beck <gbeck at sernet.de>
Date:   Wed Mar 20 10:01:43 2013 +0100

    s3:smbd: call scavenger_schedule_disconnected() from close normal file for durable handles
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit c2ef5182e32fafeb3e279d9fc3a2a409e4aa0543)

commit f688ed37faa5c4e8979c0ae6e18859e9b0dc020b
Author: Gregor Beck <gbeck at sernet.de>
Date:   Thu Feb 7 15:26:37 2013 +0100

    s3:smbd: add a scavenger process for disconnected durable handles
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>
    (cherry picked from commit 1ed22ba4b7998c1fc29476e931bd463f2bc1ba7e)
    
    Conflicts:
    
    	source3/Makefile.in

commit 888694d3b15c54696e9ccde4b37a4eb1e98f2e65
Author: Gregor Beck <gbeck at sernet.de>
Date:   Wed Mar 13 11:35:37 2013 +0100

    s3:locking: add function share_mode_cleanup_disconnected()
    
    For a given file, clean share mode entries for a given persistent file id.
    
    Pair-Programmed-With: Michael Adam <obnox at samba.org>
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Signed-off-by: Michael Adam <obnox at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit f608bedfca4118b7e3606802df40e266bcc099d8)

commit 4e423bc59703994842d6c271203894c485e9faa3
Author: Gregor Beck <gbeck at sernet.de>
Date:   Wed Mar 20 10:22:06 2013 +0100

    s3:locking: improve debug output of parse_share_modes()
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 0ac0b35dad796d10cf04ab77a53a926420cc0589)

commit 73f7c56e1c890d9e50665b0bdd23234925d48112
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Mar 12 15:10:51 2013 +0100

    s3:locking: no need to make a file_id passed by value a constant
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 3d3e7e837a339dfc1aaf4d7fc52f95f3f6a80173)
    
    Conflicts:
    
    	source3/locking/share_mode_lock.c

commit 1446ff47058923d1c4e5383fa05f207a05e01027
Author: Gregor Beck <gbeck at sernet.de>
Date:   Wed Mar 13 14:47:18 2013 +0100

    s3:locking:brlock: add function brl_cleanup_disconnected()
    
    For a given file, clean up brl entries belonging to a given persistent file id.
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit ee81a6e7d0263d263f7d4e7bd5bd9c4156cae8cf)

commit 66eedcdea8043ad9ae815c0ad3d9c9fad9b78da1
Author: Michael Adam <obnox at samba.org>
Date:   Fri Apr 12 11:13:57 2013 +0200

    s3:locking:brlock: explain the lockdb_clean semantic better in brl_reconnect_disconnected()
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 6ee1555df2e69aead00ee231c990020cc4bf04bc)

commit b25d4ae48b30850e26a2186a507c80d85fc017c7
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Mar 5 14:49:28 2013 +0100

    s3:locking:brlock: let validate_lock_entries keep entries for disconnected servers in traverses
    
    We should not remove locks of disconnected opens just like that.
    When getting the byte range lock record for a newly connected file
    handle, we still do the clean up, because in that situation,
    disconnected entries are not valid any more.
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit f08bda22dc7a5038fab77ad7dd090a6f72d94c7f)

commit 383e20d9cafb2d25400105184eb500e1f12baf42
Author: Michael Adam <obnox at samba.org>
Date:   Fri Apr 12 11:05:29 2013 +0200

    s3:locking:brlock: improve the comment for the brl self cleaning code
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit fe0bf0b6d67a49a30969f922ee65f0af88a952a1)

commit ff5e65780e65367cd1c4d917a5efd93732f77bbd
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Mar 5 14:02:10 2013 +0100

    s3:locking:brlock: use serverids_exist to validate_lock_entries
    
    ...instead of checking each server-id separately which can
    be expensive in a cluster.
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 02cc5a5c6a6b6b2b796abe573a671853d945b22f)

commit 9fa4365957d5c76d1b0276cca627f6204b73527d
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Mar 12 14:36:32 2013 +0100

    s3:smbXsrv_open: add function smbXsrv_open_cleanup()
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 941e84dcfe985559e5e75318e7b5dd9d50fcc47b)

commit db0325f613b1ab0d469dc0fa8a80662fc5e664b3
Author: Gregor Beck <gbeck at sernet.de>
Date:   Tue Mar 12 13:43:30 2013 +0100

    s3:smbXsrv_open: factor out smbXsrv_open_global_parse_record
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 9d47dc8958f7fcab77460495bd1ae940122dddd8)

commit 17106d77fe71c8b07e36bad58584bf0c98277771
Author: Gregor Beck <gbeck at sernet.de>
Date:   Wed Dec 12 16:06:50 2012 +0100

    s3:smbXsrv_open: add smbXsrv_open_global_traverse()
    
    Signed-off-by: Gregor Beck <gbeck at sernet.de>
    Reviewed-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit d23f19ab00314d773edb07a45e754365db378668)

commit e5c3875cb23a33a8fe932d6f2ea6496a4401d0c0
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Mar 5 15:54:44 2013 +0100

    lib: Add prctl_set_comment to utils.
    
    Reviewed-by: David Disseldorp <ddiss at samba.org>
    (cherry picked from commit f9fb3faaef4c15b7c4c3748b0e93fa3061b573c3)
    
    Conflicts:
    
    	lib/util/wscript_build

commit 5eccfbfa57b964e6de544545b03b503f777f647f
Author: Michael Adam <obnox at samba.org>
Date:   Mon Feb 18 23:21:24 2013 +0100

    s3:smbd:smb2: fix segfault (access after free) in durable disconnect code
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Michael Adam <obnox at samba.org>
    Autobuild-Date(master): Tue Feb 19 11:12:01 CET 2013 on sn-devel-104
    (cherry picked from commit bdb80aeb11d5458e281483a5cdc57f5481979cc9)

commit af175453c30101b7a4528b3128e4ff6cd22e20d8
Author: Michael Adam <obnox at samba.org>
Date:   Tue Feb 12 17:44:51 2013 +0100

    s3:smbd: add debugging to close code (regarding disconnect of a durable)
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Mon Feb 18 17:42:45 CET 2013 on sn-devel-104
    (cherry picked from commit cfebce3c56474ac914474b57ed94f93418b0564b)

commit 6a8cd1c61e6e89978b19c33291ff1a85b36ea9b3
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 13 08:26:43 2013 -0500

    s3:smbd: use smbXsrv_open_close() instead of smbXsrv_open_update()
    
    This makes sure we store the correct disconnect_time for disconnected
    durable handles.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>
    (cherry picked from commit f0e6a9be00e441e50f0087c543e1b7c9012d126f)

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

Summary of changes:
 lib/util/debug.c                                   |    1 +
 lib/util/debug.h                                   |    3 +-
 .../lib/version_test.c => lib/util/util_process.c  |   18 +-
 lib/{smbconf/smbconf_txt.h => util/util_process.h} |   26 +-
 lib/util/wscript_build                             |    3 +-
 source3/Makefile.in                                |    3 +-
 source3/librpc/idl/messaging.idl                   |    1 +
 source3/locking/brlock.c                           |  152 +++++-
 source3/locking/proto.h                            |   10 +-
 source3/locking/share_mode_lock.c                  |  119 ++++-
 source3/smbd/close.c                               |   29 +-
 source3/smbd/globals.h                             |    7 +
 source3/smbd/scavenger.c                           |  531 ++++++++++++++++++++
 .../echo_server.h => source3/smbd/scavenger.h      |   20 +-
 source3/smbd/server.c                              |    5 +
 source3/smbd/smb2_create.c                         |    9 +-
 source3/smbd/smbXsrv_open.c                        |  173 +++++++
 source3/wscript_build                              |    1 +
 18 files changed, 1047 insertions(+), 64 deletions(-)
 copy source3/lib/version_test.c => lib/util/util_process.c (68%)
 copy lib/{smbconf/smbconf_txt.h => util/util_process.h} (62%)
 create mode 100644 source3/smbd/scavenger.c
 copy source4/echo_server/echo_server.h => source3/smbd/scavenger.h (69%)


Changeset truncated at 500 lines:

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 7509f90..6207b61 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -176,6 +176,7 @@ static const char *default_classname_table[] = {
 	"msdfs",	     /* DBGC_MSDFS	  */
 	"dmapi",	     /* DBGC_DMAPI	  */
 	"registry",          /* DBGC_REGISTRY     */
+	"scavenger",         /* DBGC_SCAVENGER    */
 	NULL
 };
 
diff --git a/lib/util/debug.h b/lib/util/debug.h
index 2566418..c61fd13 100644
--- a/lib/util/debug.h
+++ b/lib/util/debug.h
@@ -79,9 +79,10 @@ bool dbghdr( int level, const char *location, const char *func);
 #define DBGC_MSDFS		17
 #define DBGC_DMAPI		18
 #define DBGC_REGISTRY		19
+#define DBGC_SCAVENGER		20
 
 /* Always ensure this is updated when new fixed classes area added, to ensure the array in debug.c is the right size */
-#define DBGC_MAX_FIXED		19
+#define DBGC_MAX_FIXED		20
 
 /* So you can define DBGC_CLASS before including debug.h */
 #ifndef DBGC_CLASS
diff --git a/source3/lib/version_test.c b/lib/util/util_process.c
similarity index 68%
copy from source3/lib/version_test.c
copy to lib/util/util_process.c
index 880cfeb..6036e27 100644
--- a/source3/lib/version_test.c
+++ b/lib/util/util_process.c
@@ -1,7 +1,9 @@
 /*
  *  Unix SMB/CIFS implementation.
- *  version_test - test program for samba_version_strion()
- *  Copyright (C) Michael Adam 2009
+ *
+ *  Process utils.
+ *
+ *  Copyright (c) 2013      Andreas Schneider <asn at samba.org>
  *
  *  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
@@ -17,10 +19,16 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "includes.h"
+#include "util_process.h"
+
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
 
-int main(void)
+int prctl_set_comment(const char *comment)
 {
-	printf("%s\n", samba_version_string());
+#if defined(HAVE_PRCTL) && defined(PR_SET_NAME)
+	return prctl(PR_SET_NAME, (unsigned long) comment, 0, 0, 0);
+#endif
 	return 0;
 }
diff --git a/lib/smbconf/smbconf_txt.h b/lib/util/util_process.h
similarity index 62%
copy from lib/smbconf/smbconf_txt.h
copy to lib/util/util_process.h
index 72d6207..6e1ef07 100644
--- a/lib/smbconf/smbconf_txt.h
+++ b/lib/util/util_process.h
@@ -1,7 +1,9 @@
 /*
  *  Unix SMB/CIFS implementation.
- *  libsmbconf - Samba configuration library
- *  Copyright (C) Michael Adam 2009
+ *
+ *  Process utils.
+ *
+ *  Copyright (c) 2013      Andreas Schneider <asn at samba.org>
  *
  *  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
@@ -17,17 +19,17 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __LIBSMBCONF_TXT_H__
-#define __LIBSMBCONF_TXT_H__
-
-struct smbconf_ctx;
+#ifndef _SAMBA_UTIL_PROCESS_H
+#define _SAMBA_UTIL_PROCESS_H
 
 /**
- * initialization functions for the text/file backend modules
+ * @brief Set the process comment name.
+ *
+ * @param[in]  comment  The comment to set which shouldn't be longer than 16
+ *                      16 characters (including \0).
+ *
+ * @return              -1 on error, 0 on success.
  */
+int prctl_set_comment(const char *comment);
 
-sbcErr smbconf_init_txt(TALLOC_CTX *mem_ctx,
-			struct smbconf_ctx **conf_ctx,
-			const char *path);
-
-#endif /*  _LIBSMBCONF_TXT_H_  */
+#endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index ddaf90f..27c9ec7 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -7,7 +7,8 @@ bld.SAMBA_LIBRARY('samba-util',
                     signal.c system.c params.c util.c util_id.c util_net.c
                     util_strlist.c util_paths.c idtree.c debug.c fault.c base64.c
                     util_str.c util_str_common.c substitute.c ms_fnmatch.c
-                    server_id.c dprintf.c parmlist.c bitmap.c pidfile.c''',
+                    server_id.c dprintf.c parmlist.c bitmap.c pidfile.c
+                    util_process.c''',
                   deps='DYNCONFIG',
                   public_deps='talloc execinfo uid_wrapper pthread LIBCRYPTO charset util_setid',
                   public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h samba_util.h string_wrappers.h',
diff --git a/source3/Makefile.in b/source3/Makefile.in
index c7c6250..96727fc 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -431,7 +431,7 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \
 		   ../lib/util/genrand.o ../lib/util/util_net.o \
 		   ../lib/util/become_daemon.o ../lib/util/system.o \
 		   ../lib/util/tevent_unix.o ../lib/util/tevent_ntstatus.o \
-		   ../lib/util/tevent_werror.o \
+		   ../lib/util/tevent_werror.o ../lib/util/util_process.o\
 		   lib/tevent_barrier.o \
 		   ../lib/util/smb_threads.o ../lib/util/util_id.o \
 		   ../lib/util/blocking.o ../lib/util/rfc1738.o \
@@ -986,6 +986,7 @@ SMBD_OBJ_SRV = smbd/server_reload.o \
 	       smbd/smbXsrv_tcon.o \
 	       smbd/smbXsrv_open.o \
 	       smbd/durable.o \
+	       smbd/scavenger.o \
 	       $(MANGLE_OBJ) @VFS_STATIC@
 
 SMBD_OBJ_BASE = $(PARAM_WITHOUT_REG_OBJ) $(SMBD_OBJ_SRV) $(LIBSMB_OBJ) \
diff --git a/source3/librpc/idl/messaging.idl b/source3/librpc/idl/messaging.idl
index df1f321..c262889 100644
--- a/source3/librpc/idl/messaging.idl
+++ b/source3/librpc/idl/messaging.idl
@@ -87,6 +87,7 @@ interface messaging
 
 		/* Trigger a notify cleanup run */
 		MSG_SMB_NOTIFY_CLEANUP		= 0x0314,
+		MSG_SMB_SCAVENGER		= 0x0315,
 
 		/* winbind messages */
 		MSG_WINBIND_FINISHED		= 0x0401,
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index b7abaa9..0654209 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -32,6 +32,7 @@
 #include "dbwrap/dbwrap_open.h"
 #include "serverid.h"
 #include "messages.h"
+#include "util_tdb.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_LOCKING
@@ -1595,7 +1596,11 @@ bool brl_reconnect_disconnected(struct files_struct *fsp)
 		return false;
 	}
 
-	/* we want to validate ourself */
+	/*
+	 * When reconnecting, we do not want to validate the brlock entries
+	 * and thereby remove our own (disconnected) entries but reactivate
+	 * them instead.
+	 */
 	fsp->lockdb_clean = true;
 
 	br_lck = brl_get_locks(talloc_tos(), fsp);
@@ -1650,22 +1655,62 @@ bool brl_reconnect_disconnected(struct files_struct *fsp)
 /****************************************************************************
  Ensure this set of lock entries is valid.
 ****************************************************************************/
-static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct **pplocks)
+static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct **pplocks,
+				  bool keep_disconnected)
 {
 	unsigned int i;
 	unsigned int num_valid_entries = 0;
 	struct lock_struct *locks = *pplocks;
+	TALLOC_CTX *frame = talloc_stackframe();
+	struct server_id *ids;
+	bool *exists;
+
+	ids = talloc_array(frame, struct server_id, *pnum_entries);
+	if (ids == NULL) {
+		DEBUG(0, ("validate_lock_entries: "
+			  "talloc_array(struct server_id, %u) failed\n",
+			  *pnum_entries));
+		talloc_free(frame);
+		return false;
+	}
+
+	exists = talloc_array(frame, bool, *pnum_entries);
+	if (exists == NULL) {
+		DEBUG(0, ("validate_lock_entries: "
+			  "talloc_array(bool, %u) failed\n",
+			  *pnum_entries));
+		talloc_free(frame);
+		return false;
+	}
 
 	for (i = 0; i < *pnum_entries; i++) {
-		struct lock_struct *lock_data = &locks[i];
-		if (!serverid_exists(&lock_data->context.pid)) {
-			/* This process no longer exists - mark this
-			   entry as invalid by zeroing it. */
-			ZERO_STRUCTP(lock_data);
-		} else {
+		ids[i] = locks[i].context.pid;
+	}
+
+	if (!serverids_exist(ids, *pnum_entries, exists)) {
+		DEBUG(3, ("validate_lock_entries: serverids_exists failed\n"));
+		talloc_free(frame);
+		return false;
+	}
+
+	for (i = 0; i < *pnum_entries; i++) {
+		if (exists[i]) {
 			num_valid_entries++;
+			continue;
 		}
+
+		if (keep_disconnected &&
+		    server_id_is_disconnected(&ids[i]))
+		{
+			num_valid_entries++;
+			continue;
+		}
+
+		/* This process no longer exists - mark this
+		   entry as invalid by zeroing it. */
+		ZERO_STRUCTP(&locks[i]);
 	}
+	TALLOC_FREE(frame);
 
 	if (num_valid_entries != *pnum_entries) {
 		struct lock_struct *new_lock_data = NULL;
@@ -1739,7 +1784,7 @@ static int brl_traverse_fn(struct db_record *rec, void *state)
 
 	/* Ensure the lock db is clean of entries from invalid processes. */
 
-	if (!validate_lock_entries(&num_locks, &locks)) {
+	if (!validate_lock_entries(&num_locks, &locks, true)) {
 		SAFE_FREE(locks);
 		return -1; /* Terminate traversal */
 	}
@@ -1927,12 +1972,21 @@ static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
 	if (!fsp->lockdb_clean) {
 		int orig_num_locks = br_lck->num_locks;
 
-		/* This is the first time we've accessed this. */
-		/* Go through and ensure all entries exist - remove any that don't. */
-		/* Makes the lockdb self cleaning at low cost. */
+		/*
+		 * This is the first time we access the byte range lock
+		 * record with this fsp. Go through and ensure all entries
+		 * are valid - remove any that don't.
+		 * This makes the lockdb self cleaning at low cost.
+		 *
+		 * Note: Disconnected entries belong to disconnected
+		 * durable handles. So at this point, we have a new
+		 * handle on the file and the disconnected durable has
+		 * already been closed (we are not a durable reconnect).
+		 * So we need to clean the disconnected brl entry.
+		 */
 
 		if (!validate_lock_entries(&br_lck->num_locks,
-					   &br_lck->lock_data)) {
+					   &br_lck->lock_data, false)) {
 			SAFE_FREE(br_lck->lock_data);
 			TALLOC_FREE(br_lck);
 			return NULL;
@@ -2099,3 +2153,75 @@ void brl_revalidate(struct messaging_context *msg_ctx,
 	TALLOC_FREE(state);
 	return;
 }
+
+bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id)
+{
+	bool ret = false;
+	TALLOC_CTX *frame = talloc_stackframe();
+	TDB_DATA key, val;
+	struct db_record *rec;
+	struct lock_struct *lock;
+	unsigned n, num;
+	NTSTATUS status;
+
+	key = make_tdb_data((void*)&fid, sizeof(fid));
+
+	rec = dbwrap_fetch_locked(brlock_db, frame, key);
+	if (rec == NULL) {
+		DEBUG(5, ("brl_cleanup_disconnected: failed to fetch record "
+			  "for file %s\n", file_id_string(frame, &fid)));
+		goto done;
+	}
+
+	val = dbwrap_record_get_value(rec);
+	lock = (struct lock_struct*)val.dptr;
+	num = val.dsize / sizeof(struct lock_struct);
+	if (lock == NULL) {
+		DEBUG(10, ("brl_cleanup_disconnected: no byte range locks for "
+			   "file %s\n", file_id_string(frame, &fid)));
+		ret = true;
+		goto done;
+	}
+
+	for (n=0; n<num; n++) {
+		struct lock_context *ctx = &lock[n].context;
+
+		if (!server_id_is_disconnected(&ctx->pid)) {
+			DEBUG(5, ("brl_cleanup_disconnected: byte range lock "
+				  "%s used by server %s, do not cleanup\n",
+				  file_id_string(frame, &fid),
+				  server_id_str(frame, &ctx->pid)));
+			goto done;
+		}
+
+		if (ctx->smblctx != open_persistent_id)	{
+			DEBUG(5, ("brl_cleanup_disconnected: byte range lock "
+				  "%s expected smblctx %llu but found %llu"
+				  ", do not cleanup\n",
+				  file_id_string(frame, &fid),
+				  (unsigned long long)open_persistent_id,
+				  (unsigned long long)ctx->smblctx));
+			goto done;
+		}
+	}
+
+	status = dbwrap_record_delete(rec);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(5, ("brl_cleanup_disconnected: failed to delete record "
+			  "for file %s from %s, open %llu: %s\n",
+			  file_id_string(frame, &fid), dbwrap_name(brlock_db),
+			  (unsigned long long)open_persistent_id,
+			  nt_errstr(status)));
+		goto done;
+	}
+
+	DEBUG(10, ("brl_cleanup_disconnected: "
+		   "file %s cleaned up %u entries from open %llu\n",
+		   file_id_string(frame, &fid), num,
+		   (unsigned long long)open_persistent_id));
+
+	ret = true;
+done:
+	talloc_free(frame);
+	return ret;
+}
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index c170c73..bb7255d 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -97,6 +97,7 @@ void brl_revalidate(struct messaging_context *msg_ctx,
 		    uint32_t msg_type,
 		    struct server_id server_id,
 		    DATA_BLOB *data);
+bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id);
 
 /* The following definitions come from locking/locking.c  */
 
@@ -149,15 +150,15 @@ bool locking_init_readonly(void);
 bool locking_end(void);
 char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e);
 struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
-						     const struct file_id id);
+						     struct file_id id);
 struct share_mode_lock *get_share_mode_lock(
 	TALLOC_CTX *mem_ctx,
-	const struct file_id id,
+	struct file_id id,
 	const char *servicepath,
 	const struct smb_filename *smb_fname,
 	const struct timespec *old_write_time);
 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
-						  const struct file_id id);
+						  struct file_id id);
 bool rename_share_filename(struct messaging_context *msg_ctx,
 			struct share_mode_lock *lck,
 			const char *servicepath,
@@ -201,6 +202,9 @@ bool set_write_time(struct file_id fileid, struct timespec write_time);
 int share_mode_forall(void (*fn)(const struct share_mode_entry *, const char *,
 				 const char *, void *),
 		      void *private_data);
+bool share_mode_cleanup_disconnected(struct file_id id,
+				     uint64_t open_persistent_id);
+
 
 /* The following definitions come from locking/posix.c  */
 
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index a82c44e..266be65 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -104,10 +104,9 @@ bool locking_end(void)
  Form a static locking key for a dev/inode pair.
 ******************************************************************/
 
-static TDB_DATA locking_key(const struct file_id *id, struct file_id *tmp)
+static TDB_DATA locking_key(const struct file_id *id)
 {
-	*tmp = *id;
-	return make_tdb_data((const uint8_t *)tmp, sizeof(*tmp));
+	return make_tdb_data((const uint8_t *)id, sizeof(*id));
 }
 
 /*******************************************************************
@@ -133,7 +132,8 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
 	ndr_err = ndr_pull_struct_blob(
 		&blob, d, d, (ndr_pull_flags_fn_t)ndr_pull_share_mode_data);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-		DEBUG(1, ("ndr_pull_share_mode_lock failed\n"));
+		DEBUG(1, ("ndr_pull_share_mode_lock failed: %s\n",
+			  ndr_errstr(ndr_err)));
 		goto fail;
 	}
 
@@ -286,15 +286,14 @@ fail:
 ********************************************************************/
 
 static struct share_mode_lock *get_share_mode_lock_internal(
-	TALLOC_CTX *mem_ctx, const struct file_id id,
+	TALLOC_CTX *mem_ctx, struct file_id id,
 	const char *servicepath, const struct smb_filename *smb_fname,
 	const struct timespec *old_write_time)
 {
 	struct share_mode_lock *lck;
 	struct share_mode_data *d;
-	struct file_id tmp;
 	struct db_record *rec;
-	TDB_DATA key = locking_key(&id, &tmp);
+	TDB_DATA key = locking_key(&id);
 	TDB_DATA value;
 
 	rec = dbwrap_fetch_locked(lock_db, mem_ctx, key);
@@ -351,7 +350,7 @@ static int the_lock_destructor(struct share_mode_lock *l)
 
 struct share_mode_lock *get_share_mode_lock(
 	TALLOC_CTX *mem_ctx,
-	const struct file_id id,
+	struct file_id id,
 	const char *servicepath,
 	const struct smb_filename *smb_fname,
 	const struct timespec *old_write_time)
@@ -395,11 +394,10 @@ fail:
 ********************************************************************/
 
 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
-						  const struct file_id id)
+						  struct file_id id)
 {
 	struct share_mode_lock *lck;
-	struct file_id tmp;
-	TDB_DATA key = locking_key(&id, &tmp);
+	TDB_DATA key = locking_key(&id);
 	TDB_DATA data;
 	NTSTATUS status;
 
@@ -502,3 +500,102 @@ int share_mode_forall(void (*fn)(const struct share_mode_entry *, const char *,
 		return count;
 	}
 }
+
+bool share_mode_cleanup_disconnected(struct file_id fid,
+				     uint64_t open_persistent_id)
+{
+	bool ret = false;
+	TALLOC_CTX *frame = talloc_stackframe();
+	unsigned n;
+	struct share_mode_data *data;
+	struct share_mode_lock *lck;
+	bool ok;
+
+	lck = get_existing_share_mode_lock(frame, fid);
+	if (lck == NULL) {
+		DEBUG(5, ("share_mode_cleanup_disconnected: "
+			  "Could not fetch share mode entry for %s\n",
+			  file_id_string(frame, &fid)));
+		goto done;
+	}
+	data = lck->data;
+


-- 
Samba Shared Repository


More information about the samba-cvs mailing list