Latest leases patchset - getting there !

Jeremy Allison jra at samba.org
Wed Nov 12 11:58:46 MST 2014


On Tue, Nov 11, 2014 at 04:37:46PM -0800, Jeremy Allison wrote:
> 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.

Slightly updated version of this patchset.
Only the middle (second) patch is changed.

Changes from metze-wip-15.patchset were:

1). Inside find_fsp_lease(), when allocating
a new smb2_lease struct, always set the
lease_version field to 2, as we are always
updating the epoch. Correct version will
be set when marshalling the lease reply.

2). Removed the change to smb2_create.c.
Existing marshalling code in smb2_lease_push()
already does the correct versioning based
on length.

Please squash into existing patchset !

Cheers,

	Jeremy.
-------------- next part --------------
From cbd55f683c1867a2d612b4f44fa29f5c65bb7e18 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 9aa8fcc7bf235725227e460e14a74319c1d7fa06 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, smb2_lease_push() will zero out the epoch on v1 reply.

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

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index f9effe3..d8794a9 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1593,6 +1593,8 @@ struct fsp_lease *find_fsp_lease(files_struct *new_fsp,
 	new_fsp->lease->ref_count = 1;
 	new_fsp->lease->lease.lease_key = *key;
 	new_fsp->lease->lease.lease_state = o->current_state;
+	/* Internally treat all leases as version 2 with epoch. */
+	new_fsp->lease->lease.lease_version = 2;
 	new_fsp->lease->lease.lease_epoch = o->epoch;
 	return new_fsp->lease;
 }
@@ -1673,9 +1675,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 +4311,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);
-- 
2.1.0.rc2.206.gedb03e5


From b23cd065d828e7484f4a8f9e9764bc86cbb50d66 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 d8794a9..3fa41f3 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1649,6 +1649,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