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 "system/network.h"
21 #include "system/filesys.h"
22 #include "system/wait.h"
27 #include "lib/tdb_wrap/tdb_wrap.h"
28 #include "lib/util/dlinklist.h"
29 #include "lib/util/debug.h"
30 #include "lib/util/samba_util.h"
31 #include "lib/util/talloc_report.h"
33 #include "ctdb_private.h"
34 #include "ctdb_client.h"
36 #include "protocol/protocol_private.h"
38 #include "common/reqid.h"
39 #include "common/common.h"
40 #include "common/logging.h"
43 struct ctdb_control_state {
44 struct ctdb_context *ctdb;
46 ctdb_control_callback_fn_t callback;
53 dump talloc memory hierarchy, returning it as a blob to the client
55 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata)
60 report = talloc_report_str(outdata, NULL);
63 (__location__ " talloc_report_str failed\n"));
66 reportlen = talloc_get_size(report);
69 reportlen -= 1; /* strip trailing zero */
72 outdata->dptr = (uint8_t *)report;
73 outdata->dsize = reportlen;
77 static int32_t control_not_implemented(const char *unsupported,
78 const char *alternate)
80 if (alternate == NULL) {
82 ("Control %s is not implemented any more\n",
86 ("Control %s is not implemented any more, use %s instead\n",
87 unsupported, alternate));
92 struct ctdb_echo_data_state {
93 struct ctdb_context *ctdb;
94 struct ctdb_req_control_old *c;
95 struct ctdb_echo_data *data;
98 static void ctdb_echo_data_timeout(
99 struct tevent_context *ev,
100 struct tevent_timer *te,
104 static int32_t ctdb_control_echo_data(
105 struct ctdb_context *ctdb,
106 struct ctdb_req_control_old *c,
110 struct ctdb_echo_data_state *state = NULL;
111 struct tevent_timer *te = NULL;
116 state = talloc_zero(ctdb, struct ctdb_echo_data_state);
117 CTDB_NO_MEMORY(ctdb, state);
120 ret = ctdb_echo_data_pull(
121 indata.dptr, indata.dsize, state, &state->data, &np);
123 DBG_DEBUG("ctdb_echo_data_pull failed: %s\n",
129 te = tevent_add_timer(
132 timeval_current_ofs_msec(delay),
133 ctdb_echo_data_timeout,
136 DBG_DEBUG("tevent_add_timer failed\n");
141 state->c = talloc_move(state, &c);
147 static void ctdb_echo_data_timeout(
148 struct tevent_context *ev,
149 struct tevent_timer *te,
153 struct ctdb_echo_data_state *state = talloc_get_type_abort(
154 private_data, struct ctdb_echo_data_state);
155 size_t len = ctdb_echo_data_len(state->data);
160 DBG_DEBUG("reqid=%"PRIu32" len=%zu\n", state->c->hdr.reqid, len);
162 buf = talloc_array(state, uint8_t, len);
164 DBG_WARNING("talloc_array(%zu) failed\n", len);
167 ctdb_echo_data_push(state->data, buf, &np);
168 data = (TDB_DATA) { .dptr = buf, .dsize = np };
170 ctdb_request_control_reply(state->ctdb, state->c, &data, 0, NULL);
176 static int ctdb_control_disable_node(struct ctdb_context *ctdb)
178 struct ctdb_node *node;
180 node = ctdb_find_node(ctdb, CTDB_CURRENT_NODE);
183 DBG_ERR("Unable to find current node\n");
187 D_ERR("Disable node\n");
188 node->flags |= NODE_FLAGS_PERMANENTLY_DISABLED;
193 static int ctdb_control_enable_node(struct ctdb_context *ctdb)
195 struct ctdb_node *node;
197 node = ctdb_find_node(ctdb, CTDB_CURRENT_NODE);
200 DBG_ERR("Unable to find current node\n");
204 D_ERR("Enable node\n");
205 node->flags &= ~NODE_FLAGS_PERMANENTLY_DISABLED;
211 process a control request
213 static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
214 struct ctdb_req_control_old *c,
216 TDB_DATA *outdata, uint32_t srcnode,
217 const char **errormsg,
220 uint32_t opcode = c->opcode;
221 uint64_t srvid = c->srvid;
222 uint32_t client_id = c->client_id;
223 static int level = DEBUG_ERR;
226 case CTDB_CONTROL_PROCESS_EXISTS: {
227 CHECK_CONTROL_DATA_SIZE(sizeof(pid_t));
228 return ctdb_control_process_exists(ctdb, *(pid_t *)indata.dptr);
231 case CTDB_CONTROL_SET_DEBUG: {
236 CHECK_CONTROL_DATA_SIZE(sizeof(int32_t));
237 debug.ptr = indata.dptr;
238 debuglevel_set(*debug.level);
242 case CTDB_CONTROL_GET_DEBUG: {
243 CHECK_CONTROL_DATA_SIZE(0);
244 level = debuglevel_get();
245 outdata->dptr = (uint8_t *)&(level);
246 outdata->dsize = sizeof(DEBUGLEVEL);
250 case CTDB_CONTROL_STATISTICS: {
251 CHECK_CONTROL_DATA_SIZE(0);
252 ctdb->statistics.memory_used = talloc_total_size(NULL);
253 ctdb->statistics.num_clients = ctdb->num_clients;
254 ctdb->statistics.frozen = (ctdb_db_all_frozen(ctdb) ? 1 : 0);
255 ctdb->statistics.recovering = (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE);
256 ctdb->statistics.statistics_current_time = timeval_current();
258 outdata->dptr = (uint8_t *)&ctdb->statistics;
259 outdata->dsize = sizeof(ctdb->statistics);
263 case CTDB_CONTROL_GET_ALL_TUNABLES: {
264 CHECK_CONTROL_DATA_SIZE(0);
265 outdata->dptr = (uint8_t *)&ctdb->tunable;
266 outdata->dsize = sizeof(ctdb->tunable);
270 case CTDB_CONTROL_DUMP_MEMORY: {
271 CHECK_CONTROL_DATA_SIZE(0);
272 return ctdb_dump_memory(ctdb, outdata);
275 case CTDB_CONTROL_STATISTICS_RESET: {
276 struct ctdb_db_context *ctdb_db;
278 CHECK_CONTROL_DATA_SIZE(0);
279 ZERO_STRUCT(ctdb->statistics);
280 for (ctdb_db = ctdb->db_list;
282 ctdb_db = ctdb_db->next) {
283 ctdb_db_statistics_reset(ctdb_db);
285 ctdb->statistics.statistics_start_time = timeval_current();
289 case CTDB_CONTROL_GETVNNMAP:
290 return ctdb_control_getvnnmap(ctdb, opcode, indata, outdata);
292 case CTDB_CONTROL_GET_DBMAP:
293 return ctdb_control_getdbmap(ctdb, opcode, indata, outdata);
295 case CTDB_CONTROL_GET_NODEMAPv4:
296 return control_not_implemented("GET_NODEMAPv4", "GET_NODEMAP");
298 case CTDB_CONTROL_GET_NODEMAP:
299 return ctdb_control_getnodemap(ctdb, opcode, indata, outdata);
301 case CTDB_CONTROL_GET_NODES_FILE:
302 return ctdb_control_getnodesfile(ctdb, opcode, indata, outdata);
304 case CTDB_CONTROL_RELOAD_NODES_FILE:
305 CHECK_CONTROL_DATA_SIZE(0);
306 return ctdb_control_reload_nodes_file(ctdb, opcode);
308 case CTDB_CONTROL_SET_DB_STICKY: {
310 struct ctdb_db_context *ctdb_db;
312 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
313 db_id = *(uint32_t *)indata.dptr;
314 ctdb_db = find_ctdb_db(ctdb, db_id);
315 if (ctdb_db == NULL) return -1;
316 return ctdb_set_db_sticky(ctdb, ctdb_db);
319 case CTDB_CONTROL_SETVNNMAP:
320 return ctdb_control_setvnnmap(ctdb, opcode, indata, outdata);
322 case CTDB_CONTROL_PULL_DB:
323 return control_not_implemented("PULL_DB", NULL);
325 case CTDB_CONTROL_SET_DMASTER:
326 return control_not_implemented("SET_DMASTER", NULL);
328 case CTDB_CONTROL_PUSH_DB:
329 return control_not_implemented("PUSH_DB", NULL);
331 case CTDB_CONTROL_GET_RECMODE: {
332 return ctdb->recovery_mode;
335 case CTDB_CONTROL_SET_RECMASTER:
336 return control_not_implemented("SET_RECMASTER", NULL);
338 case CTDB_CONTROL_GET_RECMASTER:
339 return control_not_implemented("GET_RECMASTER", NULL);
341 case CTDB_CONTROL_GET_PID:
344 case CTDB_CONTROL_GET_PNN:
347 case CTDB_CONTROL_PING:
348 CHECK_CONTROL_DATA_SIZE(0);
349 return ctdb->num_clients;
351 case CTDB_CONTROL_GET_RUNSTATE:
352 CHECK_CONTROL_DATA_SIZE(0);
353 outdata->dptr = (uint8_t *)&ctdb->runstate;
354 outdata->dsize = sizeof(uint32_t);
358 case CTDB_CONTROL_SET_DB_READONLY: {
360 struct ctdb_db_context *ctdb_db;
362 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
363 db_id = *(uint32_t *)indata.dptr;
364 ctdb_db = find_ctdb_db(ctdb, db_id);
365 if (ctdb_db == NULL) return -1;
366 return ctdb_set_db_readonly(ctdb, ctdb_db);
368 case CTDB_CONTROL_GET_DBNAME: {
370 struct ctdb_db_context *ctdb_db;
372 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
373 db_id = *(uint32_t *)indata.dptr;
374 ctdb_db = find_ctdb_db(ctdb, db_id);
375 if (ctdb_db == NULL) return -1;
376 outdata->dptr = discard_const(ctdb_db->db_name);
377 outdata->dsize = strlen(ctdb_db->db_name)+1;
381 case CTDB_CONTROL_GETDBPATH: {
383 struct ctdb_db_context *ctdb_db;
385 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
386 db_id = *(uint32_t *)indata.dptr;
387 ctdb_db = find_ctdb_db(ctdb, db_id);
388 if (ctdb_db == NULL) return -1;
389 outdata->dptr = discard_const(ctdb_db->db_path);
390 outdata->dsize = strlen(ctdb_db->db_path)+1;
394 case CTDB_CONTROL_DB_ATTACH:
395 return ctdb_control_db_attach(ctdb,
404 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
405 return ctdb_control_db_attach(ctdb,
408 CTDB_DB_FLAGS_PERSISTENT,
414 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
415 return ctdb_control_db_attach(ctdb,
418 CTDB_DB_FLAGS_REPLICATED,
424 case CTDB_CONTROL_SET_CALL:
425 return control_not_implemented("SET_CALL", NULL);
427 case CTDB_CONTROL_TRAVERSE_START:
428 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_traverse_start));
429 return ctdb_control_traverse_start(ctdb, indata, outdata, srcnode, client_id);
431 case CTDB_CONTROL_TRAVERSE_START_EXT:
432 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_traverse_start_ext));
433 return ctdb_control_traverse_start_ext(ctdb, indata, outdata, srcnode, client_id);
435 case CTDB_CONTROL_TRAVERSE_ALL:
436 return ctdb_control_traverse_all(ctdb, indata, outdata);
438 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
439 return ctdb_control_traverse_all_ext(ctdb, indata, outdata);
441 case CTDB_CONTROL_TRAVERSE_DATA:
442 return ctdb_control_traverse_data(ctdb, indata, outdata);
444 case CTDB_CONTROL_TRAVERSE_KILL:
445 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_traverse_start));
446 return ctdb_control_traverse_kill(ctdb, indata, outdata, srcnode);
448 case CTDB_CONTROL_REGISTER_SRVID:
449 return daemon_register_message_handler(ctdb, client_id, srvid);
451 case CTDB_CONTROL_DEREGISTER_SRVID:
452 return daemon_deregister_message_handler(ctdb, client_id, srvid);
454 case CTDB_CONTROL_CHECK_SRVIDS:
455 return control_not_implemented("CHECK_SRVIDS", NULL);
457 case CTDB_CONTROL_ENABLE_SEQNUM:
458 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
459 return ctdb_ltdb_enable_seqnum(ctdb, *(uint32_t *)indata.dptr);
461 case CTDB_CONTROL_UPDATE_SEQNUM:
462 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
463 return ctdb_ltdb_update_seqnum(ctdb, *(uint32_t *)indata.dptr, srcnode);
465 case CTDB_CONTROL_FREEZE:
466 CHECK_CONTROL_DATA_SIZE(0);
467 return ctdb_control_freeze(ctdb, c, async_reply);
469 case CTDB_CONTROL_THAW:
470 return control_not_implemented("THAW", NULL);
472 case CTDB_CONTROL_SET_RECMODE:
473 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
474 return ctdb_control_set_recmode(ctdb, c, indata, async_reply, errormsg);
476 case CTDB_CONTROL_GET_MONMODE:
477 return control_not_implemented("GET_MONMODE", NULL);
479 case CTDB_CONTROL_ENABLE_MONITOR:
480 return control_not_implemented("ENABLE_MONITOR", NULL);
482 case CTDB_CONTROL_RUN_EVENTSCRIPTS:
483 return control_not_implemented("RUN_EVENTSCRIPTS", NULL);
485 case CTDB_CONTROL_DISABLE_MONITOR:
486 return control_not_implemented("DISABLE_MONITOR", NULL);
488 case CTDB_CONTROL_SHUTDOWN:
489 DEBUG(DEBUG_NOTICE,("Received SHUTDOWN command.\n"));
490 ctdb_shutdown_sequence(ctdb, 0);
491 /* In case above returns due to duplicate shutdown */
494 case CTDB_CONTROL_TAKEOVER_IPv4:
495 return control_not_implemented("TAKEOVER_IPv4", "TAKEOVER_IP");
497 case CTDB_CONTROL_TAKEOVER_IP:
498 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ip));
499 return ctdb_control_takeover_ip(ctdb, c, indata, async_reply);
501 case CTDB_CONTROL_RELEASE_IPv4:
502 return control_not_implemented("RELEASE_IPv4", "RELEASE_IP");
504 case CTDB_CONTROL_RELEASE_IP:
505 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ip));
506 return ctdb_control_release_ip(ctdb, c, indata, async_reply);
508 case CTDB_CONTROL_IPREALLOCATED:
509 CHECK_CONTROL_DATA_SIZE(0);
510 return ctdb_control_ipreallocated(ctdb, c, async_reply);
512 case CTDB_CONTROL_GET_PUBLIC_IPSv4:
513 return control_not_implemented("GET_PUBLIC_IPSv4",
516 case CTDB_CONTROL_GET_PUBLIC_IPS:
517 CHECK_CONTROL_DATA_SIZE(0);
518 return ctdb_control_get_public_ips(ctdb, c, outdata);
520 case CTDB_CONTROL_TCP_CLIENT:
521 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
522 return ctdb_control_tcp_client(ctdb, client_id, indata);
524 case CTDB_CONTROL_STARTUP:
525 CHECK_CONTROL_DATA_SIZE(0);
526 return ctdb_control_startup(ctdb, srcnode);
528 case CTDB_CONTROL_TCP_ADD:
529 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
530 return ctdb_control_tcp_add(ctdb, indata, false);
532 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
533 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
534 return ctdb_control_tcp_add(ctdb, indata, true);
536 case CTDB_CONTROL_TCP_REMOVE:
537 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
538 return ctdb_control_tcp_remove(ctdb, indata);
540 case CTDB_CONTROL_SET_TUNABLE:
541 return ctdb_control_set_tunable(ctdb, indata);
543 case CTDB_CONTROL_GET_TUNABLE:
544 return ctdb_control_get_tunable(ctdb, indata, outdata);
546 case CTDB_CONTROL_LIST_TUNABLES:
547 return ctdb_control_list_tunables(ctdb, outdata);
549 case CTDB_CONTROL_MODIFY_FLAGS:
550 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_node_flag_change));
551 return ctdb_control_modflags(ctdb, indata);
553 case CTDB_CONTROL_KILL_TCP:
554 return control_not_implemented("KILL_TCP", NULL);
556 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
557 CHECK_CONTROL_DATA_SIZE(sizeof(ctdb_sock_addr));
558 return ctdb_control_get_tcp_tickle_list(ctdb, indata, outdata);
560 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
561 /* data size is verified in the called function */
562 return ctdb_control_set_tcp_tickle_list(ctdb, indata);
564 case CTDB_CONTROL_REGISTER_SERVER_ID:
565 return control_not_implemented("REGISTER_SERVER_ID", NULL);
567 case CTDB_CONTROL_UNREGISTER_SERVER_ID:
568 return control_not_implemented("UNREGISTER_SERVER_ID", NULL);
570 case CTDB_CONTROL_CHECK_SERVER_ID:
571 return control_not_implemented("CHECK_SERVER_ID", NULL);
573 case CTDB_CONTROL_GET_SERVER_ID_LIST:
574 return control_not_implemented("SERVER_ID_LIST", NULL);
576 case CTDB_CONTROL_PERSISTENT_STORE:
577 return control_not_implemented("PERSISTENT_STORE", NULL);
579 case CTDB_CONTROL_UPDATE_RECORD:
580 return ctdb_control_update_record(ctdb, c, indata, async_reply);
582 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
583 return ctdb_control_send_gratious_arp(ctdb, indata);
585 case CTDB_CONTROL_TRANSACTION_START:
586 return control_not_implemented("TRANSACTION_START", NULL);
588 case CTDB_CONTROL_TRANSACTION_COMMIT:
589 return control_not_implemented("TRANSACTION_COMMIT", NULL);
591 case CTDB_CONTROL_WIPE_DATABASE:
592 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_transdb));
593 return ctdb_control_wipe_database(ctdb, indata);
595 case CTDB_CONTROL_UPTIME:
596 return ctdb_control_uptime(ctdb, outdata);
598 case CTDB_CONTROL_START_RECOVERY:
599 return ctdb_control_start_recovery(ctdb, c, async_reply);
601 case CTDB_CONTROL_END_RECOVERY:
602 return ctdb_control_end_recovery(ctdb, c, async_reply);
604 case CTDB_CONTROL_TRY_DELETE_RECORDS:
605 return ctdb_control_try_delete_records(ctdb, indata, outdata);
607 case CTDB_CONTROL_ADD_PUBLIC_IP:
608 return ctdb_control_add_public_address(ctdb, indata);
610 case CTDB_CONTROL_DEL_PUBLIC_IP:
611 return ctdb_control_del_public_address(ctdb, indata);
613 case CTDB_CONTROL_GET_CAPABILITIES:
614 return ctdb_control_get_capabilities(ctdb, outdata);
616 case CTDB_CONTROL_START_PERSISTENT_UPDATE:
617 return ctdb_control_start_persistent_update(ctdb, c, indata);
619 case CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE:
620 return ctdb_control_cancel_persistent_update(ctdb, c, indata);
622 case CTDB_CONTROL_TRANS2_COMMIT:
623 case CTDB_CONTROL_TRANS2_COMMIT_RETRY:
624 return control_not_implemented("TRANS2_COMMIT", "TRANS3_COMMIT");
626 case CTDB_CONTROL_TRANS2_ERROR:
627 return control_not_implemented("TRANS2_ERROR", NULL);
629 case CTDB_CONTROL_TRANS2_FINISHED:
630 return control_not_implemented("TRANS2_FINISHED", NULL);
632 case CTDB_CONTROL_TRANS2_ACTIVE:
633 return control_not_implemented("TRANS2_ACTIVE", NULL);
635 case CTDB_CONTROL_TRANS3_COMMIT:
636 return ctdb_control_trans3_commit(ctdb, c, indata, async_reply);
638 case CTDB_CONTROL_RECD_PING:
639 CHECK_CONTROL_DATA_SIZE(0);
640 return ctdb_control_recd_ping(ctdb);
642 case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS:
643 return control_not_implemented("GET_EVENT_SCRIPT_STATUS", NULL);
645 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
646 CHECK_CONTROL_DATA_SIZE(sizeof(double));
647 CTDB_UPDATE_RECLOCK_LATENCY(ctdb, "recd reclock", reclock.recd, *((double *)indata.dptr));
649 case CTDB_CONTROL_GET_RECLOCK_FILE:
650 CHECK_CONTROL_DATA_SIZE(0);
651 if (ctdb->recovery_lock != NULL) {
652 outdata->dptr = discard_const(ctdb->recovery_lock);
653 outdata->dsize = strlen(ctdb->recovery_lock) + 1;
656 case CTDB_CONTROL_SET_RECLOCK_FILE:
657 return control_not_implemented("SET_RECLOCK", NULL);
659 case CTDB_CONTROL_STOP_NODE:
660 CHECK_CONTROL_DATA_SIZE(0);
661 return ctdb_control_stop_node(ctdb);
663 case CTDB_CONTROL_CONTINUE_NODE:
664 CHECK_CONTROL_DATA_SIZE(0);
665 return ctdb_control_continue_node(ctdb);
667 case CTDB_CONTROL_SET_NATGWSTATE:
668 return control_not_implemented("SET_NATGWSTATE", NULL);
670 case CTDB_CONTROL_SET_LMASTERROLE: {
671 uint32_t lmasterrole;
673 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
674 lmasterrole = *(uint32_t *)indata.dptr;
675 if (lmasterrole == 0) {
676 ctdb->capabilities &= ~CTDB_CAP_LMASTER;
678 ctdb->capabilities |= CTDB_CAP_LMASTER;
683 case CTDB_CONTROL_SET_RECMASTERROLE: {
684 uint32_t recmasterrole;
686 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
687 recmasterrole = *(uint32_t *)indata.dptr;
688 if (recmasterrole == 0) {
689 ctdb->capabilities &= ~CTDB_CAP_RECMASTER;
691 ctdb->capabilities |= CTDB_CAP_RECMASTER;
696 case CTDB_CONTROL_ENABLE_SCRIPT:
697 return control_not_implemented("ENABLE_SCRIPT", NULL);
699 case CTDB_CONTROL_DISABLE_SCRIPT:
700 return control_not_implemented("DISABLE_SCRIPT", NULL);
702 case CTDB_CONTROL_SET_BAN_STATE:
703 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_ban_state));
704 return ctdb_control_set_ban_state(ctdb, indata);
706 case CTDB_CONTROL_GET_BAN_STATE:
707 CHECK_CONTROL_DATA_SIZE(0);
708 return ctdb_control_get_ban_state(ctdb, outdata);
710 case CTDB_CONTROL_SET_DB_PRIORITY:
711 return control_not_implemented("SET_DB_PRIORITY", NULL);
713 case CTDB_CONTROL_GET_DB_PRIORITY:
714 return control_not_implemented("GET_DB_PRIORITY", NULL);
716 case CTDB_CONTROL_TRANSACTION_CANCEL:
717 return control_not_implemented("TRANSACTION_CANCEL", NULL);
719 case CTDB_CONTROL_REGISTER_NOTIFY:
720 return ctdb_control_register_notify(ctdb, client_id, indata);
722 case CTDB_CONTROL_DEREGISTER_NOTIFY:
723 CHECK_CONTROL_DATA_SIZE(sizeof(uint64_t));
724 return ctdb_control_deregister_notify(ctdb, client_id, indata);
726 case CTDB_CONTROL_GET_LOG:
727 return control_not_implemented("GET_LOG", NULL);
729 case CTDB_CONTROL_CLEAR_LOG:
730 return control_not_implemented("CLEAR_LOG", NULL);
732 case CTDB_CONTROL_GET_DB_SEQNUM:
733 CHECK_CONTROL_DATA_SIZE(sizeof(uint64_t));
734 return ctdb_control_get_db_seqnum(ctdb, indata, outdata);
736 case CTDB_CONTROL_DB_SET_HEALTHY:
737 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
738 return ctdb_control_db_set_healthy(ctdb, indata);
740 case CTDB_CONTROL_DB_GET_HEALTH:
741 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
742 return ctdb_control_db_get_health(ctdb, indata, outdata);
744 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
745 CHECK_CONTROL_DATA_SIZE(sizeof(ctdb_sock_addr));
746 return ctdb_control_get_public_ip_info(ctdb, c, indata, outdata);
748 case CTDB_CONTROL_GET_IFACES:
749 CHECK_CONTROL_DATA_SIZE(0);
750 return ctdb_control_get_ifaces(ctdb, c, outdata);
752 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
753 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_iface));
754 return ctdb_control_set_iface_link(ctdb, c, indata);
756 case CTDB_CONTROL_GET_STAT_HISTORY:
757 CHECK_CONTROL_DATA_SIZE(0);
758 return ctdb_control_get_stat_history(ctdb, c, outdata);
760 case CTDB_CONTROL_SCHEDULE_FOR_DELETION: {
761 struct ctdb_control_schedule_for_deletion *d;
762 size_t size = offsetof(struct ctdb_control_schedule_for_deletion, key);
763 CHECK_CONTROL_MIN_DATA_SIZE(size);
764 d = (struct ctdb_control_schedule_for_deletion *)indata.dptr;
766 CHECK_CONTROL_DATA_SIZE(size);
767 return ctdb_control_schedule_for_deletion(ctdb, indata);
769 case CTDB_CONTROL_GET_DB_STATISTICS:
770 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
771 return ctdb_control_get_db_statistics(ctdb, *(uint32_t *)indata.dptr, outdata);
773 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
774 CHECK_CONTROL_DATA_SIZE(0);
775 return ctdb_control_reload_public_ips(ctdb, c, async_reply);
777 case CTDB_CONTROL_RECEIVE_RECORDS:
778 return control_not_implemented("RECEIVE_RECORDS", NULL);
780 case CTDB_CONTROL_DB_DETACH:
781 return ctdb_control_db_detach(ctdb, indata, client_id);
783 case CTDB_CONTROL_DB_FREEZE:
784 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
785 return ctdb_control_db_freeze(ctdb, c, *(uint32_t *)indata.dptr,
788 case CTDB_CONTROL_DB_THAW:
789 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
790 return ctdb_control_db_thaw(ctdb, *(uint32_t *)indata.dptr);
792 case CTDB_CONTROL_DB_TRANSACTION_START:
793 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_transdb));
794 return ctdb_control_db_transaction_start(ctdb, indata);
796 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
797 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_transdb));
798 return ctdb_control_db_transaction_commit(ctdb, indata);
800 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
801 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
802 return ctdb_control_db_transaction_cancel(ctdb, indata);
804 case CTDB_CONTROL_DB_PULL:
805 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_pulldb_ext));
806 return ctdb_control_db_pull(ctdb, c, indata, outdata);
808 case CTDB_CONTROL_DB_PUSH_START:
809 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_pulldb_ext));
810 return ctdb_control_db_push_start(ctdb, indata);
812 case CTDB_CONTROL_DB_PUSH_CONFIRM:
813 CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
814 return ctdb_control_db_push_confirm(ctdb, indata, outdata);
816 case CTDB_CONTROL_DB_OPEN_FLAGS: {
818 struct ctdb_db_context *ctdb_db;
821 CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
822 db_id = *(uint32_t *)indata.dptr;
823 ctdb_db = find_ctdb_db(ctdb, db_id);
824 if (ctdb_db == NULL) {
828 tdb_flags = tdb_get_flags(ctdb_db->ltdb->tdb);
830 outdata->dptr = talloc_size(outdata, sizeof(tdb_flags));
831 if (outdata->dptr == NULL) {
835 outdata->dsize = sizeof(tdb_flags);
836 memcpy(outdata->dptr, &tdb_flags, outdata->dsize);
840 case CTDB_CONTROL_CHECK_PID_SRVID:
841 CHECK_CONTROL_DATA_SIZE((sizeof(pid_t) + sizeof(uint64_t)));
842 return ctdb_control_check_pid_srvid(ctdb, indata);
844 case CTDB_CONTROL_TUNNEL_REGISTER:
845 return ctdb_control_tunnel_register(ctdb, client_id, srvid);
847 case CTDB_CONTROL_TUNNEL_DEREGISTER:
848 return ctdb_control_tunnel_deregister(ctdb, client_id, srvid);
850 case CTDB_CONTROL_VACUUM_FETCH:
851 return ctdb_control_vacuum_fetch(ctdb, indata);
853 case CTDB_CONTROL_DB_VACUUM: {
854 struct ctdb_db_vacuum db_vacuum;
856 CHECK_CONTROL_DATA_SIZE(ctdb_db_vacuum_len(&db_vacuum));
857 return ctdb_control_db_vacuum(ctdb, c, indata, async_reply);
859 case CTDB_CONTROL_ECHO_DATA: {
860 return ctdb_control_echo_data(ctdb, c, indata, async_reply);
863 case CTDB_CONTROL_DISABLE_NODE:
864 CHECK_CONTROL_DATA_SIZE(0);
865 return ctdb_control_disable_node(ctdb);
867 case CTDB_CONTROL_ENABLE_NODE:
868 CHECK_CONTROL_DATA_SIZE(0);
869 return ctdb_control_enable_node(ctdb);
871 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
872 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
873 return ctdb_control_tcp_client_disconnected(ctdb, client_id, indata);
875 case CTDB_CONTROL_TCP_CLIENT_PASSED:
876 CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
877 return ctdb_control_tcp_client_passed(ctdb, client_id, indata);
880 DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
886 send a reply for a ctdb control
888 void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control_old *c,
889 TDB_DATA *outdata, int32_t status, const char *errormsg)
891 struct ctdb_reply_control_old *r;
894 /* some controls send no reply */
895 if (c->flags & CTDB_CTRL_FLAG_NOREPLY) {
899 len = offsetof(struct ctdb_reply_control_old, data) + (outdata?outdata->dsize:0);
901 len += strlen(errormsg);
903 r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CONTROL, len, struct ctdb_reply_control_old);
905 DEBUG(DEBUG_ERR,(__location__ "Unable to allocate transport - OOM or transport is down\n"));
909 r->hdr.destnode = c->hdr.srcnode;
910 r->hdr.reqid = c->hdr.reqid;
912 r->datalen = outdata?outdata->dsize:0;
913 if (outdata && outdata->dsize) {
914 memcpy(&r->data[0], outdata->dptr, outdata->dsize);
917 r->errorlen = strlen(errormsg);
918 memcpy(&r->data[r->datalen], errormsg, r->errorlen);
921 ctdb_queue_packet_opcode(ctdb, &r->hdr, c->opcode);
927 called when a CTDB_REQ_CONTROL packet comes in
929 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
931 struct ctdb_req_control_old *c = (struct ctdb_req_control_old *)hdr;
932 TDB_DATA data, *outdata;
934 bool async_reply = false;
935 const char *errormsg = NULL;
937 data.dptr = &c->data[0];
938 data.dsize = c->datalen;
940 outdata = talloc_zero(c, TDB_DATA);
942 status = ctdb_control_dispatch(ctdb, c, data, outdata, hdr->srcnode,
943 &errormsg, &async_reply);
946 ctdb_request_control_reply(ctdb, c, outdata, status, errormsg);
951 called when a CTDB_REPLY_CONTROL packet comes in
953 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
955 struct ctdb_reply_control_old *c = (struct ctdb_reply_control_old *)hdr;
957 struct ctdb_control_state *state;
958 const char *errormsg = NULL;
960 state = reqid_find(ctdb->idr, hdr->reqid, struct ctdb_control_state);
962 DEBUG(DEBUG_ERR,("pnn %u Invalid reqid %u in ctdb_reply_control\n",
963 ctdb->pnn, hdr->reqid));
967 if (hdr->reqid != state->reqid) {
968 /* we found a record but it was the wrong one */
969 DEBUG(DEBUG_ERR, ("Dropped orphaned control reply with reqid:%u\n", hdr->reqid));
973 data.dptr = &c->data[0];
974 data.dsize = c->datalen;
976 errormsg = talloc_strndup(state,
977 (char *)&c->data[c->datalen], c->errorlen);
980 /* make state a child of the packet, so it goes away when the packet
982 talloc_steal(hdr, state);
984 state->callback(ctdb, c->status, data, errormsg, state->private_data);
987 static int ctdb_control_destructor(struct ctdb_control_state *state)
989 reqid_remove(state->ctdb->idr, state->reqid);
994 handle a timeout of a control
996 static void ctdb_control_timeout(struct tevent_context *ev,
997 struct tevent_timer *te,
998 struct timeval t, void *private_data)
1000 struct ctdb_control_state *state = talloc_get_type(private_data, struct ctdb_control_state);
1001 TALLOC_CTX *tmp_ctx = talloc_new(ev);
1003 CTDB_INCREMENT_STAT(state->ctdb, timeouts.control);
1005 talloc_steal(tmp_ctx, state);
1007 state->callback(state->ctdb, -1, tdb_null,
1008 "ctdb_control timed out",
1009 state->private_data);
1010 talloc_free(tmp_ctx);
1015 send a control message to a node
1017 int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
1018 uint64_t srvid, uint32_t opcode, uint32_t client_id,
1021 ctdb_control_callback_fn_t callback,
1024 struct ctdb_req_control_old *c;
1025 struct ctdb_control_state *state;
1028 if (ctdb->methods == NULL) {
1029 DEBUG(DEBUG_INFO,(__location__ " Failed to send control. Transport is DOWN\n"));
1033 if (((destnode == CTDB_BROADCAST_ACTIVE) ||
1034 (destnode == CTDB_BROADCAST_ALL) ||
1035 (destnode == CTDB_BROADCAST_CONNECTED)) &&
1036 !(flags & CTDB_CTRL_FLAG_NOREPLY)) {
1037 DEBUG(DEBUG_CRIT,("Attempt to broadcast control without NOREPLY\n"));
1041 if (destnode != CTDB_BROADCAST_ACTIVE &&
1042 destnode != CTDB_BROADCAST_ALL &&
1043 destnode != CTDB_BROADCAST_CONNECTED &&
1044 (!ctdb_validate_pnn(ctdb, destnode) ||
1045 (ctdb->nodes[destnode]->flags & NODE_FLAGS_DISCONNECTED))) {
1046 if (!(flags & CTDB_CTRL_FLAG_NOREPLY)) {
1047 callback(ctdb, -1, tdb_null, "ctdb_control to disconnected node", private_data);
1052 /* the state is made a child of private_data if possible. This means any reply
1053 will be discarded if the private_data goes away */
1054 state = talloc(private_data?private_data:ctdb, struct ctdb_control_state);
1055 CTDB_NO_MEMORY(ctdb, state);
1057 state->reqid = reqid_new(ctdb->idr, state);
1058 state->callback = callback;
1059 state->private_data = private_data;
1061 state->flags = flags;
1063 talloc_set_destructor(state, ctdb_control_destructor);
1065 len = offsetof(struct ctdb_req_control_old, data) + data.dsize;
1066 c = ctdb_transport_allocate(ctdb, state, CTDB_REQ_CONTROL, len,
1067 struct ctdb_req_control_old);
1068 CTDB_NO_MEMORY(ctdb, c);
1069 talloc_set_name_const(c, "ctdb_req_control packet");
1071 c->hdr.destnode = destnode;
1072 c->hdr.reqid = state->reqid;
1074 c->client_id = client_id;
1077 c->datalen = data.dsize;
1079 memcpy(&c->data[0], data.dptr, data.dsize);
1082 ctdb_queue_packet(ctdb, &c->hdr);
1084 if (flags & CTDB_CTRL_FLAG_NOREPLY) {
1089 if (ctdb->tunable.control_timeout) {
1090 tevent_add_timer(ctdb->ev, state,
1091 timeval_current_ofs(ctdb->tunable.control_timeout, 0),
1092 ctdb_control_timeout, state);