[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Tue Oct 2 20:23:02 UTC 2018


The branch, master has been updated
       via  cff1b31 smbd: Simplify downgrade_share_lease
       via  a93aa15 smbd: Move downgrade_share_lease into downgrade_lease
       via  56139b8 smbd: Simplify downgrade_lease
       via  664808a smbd: Slightly simplify downgrade_lease()
       via  4980e60 smbd: Use find_share_mode_lease() in downgrade_share_lease
       via  0e7c546 smbd: Move downgrade_share_lease() to smbd/oplock.c
      from  6240022 tests: Check pam_winbind pw change with different options

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


- Log -----------------------------------------------------------------
commit cff1b31c2a82d7e07b7d413bed8a2843f1cd6508
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Sep 16 11:25:14 2018 +0200

    smbd: Simplify downgrade_share_lease
    
    Coalesce the NT_STATUS_OPLOCK_BREAK_IN_PROGRESS case into just one
    if-condition
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Tue Oct  2 22:22:37 CEST 2018 on sn-devel-144

commit a93aa1511fe71a7d43facb79cca7e89aed289075
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 14 16:41:25 2018 +0200

    smbd: Move downgrade_share_lease into downgrade_lease
    
    The next step will simplify the logic of the code.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 56139b8ec621d47d542042e7aa512aa07fd53fd0
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 14 16:10:58 2018 +0200

    smbd: Simplify downgrade_lease
    
    To me, the "additive" SMB2_LEASE_WRITE|SMB2_LEASE_HANDLE is easier to
    read than the negated ~SMB2_LEASE_READ.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 664808af09bf42206af2ce15c9e9b5d773ab56ca
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 14 16:03:57 2018 +0200

    smbd: Slightly simplify downgrade_lease()
    
    As much as I dislike }else{ and prefer early returns, I even more
    dislike asking for the same condition in two different ways.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 4980e60dfc5b9e6b96ea8c8de4d2e911c9c2f011
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 14 13:30:43 2018 +0200

    smbd: Use find_share_mode_lease() in downgrade_share_lease
    
    Simple simplification: In locking/ we did not have the direct
    reference to find_share_mode_lock.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 0e7c5464631cee3a7eda0d03a941b5179981019c
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 14 13:18:50 2018 +0200

    smbd: Move downgrade_share_lease() to smbd/oplock.c
    
    This function is pretty closely entangled with its only caller. In
    particular the NT_STATUS_OPLOCK_BREAK_IN_PROGRESS triggers acitivity
    in the caller, and that's the only case where "*_l" is being set to
    non-NULL. Prepare for cleanup
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

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

Summary of changes:
 source3/locking/locking.c | 85 ----------------------------------------------
 source3/locking/proto.h   |  6 ----
 source3/smbd/oplock.c     | 86 ++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 78 insertions(+), 99 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 8ee9237..ae5f0bb 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -969,91 +969,6 @@ bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp)
 	return True;
 }
 
-NTSTATUS downgrade_share_lease(struct smbd_server_connection *sconn,
-			       struct share_mode_lock *lck,
-			       const struct smb2_lease_key *key,
-			       uint32_t new_lease_state,
-			       struct share_mode_lease **_l)
-{
-	struct share_mode_data *d = lck->data;
-	struct share_mode_lease *l;
-	uint32_t i;
-
-	*_l = NULL;
-
-	for (i=0; i<d->num_leases; i++) {
-		if (smb2_lease_equal(&sconn->client->connections->smb2.client.guid,
-				     key,
-				     &d->leases[i].client_guid,
-				     &d->leases[i].lease_key)) {
-			break;
-		}
-	}
-	if (i == d->num_leases) {
-		DEBUG(10, ("lease not found\n"));
-		return NT_STATUS_INVALID_PARAMETER;
-	}
-
-	l = &d->leases[i];
-
-	if (!l->breaking) {
-		DBG_WARNING("Attempt to break from %"PRIu32" to %"PRIu32" - "
-			    "but we're not in breaking state\n",
-			    l->current_state, new_lease_state);
-		return NT_STATUS_UNSUCCESSFUL;
-	}
-
-	/*
-	 * Can't upgrade anything: l->breaking_to_requested (and l->current_state)
-	 * must be a strict bitwise superset of new_lease_state
-	 */
-	if ((new_lease_state & l->breaking_to_requested) != new_lease_state) {
-		DBG_WARNING("Attempt to upgrade from %"PRIu32" to %"PRIu32" "
-			    "- expected %"PRIu32"\n",
-			    l->current_state, new_lease_state,
-			    l->breaking_to_requested);
-		return NT_STATUS_REQUEST_NOT_ACCEPTED;
-	}
-
-	if (l->current_state != new_lease_state) {
-		l->current_state = new_lease_state;
-		d->modified = true;
-	}
-
-	if ((new_lease_state & ~l->breaking_to_required) != 0) {
-		DBG_INFO("lease state %"PRIu32" not fully broken from "
-			 "%"PRIu32" to %"PRIu32"\n",
-			 new_lease_state,
-			 l->current_state,
-			 l->breaking_to_required);
-		l->breaking_to_requested = l->breaking_to_required;
-		if (l->current_state & (~SMB2_LEASE_READ)) {
-			/*
-			 * Here we break in steps, as windows does
-			 * see the breaking3 and v2_breaking3 tests.
-			 */
-			l->breaking_to_requested |= SMB2_LEASE_READ;
-		}
-		d->modified = true;
-		*_l = l;
-		return NT_STATUS_OPLOCK_BREAK_IN_PROGRESS;
-	}
-
-	DBG_DEBUG("breaking from %"PRIu32" to %"PRIu32" - "
-		  "expected %"PRIu32"\n",
-		  l->current_state,
-		  new_lease_state,
-		  l->breaking_to_requested);
-
-	l->breaking_to_requested = 0;
-	l->breaking_to_required = 0;
-	l->breaking = false;
-
-	d->modified = true;
-
-	return NT_STATUS_OK;
-}
-
 /****************************************************************************
  Adds a delete on close token.
 ****************************************************************************/
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index b615a4a..22b7966 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -184,12 +184,6 @@ bool mark_share_mode_disconnected(struct share_mode_lock *lck,
 				  struct files_struct *fsp);
 bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
 bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp);
-struct share_mode_lease;
-NTSTATUS downgrade_share_lease(struct smbd_server_connection *sconn,
-			       struct share_mode_lock *lck,
-			       const struct smb2_lease_key *key,
-			       uint32_t new_lease_state,
-			       struct share_mode_lease **_l);
 bool get_delete_on_close_token(struct share_mode_lock *lck,
 				uint32_t name_hash,
 				const struct security_token **pp_nt_tok,
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 827dbeb..a7ac846 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -525,8 +525,10 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
 {
 	struct smbd_server_connection *sconn = xconn->client->sconn;
 	struct share_mode_lock *lck;
+	struct share_mode_data *d = NULL;
 	struct share_mode_lease *l = NULL;
 	const struct file_id id = ids[0];
+	int idx;
 	uint32_t i;
 	NTSTATUS status;
 
@@ -537,14 +539,65 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
 	if (lck == NULL) {
 		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 	}
-	status = downgrade_share_lease(sconn, lck, key, lease_state, &l);
+	d = lck->data;
 
-	DEBUG(10, ("%s: Downgrading %s to %x => %s\n", __func__,
-		   file_id_string_tos(&id), (unsigned)lease_state, nt_errstr(status)));
+	idx = find_share_mode_lease(
+		d, &sconn->client->connections->smb2.client.guid, key);
+	if (idx == -1) {
+		DEBUG(10, ("lease not found\n"));
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+	l = &d->leases[idx];
+
+	if (!l->breaking) {
+		DBG_WARNING("Attempt to break from %"PRIu32" to %"PRIu32" - "
+			    "but we're not in breaking state\n",
+			    l->current_state, lease_state);
+		TALLOC_FREE(lck);
+		return NT_STATUS_UNSUCCESSFUL;
+	}
+
+	/*
+	 * Can't upgrade anything: l->breaking_to_requested (and l->current_state)
+	 * must be a strict bitwise superset of new_lease_state
+	 */
+	if ((lease_state & l->breaking_to_requested) != lease_state) {
+		DBG_WARNING("Attempt to upgrade from %"PRIu32" to %"PRIu32" "
+			    "- expected %"PRIu32"\n",
+			    l->current_state, lease_state,
+			    l->breaking_to_requested);
+		TALLOC_FREE(lck);
+		return NT_STATUS_REQUEST_NOT_ACCEPTED;
+	}
+
+	if (l->current_state != lease_state) {
+		l->current_state = lease_state;
+		d->modified = true;
+	}
 
-	if (NT_STATUS_EQUAL(status, NT_STATUS_OPLOCK_BREAK_IN_PROGRESS)) {
+	status = NT_STATUS_OK;
+
+	d->modified = true;
+
+	if ((lease_state & ~l->breaking_to_required) != 0) {
 		struct downgrade_lease_additional_state *state;
 
+		DBG_INFO("lease state %"PRIu32" not fully broken from "
+			 "%"PRIu32" to %"PRIu32"\n",
+			 lease_state,
+			 l->current_state,
+			 l->breaking_to_required);
+
+		l->breaking_to_requested = l->breaking_to_required;
+
+		if (l->current_state & (SMB2_LEASE_WRITE|SMB2_LEASE_HANDLE)) {
+			/*
+			 * Here we break in steps, as windows does
+			 * see the breaking3 and v2_breaking3 tests.
+			 */
+			l->breaking_to_requested |= SMB2_LEASE_READ;
+		}
+
 		state = talloc_zero(xconn,
 				    struct downgrade_lease_additional_state);
 		if (state == NULL) {
@@ -560,9 +613,6 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
 		}
 
 		state->xconn = xconn;
-		if (l->current_state & (~SMB2_LEASE_READ)) {
-			state->break_flags = SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED;
-		}
 		state->lease_key = l->lease_key;
 		state->break_from = l->current_state;
 		state->break_to = l->breaking_to_requested;
@@ -570,7 +620,10 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
 			state->new_epoch = l->epoch;
 		}
 
-		if (state->break_flags == 0) {
+		if (l->current_state & (SMB2_LEASE_WRITE|SMB2_LEASE_HANDLE)) {
+			state->break_flags =
+				SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED;
+		} else {
 			/*
 			 * This is an async break without
 			 * SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED
@@ -590,8 +643,25 @@ NTSTATUS downgrade_lease(struct smbXsrv_connection *xconn,
 					  xconn->client->raw_ev_ctx,
 					  downgrade_lease_additional_trigger,
 					  state);
+
+		status = NT_STATUS_OPLOCK_BREAK_IN_PROGRESS;
+	} else {
+		DBG_DEBUG("breaking from %"PRIu32" to %"PRIu32" - "
+			  "expected %"PRIu32"\n",
+			  l->current_state,
+			  lease_state,
+			  l->breaking_to_requested);
+
+		l->breaking_to_requested = 0;
+		l->breaking_to_required = 0;
+		l->breaking = false;
+
+		d->modified = true;
 	}
 
+	DEBUG(10, ("%s: Downgrading %s to %x => %s\n", __func__,
+		   file_id_string_tos(&id), (unsigned)lease_state, nt_errstr(status)));
+
 	{
 		struct downgrade_lease_fsps_state state = {
 			.id = id, .lck = lck, .key = key,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list