[PATCH] messaging cleanup
Volker Lendecke
vl at samba.org
Sat Jul 23 07:08:22 UTC 2016
Hi!
Some cleanup and a small drive-by fix. Review appreciated!
Thanks, Volker
-------------- next part --------------
>From 83d6d219dcf0b9c4556d8bf3317064d0788a6e17 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 14 Jul 2016 12:47:16 +0200
Subject: [PATCH 1/2] lib: Move "message_send_all" to serverid.c
Trying to trim down messages.c a bit: Sending to all processes that are
registered in serverid.tdb and filtering to me is not really logic of general
messaging but more of the serverid code.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/messages.h | 15 -----
source3/include/serverid.h | 18 ++++++
source3/lib/messages.c | 102 ------------------------------
source3/lib/serverid.c | 95 ++++++++++++++++++++++++++++
source3/passdb/pdb_interface.c | 1 +
source3/rpc_server/fss/srv_fss_agent.c | 1 +
source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 1 +
source3/smbd/statcache.c | 1 +
8 files changed, 117 insertions(+), 117 deletions(-)
diff --git a/source3/include/messages.h b/source3/include/messages.h
index 2eaf146..1b4e2f6 100644
--- a/source3/include/messages.h
+++ b/source3/include/messages.h
@@ -36,17 +36,6 @@
#define MSG_FLAG_LOWPRIORITY 0x80000000
-/* Flags to classify messages - used in message_send_all() */
-/* Sender will filter by flag. */
-
-#define FLAG_MSG_GENERAL 0x0001
-#define FLAG_MSG_SMBD 0x0002
-#define FLAG_MSG_NMBD 0x0004
-#define FLAG_MSG_WINBIND 0x0008
-#define FLAG_MSG_PRINT_GENERAL 0x0010
-/* dbwrap messages 4001-4999 */
-#define FLAG_MSG_DBWRAP 0x0020
-
/*
* ctdb gives us 64-bit server ids for messaging_send. This is done to avoid
* pid clashes and to be able to register for special messages like "all
@@ -84,10 +73,6 @@ int messaging_ctdbd_reinit(struct messaging_context *msg_ctx,
struct messaging_backend *backend);
struct ctdbd_connection *messaging_ctdbd_connection(void);
-bool message_send_all(struct messaging_context *msg_ctx,
- int msg_type,
- const void *buf, size_t len,
- int *n_sent);
struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev);
diff --git a/source3/include/serverid.h b/source3/include/serverid.h
index 19caec8..749b950 100644
--- a/source3/include/serverid.h
+++ b/source3/include/serverid.h
@@ -24,6 +24,17 @@
#include "lib/dbwrap/dbwrap.h"
#include "librpc/gen_ndr/server_id.h"
+/* Flags to classify messages - used in message_send_all() */
+/* Sender will filter by flag. */
+
+#define FLAG_MSG_GENERAL 0x0001
+#define FLAG_MSG_SMBD 0x0002
+#define FLAG_MSG_NMBD 0x0004
+#define FLAG_MSG_WINBIND 0x0008
+#define FLAG_MSG_PRINT_GENERAL 0x0010
+/* dbwrap messages 4001-4999 */
+#define FLAG_MSG_DBWRAP 0x0020
+
/*
* Register a server with its unique id
*/
@@ -60,4 +71,11 @@ bool serverid_traverse_read(int (*fn)(const struct server_id *id,
*/
bool serverid_parent_init(TALLOC_CTX *mem_ctx);
+struct messaging_context;
+
+bool message_send_all(struct messaging_context *msg_ctx,
+ int msg_type,
+ const void *buf, size_t len,
+ int *n_sent);
+
#endif
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index ba97fb5..98bcf82 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -105,108 +105,6 @@ static void ping_message(struct messaging_context *msg_ctx,
messaging_send(msg_ctx, src, MSG_PONG, data);
}
-/****************************************************************************
- Register/replace a dispatch function for a particular message type.
- JRA changed Dec 13 2006. Only one message handler now permitted per type.
- *NOTE*: Dispatch functions must be able to cope with incoming
- messages on an *odd* byte boundary.
-****************************************************************************/
-
-struct msg_all {
- struct messaging_context *msg_ctx;
- int msg_type;
- uint32_t msg_flag;
- const void *buf;
- size_t len;
- int n_sent;
-};
-
-/****************************************************************************
- Send one of the messages for the broadcast.
-****************************************************************************/
-
-static int traverse_fn(struct db_record *rec, const struct server_id *id,
- uint32_t msg_flags, void *state)
-{
- struct msg_all *msg_all = (struct msg_all *)state;
- NTSTATUS status;
-
- /* Don't send if the receiver hasn't registered an interest. */
-
- if((msg_flags & msg_all->msg_flag) == 0) {
- return 0;
- }
-
- /* If the msg send fails because the pid was not found (i.e. smbd died),
- * the msg has already been deleted from the messages.tdb.*/
-
- status = messaging_send_buf(msg_all->msg_ctx, *id, msg_all->msg_type,
- (const uint8_t *)msg_all->buf, msg_all->len);
-
- if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
- struct server_id_buf idbuf;
-
- /*
- * If the pid was not found delete the entry from
- * serverid.tdb
- */
-
- DEBUG(2, ("pid %s doesn't exist\n",
- server_id_str_buf(*id, &idbuf)));
-
- dbwrap_record_delete(rec);
- }
- msg_all->n_sent++;
- return 0;
-}
-
-/**
- * Send a message to all smbd processes.
- *
- * It isn't very efficient, but should be OK for the sorts of
- * applications that use it. When we need efficient broadcast we can add
- * it.
- *
- * @param n_sent Set to the number of messages sent. This should be
- * equal to the number of processes, but be careful for races.
- *
- * @retval True for success.
- **/
-bool message_send_all(struct messaging_context *msg_ctx,
- int msg_type,
- const void *buf, size_t len,
- int *n_sent)
-{
- struct msg_all msg_all;
-
- msg_all.msg_type = msg_type;
- if (msg_type < 0x100) {
- msg_all.msg_flag = FLAG_MSG_GENERAL;
- } else if (msg_type > 0x100 && msg_type < 0x200) {
- msg_all.msg_flag = FLAG_MSG_NMBD;
- } else if (msg_type > 0x200 && msg_type < 0x300) {
- msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
- } else if (msg_type > 0x300 && msg_type < 0x400) {
- msg_all.msg_flag = FLAG_MSG_SMBD;
- } else if (msg_type > 0x400 && msg_type < 0x600) {
- msg_all.msg_flag = FLAG_MSG_WINBIND;
- } else if (msg_type > 4000 && msg_type < 5000) {
- msg_all.msg_flag = FLAG_MSG_DBWRAP;
- } else {
- return false;
- }
-
- msg_all.buf = buf;
- msg_all.len = len;
- msg_all.n_sent = 0;
- msg_all.msg_ctx = msg_ctx;
-
- serverid_traverse(traverse_fn, &msg_all);
- if (n_sent)
- *n_sent = msg_all.n_sent;
- return true;
-}
-
static void messaging_recv_cb(const uint8_t *msg, size_t msg_len,
int *fds, size_t num_fds,
void *private_data)
diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c
index 5c2fa65..f2c6400 100644
--- a/source3/lib/serverid.c
+++ b/source3/lib/serverid.c
@@ -313,3 +313,98 @@ bool serverid_traverse(int (*fn)(struct db_record *rec,
status = dbwrap_traverse(db, serverid_traverse_fn, &state, NULL);
return NT_STATUS_IS_OK(status);
}
+
+struct msg_all {
+ struct messaging_context *msg_ctx;
+ int msg_type;
+ uint32_t msg_flag;
+ const void *buf;
+ size_t len;
+ int n_sent;
+};
+
+/****************************************************************************
+ Send one of the messages for the broadcast.
+****************************************************************************/
+
+static int traverse_fn(struct db_record *rec, const struct server_id *id,
+ uint32_t msg_flags, void *state)
+{
+ struct msg_all *msg_all = (struct msg_all *)state;
+ NTSTATUS status;
+
+ /* Don't send if the receiver hasn't registered an interest. */
+
+ if((msg_flags & msg_all->msg_flag) == 0) {
+ return 0;
+ }
+
+ /* If the msg send fails because the pid was not found (i.e. smbd died),
+ * the msg has already been deleted from the messages.tdb.*/
+
+ status = messaging_send_buf(msg_all->msg_ctx, *id, msg_all->msg_type,
+ (const uint8_t *)msg_all->buf, msg_all->len);
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
+ struct server_id_buf idbuf;
+
+ /*
+ * If the pid was not found delete the entry from
+ * serverid.tdb
+ */
+
+ DEBUG(2, ("pid %s doesn't exist\n",
+ server_id_str_buf(*id, &idbuf)));
+
+ dbwrap_record_delete(rec);
+ }
+ msg_all->n_sent++;
+ return 0;
+}
+
+/**
+ * Send a message to all smbd processes.
+ *
+ * It isn't very efficient, but should be OK for the sorts of
+ * applications that use it. When we need efficient broadcast we can add
+ * it.
+ *
+ * @param n_sent Set to the number of messages sent. This should be
+ * equal to the number of processes, but be careful for races.
+ *
+ * @retval True for success.
+ **/
+bool message_send_all(struct messaging_context *msg_ctx,
+ int msg_type,
+ const void *buf, size_t len,
+ int *n_sent)
+{
+ struct msg_all msg_all;
+
+ msg_all.msg_type = msg_type;
+ if (msg_type < 0x100) {
+ msg_all.msg_flag = FLAG_MSG_GENERAL;
+ } else if (msg_type > 0x100 && msg_type < 0x200) {
+ msg_all.msg_flag = FLAG_MSG_NMBD;
+ } else if (msg_type > 0x200 && msg_type < 0x300) {
+ msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
+ } else if (msg_type > 0x300 && msg_type < 0x400) {
+ msg_all.msg_flag = FLAG_MSG_SMBD;
+ } else if (msg_type > 0x400 && msg_type < 0x600) {
+ msg_all.msg_flag = FLAG_MSG_WINBIND;
+ } else if (msg_type > 4000 && msg_type < 5000) {
+ msg_all.msg_flag = FLAG_MSG_DBWRAP;
+ } else {
+ return false;
+ }
+
+ msg_all.buf = buf;
+ msg_all.len = len;
+ msg_all.n_sent = 0;
+ msg_all.msg_ctx = msg_ctx;
+
+ serverid_traverse(traverse_fn, &msg_all);
+ if (n_sent)
+ *n_sent = msg_all.n_sent;
+ return true;
+}
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index 6b6b106..5260320 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -25,6 +25,7 @@
#include "passdb.h"
#include "secrets.h"
#include "messages.h"
+#include "serverid.h"
#include "../librpc/gen_ndr/samr.h"
#include "../librpc/gen_ndr/drsblobs.h"
#include "../librpc/gen_ndr/ndr_drsblobs.h"
diff --git a/source3/rpc_server/fss/srv_fss_agent.c b/source3/rpc_server/fss/srv_fss_agent.c
index 2a1f770..880244e 100644
--- a/source3/rpc_server/fss/srv_fss_agent.c
+++ b/source3/rpc_server/fss/srv_fss_agent.c
@@ -20,6 +20,7 @@
#include "includes.h"
#include "ntdomain.h"
#include "include/messages.h"
+#include "serverid.h"
#include "include/auth.h"
#include "../libcli/security/security.h"
#include "../libcli/util/hresult.h"
diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
index 980411e..d6e1dfa 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -37,6 +37,7 @@
#include "smbd/globals.h"
#include "auth.h"
#include "messages.h"
+#include "serverid.h"
#include "lib/conn_tdb.h"
extern const struct generic_mapping file_generic_mapping;
diff --git a/source3/smbd/statcache.c b/source3/smbd/statcache.c
index b0b2640..89a4a3d 100644
--- a/source3/smbd/statcache.c
+++ b/source3/smbd/statcache.c
@@ -24,6 +24,7 @@
#include "../lib/util/memcache.h"
#include "smbd/smbd.h"
#include "messages.h"
+#include "serverid.h"
#include "smbprofile.h"
#include <tdb.h>
--
1.9.1
>From e6bbf088e63141e9b82760bae03469a500d1fd80 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 22 Jul 2016 15:43:58 +0200
Subject: [PATCH 2/2] fss_agent: Fix a signed/unsigned mixup
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/rpc_server/fss/srv_fss_agent.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/rpc_server/fss/srv_fss_agent.c b/source3/rpc_server/fss/srv_fss_agent.c
index 880244e..0fc974b 100644
--- a/source3/rpc_server/fss/srv_fss_agent.c
+++ b/source3/rpc_server/fss/srv_fss_agent.c
@@ -63,7 +63,7 @@ static const struct {
static uint32_t fss_ntstatus_map(NTSTATUS status)
{
- int i;
+ size_t i;
if (NT_STATUS_IS_OK(status))
return 0;
--
1.9.1
More information about the samba-technical
mailing list