[SCM] Samba Shared Repository - branch master updated

Christof Schmitt cs at samba.org
Sun Apr 14 05:19:02 UTC 2019


The branch, master has been updated
       via  a187b7ef8fe smbd: Remove share_mode_lease and the leases array from share_mode_entry
       via  ad413ce91b3 smbd: Use share_mode_forall_leases in share_mode_cleanup_disconnected()
       via  310c85e78fc smbd: Use share_mode_forall_leases in do_break_to_none()
       via  c12641e80dd smbd: Use share_mode_forall_leases in rename_share_filename()
       via  302bdd7f913 smbd: Add share_mode_forall_leases()
       via  fbe6b3e900e smbd: Use leases_db in lease_match()
       via  b656ebf54af smbd: Make find_share_mode_lease() static
       via  29ce005f128 smbd: Use leases_db in process_oplock_break_message()
       via  8ff60fcc061 smbd: Use leases_db in vfs_default_durable_reconnect()
       via  274f5d9541d smbd: Use leases_db in downgrade_lease()
       via  7fc76c47867 smbd: Use leases_db in try_lease_upgrade()
       via  7cc9b426a44 smbd: Split up grant_fsp_lease()
       via  fa2cea30917 smbd: Add update_share_mode_lease_from_db()
       via  2ea2605e700 smbd: Don't pass up lease_idx from grant_fsp_lease
       via  552faa910fd smbd: Don't pass lease_idx down to set_share_mode()
       via  c54d27b12c7 utils: Use leases_db in smbstatus
       via  1269bfe47bb smbd: Use leases_db in fsp_lease_update()
       via  b4b941f2af6 smbd: Use leases_db in get_lease_type()
       via  b221487371c smbd: Use leases_db in delay_for_oplock()
       via  c2ca8217245 smbd: Use share_mode_entry's lease data in lease_match()
       via  b9b35947c75 smbd: Use share_mode_entry's lease data in vfs_default_durable_reconnect()
       via  9ca5b611575 smbd: Use share_mode_entry's lease data in remove_share_mode_lease()
       via  1ae77361483 smbd: Use share_mode_entry's lease data in remove_share_mode_lease()
       via  909147e8c16 smbd: Use share_mode_entry's lease data in is_same_lease()
       via  f33cb162788 smbd: Use share_mode_entry's lease data in delay_rename_for_lease_break()
       via  70fd809db6b smbd: Use share_mode_entry's lease data in delay_for_oplock()
       via  10a60df1ccc smbd: Add lease key to share_mode_entry
       via  6cd59da1719 smbd: Use leases_db_set()
       via  5f850a80d2d leases_db: Add getter/setter for share_mode_lease metadata
       via  f46023ed702 leases_db: Add share_mode_lease info to leases.tdb
       via  a69db298d44 smbd: Pass lease parameters explicitly to find_fsp_lease
       via  3eed19de048 smbd: Introduce a helper variable in delay_for_oplock()
       via  6e485441a60 smbd: Introduce a helper variable in delay_for_oplock()
       via  b3d0c7e32c9 smbd: Small optimization for break_to_none
      from  98521ce51c6 .gitlab-ci.yml: show the system state also as after_script

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


- Log -----------------------------------------------------------------
commit a187b7ef8fe91d227aeda5a2d9d4400d43c9d4ef
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 17:42:51 2018 +0200

    smbd: Remove share_mode_lease and the leases array from share_mode_entry
    
    This also removes the temporary functions introduced during the patchset.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>
    
    Autobuild-User(master): Christof Schmitt <cs at samba.org>
    Autobuild-Date(master): Sun Apr 14 05:18:14 UTC 2019 on sn-devel-144

commit ad413ce91b31697f60c31394004272bcd6418596
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 13:22:12 2018 +0200

    smbd: Use share_mode_forall_leases in share_mode_cleanup_disconnected()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 310c85e78fc0833373db0c1ccec04f172c8abff6
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 17 17:01:38 2018 +0200

    smbd: Use share_mode_forall_leases in do_break_to_none()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit c12641e80dd7b1587cb7961a6f21df679668fba3
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 17 13:24:56 2018 +0200

    smbd: Use share_mode_forall_leases in rename_share_filename()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 302bdd7f9132b64daf65ceddc1658c3f91d7f0c1
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 17 13:14:22 2018 +0200

    smbd: Add share_mode_forall_leases()
    
    Function to walk all leases for a file exactly once. This used to be simpler
    with the leases[] array, thus this function that encapsulates the complexity.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit fbe6b3e900e5b1f270e33b4c63fd651dfbfd53b8
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 16:31:55 2018 +0200

    smbd: Use leases_db in lease_match()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit b656ebf54afcd322cc7dcaa1a913a557027840fd
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 12:36:25 2018 +0200

    smbd: Make find_share_mode_lease() static
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 29ce005f12809f6af5ff2ab5b33af26b25c7063a
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 18 15:18:15 2018 +0200

    smbd: Use leases_db in process_oplock_break_message()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 8ff60fcc0618c3501478831d771e54e9665303ef
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 13:37:23 2018 +0200

    smbd: Use leases_db in vfs_default_durable_reconnect()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 274f5d9541de7c61f52d42789c701c212b9caa6b
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 12:05:57 2018 +0200

    smbd: Use leases_db in downgrade_lease()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 7fc76c47867460a29ef82b65052a47b13c530a17
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 18 13:51:01 2018 +0200

    smbd: Use leases_db in try_lease_upgrade()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 7cc9b426a44b1e12c6261836d0a86eabb7c92c34
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 18 13:00:49 2018 +0200

    smbd: Split up grant_fsp_lease()
    
    Simple refactoring into simpler routines. View best with "git show -b"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit fa2cea30917667e1f8f084c33cbbbd564f02e452
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 10:25:31 2018 +0200

    smbd: Add update_share_mode_lease_from_db()
    
    This is an interim function supposed to be around for just a few patches as
    long as we have both the leases.tdb entries and the leases[] in
    share_mode_entries around. It makes it easier to transition to just use
    leases.tdb while keeping the code running.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 2ea2605e7002508aa952899fb8f81e4e62684767
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 18 11:37:28 2018 +0200

    smbd: Don't pass up lease_idx from grant_fsp_lease
    
    The only reason for grant_fsp_lease to return the lease_idx was to pass it down
    to set_share_mode. That does not need it anymore.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 552faa910fdcfb95602440096ec3fac9e6015177
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 18 11:31:27 2018 +0200

    smbd: Don't pass lease_idx down to set_share_mode()
    
    Temporary patch to keep the code running. The new code in set_share_mode() will
    leave again once the patchset to remove share_mode_lease and thus the lease_idx
    in share_mode_entry goes away.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit c54d27b12c7a978671fcea752da552d84a7e3668
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 12:52:46 2018 +0200

    utils: Use leases_db in smbstatus
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 1269bfe47bb0f5a19e8e54f01de375cc0a43191e
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 16:38:28 2019 +0200

    smbd: Use leases_db in fsp_lease_update()
    
    Remove a reference to "struct share_mode_lease"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit b4b941f2af601482725ae826b77b863200fee604
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 13 12:48:30 2018 +0200

    smbd: Use leases_db in get_lease_type()
    
    Remove a reference to share_mode_data->leases[]
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit b221487371cd1e953b2919be67a190626ba28399
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 13 12:48:30 2018 +0200

    smbd: Use leases_db in delay_for_oplock()
    
    Remove a reference to share_mode_data->leases[]
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit c2ca82172457bd369715398aa7fda2af4e23f61f
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 21:54:27 2019 +0200

    smbd: Use share_mode_entry's lease data in lease_match()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit b9b35947c75d7aafb303535de37854d90f4f8b76
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 21:34:24 2019 +0200

    smbd: Use share_mode_entry's lease data in vfs_default_durable_reconnect()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 9ca5b611575e01467fe1651d06b843a7be50ae5b
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 16:39:31 2018 +0200

    smbd: Use share_mode_entry's lease data in remove_share_mode_lease()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 1ae773614830e9142cc1a0bb8dfc94b3f7d21ad7
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 14:14:32 2018 +0200

    smbd: Use share_mode_entry's lease data in remove_share_mode_lease()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 909147e8c16731b786a1d6eae549d53737c2369e
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 19 14:29:23 2018 +0200

    smbd: Use share_mode_entry's lease data in is_same_lease()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit f33cb162788397863e03e8288f34aa32c345cee5
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 13 19:11:22 2018 +0200

    smbd: Use share_mode_entry's lease data in delay_rename_for_lease_break()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 70fd809db6b3d67077e42338e1b68310754278e2
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 14:05:15 2019 +0200

    smbd: Use share_mode_entry's lease data in delay_for_oplock()
    
    This was the last "share_mode_lease" reference in this function, remove
    variable "l".
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 10a60df1ccc5e5992c63802861589fb81372f64e
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 13 12:47:55 2018 +0200

    smbd: Add lease key to share_mode_entry
    
    Instead of indexing into the leases[] array, put the lease_db reference into
    the share_mode_entry. For simplicity, put in the client guid as well. We
    *might* be able to retrieve that from somewhere else, but as other smbd
    processes have to look at the lease values, put in the full leases_db index
    data.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 6cd59da1719e3f4830a7cea5db4347bf9e319b92
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 8 16:21:41 2019 +0200

    smbd: Use leases_db_set()
    
    Whenever we update the share_mode_lease struct, also update the leases.tdb
    entry.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 5f850a80d2d83838fd713a6b19e716ec47b86bbf
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 11 16:23:38 2018 +0200

    leases_db: Add getter/setter for share_mode_lease metadata
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit f46023ed7021880612150d762540fda656c89b74
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 11 16:13:24 2018 +0200

    leases_db: Add share_mode_lease info to leases.tdb
    
    This is the data stored in share_mode_lease inside the leases[] array in
    locking.tdb. This and all the following patches move all leases array to
    looking at the leases.tdb.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit a69db298d440f38fdc2e222d01ecf8d52e0dcc0a
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 18 09:55:51 2018 +0200

    smbd: Pass lease parameters explicitly to find_fsp_lease
    
    This avoids a use of "struct share_mode_lease"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 3eed19de04887bec8a01af55eb33acc89ef80b7c
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 15:14:38 2019 +0200

    smbd: Introduce a helper variable in delay_for_oplock()
    
    This removes a few explicit share_mode_lease dereferences
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 6e485441a60f75e8500541ba9790e55f5a86041f
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 14:19:30 2019 +0200

    smbd: Introduce a helper variable in delay_for_oplock()
    
    Why? I am preparing a patchset that will remove
    "share_mode_lease". This patch is a micro-step towards that, removing
    a set of references to this struct.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit b3d0c7e32c9b56dad9003f6bbb067da4aa0a6753
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 9 16:34:24 2019 +0200

    smbd: Small optimization for break_to_none
    
    We don't need to memzero the struct when we can struct-initialize it a
    bit later, implicitly initializing the rest to zero.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Christof Schmitt <cs at samba.org>

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

Summary of changes:
 source3/librpc/idl/leases_db.idl  |  26 +++
 source3/librpc/idl/open_files.idl |  35 +---
 source3/locking/leases_db.c       | 185 ++++++++++++++++++
 source3/locking/leases_db.h       |  20 ++
 source3/locking/locking.c         | 191 ++++++++++++------
 source3/locking/proto.h           |  16 +-
 source3/locking/share_mode_lock.c |  40 +++-
 source3/smbd/durable.c            |  47 +++--
 source3/smbd/open.c               | 313 +++++++++++++++++------------
 source3/smbd/oplock.c             | 401 +++++++++++++++++++++++++-------------
 source3/smbd/proto.h              |  10 +-
 source3/smbd/smb2_setinfo.c       |   7 +-
 source3/utils/status.c            |  35 +++-
 13 files changed, 922 insertions(+), 404 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/librpc/idl/leases_db.idl b/source3/librpc/idl/leases_db.idl
index d0218756ade..ed9f27643ab 100644
--- a/source3/librpc/idl/leases_db.idl
+++ b/source3/librpc/idl/leases_db.idl
@@ -22,6 +22,32 @@ interface leases_db
 	} leases_db_file;
 
 	typedef [public] struct {
+		smb2_lease_state	current_state;
+		/*
+		 * 'breaking' indicates that we're waiting
+		 * for a lease break ack from the client
+		 * and breaking_to_requested and breaking_to_required
+		 * have a meaning.
+		 *
+		 * breaking_to_requested is the value already sent to
+		 * the client, the client needs to ack to this (or less).
+		 *
+		 * breaking_to_required is the internal value that needs to
+		 * be reached before we can reset breaking = false, this
+		 * may requires multiple roundtrips to the client, e.g.
+		 * when the lease broken to a more reduced value, while
+		 * the lease break is still in progress.
+		 *
+		 * The following can be assumed (if breaking == true):
+		 *
+		 * current_state>breaking_to_requested>=breaking_to_required
+		 */
+		boolean8		breaking;
+		smb2_lease_state	breaking_to_requested;
+		smb2_lease_state	breaking_to_required;
+		uint16			lease_version;
+		uint16			epoch;
+
 		uint32 num_files;
 		[size_is(num_files)] leases_db_file files[];
 	} leases_db_value;
diff --git a/source3/librpc/idl/open_files.idl b/source3/librpc/idl/open_files.idl
index c07a903878e..2f6f861b5e6 100644
--- a/source3/librpc/idl/open_files.idl
+++ b/source3/librpc/idl/open_files.idl
@@ -12,41 +12,12 @@ import "misc.idl";
 
 interface open_files
 {
-	typedef [public,flag(NDR_PAHEX)] struct {
-		GUID			client_guid;
-		smb2_lease_key		lease_key;
-		smb2_lease_state	current_state;
-		/*
-		 * 'breaking' indicates that we're waiting
-		 * for a lease break ack from the client
-		 * and breaking_to_requested and breaking_to_required
-		 * have a meaning.
-		 *
-		 * breaking_to_requested is the value already sent to
-		 * the client, the client needs to ack to this (or less).
-		 *
-		 * breaking_to_required is the internal value that needs to
-		 * be reached before we can reset breaking = false, this
-		 * may requires multiple roundtrips to the client, e.g.
-		 * when the lease broken to a more reduced value, while
-		 * the lease break is still in progress.
-		 *
-		 * The following can be assumed (if breaking == true):
-		 *
-		 * current_state > breaking_to_requested >= breaking_to_required
-		 */
-		boolean8		breaking;
-		smb2_lease_state	breaking_to_requested;
-		smb2_lease_state	breaking_to_required;
-		uint16			lease_version;
-		uint16			epoch;
-	} share_mode_lease;
-
 	typedef [public] struct {
 		server_id	pid;
 		hyper		op_mid;
 		uint16		op_type;
-		uint32		lease_idx;
+		GUID		client_guid;
+		smb2_lease_key  lease_key;
 		uint32		access_mask;
 		uint32		share_access;
 		uint32		private_options;
@@ -76,8 +47,6 @@ interface open_files
 		[string,charset(UTF8)] char *stream_name;
 		uint32 num_share_modes;
 		[size_is(num_share_modes)] share_mode_entry share_modes[];
-		uint32 num_leases;
-		[size_is(num_leases)] share_mode_lease leases[];
 		uint32 num_delete_tokens;
 		[size_is(num_delete_tokens)] delete_token delete_tokens[];
 		timespec old_write_time;
diff --git a/source3/locking/leases_db.c b/source3/locking/leases_db.c
index 3893841b172..17778050acc 100644
--- a/source3/locking/leases_db.c
+++ b/source3/locking/leases_db.c
@@ -196,6 +196,9 @@ static NTSTATUS leases_db_do_locked(
 
 struct leases_db_add_state {
 	const struct file_id *id;
+	uint32_t current_state;
+	uint16_t lease_version;
+	uint16_t epoch;
 	const char *servicepath;
 	const char *base_name;
 	const char *stream_name;
@@ -217,6 +220,13 @@ static void leases_db_add_fn(
 		}
 	}
 
+	if (value->num_files == 0) {
+		/* new record */
+		value->current_state = state->current_state;
+		value->lease_version = state->lease_version;
+		value->epoch = state->epoch;
+	}
+
 	tmp = talloc_realloc(
 		value,
 		value->files,
@@ -242,12 +252,18 @@ static void leases_db_add_fn(
 NTSTATUS leases_db_add(const struct GUID *client_guid,
 		       const struct smb2_lease_key *lease_key,
 		       const struct file_id *id,
+		       uint32_t current_state,
+		       uint16_t lease_version,
+		       uint16_t epoch,
 		       const char *servicepath,
 		       const char *base_name,
 		       const char *stream_name)
 {
 	struct leases_db_add_state state = {
 		.id = id,
+		.current_state = current_state,
+		.lease_version = lease_version,
+		.epoch = epoch,
 		.servicepath = servicepath,
 		.base_name = base_name,
 		.stream_name = stream_name,
@@ -443,6 +459,175 @@ NTSTATUS leases_db_rename(const struct GUID *client_guid,
 	return state.status;
 }
 
+struct leases_db_set_state {
+	uint32_t current_state;
+	bool breaking;
+	uint32_t breaking_to_requested;
+	uint32_t breaking_to_required;
+	uint16_t lease_version;
+	uint16_t epoch;
+};
+
+static void leases_db_set_fn(
+	struct leases_db_value *value, bool *modified, void *private_data)
+{
+	struct leases_db_set_state *state = private_data;
+
+	if (value->num_files == 0) {
+		DBG_WARNING("leases_db_set on new entry\n");
+		return;
+	}
+	value->current_state = state->current_state;
+	value->breaking = state->breaking;
+	value->breaking_to_requested = state->breaking_to_requested;
+	value->breaking_to_required = state->breaking_to_required;
+	value->lease_version = state->lease_version;
+	value->epoch = state->epoch;
+	*modified = true;
+}
+
+NTSTATUS leases_db_set(const struct GUID *client_guid,
+		       const struct smb2_lease_key *lease_key,
+		       uint32_t current_state,
+		       bool breaking,
+		       uint32_t breaking_to_requested,
+		       uint32_t	breaking_to_required,
+		       uint16_t lease_version,
+		       uint16_t epoch)
+{
+	struct leases_db_set_state state = {
+		.current_state = current_state,
+		.breaking = breaking,
+		.breaking_to_requested = breaking_to_requested,
+		.breaking_to_required = breaking_to_required,
+		.lease_version = lease_version,
+		.epoch = epoch,
+	};
+	NTSTATUS status;
+
+	status = leases_db_do_locked(
+		client_guid, lease_key, leases_db_set_fn, &state);
+	if (!NT_STATUS_IS_OK(status)) {
+		DBG_DEBUG("leases_db_do_locked failed: %s\n",
+			  nt_errstr(status));
+		return status;
+	}
+	return NT_STATUS_OK;
+}
+
+struct leases_db_get_state {
+	const struct file_id *file_id;
+	uint32_t *current_state;
+	bool *breaking;
+	uint32_t *breaking_to_requested;
+	uint32_t *breaking_to_required;
+	uint16_t *lease_version;
+	uint16_t *epoch;
+	NTSTATUS status;
+};
+
+static void leases_db_get_fn(TDB_DATA key, TDB_DATA data, void *private_data)
+{
+	struct leases_db_get_state *state = private_data;
+	DATA_BLOB blob = { .data = data.dptr, .length = data.dsize };
+	enum ndr_err_code ndr_err;
+	struct leases_db_value *value;
+	uint32_t i;
+
+	value = talloc(talloc_tos(), struct leases_db_value);
+	if (value == NULL) {
+		state->status = NT_STATUS_NO_MEMORY;
+		return;
+	}
+
+	ndr_err = ndr_pull_struct_blob_all(
+		&blob, value, value,
+		(ndr_pull_flags_fn_t)ndr_pull_leases_db_value);
+	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+		DBG_DEBUG("ndr_pull_struct_blob_failed: %s\n",
+			  ndr_errstr(ndr_err));
+		TALLOC_FREE(value);
+		state->status = ndr_map_error2ntstatus(ndr_err);
+		return;
+	}
+
+	if (DEBUGLEVEL >= 10) {
+		DBG_DEBUG("\n");
+		NDR_PRINT_DEBUG(leases_db_value, value);
+	}
+
+	/* id must exist. */
+	for (i = 0; i < value->num_files; i++) {
+		if (file_id_equal(state->file_id, &value->files[i].id)) {
+			break;
+		}
+	}
+
+	if (i == value->num_files) {
+		state->status = NT_STATUS_NOT_FOUND;
+		TALLOC_FREE(value);
+		return;
+	}
+
+	if (state->current_state != NULL) {
+		*state->current_state = value->current_state;
+	};
+	if (state->breaking != NULL) {
+		*state->breaking = value->breaking;
+	};
+	if (state->breaking_to_requested != NULL) {
+		*state->breaking_to_requested = value->breaking_to_requested;
+	};
+	if (state->breaking_to_required != NULL) {
+		*state->breaking_to_required = value->breaking_to_required;
+	};
+	if (state->lease_version != NULL) {
+		*state->lease_version = value->lease_version;
+	};
+	if (state->epoch != NULL) {
+		*state->epoch = value->epoch;
+	};
+
+	TALLOC_FREE(value);
+	state->status = NT_STATUS_OK;
+}
+
+NTSTATUS leases_db_get(const struct GUID *client_guid,
+		       const struct smb2_lease_key *lease_key,
+		       const struct file_id *file_id,
+		       uint32_t *current_state,
+		       bool *breaking,
+		       uint32_t *breaking_to_requested,
+		       uint32_t	*breaking_to_required,
+		       uint16_t *lease_version,
+		       uint16_t *epoch)
+{
+	struct leases_db_get_state state = {
+		.file_id = file_id,
+		.current_state = current_state,
+		.breaking = breaking,
+		.breaking_to_requested = breaking_to_requested,
+		.breaking_to_required = breaking_to_required,
+		.lease_version = lease_version,
+		.epoch = epoch,
+	};
+	struct leases_db_key_buf keybuf;
+	TDB_DATA db_key = leases_db_key(&keybuf, client_guid, lease_key);
+	NTSTATUS status;
+
+	if (!leases_db_init(true)) {
+		return NT_STATUS_INTERNAL_ERROR;
+	}
+
+	status = dbwrap_parse_record(
+		leases_db, db_key, leases_db_get_fn, &state);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+	return state.status;
+
+}
+
 NTSTATUS leases_db_copy_file_ids(TALLOC_CTX *mem_ctx,
 			uint32_t num_files,
 			const struct leases_db_file *files,
diff --git a/source3/locking/leases_db.h b/source3/locking/leases_db.h
index 383575a2d88..99a4a78315c 100644
--- a/source3/locking/leases_db.h
+++ b/source3/locking/leases_db.h
@@ -30,6 +30,9 @@ bool leases_db_init(bool read_only);
 NTSTATUS leases_db_add(const struct GUID *client_guid,
 		       const struct smb2_lease_key *lease_key,
 		       const struct file_id *id,
+		       uint32_t current_state,
+		       uint16_t lease_version,
+		       uint16_t epoch,
 		       const char *servicepath,
 		       const char *filename,
 		       const char *stream_name);
@@ -48,6 +51,23 @@ NTSTATUS leases_db_rename(const struct GUID *client_guid,
 			const char *servicepath_new,
 			const char *filename_new,
 			const char *stream_name_new);
+NTSTATUS leases_db_set(const struct GUID *client_guid,
+		       const struct smb2_lease_key *lease_key,
+		       uint32_t current_state,
+		       bool breaking,
+		       uint32_t breaking_to_requested,
+		       uint32_t	breaking_to_required,
+		       uint16_t lease_version,
+		       uint16_t epoch);
+NTSTATUS leases_db_get(const struct GUID *client_guid,
+		       const struct smb2_lease_key *lease_key,
+		       const struct file_id *file_id,
+		       uint32_t *current_state,
+		       bool *breaking,
+		       uint32_t *breaking_to_requested,
+		       uint32_t	*breaking_to_required,
+		       uint16_t *lease_version,
+		       uint16_t *epoch);
 NTSTATUS leases_db_copy_file_ids(TALLOC_CTX *mem_ctx,
 			uint32_t num_files,
 			const struct leases_db_file *files,
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index d4c3b32be7f..10e9606d134 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -459,6 +459,32 @@ struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
 	return get_share_mode_lock(mem_ctx, id, NULL, NULL, NULL);
 }
 
+static bool rename_lease_fn(struct share_mode_lock *lck,
+			    struct share_mode_entry *e,
+			    void *private_data)
+{
+	struct share_mode_data *d = lck->data;
+	NTSTATUS status;
+
+	status = leases_db_rename(&e->client_guid,
+				  &e->lease_key,
+				  &d->id,
+				  d->servicepath,
+				  d->base_name,
+				  d->stream_name);
+
+	if (!NT_STATUS_IS_OK(status)) {
+		/* Any error recovery possible here ? */
+		DBG_WARNING("Failed to rename lease key for "
+			    "renamed file %s:%s. %s\n",
+			    d->base_name,
+			    d->stream_name,
+			    nt_errstr(status));
+	}
+
+	return false;
+}
+
 /*******************************************************************
  Sets the service name and filename for rename.
  At this point we emit "file renamed" messages to all
@@ -484,6 +510,7 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
 	bool strip_two_chars = false;
 	bool has_stream = smb_fname_dst->stream_name != NULL;
 	struct server_id self_pid = messaging_server_id(msg_ctx);
+	bool ok;
 
 	DEBUG(10, ("rename_share_filename: servicepath %s newname %s\n",
 		   servicepath, smb_fname_dst->base_name));
@@ -576,28 +603,12 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
 				   (uint8_t *)frm, msg_len);
 	}
 
-	for (i=0; i<d->num_leases; i++) {
-		/* Update the filename in leases_db. */
-		NTSTATUS status;
-		struct share_mode_lease *l;
-
-		l = &d->leases[i];
-
-		status = leases_db_rename(&l->client_guid,
-					&l->lease_key,
-					&id,
-					d->servicepath,
-					d->base_name,
-					d->stream_name);
-		if (!NT_STATUS_IS_OK(status)) {
-			/* Any error recovery possible here ? */
-			DEBUG(1,("Failed to rename lease key for "
-				"renamed file %s:%s. %s\n",
-				d->base_name,
-				d->stream_name,
-				nt_errstr(status)));
-			continue;
-		}
+	ok = share_mode_forall_leases(lck, rename_lease_fn, NULL);
+	if (!ok) {
+		/*
+		 * Ignore error here. Not sure what to do..
+		 */
+		DBG_WARNING("share_mode_forall_leases failed\n");
 	}
 
 	return True;
@@ -660,10 +671,7 @@ bool is_valid_share_mode_entry(const struct share_mode_entry *e)
 static void remove_share_mode_lease(struct share_mode_data *d,
 				    struct share_mode_entry *e)
 {
-	struct GUID client_guid;
-	struct smb2_lease_key lease_key;
 	uint16_t op_type;
-	uint32_t lease_idx;
 	uint32_t i;
 
 	op_type = e->op_type;
@@ -680,18 +688,20 @@ static void remove_share_mode_lease(struct share_mode_data *d,
 	 * it, remove it.
 	 */
 
-	lease_idx = e->lease_idx;
-	e->lease_idx = UINT32_MAX;
-
 	for (i=0; i<d->num_share_modes; i++) {
-		if (d->share_modes[i].stale) {
+		struct share_mode_entry *e2 = &d->share_modes[i];
+
+		if (e2->stale) {
 			continue;
 		}
-		if (e == &d->share_modes[i]) {
+		if (e == e2) {
 			/* Not ourselves. */
 			continue;
 		}
-		if (d->share_modes[i].lease_idx == lease_idx) {
+		if (smb2_lease_equal(&e->client_guid,
+				     &e->lease_key,
+				     &e2->client_guid,
+				     &e2->lease_key)) {
 			break;
 		}
 	}
@@ -702,29 +712,12 @@ static void remove_share_mode_lease(struct share_mode_data *d,
 		return;
 	}
 
-	memcpy(&client_guid,
-		&d->leases[lease_idx].client_guid,
-		sizeof(client_guid));
-	lease_key = d->leases[lease_idx].lease_key;
-
-	d->num_leases -= 1;
-	d->leases[lease_idx] = d->leases[d->num_leases];
-
-	/*
-	 * We changed the lease array. Fix all references to it.
-	 */
-	for (i=0; i<d->num_share_modes; i++) {
-		if (d->share_modes[i].lease_idx == d->num_leases) {
-			d->share_modes[i].lease_idx = lease_idx;
-		}
-	}
-
 	{
 		NTSTATUS status;
 
-		status = leases_db_del(&client_guid,
-					&lease_key,
-					&d->id);


-- 
Samba Shared Repository



More information about the samba-cvs mailing list