[PATCH] some patches for messaging3
Volker Lendecke
Volker.Lendecke at SerNet.DE
Thu Jan 9 02:32:22 MST 2014
Hi!
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 8d23248f0e0934b2d82129335a9a34281465f962 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 8 Jan 2014 16:13:11 +0100
Subject: [PATCH 1/3] messaging: Move the self-send logic out of messaging_tdb
This is not specific to tdb
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages.c | 52 ++++++++++++++++++++++++++++++++++++++++
source3/lib/messages_local.c | 54 ------------------------------------------
2 files changed, 52 insertions(+), 54 deletions(-)
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index f4d6227..fa3855c 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -344,6 +344,15 @@ void messaging_deregister(struct messaging_context *ctx, uint32_t msg_type,
}
}
+struct messaging_selfsend_state {
+ struct messaging_context *msg;
+ struct messaging_rec rec;
+};
+
+static void messaging_trigger_self(struct tevent_context *ev,
+ struct tevent_immediate *im,
+ void *private_data);
+
/*
Send a message to a particular server
*/
@@ -362,10 +371,53 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
msg_ctx->remote);
}
#endif
+
+ if (server_id_equal(&msg_ctx->id, &server)) {
+ struct messaging_selfsend_state *state;
+ struct tevent_immediate *im;
+
+ im = tevent_create_immediate(msg_ctx);
+ if (im == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ state = talloc(im, struct messaging_selfsend_state);
+ if (state == NULL) {
+ TALLOC_FREE(im);
+ return NT_STATUS_NO_MEMORY;
+ }
+ state->msg = msg_ctx;
+ state->rec.msg_version = MESSAGE_VERSION;
+ state->rec.msg_type = msg_type & MSG_TYPE_MASK;
+ state->rec.dest = server;
+ state->rec.src = msg_ctx->id;
+
+ state->rec.buf = data_blob_talloc(
+ state, data->data, data->length);
+ if ((state->rec.buf.length != 0) &&
+ (state->rec.buf.data == NULL)) {
+ TALLOC_FREE(im);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ tevent_schedule_immediate(im, msg_ctx->event_ctx,
+ messaging_trigger_self, state);
+ return NT_STATUS_OK;
+ }
+
return msg_ctx->local->send_fn(msg_ctx, server, msg_type, data,
msg_ctx->local);
}
+static void messaging_trigger_self(struct tevent_context *ev,
+ struct tevent_immediate *im,
+ void *private_data)
+{
+ struct messaging_selfsend_state *state = talloc_get_type_abort(
+ private_data, struct messaging_selfsend_state);
+ messaging_dispatch_rec(state->msg, &state->rec);
+}
+
NTSTATUS messaging_send_buf(struct messaging_context *msg_ctx,
struct server_id server, uint32_t msg_type,
const uint8_t *buf, size_t len)
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c
index 36a267a..c74c0aa 100644
--- a/source3/lib/messages_local.c
+++ b/source3/lib/messages_local.c
@@ -354,15 +354,6 @@ static NTSTATUS message_notify(struct server_id procid)
Send a message to a particular pid.
****************************************************************************/
-struct messaging_tdb_self_state {
- struct messaging_context *msg;
- struct messaging_rec rec;
-};
-
-static void messaging_tdb_trigger_self(struct tevent_context *ev,
- struct tevent_immediate *im,
- void *private_data);
-
static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
struct server_id pid, int msg_type,
const DATA_BLOB *data,
@@ -389,41 +380,6 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
SMB_ASSERT(procid_to_pid(&pid) > 0);
- if (server_id_equal(&msg_ctx->id, &pid)) {
- struct messaging_tdb_self_state *state;
- struct tevent_immediate *im;
-
- TALLOC_FREE(frame);
-
- im = tevent_create_immediate(msg_ctx);
- if (im == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- state = talloc(im, struct messaging_tdb_self_state);
- if (state == NULL) {
- TALLOC_FREE(im);
- return NT_STATUS_NO_MEMORY;
- }
- state->msg = msg_ctx;
- state->rec.msg_version = MESSAGE_VERSION;
- state->rec.msg_type = msg_type & MSG_TYPE_MASK;
- state->rec.dest = pid;
- state->rec.src = msg_ctx->id;
-
- state->rec.buf = data_blob_talloc(
- state, data->data, data->length);
- if ((state->rec.buf.length != 0) &&
- (state->rec.buf.data == NULL)) {
- TALLOC_FREE(im);
- return NT_STATUS_NO_MEMORY;
- }
-
- tevent_schedule_immediate(im, msg_ctx->event_ctx,
- messaging_tdb_trigger_self, state);
- return NT_STATUS_OK;
- }
-
key = message_key_pid(frame, pid);
if (tdb_chainlock(tdb->tdb, key) != 0) {
@@ -481,16 +437,6 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
return status;
}
-static void messaging_tdb_trigger_self(struct tevent_context *ev,
- struct tevent_immediate *im,
- void *private_data)
-{
- struct messaging_tdb_self_state *state = talloc_get_type_abort(
- private_data, struct messaging_tdb_self_state);
- messaging_dispatch_rec(state->msg, &state->rec);
-}
-
-
/****************************************************************************
Retrieve all messages for a process.
****************************************************************************/
--
1.7.9.5
From 2b0b5fd583e77bea48d2dcf0a80cfcf112baf9b6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 8 Jan 2014 16:15:27 +0100
Subject: [PATCH 2/3] messaging: Use talloc_pooled_object
... not as a speed improvement, it saves the second NULL check
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index fa3855c..e6681b5 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -381,7 +381,8 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
return NT_STATUS_NO_MEMORY;
}
- state = talloc(im, struct messaging_selfsend_state);
+ state = talloc_pooled_object(
+ im, struct messaging_selfsend_state, 1, data->length);
if (state == NULL) {
TALLOC_FREE(im);
return NT_STATUS_NO_MEMORY;
@@ -392,13 +393,9 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
state->rec.dest = server;
state->rec.src = msg_ctx->id;
+ /* Can't fail, it's a pooled_object */
state->rec.buf = data_blob_talloc(
state, data->data, data->length);
- if ((state->rec.buf.length != 0) &&
- (state->rec.buf.data == NULL)) {
- TALLOC_FREE(im);
- return NT_STATUS_NO_MEMORY;
- }
tevent_schedule_immediate(im, msg_ctx->event_ctx,
messaging_trigger_self, state);
--
1.7.9.5
From 112addd46f7f52e81864c73a492023f88adf02ad Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 8 Jan 2014 16:32:39 +0100
Subject: [PATCH 3/3] messaging: Fix a memleak (master only..)
Immediate tevents don't free themselves as timed events do :-)
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index e6681b5..ba473ae 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -376,15 +376,10 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
struct messaging_selfsend_state *state;
struct tevent_immediate *im;
- im = tevent_create_immediate(msg_ctx);
- if (im == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
state = talloc_pooled_object(
- im, struct messaging_selfsend_state, 1, data->length);
+ msg_ctx, struct messaging_selfsend_state,
+ 1, data->length);
if (state == NULL) {
- TALLOC_FREE(im);
return NT_STATUS_NO_MEMORY;
}
state->msg = msg_ctx;
@@ -397,6 +392,12 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
state->rec.buf = data_blob_talloc(
state, data->data, data->length);
+ im = tevent_create_immediate(state);
+ if (im == NULL) {
+ TALLOC_FREE(state);
+ return NT_STATUS_NO_MEMORY;
+ }
+
tevent_schedule_immediate(im, msg_ctx->event_ctx,
messaging_trigger_self, state);
return NT_STATUS_OK;
@@ -413,6 +414,7 @@ static void messaging_trigger_self(struct tevent_context *ev,
struct messaging_selfsend_state *state = talloc_get_type_abort(
private_data, struct messaging_selfsend_state);
messaging_dispatch_rec(state->msg, &state->rec);
+ TALLOC_FREE(state);
}
NTSTATUS messaging_send_buf(struct messaging_context *msg_ctx,
--
1.7.9.5
More information about the samba-technical
mailing list