PATCH: Simplify share_mode_data a bit

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Mar 21 07:29:32 MDT 2014


Hi!

Attached find a patchset that removes the file_id from the
share_mode_data. locking.tdb is indexed by the file_id, so
it seems superfluous to have it in the data portion as well.

Review would be appreciated!

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 09b4b3daeb559bd9de80fdc162c4c0e42aae0a62 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Mar 2014 14:36:11 +0100
Subject: [PATCH 1/7] smbd: Explicitly pass "file_id" to rename_open_files

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

diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index b189d66..a66aa5a 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -6101,6 +6101,7 @@ static bool resolve_wildcards(TALLOC_CTX *ctx,
 
 static void rename_open_files(connection_struct *conn,
 			      struct share_mode_lock *lck,
+			      struct file_id id,
 			      uint32_t orig_name_hash,
 			      const struct smb_filename *smb_fname_dst)
 {
@@ -6109,7 +6110,7 @@ static void rename_open_files(connection_struct *conn,
 	NTSTATUS status;
 	uint32_t new_name_hash = 0;
 
-	for(fsp = file_find_di_first(conn->sconn, lck->data->id); fsp;
+	for(fsp = file_find_di_first(conn->sconn, id); fsp;
 	    fsp = file_find_di_next(fsp)) {
 		/* fsp_name is a relative path under the fsp. To change this for other
 		   sharepaths we need to manipulate relative paths. */
@@ -6135,7 +6136,7 @@ static void rename_open_files(connection_struct *conn,
 
 	if (!did_rename) {
 		DEBUG(10, ("rename_open_files: no open files on file_id %s "
-			   "for %s\n", file_id_string_tos(&lck->data->id),
+			   "for %s\n", file_id_string_tos(&id),
 			   smb_fname_str_dbg(smb_fname_dst)));
 	}
 
@@ -6498,7 +6499,8 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
 		notify_rename(conn, fsp->is_directory, fsp->fsp_name,
 			      smb_fname_dst);
 
-		rename_open_files(conn, lck, fsp->name_hash, smb_fname_dst);
+		rename_open_files(conn, lck, fsp->file_id, fsp->name_hash,
+				  smb_fname_dst);
 
 		/*
 		 * A rename acts as a new file create w.r.t. allowing an initial delete
-- 
1.7.9.5


From 9e88e7071e545015405a71024a0dad9aa513a055 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Mar 2014 14:36:11 +0100
Subject: [PATCH 2/7] smbd: Explicitly pass "file_id" to schedule_defer_open

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

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index f995c0b..ba633b9 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1738,6 +1738,7 @@ static NTSTATUS fcb_or_dos_open(struct smb_request *req,
 }
 
 static void schedule_defer_open(struct share_mode_lock *lck,
+				struct file_id id,
 				struct timeval request_time,
 				struct smb_request *req)
 {
@@ -1768,7 +1769,7 @@ static void schedule_defer_open(struct share_mode_lock *lck,
 
 	state.delayed_for_oplocks = True;
 	state.async_open = false;
-	state.id = lck->data->id;
+	state.id = id;
 
 	if (!request_timed_out(request_time, timeout)) {
 		defer_open(lck, request_time, timeout, req, &state);
@@ -2412,7 +2413,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		}
 
 		if (delay_for_oplock(fsp, 0, lck, false, create_disposition)) {
-			schedule_defer_open(lck, request_time, req);
+			schedule_defer_open(lck, fsp->file_id, request_time, req);
 			TALLOC_FREE(lck);
 			DEBUG(10, ("Sent oplock break request to kernel "
 				   "oplock holder\n"));
@@ -2525,7 +2526,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		    fsp, oplock_request, lck,
 		    NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION),
 		    create_disposition)) {
-		schedule_defer_open(lck, request_time, req);
+		schedule_defer_open(lck, fsp->file_id, request_time, req);
 		TALLOC_FREE(lck);
 		fd_close(fsp);
 		return NT_STATUS_SHARING_VIOLATION;
-- 
1.7.9.5


From 1f878805b2a294004e9e2f05708341bf0a2862b9 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Mar 2014 14:45:42 +0100
Subject: [PATCH 3/7] smbd: Use fsp->file_id in open_file_ntcreate

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 ba633b9..d05c9ec 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2426,7 +2426,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		 */
 		state.delayed_for_oplocks = false;
 		state.async_open = false;
-		state.id = lck->data->id;
+		state.id = fsp->file_id;
 		defer_open(lck, request_time, timeval_set(0, 0), req, &state);
 		TALLOC_FREE(lck);
 		DEBUG(10, ("No Samba oplock around after EWOULDBLOCK. "
-- 
1.7.9.5


From 6abb8d6e6c186d00c9e8d9b8ab390827a74f1958 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Mar 2014 14:36:11 +0100
Subject: [PATCH 4/7] smbd: Explicitly pass "file_id" to rename_share_filename

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

diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 54c92b1..4ef6b89 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -468,6 +468,7 @@ struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
 
 bool rename_share_filename(struct messaging_context *msg_ctx,
 			struct share_mode_lock *lck,
+			struct file_id id,
 			const char *servicepath,
 			uint32_t orig_name_hash,
 			uint32_t new_name_hash,
@@ -523,7 +524,7 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
 		return False;
 	}
 
-	push_file_id_24(frm, &d->id);
+	push_file_id_24(frm, &id);
 
 	DEBUG(10,("rename_share_filename: msg_len = %u\n", (unsigned int)msg_len ));
 
@@ -565,7 +566,7 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
 			  "pid %s file_id %s sharepath %s base_name %s "
 			  "stream_name %s\n",
 			  procid_str_static(&se->pid),
-			  file_id_string_tos(&d->id),
+			  file_id_string_tos(&id),
 			  d->servicepath, d->base_name,
 			has_stream ? d->stream_name : ""));
 
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index a897fea..dc115e1 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -164,6 +164,7 @@ struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
 						  struct file_id id);
 bool rename_share_filename(struct messaging_context *msg_ctx,
 			struct share_mode_lock *lck,
+			struct file_id id,
 			const char *servicepath,
 			uint32_t orig_name_hash,
 			uint32_t new_name_hash,
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index a66aa5a..9603975 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -6141,7 +6141,7 @@ static void rename_open_files(connection_struct *conn,
 	}
 
 	/* Send messages to all smbd's (not ourself) that the name has changed. */
-	rename_share_filename(conn->sconn->msg_ctx, lck, conn->connectpath,
+	rename_share_filename(conn->sconn->msg_ctx, lck, id, conn->connectpath,
 			      orig_name_hash, new_name_hash,
 			      smb_fname_dst);
 
-- 
1.7.9.5


From a636c1a8f010f2407ccaa2b1d37f7f2795a8b9f3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Mar 2014 14:53:14 +0100
Subject: [PATCH 5/7] smbd: Avoid checking the_lock->id for fresh locks

If we just fetched the lock, this check will always be true.

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

diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index 5d0874c..a34f304 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -385,15 +385,16 @@ struct share_mode_lock *get_share_mode_lock(
 		}
 		talloc_set_destructor(the_lock, the_lock_destructor);
 	} else {
+		if (!file_id_equal(&the_lock->data->id, &id)) {
+			DEBUG(1, ("Can not lock two share modes "
+				  "simultaneously\n"));
+			goto fail;
+		}
 		if (talloc_reference(lck, the_lock) == NULL) {
 			DEBUG(1, ("talloc_reference failed\n"));
 			goto fail;
 		}
 	}
-	if (!file_id_equal(&the_lock->data->id, &id)) {
-		DEBUG(1, ("Can not lock two share modes simultaneously\n"));
-		goto fail;
-	}
 	lck->data = the_lock->data;
 	return lck;
 fail:
-- 
1.7.9.5


From 3000cb2dfcd57919719daa6c0fb9b928e301ba3c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Mar 2014 14:57:19 +0100
Subject: [PATCH 6/7] smbd: Keep "the_lock"s file id separately

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

diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index a34f304..50d5cf1 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -351,10 +351,12 @@ static struct share_mode_lock *get_share_mode_lock_internal(
  * talloc_reference.
  */
 static struct share_mode_lock *the_lock;
+static struct file_id the_lock_id;
 
 static int the_lock_destructor(struct share_mode_lock *l)
 {
 	the_lock = NULL;
+	ZERO_STRUCT(the_lock_id);
 	return 0;
 }
 
@@ -384,8 +386,9 @@ struct share_mode_lock *get_share_mode_lock(
 			goto fail;
 		}
 		talloc_set_destructor(the_lock, the_lock_destructor);
+		the_lock_id = id;
 	} else {
-		if (!file_id_equal(&the_lock->data->id, &id)) {
+		if (!file_id_equal(&the_lock_id, &id)) {
 			DEBUG(1, ("Can not lock two share modes "
 				  "simultaneously\n"));
 			goto fail;
-- 
1.7.9.5


From d0c095c94180239a3f195debebbacab600226cdc Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Mar 2014 14:58:19 +0100
Subject: [PATCH 7/7] smbd: Remove unused "share_mode_data->id"

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/librpc/idl/open_files.idl |    1 -
 source3/locking/share_mode_lock.c |    1 -
 2 files changed, 2 deletions(-)

diff --git a/source3/librpc/idl/open_files.idl b/source3/librpc/idl/open_files.idl
index 686bc02..0ebc819 100644
--- a/source3/librpc/idl/open_files.idl
+++ b/source3/librpc/idl/open_files.idl
@@ -41,7 +41,6 @@ interface open_files
 		[string,charset(UTF8)] char *servicepath;
 		[string,charset(UTF8)] char *base_name;
 		[string,charset(UTF8)] char *stream_name;
-		file_id id;
 		uint32 num_share_modes;
 		[size_is(num_share_modes)] share_mode_entry share_modes[];
 		uint32 num_delete_tokens;
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index 50d5cf1..5e25404 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -331,7 +331,6 @@ static struct share_mode_lock *get_share_mode_lock_internal(
 		TALLOC_FREE(rec);
 		return NULL;
 	}
-	d->id = id;
 	d->record = talloc_move(d, &rec);
 	talloc_set_destructor(d, share_mode_data_destructor);
 
-- 
1.7.9.5



More information about the samba-technical mailing list