From 15888bca16fa367601eff22fa1212497b16e2f61 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 16 Jun 2017 15:20:22 +0200 Subject: [PATCH 01/13] notifyd: Only ask for messaging_ctdb_conn when clustering Without clustering, messaging_ctdb_conn will fail anyway. Review with "git show -b". Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit 939576d968d1e0159456baf6dd1e3c454b98995a) --- source3/smbd/notifyd/notifyd.c | 65 +++++++++++++++++++++++------------------- source3/smbd/server.c | 8 ++++-- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index 087952ad9d7..0de56dab2ad 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -241,13 +241,15 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, tevent_req_set_callback(subreq, notifyd_handler_done, req); #ifdef CLUSTER_SUPPORT - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_DB, - notifyd_got_db, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + if (ctdbd_conn != NULL) { + subreq = messaging_handler_send(state, ev, msg_ctx, + MSG_SMB_NOTIFY_DB, + notifyd_got_db, state); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, notifyd_handler_done, req); } - tevent_req_set_callback(subreq, notifyd_handler_done, req); #endif names_db = messaging_names_db(msg_ctx); @@ -269,32 +271,37 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, } #ifdef CLUSTER_SUPPORT - state->log = talloc_zero(state, struct messaging_reclog); - if (tevent_req_nomem(state->log, req)) { - return tevent_req_post(req, ev); - } + if (ctdbd_conn != NULL) { + state->log = talloc_zero(state, struct messaging_reclog); + if (tevent_req_nomem(state->log, req)) { + return tevent_req_post(req, ev); + } - subreq = notifyd_broadcast_reclog_send( - state->log, ev, ctdbd_conn, messaging_server_id(msg_ctx), - state->log); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, notifyd_broadcast_reclog_finished, - req); + subreq = notifyd_broadcast_reclog_send( + state->log, ev, ctdbd_conn, + messaging_server_id(msg_ctx), + state->log); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, + notifyd_broadcast_reclog_finished, + req); - subreq = notifyd_clean_peers_send(state, ev, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, notifyd_clean_peers_finished, - req); + subreq = notifyd_clean_peers_send(state, ev, state); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, notifyd_clean_peers_finished, + req); - ret = register_with_ctdbd(ctdbd_conn, CTDB_SRVID_SAMBA_NOTIFY_PROXY, - notifyd_snoop_broadcast, state); - if (ret != 0) { - tevent_req_error(req, ret); - return tevent_req_post(req, ev); + ret = register_with_ctdbd(ctdbd_conn, + CTDB_SRVID_SAMBA_NOTIFY_PROXY, + notifyd_snoop_broadcast, state); + if (ret != 0) { + tevent_req_error(req, ret); + return tevent_req_post(req, ev); + } } #endif diff --git a/source3/smbd/server.c b/source3/smbd/server.c index f97b5e8f2ab..3362c5ae720 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -331,6 +331,7 @@ static struct tevent_req *notifyd_req(struct messaging_context *msg_ctx, struct tevent_req *req; sys_notify_watch_fn sys_notify_watch = NULL; struct sys_notify_context *sys_notify_ctx = NULL; + struct ctdbd_connection *ctdbd_conn = NULL; if (lp_kernel_change_notify()) { @@ -355,8 +356,11 @@ static struct tevent_req *notifyd_req(struct messaging_context *msg_ctx, } } - req = notifyd_send(msg_ctx, ev, msg_ctx, - messaging_ctdbd_connection(), + if (lp_clustering()) { + ctdbd_conn = messaging_ctdbd_connection(); + } + + req = notifyd_send(msg_ctx, ev, msg_ctx, ctdbd_conn, sys_notify_watch, sys_notify_ctx); if (req == NULL) { TALLOC_FREE(sys_notify_ctx); -- 2.13.5 From abf6a7a616b6c0b5a90d58c5da4b67e67ba5f1ae Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 5 Jul 2017 09:34:51 +0200 Subject: [PATCH 02/13] notifyd: Consolidate two #ifdef CLUSTER into one Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit d0a7bccae9856aba44a057c09499aa0de6b21862) --- source3/smbd/notifyd/notifyd.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index 0de56dab2ad..e747be2756f 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -240,18 +240,6 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, } tevent_req_set_callback(subreq, notifyd_handler_done, req); -#ifdef CLUSTER_SUPPORT - if (ctdbd_conn != NULL) { - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_DB, - notifyd_got_db, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, notifyd_handler_done, req); - } -#endif - names_db = messaging_names_db(msg_ctx); ret = server_id_db_set_exclusive(names_db, "notify-daemon"); @@ -272,6 +260,15 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, #ifdef CLUSTER_SUPPORT if (ctdbd_conn != NULL) { + + subreq = messaging_handler_send(state, ev, msg_ctx, + MSG_SMB_NOTIFY_DB, + notifyd_got_db, state); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, notifyd_handler_done, req); + state->log = talloc_zero(state, struct messaging_reclog); if (tevent_req_nomem(state->log, req)) { return tevent_req_post(req, ev); -- 2.13.5 From e1ac563052a2c9fc7e6cf69f42a33e66655bf56c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 5 Jul 2017 09:37:14 +0200 Subject: [PATCH 03/13] notifyd: Avoid an if-expression Best reviewed with "git show -b -U10" Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit b8dccd11ea3d43b9ee51811c1ce7d81b91a549ca) --- source3/smbd/notifyd/notifyd.c | 69 ++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index e747be2756f..b92c2f9d185 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -259,46 +259,43 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, } #ifdef CLUSTER_SUPPORT - if (ctdbd_conn != NULL) { - - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_DB, - notifyd_got_db, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, notifyd_handler_done, req); + subreq = messaging_handler_send(state, ev, msg_ctx, + MSG_SMB_NOTIFY_DB, + notifyd_got_db, state); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, notifyd_handler_done, req); - state->log = talloc_zero(state, struct messaging_reclog); - if (tevent_req_nomem(state->log, req)) { - return tevent_req_post(req, ev); - } + state->log = talloc_zero(state, struct messaging_reclog); + if (tevent_req_nomem(state->log, req)) { + return tevent_req_post(req, ev); + } - subreq = notifyd_broadcast_reclog_send( - state->log, ev, ctdbd_conn, - messaging_server_id(msg_ctx), - state->log); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, - notifyd_broadcast_reclog_finished, - req); + subreq = notifyd_broadcast_reclog_send( + state->log, ev, ctdbd_conn, + messaging_server_id(msg_ctx), + state->log); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, + notifyd_broadcast_reclog_finished, + req); - subreq = notifyd_clean_peers_send(state, ev, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, notifyd_clean_peers_finished, - req); + subreq = notifyd_clean_peers_send(state, ev, state); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, notifyd_clean_peers_finished, + req); - ret = register_with_ctdbd(ctdbd_conn, - CTDB_SRVID_SAMBA_NOTIFY_PROXY, - notifyd_snoop_broadcast, state); - if (ret != 0) { - tevent_req_error(req, ret); - return tevent_req_post(req, ev); - } + ret = register_with_ctdbd(ctdbd_conn, + CTDB_SRVID_SAMBA_NOTIFY_PROXY, + notifyd_snoop_broadcast, state); + if (ret != 0) { + tevent_req_error(req, ret); + return tevent_req_post(req, ev); } #endif -- 2.13.5 From b9326bff803819f710a8ea202a18fae7687f1c84 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Jun 2017 08:38:19 +0200 Subject: [PATCH 04/13] messaging: make messaging_rec_create public Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit 0c1e08b5901e54c70cf72c74837a8ed8cc77f0b8) --- source3/include/messages.h | 5 +++++ source3/lib/messages.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source3/include/messages.h b/source3/include/messages.h index ea89383e02d..cf0d76a77c8 100644 --- a/source3/include/messages.h +++ b/source3/include/messages.h @@ -153,6 +153,11 @@ int messaging_cleanup(struct messaging_context *msg_ctx, pid_t pid); bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg); +struct messaging_rec *messaging_rec_create( + TALLOC_CTX *mem_ctx, struct server_id src, struct server_id dst, + uint32_t msg_type, const struct iovec *iov, int iovlen, + const int *fds, size_t num_fds); + #include "librpc/gen_ndr/ndr_messaging.h" #endif diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 69dfbf30b67..d40a4b369c6 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -108,7 +108,7 @@ static void ping_message(struct messaging_context *msg_ctx, messaging_send(msg_ctx, src, MSG_PONG, data); } -static struct messaging_rec *messaging_rec_create( +struct messaging_rec *messaging_rec_create( TALLOC_CTX *mem_ctx, struct server_id src, struct server_id dst, uint32_t msg_type, const struct iovec *iov, int iovlen, const int *fds, size_t num_fds) -- 2.13.5 From 6800258929410e4507cbd7cc28cc2270e6439506 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Jun 2017 08:38:53 +0200 Subject: [PATCH 05/13] notifyd: Use messaging_register for MSG_SMB_NOTIFY_REC_CHANGE Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit b6079af1c41481714ac981fdd19f89ee197b4200) --- source3/smbd/notifyd/notifyd.c | 73 ++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index b92c2f9d185..666befb6579 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -31,6 +31,7 @@ #include "notifyd.h" #include "lib/util/server_id_db.h" #include "lib/util/tevent_unix.h" +#include "lib/util/tevent_ntstatus.h" #include "ctdbd_conn.h" #include "ctdb_srvids.h" #include "server_id_db_util.h" @@ -121,9 +122,9 @@ struct notifyd_peer { time_t last_broadcast; }; -static bool notifyd_rec_change(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); +static void notifyd_rec_change(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); static bool notifyd_trigger(struct messaging_context *msg_ctx, struct messaging_rec **prec, void *private_data); @@ -194,6 +195,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct tevent_req *req, *subreq; struct notifyd_state *state; struct server_id_db *names_db; + NTSTATUS status; int ret; req = tevent_req_create(mem_ctx, &state, struct notifyd_state); @@ -216,19 +218,17 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, return tevent_req_post(req, ev); } - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_REC_CHANGE, - notifyd_rec_change, state); - if (tevent_req_nomem(subreq, req)) { + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_REC_CHANGE, + notifyd_rec_change); + if (tevent_req_nterror(req, status)) { return tevent_req_post(req, ev); } - tevent_req_set_callback(subreq, notifyd_handler_done, req); subreq = messaging_handler_send(state, ev, msg_ctx, MSG_SMB_NOTIFY_TRIGGER, notifyd_trigger, state); if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + goto deregister_rec_change; } tevent_req_set_callback(subreq, notifyd_handler_done, req); @@ -236,7 +236,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, MSG_SMB_NOTIFY_GET_DB, notifyd_get_db, state); if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + goto deregister_rec_change; } tevent_req_set_callback(subreq, notifyd_handler_done, req); @@ -247,7 +247,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, DEBUG(10, ("%s: server_id_db_add failed: %s\n", __func__, strerror(ret))); tevent_req_error(req, ret); - return tevent_req_post(req, ev); + goto deregister_rec_change; } if (ctdbd_conn == NULL) { @@ -263,13 +263,13 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, MSG_SMB_NOTIFY_DB, notifyd_got_db, state); if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + goto deregister_rec_change; } tevent_req_set_callback(subreq, notifyd_handler_done, req); state->log = talloc_zero(state, struct messaging_reclog); if (tevent_req_nomem(state->log, req)) { - return tevent_req_post(req, ev); + goto deregister_rec_change; } subreq = notifyd_broadcast_reclog_send( @@ -277,7 +277,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, messaging_server_id(msg_ctx), state->log); if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + goto deregister_rec_change; } tevent_req_set_callback(subreq, notifyd_broadcast_reclog_finished, @@ -285,7 +285,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, subreq = notifyd_clean_peers_send(state, ev, state); if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + goto deregister_rec_change; } tevent_req_set_callback(subreq, notifyd_clean_peers_finished, req); @@ -295,11 +295,15 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, notifyd_snoop_broadcast, state); if (ret != 0) { tevent_req_error(req, ret); - return tevent_req_post(req, ev); + goto deregister_rec_change; } #endif return req; + +deregister_rec_change: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_REC_CHANGE, state); + return tevent_req_post(req, ev); } static void notifyd_handler_done(struct tevent_req *subreq) @@ -567,40 +571,38 @@ static bool notifyd_parse_rec_change(uint8_t *buf, size_t bufsize, return true; } -static bool notifyd_rec_change(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data) +static void notifyd_rec_change(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data) { struct notifyd_state *state = talloc_get_type_abort( private_data, struct notifyd_state); struct server_id_buf idbuf; - struct messaging_rec *rec = *prec; struct notify_rec_change_msg *msg; size_t pathlen; bool ok; - DEBUG(10, ("%s: Got %d bytes from %s\n", __func__, - (unsigned)rec->buf.length, - server_id_str_buf(rec->src, &idbuf))); + DBG_DEBUG("Got %zu bytes from %s\n", data->length, + server_id_str_buf(src, &idbuf)); - ok = notifyd_parse_rec_change(rec->buf.data, rec->buf.length, + ok = notifyd_parse_rec_change(data->data, data->length, &msg, &pathlen); if (!ok) { - return true; + return; } ok = notifyd_apply_rec_change( - &rec->src, msg->path, pathlen, &msg->instance, + &src, msg->path, pathlen, &msg->instance, state->entries, state->sys_notify_watch, state->sys_notify_ctx, state->msg_ctx); if (!ok) { DEBUG(1, ("%s: notifyd_apply_rec_change failed, ignoring\n", __func__)); - return true; + return; } if ((state->log == NULL) || (state->ctdbd_conn == NULL)) { - return true; + return; } #ifdef CLUSTER_SUPPORT @@ -608,6 +610,7 @@ static bool notifyd_rec_change(struct messaging_context *msg_ctx, struct messaging_rec **tmp; struct messaging_reclog *log; + struct iovec iov = { .iov_base = data->data, .iov_len = data->length }; log = state->log; @@ -615,11 +618,19 @@ static bool notifyd_rec_change(struct messaging_context *msg_ctx, log->num_recs+1); if (tmp == NULL) { DEBUG(1, ("%s: talloc_realloc failed, ignoring\n", __func__)); - return true; + return; } log->recs = tmp; - log->recs[log->num_recs] = talloc_move(log->recs, prec); + log->recs[log->num_recs] = messaging_rec_create( + log->recs, src, messaging_server_id(msg_ctx), + msg_type, &iov, 1, NULL, 0); + + if (log->recs[log->num_recs] == NULL) { + DBG_WARNING("messaging_rec_create failed, ignoring\n"); + return; + } + log->num_recs += 1; if (log->num_recs >= 100) { @@ -632,8 +643,6 @@ static bool notifyd_rec_change(struct messaging_context *msg_ctx, } #endif - - return true; } struct notifyd_trigger_state { -- 2.13.5 From 6b42fbd96ce09422caf3015bad21a45c2a38551d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Jun 2017 08:45:17 +0200 Subject: [PATCH 06/13] notifyd: Use messaging_register for MSG_SMB_NOTIFY_TRIGGER Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit db15feb162326cb03fb06df24bcdafa5d5cb3087) --- source3/smbd/notifyd/notifyd.c | 61 ++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index 666befb6579..574037582f5 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -125,9 +125,9 @@ struct notifyd_peer { static void notifyd_rec_change(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data); -static bool notifyd_trigger(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); +static void notifyd_trigger(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); static bool notifyd_get_db(struct messaging_context *msg_ctx, struct messaging_rec **prec, void *private_data); @@ -224,19 +224,17 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, return tevent_req_post(req, ev); } - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_TRIGGER, - notifyd_trigger, state); - if (tevent_req_nomem(subreq, req)) { + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_TRIGGER, + notifyd_trigger); + if (tevent_req_nterror(req, status)) { goto deregister_rec_change; } - tevent_req_set_callback(subreq, notifyd_handler_done, req); subreq = messaging_handler_send(state, ev, msg_ctx, MSG_SMB_NOTIFY_GET_DB, notifyd_get_db, state); if (tevent_req_nomem(subreq, req)) { - goto deregister_rec_change; + goto deregister_trigger; } tevent_req_set_callback(subreq, notifyd_handler_done, req); @@ -247,7 +245,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, DEBUG(10, ("%s: server_id_db_add failed: %s\n", __func__, strerror(ret))); tevent_req_error(req, ret); - goto deregister_rec_change; + goto deregister_trigger; } if (ctdbd_conn == NULL) { @@ -263,13 +261,13 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, MSG_SMB_NOTIFY_DB, notifyd_got_db, state); if (tevent_req_nomem(subreq, req)) { - goto deregister_rec_change; + goto deregister_trigger; } tevent_req_set_callback(subreq, notifyd_handler_done, req); state->log = talloc_zero(state, struct messaging_reclog); if (tevent_req_nomem(state->log, req)) { - goto deregister_rec_change; + goto deregister_trigger; } subreq = notifyd_broadcast_reclog_send( @@ -277,7 +275,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, messaging_server_id(msg_ctx), state->log); if (tevent_req_nomem(subreq, req)) { - goto deregister_rec_change; + goto deregister_trigger; } tevent_req_set_callback(subreq, notifyd_broadcast_reclog_finished, @@ -285,7 +283,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, subreq = notifyd_clean_peers_send(state, ev, state); if (tevent_req_nomem(subreq, req)) { - goto deregister_rec_change; + goto deregister_trigger; } tevent_req_set_callback(subreq, notifyd_clean_peers_finished, req); @@ -295,12 +293,14 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, notifyd_snoop_broadcast, state); if (ret != 0) { tevent_req_error(req, ret); - goto deregister_rec_change; + goto deregister_trigger; } #endif return req; +deregister_trigger: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_TRIGGER, state); deregister_rec_change: messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_REC_CHANGE, state); return tevent_req_post(req, ev); @@ -655,34 +655,33 @@ struct notifyd_trigger_state { static void notifyd_trigger_parser(TDB_DATA key, TDB_DATA data, void *private_data); -static bool notifyd_trigger(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data) +static void notifyd_trigger(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data) { struct notifyd_state *state = talloc_get_type_abort( private_data, struct notifyd_state); struct server_id my_id = messaging_server_id(msg_ctx); - struct messaging_rec *rec = *prec; struct notifyd_trigger_state tstate; const char *path; const char *p, *next_p; - if (rec->buf.length < offsetof(struct notify_trigger_msg, path) + 1) { - DEBUG(1, ("message too short, ignoring: %u\n", - (unsigned)rec->buf.length)); - return true; + if (data->length < offsetof(struct notify_trigger_msg, path) + 1) { + DBG_WARNING("message too short, ignoring: %zu\n", + data->length); + return; } - if (rec->buf.data[rec->buf.length-1] != 0) { + if (data->data[data->length-1] != 0) { DEBUG(1, ("%s: path not 0-terminated, ignoring\n", __func__)); - return true; + return; } tstate.msg_ctx = msg_ctx; - tstate.covered_by_sys_notify = (rec->src.vnn == my_id.vnn); - tstate.covered_by_sys_notify &= !server_id_equal(&rec->src, &my_id); + tstate.covered_by_sys_notify = (src.vnn == my_id.vnn); + tstate.covered_by_sys_notify &= !server_id_equal(&src, &my_id); - tstate.msg = (struct notify_trigger_msg *)rec->buf.data; + tstate.msg = (struct notify_trigger_msg *)data->data; path = tstate.msg->path; DEBUG(10, ("%s: Got trigger_msg action=%u, filter=%u, path=%s\n", @@ -692,7 +691,7 @@ static bool notifyd_trigger(struct messaging_context *msg_ctx, if (path[0] != '/') { DEBUG(1, ("%s: path %s does not start with /, ignoring\n", __func__, path)); - return true; + return; } for (p = strchr(path+1, '/'); p != NULL; p = next_p) { @@ -716,7 +715,7 @@ static bool notifyd_trigger(struct messaging_context *msg_ctx, continue; } - if (rec->src.vnn != my_id.vnn) { + if (src.vnn != my_id.vnn) { continue; } @@ -731,8 +730,6 @@ static bool notifyd_trigger(struct messaging_context *msg_ctx, notifyd_trigger_parser, &tstate); } } - - return true; } static void notifyd_send_delete(struct messaging_context *msg_ctx, -- 2.13.5 From e88a53dad5036e7dfc23ae8b31bb24222fbc3e97 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Jun 2017 08:48:45 +0200 Subject: [PATCH 07/13] notifyd: Use messaging_register for MSG_SMB_NOTIFY_GET_DB Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit dc39bb45624f8d6859dadc3c9a9a85793a5a7d0d) --- source3/smbd/notifyd/notifyd.c | 47 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index 574037582f5..2be0ae2d3f9 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -128,9 +128,9 @@ static void notifyd_rec_change(struct messaging_context *msg_ctx, static void notifyd_trigger(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data); -static bool notifyd_get_db(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); +static void notifyd_get_db(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); #ifdef CLUSTER_SUPPORT static bool notifyd_got_db(struct messaging_context *msg_ctx, @@ -230,13 +230,11 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, goto deregister_rec_change; } - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_GET_DB, - notifyd_get_db, state); - if (tevent_req_nomem(subreq, req)) { + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_GET_DB, + notifyd_get_db); + if (tevent_req_nterror(req, status)) { goto deregister_trigger; } - tevent_req_set_callback(subreq, notifyd_handler_done, req); names_db = messaging_names_db(msg_ctx); @@ -245,7 +243,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, DEBUG(10, ("%s: server_id_db_add failed: %s\n", __func__, strerror(ret))); tevent_req_error(req, ret); - goto deregister_trigger; + goto deregister_get_db; } if (ctdbd_conn == NULL) { @@ -261,13 +259,13 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, MSG_SMB_NOTIFY_DB, notifyd_got_db, state); if (tevent_req_nomem(subreq, req)) { - goto deregister_trigger; + goto deregister_get_db; } tevent_req_set_callback(subreq, notifyd_handler_done, req); state->log = talloc_zero(state, struct messaging_reclog); if (tevent_req_nomem(state->log, req)) { - goto deregister_trigger; + goto deregister_get_db; } subreq = notifyd_broadcast_reclog_send( @@ -275,7 +273,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, messaging_server_id(msg_ctx), state->log); if (tevent_req_nomem(subreq, req)) { - goto deregister_trigger; + goto deregister_get_db; } tevent_req_set_callback(subreq, notifyd_broadcast_reclog_finished, @@ -283,7 +281,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, subreq = notifyd_clean_peers_send(state, ev, state); if (tevent_req_nomem(subreq, req)) { - goto deregister_trigger; + goto deregister_get_db; } tevent_req_set_callback(subreq, notifyd_clean_peers_finished, req); @@ -293,12 +291,14 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, notifyd_snoop_broadcast, state); if (ret != 0) { tevent_req_error(req, ret); - goto deregister_trigger; + goto deregister_get_db; } #endif return req; +deregister_get_db: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_GET_DB, state); deregister_trigger: messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_TRIGGER, state); deregister_rec_change: @@ -851,13 +851,12 @@ static void notifyd_send_delete(struct messaging_context *msg_ctx, } } -static bool notifyd_get_db(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data) +static void notifyd_get_db(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data) { struct notifyd_state *state = talloc_get_type_abort( private_data, struct notifyd_state); - struct messaging_rec *rec = *prec; struct server_id_buf id1, id2; NTSTATUS status; uint64_t rec_index = UINT64_MAX; @@ -868,11 +867,11 @@ static bool notifyd_get_db(struct messaging_context *msg_ctx, dbsize = dbwrap_marshall(state->entries, NULL, 0); - buf = talloc_array(rec, uint8_t, dbsize); + buf = talloc_array(talloc_tos(), uint8_t, dbsize); if (buf == NULL) { DEBUG(1, ("%s: talloc_array(%ju) failed\n", __func__, (uintmax_t)dbsize)); - return true; + return; } dbsize = dbwrap_marshall(state->entries, buf, dbsize); @@ -882,7 +881,7 @@ static bool notifyd_get_db(struct messaging_context *msg_ctx, (uintmax_t)talloc_get_size(buf), (uintmax_t)dbsize)); TALLOC_FREE(buf); - return true; + return; } if (state->log != NULL) { @@ -898,17 +897,15 @@ static bool notifyd_get_db(struct messaging_context *msg_ctx, DEBUG(10, ("%s: Sending %ju bytes to %s->%s\n", __func__, (uintmax_t)iov_buflen(iov, ARRAY_SIZE(iov)), server_id_str_buf(messaging_server_id(msg_ctx), &id1), - server_id_str_buf(rec->src, &id2))); + server_id_str_buf(src, &id2))); - status = messaging_send_iov(msg_ctx, rec->src, MSG_SMB_NOTIFY_DB, + status = messaging_send_iov(msg_ctx, src, MSG_SMB_NOTIFY_DB, iov, ARRAY_SIZE(iov), NULL, 0); TALLOC_FREE(buf); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("%s: messaging_send_iov failed: %s\n", __func__, nt_errstr(status))); } - - return true; } #ifdef CLUSTER_SUPPORT -- 2.13.5 From 333c694ee7e0b1350f0f16170a084724f9862eca Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Jun 2017 08:56:35 +0200 Subject: [PATCH 08/13] notifyd: Use messaging_register for MSG_SMB_NOTIFY_DB Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit 9430fab61cb746e590db307af37219f8f29b7fd8) --- source3/smbd/notifyd/notifyd.c | 71 +++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index 2be0ae2d3f9..b049c128a4f 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -133,9 +133,9 @@ static void notifyd_get_db(struct messaging_context *msg_ctx, struct server_id src, DATA_BLOB *data); #ifdef CLUSTER_SUPPORT -static bool notifyd_got_db(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); +static void notifyd_got_db(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); static void notifyd_broadcast_reclog(struct ctdbd_connection *ctdbd_conn, struct server_id src, struct messaging_reclog *log); @@ -192,7 +192,10 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, sys_notify_watch_fn sys_notify_watch, struct sys_notify_context *sys_notify_ctx) { - struct tevent_req *req, *subreq; + struct tevent_req *req; +#ifdef CLUSTER_SUPPORT + struct tevent_req *subreq; +#endif struct notifyd_state *state; struct server_id_db *names_db; NTSTATUS status; @@ -255,17 +258,15 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, } #ifdef CLUSTER_SUPPORT - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_DB, - notifyd_got_db, state); - if (tevent_req_nomem(subreq, req)) { + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_DB, + notifyd_got_db); + if (tevent_req_nterror(req, status)) { goto deregister_get_db; } - tevent_req_set_callback(subreq, notifyd_handler_done, req); state->log = talloc_zero(state, struct messaging_reclog); if (tevent_req_nomem(state->log, req)) { - goto deregister_get_db; + goto deregister_db; } subreq = notifyd_broadcast_reclog_send( @@ -273,7 +274,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, messaging_server_id(msg_ctx), state->log); if (tevent_req_nomem(subreq, req)) { - goto deregister_get_db; + goto deregister_db; } tevent_req_set_callback(subreq, notifyd_broadcast_reclog_finished, @@ -281,7 +282,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, subreq = notifyd_clean_peers_send(state, ev, state); if (tevent_req_nomem(subreq, req)) { - goto deregister_get_db; + goto deregister_db; } tevent_req_set_callback(subreq, notifyd_clean_peers_finished, req); @@ -291,12 +292,16 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, notifyd_snoop_broadcast, state); if (ret != 0) { tevent_req_error(req, ret); - goto deregister_get_db; + goto deregister_db; } #endif return req; +#ifdef CLUSTER_SUPPORT +deregister_db: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_DB, state); +#endif deregister_get_db: messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_GET_DB, state); deregister_trigger: @@ -913,13 +918,12 @@ static void notifyd_get_db(struct messaging_context *msg_ctx, static int notifyd_add_proxy_syswatches(struct db_record *rec, void *private_data); -static bool notifyd_got_db(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data) +static void notifyd_got_db(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data) { struct notifyd_state *state = talloc_get_type_abort( private_data, struct notifyd_state); - struct messaging_rec *rec = *prec; struct notifyd_peer *p = NULL; struct server_id_buf idbuf; NTSTATUS status; @@ -927,52 +931,49 @@ static bool notifyd_got_db(struct messaging_context *msg_ctx, size_t i; for (i=0; inum_peers; i++) { - if (server_id_equal(&rec->src, &state->peers[i]->pid)) { + if (server_id_equal(&src, &state->peers[i]->pid)) { p = state->peers[i]; break; } } if (p == NULL) { - DEBUG(10, ("%s: Did not find peer for db from %s\n", - __func__, server_id_str_buf(rec->src, &idbuf))); - return true; + DBG_DEBUG("Did not find peer for db from %s\n", + server_id_str_buf(src, &idbuf)); + return; } - if (rec->buf.length < 8) { - DEBUG(10, ("%s: Got short db length %u from %s\n", __func__, - (unsigned)rec->buf.length, - server_id_str_buf(rec->src, &idbuf))); + if (data->length < 8) { + DBG_DEBUG("Got short db length %zu from %s\n", data->length, + server_id_str_buf(src, &idbuf)); TALLOC_FREE(p); - return true; + return; } - p->rec_index = BVAL(rec->buf.data, 0); + p->rec_index = BVAL(data->data, 0); p->db = db_open_rbt(p); if (p->db == NULL) { DEBUG(10, ("%s: db_open_rbt failed\n", __func__)); TALLOC_FREE(p); - return true; + return; } - status = dbwrap_unmarshall(p->db, rec->buf.data + 8, - rec->buf.length - 8); + status = dbwrap_unmarshall(p->db, data->data + 8, + data->length - 8); if (!NT_STATUS_IS_OK(status)) { DEBUG(10, ("%s: dbwrap_unmarshall returned %s for db %s\n", __func__, nt_errstr(status), - server_id_str_buf(rec->src, &idbuf))); + server_id_str_buf(src, &idbuf))); TALLOC_FREE(p); - return true; + return; } dbwrap_traverse_read(p->db, notifyd_add_proxy_syswatches, state, &count); DEBUG(10, ("%s: Database from %s contained %d records\n", __func__, - server_id_str_buf(rec->src, &idbuf), count)); - - return true; + server_id_str_buf(src, &idbuf), count)); } static void notifyd_broadcast_reclog(struct ctdbd_connection *ctdbd_conn, -- 2.13.5 From 58563a55a9345ce74c889bf3dcefa539b899ab60 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Jun 2017 08:57:18 +0200 Subject: [PATCH 09/13] notifyd: Remove notifyd_handler_done Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit 197186a1fcc2c190fac9a16893234c337e6ec01c) --- source3/smbd/notifyd/notifyd.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index b049c128a4f..052fbcc101f 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -175,8 +175,6 @@ static int sys_notify_watch_dummy( return 0; } -static void notifyd_handler_done(struct tevent_req *subreq); - #ifdef CLUSTER_SUPPORT static void notifyd_broadcast_reclog_finished(struct tevent_req *subreq); static void notifyd_clean_peers_finished(struct tevent_req *subreq); @@ -311,17 +309,6 @@ deregister_rec_change: return tevent_req_post(req, ev); } -static void notifyd_handler_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data( - subreq, struct tevent_req); - int ret; - - ret = messaging_handler_recv(subreq); - TALLOC_FREE(subreq); - tevent_req_error(req, ret); -} - #ifdef CLUSTER_SUPPORT static void notifyd_broadcast_reclog_finished(struct tevent_req *subreq) -- 2.13.5 From 66615bd2d4287c2c20de392e08c6211f85bee76c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Jun 2017 09:01:46 +0200 Subject: [PATCH 10/13] messaging: Remove messaging_handler_send This did not really take off, notifyd was the only user Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Fri Jul 7 05:11:48 CEST 2017 on sn-devel-144 (cherry picked from commit 5eccc2fd0072409f166c63e6876266f926411423) --- source3/include/messages.h | 8 ----- source3/lib/messages.c | 81 ---------------------------------------------- 2 files changed, 89 deletions(-) diff --git a/source3/include/messages.h b/source3/include/messages.h index cf0d76a77c8..0d98d2107b2 100644 --- a/source3/include/messages.h +++ b/source3/include/messages.h @@ -141,14 +141,6 @@ struct tevent_req *messaging_read_send(TALLOC_CTX *mem_ctx, int messaging_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct messaging_rec **presult); -struct tevent_req *messaging_handler_send( - TALLOC_CTX *mem_ctx, struct tevent_context *ev, - struct messaging_context *msg_ctx, uint32_t msg_type, - bool (*handler)(struct messaging_context *msg_ctx, - struct messaging_rec **rec, void *private_data), - void *private_data); -int messaging_handler_recv(struct tevent_req *req); - int messaging_cleanup(struct messaging_context *msg_ctx, pid_t pid); bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg); diff --git a/source3/lib/messages.c b/source3/lib/messages.c index d40a4b369c6..c70fb8150f7 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -904,87 +904,6 @@ int messaging_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, return 0; } -struct messaging_handler_state { - struct tevent_context *ev; - struct messaging_context *msg_ctx; - uint32_t msg_type; - bool (*handler)(struct messaging_context *msg_ctx, - struct messaging_rec **rec, void *private_data); - void *private_data; -}; - -static void messaging_handler_got_msg(struct tevent_req *subreq); - -struct tevent_req *messaging_handler_send( - TALLOC_CTX *mem_ctx, struct tevent_context *ev, - struct messaging_context *msg_ctx, uint32_t msg_type, - bool (*handler)(struct messaging_context *msg_ctx, - struct messaging_rec **rec, void *private_data), - void *private_data) -{ - struct tevent_req *req, *subreq; - struct messaging_handler_state *state; - - req = tevent_req_create(mem_ctx, &state, - struct messaging_handler_state); - if (req == NULL) { - return NULL; - } - state->ev = ev; - state->msg_ctx = msg_ctx; - state->msg_type = msg_type; - state->handler = handler; - state->private_data = private_data; - - subreq = messaging_read_send(state, state->ev, state->msg_ctx, - state->msg_type); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, messaging_handler_got_msg, req); - return req; -} - -static void messaging_handler_got_msg(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data( - subreq, struct tevent_req); - struct messaging_handler_state *state = tevent_req_data( - req, struct messaging_handler_state); - struct messaging_rec *rec; - int ret; - bool ok; - - ret = messaging_read_recv(subreq, state, &rec); - TALLOC_FREE(subreq); - if (tevent_req_error(req, ret)) { - return; - } - - subreq = messaging_read_send(state, state->ev, state->msg_ctx, - state->msg_type); - if (tevent_req_nomem(subreq, req)) { - return; - } - tevent_req_set_callback(subreq, messaging_handler_got_msg, req); - - ok = state->handler(state->msg_ctx, &rec, state->private_data); - TALLOC_FREE(rec); - if (ok) { - /* - * Next round - */ - return; - } - TALLOC_FREE(subreq); - tevent_req_done(req); -} - -int messaging_handler_recv(struct tevent_req *req) -{ - return tevent_req_simple_recv_unix(req); -} - static bool messaging_append_new_waiters(struct messaging_context *msg_ctx) { if (msg_ctx->num_new_waiters == 0) { -- 2.13.5 From 56f3048aa159e6e5100096c4d31b55ad57610155 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 13 Jul 2017 16:01:53 +0200 Subject: [PATCH 11/13] selftest: enable kernel change notifications in the fileserver environment This environment is currently not used for any test in the smb2 testsuite, so this change doesn't affect any existing test. A subsequent commit will add a test for change notifications with kernel change notify enabled. It verifies a bug (this one) that only crops up in such a setup and causes rename events to get lost. Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison (backported from commit fb8e0343ebebac322d545b54c33b3c1e7bcda393) --- selftest/target/Samba3.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index b3bcc8a60b4..66ac1e1f45f 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -781,6 +781,8 @@ sub setup_fileserver($$) push(@dirs,$tarmode_sharedir); my $fileserver_options = " + kernel change notify = yes + [lowercase] path = $lower_case_share_dir comment = smb username is [%U] -- 2.13.5 From f12b2b67a90c934445d563e9203e0344a1db8fa7 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 13 Jul 2017 16:04:50 +0200 Subject: [PATCH 12/13] selftest: run smb2.notify-inotify testsuite against fileserver Next commit adds the suite and a test. Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison (cherry picked from commit 71a68d22a15d12c4038026dd065c54721ddc6723) --- source3/selftest/tests.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 746f3ea0bf6..18045123016 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -56,6 +56,7 @@ finally: have_libarchive = ("HAVE_LIBARCHIVE" in config_hash) have_linux_kernel_oplocks = ("HAVE_KERNEL_OPLOCKS_LINUX" in config_hash) +have_inotify = ("HAVE_INOTIFY" in config_hash) plantestsuite("samba3.blackbox.success", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/test_success.sh")]) plantestsuite("samba3.blackbox.failure", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/test_failure.sh")]) @@ -456,6 +457,9 @@ for t in tests: elif t == "smb2.kernel-oplocks": if have_linux_kernel_oplocks: plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER/kernel_oplocks -U$USERNAME%$PASSWORD') + elif t == "smb2.notify-inotify": + if have_inotify: + plansmbtorture4testsuite(t, "fileserver", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD') elif t == "vfs.acl_xattr": plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD') else: -- 2.13.5 From c2972b3c2730045ae5b28a6ea1cd71623fec9ccf Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 13 Jul 2017 16:05:49 +0200 Subject: [PATCH 13/13] s4/torture: add a test for rename change notification with inotify enabled This is already fixed in master by 5eccc2fd0072409f166c63e6876266f926411423~10..5eccc2fd0072409f166c63e6876266f926411423. Bug: https://bugzilla.samba.org/show_bug.cgi?id=12903 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Sat Aug 26 05:05:08 CEST 2017 on sn-devel-144 (backported from commit 51f40a0e1d10069f55a5884ff1579e8f15f10a1e) --- source4/torture/smb2/notify.c | 158 ++++++++++++++++++++++++++++++++++++++++++ source4/torture/smb2/smb2.c | 1 + 2 files changed, 159 insertions(+) diff --git a/source4/torture/smb2/notify.c b/source4/torture/smb2/notify.c index 90f5ad9a633..8ca413a9b01 100644 --- a/source4/torture/smb2/notify.c +++ b/source4/torture/smb2/notify.c @@ -2354,6 +2354,151 @@ static bool torture_smb2_notify_rmdir4(struct torture_context *torture, return torture_smb2_notify_rmdir(torture, tree1, tree2, true); } +static void notify_timeout(struct tevent_context *ev, + struct tevent_timer *te, + struct timeval current_time, + void *private_data) +{ + struct smb2_request *req = talloc_get_type_abort( + private_data, struct smb2_request); + + smb2_cancel(req); +} + +static bool torture_smb2_inotify_rename(struct torture_context *torture, + struct smb2_tree *tree1, + struct smb2_tree *tree2) +{ + NTSTATUS status; + struct smb2_notify notify; + struct notify_changes change1 = {0}; + struct notify_changes change2 = {0}; + struct smb2_create create; + union smb_setfileinfo sinfo; + struct smb2_handle h1 = {{0}}; + struct smb2_handle h2 = {{0}}; + struct smb2_request *req; + struct tevent_timer *te = NULL; + bool ok = false; + + smb2_deltree(tree1, BASEDIR); + + torture_comment(torture, "Testing change notify of a rename with inotify\n"); + + status = torture_smb2_testdir(tree1, BASEDIR, &h1); + torture_assert_ntstatus_ok_goto(torture, status, ok, done, "torture_smb2_testdir failed"); + + ZERO_STRUCT(create); + create.in.desired_access = SEC_RIGHTS_FILE_READ | + SEC_RIGHTS_FILE_WRITE| + SEC_RIGHTS_FILE_ALL; + create.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; + create.in.file_attributes = FILE_ATTRIBUTE_NORMAL; + create.in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE | + NTCREATEX_SHARE_ACCESS_DELETE; + create.in.create_disposition = NTCREATEX_DISP_OPEN_IF; + create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS; + create.in.fname = BASEDIR "\\subdir-name"; + + status = smb2_create(tree2, torture, &create); + torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_create failed\n"); + h2 = create.out.file.handle; + + ZERO_STRUCT(notify); + notify.level = RAW_NOTIFY_SMB2; + notify.in.buffer_size = 4096; + notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME; + notify.in.file.handle = h1; + notify.in.recursive = true; + req = smb2_notify_send(tree1, ¬ify); + torture_assert_not_null_goto(torture, req, ok, done, "smb2_notify_send failed\n"); + + while (!NT_STATUS_EQUAL(req->status, STATUS_PENDING)) { + if (tevent_loop_once(torture->ev) != 0) { + return false; + } + } + + ZERO_STRUCT(sinfo); + sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION; + sinfo.rename_information.in.file.handle = h2; + sinfo.rename_information.in.new_name = BASEDIR "\\subdir-name-r"; + + status = smb2_setinfo_file(tree2, &sinfo); + torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_setinfo_file failed\n"); + + smb2_util_close(tree2, h2); + + te = tevent_add_timer(torture->ev, + tree1, + tevent_timeval_current_ofs(1, 0), + notify_timeout, + req); + torture_assert_not_null_goto(torture, te, ok, done, "tevent_add_timer failed\n"); + + status = smb2_notify_recv(req, torture, ¬ify); + torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_notify_recv failed\n"); + + torture_assert_goto(torture, notify.out.num_changes == 1 || notify.out.num_changes == 2, + ok, done, "bad notify\n"); + + change1 = notify.out.changes[0]; + if (notify.out.num_changes == 2) { + change2 = notify.out.changes[1]; + } else { + /* + * We may only get one event at a time, so check for the + * matching second event for the oldname/newname or + * removed/added pair. + */ + ZERO_STRUCT(notify); + notify.level = RAW_NOTIFY_SMB2; + notify.in.buffer_size = 4096; + notify.in.completion_filter = FILE_NOTIFY_CHANGE_NAME; + notify.in.file.handle = h1; + notify.in.recursive = true; + req = smb2_notify_send(tree1, ¬ify); + torture_assert_not_null_goto(torture, req, ok, done, "smb2_notify_send failed\n"); + + status = smb2_notify_recv(req, torture, ¬ify); + torture_assert_ntstatus_ok_goto(torture, status, ok, done, "smb2_notify_recv failed\n"); + + torture_assert_goto(torture, notify.out.num_changes == 1, ok, done, + "bad notify\n"); + + change2 = notify.out.changes[0]; + } + + if ((change1.action != NOTIFY_ACTION_OLD_NAME) && + (change1.action != NOTIFY_ACTION_REMOVED)) + { + torture_fail_goto(torture, done, "bad change notification\n"); + } + torture_assert_str_equal_goto(torture, change1.name.s, "subdir-name", + ok, done, "bad change notification\n"); + + if ((change2.action != NOTIFY_ACTION_NEW_NAME) && + (change2.action != NOTIFY_ACTION_ADDED)) + { + torture_fail_goto(torture, done, "bad change notification\n"); + } + torture_assert_str_equal_goto(torture, change2.name.s, "subdir-name-r", + ok, done, "bad change notification\n"); + + ok = true; +done: + if (!smb2_util_handle_empty(h1)) { + smb2_util_close(tree2, h1); + } + if (!smb2_util_handle_empty(h2)) { + smb2_util_close(tree2, h2); + } + + smb2_deltree(tree1, BASEDIR); + return ok; +} + /* basic testing of SMB2 change notify */ @@ -2393,3 +2538,16 @@ struct torture_suite *torture_smb2_notify_init(void) return suite; } +/* + basic testing of SMB2 change notify +*/ +struct torture_suite *torture_smb2_notify_inotify_init(void) +{ + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "notify-inotify"); + + suite->description = talloc_strdup(suite, "SMB2-NOTIFY tests that use inotify"); + + torture_suite_add_2smb2_test(suite, "inotify-rename", torture_smb2_inotify_rename); + + return suite; +} diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c index cfea9832783..0b82276929d 100644 --- a/source4/torture/smb2/smb2.c +++ b/source4/torture/smb2/smb2.c @@ -155,6 +155,7 @@ NTSTATUS torture_smb2_init(void) torture_suite_add_suite(suite, torture_smb2_create_init()); torture_suite_add_suite(suite, torture_smb2_acls_init()); torture_suite_add_suite(suite, torture_smb2_notify_init()); + torture_suite_add_suite(suite, torture_smb2_notify_inotify_init()); torture_suite_add_suite(suite, torture_smb2_notify_disabled_init()); torture_suite_add_suite(suite, torture_smb2_durable_open_init()); torture_suite_add_suite(suite, torture_smb2_durable_open_disconnect_init()); -- 2.13.5