lib: Make register_with_ctdbd return 0/errno
authorVolker Lendecke <vl@samba.org>
Sat, 3 Oct 2015 03:42:05 +0000 (20:42 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 7 Oct 2015 21:54:05 +0000 (23:54 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/ctdbd_conn.h
source3/lib/ctdb_dummy.c
source3/lib/ctdbd_conn.c
source3/lib/messages_ctdbd.c
source3/smbd/notifyd/notifyd.c

index 6c46cdb3d00f69c60d10318e105b32d9b04d3ea8..1db0c0a40e9e2ed9d079f219cf1b9bb873f61c02 100644 (file)
@@ -86,12 +86,12 @@ NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn);
 
 struct ctdb_req_message;
 
-NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
-                            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);
+int register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
+                       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(const char *sockname, int timeout);
 
 #endif /* _CTDBD_CONN_H */
index d8658cf1f53c56d6e9361e7b8e9e61d324d3cadd..dea1db664d42ba448c15662eadbcecb923d21310 100644 (file)
@@ -36,14 +36,14 @@ NTSTATUS ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
-NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
-                            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)
+int register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
+                       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;
+       return ENOSYS;
 }
 
 NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
index bdb6746494a371de610d702e5271ff2c4282089c..347606c4aff0c6572b64af1ce8442e345f5d29d1 100644 (file)
@@ -100,12 +100,12 @@ 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,
-                            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)
+int register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
+                       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)
 {
 
        int ret, cstatus;
@@ -116,7 +116,7 @@ NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
                            CTDB_CONTROL_REGISTER_SRVID, srvid, 0,
                            tdb_null, NULL, NULL, &cstatus);
        if (ret != 0) {
-               return map_nt_error_from_unix(ret);
+               return ret;
        }
 
        num_callbacks = talloc_array_length(conn->callbacks);
@@ -124,7 +124,7 @@ NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
        tmp = talloc_realloc(conn, conn->callbacks, struct ctdbd_srvid_cb,
                             num_callbacks + 1);
        if (tmp == NULL) {
-               return NT_STATUS_NO_MEMORY;
+               return ENOMEM;
        }
        conn->callbacks = tmp;
 
@@ -132,7 +132,7 @@ NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
                .srvid = srvid, .cb = cb, .private_data = private_data
        };
 
-       return NT_STATUS_OK;
+       return 0;
 }
 
 static int ctdbd_msg_call_back(struct ctdbd_connection *conn,
@@ -467,11 +467,12 @@ static NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
        generate_random_buffer((unsigned char *)&conn->rand_srvid,
                               sizeof(conn->rand_srvid));
 
-       status = register_with_ctdbd(conn, conn->rand_srvid, NULL, NULL);
+       ret = register_with_ctdbd(conn, conn->rand_srvid, NULL, NULL);
 
-       if (!NT_STATUS_IS_OK(status)) {
+       if (ret != 0) {
                DEBUG(5, ("Could not register random srvid: %s\n",
-                         nt_errstr(status)));
+                         strerror(ret)));
+               status = map_nt_error_from_unix(ret);
                goto fail;
        }
 
@@ -493,6 +494,7 @@ NTSTATUS ctdbd_messaging_connection(TALLOC_CTX *mem_ctx,
 {
         struct ctdbd_connection *conn;
        NTSTATUS status;
+       int ret;
 
        status = ctdbd_init_connection(mem_ctx, sockname, timeout, &conn);
 
@@ -500,8 +502,9 @@ NTSTATUS ctdbd_messaging_connection(TALLOC_CTX *mem_ctx,
                return status;
        }
 
-       status = register_with_ctdbd(conn, MSG_SRVID_SAMBA, NULL, NULL);
-       if (!NT_STATUS_IS_OK(status)) {
+       ret = register_with_ctdbd(conn, MSG_SRVID_SAMBA, NULL, NULL);
+       if (ret != 0) {
+               status = map_nt_error_from_unix(ret);
                goto fail;
        }
 
@@ -1204,7 +1207,6 @@ NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
 {
        struct ctdb_control_tcp_addr p;
        TDB_DATA data = { .dptr = (uint8_t *)&p, .dsize = sizeof(p) };
-       NTSTATUS status;
        int ret;
        struct sockaddr_storage client;
        struct sockaddr_storage server;
@@ -1233,10 +1235,10 @@ NTSTATUS ctdbd_register_ips(struct ctdbd_connection *conn,
         * We want to be told about IP releases
         */
 
-       status = register_with_ctdbd(conn, CTDB_SRVID_RELEASE_IP,
-                                    cb, private_data);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       ret = register_with_ctdbd(conn, CTDB_SRVID_RELEASE_IP,
+                                 cb, private_data);
+       if (ret != 0) {
+               return map_nt_error_from_unix(ret);
        }
 
        /*
index 4d8b574f354f9788d2d8bbb8e574112f01f7565f..e6724a856a2f311b986875bc8976ca8e0dcdbcdb 100644 (file)
@@ -171,6 +171,7 @@ NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
        struct messaging_backend *result;
        struct messaging_ctdbd_context *ctx;
        NTSTATUS status;
+       int ret;
 
        if (!(result = talloc(mem_ctx, struct messaging_backend))) {
                DEBUG(0, ("talloc failed\n"));
@@ -202,8 +203,14 @@ NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
                return status;
        }
 
-       status = register_with_ctdbd(ctx->conn, getpid(),
-                                    messaging_ctdb_recv, msg_ctx);
+       ret = register_with_ctdbd(ctx->conn, getpid(),
+                                 messaging_ctdb_recv, msg_ctx);
+       if (ret != 0) {
+               DEBUG(10, ("register_with_ctdbd failed: %s\n",
+                          strerror(ret)));
+               TALLOC_FREE(result);
+               return map_nt_error_from_unix(ret);
+       }
 
        global_ctdb_connection_pid = getpid();
        global_ctdbd_connection = ctx->conn;
index 3a9bc752c76356025f5e54d62b4e09d379a10af5..5554273320f0c5e976ce9d809fa4e65ba524fc63 100644 (file)
@@ -181,7 +181,6 @@ 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);
@@ -275,10 +274,10 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
        tevent_req_set_callback(subreq, notifyd_clean_peers_finished,
                                req);
 
-       status = register_with_ctdbd(ctdbd_conn, CTDB_SRVID_SAMBA_NOTIFY_PROXY,
-                                    notifyd_snoop_broadcast, state);
-       if (!NT_STATUS_IS_OK(status)) {
-               tevent_req_error(req, map_errno_from_nt_status(status));
+       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);
        }