summaryrefslogtreecommitdiffstats
path: root/source3/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-09-10 16:13:18 +0200
committerStefan Metzmacher <metze@samba.org>2014-09-14 16:29:30 +0200
commit7bc2e2d0d4a6706769a436798aa29d18a8f7c221 (patch)
tree4cd3cd65933d85d2d49cdf214e0d90f01ed67687 /source3/lib
parent9269a8e5d4f92569cf529e530bf800971c23682d (diff)
downloadsamba-7bc2e2d0d4a6706769a436798aa29d18a8f7c221.tar.gz
samba-7bc2e2d0d4a6706769a436798aa29d18a8f7c221.tar.xz
samba-7bc2e2d0d4a6706769a436798aa29d18a8f7c221.zip
messaging_dgm: Don't expose the messaging_dgm_context
Right now we can only support one messaging_dgm_context per process anyway, the code has checks for this. I would like to keep it that way, in the future we will have multiple messaging_context's or imessaging_context's filtering based upon the dst server_id. Why this change? messaging_dgm's lockfile contains the serverid->unique_id. When designing messaging_dgm, I had in mind to remove the serverid.tdb and replace it with the dgm lockfiles for server lookup and enumeration. I have a WIP-patchset that gets rid of almost all users of serverid.tdb. The problem is serverid_exists. Here we don't have a messaging_context available, and it would be pretty intrusive to make it so. This problem has plagued us since ctdb was developed, see for example the comment /* * This is a Samba3 hack/optimization. Routines like process_exists need to * talk to ctdbd, and they don't get handed a messaging context. */ in messaging_ctdb.c. This patchset removes this problem in a radical way: Treat the messaging_dgm context as one globally available structure and be done with it. The ctdb socket could go the same way in the future. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Sun Sep 14 16:29:30 CEST 2014 on sn-devel-104
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/messages.c33
-rw-r--r--source3/lib/messages_dgm.c47
-rw-r--r--source3/lib/messages_dgm.h16
3 files changed, 59 insertions, 37 deletions
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 80ecec4aaa..52d6538542 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -73,8 +73,6 @@ struct messaging_context {
struct tevent_req **waiters;
unsigned num_waiters;
- struct messaging_dgm_context *local;
-
struct messaging_backend *remote;
};
@@ -240,6 +238,12 @@ static void messaging_recv_cb(const uint8_t *msg, size_t msg_len,
messaging_dispatch_rec(msg_ctx, &rec);
}
+static int messaging_context_destructor(struct messaging_context *ctx)
+{
+ messaging_dgm_destroy();
+ return 0;
+}
+
struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev)
{
@@ -256,9 +260,9 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
sec_init();
- ret = messaging_dgm_init(ctx, ctx->event_ctx, ctx->id,
+ ret = messaging_dgm_init(ctx->event_ctx, ctx->id,
lp_cache_directory(), sec_initial_uid(),
- messaging_recv_cb, ctx, &ctx->local);
+ messaging_recv_cb, ctx);
if (ret != 0) {
DEBUG(2, ("messaging_dgm_init failed: %s\n", strerror(ret)));
@@ -266,6 +270,8 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
return NULL;
}
+ talloc_set_destructor(ctx, messaging_context_destructor);
+
if (lp_clustering()) {
status = messaging_ctdbd_init(ctx, ctx, &ctx->remote);
@@ -302,14 +308,13 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
NTSTATUS status;
int ret;
- TALLOC_FREE(msg_ctx->local);
+ messaging_dgm_destroy();
msg_ctx->id = procid_self();
- ret = messaging_dgm_init(msg_ctx, msg_ctx->event_ctx, msg_ctx->id,
+ ret = messaging_dgm_init(msg_ctx->event_ctx, msg_ctx->id,
lp_cache_directory(), sec_initial_uid(),
- messaging_recv_cb, msg_ctx,
- &msg_ctx->local);
+ messaging_recv_cb, msg_ctx);
if (ret != 0) {
DEBUG(0, ("messaging_dgm_init failed: %s\n", strerror(errno)));
return map_nt_error_from_unix(ret);
@@ -480,7 +485,7 @@ NTSTATUS messaging_send_iov(struct messaging_context *msg_ctx,
memcpy(&iov2[1], iov, iovlen * sizeof(*iov));
become_root();
- ret = messaging_dgm_send(msg_ctx->local, server.pid, iov2, iovlen+1);
+ ret = messaging_dgm_send(server.pid, iov2, iovlen+1);
unbecome_root();
if (ret != 0) {
@@ -549,7 +554,7 @@ struct tevent_req *messaging_filtered_read_send(
tevent_req_defer_callback(req, state->ev);
state->tevent_handle = messaging_dgm_register_tevent_context(
- state, msg_ctx->local, ev);
+ state, ev);
if (tevent_req_nomem(state, req)) {
return tevent_req_post(req, ev);
}
@@ -908,11 +913,9 @@ bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg)
static int mess_parent_dgm_cleanup(void *private_data)
{
- struct messaging_context *msg_ctx = talloc_get_type_abort(
- private_data, struct messaging_context);
int ret;
- ret = messaging_dgm_wipe(msg_ctx->local);
+ ret = messaging_dgm_wipe();
DEBUG(10, ("messaging_dgm_wipe returned %s\n",
ret ? strerror(ret) : "ok"));
return lp_parm_int(-1, "messaging", "messaging dgm cleanup interval",
@@ -946,9 +949,9 @@ int messaging_cleanup(struct messaging_context *msg_ctx, pid_t pid)
int ret;
if (pid == 0) {
- ret = messaging_dgm_wipe(msg_ctx->local);
+ ret = messaging_dgm_wipe();
} else {
- ret = messaging_dgm_cleanup(msg_ctx->local, pid);
+ ret = messaging_dgm_cleanup(pid);
}
return ret;
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index 1021c7c784..471aed464c 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -50,6 +50,8 @@ struct messaging_dgm_context {
bool *have_dgm_context;
};
+static struct messaging_dgm_context *global_dgm_context;
+
static void messaging_dgm_recv(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len,
void *private_data);
@@ -170,16 +172,14 @@ static int messaging_dgm_lockfile_remove(const char *cache_dir, pid_t pid)
return ret;
}
-int messaging_dgm_init(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
+int messaging_dgm_init(struct tevent_context *ev,
struct server_id pid,
const char *cache_dir,
uid_t dir_owner,
void (*recv_cb)(const uint8_t *msg,
size_t msg_len,
void *private_data),
- void *recv_cb_private_data,
- struct messaging_dgm_context **pctx)
+ void *recv_cb_private_data)
{
struct messaging_dgm_context *ctx;
int ret;
@@ -194,7 +194,7 @@ int messaging_dgm_init(TALLOC_CTX *mem_ctx,
return EEXIST;
}
- ctx = talloc_zero(mem_ctx, struct messaging_dgm_context);
+ ctx = talloc_zero(NULL, struct messaging_dgm_context);
if (ctx == NULL) {
goto fail_nomem;
}
@@ -263,7 +263,7 @@ int messaging_dgm_init(TALLOC_CTX *mem_ctx,
ctx->have_dgm_context = &have_dgm_context;
- *pctx = ctx;
+ global_dgm_context = ctx;
return 0;
fail_nomem:
@@ -291,13 +291,22 @@ static int messaging_dgm_context_destructor(struct messaging_dgm_context *c)
return 0;
}
-int messaging_dgm_send(struct messaging_dgm_context *ctx, pid_t pid,
- const struct iovec *iov, int iovlen)
+void messaging_dgm_destroy(void)
+{
+ TALLOC_FREE(global_dgm_context);
+}
+
+int messaging_dgm_send(pid_t pid, const struct iovec *iov, int iovlen)
{
+ struct messaging_dgm_context *ctx = global_dgm_context;
struct sockaddr_un dst;
ssize_t dst_pathlen;
int ret;
+ if (ctx == NULL) {
+ return ENOTCONN;
+ }
+
dst = (struct sockaddr_un) { .sun_family = AF_UNIX };
dst_pathlen = snprintf(dst.sun_path, sizeof(dst.sun_path),
@@ -323,12 +332,17 @@ static void messaging_dgm_recv(struct unix_msg_ctx *ctx,
dgm_ctx->recv_cb(msg, msg_len, dgm_ctx->recv_cb_private_data);
}
-int messaging_dgm_cleanup(struct messaging_dgm_context *ctx, pid_t pid)
+int messaging_dgm_cleanup(pid_t pid)
{
+ struct messaging_dgm_context *ctx = global_dgm_context;
struct sun_path_buf lockfile_name, socket_name;
int fd, ret;
struct flock lck = {};
+ if (ctx == NULL) {
+ return ENOTCONN;
+ }
+
ret = messaging_dgm_lockfile_name(&lockfile_name, ctx->cache_dir.buf,
pid);
if (ret != 0) {
@@ -369,14 +383,19 @@ int messaging_dgm_cleanup(struct messaging_dgm_context *ctx, pid_t pid)
return 0;
}
-int messaging_dgm_wipe(struct messaging_dgm_context *ctx)
+int messaging_dgm_wipe(void)
{
+ struct messaging_dgm_context *ctx = global_dgm_context;
struct sun_path_buf msgdir_name;
DIR *msgdir;
struct dirent *dp;
pid_t our_pid = getpid();
int ret;
+ if (ctx == NULL) {
+ return ENOTCONN;
+ }
+
/*
* We scan the socket directory and not the lock directory. Otherwise
* we would race against messaging_dgm_lockfile_create's open(O_CREAT)
@@ -413,7 +432,7 @@ int messaging_dgm_wipe(struct messaging_dgm_context *ctx)
continue;
}
- ret = messaging_dgm_cleanup(ctx, pid);
+ ret = messaging_dgm_cleanup(pid);
DEBUG(10, ("messaging_dgm_cleanup(%lu) returned %s\n",
pid, ret ? strerror(ret) : "ok"));
}
@@ -423,8 +442,12 @@ int messaging_dgm_wipe(struct messaging_dgm_context *ctx)
}
void *messaging_dgm_register_tevent_context(TALLOC_CTX *mem_ctx,
- struct messaging_dgm_context *ctx,
struct tevent_context *ev)
{
+ struct messaging_dgm_context *ctx = global_dgm_context;
+
+ if (ctx == NULL) {
+ return NULL;
+ }
return poll_funcs_tevent_register(mem_ctx, ctx->msg_callbacks, ev);
}
diff --git a/source3/lib/messages_dgm.h b/source3/lib/messages_dgm.h
index b403117848..169d863219 100644
--- a/source3/lib/messages_dgm.h
+++ b/source3/lib/messages_dgm.h
@@ -20,23 +20,19 @@
#ifndef _MESSAGES_DGM_H_
#define _MESSAGES_DGM_H_
-struct messaging_dgm_context;
-int messaging_dgm_init(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
+int messaging_dgm_init(struct tevent_context *ev,
struct server_id pid,
const char *cache_dir,
uid_t dir_owner,
void (*recv_cb)(const uint8_t *msg,
size_t msg_len,
void *private_data),
- void *recv_cb_private_data,
- struct messaging_dgm_context **pctx);
-int messaging_dgm_send(struct messaging_dgm_context *ctx, pid_t pid,
- const struct iovec *iov, int iovlen);
-int messaging_dgm_cleanup(struct messaging_dgm_context *ctx, pid_t pid);
-int messaging_dgm_wipe(struct messaging_dgm_context *ctx);
+ void *recv_cb_private_data);
+void messaging_dgm_destroy(void);
+int messaging_dgm_send(pid_t pid, const struct iovec *iov, int iovlen);
+int messaging_dgm_cleanup(pid_t pid);
+int messaging_dgm_wipe(void);
void *messaging_dgm_register_tevent_context(TALLOC_CTX *mem_ctx,
- struct messaging_dgm_context *ctx,
struct tevent_context *ev);
#endif