[PATCH] Small simplification for dbwrap

Volker Lendecke Volker.Lendecke at SerNet.DE
Wed Nov 29 07:53:10 UTC 2017


Hi!

Review 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 ea08f3bad95d4b60e32400d537650071f949ebf0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 1 Jul 2017 08:20:23 +0200
Subject: [PATCH 1/2] smbd: Avoid using dbwrap_watched_watch_recv's prec
 argument

This is the only user of the "prec" argument of
dbwrap_watched_watch_recv. The next patch will remove this
functionality, as it's easily replaced here.

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

diff --git a/source3/smbd/smbXsrv_session.c b/source3/smbd/smbXsrv_session.c
index f84d2a94ce1..24767483287 100644
--- a/source3/smbd/smbXsrv_session.c
+++ b/source3/smbd/smbXsrv_session.c
@@ -956,6 +956,7 @@ struct smb2srv_session_close_previous_state {
 	struct tevent_context *ev;
 	struct smbXsrv_connection *connection;
 	struct dom_sid *current_sid;
+	uint64_t previous_session_id;
 	uint64_t current_session_id;
 	struct db_record *db_rec;
 };
@@ -984,6 +985,7 @@ struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
 	}
 	state->ev = ev;
 	state->connection = conn;
+	state->previous_session_id = previous_session_id;
 	state->current_session_id = current_session_id;
 
 	if (global_zeros != 0) {
@@ -1124,15 +1126,21 @@ static void smb2srv_session_close_previous_modified(struct tevent_req *subreq)
 	struct smb2srv_session_close_previous_state *state =
 		tevent_req_data(req,
 		struct smb2srv_session_close_previous_state);
+	uint32_t global_id;
 	NTSTATUS status;
 
-	status = dbwrap_watched_watch_recv(subreq, state, &state->db_rec, NULL,
-					   NULL);
+	status = dbwrap_watched_watch_recv(subreq, state, NULL, NULL, NULL);
 	TALLOC_FREE(subreq);
 	if (tevent_req_nterror(req, status)) {
 		return;
 	}
 
+	global_id = state->previous_session_id & UINT32_MAX;
+
+	state->db_rec = smbXsrv_session_global_fetch_locked(
+		state->connection->client->session_table->global.db_ctx,
+		global_id, state /* TALLOC_CTX */);
+
 	smb2srv_session_close_previous_check(req);
 }
 
-- 
2.11.0


From 62fcbb3c7723576d81de9395acfd99c817d35a5e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 1 Jul 2017 08:27:57 +0200
Subject: [PATCH 2/2] dbwrap_watch: Remove the "prec" parameter from watch_recv

The initial idea was to have some "atomicity" in this API. Every
caller interested in a record would have to do something with
it once it changes. However, only one caller really used this
feature, and that is easily changed to not use it. So
remove the complexity.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/dbwrap/dbwrap_watch.c   | 37 +------------------------------------
 source3/lib/dbwrap/dbwrap_watch.h   |  2 --
 source3/lib/g_lock.c                |  2 +-
 source3/smbd/open.c                 |  3 +--
 source3/smbd/smb2_setinfo.c         |  3 +--
 source3/smbd/smbXsrv_session.c      |  2 +-
 source3/torture/test_dbwrap_watch.c |  3 +--
 7 files changed, 6 insertions(+), 46 deletions(-)

diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c
index be0a0d37e0b..3e91f46b428 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -1003,18 +1003,12 @@ static void dbwrap_watched_watch_done(struct tevent_req *subreq)
 }
 
 NTSTATUS dbwrap_watched_watch_recv(struct tevent_req *req,
-				   TALLOC_CTX *mem_ctx,
-				   struct db_record **prec,
 				   bool *blockerdead,
 				   struct server_id *blocker)
 {
 	struct dbwrap_watched_watch_state *state = tevent_req_data(
 		req, struct dbwrap_watched_watch_state);
-	struct db_watched_subrec *subrec;
 	NTSTATUS status;
-	TDB_DATA key;
-	struct db_record *rec;
-	bool ok;
 
 	if (tevent_req_is_nterror(req, &status)) {
 		return status;
@@ -1025,35 +1019,6 @@ NTSTATUS dbwrap_watched_watch_recv(struct tevent_req *req,
 	if (blocker != NULL) {
 		*blocker = state->blocker;
 	}
-	if (prec == NULL) {
-		return NT_STATUS_OK;
-	}
-
-	ok = dbwrap_record_watchers_key_parse(state->w_key, NULL, NULL, &key);
-	if (!ok) {
-		return NT_STATUS_INTERNAL_DB_ERROR;
-	}
-
-	rec = dbwrap_fetch_locked(state->db, mem_ctx, key);
-	if (rec == NULL) {
-		return NT_STATUS_INTERNAL_DB_ERROR;
-	}
-
-	talloc_set_destructor(state, NULL);
-
-	subrec = talloc_get_type_abort(
-		rec->private_data, struct db_watched_subrec);
-
-	ok = dbwrap_watched_remove_waiter(&subrec->wrec, state->me);
-	if (ok) {
-		status = dbwrap_watched_save(subrec->subrec, &subrec->wrec,
-					     NULL, &subrec->wrec.data, 1, 0);
-		if (!NT_STATUS_IS_OK(status)) {
-			DBG_WARNING("dbwrap_watched_save failed: %s\n",
-				    nt_errstr(status));
-		}
-	}
-
-	*prec = rec;
 	return NT_STATUS_OK;
 }
+
diff --git a/source3/lib/dbwrap/dbwrap_watch.h b/source3/lib/dbwrap/dbwrap_watch.h
index 1849310ab16..e94378f2d5a 100644
--- a/source3/lib/dbwrap/dbwrap_watch.h
+++ b/source3/lib/dbwrap/dbwrap_watch.h
@@ -32,8 +32,6 @@ struct tevent_req *dbwrap_watched_watch_send(TALLOC_CTX *mem_ctx,
 					     struct db_record *rec,
 					     struct server_id blocker);
 NTSTATUS dbwrap_watched_watch_recv(struct tevent_req *req,
-				   TALLOC_CTX *mem_ctx,
-				   struct db_record **prec,
 				   bool *blockerdead,
 				   struct server_id *blocker);
 
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 8709052591d..c5d66e3855e 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -385,7 +385,7 @@ static void g_lock_lock_retry(struct tevent_req *subreq)
 	struct g_lock_lock_fn_state fn_state;
 	NTSTATUS status;
 
-	status = dbwrap_watched_watch_recv(subreq, NULL, NULL, NULL, NULL);
+	status = dbwrap_watched_watch_recv(subreq, NULL, NULL);
 	DBG_DEBUG("watch_recv returned %s\n", nt_errstr(status));
 	TALLOC_FREE(subreq);
 
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 8c52f4bba56..e55c3941092 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2390,8 +2390,7 @@ static void defer_open_done(struct tevent_req *req)
 	NTSTATUS status;
 	bool ret;
 
-	status = dbwrap_watched_watch_recv(req, talloc_tos(), NULL, NULL,
-					  NULL);
+	status = dbwrap_watched_watch_recv(req, NULL, NULL);
 	TALLOC_FREE(req);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(5, ("dbwrap_watched_watch_recv returned %s\n",
diff --git a/source3/smbd/smb2_setinfo.c b/source3/smbd/smb2_setinfo.c
index db00ba0f672..0355095c8b1 100644
--- a/source3/smbd/smb2_setinfo.c
+++ b/source3/smbd/smb2_setinfo.c
@@ -279,8 +279,7 @@ static void defer_rename_done(struct tevent_req *subreq)
 	int ret_size = 0;
 	bool ok;
 
-	status = dbwrap_watched_watch_recv(subreq, state->req, NULL, NULL,
-					   NULL);
+	status = dbwrap_watched_watch_recv(subreq, NULL, NULL);
 	TALLOC_FREE(subreq);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(5, ("dbwrap_record_watch_recv returned %s\n",
diff --git a/source3/smbd/smbXsrv_session.c b/source3/smbd/smbXsrv_session.c
index 24767483287..9e1fb6977b4 100644
--- a/source3/smbd/smbXsrv_session.c
+++ b/source3/smbd/smbXsrv_session.c
@@ -1129,7 +1129,7 @@ static void smb2srv_session_close_previous_modified(struct tevent_req *subreq)
 	uint32_t global_id;
 	NTSTATUS status;
 
-	status = dbwrap_watched_watch_recv(subreq, state, NULL, NULL, NULL);
+	status = dbwrap_watched_watch_recv(subreq, NULL, NULL);
 	TALLOC_FREE(subreq);
 	if (tevent_req_nterror(req, status)) {
 		return;
diff --git a/source3/torture/test_dbwrap_watch.c b/source3/torture/test_dbwrap_watch.c
index 5aa0430b111..97d5ea6393c 100644
--- a/source3/torture/test_dbwrap_watch.c
+++ b/source3/torture/test_dbwrap_watch.c
@@ -90,8 +90,7 @@ bool run_dbwrap_watch1(int dummy)
 		goto fail;
 	}
 
-	status = dbwrap_watched_watch_recv(req, talloc_tos(), &rec, NULL,
-					   NULL);
+	status = dbwrap_watched_watch_recv(req, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "dbwrap_record_watch_recv failed: %s\n",
 			nt_errstr(status));
-- 
2.11.0



More information about the samba-technical mailing list