ctdb-daemon: Rename struct ctdb_client_notify_register to ctdb_notify_data_old
[obnox/samba/samba-obnox.git] / source3 / lib / ctdbd_conn.c
index f091da7b2f06b7427144a033cc52ab123d9f7da1..e67a31d5bc6becce12a345abf3af56b89614b970 100644 (file)
 #include "serverid.h"
 #include "ctdbd_conn.h"
 #include "system/select.h"
-#include "lib/sys_rw_data.h"
+#include "lib/util/sys_rw_data.h"
 #include "lib/util/iov_buf.h"
 
 #include "messages.h"
 
 /* paths to these include files come from --with-ctdb= in configure */
 
-#include "ctdb.h"
 #include "ctdb_private.h"
 
 struct ctdbd_srvid_cb {
@@ -136,18 +135,18 @@ int register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
 }
 
 static int ctdbd_msg_call_back(struct ctdbd_connection *conn,
-                              struct ctdb_req_message *msg)
+                              struct ctdb_req_message_old *msg)
 {
        size_t msg_len;
        size_t i, num_callbacks;
 
        msg_len = msg->hdr.length;
-       if (msg_len < offsetof(struct ctdb_req_message, data)) {
+       if (msg_len < offsetof(struct ctdb_req_message_old, data)) {
                DEBUG(10, ("%s: len %u too small\n", __func__,
                           (unsigned)msg_len));
                return 0;
        }
-       msg_len -= offsetof(struct ctdb_req_message, data);
+       msg_len -= offsetof(struct ctdb_req_message_old, data);
 
        if (msg_len < msg->datalen) {
                DEBUG(10, ("%s: msg_len=%u < msg->datalen=%u\n", __func__,
@@ -199,7 +198,7 @@ static bool ctdbd_working(struct ctdbd_connection *conn, uint32_t vnn)
 {
        int32_t cstatus=-1;
        TDB_DATA outdata;
-       struct ctdb_node_map *m;
+       struct ctdb_node_map_old *m;
        uint32_t failure_flags;
        bool ok = false;
        int i, ret;
@@ -216,7 +215,7 @@ static bool ctdbd_working(struct ctdbd_connection *conn, uint32_t vnn)
                return false;
        }
 
-       m = (struct ctdb_node_map *)outdata.dptr;
+       m = (struct ctdb_node_map_old *)outdata.dptr;
 
        for (i=0; i<m->num; i++) {
                if (vnn == m->nodes[i].pnn) {
@@ -301,7 +300,7 @@ static int ctdb_read_packet(int fd, int timeout, TALLOC_CTX *mem_ctx,
        ssize_t nread;
 
        if (timeout != -1) {
-               ret = poll_one_fd(fd, POLLIN, timeout, &revents);
+               ret = poll_intr_one_fd(fd, POLLIN, timeout, &revents);
                if (ret == -1) {
                        return errno;
                }
@@ -371,7 +370,7 @@ static int ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
        ctdb_packet_dump(hdr);
 
        if (hdr->operation == CTDB_REQ_MESSAGE) {
-               struct ctdb_req_message *msg = (struct ctdb_req_message *)hdr;
+               struct ctdb_req_message_old *msg = (struct ctdb_req_message_old *)hdr;
 
                if (conn->msg_ctx == NULL) {
                        DEBUG(1, ("Got a message without having a msg ctx, "
@@ -431,7 +430,7 @@ static int ctdbd_init_connection(TALLOC_CTX *mem_ctx,
 
        conn->sockname = talloc_strdup(conn, sockname);
        if (conn->sockname == NULL) {
-               DBG_ERR("%s: talloc failed\n", __func__);
+               DBG_ERR("talloc failed\n");
                ret = ENOMEM;
                goto fail;
        }
@@ -527,7 +526,7 @@ int ctdbd_conn_get_fd(struct ctdbd_connection *conn)
 static int ctdb_handle_message(struct ctdbd_connection *conn,
                               struct ctdb_req_header *hdr)
 {
-       struct ctdb_req_message *msg;
+       struct ctdb_req_message_old *msg;
 
        if (hdr->operation != CTDB_REQ_MESSAGE) {
                DEBUG(0, ("Received async msg of type %u, discarding\n",
@@ -535,7 +534,7 @@ static int ctdb_handle_message(struct ctdbd_connection *conn,
                return EINVAL;
        }
 
-       msg = (struct ctdb_req_message *)hdr;
+       msg = (struct ctdb_req_message_old *)hdr;
 
        ctdbd_msg_call_back(conn, msg);
 
@@ -577,17 +576,15 @@ static void ctdbd_socket_handler(struct tevent_context *event_ctx,
  */
 
 int ctdbd_register_msg_ctx(struct ctdbd_connection *conn,
-                          struct messaging_context *msg_ctx)
+                          struct messaging_context *msg_ctx,
+                          struct tevent_context *ev)
 {
        SMB_ASSERT(conn->msg_ctx == NULL);
        SMB_ASSERT(conn->fde == NULL);
 
-       if (!(conn->fde = tevent_add_fd(messaging_tevent_context(msg_ctx),
-                                      conn,
-                                      conn->fd,
-                                      TEVENT_FD_READ,
-                                      ctdbd_socket_handler,
-                                      conn))) {
+       conn->fde = tevent_add_fd(ev, conn, conn->fd, TEVENT_FD_READ,
+                                 ctdbd_socket_handler, conn);
+       if (conn->fde == NULL) {
                DEBUG(0, ("event_add_fd failed\n"));
                return ENOMEM;
        }
@@ -601,12 +598,12 @@ int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
                             uint32_t dst_vnn, uint64_t dst_srvid,
                             const struct iovec *iov, int iovlen)
 {
-       struct ctdb_req_message r;
+       struct ctdb_req_message_old r;
        struct iovec iov2[iovlen+1];
        size_t buflen = iov_buflen(iov, iovlen);
        ssize_t nwritten;
 
-       r.hdr.length = offsetof(struct ctdb_req_message, data) + buflen;
+       r.hdr.length = offsetof(struct ctdb_req_message_old, data) + buflen;
        r.hdr.ctdb_magic = CTDB_MAGIC;
        r.hdr.ctdb_version = CTDB_PROTOCOL;
        r.hdr.generation = 1;
@@ -621,7 +618,7 @@ int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
        ctdb_packet_dump(&r.hdr);
 
        iov2[0].iov_base = &r;
-       iov2[0].iov_len = offsetof(struct ctdb_req_message, data);
+       iov2[0].iov_len = offsetof(struct ctdb_req_message_old, data);
        memcpy(&iov2[1], iov, iovlen * sizeof(struct iovec));
 
        nwritten = write_data_iov(conn->fd, iov2, iovlen+1);
@@ -643,15 +640,15 @@ static int ctdbd_control(struct ctdbd_connection *conn,
                         TALLOC_CTX *mem_ctx, TDB_DATA *outdata,
                         int *cstatus)
 {
-       struct ctdb_req_control req;
+       struct ctdb_req_control_old req;
        struct ctdb_req_header *hdr;
-       struct ctdb_reply_control *reply = NULL;
+       struct ctdb_reply_control_old *reply = NULL;
        struct iovec iov[2];
        ssize_t nwritten;
        int ret;
 
        ZERO_STRUCT(req);
-       req.hdr.length = offsetof(struct ctdb_req_control, data) + data.dsize;
+       req.hdr.length = offsetof(struct ctdb_req_control_old, data) + data.dsize;
        req.hdr.ctdb_magic   = CTDB_MAGIC;
        req.hdr.ctdb_version = CTDB_PROTOCOL;
        req.hdr.operation    = CTDB_REQ_CONTROL;
@@ -666,7 +663,7 @@ static int ctdbd_control(struct ctdbd_connection *conn,
        ctdb_packet_dump(&req.hdr);
 
        iov[0].iov_base = &req;
-       iov[0].iov_len = offsetof(struct ctdb_req_control, data);
+       iov[0].iov_len = offsetof(struct ctdb_req_control_old, data);
        iov[1].iov_base = data.dptr;
        iov[1].iov_len = data.dsize;
 
@@ -694,7 +691,7 @@ static int ctdbd_control(struct ctdbd_connection *conn,
                TALLOC_FREE(hdr);
                return EIO;
        }
-       reply = (struct ctdb_reply_control *)hdr;
+       reply = (struct ctdb_reply_control_old *)hdr;
 
        if (outdata) {
                if (!(outdata->dptr = (uint8_t *)talloc_memdup(
@@ -745,7 +742,7 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
        }
 
        for (i=0; i<num_pids; i++) {
-               struct ctdb_req_control req;
+               struct ctdb_req_control_old req;
                pid_t pid;
                struct iovec iov[2];
                ssize_t nwritten;
@@ -765,7 +762,7 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
                           (int)pids[i].vnn, (int)pid,
                           (int)reqids[i]));
 
-               req.hdr.length = offsetof(struct ctdb_req_control, data);
+               req.hdr.length = offsetof(struct ctdb_req_control_old, data);
                req.hdr.length += sizeof(pid);
                req.hdr.ctdb_magic   = CTDB_MAGIC;
                req.hdr.ctdb_version = CTDB_PROTOCOL;
@@ -781,7 +778,7 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
                ctdb_packet_dump(&req.hdr);
 
                iov[0].iov_base = &req;
-               iov[0].iov_len = offsetof(struct ctdb_req_control, data);
+               iov[0].iov_len = offsetof(struct ctdb_req_control_old, data);
                iov[1].iov_base = &pid;
                iov[1].iov_len = sizeof(pid);
 
@@ -797,7 +794,7 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
 
        while (num_received < num_pids) {
                struct ctdb_req_header *hdr;
-               struct ctdb_reply_control *reply;
+               struct ctdb_reply_control_old *reply;
                uint32_t reqid;
                int ret;
 
@@ -812,7 +809,7 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
                        DEBUG(10, ("Received invalid reply\n"));
                        goto fail;
                }
-               reply = (struct ctdb_reply_control *)hdr;
+               reply = (struct ctdb_reply_control_old *)hdr;
 
                reqid = reply->hdr.reqid;
 
@@ -921,7 +918,7 @@ int ctdbd_db_attach(struct ctdbd_connection *conn,
  */
 int ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id, TDB_DATA key)
 {
-       struct ctdb_req_call req;
+       struct ctdb_req_call_old req;
        struct ctdb_req_header *hdr;
        struct iovec iov[2];
        ssize_t nwritten;
@@ -929,7 +926,7 @@ int ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id, TDB_DATA key)
 
        ZERO_STRUCT(req);
 
-       req.hdr.length = offsetof(struct ctdb_req_call, data) + key.dsize;
+       req.hdr.length = offsetof(struct ctdb_req_call_old, data) + key.dsize;
        req.hdr.ctdb_magic   = CTDB_MAGIC;
        req.hdr.ctdb_version = CTDB_PROTOCOL;
        req.hdr.operation    = CTDB_REQ_CALL;
@@ -943,7 +940,7 @@ int ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id, TDB_DATA key)
        ctdb_packet_dump(&req.hdr);
 
        iov[0].iov_base = &req;
-       iov[0].iov_len = offsetof(struct ctdb_req_call, data);
+       iov[0].iov_len = offsetof(struct ctdb_req_call_old, data);
        iov[1].iov_base = key.dptr;
        iov[1].iov_len = key.dsize;
 
@@ -979,9 +976,9 @@ int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
                               void *private_data),
                void *private_data)
 {
-       struct ctdb_req_call req;
+       struct ctdb_req_call_old req;
        struct ctdb_req_header *hdr = NULL;
-       struct ctdb_reply_call *reply;
+       struct ctdb_reply_call_old *reply;
        struct iovec iov[2];
        ssize_t nwritten;
        uint32_t flags;
@@ -991,7 +988,7 @@ int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
 
        ZERO_STRUCT(req);
 
-       req.hdr.length = offsetof(struct ctdb_req_call, data) + key.dsize;
+       req.hdr.length = offsetof(struct ctdb_req_call_old, data) + key.dsize;
        req.hdr.ctdb_magic   = CTDB_MAGIC;
        req.hdr.ctdb_version = CTDB_PROTOCOL;
        req.hdr.operation    = CTDB_REQ_CALL;
@@ -1002,7 +999,7 @@ int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
        req.keylen           = key.dsize;
 
        iov[0].iov_base = &req;
-       iov[0].iov_len = offsetof(struct ctdb_req_call, data);
+       iov[0].iov_len = offsetof(struct ctdb_req_call_old, data);
        iov[1].iov_base = key.dptr;
        iov[1].iov_len = key.dsize;
 
@@ -1023,7 +1020,7 @@ int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
                ret = EIO;
                goto fail;
        }
-       reply = (struct ctdb_reply_call *)hdr;
+       reply = (struct ctdb_reply_call_old *)hdr;
 
        if (reply->datalen == 0) {
                /*
@@ -1096,8 +1093,8 @@ int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
 
        while (True) {
                struct ctdb_req_header *hdr = NULL;
-               struct ctdb_req_message *m;
-               struct ctdb_rec_data *d;
+               struct ctdb_req_message_old *m;
+               struct ctdb_rec_data_old *d;
 
                ret = ctdb_read_packet(conn->fd, conn->timeout, conn, &hdr);
                if (ret != 0) {
@@ -1113,8 +1110,8 @@ int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
                        return EIO;
                }
 
-               m = (struct ctdb_req_message *)hdr;
-               d = (struct ctdb_rec_data *)&m->data[0];
+               m = (struct ctdb_req_message_old *)hdr;
+               d = (struct ctdb_rec_data_old *)&m->data[0];
                if (m->datalen < sizeof(uint32_t) || m->datalen != d->length) {
                        DEBUG(0, ("Got invalid traverse data of length %d\n",
                                  (int)m->datalen));
@@ -1254,7 +1251,7 @@ int ctdbd_control_local(struct ctdbd_connection *conn, uint32_t opcode,
 
 int ctdb_watch_us(struct ctdbd_connection *conn)
 {
-       struct ctdb_client_notify_register reg_data;
+       struct ctdb_notify_data_old reg_data;
        size_t struct_len;
        int ret;
        int cstatus;
@@ -1263,7 +1260,7 @@ int ctdb_watch_us(struct ctdbd_connection *conn)
        reg_data.len = 1;
        reg_data.notify_data[0] = 0;
 
-       struct_len = offsetof(struct ctdb_client_notify_register,
+       struct_len = offsetof(struct ctdb_notify_data_old,
                              notify_data) + reg_data.len;
 
        ret = ctdbd_control_local(