/*
wait for all nodes to be connected
*/
-void ctdb_connect_wait(struct ctdb_context *ctdb)
+void ctdb_daemon_connect_wait(struct ctdb_context *ctdb)
{
int expected = ctdb->num_nodes - 1;
if (ctdb->flags & CTDB_FLAG_SELF_CONNECT) {
}
+/*
+ handle a connect wait reply packet
+ */
+static void ctdb_reply_connect_wait(struct ctdb_context *ctdb,
+ struct ctdb_req_header *hdr)
+{
+ struct ctdb_reply_connect_wait *r = (struct ctdb_reply_connect_wait *)hdr;
+ ctdb->num_connected = r->num_connected;
+}
+
/*
this is called in the client, when data comes in from the daemon
*/
case CTDB_REQ_MESSAGE:
ctdb_request_message(ctdb, hdr);
break;
+
+ case CTDB_REPLY_CONNECT_WAIT:
+ ctdb_reply_connect_wait(ctdb, hdr);
+ break;
}
}
}
+/*
+ send a message - from client context
+ */
int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
uint32_t srvid, TDB_DATA data)
{
talloc_free(r);
return 0;
}
+
+/*
+ wait for all nodes to be connected - from client
+ */
+static void ctdb_client_connect_wait(struct ctdb_context *ctdb)
+{
+ struct ctdb_req_connect_wait r;
+ int res;
+
+ ZERO_STRUCT(r);
+
+ r.hdr.length = sizeof(r);
+ r.hdr.ctdb_magic = CTDB_MAGIC;
+ r.hdr.ctdb_version = CTDB_VERSION;
+ r.hdr.operation = CTDB_REQ_CONNECT_WAIT;
+
+ res = ctdb_queue_send(ctdb->daemon.queue, (uint8_t *)&r.hdr, r.hdr.length);
+ if (res != 0) {
+ printf("Failed to queue a connect wait request\n");
+ return;
+ }
+
+ /* now we can go into the normal wait routine, as the reply packet
+ will update the ctdb->num_connected variable */
+ ctdb_daemon_connect_wait(ctdb);
+}
+
+/*
+ wait for all nodes to be connected
+*/
+void ctdb_connect_wait(struct ctdb_context *ctdb)
+{
+ if (!(ctdb->flags & CTDB_FLAG_DAEMON_MODE)) {
+ ctdb_daemon_connect_wait(ctdb);
+ return;
+ }
+
+ ctdb_client_connect_wait(ctdb);
+}
/*XXX cant use this since it returns an int CTDB_NO_MEMORY(ctdb, r);*/
talloc_set_name_const(r, "req_message packet");
+ ZERO_STRUCT(*r);
+
r->hdr.length = len;
r->hdr.ctdb_magic = CTDB_MAGIC;
r->hdr.ctdb_version = CTDB_VERSION;
}
+/*
+ called when the daemon gets a connect wait request from a client
+ */
+static void daemon_request_connect_wait(struct ctdb_client *client,
+ struct ctdb_req_connect_wait *c)
+{
+ struct ctdb_reply_connect_wait r;
+ int res;
+
+ /* first wait - in the daemon */
+ ctdb_daemon_connect_wait(client->ctdb);
+
+ /* now send the reply */
+ ZERO_STRUCT(r);
+
+ r.hdr.length = sizeof(r);
+ r.hdr.ctdb_magic = CTDB_MAGIC;
+ r.hdr.ctdb_version = CTDB_VERSION;
+ r.hdr.operation = CTDB_REPLY_CONNECT_WAIT;
+ r.num_connected = client->ctdb->num_connected;
+
+ res = ctdb_queue_send(client->queue, (uint8_t *)&r.hdr, r.hdr.length);
+ if (res != 0) {
+ printf("Failed to queue a connect wait response\n");
+ return;
+ }
+}
+
/*
destroy a ctdb_client
*/
case CTDB_REQ_MESSAGE:
daemon_request_message_from_client(client, (struct ctdb_req_message *)hdr);
break;
+
+ case CTDB_REQ_CONNECT_WAIT:
+ daemon_request_connect_wait(client, (struct ctdb_req_connect_wait *)hdr);
+ break;
}
done:
operation IDs
*/
enum ctdb_operation {
- CTDB_REQ_CALL = 0,
- CTDB_REPLY_CALL = 1,
- CTDB_REPLY_REDIRECT = 2,
- CTDB_REQ_DMASTER = 3,
- CTDB_REPLY_DMASTER = 4,
- CTDB_REPLY_ERROR = 5,
- CTDB_REQ_REGISTER = 6,
- CTDB_REQ_MESSAGE = 7
+ CTDB_REQ_CALL = 0,
+ CTDB_REPLY_CALL = 1,
+ CTDB_REPLY_REDIRECT = 2,
+ CTDB_REQ_DMASTER = 3,
+ CTDB_REPLY_DMASTER = 4,
+ CTDB_REPLY_ERROR = 5,
+ CTDB_REQ_REGISTER = 6,
+ CTDB_REQ_MESSAGE = 7,
+ CTDB_REQ_CONNECT_WAIT = 8,
+ CTDB_REPLY_CONNECT_WAIT = 9
};
#define CTDB_MAGIC 0x43544442 /* CTDB */
uint8_t data[1];
};
+struct ctdb_req_connect_wait {
+ struct ctdb_req_header hdr;
+};
+
+struct ctdb_reply_connect_wait {
+ struct ctdb_req_header hdr;
+ uint32_t num_connected;
+};
+
/* internal prototypes */
void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
uint32_t srvid, TDB_DATA data);
+/*
+ wait for all nodes to be connected
+*/
+void ctdb_daemon_connect_wait(struct ctdb_context *ctdb);
+
#endif