Latest leases patchset - getting there !

Jeremy Allison jra at samba.org
Tue Nov 11 17:37:46 MST 2014


On Tue, Nov 11, 2014 at 03:12:16PM -0800, Jeremy Allison wrote:
> On Tue, Nov 11, 2014 at 10:41:38PM +0100, Stefan (metze) Metzmacher wrote:
> > Am 11.11.2014 um 21:36 schrieb Jeremy Allison:
> > > On Tue, Nov 11, 2014 at 12:30:31PM -0800, Jeremy Allison wrote:
> > >> Also the change for "level2 oplocks = no" must be documented
> > >> in the new "smb2 leases" section in the manpage. Here is a
> > >> new version of that patch (attached).
> > > 
> > > Bah, forgot to add the "related" in the level2oplocks man
> > > page. Updated version attached !
> > 
> > Thanks, I'll integrate this tomorrow.
> > 
> > here's ontop13.diff.txt with some more fixes
> > and new tests which demonstrate a problem
> > of outdated fsp->lease information if a lease is shared
> > between two smbd processes.
> 
> Here is a patch on top of ontop13.diff.txt which
> fixes us for smb2.lease.complex1.

OK, here's a patchset that includes this previous
patch and fixes both issues. It should apply
cleanly on top of ontop13.diff.txt.

The realization was that we need to internally
treat all leases as v2, and update the epoch
correctly no matter whether the client was
using v1 or v2 lease requests.

If the client requested a v1 lease just null
out the epoch value before marshalling and
sending back in the create reply.

Please review and maybe squash these into
the existing leases patch.

Cheers,

	Jeremy.
-------------- next part --------------
From 8a0fae8d913239b99fcc8403c53b393b4d3e7997 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 11 Nov 2014 15:10:56 -0800
Subject: [PATCH 1/3] s3: leases : If we are requested to send a break message
 from another smbd, ensure we're in sync with the current lease state.

If a lease is shared between two smbd processes the state can get out of sync.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/oplock.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index e97ade6..d28914c 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -598,9 +598,7 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
 		return;
 	}
 
-	if ((fsp->oplock_type == LEASE_OPLOCK) &&
-	    (fsp->lease->lease.lease_version != 1)) {
-		/* Need to increment the epoch */
+	if (fsp->oplock_type == LEASE_OPLOCK) {
 		struct share_mode_lock *lck;
 		int idx;
 
@@ -615,8 +613,13 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
 		if (idx != -1) {
 			struct share_mode_oplock *o;
 			o = &lck->data->leases[idx];
-			o->epoch += 1;
-			fsp->lease->lease.lease_epoch = o->epoch;
+			/* Ensure we're in sync with current lease state. */
+			fsp->lease->lease.lease_state = o->current_state;
+			if (fsp->lease->lease.lease_version != 1) {
+				/* Need to increment the epoch */
+				o->epoch += 1;
+				fsp->lease->lease.lease_epoch = o->epoch;
+			}
 		}
 
 		TALLOC_FREE(lck);
-- 
2.1.0.rc2.206.gedb03e5


From c7f326a96e4cda4f0b85e62137d996b443784f96 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 11 Nov 2014 16:29:40 -0800
Subject: [PATCH 2/3] s3: leases: I just had an epiphany. As we need to keep
 lease state in sync, *always* increment epoch on changes.

Internally treat all leases as v2, just zero out the epoch on v1 reply.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/open.c        | 8 ++------
 source3/smbd/oplock.c      | 8 +++-----
 source3/smbd/smb2_create.c | 5 +++++
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index f9effe3..6111900 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1673,9 +1673,7 @@ static NTSTATUS grant_fsp_lease(files_struct *fsp, struct share_mode_data *d,
 	fsp->lease->ref_count = 1;
 	fsp->lease->lease = *lease;
 	fsp->lease->lease.lease_state = granted;
-	if (fsp->lease->lease.lease_version > 1) {
-		fsp->lease->lease.lease_epoch += 1;
-	}
+	fsp->lease->lease.lease_epoch += 1;
 
 	*p_lease_idx = d->num_leases;
 
@@ -4311,9 +4309,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
 		if (NT_STATUS_EQUAL(status, NT_STATUS_OPLOCK_NOT_GRANTED)) {
 			/* Dynamic share file. No leases and update epoch... */
 			lease->lease_state = SMB2_LEASE_NONE;
-			if (lease->lease_version > 1) {
-				lease->lease_epoch += 1;
-			}
+			lease->lease_epoch += 1;
 		} else if (!NT_STATUS_IS_OK(status)) {
 			goto fail;
 		}
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index d28914c..5523de9 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -615,11 +615,9 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
 			o = &lck->data->leases[idx];
 			/* Ensure we're in sync with current lease state. */
 			fsp->lease->lease.lease_state = o->current_state;
-			if (fsp->lease->lease.lease_version != 1) {
-				/* Need to increment the epoch */
-				o->epoch += 1;
-				fsp->lease->lease.lease_epoch = o->epoch;
-			}
+			/* Need to increment the epoch */
+			o->epoch += 1;
+			fsp->lease->lease.lease_epoch = o->epoch;
 		}
 
 		TALLOC_FREE(lck);
diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c
index 0c49c70..83078a5 100644
--- a/source3/smbd/smb2_create.c
+++ b/source3/smbd/smb2_create.c
@@ -1213,6 +1213,11 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
 			lease.lease_flags &=
 				SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET;
 
+			if (lease.lease_version == 1) {
+				/* Ignore epoch. */
+				lease.lease_epoch = 0;
+			}
+
 			if (!smb2_lease_push(&lease, buf, lease_len)) {
 				tevent_req_nterror(
 					req, NT_STATUS_INTERNAL_ERROR);
-- 
2.1.0.rc2.206.gedb03e5


From 3dde7bf866ce0aedf19033e328a02bde5b9bba39 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 11 Nov 2014 16:31:37 -0800
Subject: [PATCH 3/3] s3: leases: Remember to update epoch on lease update
 (e.g. from RH -> RWH).

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/open.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 6111900..513202c 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1647,6 +1647,8 @@ static NTSTATUS grant_fsp_lease(files_struct *fsp, struct share_mode_data *d,
 
 		if (do_upgrade) {
 			o->current_state = granted;
+			o->epoch += 1;
+			fsp->lease->lease.lease_epoch = o->epoch;
 		}
 		fsp->lease->lease.lease_state = o->current_state;
 		return NT_STATUS_OK;
-- 
2.1.0.rc2.206.gedb03e5



More information about the samba-technical mailing list