Some trivial patches

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Sep 6 10:27:41 CEST 2013


Hi!

Some trivial patches from staring at oplock and related
code.

Please review&push.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de

*****************************************************************
visit us on it-sa:IT security exhibitions in Nürnberg, Germany
October 8th - 10th 2013, hall 12, booth 333
free tickets available via code 270691 on: www.it-sa.de/gutschein
******************************************************************
-------------- next part --------------
From d69f079598f3d4cb73c97e9e8c5a7a0c6ee9354f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 14:38:47 +0000
Subject: [PATCH 01/12] smbd: Simplify find_share_mode_entry

There's no point checking the validity of the "entry" argument more
than once

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/locking/locking.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 5090082..1567f8f 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -751,10 +751,13 @@ static struct share_mode_entry *find_share_mode_entry(struct share_mode_data *d,
 {
 	int i;
 
+	if (!is_valid_share_mode_entry(entry)) {
+		return NULL;
+	}
+
 	for (i=0; i<d->num_share_modes; i++) {
 		struct share_mode_entry *e = &d->share_modes[i];
-		if (is_valid_share_mode_entry(entry) &&
-		    is_valid_share_mode_entry(e) &&
+		if (is_valid_share_mode_entry(e) &&
 		    share_modes_identical(e, entry)) {
 			return e;
 		}
-- 
1.8.1.2


From f98675b862111121e12b4899880f08b75178cd5d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 14:40:35 +0000
Subject: [PATCH 02/12] smbd: Apply some const to share_modes_identical

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/locking/locking.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 1567f8f..5343ba4 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -733,8 +733,8 @@ void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
  not automatically a logic error if they are identical. JRA.)
 ********************************************************************/
 
-static bool share_modes_identical(struct share_mode_entry *e1,
-				  struct share_mode_entry *e2)
+static bool share_modes_identical(const struct share_mode_entry *e1,
+				  const struct share_mode_entry *e2)
 {
 	/* We used to check for e1->share_access == e2->share_access here
 	   as well as the other fields but 2 different DOS or FCB opens
-- 
1.8.1.2


From fdcf7d59d9fdebbc6197cf763ca0f9d221e4c6b8 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 14:40:58 +0000
Subject: [PATCH 03/12] smbd: Apply some const to find_share_mode_entry

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/locking/locking.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 5343ba4..ad56cb1 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -746,8 +746,8 @@ static bool share_modes_identical(const struct share_mode_entry *e1,
 		e1->share_file_id == e2->share_file_id );
 }
 
-static struct share_mode_entry *find_share_mode_entry(struct share_mode_data *d,
-						      struct share_mode_entry *entry)
+static struct share_mode_entry *find_share_mode_entry(
+	struct share_mode_data *d, const struct share_mode_entry *entry)
 {
 	int i;
 
-- 
1.8.1.2


From b11039bda4586437877a8c0d511aa3d02c98c29e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 14:44:45 +0000
Subject: [PATCH 04/12] smbd: Remove unused should_notify_deferred_opens

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/oplock.c | 10 ----------
 source3/smbd/proto.h  |  1 -
 2 files changed, 11 deletions(-)

diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 4cdf68b..ba8298f 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -211,16 +211,6 @@ bool downgrade_oplock(files_struct *fsp)
 	return ret;
 }
 
-/*
- * Some kernel oplock implementations handle the notification themselves.
- */
-bool should_notify_deferred_opens(struct smbd_server_connection *sconn)
-{
-	struct kernel_oplocks *koplocks = sconn->oplocks.kernel_ops;
-	return !(koplocks &&
-		(koplocks->flags & KOPLOCKS_DEFERRED_OPEN_NOTIFICATION));
-}
-
 /****************************************************************************
  Set up an oplock break message.
 ****************************************************************************/
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index f572c35..d9b9d4d 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -663,7 +663,6 @@ NTSTATUS set_file_oplock(files_struct *fsp, int oplock_type);
 void release_file_oplock(files_struct *fsp);
 bool remove_oplock(files_struct *fsp);
 bool downgrade_oplock(files_struct *fsp);
-bool should_notify_deferred_opens(struct smbd_server_connection *sconn);
 void contend_level2_oplocks_begin(files_struct *fsp,
 				  enum level2_contention_type type);
 void contend_level2_oplocks_end(files_struct *fsp,
-- 
1.8.1.2


From 851daa1440dccf115ec6de3f8f2b78ad5b24abbb Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 09:23:39 +0000
Subject: [PATCH 05/12] smbd: Remove two confusing TALLOC_FREE calls

We don't have lck allocated yet at these points. Remove the TALLOC_FREE
calls that triggered me looking for the get_share_mode_lock calls.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/open.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index f4210d7..fc6a94c 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2337,7 +2337,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		if (NT_STATUS_EQUAL(fsp_open, NT_STATUS_RETRY)) {
 			schedule_async_open(request_time, req);
 		}
-		TALLOC_FREE(lck);
 		return fsp_open;
 	}
 
@@ -2351,7 +2350,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		 * just fail the open to prevent creating any problems
 		 * in the open file db having the wrong dev/ino key.
 		 */
-		TALLOC_FREE(lck);
 		fd_close(fsp);
 		DEBUG(1,("open_file_ntcreate: file %s - dev/ino mismatch. "
 			"Old (dev=0x%llu, ino =0x%llu). "
-- 
1.8.1.2


From 6d8d944a83a2306190d60e7b7b1f75684f066dd6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 29 Aug 2013 14:53:01 +0000
Subject: [PATCH 06/12] smbd: Fix a const warning

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/trans2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index e6bb12c..e02d646 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -3078,7 +3078,7 @@ NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
 	const char *vname = volume_label(talloc_tos(), SNUM(conn));
 	int snum = SNUM(conn);
 	char *fstype = lp_fstype(talloc_tos(), SNUM(conn));
-	char *filename = NULL;
+	const char *filename = NULL;
 	uint32 additional_flags = 0;
 	struct smb_filename smb_fname;
 	SMB_STRUCT_STAT st;
-- 
1.8.1.2


From be514d8620edad4342579c1c3415e42a0bdfe606 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 11:51:48 +0000
Subject: [PATCH 07/12] lib: Apply some const to pull_file_id_24

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/file_id.c | 2 +-
 source3/lib/file_id.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/lib/file_id.c b/source3/lib/file_id.c
index ba4b3a3..f8295ce 100644
--- a/source3/lib/file_id.c
+++ b/source3/lib/file_id.c
@@ -80,7 +80,7 @@ void push_file_id_24(char *buf, const struct file_id *id)
 /*
   pull a 24 byte version of a file id from a buffer
  */
-void pull_file_id_24(char *buf, struct file_id *id)
+void pull_file_id_24(const char *buf, struct file_id *id)
 {
 	ZERO_STRUCTP(id);
 	id->devid  = IVAL(buf,  0);
diff --git a/source3/lib/file_id.h b/source3/lib/file_id.h
index 2ca8390..6fa9840 100644
--- a/source3/lib/file_id.h
+++ b/source3/lib/file_id.h
@@ -34,4 +34,4 @@ const char *file_id_string_tos(const struct file_id *id);
 const char *file_id_string(TALLOC_CTX *mem_ctx, const struct file_id *id);
 void push_file_id_16(char *buf, const struct file_id *id);
 void push_file_id_24(char *buf, const struct file_id *id);
-void pull_file_id_24(char *buf, struct file_id *id);
+void pull_file_id_24(const char *buf, struct file_id *id);
-- 
1.8.1.2


From 2693c9a17acd67788cabb9249c2cad4ea9115514 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 11:55:27 +0000
Subject: [PATCH 08/12] smbd: Apply some const to message_to_share_mode_entry

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/oplock.c | 2 +-
 source3/smbd/proto.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index ba8298f..11e302a 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -819,7 +819,7 @@ void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
  De-linearize an internal oplock break message to a share mode entry struct.
 ****************************************************************************/
 
-void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
+void message_to_share_mode_entry(struct share_mode_entry *e, const char *msg)
 {
 	e->pid.pid = (pid_t)IVAL(msg,OP_BREAK_MSG_PID_OFFSET);
 	e->op_mid = BVAL(msg,OP_BREAK_MSG_MID_OFFSET);
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index d9b9d4d..8b6987e 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -672,7 +672,7 @@ void smbd_contend_level2_oplocks_begin(files_struct *fsp,
 void smbd_contend_level2_oplocks_end(files_struct *fsp,
 				enum level2_contention_type type);
 void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e);
-void message_to_share_mode_entry(struct share_mode_entry *e, char *msg);
+void message_to_share_mode_entry(struct share_mode_entry *e, const char *msg);
 bool init_oplocks(struct smbd_server_connection *sconn);
 void init_kernel_oplocks(struct smbd_server_connection *sconn);
 
-- 
1.8.1.2


From b3c38115d2ad8cbc729b64fb375696277130697b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 2 Sep 2013 09:40:46 +0000
Subject: [PATCH 09/12] smbd: Remove a silly "? true : false"

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/open.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index fc6a94c..6ced3c2 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1355,7 +1355,7 @@ static bool file_has_brlocks(files_struct *fsp)
 	if (!br_lck)
 		return false;
 
-	return br_lck->num_locks > 0 ? true : false;
+	return (br_lck->num_locks > 0);
 }
 
 static void grant_fsp_oplock_type(files_struct *fsp,
-- 
1.8.1.2


From 475ab414216a92be7be03a54a7a832422ee556c7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 2 Sep 2013 09:06:13 +0000
Subject: [PATCH 10/12] smbd: Slightly simplify send_break_message

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/open.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 6ced3c2..e5ea715 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1186,8 +1186,7 @@ static NTSTATUS send_break_message(files_struct *fsp,
 
 	status = messaging_send_buf(fsp->conn->sconn->msg_ctx, exclusive->pid,
 				    MSG_SMB_BREAK_REQUEST,
-				    (uint8 *)msg,
-				    MSG_SMB_SHARE_MODE_ENTRY_SIZE);
+				    (uint8 *)msg, sizeof(msg));
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(3, ("Could not send oplock break message: %s\n",
 			  nt_errstr(status)));
-- 
1.8.1.2


From 8b63ad7ffb27529778a26a74de0db4a50c49bfc7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 2 Sep 2013 09:08:04 +0000
Subject: [PATCH 11/12] smbd: Slightly simplify do_break_to_none

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/oplock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 11e302a..96c451c 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -753,8 +753,7 @@ static void do_break_to_none(struct tevent_context *ctx,
 			messaging_send_buf(state->sconn->msg_ctx,
 					share_entry->pid,
 					MSG_SMB_ASYNC_LEVEL2_BREAK,
-					(uint8 *)msg,
-					MSG_SMB_SHARE_MODE_ENTRY_SIZE);
+					(uint8 *)msg, sizeof(msg));
 		}
 	}
 
-- 
1.8.1.2


From 7db1518b8a7e26b944b83271174d91a7e119f256 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 2 Sep 2013 09:09:16 +0000
Subject: [PATCH 12/12] smbd: Slightly simplify enum_file_close_fn

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
index 1af350a..8f3a4cf 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -2480,8 +2480,7 @@ static void enum_file_close_fn( const struct share_mode_entry *e,
 	state->r->out.result = ntstatus_to_werror(
 		messaging_send_buf(state->msg_ctx,
 				e->pid, MSG_SMB_CLOSE_FILE,
-				(uint8 *)msg,
-				MSG_SMB_SHARE_MODE_ENTRY_SIZE));
+				(uint8 *)msg, sizeof(msg)));
 }
 
 /********************************************************************
-- 
1.8.1.2



More information about the samba-technical mailing list