diff options
author | Volker Lendecke <vl@samba.org> | 2014-07-17 11:23:46 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-08-11 23:57:12 +0200 |
commit | 3aa3c6ed012dd344cbc91ac49870c6adc4c3d891 (patch) | |
tree | de78f678b7cd8cf178455582b4c9fbc115b5b10d /source3 | |
parent | 28db680a0df9ce4329668d50ce7ba6d5a7c29761 (diff) | |
download | samba-3aa3c6ed012dd344cbc91ac49870c6adc4c3d891.tar.gz samba-3aa3c6ed012dd344cbc91ac49870c6adc4c3d891.tar.xz samba-3aa3c6ed012dd344cbc91ac49870c6adc4c3d891.zip |
messaging3: Directly refer to messaging_dgm in messages.c
This removes the messaging_backend abstraction layer from messages_dgm.c. That
layer was introduced for ctdb and is still used there. But as the messaging_dgm
interface is very slim anyway, I don't think directly calling it is too bad.
Why this commit? It is another step towards making messages_dgm
independent of messages.[ch], thus it might become usable in other
contexts like ctdb and source4
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/messages.h | 16 | ||||
-rw-r--r-- | source3/lib/messages.c | 27 | ||||
-rw-r--r-- | source3/lib/messages_dgm.c | 57 |
3 files changed, 36 insertions, 64 deletions
diff --git a/source3/include/messages.h b/source3/include/messages.h index 32c636f3fa..328161021f 100644 --- a/source3/include/messages.h +++ b/source3/include/messages.h @@ -73,21 +73,25 @@ struct messaging_backend { void *private_data; }; +struct messaging_dgm_context; int messaging_dgm_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct server_id pid, - struct messaging_backend **presult, void (*recv_cb)(int msg_type, struct server_id src, struct server_id dst, const uint8_t *msg, size_t msg_len, void *private_data), - void *recv_cb_private_data); -int messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid); -int messaging_dgm_wipe(struct messaging_context *msg_ctx); + void *recv_cb_private_data, + struct messaging_dgm_context **pctx); +int messaging_dgm_send(struct messaging_dgm_context *ctx, + struct server_id src, struct server_id pid, + int msg_type, 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 *messaging_dgm_register_tevent_context(TALLOC_CTX *mem_ctx, - struct messaging_context *msg_ctx, + struct messaging_dgm_context *ctx, struct tevent_context *ev); NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx, @@ -105,8 +109,6 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, struct server_id messaging_server_id(const struct messaging_context *msg_ctx); struct tevent_context *messaging_tevent_context( struct messaging_context *msg_ctx); -struct messaging_backend *messaging_local_backend( - struct messaging_context *msg_ctx); /* * re-init after a fork diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 78a867adf4..18376bbe53 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -72,7 +72,8 @@ struct messaging_context { struct tevent_req **waiters; unsigned num_waiters; - struct messaging_backend *local; + struct messaging_dgm_context *local; + struct messaging_backend *remote; bool *have_context; @@ -245,7 +246,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, ctx->have_context = &have_context; ret = messaging_dgm_init(ctx, ctx->event_ctx, ctx->id, - &ctx->local, messaging_recv_cb, ctx); + messaging_recv_cb, ctx, &ctx->local); if (ret != 0) { DEBUG(2, ("messaging_dgm_init failed: %s\n", strerror(ret))); @@ -304,8 +305,8 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx) msg_ctx->id = procid_self(); ret = messaging_dgm_init(msg_ctx, msg_ctx->event_ctx, - msg_ctx->id, &msg_ctx->local, - messaging_recv_cb, msg_ctx); + msg_ctx->id, messaging_recv_cb, msg_ctx, + &msg_ctx->local); if (ret != 0) { DEBUG(0, ("messaging_dgm_init failed: %s\n", strerror(errno))); return map_nt_error_from_unix(ret); @@ -468,8 +469,8 @@ NTSTATUS messaging_send_iov(struct messaging_context *msg_ctx, return NT_STATUS_OK; } - ret = msg_ctx->local->send_fn(msg_ctx->id, server, msg_type, - iov, iovlen, msg_ctx->local); + ret = messaging_dgm_send(msg_ctx->local, msg_ctx->id, server, msg_type, + iov, iovlen); if (ret != 0) { return map_nt_error_from_unix(ret); } @@ -536,7 +537,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, ev); + state, msg_ctx->local, ev); if (tevent_req_nomem(state, req)) { return tevent_req_post(req, ev); } @@ -899,7 +900,7 @@ static int mess_parent_dgm_cleanup(void *private_data) private_data, struct messaging_context); int ret; - ret = messaging_dgm_wipe(msg_ctx); + ret = messaging_dgm_wipe(msg_ctx->local); DEBUG(10, ("messaging_dgm_wipe returned %s\n", ret ? strerror(ret) : "ok")); return lp_parm_int(-1, "messaging", "messaging dgm cleanup interval", @@ -933,20 +934,14 @@ int messaging_cleanup(struct messaging_context *msg_ctx, pid_t pid) int ret; if (pid == 0) { - ret = messaging_dgm_wipe(msg_ctx); + ret = messaging_dgm_wipe(msg_ctx->local); } else { - ret = messaging_dgm_cleanup(msg_ctx, pid); + ret = messaging_dgm_cleanup(msg_ctx->local, pid); } return ret; } -struct messaging_backend *messaging_local_backend( - struct messaging_context *msg_ctx) -{ - return msg_ctx->local; -} - struct tevent_context *messaging_tevent_context( struct messaging_context *msg_ctx) { diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index 3fafebdbde..69d8677fbc 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -50,10 +50,6 @@ struct messaging_dgm_hdr { struct server_id src; }; -static int messaging_dgm_send(struct server_id src, - struct server_id pid, int msg_type, - const struct iovec *iov, int iovlen, - struct messaging_backend *backend); static void messaging_dgm_recv(struct unix_msg_ctx *ctx, uint8_t *msg, size_t msg_len, void *private_data); @@ -174,16 +170,15 @@ static int messaging_dgm_lockfile_remove(TALLOC_CTX *tmp_ctx, int messaging_dgm_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct server_id pid, - struct messaging_backend **presult, void (*recv_cb)(int msg_type, struct server_id src, struct server_id dst, const uint8_t *msg, size_t msg_len, void *private_data), - void *recv_cb_private_data) + void *recv_cb_private_data, + struct messaging_dgm_context **pctx) { - struct messaging_backend *result; struct messaging_dgm_context *ctx; int ret; bool ok; @@ -198,19 +193,11 @@ int messaging_dgm_init(TALLOC_CTX *mem_ctx, return errno; } - result = talloc(mem_ctx, struct messaging_backend); - if (result == NULL) { - goto fail_nomem; - } - ctx = talloc_zero(result, struct messaging_dgm_context); + ctx = talloc_zero(mem_ctx, struct messaging_dgm_context); if (ctx == NULL) { goto fail_nomem; } - - result->private_data = ctx; - result->send_fn = messaging_dgm_send; ctx->pid = pid; - ctx->recv_cb = recv_cb; ctx->recv_cb_private_data = recv_cb_private_data; @@ -228,7 +215,7 @@ int messaging_dgm_init(TALLOC_CTX *mem_ctx, sizeof(socket_address.sun_path), "%s/%u", socket_dir, (unsigned)pid.pid); if (sockname_len >= sizeof(socket_address.sun_path)) { - TALLOC_FREE(result); + TALLOC_FREE(ctx); return ENAMETOOLONG; } @@ -239,7 +226,7 @@ int messaging_dgm_init(TALLOC_CTX *mem_ctx, if (ret != 0) { DEBUG(1, ("%s: messaging_dgm_create_lockfile failed: %s\n", __func__, strerror(ret))); - TALLOC_FREE(result); + TALLOC_FREE(ctx); return ret; } @@ -258,7 +245,7 @@ int messaging_dgm_init(TALLOC_CTX *mem_ctx, 0700); if (!ok) { DEBUG(1, ("Could not create socket directory\n")); - TALLOC_FREE(result); + TALLOC_FREE(ctx); return EACCES; } TALLOC_FREE(socket_dir); @@ -271,16 +258,16 @@ int messaging_dgm_init(TALLOC_CTX *mem_ctx, messaging_dgm_recv, ctx, &ctx->dgm_ctx); if (ret != 0) { DEBUG(1, ("unix_msg_init failed: %s\n", strerror(ret))); - TALLOC_FREE(result); + TALLOC_FREE(ctx); return ret; } talloc_set_destructor(ctx, messaging_dgm_context_destructor); - *presult = result; + *pctx = ctx; return 0; fail_nomem: - TALLOC_FREE(result); + TALLOC_FREE(ctx); return ENOMEM; } @@ -301,13 +288,10 @@ static int messaging_dgm_context_destructor(struct messaging_dgm_context *c) return 0; } -static int messaging_dgm_send(struct server_id src, - struct server_id pid, int msg_type, - const struct iovec *iov, int iovlen, - struct messaging_backend *backend) +int messaging_dgm_send(struct messaging_dgm_context *ctx, + struct server_id src, struct server_id pid, + int msg_type, const struct iovec *iov, int iovlen) { - struct messaging_dgm_context *ctx = talloc_get_type_abort( - backend->private_data, struct messaging_dgm_context); struct messaging_dgm_hdr hdr; struct iovec iov2[iovlen + 1]; struct server_id_buf idbuf; @@ -371,11 +355,8 @@ static void messaging_dgm_recv(struct unix_msg_ctx *ctx, dgm_ctx->recv_cb_private_data); } -int messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) +int messaging_dgm_cleanup(struct messaging_dgm_context *ctx, pid_t pid) { - struct messaging_backend *be = messaging_local_backend(msg_ctx); - struct messaging_dgm_context *ctx = talloc_get_type_abort( - be->private_data, struct messaging_dgm_context); char *lockfile_name, *socket_name; int fd, ret; struct flock lck = {}; @@ -424,11 +405,8 @@ int messaging_dgm_cleanup(struct messaging_context *msg_ctx, pid_t pid) return 0; } -int messaging_dgm_wipe(struct messaging_context *msg_ctx) +int messaging_dgm_wipe(struct messaging_dgm_context *ctx) { - struct messaging_backend *be = messaging_local_backend(msg_ctx); - struct messaging_dgm_context *ctx = talloc_get_type_abort( - be->private_data, struct messaging_dgm_context); char *msgdir_name; DIR *msgdir; struct dirent *dp; @@ -472,7 +450,7 @@ int messaging_dgm_wipe(struct messaging_context *msg_ctx) continue; } - ret = messaging_dgm_cleanup(msg_ctx, pid); + ret = messaging_dgm_cleanup(ctx, pid); DEBUG(10, ("messaging_dgm_cleanup(%lu) returned %s\n", pid, ret ? strerror(ret) : "ok")); } @@ -482,11 +460,8 @@ int messaging_dgm_wipe(struct messaging_context *msg_ctx) } void *messaging_dgm_register_tevent_context(TALLOC_CTX *mem_ctx, - struct messaging_context *msg_ctx, + struct messaging_dgm_context *ctx, struct tevent_context *ev) { - struct messaging_backend *be = messaging_local_backend(msg_ctx); - struct messaging_dgm_context *ctx = talloc_get_type_abort( - be->private_data, struct messaging_dgm_context); return poll_funcs_tevent_register(mem_ctx, ctx->msg_callbacks, ev); } |