static void daemon_request_shutdown(struct ctdb_client *client,
struct ctdb_req_shutdown *f)
{
- struct ctdb_req_finished r;
+ struct ctdb_reply_shutdown rs;
+ struct ctdb_context *ctdb = talloc_get_type(client->ctdb, struct ctdb_context);
int len;
uint32_t node;
- len = sizeof(struct ctdb_req_finished);
- ZERO_STRUCT(r);
- r.hdr.length = len;
- r.hdr.ctdb_magic = CTDB_MAGIC;
- r.hdr.ctdb_version = CTDB_VERSION;
- r.hdr.operation = CTDB_REQ_FINISHED;
- r.hdr.srcnode = ctdb->vnn;
- r.hdr.reqid = 0;
+ /* we dont send to ourself so we can already count one daemon as
+ exiting */
+ ctdb->num_finished++;
+
/* loop over all nodes of the cluster */
- for (node=0; node<ctdb_num_nodes;node++) {
- r.hdr.destnode = node;
- ctdb_queue_packet(ctdb, &r->hdr);
+ for (node=0; node<ctdb->num_nodes;node++) {
+ struct ctdb_req_finished *rf;
+
+ /* dont send a message to ourself */
+ if (ctdb->vnn == node) {
+ continue;
+ }
+
+ len = sizeof(struct ctdb_req_finished);
+ rf = ctdb->methods->allocate_pkt(ctdb, len);
+ CTDB_NO_MEMORY_FATAL(ctdb, rf);
+ talloc_set_name_const(rf, "ctdb_req_finished packet");
+
+ ZERO_STRUCT(*rf);
+ rf->hdr.length = len;
+ rf->hdr.ctdb_magic = CTDB_MAGIC;
+ rf->hdr.ctdb_version = CTDB_VERSION;
+ rf->hdr.operation = CTDB_REQ_FINISHED;
+ rf->hdr.destnode = node;
+ rf->hdr.srcnode = ctdb->vnn;
+ rf->hdr.reqid = 0;
+
+ ctdb_queue_packet(ctdb, &(rf->hdr));
+
+ talloc_free(rf);
}
- /* send a shutdown reply back to the client */
+ /* wait until all nodes have are prepared to shutdown */
+ while (ctdb->num_finished != ctdb->num_nodes) {
+ event_loop_once(ctdb->ev);
+ }
+ /* send a shutdown reply back to the client */
+ len = sizeof(struct ctdb_reply_shutdown);
+ ZERO_STRUCT(rs);
+ rs.hdr.length = len;
+ rs.hdr.ctdb_magic = CTDB_MAGIC;
+ rs.hdr.ctdb_version = CTDB_VERSION;
+ rs.hdr.operation = CTDB_REPLY_SHUTDOWN;
+ ctdb_queue_send(client->queue, (uint8_t *)&(rs.hdr), rs.hdr.length);
+ /* XXX we should wait here until the packet has been sent to the client */
+
+ /* all daemons have requested to finish - we now exit */
+ DEBUG(1,("All daemons finished - exiting\n"));
+ _exit(0);
}
/*
void ctdb_request_finished(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
{
ctdb->num_finished++;
- if (ctdb->num_finished == ctdb->num_nodes) {
- /* all daemons have requested to finish - we now exit */
- DEBUG(1,("All daemons finished - exiting\n"));
- _exit(0);
- }
}