[PATCH] Simplify ctdbd_conn.c a bit
Volker Lendecke
Volker.Lendecke at SerNet.DE
Sat Jul 11 13:55:47 UTC 2015
Hi!
Review&push appreciated!
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 635f150e100d62d354194e004a0d6b74e099a730 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 1 Jul 2015 17:00:43 +0200
Subject: [PATCH 1/9] ctdbd_conn: Fix a memleak
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index fae086a..5dab65a 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -390,6 +390,7 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
DEBUG(1, ("Got a message without having a msg ctx, "
"dropping msg %llu\n",
(long long unsigned)msg->srvid));
+ TALLOC_FREE(hdr);
goto next_pkt;
}
--
1.9.1
From 7d619ed87d11b1977b4b506645108a5befdf2a7b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 11 Jul 2015 12:21:55 +0200
Subject: [PATCH 2/9] ctdbd_conn: Rename "ret"->"ok"
We'll need "ret" soon
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 5dab65a..3ae6a44 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -396,15 +396,15 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
if ((conn->release_ip_handler != NULL)
&& (msg->srvid == CTDB_SRVID_RELEASE_IP)) {
- bool ret;
+ bool ok;
/* must be dispatched immediately */
DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
- ret = conn->release_ip_handler((const char *)msg->data,
+ ok = conn->release_ip_handler((const char *)msg->data,
conn->release_ip_priv);
TALLOC_FREE(hdr);
- if (ret) {
+ if (ok) {
/*
* We need to release the ip,
* so return an error to the upper layers.
--
1.9.1
From 47af5a7014e7443f5dd74e7840bc96898245aab5 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 11 Jul 2015 12:23:22 +0200
Subject: [PATCH 3/9] ctdbd_conn: Make ctdb_read_packet return 0/errno
A little less dependencies
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 46 ++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 3ae6a44..075beb3 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -301,8 +301,8 @@ static int ctdbd_connect(int *pfd)
return 0;
}
-static NTSTATUS ctdb_read_packet(int fd, TALLOC_CTX *mem_ctx,
- struct ctdb_req_header **result)
+static int ctdb_read_packet(int fd, TALLOC_CTX *mem_ctx,
+ struct ctdb_req_header **result)
{
int timeout = lp_ctdb_timeout();
struct ctdb_req_header *req;
@@ -317,31 +317,31 @@ static NTSTATUS ctdb_read_packet(int fd, TALLOC_CTX *mem_ctx,
if (timeout != -1) {
ret = poll_one_fd(fd, POLLIN, timeout, &revents);
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ return errno;
}
if (ret == 0) {
- return NT_STATUS_IO_TIMEOUT;
+ return ETIMEDOUT;
}
if (ret != 1) {
- return NT_STATUS_UNEXPECTED_IO_ERROR;
+ return EIO;
}
}
nread = read_data(fd, &msglen, sizeof(msglen));
if (nread == -1) {
- return map_nt_error_from_unix(errno);
+ return errno;
}
if (nread == 0) {
- return NT_STATUS_UNEXPECTED_IO_ERROR;
+ return EIO;
}
if (msglen < sizeof(struct ctdb_req_header)) {
- return NT_STATUS_UNEXPECTED_IO_ERROR;
+ return EIO;
}
req = talloc_size(mem_ctx, msglen);
if (req == NULL) {
- return NT_STATUS_NO_MEMORY;
+ return ENOMEM;
}
talloc_set_name_const(req, "struct ctdb_req_header");
@@ -350,14 +350,14 @@ static NTSTATUS ctdb_read_packet(int fd, TALLOC_CTX *mem_ctx,
nread = read_data(fd, ((char *)req) + sizeof(msglen),
msglen - sizeof(msglen));
if (nread == -1) {
- return map_nt_error_from_unix(errno);
+ return errno;
}
if (nread == 0) {
- return NT_STATUS_UNEXPECTED_IO_ERROR;
+ return EIO;
}
*result = req;
- return NT_STATUS_OK;
+ return 0;
}
/*
@@ -370,13 +370,13 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
struct ctdb_req_header **result)
{
struct ctdb_req_header *hdr;
- NTSTATUS status;
+ int ret;
next_pkt:
- status = ctdb_read_packet(conn->fd, mem_ctx, &hdr);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("ctdb_read_packet failed: %s\n", nt_errstr(status)));
+ ret = ctdb_read_packet(conn->fd, mem_ctx, &hdr);
+ if (ret != 0) {
+ DEBUG(0, ("ctdb_read_packet failed: %s\n", strerror(ret)));
cluster_fatal("ctdbd died\n");
}
@@ -590,10 +590,11 @@ static void ctdbd_socket_handler(struct tevent_context *event_ctx,
private_data, struct ctdbd_connection);
struct ctdb_req_header *hdr = NULL;
NTSTATUS status;
+ int ret;
- status = ctdb_read_packet(conn->fd, talloc_tos(), &hdr);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("ctdb_read_packet failed: %s\n", nt_errstr(status)));
+ ret = ctdb_read_packet(conn->fd, talloc_tos(), &hdr);
+ if (ret != 0) {
+ DEBUG(0, ("ctdb_read_packet failed: %s\n", strerror(ret)));
cluster_fatal("ctdbd died\n");
}
@@ -1402,11 +1403,12 @@ NTSTATUS ctdbd_traverse(uint32_t db_id,
struct ctdb_req_header *hdr = NULL;
struct ctdb_req_message *m;
struct ctdb_rec_data *d;
+ int ret;
- status = ctdb_read_packet(conn->fd, conn, &hdr);
- if (!NT_STATUS_IS_OK(status)) {
+ ret = ctdb_read_packet(conn->fd, conn, &hdr);
+ if (ret != 0) {
DEBUG(0, ("ctdb_read_packet failed: %s\n",
- nt_errstr(status)));
+ strerror(ret)));
cluster_fatal("ctdbd died\n");
}
--
1.9.1
From 9e10d7557f6f860d40eff278e127ba5f0bd3d302 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 19 Jun 2015 11:47:01 +0200
Subject: [PATCH 4/9] ctdbd_conn: Convert ctdb_handle_message to return 0/errno
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 075beb3..3d23f58 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -539,15 +539,15 @@ int ctdbd_conn_get_fd(struct ctdbd_connection *conn)
/*
* Packet handler to receive and handle a ctdb message
*/
-static NTSTATUS ctdb_handle_message(struct ctdbd_connection *conn,
- struct ctdb_req_header *hdr)
+static int ctdb_handle_message(struct ctdbd_connection *conn,
+ struct ctdb_req_header *hdr)
{
struct ctdb_req_message *msg;
if (hdr->operation != CTDB_REQ_MESSAGE) {
DEBUG(0, ("Received async msg of type %u, discarding\n",
hdr->operation));
- return NT_STATUS_INVALID_PARAMETER;
+ return EINVAL;
}
msg = (struct ctdb_req_message *)hdr;
@@ -569,12 +569,12 @@ static NTSTATUS ctdb_handle_message(struct ctdbd_connection *conn,
conn->release_ip_handler = NULL;
conn->release_ip_priv = NULL;
}
- return NT_STATUS_OK;
+ return 0;
}
ctdbd_msg_call_back(conn, msg);
- return NT_STATUS_OK;
+ return 0;
}
/*
@@ -589,7 +589,6 @@ static void ctdbd_socket_handler(struct tevent_context *event_ctx,
struct ctdbd_connection *conn = talloc_get_type_abort(
private_data, struct ctdbd_connection);
struct ctdb_req_header *hdr = NULL;
- NTSTATUS status;
int ret;
ret = ctdb_read_packet(conn->fd, talloc_tos(), &hdr);
@@ -598,13 +597,13 @@ static void ctdbd_socket_handler(struct tevent_context *event_ctx,
cluster_fatal("ctdbd died\n");
}
- status = ctdb_handle_message(conn, hdr);
+ ret = ctdb_handle_message(conn, hdr);
TALLOC_FREE(hdr);
- if (!NT_STATUS_IS_OK(status)) {
+ if (ret != 0) {
DEBUG(10, ("could not handle incoming message: %s\n",
- nt_errstr(status)));
+ strerror(ret)));
}
}
--
1.9.1
From f378b73d612158035bc9c9f036b37558ff87d2fe Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 19 Jun 2015 11:47:01 +0200
Subject: [PATCH 5/9] ctdbd_conn: Convert ctdb_read_req to return 0/errno
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 56 ++++++++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 3d23f58..e4a0833 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -365,9 +365,8 @@ static int ctdb_read_packet(int fd, TALLOC_CTX *mem_ctx,
* messages that might come in between.
*/
-static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
- TALLOC_CTX *mem_ctx,
- struct ctdb_req_header **result)
+static int ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
+ TALLOC_CTX *mem_ctx, struct ctdb_req_header **result)
{
struct ctdb_req_header *hdr;
int ret;
@@ -413,7 +412,7 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
*/
conn->release_ip_handler = NULL;
conn->release_ip_priv = NULL;
- return NT_STATUS_ADDRESS_CLOSED;
+ return EADDRNOTAVAIL;
}
goto next_pkt;
}
@@ -433,7 +432,7 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
*result = talloc_move(mem_ctx, &hdr);
- return NT_STATUS_OK;
+ return 0;
}
static int ctdbd_connection_destructor(struct ctdbd_connection *c)
@@ -685,6 +684,7 @@ static NTSTATUS ctdbd_control(struct ctdbd_connection *conn,
struct iovec iov[2];
ssize_t nwritten;
NTSTATUS status;
+ int ret;
if (conn == NULL) {
status = ctdbd_init_connection(NULL, &new_conn);
@@ -732,10 +732,10 @@ static NTSTATUS ctdbd_control(struct ctdbd_connection *conn,
return NT_STATUS_OK;
}
- status = ctdb_read_req(conn, req.hdr.reqid, NULL, &hdr);
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(10, ("ctdb_read_req failed: %s\n", nt_errstr(status)));
+ ret = ctdb_read_req(conn, req.hdr.reqid, NULL, &hdr);
+ if (ret != 0) {
+ DEBUG(10, ("ctdb_read_req failed: %s\n", strerror(ret)));
+ status = map_nt_error_from_unix(ret);
goto fail;
}
@@ -789,7 +789,6 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
{
TALLOC_CTX *frame = talloc_stackframe();
int i, num_received;
- NTSTATUS status;
uint32_t *reqids;
bool result = false;
@@ -841,7 +840,6 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
if (nwritten == -1) {
- status = map_nt_error_from_unix(errno);
DEBUG(10, ("write_data_iov failed: %s\n",
strerror(errno)));
goto fail;
@@ -854,11 +852,12 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
struct ctdb_req_header *hdr;
struct ctdb_reply_control *reply;
uint32_t reqid;
+ int ret;
- status = ctdb_read_req(conn, 0, talloc_tos(), &hdr);
- if (!NT_STATUS_IS_OK(status)) {
+ ret = ctdb_read_req(conn, 0, talloc_tos(), &hdr);
+ if (ret != 0) {
DEBUG(10, ("ctdb_read_req failed: %s\n",
- nt_errstr(status)));
+ strerror(ret)));
goto fail;
}
@@ -993,7 +992,6 @@ bool ctdb_serverids_exist(struct ctdbd_connection *conn,
bool *results)
{
unsigned i, num_received;
- NTSTATUS status;
struct ctdb_vnn_list *vnns = NULL;
unsigned num_vnns;
@@ -1038,7 +1036,6 @@ bool ctdb_serverids_exist(struct ctdbd_connection *conn,
nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
if (nwritten == -1) {
- status = map_nt_error_from_unix(errno);
DEBUG(10, ("write_data_iov failed: %s\n",
strerror(errno)));
goto fail;
@@ -1053,11 +1050,12 @@ bool ctdb_serverids_exist(struct ctdbd_connection *conn,
struct ctdb_vnn_list *vnn;
uint32_t reqid;
uint8_t *reply_data;
+ int ret;
- status = ctdb_read_req(conn, 0, talloc_tos(), &hdr);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1, ("ctdb_read_req failed: %s\n",
- nt_errstr(status)));
+ ret = ctdb_read_req(conn, 0, talloc_tos(), &hdr);
+ if (ret != 0) {
+ DEBUG(10, ("ctdb_read_req failed: %s\n",
+ strerror(ret)));
goto fail;
}
@@ -1225,6 +1223,7 @@ NTSTATUS ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id,
struct iovec iov[2];
ssize_t nwritten;
NTSTATUS status;
+ int ret;
ZERO_STRUCT(req);
@@ -1252,10 +1251,10 @@ NTSTATUS ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id,
cluster_fatal("cluster dispatch daemon msg write error\n");
}
- status = ctdb_read_req(conn, req.hdr.reqid, NULL, &hdr);
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("ctdb_read_req failed: %s\n", nt_errstr(status)));
+ ret = ctdb_read_req(conn, req.hdr.reqid, NULL, &hdr);
+ if (ret != 0) {
+ DEBUG(10, ("ctdb_read_req failed: %s\n", strerror(ret)));
+ status = map_nt_error_from_unix(ret);
goto fail;
}
@@ -1288,6 +1287,7 @@ NTSTATUS ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
ssize_t nwritten;
NTSTATUS status;
uint32_t flags;
+ int ret;
flags = local_copy ? CTDB_WANT_READONLY : 0;
@@ -1314,10 +1314,10 @@ NTSTATUS ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
cluster_fatal("cluster dispatch daemon msg write error\n");
}
- status = ctdb_read_req(conn, req.hdr.reqid, NULL, &hdr);
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("ctdb_read_req failed: %s\n", nt_errstr(status)));
+ ret = ctdb_read_req(conn, req.hdr.reqid, NULL, &hdr);
+ if (ret != 0) {
+ DEBUG(10, ("ctdb_read_req failed: %s\n", strerror(ret)));
+ status = map_nt_error_from_unix(ret);
goto fail;
}
--
1.9.1
From 7909828151f8ce8c7ec00ee1cbee6333b45accc6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 23 Jun 2015 16:55:09 +0200
Subject: [PATCH 6/9] ctdbd_conn: Make register_with_ctdbd use an int-returning
callback
This will allow an early return from ctdbd_msg_call_back so that we can also
handle CTDB_SRVID_RELEASE_IP via register_with_ctdbd.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/ctdbd_conn.h | 8 ++++----
source3/lib/ctdb_dummy.c | 8 ++++----
source3/lib/ctdbd_conn.c | 16 ++++++++--------
source3/lib/messages_ctdbd.c | 8 +++++---
source3/smbd/notifyd/notifyd.c | 30 ++++++++++++++++--------------
source3/smbd/server.c | 4 +++-
6 files changed, 40 insertions(+), 34 deletions(-)
diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index 6cf123f..bbfb4c4 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -89,10 +89,10 @@ NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn);
struct ctdb_req_message;
NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
- void (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
- uint64_t dst_srvid,
- const uint8_t *msg, size_t msglen,
- void *private_data),
+ int (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data),
void *private_data);
NTSTATUS ctdbd_probe(void);
diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
index b4300c1..23b84ae 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -37,10 +37,10 @@ NTSTATUS ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
}
NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
- void (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
- uint64_t dst_srvid,
- const uint8_t *msg, size_t msglen,
- void *private_data),
+ int (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data),
void *private_data)
{
return NT_STATUS_NOT_IMPLEMENTED;
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index e4a0833..af6195a 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -35,10 +35,10 @@
struct ctdbd_srvid_cb {
uint64_t srvid;
- void (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
- uint64_t dst_srvid,
- const uint8_t *msg, size_t msglen,
- void *private_data);
+ int (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data);
void *private_data;
};
@@ -101,10 +101,10 @@ static void ctdb_packet_dump(struct ctdb_req_header *hdr)
* Register a srvid with ctdbd
*/
NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
- void (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
- uint64_t dst_srvid,
- const uint8_t *msg, size_t msglen,
- void *private_data),
+ int (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data),
void *private_data)
{
diff --git a/source3/lib/messages_ctdbd.c b/source3/lib/messages_ctdbd.c
index 248fc0d..294debe 100644
--- a/source3/lib/messages_ctdbd.c
+++ b/source3/lib/messages_ctdbd.c
@@ -109,7 +109,7 @@ static int messaging_ctdbd_destructor(struct messaging_ctdbd_context *ctx)
return 0;
}
-static void messaging_ctdb_recv(
+static int messaging_ctdb_recv(
uint32_t src_vnn, uint32_t dst_vnn, uint64_t dst_srvid,
const uint8_t *msg, size_t msg_len, void *private_data)
{
@@ -125,7 +125,7 @@ static void messaging_ctdb_recv(
if (msg_len < MESSAGE_HDR_LENGTH) {
DEBUG(1, ("%s: message too short: %u\n", __func__,
(unsigned)msg_len));
- return;
+ return 0;
}
message_hdr_get(&msg_type, &src, &dst, msg);
@@ -145,7 +145,7 @@ static void messaging_ctdb_recv(
DEBUG(10, ("%s: I'm %s, ignoring msg to %s\n", __func__,
server_id_str_buf(me, &id1),
server_id_str_buf(dst, &id2)));
- return;
+ return 0;
}
/*
@@ -159,6 +159,8 @@ static void messaging_ctdb_recv(
DEBUG(10, ("%s: messaging_send_iov_from failed: %s\n",
__func__, nt_errstr(status)));
}
+
+ return 0;
}
NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c
index d9fb11d..3a9bc75 100644
--- a/source3/smbd/notifyd/notifyd.c
+++ b/source3/smbd/notifyd/notifyd.c
@@ -167,10 +167,10 @@ static int sys_notify_watch_dummy(
static void notifyd_handler_done(struct tevent_req *subreq);
static void notifyd_broadcast_reclog_finished(struct tevent_req *subreq);
static void notifyd_clean_peers_finished(struct tevent_req *subreq);
-static void notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
- uint64_t dst_srvid,
- const uint8_t *msg, size_t msglen,
- void *private_data);
+static int notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data);
struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
struct messaging_context *msg_ctx,
@@ -1352,10 +1352,10 @@ fail:
* broadcast, which will then trigger a fresh database pull.
*/
-static void notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
- uint64_t dst_srvid,
- const uint8_t *msg, size_t msglen,
- void *private_data)
+static int notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data)
{
struct notifyd_state *state = talloc_get_type_abort(
private_data, struct notifyd_state);
@@ -1369,18 +1369,18 @@ static void notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
if (msglen < MESSAGE_HDR_LENGTH) {
DEBUG(10, ("%s: Got short broadcast\n", __func__));
- return;
+ return 0;
}
message_hdr_get(&msg_type, &src, &dst, msg);
if (msg_type != MSG_SMB_NOTIFY_REC_CHANGES) {
DEBUG(10, ("%s Got message %u, ignoring\n", __func__,
(unsigned)msg_type));
- return;
+ return 0;
}
if (server_id_equal(&src, &my_id)) {
DEBUG(10, ("%s: Ignoring my own broadcast\n", __func__));
- return;
+ return 0;
}
DEBUG(10, ("%s: Got MSG_SMB_NOTIFY_REC_CHANGES from %s\n",
@@ -1395,7 +1395,7 @@ static void notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
notifyd_apply_reclog(state->peers[i],
msg + MESSAGE_HDR_LENGTH,
msglen - MESSAGE_HDR_LENGTH);
- return;
+ return 0;
}
}
@@ -1405,7 +1405,7 @@ static void notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
p = notifyd_peer_new(state, src);
if (p == NULL) {
DEBUG(10, ("%s: notifyd_peer_new failed\n", __func__));
- return;
+ return 0;
}
status = messaging_send_buf(state->msg_ctx, src, MSG_SMB_NOTIFY_GET_DB,
@@ -1414,8 +1414,10 @@ static void notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn,
DEBUG(10, ("%s: messaging_send_buf failed: %s\n",
__func__, nt_errstr(status)));
TALLOC_FREE(p);
- return;
+ return 0;
}
+
+ return 0;
}
struct notifyd_parse_db_state {
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 5de7f9a..8c77500 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -265,7 +265,7 @@ static void smbd_parent_id_cache_delete(struct messaging_context *ctx,
messaging_send_to_children(ctx, msg_type, msg_data);
}
-static void smbd_parent_ctdb_reconfigured(
+static int smbd_parent_ctdb_reconfigured(
uint32_t src_vnn, uint32_t dst_vnn, uint64_t dst_srvid,
const uint8_t *msg, size_t msglen, void *private_data)
{
@@ -281,6 +281,8 @@ static void smbd_parent_ctdb_reconfigured(
messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
MSG_SMB_BRL_VALIDATE, NULL, 0);
+
+ return 0;
}
static void add_child_pid(struct smbd_parent_context *parent,
--
1.9.1
From 0e6473d4cb0d607f84a490cca1fa41c68016241b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 23 Jun 2015 16:59:00 +0200
Subject: [PATCH 7/9] ctdbd_conn: Return early from ctdbd_msg_call_back
... if the callback returns != 0
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index af6195a..e2b564e 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -136,8 +136,8 @@ NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
return NT_STATUS_OK;
}
-static void ctdbd_msg_call_back(struct ctdbd_connection *conn,
- struct ctdb_req_message *msg)
+static int ctdbd_msg_call_back(struct ctdbd_connection *conn,
+ struct ctdb_req_message *msg)
{
size_t msg_len;
size_t i, num_callbacks;
@@ -146,14 +146,14 @@ static void ctdbd_msg_call_back(struct ctdbd_connection *conn,
if (msg_len < offsetof(struct ctdb_req_message, data)) {
DEBUG(10, ("%s: len %u too small\n", __func__,
(unsigned)msg_len));
- return;
+ return 0;
}
msg_len -= offsetof(struct ctdb_req_message, data);
if (msg_len < msg->datalen) {
DEBUG(10, ("%s: msg_len=%u < msg->datalen=%u\n", __func__,
(unsigned)msg_len, (unsigned)msg->datalen));
- return;
+ return 0;
}
num_callbacks = talloc_array_length(conn->callbacks);
@@ -162,11 +162,17 @@ static void ctdbd_msg_call_back(struct ctdbd_connection *conn,
struct ctdbd_srvid_cb *cb = &conn->callbacks[i];
if ((cb->srvid == msg->srvid) && (cb->cb != NULL)) {
- cb->cb(msg->hdr.srcnode, msg->hdr.destnode,
- msg->srvid, msg->data, msg->datalen,
- cb->private_data);
+ int ret;
+
+ ret = cb->cb(msg->hdr.srcnode, msg->hdr.destnode,
+ msg->srvid, msg->data, msg->datalen,
+ cb->private_data);
+ if (ret != 0) {
+ return ret;
+ }
}
}
+ return 0;
}
/*
--
1.9.1
From 4d1359efbbedc271b39227ba5e631aa783160b22 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 23 Jun 2015 17:04:59 +0200
Subject: [PATCH 8/9] ctdbd_conn: Do an early return from ctdb_read_req
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index e2b564e..77e4e0e 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -423,7 +423,11 @@ static int ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
goto next_pkt;
}
- ctdbd_msg_call_back(conn, msg);
+ ret = ctdbd_msg_call_back(conn, msg);
+ if (ret != 0) {
+ return ret;
+ }
+
TALLOC_FREE(hdr);
goto next_pkt;
}
--
1.9.1
From 56a09c8d81adfb428440454f1ad94b0cbed337c5 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 23 Jun 2015 19:07:44 +0200
Subject: [PATCH 9/9] ctdbd_conn: Move release_ip handling into process.c
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/ctdbd_conn.h | 6 +++--
source3/lib/ctdb_dummy.c | 6 +++--
source3/lib/ctdbd_conn.c | 60 +++++---------------------------------------
source3/smbd/process.c | 23 +++++++++++++----
4 files changed, 32 insertions(+), 63 deletions(-)
diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index bbfb4c4..b60a0e5 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -75,8 +75,10 @@ NTSTATUS ctdbd_traverse(uint32_t db_id,
NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
const struct sockaddr_storage *server,
const struct sockaddr_storage *client,
- bool (*release_ip_handler)(const char *ip_addr,
- void *private_data),
+ int (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data),
void *private_data);
NTSTATUS ctdbd_control_local(struct ctdbd_connection *conn, uint32_t opcode,
diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
index 23b84ae..df05de7 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -49,8 +49,10 @@ NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
const struct sockaddr_storage *_server,
const struct sockaddr_storage *_client,
- bool (*release_ip_handler)(const char *ip_addr,
- void *private_data),
+ int (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data),
void *private_data)
{
return NT_STATUS_NOT_IMPLEMENTED;
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 77e4e0e..9f293ef 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -50,9 +50,6 @@ struct ctdbd_connection {
struct ctdbd_srvid_cb *callbacks;
int fd;
struct tevent_fd *fde;
-
- bool (*release_ip_handler)(const char *ip_addr, void *private_data);
- void *release_ip_priv;
};
static uint32_t ctdbd_next_reqid(struct ctdbd_connection *conn)
@@ -399,30 +396,6 @@ static int ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
goto next_pkt;
}
- if ((conn->release_ip_handler != NULL)
- && (msg->srvid == CTDB_SRVID_RELEASE_IP)) {
- bool ok;
-
- /* must be dispatched immediately */
- DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
- ok = conn->release_ip_handler((const char *)msg->data,
- conn->release_ip_priv);
- TALLOC_FREE(hdr);
-
- if (ok) {
- /*
- * We need to release the ip,
- * so return an error to the upper layers.
- *
- * We make sure we don't trigger this again.
- */
- conn->release_ip_handler = NULL;
- conn->release_ip_priv = NULL;
- return EADDRNOTAVAIL;
- }
- goto next_pkt;
- }
-
ret = ctdbd_msg_call_back(conn, msg);
if (ret != 0) {
return ret;
@@ -561,26 +534,6 @@ static int ctdb_handle_message(struct ctdbd_connection *conn,
msg = (struct ctdb_req_message *)hdr;
- if ((conn->release_ip_handler != NULL)
- && (msg->srvid == CTDB_SRVID_RELEASE_IP)) {
- bool ret;
-
- /* must be dispatched immediately */
- DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
- ret = conn->release_ip_handler((const char *)msg->data,
- conn->release_ip_priv);
- if (ret) {
- /*
- * We need to release the ip.
- *
- * We make sure we don't trigger this again.
- */
- conn->release_ip_handler = NULL;
- conn->release_ip_priv = NULL;
- }
- return 0;
- }
-
ctdbd_msg_call_back(conn, msg);
return 0;
@@ -1498,8 +1451,10 @@ static void smbd_ctdb_canonicalize_ip(const struct sockaddr_storage *in,
NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
const struct sockaddr_storage *_server,
const struct sockaddr_storage *_client,
- bool (*release_ip_handler)(const char *ip_addr,
- void *private_data),
+ int (*cb)(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data),
void *private_data)
{
struct ctdb_control_tcp_addr p;
@@ -1511,7 +1466,6 @@ NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
/*
* Only one connection so far
*/
- SMB_ASSERT(conn->release_ip_handler == NULL);
smbd_ctdb_canonicalize_ip(_client, &client);
smbd_ctdb_canonicalize_ip(_server, &server);
@@ -1529,14 +1483,12 @@ NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
return NT_STATUS_INTERNAL_ERROR;
}
- conn->release_ip_handler = release_ip_handler;
- conn->release_ip_priv = private_data;
-
/*
* We want to be told about IP releases
*/
- status = register_with_ctdbd(conn, CTDB_SRVID_RELEASE_IP, NULL, NULL);
+ status = register_with_ctdbd(conn, CTDB_SRVID_RELEASE_IP,
+ cb, private_data);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index c83f3bc..12ce0d1 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -2616,18 +2616,31 @@ static void smbd_release_ip_immediate(struct tevent_context *ctx,
/****************************************************************************
received when we should release a specific IP
****************************************************************************/
-static bool release_ip(const char *ip, void *priv)
+static int release_ip(uint32_t src_vnn, uint32_t dst_vnn,
+ uint64_t dst_srvid,
+ const uint8_t *msg, size_t msglen,
+ void *private_data)
{
struct smbd_release_ip_state *state =
- talloc_get_type_abort(priv,
+ talloc_get_type_abort(private_data,
struct smbd_release_ip_state);
struct smbXsrv_connection *xconn = state->xconn;
+ const char *ip;
const char *addr = state->addr;
const char *p = addr;
+ if (msglen == 0) {
+ return 0;
+ }
+ if (msg[msglen-1] != '\0') {
+ return 0;
+ }
+
+ ip = (const char *)msg;
+
if (!NT_STATUS_IS_OK(xconn->transport.status)) {
/* avoid recursion */
- return false;
+ return 0;
}
if (strncmp("::ffff:", addr, 7) == 0) {
@@ -2668,10 +2681,10 @@ static bool release_ip(const char *ip, void *priv)
* Make sure we don't get any io on the connection.
*/
xconn->transport.status = NT_STATUS_ADDRESS_CLOSED;
- return true;
+ return EADDRNOTAVAIL;
}
- return false;
+ return 0;
}
static NTSTATUS smbd_register_ips(struct smbXsrv_connection *xconn,
--
1.9.1
More information about the samba-technical
mailing list