2 ctdb_control protocol code
4 Copyright (C) Andrew Tridgell 2007
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "lib/tdb/include/tdb.h"
21 #include "system/network.h"
22 #include "system/filesys.h"
23 #include "system/wait.h"
24 #include "../include/ctdb_private.h"
25 #include "lib/util/dlinklist.h"
29 struct ctdb_control_state {
30 struct ctdb_context *ctdb;
32 ctdb_control_callback_fn_t callback;
39 dump talloc memory hierarchy, returning it as a blob to the client
41 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata)
43 /* dump to a file, then send the file as a blob */
48 DEBUG(DEBUG_ERR,(__location__ " Unable to open tmpfile - %s\n", strerror(errno)));
51 talloc_report_full(NULL, f);
54 outdata->dptr = talloc_size(outdata, fsize);
55 CTDB_NO_MEMORY(ctdb, outdata->dptr);
56 outdata->dsize = fread(outdata->dptr, 1, fsize, f);
58 if (outdata->dsize != fsize) {
59 DEBUG(DEBUG_ERR,(__location__ " Unable to read tmpfile\n"));
67 process a control request
69 static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
70 struct ctdb_req_control *c,
72 TDB_DATA *outdata, uint32_t srcnode,
73 const char **errormsg,
76 uint32_t opcode = c->opcode;
77 uint64_t srvid = c->srvid;
78 uint32_t client_id = c->client_id;
81 case CTDB_CONTROL_PROCESS_EXISTS: {
82 CHECK_CONTROL_DATA_SIZE(sizeof(pid_t));
83 return ctdb_control_process_exists(ctdb, *(pid_t *)indata.dptr);
86 case CTDB_CONTROL_SET_DEBUG: {
87 CHECK_CONTROL_DATA_SIZE(sizeof(int32_t));
88 LogLevel = *(int32_t *)indata.dptr;
92 case CTDB_CONTROL_GET_DEBUG: {
93 CHECK_CONTROL_DATA_SIZE(0);
94 outdata->dptr = (uint8_t *)&LogLevel;
95 outdata->dsize = sizeof(LogLevel);
99 case CTDB_CONTROL_STATISTICS: {
101 CHECK_CONTROL_DATA_SIZE(0);
102 ctdb->statistics.memory_used = talloc_total_size(NULL);
103 ctdb->statistics.num_clients = ctdb->num_clients;
104 ctdb->statistics.frozen = 0;
105 for (i=1; i<= NUM_DB_PRIORITIES; i++) {
106 if (ctdb->freeze_mode[i] == CTDB_FREEZE_FROZEN) {
107 ctdb->statistics.frozen = 1;
110 ctdb->statistics.recovering = (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE);
111 ctdb->statistics.statistics_current_time = timeval_current();
113 outdata->dptr = (uint8_t *)&ctdb->statistics;
114 outdata->dsize = sizeof(ctdb->statistics);
118 case CTDB_CONTROL_GET_ALL_TUNABLES: {
119 CHECK_CONTROL_DATA_SIZE(0);
120 outdata->dptr = (uint8_t *)&ctdb->tunable;
121 outdata->dsize = sizeof(ctdb->tunable);
125 case CTDB_CONTROL_DUMP_MEMORY: {
126 CHECK_CONTROL_DATA_SIZE(0);
127 return ctdb_dump_memory(ctdb, outdata);
130 case CTDB_CONTROL_STATISTICS_RESET: {
131 CHECK_CONTROL_DATA_SIZE(0);
132 ZERO_STRUCT(ctdb->statistics);
133 ctdb->statistics.statistics_start_time = timeval_current();
137 case CTDB_CONTROL_GETVNNMAP:
138 return ctdb_control_getvnnmap(ctdb, opcode, indata, outdata);
140 case CTDB_CONTROL_GET_DBMAP:
141 return ctdb_control_getdbmap(ctdb, opcode, indata, outdata);
143 case CTDB_CONTROL_GET_NODEMAPv4:
144 return ctdb_control_getnodemapv4(ctdb, opcode, indata, outdata);
146 case CTDB_CONTROL_GET_NODEMAP:
147 return ctdb_control_getnodemap(ctdb, opcode, indata, outdata);
149 case CTDB_CONTROL_RELOAD_NODES_FILE:
150 CHECK_CONTROL_DATA_SIZE(0);
151 return ctdb_control_reload_nodes_file(ctdb, opcode);
153 case CTDB_CONTROL_SET_DB_STICKY: {
155 struct ctdb_db_context *ctdb_db;
157 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
158 db_id = *(uint32_t *)indata.dptr;
159 ctdb_db = find_ctdb_db(ctdb, db_id);
160 if (ctdb_db == NULL) return -1;
161 return ctdb_set_db_sticky(ctdb, ctdb_db);
164 case CTDB_CONTROL_SETVNNMAP:
165 return ctdb_control_setvnnmap(ctdb, opcode, indata, outdata);
167 case CTDB_CONTROL_PULL_DB:
168 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_pulldb));
169 return ctdb_control_pull_db(ctdb, indata, outdata);
171 case CTDB_CONTROL_SET_DMASTER:
172 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_set_dmaster));
173 DEBUG(DEBUG_ERR, ("The SET_DMASTER control is not implemented "
177 case CTDB_CONTROL_PUSH_DB:
178 return ctdb_control_push_db(ctdb, indata);
180 case CTDB_CONTROL_GET_RECMODE: {
182 if (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE) {
183 return CTDB_RECOVERY_ACTIVE;
185 for (i=1; i<=NUM_DB_PRIORITIES; i++) {
186 if (ctdb->freeze_mode[i] == CTDB_FREEZE_FROZEN) {
187 return CTDB_RECOVERY_ACTIVE;
190 return CTDB_RECOVERY_NORMAL;
193 case CTDB_CONTROL_SET_RECMASTER: {
194 return ctdb_control_set_recmaster(ctdb, opcode, indata);
197 case CTDB_CONTROL_GET_RECMASTER:
198 return ctdb->recovery_master;
200 case CTDB_CONTROL_GET_PID:
203 case CTDB_CONTROL_GET_PNN:
206 case CTDB_CONTROL_PING:
207 CHECK_CONTROL_DATA_SIZE(0);
208 return ctdb->num_clients;
210 case CTDB_CONTROL_SET_DB_READONLY: {
212 struct ctdb_db_context *ctdb_db;
214 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
215 db_id = *(uint32_t *)indata.dptr;
216 ctdb_db = find_ctdb_db(ctdb, db_id);
217 if (ctdb_db == NULL) return -1;
218 return ctdb_set_db_readonly(ctdb, ctdb_db);
220 case CTDB_CONTROL_GET_DBNAME: {
222 struct ctdb_db_context *ctdb_db;
224 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
225 db_id = *(uint32_t *)indata.dptr;
226 ctdb_db = find_ctdb_db(ctdb, db_id);
227 if (ctdb_db == NULL) return -1;
228 outdata->dptr = discard_const(ctdb_db->db_name);
229 outdata->dsize = strlen(ctdb_db->db_name)+1;
233 case CTDB_CONTROL_GETDBPATH: {
235 struct ctdb_db_context *ctdb_db;
237 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
238 db_id = *(uint32_t *)indata.dptr;
239 ctdb_db = find_ctdb_db(ctdb, db_id);
240 if (ctdb_db == NULL) return -1;
241 outdata->dptr = discard_const(ctdb_db->db_path);
242 outdata->dsize = strlen(ctdb_db->db_path)+1;
246 case CTDB_CONTROL_DB_ATTACH:
247 return ctdb_control_db_attach(ctdb, indata, outdata, srvid, false, client_id, c, async_reply);
249 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
250 return ctdb_control_db_attach(ctdb, indata, outdata, srvid, true, client_id, c, async_reply);
252 case CTDB_CONTROL_SET_CALL: {
253 struct ctdb_control_set_call *sc =
254 (struct ctdb_control_set_call *)indata.dptr;
255 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_set_call));
256 return ctdb_daemon_set_call(ctdb, sc->db_id, sc->fn, sc->id);
259 case CTDB_CONTROL_TRAVERSE_START:
260 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_traverse_start));
261 return ctdb_control_traverse_start(ctdb, indata, outdata, srcnode, client_id);
263 case CTDB_CONTROL_TRAVERSE_START_EXT:
264 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_traverse_start_ext));
265 return ctdb_control_traverse_start_ext(ctdb, indata, outdata, srcnode, client_id);
267 case CTDB_CONTROL_TRAVERSE_ALL:
268 return ctdb_control_traverse_all(ctdb, indata, outdata);
270 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
271 return ctdb_control_traverse_all_ext(ctdb, indata, outdata);
273 case CTDB_CONTROL_TRAVERSE_DATA:
274 return ctdb_control_traverse_data(ctdb, indata, outdata);
276 case CTDB_CONTROL_TRAVERSE_KILL:
277 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_traverse_start));
278 return ctdb_control_traverse_kill(ctdb, indata, outdata, srcnode);
280 case CTDB_CONTROL_REGISTER_SRVID:
281 return daemon_register_message_handler(ctdb, client_id, srvid);
283 case CTDB_CONTROL_DEREGISTER_SRVID:
284 return daemon_deregister_message_handler(ctdb, client_id, srvid);
286 case CTDB_CONTROL_CHECK_SRVIDS:
287 return daemon_check_srvids(ctdb, indata, outdata);
289 case CTDB_CONTROL_ENABLE_SEQNUM:
290 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
291 return ctdb_ltdb_enable_seqnum(ctdb, *(uint32_t *)indata.dptr);
293 case CTDB_CONTROL_UPDATE_SEQNUM:
294 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
295 return ctdb_ltdb_update_seqnum(ctdb, *(uint32_t *)indata.dptr, srcnode);
297 case CTDB_CONTROL_FREEZE:
298 CHECK_CONTROL_DATA_SIZE(0);
299 return ctdb_control_freeze(ctdb, c, async_reply);
301 case CTDB_CONTROL_THAW:
302 CHECK_CONTROL_DATA_SIZE(0);
303 return ctdb_control_thaw(ctdb, (uint32_t)c->srvid);
305 case CTDB_CONTROL_SET_RECMODE:
306 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
307 return ctdb_control_set_recmode(ctdb, c, indata, async_reply, errormsg);
309 case CTDB_CONTROL_GET_MONMODE:
310 CHECK_CONTROL_DATA_SIZE(0);
311 return ctdb_monitoring_mode(ctdb);
313 case CTDB_CONTROL_ENABLE_MONITOR:
314 CHECK_CONTROL_DATA_SIZE(0);
315 ctdb_enable_monitoring(ctdb);
318 case CTDB_CONTROL_RUN_EVENTSCRIPTS:
319 return ctdb_run_eventscripts(ctdb, c, indata, async_reply);
321 case CTDB_CONTROL_DISABLE_MONITOR:
322 CHECK_CONTROL_DATA_SIZE(0);
323 ctdb_disable_monitoring(ctdb);
326 case CTDB_CONTROL_SHUTDOWN:
327 DEBUG(DEBUG_NOTICE,("Received SHUTDOWN command. Stopping CTDB daemon.\n"));
328 ctdb_stop_recoverd(ctdb);
329 ctdb_stop_keepalive(ctdb);
330 ctdb_stop_monitoring(ctdb);
331 ctdb_release_all_ips(ctdb);
332 ctdb_event_script(ctdb, CTDB_EVENT_SHUTDOWN);
333 if (ctdb->methods != NULL) {
334 ctdb->methods->shutdown(ctdb);
338 case CTDB_CONTROL_TAKEOVER_IPv4:
339 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ipv4));
340 return ctdb_control_takeover_ipv4(ctdb, c, indata, async_reply);
342 case CTDB_CONTROL_TAKEOVER_IP:
343 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ip));
344 return ctdb_control_takeover_ip(ctdb, c, indata, async_reply);
346 case CTDB_CONTROL_RELEASE_IPv4:
347 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ipv4));
348 return ctdb_control_release_ipv4(ctdb, c, indata, async_reply);
350 case CTDB_CONTROL_RELEASE_IP:
351 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ip));
352 return ctdb_control_release_ip(ctdb, c, indata, async_reply);
354 case CTDB_CONTROL_IPREALLOCATED:
355 CHECK_CONTROL_DATA_SIZE(0);
356 return ctdb_control_ipreallocated(ctdb, c, async_reply);
358 case CTDB_CONTROL_GET_PUBLIC_IPSv4:
359 CHECK_CONTROL_DATA_SIZE(0);
360 return ctdb_control_get_public_ipsv4(ctdb, c, outdata);
362 case CTDB_CONTROL_GET_PUBLIC_IPS:
363 CHECK_CONTROL_DATA_SIZE(0);
364 return ctdb_control_get_public_ips(ctdb, c, outdata);
366 case CTDB_CONTROL_TCP_CLIENT:
367 return ctdb_control_tcp_client(ctdb, client_id, indata);
369 case CTDB_CONTROL_STARTUP:
370 CHECK_CONTROL_DATA_SIZE(0);
371 return ctdb_control_startup(ctdb, srcnode);
373 case CTDB_CONTROL_TCP_ADD:
374 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
375 return ctdb_control_tcp_add(ctdb, indata, false);
377 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
378 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
379 return ctdb_control_tcp_add(ctdb, indata, true);
381 case CTDB_CONTROL_TCP_REMOVE:
382 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
383 return ctdb_control_tcp_remove(ctdb, indata);
385 case CTDB_CONTROL_SET_TUNABLE:
386 return ctdb_control_set_tunable(ctdb, indata);
388 case CTDB_CONTROL_GET_TUNABLE:
389 return ctdb_control_get_tunable(ctdb, indata, outdata);
391 case CTDB_CONTROL_LIST_TUNABLES:
392 return ctdb_control_list_tunables(ctdb, outdata);
394 case CTDB_CONTROL_MODIFY_FLAGS:
395 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_node_flag_change));
396 return ctdb_control_modflags(ctdb, indata);
398 case CTDB_CONTROL_KILL_TCP:
399 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_killtcp));
400 return ctdb_control_kill_tcp(ctdb, indata);
402 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
403 CHECK_CONTROL_DATA_SIZE(sizeof(ctdb_sock_addr));
404 return ctdb_control_get_tcp_tickle_list(ctdb, indata, outdata);
406 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
407 /* data size is verified in the called function */
408 return ctdb_control_set_tcp_tickle_list(ctdb, indata);
410 case CTDB_CONTROL_REGISTER_SERVER_ID:
411 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
412 return ctdb_control_register_server_id(ctdb, client_id, indata);
414 case CTDB_CONTROL_UNREGISTER_SERVER_ID:
415 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
416 return ctdb_control_unregister_server_id(ctdb, indata);
418 case CTDB_CONTROL_CHECK_SERVER_ID:
419 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
420 return ctdb_control_check_server_id(ctdb, indata);
422 case CTDB_CONTROL_GET_SERVER_ID_LIST:
423 CHECK_CONTROL_DATA_SIZE(0);
424 return ctdb_control_get_server_id_list(ctdb, outdata);
426 case CTDB_CONTROL_PERSISTENT_STORE:
427 return ctdb_control_persistent_store(ctdb, c, indata, async_reply);
429 case CTDB_CONTROL_UPDATE_RECORD:
430 return ctdb_control_update_record(ctdb, c, indata, async_reply);
432 case CTDB_CONTROL_SEND_GRATIOUS_ARP:
433 return ctdb_control_send_gratious_arp(ctdb, indata);
435 case CTDB_CONTROL_TRANSACTION_START:
436 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
437 return ctdb_control_transaction_start(ctdb, *(uint32_t *)indata.dptr);
439 case CTDB_CONTROL_TRANSACTION_COMMIT:
440 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
441 return ctdb_control_transaction_commit(ctdb, *(uint32_t *)indata.dptr);
443 case CTDB_CONTROL_WIPE_DATABASE:
444 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_wipe_database));
445 return ctdb_control_wipe_database(ctdb, indata);
447 case CTDB_CONTROL_UPTIME:
448 return ctdb_control_uptime(ctdb, outdata);
450 case CTDB_CONTROL_START_RECOVERY:
451 return ctdb_control_start_recovery(ctdb, c, async_reply);
453 case CTDB_CONTROL_END_RECOVERY:
454 return ctdb_control_end_recovery(ctdb, c, async_reply);
456 case CTDB_CONTROL_TRY_DELETE_RECORDS:
457 return ctdb_control_try_delete_records(ctdb, indata, outdata);
459 case CTDB_CONTROL_ADD_PUBLIC_IP:
460 return ctdb_control_add_public_address(ctdb, indata);
462 case CTDB_CONTROL_DEL_PUBLIC_IP:
463 return ctdb_control_del_public_address(ctdb, indata);
465 case CTDB_CONTROL_GET_CAPABILITIES:
466 return ctdb_control_get_capabilities(ctdb, outdata);
468 case CTDB_CONTROL_START_PERSISTENT_UPDATE:
469 return ctdb_control_start_persistent_update(ctdb, c, indata);
471 case CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE:
472 return ctdb_control_cancel_persistent_update(ctdb, c, indata);
474 case CTDB_CONTROL_TRANS2_COMMIT:
475 case CTDB_CONTROL_TRANS2_COMMIT_RETRY:
476 return ctdb_control_trans2_commit(ctdb, c, indata, async_reply);
478 case CTDB_CONTROL_TRANS2_ERROR:
479 return ctdb_control_trans2_error(ctdb, c);
481 case CTDB_CONTROL_TRANS2_FINISHED:
482 return ctdb_control_trans2_finished(ctdb, c);
484 case CTDB_CONTROL_TRANS2_ACTIVE:
485 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
486 return ctdb_control_trans2_active(ctdb, c, *(uint32_t *)indata.dptr);
488 case CTDB_CONTROL_TRANS3_COMMIT:
489 return ctdb_control_trans3_commit(ctdb, c, indata, async_reply);
491 case CTDB_CONTROL_RECD_PING:
492 CHECK_CONTROL_DATA_SIZE(0);
493 return ctdb_control_recd_ping(ctdb);
495 case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS:
496 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
497 return ctdb_control_get_event_script_status(ctdb, *(uint32_t *)indata.dptr, outdata);
499 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
500 CHECK_CONTROL_DATA_SIZE(sizeof(double));
501 CTDB_UPDATE_RECLOCK_LATENCY(ctdb, "recd reclock", reclock.recd, *((double *)indata.dptr));
503 case CTDB_CONTROL_GET_RECLOCK_FILE:
504 CHECK_CONTROL_DATA_SIZE(0);
505 if (ctdb->recovery_lock_file != NULL) {
506 outdata->dptr = discard_const(ctdb->recovery_lock_file);
507 outdata->dsize = strlen(ctdb->recovery_lock_file) + 1;
510 case CTDB_CONTROL_SET_RECLOCK_FILE:
511 ctdb->tunable.verify_recovery_lock = 0;
512 if (ctdb->recovery_lock_file != NULL) {
513 talloc_free(ctdb->recovery_lock_file);
514 ctdb->recovery_lock_file = NULL;
516 if (indata.dsize > 0) {
517 ctdb->recovery_lock_file = talloc_strdup(ctdb, discard_const(indata.dptr));
518 ctdb->tunable.verify_recovery_lock = 1;
522 case CTDB_CONTROL_STOP_NODE:
523 CHECK_CONTROL_DATA_SIZE(0);
524 return ctdb_control_stop_node(ctdb);
526 case CTDB_CONTROL_CONTINUE_NODE:
527 CHECK_CONTROL_DATA_SIZE(0);
528 return ctdb_control_continue_node(ctdb);
530 case CTDB_CONTROL_SET_NATGWSTATE: {
533 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
534 natgwstate = *(uint32_t *)indata.dptr;
535 if (natgwstate == 0) {
536 ctdb->capabilities &= ~CTDB_CAP_NATGW;
538 ctdb->capabilities |= CTDB_CAP_NATGW;
543 case CTDB_CONTROL_SET_LMASTERROLE: {
544 uint32_t lmasterrole;
546 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
547 lmasterrole = *(uint32_t *)indata.dptr;
548 if (lmasterrole == 0) {
549 ctdb->capabilities &= ~CTDB_CAP_LMASTER;
551 ctdb->capabilities |= CTDB_CAP_LMASTER;
556 case CTDB_CONTROL_SET_RECMASTERROLE: {
557 uint32_t recmasterrole;
559 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
560 recmasterrole = *(uint32_t *)indata.dptr;
561 if (recmasterrole == 0) {
562 ctdb->capabilities &= ~CTDB_CAP_RECMASTER;
564 ctdb->capabilities |= CTDB_CAP_RECMASTER;
569 case CTDB_CONTROL_ENABLE_SCRIPT:
570 return ctdb_control_enable_script(ctdb, indata);
572 case CTDB_CONTROL_DISABLE_SCRIPT:
573 return ctdb_control_disable_script(ctdb, indata);
575 case CTDB_CONTROL_SET_BAN_STATE:
576 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_ban_time));
577 return ctdb_control_set_ban_state(ctdb, indata);
579 case CTDB_CONTROL_GET_BAN_STATE:
580 CHECK_CONTROL_DATA_SIZE(0);
581 return ctdb_control_get_ban_state(ctdb, outdata);
583 case CTDB_CONTROL_SET_DB_PRIORITY:
584 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_db_priority));
585 return ctdb_control_set_db_priority(ctdb, indata);
587 case CTDB_CONTROL_GET_DB_PRIORITY: {
589 struct ctdb_db_context *ctdb_db;
591 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
592 db_id = *(uint32_t *)indata.dptr;
593 ctdb_db = find_ctdb_db(ctdb, db_id);
594 if (ctdb_db == NULL) return -1;
595 return ctdb_db->priority;
598 case CTDB_CONTROL_TRANSACTION_CANCEL:
599 CHECK_CONTROL_DATA_SIZE(0);
600 return ctdb_control_transaction_cancel(ctdb);
602 case CTDB_CONTROL_REGISTER_NOTIFY:
603 return ctdb_control_register_notify(ctdb, client_id, indata);
605 case CTDB_CONTROL_DEREGISTER_NOTIFY:
606 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_client_notify_deregister));
607 return ctdb_control_deregister_notify(ctdb, client_id, indata);
609 case CTDB_CONTROL_GET_LOG:
610 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_get_log_addr));
611 return ctdb_control_get_log(ctdb, indata);
613 case CTDB_CONTROL_CLEAR_LOG:
614 return ctdb_control_clear_log(ctdb);
616 case CTDB_CONTROL_GET_DB_SEQNUM:
617 CHECK_CONTROL_DATA_SIZE(sizeof(uint64_t));
618 return ctdb_control_get_db_seqnum(ctdb, indata, outdata);
620 case CTDB_CONTROL_DB_SET_HEALTHY:
621 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
622 return ctdb_control_db_set_healthy(ctdb, indata);
624 case CTDB_CONTROL_DB_GET_HEALTH:
625 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
626 return ctdb_control_db_get_health(ctdb, indata, outdata);
628 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
629 CHECK_CONTROL_DATA_SIZE(sizeof(ctdb_sock_addr));
630 return ctdb_control_get_public_ip_info(ctdb, c, indata, outdata);
632 case CTDB_CONTROL_GET_IFACES:
633 CHECK_CONTROL_DATA_SIZE(0);
634 return ctdb_control_get_ifaces(ctdb, c, outdata);
636 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
637 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_iface_info));
638 return ctdb_control_set_iface_link(ctdb, c, indata);
640 case CTDB_CONTROL_GET_STAT_HISTORY:
641 CHECK_CONTROL_DATA_SIZE(0);
642 return ctdb_control_get_stat_history(ctdb, c, outdata);
644 case CTDB_CONTROL_SCHEDULE_FOR_DELETION: {
645 struct ctdb_control_schedule_for_deletion *d;
646 size_t size = offsetof(struct ctdb_control_schedule_for_deletion, key);
647 CHECK_CONTROL_MIN_DATA_SIZE(size);
648 d = (struct ctdb_control_schedule_for_deletion *)indata.dptr;
650 CHECK_CONTROL_DATA_SIZE(size);
651 return ctdb_control_schedule_for_deletion(ctdb, indata);
653 case CTDB_CONTROL_GET_DB_STATISTICS:
654 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
655 return ctdb_control_get_db_statistics(ctdb, *(uint32_t *)indata.dptr, outdata);
657 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
658 CHECK_CONTROL_DATA_SIZE(0);
659 return ctdb_control_reload_public_ips(ctdb, c, async_reply);
661 case CTDB_CONTROL_RECEIVE_RECORDS:
662 return ctdb_control_receive_records(ctdb, indata, outdata);
665 DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
671 send a reply for a ctdb control
673 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
674 TDB_DATA *outdata, int32_t status, const char *errormsg)
676 struct ctdb_reply_control *r;
679 /* some controls send no reply */
680 if (c->flags & CTDB_CTRL_FLAG_NOREPLY) {
684 len = offsetof(struct ctdb_reply_control, data) + (outdata?outdata->dsize:0);
686 len += strlen(errormsg);
688 r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CONTROL, len, struct ctdb_reply_control);
690 DEBUG(DEBUG_ERR,(__location__ "Unable to allocate transport - OOM or transport is down\n"));
694 r->hdr.destnode = c->hdr.srcnode;
695 r->hdr.reqid = c->hdr.reqid;
697 r->datalen = outdata?outdata->dsize:0;
698 if (outdata && outdata->dsize) {
699 memcpy(&r->data[0], outdata->dptr, outdata->dsize);
702 r->errorlen = strlen(errormsg);
703 memcpy(&r->data[r->datalen], errormsg, r->errorlen);
706 ctdb_queue_packet_opcode(ctdb, &r->hdr, c->opcode);
712 called when a CTDB_REQ_CONTROL packet comes in
714 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
716 struct ctdb_req_control *c = (struct ctdb_req_control *)hdr;
717 TDB_DATA data, *outdata;
719 bool async_reply = false;
720 const char *errormsg = NULL;
722 data.dptr = &c->data[0];
723 data.dsize = c->datalen;
725 outdata = talloc_zero(c, TDB_DATA);
727 status = ctdb_control_dispatch(ctdb, c, data, outdata, hdr->srcnode,
728 &errormsg, &async_reply);
731 ctdb_request_control_reply(ctdb, c, outdata, status, errormsg);
736 called when a CTDB_REPLY_CONTROL packet comes in
738 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
740 struct ctdb_reply_control *c = (struct ctdb_reply_control *)hdr;
742 struct ctdb_control_state *state;
743 const char *errormsg = NULL;
745 state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_control_state);
747 DEBUG(DEBUG_ERR,("pnn %u Invalid reqid %u in ctdb_reply_control\n",
748 ctdb->pnn, hdr->reqid));
752 if (hdr->reqid != state->reqid) {
753 /* we found a record but it was the wrong one */
754 DEBUG(DEBUG_ERR, ("Dropped orphaned control reply with reqid:%u\n", hdr->reqid));
758 data.dptr = &c->data[0];
759 data.dsize = c->datalen;
761 errormsg = talloc_strndup(state,
762 (char *)&c->data[c->datalen], c->errorlen);
765 /* make state a child of the packet, so it goes away when the packet
767 talloc_steal(hdr, state);
769 state->callback(ctdb, c->status, data, errormsg, state->private_data);
772 static int ctdb_control_destructor(struct ctdb_control_state *state)
774 ctdb_reqid_remove(state->ctdb, state->reqid);
779 handle a timeout of a control
781 static void ctdb_control_timeout(struct event_context *ev, struct timed_event *te,
782 struct timeval t, void *private_data)
784 struct ctdb_control_state *state = talloc_get_type(private_data, struct ctdb_control_state);
785 TALLOC_CTX *tmp_ctx = talloc_new(ev);
787 CTDB_INCREMENT_STAT(state->ctdb, timeouts.control);
789 talloc_steal(tmp_ctx, state);
791 state->callback(state->ctdb, -1, tdb_null,
792 "ctdb_control timed out",
793 state->private_data);
794 talloc_free(tmp_ctx);
799 send a control message to a node
801 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
802 uint64_t srvid, uint32_t opcode, uint32_t client_id,
805 ctdb_control_callback_fn_t callback,
808 struct ctdb_req_control *c;
809 struct ctdb_control_state *state;
812 if (ctdb->methods == NULL) {
813 DEBUG(DEBUG_INFO,(__location__ " Failed to send control. Transport is DOWN\n"));
817 if (((destnode == CTDB_BROADCAST_VNNMAP) ||
818 (destnode == CTDB_BROADCAST_ALL) ||
819 (destnode == CTDB_BROADCAST_CONNECTED)) &&
820 !(flags & CTDB_CTRL_FLAG_NOREPLY)) {
821 DEBUG(DEBUG_CRIT,("Attempt to broadcast control without NOREPLY\n"));
825 if (destnode != CTDB_BROADCAST_VNNMAP &&
826 destnode != CTDB_BROADCAST_ALL &&
827 destnode != CTDB_BROADCAST_CONNECTED &&
828 (!ctdb_validate_pnn(ctdb, destnode) ||
829 (ctdb->nodes[destnode]->flags & NODE_FLAGS_DISCONNECTED))) {
830 if (!(flags & CTDB_CTRL_FLAG_NOREPLY)) {
831 callback(ctdb, -1, tdb_null, "ctdb_control to disconnected node", private_data);
836 /* the state is made a child of private_data if possible. This means any reply
837 will be discarded if the private_data goes away */
838 state = talloc(private_data?private_data:ctdb, struct ctdb_control_state);
839 CTDB_NO_MEMORY(ctdb, state);
841 state->reqid = ctdb_reqid_new(ctdb, state);
842 state->callback = callback;
843 state->private_data = private_data;
845 state->flags = flags;
847 talloc_set_destructor(state, ctdb_control_destructor);
849 len = offsetof(struct ctdb_req_control, data) + data.dsize;
850 c = ctdb_transport_allocate(ctdb, state, CTDB_REQ_CONTROL, len,
851 struct ctdb_req_control);
852 CTDB_NO_MEMORY(ctdb, c);
853 talloc_set_name_const(c, "ctdb_req_control packet");
855 c->hdr.destnode = destnode;
856 c->hdr.reqid = state->reqid;
858 c->client_id = client_id;
861 c->datalen = data.dsize;
863 memcpy(&c->data[0], data.dptr, data.dsize);
866 ctdb_queue_packet(ctdb, &c->hdr);
868 if (flags & CTDB_CTRL_FLAG_NOREPLY) {
873 if (ctdb->tunable.control_timeout) {
874 event_add_timed(ctdb->ev, state,
875 timeval_current_ofs(ctdb->tunable.control_timeout, 0),
876 ctdb_control_timeout, state);