a few cleanup patches

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Oct 24 03:41:25 MDT 2013


Hi!

Attached find a few smaller cleanup patches in the oplock
area. No real functional change around, just rearranging
code and parameters.

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
-------------- next part --------------
From 0f556f0e26d7d31a0ff8eabb2fb49331a2c13c2a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 13 Sep 2013 13:49:20 +0200
Subject: [PATCH 1/6] smbd: Use remove_oplock() in close_normal_file

remove_oplock is a wrapper around release_file_oplock. This streamlines
the exports of oplock.c a bit.

Reason for this patch: In a later patch I will add functionality to
remove_oplock that is required in close_normal_file as well.

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

diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index f341c72..6153066 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -735,7 +735,7 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
 
 	/* Remove the oplock before potentially deleting the file. */
 	if(fsp->oplock_type) {
-		release_file_oplock(fsp);
+		remove_oplock(fsp);
 	}
 
 	/* If this is an old DOS or FCB open and we have multiple opens on
-- 
1.7.9.5


From f45adde7dc93cb199b62591543d149f23fc532c7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 13 Sep 2013 13:55:05 +0200
Subject: [PATCH 2/6] smbd: Make release_file_oplock static

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

diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index d30aa4b..36a4b5b 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -93,7 +93,7 @@ NTSTATUS set_file_oplock(files_struct *fsp, int oplock_type)
  Attempt to release an oplock on a file. Decrements oplock count.
 ****************************************************************************/
 
-void release_file_oplock(files_struct *fsp)
+static void release_file_oplock(files_struct *fsp)
 {
 	struct smbd_server_connection *sconn = fsp->conn->sconn;
 	struct kernel_oplocks *koplocks = sconn->oplocks.kernel_ops;
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 54d6da0..bead710 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -660,7 +660,6 @@ NTSTATUS get_relative_fid_filename(connection_struct *conn,
 
 void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp);
 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);
 void contend_level2_oplocks_begin(files_struct *fsp,
-- 
1.7.9.5


From cd7b738c7bc092ca46d1e0d7303053f861233fd3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 13:27:49 +0000
Subject: [PATCH 3/6] smbd: Unify parameters to set_oplock_type

Some lines above we set fsp->oplock_type = e->op_type. I don't see
how this might have changed. This change will unify both callers of
set_file_oplock. In the next step the second parameter to set_file_oplock
will be removed.

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

diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c
index 9b05d48..15d7005 100644
--- a/source3/smbd/durable.c
+++ b/source3/smbd/durable.c
@@ -864,7 +864,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
 		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 	}
 
-	status = set_file_oplock(fsp, e->op_type);
+	status = set_file_oplock(fsp, fsp->oplock_type);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(1, ("vfs_default_durable_reconnect failed to set oplock "
 			  "after opening file: %s\n", nt_errstr(status)));
-- 
1.7.9.5


From 86b7b4311e28adedd9c5bc1464210d4357930a89 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 13:57:11 +0000
Subject: [PATCH 4/6] smbd: Remove separate oplock_type parameter from
 set_file_oplock

This avoids the question where it could happen that something else but
fsp->oplock_type might be useful as an argument here.

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

diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c
index 15d7005..c5281a8 100644
--- a/source3/smbd/durable.c
+++ b/source3/smbd/durable.c
@@ -864,7 +864,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
 		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 	}
 
-	status = set_file_oplock(fsp, fsp->oplock_type);
+	status = set_file_oplock(fsp);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(1, ("vfs_default_durable_reconnect failed to set oplock "
 			  "after opening file: %s\n", nt_errstr(status)));
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index c33a4cf..4db673a 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2703,7 +2703,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	 * file structs.
 	 */
 
-	status = set_file_oplock(fsp, fsp->oplock_type);
+	status = set_file_oplock(fsp);
 	if (!NT_STATUS_IS_OK(status)) {
 		/*
 		 * Could not get the kernel oplock
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 36a4b5b..b5d6b54 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -50,7 +50,7 @@ void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp)
  disabled (just sets flags).
 ****************************************************************************/
 
-NTSTATUS set_file_oplock(files_struct *fsp, int oplock_type)
+NTSTATUS set_file_oplock(files_struct *fsp)
 {
 	struct smbd_server_connection *sconn = fsp->conn->sconn;
 	struct kernel_oplocks *koplocks = sconn->oplocks.kernel_ops;
@@ -67,14 +67,13 @@ NTSTATUS set_file_oplock(files_struct *fsp, int oplock_type)
 
 	if ((fsp->oplock_type != NO_OPLOCK) &&
 	    use_kernel &&
-	    !koplocks->ops->set_oplock(koplocks, fsp, oplock_type))
+	    !koplocks->ops->set_oplock(koplocks, fsp, fsp->oplock_type))
 	{
 		return map_nt_error_from_unix(errno);
 	}
 
-	fsp->oplock_type = oplock_type;
 	fsp->sent_oplock_break = NO_BREAK_SENT;
-	if (oplock_type == LEVEL_II_OPLOCK) {
+	if (fsp->oplock_type == LEVEL_II_OPLOCK) {
 		sconn->oplocks.level_II_open++;
 	} else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
 		sconn->oplocks.exclusive_open++;
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index bead710..d365545 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -659,7 +659,7 @@ NTSTATUS get_relative_fid_filename(connection_struct *conn,
 /* The following definitions come from smbd/oplock.c  */
 
 void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp);
-NTSTATUS set_file_oplock(files_struct *fsp, int oplock_type);
+NTSTATUS set_file_oplock(files_struct *fsp);
 bool remove_oplock(files_struct *fsp);
 bool downgrade_oplock(files_struct *fsp);
 void contend_level2_oplocks_begin(files_struct *fsp,
-- 
1.7.9.5


From badab2c2bba00ebd8f6df8ff5859f87d5bb044ef Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 3 Sep 2013 14:02:09 +0000
Subject: [PATCH 5/6] smbd: Move oplock/sharemode ops into one place

This makes the is_stat_open special case in grant_fsp_oplock_type
redundant because in open_file_ntcreate further up we have already set
oplock_request to NO_OPLOCK for stat opens.

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

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 4db673a..28c2c1c 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1435,13 +1435,6 @@ static void grant_fsp_oplock_type(files_struct *fsp,
 		fsp->oplock_type = NO_OPLOCK;
 	}
 
-	if (is_stat_open(fsp->access_mask)) {
-		/* Leave the value already set. */
-		DEBUG(10,("grant_fsp_oplock_type: oplock type 0x%x on file %s\n",
-			fsp->oplock_type, fsp_str_dbg(fsp)));
-		return;
-	}
-
 	got_level2_oplock = false;
 	got_a_none_oplock = false;
 
@@ -2617,8 +2610,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		return status;
 	}
 
-	grant_fsp_oplock_type(fsp, lck, oplock_request);
-
 	/*
 	 * We have the share entry *locked*.....
 	 */
@@ -2680,7 +2671,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	if (file_existed) {
 		/* stat opens on existing files don't get oplocks. */
 		if (is_stat_open(open_access_mask)) {
-			fsp->oplock_type = NO_OPLOCK;
+			oplock_request = NO_OPLOCK;
 		}
 	}
 
@@ -2703,6 +2694,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	 * file structs.
 	 */
 
+	grant_fsp_oplock_type(fsp, lck, oplock_request);
+
 	status = set_file_oplock(fsp);
 	if (!NT_STATUS_IS_OK(status)) {
 		/*
-- 
1.7.9.5


From b4d179e1d94dbce0153882c1287c110c63bf947c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 26 Sep 2013 14:18:28 -0700
Subject: [PATCH 6/6] smbd: Move oplock handling together

Later on we will have all the oplock/sharemode operations in one routine.

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

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 28c2c1c..8ae2246 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2668,13 +2668,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
 	}
 
-	if (file_existed) {
-		/* stat opens on existing files don't get oplocks. */
-		if (is_stat_open(open_access_mask)) {
-			oplock_request = NO_OPLOCK;
-		}
-	}
-
 	if (new_file_created) {
 		info = FILE_WAS_CREATED;
 	} else {
@@ -2694,6 +2687,13 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	 * file structs.
 	 */
 
+	if (file_existed) {
+		/* stat opens on existing files don't get oplocks. */
+		if (is_stat_open(open_access_mask)) {
+			oplock_request = NO_OPLOCK;
+		}
+	}
+
 	grant_fsp_oplock_type(fsp, lck, oplock_request);
 
 	status = set_file_oplock(fsp);
-- 
1.7.9.5



More information about the samba-technical mailing list