4 Copyright (C) Andrew Tridgell 2007
5 Copyright (C) Ronnie Sahlberg 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "lib/tevent/tevent.h"
23 #include "system/time.h"
24 #include "system/filesys.h"
25 #include "system/network.h"
26 #include "system/locale.h"
29 #include "../include/ctdb.h"
30 #include "../include/ctdb_client.h"
31 #include "../include/ctdb_private.h"
32 #include "../common/rb_tree.h"
35 #define ERR_TIMEOUT 20 /* timed out trying to reach node */
36 #define ERR_NONODE 21 /* node does not exist */
37 #define ERR_DISNODE 22 /* node is disconnected */
39 struct ctdb_connection *ctdb_connection;
41 static void usage(void);
51 #define TIMELIMIT() timeval_current_ofs(options.timelimit, 0)
52 #define LONGTIMELIMIT() timeval_current_ofs(options.timelimit*10, 0)
55 static int control_version(struct ctdb_context *ctdb, int argc, const char **argv)
58 #define XSTR(x) STR(x)
59 printf("CTDB version: %s\n", XSTR(CTDB_VERS));
66 verify that a node exists and is reachable
68 static void verify_node(struct ctdb_context *ctdb)
71 struct ctdb_node_map *nodemap=NULL;
73 if (options.pnn == CTDB_CURRENT_NODE) {
76 if (options.pnn == CTDB_BROADCAST_ALL) {
80 /* verify the node exists */
81 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap) != 0) {
82 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
85 if (options.pnn >= nodemap->num) {
86 DEBUG(DEBUG_ERR, ("Node %u does not exist\n", options.pnn));
89 if (nodemap->nodes[options.pnn].flags & NODE_FLAGS_DELETED) {
90 DEBUG(DEBUG_ERR, ("Node %u is DELETED\n", options.pnn));
93 if (nodemap->nodes[options.pnn].flags & NODE_FLAGS_DISCONNECTED) {
94 DEBUG(DEBUG_ERR, ("Node %u is DISCONNECTED\n", options.pnn));
98 /* verify we can access the node */
99 ret = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
101 DEBUG(DEBUG_ERR,("Can not access node. Node is not operational.\n"));
107 check if a database exists
109 static int db_exists(struct ctdb_context *ctdb, const char *db_name)
112 struct ctdb_dbid_map *dbmap=NULL;
114 ret = ctdb_ctrl_getdbmap(ctdb, TIMELIMIT(), options.pnn, ctdb, &dbmap);
116 DEBUG(DEBUG_ERR, ("Unable to get dbids from node %u\n", options.pnn));
120 for(i=0;i<dbmap->num;i++){
123 ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &name);
124 if (!strcmp(name, db_name)) {
133 see if a process exists
135 static int control_process_exists(struct ctdb_context *ctdb, int argc, const char **argv)
143 if (sscanf(argv[0], "%u:%u", &pnn, &pid) != 2) {
144 DEBUG(DEBUG_ERR, ("Badly formed pnn:pid\n"));
148 ret = ctdb_ctrl_process_exists(ctdb, pnn, pid);
150 printf("%u:%u exists\n", pnn, pid);
152 printf("%u:%u does not exist\n", pnn, pid);
158 display statistics structure
160 static void show_statistics(struct ctdb_statistics *s, int show_header)
162 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
164 const char *prefix=NULL;
166 int tmp, days, hours, minutes, seconds;
171 #define STATISTICS_FIELD(n) { #n, offsetof(struct ctdb_statistics, n) }
172 STATISTICS_FIELD(num_clients),
173 STATISTICS_FIELD(frozen),
174 STATISTICS_FIELD(recovering),
175 STATISTICS_FIELD(num_recoveries),
176 STATISTICS_FIELD(client_packets_sent),
177 STATISTICS_FIELD(client_packets_recv),
178 STATISTICS_FIELD(node_packets_sent),
179 STATISTICS_FIELD(node_packets_recv),
180 STATISTICS_FIELD(keepalive_packets_sent),
181 STATISTICS_FIELD(keepalive_packets_recv),
182 STATISTICS_FIELD(node.req_call),
183 STATISTICS_FIELD(node.reply_call),
184 STATISTICS_FIELD(node.req_dmaster),
185 STATISTICS_FIELD(node.reply_dmaster),
186 STATISTICS_FIELD(node.reply_error),
187 STATISTICS_FIELD(node.req_message),
188 STATISTICS_FIELD(node.req_control),
189 STATISTICS_FIELD(node.reply_control),
190 STATISTICS_FIELD(client.req_call),
191 STATISTICS_FIELD(client.req_message),
192 STATISTICS_FIELD(client.req_control),
193 STATISTICS_FIELD(timeouts.call),
194 STATISTICS_FIELD(timeouts.control),
195 STATISTICS_FIELD(timeouts.traverse),
196 STATISTICS_FIELD(total_calls),
197 STATISTICS_FIELD(pending_calls),
198 STATISTICS_FIELD(lockwait_calls),
199 STATISTICS_FIELD(pending_lockwait_calls),
200 STATISTICS_FIELD(childwrite_calls),
201 STATISTICS_FIELD(pending_childwrite_calls),
202 STATISTICS_FIELD(memory_used),
203 STATISTICS_FIELD(max_hop_count),
205 tmp = s->statistics_current_time.tv_sec - s->statistics_start_time.tv_sec;
214 if (options.machinereadable){
216 printf("CTDB version:");
217 printf("Current time of statistics:");
218 printf("Statistics collected since:");
219 for (i=0;i<ARRAY_SIZE(fields);i++) {
220 printf("%s:", fields[i].name);
222 printf("num_reclock_ctdbd_latency:");
223 printf("min_reclock_ctdbd_latency:");
224 printf("avg_reclock_ctdbd_latency:");
225 printf("max_reclock_ctdbd_latency:");
227 printf("num_reclock_recd_latency:");
228 printf("min_reclock_recd_latency:");
229 printf("avg_reclock_recd_latency:");
230 printf("max_reclock_recd_latency:");
232 printf("num_call_latency:");
233 printf("min_call_latency:");
234 printf("avg_call_latency:");
235 printf("max_call_latency:");
237 printf("num_lockwait_latency:");
238 printf("min_lockwait_latency:");
239 printf("avg_lockwait_latency:");
240 printf("max_lockwait_latency:");
242 printf("num_childwrite_latency:");
243 printf("min_childwrite_latency:");
244 printf("avg_childwrite_latency:");
245 printf("max_childwrite_latency:");
248 printf("%d:", CTDB_VERSION);
249 printf("%d:", (int)s->statistics_current_time.tv_sec);
250 printf("%d:", (int)s->statistics_start_time.tv_sec);
251 for (i=0;i<ARRAY_SIZE(fields);i++) {
252 printf("%d:", *(uint32_t *)(fields[i].offset+(uint8_t *)s));
254 printf("%d:", s->reclock.ctdbd.num);
255 printf("%.6f:", s->reclock.ctdbd.min);
256 printf("%.6f:", s->reclock.ctdbd.num?s->reclock.ctdbd.total/s->reclock.ctdbd.num:0.0);
257 printf("%.6f:", s->reclock.ctdbd.max);
259 printf("%d:", s->reclock.recd.num);
260 printf("%.6f:", s->reclock.recd.min);
261 printf("%.6f:", s->reclock.recd.num?s->reclock.recd.total/s->reclock.recd.num:0.0);
262 printf("%.6f:", s->reclock.recd.max);
264 printf("%d:", s->call_latency.num);
265 printf("%.6f:", s->call_latency.min);
266 printf("%.6f:", s->call_latency.num?s->call_latency.total/s->call_latency.num:0.0);
267 printf("%.6f:", s->call_latency.max);
269 printf("%d:", s->lockwait_latency.num);
270 printf("%.6f:", s->lockwait_latency.min);
271 printf("%.6f:", s->lockwait_latency.num?s->lockwait_latency.total/s->lockwait_latency.num:0.0);
272 printf("%.6f:", s->lockwait_latency.max);
274 printf("%d:", s->childwrite_latency.num);
275 printf("%.6f:", s->childwrite_latency.min);
276 printf("%.6f:", s->childwrite_latency.num?s->childwrite_latency.total/s->childwrite_latency.num:0.0);
277 printf("%.6f:", s->childwrite_latency.max);
280 printf("CTDB version %u\n", CTDB_VERSION);
281 printf("Current time of statistics : %s", ctime(&s->statistics_current_time.tv_sec));
282 printf("Statistics collected since : (%03d %02d:%02d:%02d) %s", days, hours, minutes, seconds, ctime(&s->statistics_start_time.tv_sec));
284 for (i=0;i<ARRAY_SIZE(fields);i++) {
285 if (strchr(fields[i].name, '.')) {
286 preflen = strcspn(fields[i].name, ".")+1;
287 if (!prefix || strncmp(prefix, fields[i].name, preflen) != 0) {
288 prefix = fields[i].name;
289 printf(" %*.*s\n", preflen-1, preflen-1, fields[i].name);
294 printf(" %*s%-22s%*s%10u\n",
296 fields[i].name+preflen,
298 *(uint32_t *)(fields[i].offset+(uint8_t *)s));
300 printf(" %-30s %.6f/%.6f/%.6f sec out of %d\n", "reclock_ctdbd MIN/AVG/MAX", s->reclock.ctdbd.min, s->reclock.ctdbd.num?s->reclock.ctdbd.total/s->reclock.ctdbd.num:0.0, s->reclock.ctdbd.max, s->reclock.ctdbd.num);
302 printf(" %-30s %.6f/%.6f/%.6f sec out of %d\n", "reclock_recd MIN/AVG/MAX", s->reclock.recd.min, s->reclock.recd.num?s->reclock.recd.total/s->reclock.recd.num:0.0, s->reclock.recd.max, s->reclock.recd.num);
304 printf(" %-30s %.6f/%.6f/%.6f sec out of %d\n", "call_latency MIN/AVG/MAX", s->call_latency.min, s->call_latency.num?s->call_latency.total/s->call_latency.num:0.0, s->call_latency.max, s->call_latency.num);
305 printf(" %-30s %.6f/%.6f/%.6f sec out of %d\n", "lockwait_latency MIN/AVG/MAX", s->lockwait_latency.min, s->lockwait_latency.num?s->lockwait_latency.total/s->lockwait_latency.num:0.0, s->lockwait_latency.max, s->lockwait_latency.num);
306 printf(" %-30s %.6f/%.6f/%.6f sec out of %d\n", "childwrite_latency MIN/AVG/MAX", s->childwrite_latency.min, s->childwrite_latency.num?s->childwrite_latency.total/s->childwrite_latency.num:0.0, s->childwrite_latency.max, s->childwrite_latency.num);
309 talloc_free(tmp_ctx);
313 display remote ctdb statistics combined from all nodes
315 static int control_statistics_all(struct ctdb_context *ctdb)
318 struct ctdb_statistics statistics;
322 nodes = ctdb_get_connected_nodes(ctdb, TIMELIMIT(), ctdb, &num_nodes);
323 CTDB_NO_MEMORY(ctdb, nodes);
325 ZERO_STRUCT(statistics);
327 for (i=0;i<num_nodes;i++) {
328 struct ctdb_statistics s1;
330 uint32_t *v1 = (uint32_t *)&s1;
331 uint32_t *v2 = (uint32_t *)&statistics;
333 offsetof(struct ctdb_statistics, __last_counter) / sizeof(uint32_t);
334 ret = ctdb_ctrl_statistics(ctdb, nodes[i], &s1);
336 DEBUG(DEBUG_ERR, ("Unable to get statistics from node %u\n", nodes[i]));
339 for (j=0;j<num_ints;j++) {
342 statistics.max_hop_count =
343 MAX(statistics.max_hop_count, s1.max_hop_count);
344 statistics.call_latency.max =
345 MAX(statistics.call_latency.max, s1.call_latency.max);
346 statistics.lockwait_latency.max =
347 MAX(statistics.lockwait_latency.max, s1.lockwait_latency.max);
350 printf("Gathered statistics for %u nodes\n", num_nodes);
351 show_statistics(&statistics, 1);
356 display remote ctdb statistics
358 static int control_statistics(struct ctdb_context *ctdb, int argc, const char **argv)
361 struct ctdb_statistics statistics;
363 if (options.pnn == CTDB_BROADCAST_ALL) {
364 return control_statistics_all(ctdb);
367 ret = ctdb_ctrl_statistics(ctdb, options.pnn, &statistics);
369 DEBUG(DEBUG_ERR, ("Unable to get statistics from node %u\n", options.pnn));
372 show_statistics(&statistics, 1);
378 reset remote ctdb statistics
380 static int control_statistics_reset(struct ctdb_context *ctdb, int argc, const char **argv)
384 ret = ctdb_statistics_reset(ctdb, options.pnn);
386 DEBUG(DEBUG_ERR, ("Unable to reset statistics on node %u\n", options.pnn));
394 display remote ctdb rolling statistics
396 static int control_stats(struct ctdb_context *ctdb, int argc, const char **argv)
399 struct ctdb_statistics_wire *stats;
400 int i, num_records = -1;
403 num_records = atoi(argv[0]) - 1;
406 ret = ctdb_ctrl_getstathistory(ctdb, TIMELIMIT(), options.pnn, ctdb, &stats);
408 DEBUG(DEBUG_ERR, ("Unable to get rolling statistics from node %u\n", options.pnn));
411 for (i=0;i<stats->num;i++) {
412 if (stats->stats[i].statistics_start_time.tv_sec == 0) {
415 show_statistics(&stats->stats[i], i==0);
416 if (i == num_records) {
425 display uptime of remote node
427 static int control_uptime(struct ctdb_context *ctdb, int argc, const char **argv)
430 struct ctdb_uptime *uptime = NULL;
431 int tmp, days, hours, minutes, seconds;
433 ret = ctdb_ctrl_uptime(ctdb, ctdb, TIMELIMIT(), options.pnn, &uptime);
435 DEBUG(DEBUG_ERR, ("Unable to get uptime from node %u\n", options.pnn));
439 if (options.machinereadable){
440 printf(":Current Node Time:Ctdb Start Time:Last Recovery/Failover Time:Last Recovery/IPFailover Duration:\n");
441 printf(":%u:%u:%u:%lf\n",
442 (unsigned int)uptime->current_time.tv_sec,
443 (unsigned int)uptime->ctdbd_start_time.tv_sec,
444 (unsigned int)uptime->last_recovery_finished.tv_sec,
445 timeval_delta(&uptime->last_recovery_finished,
446 &uptime->last_recovery_started)
451 printf("Current time of node : %s", ctime(&uptime->current_time.tv_sec));
453 tmp = uptime->current_time.tv_sec - uptime->ctdbd_start_time.tv_sec;
461 printf("Ctdbd start time : (%03d %02d:%02d:%02d) %s", days, hours, minutes, seconds, ctime(&uptime->ctdbd_start_time.tv_sec));
463 tmp = uptime->current_time.tv_sec - uptime->last_recovery_finished.tv_sec;
471 printf("Time of last recovery/failover: (%03d %02d:%02d:%02d) %s", days, hours, minutes, seconds, ctime(&uptime->last_recovery_finished.tv_sec));
473 printf("Duration of last recovery/failover: %lf seconds\n",
474 timeval_delta(&uptime->last_recovery_finished,
475 &uptime->last_recovery_started));
481 show the PNN of the current node
483 static int control_pnn(struct ctdb_context *ctdb, int argc, const char **argv)
488 ret = ctdb_getpnn(ctdb_connection, options.pnn, &mypnn);
490 DEBUG(DEBUG_ERR, ("Unable to get pnn from node."));
494 printf("PNN:%d\n", mypnn);
500 struct pnn_node *next;
505 static struct pnn_node *read_nodes_file(TALLOC_CTX *mem_ctx)
507 const char *nodes_list;
511 struct pnn_node *pnn_nodes = NULL;
512 struct pnn_node *pnn_node;
513 struct pnn_node *tmp_node;
515 /* read the nodes file */
516 nodes_list = getenv("CTDB_NODES");
517 if (nodes_list == NULL) {
518 nodes_list = "/etc/ctdb/nodes";
520 lines = file_lines_load(nodes_list, &nlines, mem_ctx);
524 while (nlines > 0 && strcmp(lines[nlines-1], "") == 0) {
527 for (i=0, pnn=0; i<nlines; i++) {
531 /* strip leading spaces */
532 while((*node == ' ') || (*node == '\t')) {
539 if (strcmp(node, "") == 0) {
542 pnn_node = talloc(mem_ctx, struct pnn_node);
543 pnn_node->pnn = pnn++;
544 pnn_node->addr = talloc_strdup(pnn_node, node);
545 pnn_node->next = pnn_nodes;
546 pnn_nodes = pnn_node;
549 /* swap them around so we return them in incrementing order */
550 pnn_node = pnn_nodes;
554 pnn_node = pnn_node->next;
556 tmp_node->next = pnn_nodes;
557 pnn_nodes = tmp_node;
564 show the PNN of the current node
565 discover the pnn by loading the nodes file and try to bind to all
566 addresses one at a time until the ip address is found.
568 static int control_xpnn(struct ctdb_context *ctdb, int argc, const char **argv)
570 TALLOC_CTX *mem_ctx = talloc_new(NULL);
571 struct pnn_node *pnn_nodes;
572 struct pnn_node *pnn_node;
574 pnn_nodes = read_nodes_file(mem_ctx);
575 if (pnn_nodes == NULL) {
576 DEBUG(DEBUG_ERR,("Failed to read nodes file\n"));
577 talloc_free(mem_ctx);
581 for(pnn_node=pnn_nodes;pnn_node;pnn_node=pnn_node->next) {
584 if (parse_ip(pnn_node->addr, NULL, 63999, &addr) == 0) {
585 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s' in nodes file\n", pnn_node->addr));
586 talloc_free(mem_ctx);
590 if (ctdb_sys_have_ip(&addr)) {
591 printf("PNN:%d\n", pnn_node->pnn);
592 talloc_free(mem_ctx);
597 printf("Failed to detect which PNN this node is\n");
598 talloc_free(mem_ctx);
603 display remote ctdb status
605 static int control_status(struct ctdb_context *ctdb, int argc, const char **argv)
608 struct ctdb_vnn_map *vnnmap=NULL;
609 struct ctdb_node_map *nodemap=NULL;
610 uint32_t recmode, recmaster;
613 mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
618 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb, &nodemap);
620 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
624 if(options.machinereadable){
625 printf(":Node:IP:Disconnected:Banned:Disabled:Unhealthy:Stopped:Inactive:PartiallyOnline:\n");
626 for(i=0;i<nodemap->num;i++){
627 int partially_online = 0;
630 if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) {
633 if (nodemap->nodes[i].flags == 0) {
634 struct ctdb_control_get_ifaces *ifaces;
636 ret = ctdb_ctrl_get_ifaces(ctdb, TIMELIMIT(),
637 nodemap->nodes[i].pnn,
640 for (j=0; j < ifaces->num; j++) {
641 if (ifaces->ifaces[j].link_state != 0) {
644 partially_online = 1;
650 printf(":%d:%s:%d:%d:%d:%d:%d:%d:%d:\n", nodemap->nodes[i].pnn,
651 ctdb_addr_to_str(&nodemap->nodes[i].addr),
652 !!(nodemap->nodes[i].flags&NODE_FLAGS_DISCONNECTED),
653 !!(nodemap->nodes[i].flags&NODE_FLAGS_BANNED),
654 !!(nodemap->nodes[i].flags&NODE_FLAGS_PERMANENTLY_DISABLED),
655 !!(nodemap->nodes[i].flags&NODE_FLAGS_UNHEALTHY),
656 !!(nodemap->nodes[i].flags&NODE_FLAGS_STOPPED),
657 !!(nodemap->nodes[i].flags&NODE_FLAGS_INACTIVE),
663 printf("Number of nodes:%d\n", nodemap->num);
664 for(i=0;i<nodemap->num;i++){
665 static const struct {
669 { NODE_FLAGS_DISCONNECTED, "DISCONNECTED" },
670 { NODE_FLAGS_PERMANENTLY_DISABLED, "DISABLED" },
671 { NODE_FLAGS_BANNED, "BANNED" },
672 { NODE_FLAGS_UNHEALTHY, "UNHEALTHY" },
673 { NODE_FLAGS_DELETED, "DELETED" },
674 { NODE_FLAGS_STOPPED, "STOPPED" },
675 { NODE_FLAGS_INACTIVE, "INACTIVE" },
677 char *flags_str = NULL;
680 if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) {
683 if (nodemap->nodes[i].flags == 0) {
684 struct ctdb_control_get_ifaces *ifaces;
686 ret = ctdb_ctrl_get_ifaces(ctdb, TIMELIMIT(),
687 nodemap->nodes[i].pnn,
690 for (j=0; j < ifaces->num; j++) {
691 if (ifaces->ifaces[j].link_state != 0) {
694 flags_str = talloc_strdup(ctdb, "PARTIALLYONLINE");
700 for (j=0;j<ARRAY_SIZE(flag_names);j++) {
701 if (nodemap->nodes[i].flags & flag_names[j].flag) {
702 if (flags_str == NULL) {
703 flags_str = talloc_strdup(ctdb, flag_names[j].name);
705 flags_str = talloc_asprintf_append(flags_str, "|%s",
708 CTDB_NO_MEMORY_FATAL(ctdb, flags_str);
711 if (flags_str == NULL) {
712 flags_str = talloc_strdup(ctdb, "OK");
713 CTDB_NO_MEMORY_FATAL(ctdb, flags_str);
715 printf("pnn:%d %-16s %s%s\n", nodemap->nodes[i].pnn,
716 ctdb_addr_to_str(&nodemap->nodes[i].addr),
718 nodemap->nodes[i].pnn == mypnn?" (THIS NODE)":"");
719 talloc_free(flags_str);
722 ret = ctdb_ctrl_getvnnmap(ctdb, TIMELIMIT(), options.pnn, ctdb, &vnnmap);
724 DEBUG(DEBUG_ERR, ("Unable to get vnnmap from node %u\n", options.pnn));
727 if (vnnmap->generation == INVALID_GENERATION) {
728 printf("Generation:INVALID\n");
730 printf("Generation:%d\n",vnnmap->generation);
732 printf("Size:%d\n",vnnmap->size);
733 for(i=0;i<vnnmap->size;i++){
734 printf("hash:%d lmaster:%d\n", i, vnnmap->map[i]);
737 ret = ctdb_ctrl_getrecmode(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmode);
739 DEBUG(DEBUG_ERR, ("Unable to get recmode from node %u\n", options.pnn));
742 printf("Recovery mode:%s (%d)\n",recmode==CTDB_RECOVERY_NORMAL?"NORMAL":"RECOVERY",recmode);
744 ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
746 DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
749 printf("Recovery master:%d\n",recmaster);
756 struct natgw_node *next;
761 display the list of nodes belonging to this natgw configuration
763 static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **argv)
766 uint32_t capabilities;
767 const char *natgw_list;
770 struct natgw_node *natgw_nodes = NULL;
771 struct natgw_node *natgw_node;
772 struct ctdb_node_map *nodemap=NULL;
775 /* read the natgw nodes file into a linked list */
776 natgw_list = getenv("NATGW_NODES");
777 if (natgw_list == NULL) {
778 natgw_list = "/etc/ctdb/natgw_nodes";
780 lines = file_lines_load(natgw_list, &nlines, ctdb);
782 ctdb_set_error(ctdb, "Failed to load natgw node list '%s'\n", natgw_list);
785 while (nlines > 0 && strcmp(lines[nlines-1], "") == 0) {
788 for (i=0;i<nlines;i++) {
792 /* strip leading spaces */
793 while((*node == ' ') || (*node == '\t')) {
799 if (strcmp(node, "") == 0) {
802 natgw_node = talloc(ctdb, struct natgw_node);
803 natgw_node->addr = talloc_strdup(natgw_node, node);
804 CTDB_NO_MEMORY(ctdb, natgw_node->addr);
805 natgw_node->next = natgw_nodes;
806 natgw_nodes = natgw_node;
809 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap);
811 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node.\n"));
816 while(i<nodemap->num) {
817 for(natgw_node=natgw_nodes;natgw_node;natgw_node=natgw_node->next) {
818 if (!strcmp(natgw_node->addr, ctdb_addr_to_str(&nodemap->nodes[i].addr))) {
823 /* this node was not in the natgw so we just remove it from
826 if ((natgw_node == NULL)
827 || (nodemap->nodes[i].flags & NODE_FLAGS_DISCONNECTED) ) {
830 for (j=i+1; j<nodemap->num; j++) {
831 nodemap->nodes[j-1] = nodemap->nodes[j];
840 /* pick a node to be natgwmaster
841 * we dont allow STOPPED, DELETED, BANNED or UNHEALTHY nodes to become the natgwmaster
843 for(i=0;i<nodemap->num;i++){
844 if (!(nodemap->nodes[i].flags & (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_STOPPED|NODE_FLAGS_DELETED|NODE_FLAGS_BANNED|NODE_FLAGS_UNHEALTHY))) {
845 ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), nodemap->nodes[i].pnn, &capabilities);
847 DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", nodemap->nodes[i].pnn));
850 if (!(capabilities&CTDB_CAP_NATGW)) {
853 printf("%d %s\n", nodemap->nodes[i].pnn,ctdb_addr_to_str(&nodemap->nodes[i].addr));
857 /* we couldnt find any healthy node, try unhealthy ones */
858 if (i == nodemap->num) {
859 for(i=0;i<nodemap->num;i++){
860 if (!(nodemap->nodes[i].flags & (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_STOPPED|NODE_FLAGS_DELETED))) {
861 ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), nodemap->nodes[i].pnn, &capabilities);
863 DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", nodemap->nodes[i].pnn));
866 if (!(capabilities&CTDB_CAP_NATGW)) {
869 printf("%d %s\n", nodemap->nodes[i].pnn,ctdb_addr_to_str(&nodemap->nodes[i].addr));
874 /* unless all nodes are STOPPED, when we pick one anyway */
875 if (i == nodemap->num) {
876 for(i=0;i<nodemap->num;i++){
877 if (!(nodemap->nodes[i].flags & (NODE_FLAGS_DISCONNECTED|NODE_FLAGS_DELETED))) {
878 ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), nodemap->nodes[i].pnn, &capabilities);
880 DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", nodemap->nodes[i].pnn));
883 if (!(capabilities&CTDB_CAP_NATGW)) {
886 printf("%d %s\n", nodemap->nodes[i].pnn, ctdb_addr_to_str(&nodemap->nodes[i].addr));
890 /* or if we still can not find any */
891 if (i == nodemap->num) {
892 printf("-1 0.0.0.0\n");
896 /* print the pruned list of nodes belonging to this natgw list */
897 for(i=0;i<nodemap->num;i++){
898 if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) {
901 printf(":%d:%s:%d:%d:%d:%d:%d\n", nodemap->nodes[i].pnn,
902 ctdb_addr_to_str(&nodemap->nodes[i].addr),
903 !!(nodemap->nodes[i].flags&NODE_FLAGS_DISCONNECTED),
904 !!(nodemap->nodes[i].flags&NODE_FLAGS_BANNED),
905 !!(nodemap->nodes[i].flags&NODE_FLAGS_PERMANENTLY_DISABLED),
906 !!(nodemap->nodes[i].flags&NODE_FLAGS_UNHEALTHY),
907 !!(nodemap->nodes[i].flags&NODE_FLAGS_STOPPED));
914 display the status of the scripts for monitoring (or other events)
916 static int control_one_scriptstatus(struct ctdb_context *ctdb,
917 enum ctdb_eventscript_call type)
919 struct ctdb_scripts_wire *script_status;
922 ret = ctdb_ctrl_getscriptstatus(ctdb, TIMELIMIT(), options.pnn, ctdb, type, &script_status);
924 DEBUG(DEBUG_ERR, ("Unable to get script status from node %u\n", options.pnn));
928 if (script_status == NULL) {
929 if (!options.machinereadable) {
930 printf("%s cycle never run\n",
931 ctdb_eventscript_call_names[type]);
936 if (!options.machinereadable) {
937 printf("%d scripts were executed last %s cycle\n",
938 script_status->num_scripts,
939 ctdb_eventscript_call_names[type]);
941 for (i=0; i<script_status->num_scripts; i++) {
942 const char *status = NULL;
944 switch (script_status->scripts[i].status) {
955 if (script_status->scripts[i].status > 0)
959 if (options.machinereadable) {
960 printf("%s:%s:%i:%s:%lu.%06lu:%lu.%06lu:%s:\n",
961 ctdb_eventscript_call_names[type],
962 script_status->scripts[i].name,
963 script_status->scripts[i].status,
965 (long)script_status->scripts[i].start.tv_sec,
966 (long)script_status->scripts[i].start.tv_usec,
967 (long)script_status->scripts[i].finished.tv_sec,
968 (long)script_status->scripts[i].finished.tv_usec,
969 script_status->scripts[i].output);
973 printf("%-20s Status:%s ",
974 script_status->scripts[i].name, status);
976 /* Some other error, eg from stat. */
977 printf("%-20s Status:CANNOT RUN (%s)",
978 script_status->scripts[i].name,
979 strerror(-script_status->scripts[i].status));
981 if (script_status->scripts[i].status >= 0) {
982 printf("Duration:%.3lf ",
983 timeval_delta(&script_status->scripts[i].finished,
984 &script_status->scripts[i].start));
986 if (script_status->scripts[i].status != -ENOEXEC) {
988 ctime(&script_status->scripts[i].start.tv_sec));
989 if (script_status->scripts[i].status != 0) {
990 printf(" OUTPUT:%s\n",
991 script_status->scripts[i].output);
1001 static int control_scriptstatus(struct ctdb_context *ctdb,
1002 int argc, const char **argv)
1005 enum ctdb_eventscript_call type, min, max;
1009 DEBUG(DEBUG_ERR, ("Unknown arguments to scriptstatus\n"));
1014 arg = ctdb_eventscript_call_names[CTDB_EVENT_MONITOR];
1018 for (type = 0; type < CTDB_EVENT_MAX; type++) {
1019 if (strcmp(arg, ctdb_eventscript_call_names[type]) == 0) {
1025 if (type == CTDB_EVENT_MAX) {
1026 if (strcmp(arg, "all") == 0) {
1028 max = CTDB_EVENT_MAX;
1030 DEBUG(DEBUG_ERR, ("Unknown event type %s\n", argv[0]));
1035 if (options.machinereadable) {
1036 printf(":Type:Name:Code:Status:Start:End:Error Output...:\n");
1039 for (type = min; type < max; type++) {
1040 ret = control_one_scriptstatus(ctdb, type);
1050 enable an eventscript
1052 static int control_enablescript(struct ctdb_context *ctdb, int argc, const char **argv)
1060 ret = ctdb_ctrl_enablescript(ctdb, TIMELIMIT(), options.pnn, argv[0]);
1062 DEBUG(DEBUG_ERR, ("Unable to enable script %s on node %u\n", argv[0], options.pnn));
1070 disable an eventscript
1072 static int control_disablescript(struct ctdb_context *ctdb, int argc, const char **argv)
1080 ret = ctdb_ctrl_disablescript(ctdb, TIMELIMIT(), options.pnn, argv[0]);
1082 DEBUG(DEBUG_ERR, ("Unable to disable script %s on node %u\n", argv[0], options.pnn));
1090 display the pnn of the recovery master
1092 static int control_recmaster(struct ctdb_context *ctdb, int argc, const char **argv)
1097 ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
1099 DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
1102 printf("%d\n",recmaster);
1108 add a tickle to a public address
1110 static int control_add_tickle(struct ctdb_context *ctdb, int argc, const char **argv)
1112 struct ctdb_tcp_connection t;
1120 if (parse_ip_port(argv[0], &t.src_addr) == 0) {
1121 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
1124 if (parse_ip_port(argv[1], &t.dst_addr) == 0) {
1125 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[1]));
1129 data.dptr = (uint8_t *)&t;
1130 data.dsize = sizeof(t);
1132 /* tell all nodes about this tcp connection */
1133 ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE,
1134 0, data, ctdb, NULL, NULL, NULL, NULL);
1136 DEBUG(DEBUG_ERR,("Failed to add tickle\n"));
1145 delete a tickle from a node
1147 static int control_del_tickle(struct ctdb_context *ctdb, int argc, const char **argv)
1149 struct ctdb_tcp_connection t;
1157 if (parse_ip_port(argv[0], &t.src_addr) == 0) {
1158 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
1161 if (parse_ip_port(argv[1], &t.dst_addr) == 0) {
1162 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[1]));
1166 data.dptr = (uint8_t *)&t;
1167 data.dsize = sizeof(t);
1169 /* tell all nodes about this tcp connection */
1170 ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_TCP_REMOVE,
1171 0, data, ctdb, NULL, NULL, NULL, NULL);
1173 DEBUG(DEBUG_ERR,("Failed to remove tickle\n"));
1182 get a list of all tickles for this pnn
1184 static int control_get_tickles(struct ctdb_context *ctdb, int argc, const char **argv)
1186 struct ctdb_control_tcp_tickle_list *list;
1187 ctdb_sock_addr addr;
1196 port = atoi(argv[1]);
1199 if (parse_ip(argv[0], NULL, 0, &addr) == 0) {
1200 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
1204 ret = ctdb_ctrl_get_tcp_tickles(ctdb, TIMELIMIT(), options.pnn, ctdb, &addr, &list);
1206 DEBUG(DEBUG_ERR, ("Unable to list tickles\n"));
1210 if (options.machinereadable){
1211 printf(":source ip:port:destination ip:port:\n");
1212 for (i=0;i<list->tickles.num;i++) {
1213 if (port && port != ntohs(list->tickles.connections[i].dst_addr.ip.sin_port)) {
1216 printf(":%s:%u", ctdb_addr_to_str(&list->tickles.connections[i].src_addr), ntohs(list->tickles.connections[i].src_addr.ip.sin_port));
1217 printf(":%s:%u:\n", ctdb_addr_to_str(&list->tickles.connections[i].dst_addr), ntohs(list->tickles.connections[i].dst_addr.ip.sin_port));
1220 printf("Tickles for ip:%s\n", ctdb_addr_to_str(&list->addr));
1221 printf("Num tickles:%u\n", list->tickles.num);
1222 for (i=0;i<list->tickles.num;i++) {
1223 if (port && port != ntohs(list->tickles.connections[i].dst_addr.ip.sin_port)) {
1226 printf("SRC: %s:%u ", ctdb_addr_to_str(&list->tickles.connections[i].src_addr), ntohs(list->tickles.connections[i].src_addr.ip.sin_port));
1227 printf("DST: %s:%u\n", ctdb_addr_to_str(&list->tickles.connections[i].dst_addr), ntohs(list->tickles.connections[i].dst_addr.ip.sin_port));
1237 static int move_ip(struct ctdb_context *ctdb, ctdb_sock_addr *addr, uint32_t pnn)
1239 struct ctdb_all_public_ips *ips;
1240 struct ctdb_public_ip ip;
1243 uint32_t disable_time;
1245 struct ctdb_node_map *nodemap=NULL;
1246 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
1249 data.dptr = (uint8_t*)&disable_time;
1250 data.dsize = sizeof(disable_time);
1251 ret = ctdb_client_send_message(ctdb, CTDB_BROADCAST_CONNECTED, CTDB_SRVID_DISABLE_IP_CHECK, data);
1253 DEBUG(DEBUG_ERR,("Failed to send message to disable ipcheck\n"));
1259 /* read the public ip list from the node */
1260 ret = ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), pnn, ctdb, &ips);
1262 DEBUG(DEBUG_ERR, ("Unable to get public ip list from node %u\n", pnn));
1263 talloc_free(tmp_ctx);
1267 for (i=0;i<ips->num;i++) {
1268 if (ctdb_same_ip(addr, &ips->ips[i].addr)) {
1273 DEBUG(DEBUG_ERR, ("Node %u can not host ip address '%s'\n",
1274 pnn, ctdb_addr_to_str(addr)));
1275 talloc_free(tmp_ctx);
1282 data.dptr = (uint8_t *)&ip;
1283 data.dsize = sizeof(ip);
1285 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, tmp_ctx, &nodemap);
1287 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
1288 talloc_free(tmp_ctx);
1292 nodes = list_of_active_nodes_except_pnn(ctdb, nodemap, tmp_ctx, pnn);
1293 ret = ctdb_client_async_control(ctdb, CTDB_CONTROL_RELEASE_IP,
1300 DEBUG(DEBUG_ERR,("Failed to release IP on nodes\n"));
1301 talloc_free(tmp_ctx);
1305 ret = ctdb_ctrl_takeover_ip(ctdb, LONGTIMELIMIT(), pnn, &ip);
1307 DEBUG(DEBUG_ERR,("Failed to take over IP on node %d\n", pnn));
1308 talloc_free(tmp_ctx);
1312 /* update the recovery daemon so it now knows to expect the new
1313 node assignment for this ip.
1315 ret = ctdb_client_send_message(ctdb, CTDB_BROADCAST_CONNECTED, CTDB_SRVID_RECD_UPDATE_IP, data);
1317 DEBUG(DEBUG_ERR,("Failed to send message to update the ip on the recovery master.\n"));
1321 talloc_free(tmp_ctx);
1326 move/failover an ip address to a specific node
1328 static int control_moveip(struct ctdb_context *ctdb, int argc, const char **argv)
1331 ctdb_sock_addr addr;
1338 if (parse_ip(argv[0], NULL, 0, &addr) == 0) {
1339 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
1344 if (sscanf(argv[1], "%u", &pnn) != 1) {
1345 DEBUG(DEBUG_ERR, ("Badly formed pnn\n"));
1349 if (move_ip(ctdb, &addr, pnn) != 0) {
1350 DEBUG(DEBUG_ERR,("Failed to move ip to node %d\n", pnn));
1357 void getips_store_callback(void *param, void *data)
1359 struct ctdb_public_ip *node_ip = (struct ctdb_public_ip *)data;
1360 struct ctdb_all_public_ips *ips = param;
1364 ips->ips[i].pnn = node_ip->pnn;
1365 ips->ips[i].addr = node_ip->addr;
1368 void getips_count_callback(void *param, void *data)
1370 uint32_t *count = param;
1376 static uint32_t *ip_key(ctdb_sock_addr *ip)
1378 static uint32_t key[IP_KEYLEN];
1380 bzero(key, sizeof(key));
1382 switch (ip->sa.sa_family) {
1384 key[0] = ip->ip.sin_addr.s_addr;
1387 key[0] = ip->ip6.sin6_addr.s6_addr32[3];
1388 key[1] = ip->ip6.sin6_addr.s6_addr32[2];
1389 key[2] = ip->ip6.sin6_addr.s6_addr32[1];
1390 key[3] = ip->ip6.sin6_addr.s6_addr32[0];
1393 DEBUG(DEBUG_ERR, (__location__ " ERROR, unknown family passed :%u\n", ip->sa.sa_family));
1400 static void *add_ip_callback(void *parm, void *data)
1406 control_get_all_public_ips(struct ctdb_context *ctdb, TALLOC_CTX *tmp_ctx, struct ctdb_all_public_ips **ips)
1408 struct ctdb_all_public_ips *tmp_ips;
1409 struct ctdb_node_map *nodemap=NULL;
1410 trbt_tree_t *ip_tree;
1414 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, tmp_ctx, &nodemap);
1416 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
1420 ip_tree = trbt_create(tmp_ctx, 0);
1422 for(i=0;i<nodemap->num;i++){
1423 if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) {
1426 if (nodemap->nodes[i].flags & NODE_FLAGS_DISCONNECTED) {
1430 /* read the public ip list from this node */
1431 ret = ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), nodemap->nodes[i].pnn, tmp_ctx, &tmp_ips);
1433 DEBUG(DEBUG_ERR, ("Unable to get public ip list from node %u\n", nodemap->nodes[i].pnn));
1437 for (j=0; j<tmp_ips->num;j++) {
1438 struct ctdb_public_ip *node_ip;
1440 node_ip = talloc(tmp_ctx, struct ctdb_public_ip);
1441 node_ip->pnn = tmp_ips->ips[j].pnn;
1442 node_ip->addr = tmp_ips->ips[j].addr;
1444 trbt_insertarray32_callback(ip_tree,
1445 IP_KEYLEN, ip_key(&tmp_ips->ips[j].addr),
1449 talloc_free(tmp_ips);
1454 trbt_traversearray32(ip_tree, IP_KEYLEN, getips_count_callback, &count);
1456 len = offsetof(struct ctdb_all_public_ips, ips) +
1457 count*sizeof(struct ctdb_public_ip);
1458 tmp_ips = talloc_zero_size(tmp_ctx, len);
1459 trbt_traversearray32(ip_tree, IP_KEYLEN, getips_store_callback, tmp_ips);
1468 * scans all other nodes and returns a pnn for another node that can host this
1472 find_other_host_for_public_ip(struct ctdb_context *ctdb, ctdb_sock_addr *addr)
1474 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
1475 struct ctdb_all_public_ips *ips;
1476 struct ctdb_node_map *nodemap=NULL;
1479 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, tmp_ctx, &nodemap);
1481 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
1482 talloc_free(tmp_ctx);
1486 for(i=0;i<nodemap->num;i++){
1487 if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
1490 if (nodemap->nodes[i].pnn == options.pnn) {
1494 /* read the public ip list from this node */
1495 ret = ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), nodemap->nodes[i].pnn, tmp_ctx, &ips);
1497 DEBUG(DEBUG_ERR, ("Unable to get public ip list from node %u\n", nodemap->nodes[i].pnn));
1501 for (j=0;j<ips->num;j++) {
1502 if (ctdb_same_ip(addr, &ips->ips[j].addr)) {
1503 talloc_free(tmp_ctx);
1504 return nodemap->nodes[i].pnn;
1510 talloc_free(tmp_ctx);
1515 add a public ip address to a node
1517 static int control_addip(struct ctdb_context *ctdb, int argc, const char **argv)
1523 ctdb_sock_addr addr;
1524 struct ctdb_control_ip_iface *pub;
1525 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
1526 struct ctdb_all_public_ips *ips;
1530 talloc_free(tmp_ctx);
1534 if (!parse_ip_mask(argv[0], argv[1], &addr, &mask)) {
1535 DEBUG(DEBUG_ERR, ("Badly formed ip/mask : %s\n", argv[0]));
1536 talloc_free(tmp_ctx);
1540 ret = control_get_all_public_ips(ctdb, tmp_ctx, &ips);
1542 DEBUG(DEBUG_ERR, ("Unable to get public ip list from cluster\n"));
1543 talloc_free(tmp_ctx);
1548 /* check if some other node is already serving this ip, if not,
1551 for (i=0;i<ips->num;i++) {
1552 if (ctdb_same_ip(&addr, &ips->ips[i].addr)) {
1557 len = offsetof(struct ctdb_control_ip_iface, iface) + strlen(argv[1]) + 1;
1558 pub = talloc_size(tmp_ctx, len);
1559 CTDB_NO_MEMORY(ctdb, pub);
1563 pub->len = strlen(argv[1])+1;
1564 memcpy(&pub->iface[0], argv[1], strlen(argv[1])+1);
1566 ret = ctdb_ctrl_add_public_ip(ctdb, TIMELIMIT(), options.pnn, pub);
1568 DEBUG(DEBUG_ERR, ("Unable to add public ip to node %u\n", options.pnn));
1569 talloc_free(tmp_ctx);
1573 if (i == ips->num) {
1574 /* no one has this ip so we claim it */
1577 pnn = ips->ips[i].pnn;
1580 if (move_ip(ctdb, &addr, pnn) != 0) {
1581 DEBUG(DEBUG_ERR,("Failed to move ip to node %d\n", pnn));
1585 talloc_free(tmp_ctx);
1589 static int control_delip(struct ctdb_context *ctdb, int argc, const char **argv);
1591 static int control_delip_all(struct ctdb_context *ctdb, int argc, const char **argv, ctdb_sock_addr *addr)
1593 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
1594 struct ctdb_node_map *nodemap=NULL;
1595 struct ctdb_all_public_ips *ips;
1598 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, tmp_ctx, &nodemap);
1600 DEBUG(DEBUG_ERR, ("Unable to get nodemap from current node\n"));
1604 /* remove it from the nodes that are not hosting the ip currently */
1605 for(i=0;i<nodemap->num;i++){
1606 if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
1609 if (ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), nodemap->nodes[i].pnn, tmp_ctx, &ips) != 0) {
1610 DEBUG(DEBUG_ERR, ("Unable to get public ip list from node %d\n", nodemap->nodes[i].pnn));
1614 for (j=0;j<ips->num;j++) {
1615 if (ctdb_same_ip(addr, &ips->ips[j].addr)) {
1623 if (ips->ips[j].pnn == nodemap->nodes[i].pnn) {
1627 options.pnn = nodemap->nodes[i].pnn;
1628 control_delip(ctdb, argc, argv);
1632 /* remove it from every node (also the one hosting it) */
1633 for(i=0;i<nodemap->num;i++){
1634 if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
1637 if (ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), nodemap->nodes[i].pnn, tmp_ctx, &ips) != 0) {
1638 DEBUG(DEBUG_ERR, ("Unable to get public ip list from node %d\n", nodemap->nodes[i].pnn));
1642 for (j=0;j<ips->num;j++) {
1643 if (ctdb_same_ip(addr, &ips->ips[j].addr)) {
1651 options.pnn = nodemap->nodes[i].pnn;
1652 control_delip(ctdb, argc, argv);
1655 talloc_free(tmp_ctx);
1660 delete a public ip address from a node
1662 static int control_delip(struct ctdb_context *ctdb, int argc, const char **argv)
1665 ctdb_sock_addr addr;
1666 struct ctdb_control_ip_iface pub;
1667 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
1668 struct ctdb_all_public_ips *ips;
1671 talloc_free(tmp_ctx);
1675 if (parse_ip(argv[0], NULL, 0, &addr) == 0) {
1676 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
1680 if (options.pnn == CTDB_BROADCAST_ALL) {
1681 return control_delip_all(ctdb, argc, argv, &addr);
1688 ret = ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), options.pnn, tmp_ctx, &ips);
1690 DEBUG(DEBUG_ERR, ("Unable to get public ip list from cluster\n"));
1691 talloc_free(tmp_ctx);
1695 for (i=0;i<ips->num;i++) {
1696 if (ctdb_same_ip(&addr, &ips->ips[i].addr)) {
1702 DEBUG(DEBUG_ERR, ("This node does not support this public address '%s'\n",
1703 ctdb_addr_to_str(&addr)));
1704 talloc_free(tmp_ctx);
1708 if (ips->ips[i].pnn == options.pnn) {
1709 ret = find_other_host_for_public_ip(ctdb, &addr);
1711 if (move_ip(ctdb, &addr, ret) != 0) {
1712 DEBUG(DEBUG_ERR,("Failed to move ip to node %d\n", ret));
1718 ret = ctdb_ctrl_del_public_ip(ctdb, TIMELIMIT(), options.pnn, &pub);
1720 DEBUG(DEBUG_ERR, ("Unable to del public ip from node %u\n", options.pnn));
1721 talloc_free(tmp_ctx);
1725 talloc_free(tmp_ctx);
1730 kill a tcp connection
1732 static int kill_tcp(struct ctdb_context *ctdb, int argc, const char **argv)
1735 struct ctdb_control_killtcp killtcp;
1741 if (!parse_ip_port(argv[0], &killtcp.src_addr)) {
1742 DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[0]));
1746 if (!parse_ip_port(argv[1], &killtcp.dst_addr)) {
1747 DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[1]));
1751 ret = ctdb_ctrl_killtcp(ctdb, TIMELIMIT(), options.pnn, &killtcp);
1753 DEBUG(DEBUG_ERR, ("Unable to killtcp from node %u\n", options.pnn));
1764 static int control_gratious_arp(struct ctdb_context *ctdb, int argc, const char **argv)
1767 ctdb_sock_addr addr;
1773 if (!parse_ip(argv[0], NULL, 0, &addr)) {
1774 DEBUG(DEBUG_ERR, ("Bad IP '%s'\n", argv[0]));
1778 ret = ctdb_ctrl_gratious_arp(ctdb, TIMELIMIT(), options.pnn, &addr, argv[1]);
1780 DEBUG(DEBUG_ERR, ("Unable to send gratious_arp from node %u\n", options.pnn));
1788 register a server id
1790 static int regsrvid(struct ctdb_context *ctdb, int argc, const char **argv)
1793 struct ctdb_server_id server_id;
1799 server_id.pnn = strtoul(argv[0], NULL, 0);
1800 server_id.type = strtoul(argv[1], NULL, 0);
1801 server_id.server_id = strtoul(argv[2], NULL, 0);
1803 ret = ctdb_ctrl_register_server_id(ctdb, TIMELIMIT(), &server_id);
1805 DEBUG(DEBUG_ERR, ("Unable to register server_id from node %u\n", options.pnn));
1808 DEBUG(DEBUG_ERR,("Srvid registered. Sleeping for 999 seconds\n"));
1814 unregister a server id
1816 static int unregsrvid(struct ctdb_context *ctdb, int argc, const char **argv)
1819 struct ctdb_server_id server_id;
1825 server_id.pnn = strtoul(argv[0], NULL, 0);
1826 server_id.type = strtoul(argv[1], NULL, 0);
1827 server_id.server_id = strtoul(argv[2], NULL, 0);
1829 ret = ctdb_ctrl_unregister_server_id(ctdb, TIMELIMIT(), &server_id);
1831 DEBUG(DEBUG_ERR, ("Unable to unregister server_id from node %u\n", options.pnn));
1838 check if a server id exists
1840 static int chksrvid(struct ctdb_context *ctdb, int argc, const char **argv)
1844 struct ctdb_server_id server_id;
1850 server_id.pnn = strtoul(argv[0], NULL, 0);
1851 server_id.type = strtoul(argv[1], NULL, 0);
1852 server_id.server_id = strtoul(argv[2], NULL, 0);
1854 ret = ctdb_ctrl_check_server_id(ctdb, TIMELIMIT(), options.pnn, &server_id, &status);
1856 DEBUG(DEBUG_ERR, ("Unable to check server_id from node %u\n", options.pnn));
1861 printf("Server id %d:%d:%d EXISTS\n", server_id.pnn, server_id.type, server_id.server_id);
1863 printf("Server id %d:%d:%d does NOT exist\n", server_id.pnn, server_id.type, server_id.server_id);
1869 get a list of all server ids that are registered on a node
1871 static int getsrvids(struct ctdb_context *ctdb, int argc, const char **argv)
1874 struct ctdb_server_id_list *server_ids;
1876 ret = ctdb_ctrl_get_server_id_list(ctdb, ctdb, TIMELIMIT(), options.pnn, &server_ids);
1878 DEBUG(DEBUG_ERR, ("Unable to get server_id list from node %u\n", options.pnn));
1882 for (i=0; i<server_ids->num; i++) {
1883 printf("Server id %d:%d:%d\n",
1884 server_ids->server_ids[i].pnn,
1885 server_ids->server_ids[i].type,
1886 server_ids->server_ids[i].server_id);
1893 send a tcp tickle ack
1895 static int tickle_tcp(struct ctdb_context *ctdb, int argc, const char **argv)
1898 ctdb_sock_addr src, dst;
1904 if (!parse_ip_port(argv[0], &src)) {
1905 DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[0]));
1909 if (!parse_ip_port(argv[1], &dst)) {
1910 DEBUG(DEBUG_ERR, ("Bad IP:port '%s'\n", argv[1]));
1914 ret = ctdb_sys_send_tcp(&src, &dst, 0, 0, 0);
1918 DEBUG(DEBUG_ERR, ("Error while sending tickle ack\n"));
1925 display public ip status
1927 static int control_ip(struct ctdb_context *ctdb, int argc, const char **argv)
1930 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
1931 struct ctdb_all_public_ips *ips;
1933 if (options.pnn == CTDB_BROADCAST_ALL) {
1934 /* read the list of public ips from all nodes */
1935 ret = control_get_all_public_ips(ctdb, tmp_ctx, &ips);
1937 /* read the public ip list from this node */
1938 ret = ctdb_ctrl_get_public_ips(ctdb, TIMELIMIT(), options.pnn, tmp_ctx, &ips);
1941 DEBUG(DEBUG_ERR, ("Unable to get public ips from node %u\n", options.pnn));
1942 talloc_free(tmp_ctx);
1946 if (options.machinereadable){
1947 printf(":Public IP:Node:");
1948 if (options.verbose){
1949 printf("ActiveInterface:AvailableInterfaces:ConfiguredInterfaces:");
1953 if (options.pnn == CTDB_BROADCAST_ALL) {
1954 printf("Public IPs on ALL nodes\n");
1956 printf("Public IPs on node %u\n", options.pnn);
1960 for (i=1;i<=ips->num;i++) {
1961 struct ctdb_control_public_ip_info *info = NULL;
1963 char *aciface = NULL;
1964 char *avifaces = NULL;
1965 char *cifaces = NULL;
1967 if (options.pnn == CTDB_BROADCAST_ALL) {
1968 pnn = ips->ips[ips->num-i].pnn;
1974 ret = ctdb_ctrl_get_public_ip_info(ctdb, TIMELIMIT(), pnn, ctdb,
1975 &ips->ips[ips->num-i].addr, &info);
1982 for (j=0; j < info->num; j++) {
1983 if (cifaces == NULL) {
1984 cifaces = talloc_strdup(info,
1985 info->ifaces[j].name);
1987 cifaces = talloc_asprintf_append(cifaces,
1989 info->ifaces[j].name);
1992 if (info->active_idx == j) {
1993 aciface = info->ifaces[j].name;
1996 if (info->ifaces[j].link_state == 0) {
2000 if (avifaces == NULL) {
2001 avifaces = talloc_strdup(info, info->ifaces[j].name);
2003 avifaces = talloc_asprintf_append(avifaces,
2005 info->ifaces[j].name);
2010 if (options.machinereadable){
2012 ctdb_addr_to_str(&ips->ips[ips->num-i].addr),
2013 ips->ips[ips->num-i].pnn);
2014 if (options.verbose){
2017 avifaces?avifaces:"",
2018 cifaces?cifaces:"");
2022 if (options.verbose) {
2023 printf("%s node[%d] active[%s] available[%s] configured[%s]\n",
2024 ctdb_addr_to_str(&ips->ips[ips->num-i].addr),
2025 ips->ips[ips->num-i].pnn,
2027 avifaces?avifaces:"",
2028 cifaces?cifaces:"");
2031 ctdb_addr_to_str(&ips->ips[ips->num-i].addr),
2032 ips->ips[ips->num-i].pnn);
2038 talloc_free(tmp_ctx);
2045 static int control_ipinfo(struct ctdb_context *ctdb, int argc, const char **argv)
2048 ctdb_sock_addr addr;
2049 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
2050 struct ctdb_control_public_ip_info *info;
2053 talloc_free(tmp_ctx);
2057 if (parse_ip(argv[0], NULL, 0, &addr) == 0) {
2058 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
2062 /* read the public ip info from this node */
2063 ret = ctdb_ctrl_get_public_ip_info(ctdb, TIMELIMIT(), options.pnn,
2064 tmp_ctx, &addr, &info);
2066 DEBUG(DEBUG_ERR, ("Unable to get public ip[%s]info from node %u\n",
2067 argv[0], options.pnn));
2068 talloc_free(tmp_ctx);
2072 printf("Public IP[%s] info on node %u\n",
2073 ctdb_addr_to_str(&info->ip.addr),
2076 printf("IP:%s\nCurrentNode:%d\nNumInterfaces:%u\n",
2077 ctdb_addr_to_str(&info->ip.addr),
2078 info->ip.pnn, info->num);
2080 for (i=0; i<info->num; i++) {
2081 info->ifaces[i].name[CTDB_IFACE_SIZE] = '\0';
2083 printf("Interface[%u]: Name:%s Link:%s References:%u%s\n",
2084 i+1, info->ifaces[i].name,
2085 info->ifaces[i].link_state?"up":"down",
2086 (unsigned int)info->ifaces[i].references,
2087 (i==info->active_idx)?" (active)":"");
2090 talloc_free(tmp_ctx);
2095 display interfaces status
2097 static int control_ifaces(struct ctdb_context *ctdb, int argc, const char **argv)
2100 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
2101 struct ctdb_control_get_ifaces *ifaces;
2103 /* read the public ip list from this node */
2104 ret = ctdb_ctrl_get_ifaces(ctdb, TIMELIMIT(), options.pnn,
2107 DEBUG(DEBUG_ERR, ("Unable to get interfaces from node %u\n",
2109 talloc_free(tmp_ctx);
2113 if (options.machinereadable){
2114 printf(":Name:LinkStatus:References:\n");
2116 printf("Interfaces on node %u\n", options.pnn);
2119 for (i=0; i<ifaces->num; i++) {
2120 if (options.machinereadable){
2121 printf(":%s:%s:%u\n",
2122 ifaces->ifaces[i].name,
2123 ifaces->ifaces[i].link_state?"1":"0",
2124 (unsigned int)ifaces->ifaces[i].references);
2126 printf("name:%s link:%s references:%u\n",
2127 ifaces->ifaces[i].name,
2128 ifaces->ifaces[i].link_state?"up":"down",
2129 (unsigned int)ifaces->ifaces[i].references);
2133 talloc_free(tmp_ctx);
2139 set link status of an interface
2141 static int control_setifacelink(struct ctdb_context *ctdb, int argc, const char **argv)
2144 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
2145 struct ctdb_control_iface_info info;
2153 if (strlen(argv[0]) > CTDB_IFACE_SIZE) {
2154 DEBUG(DEBUG_ERR, ("interfaces name '%s' too long\n",
2156 talloc_free(tmp_ctx);
2159 strcpy(info.name, argv[0]);
2161 if (strcmp(argv[1], "up") == 0) {
2162 info.link_state = 1;
2163 } else if (strcmp(argv[1], "down") == 0) {
2164 info.link_state = 0;
2166 DEBUG(DEBUG_ERR, ("link state invalid '%s' should be 'up' or 'down'\n",
2168 talloc_free(tmp_ctx);
2172 /* read the public ip list from this node */
2173 ret = ctdb_ctrl_set_iface_link(ctdb, TIMELIMIT(), options.pnn,
2176 DEBUG(DEBUG_ERR, ("Unable to set link state for interfaces %s node %u\n",
2177 argv[0], options.pnn));
2178 talloc_free(tmp_ctx);
2182 talloc_free(tmp_ctx);
2187 display pid of a ctdb daemon
2189 static int control_getpid(struct ctdb_context *ctdb, int argc, const char **argv)
2194 ret = ctdb_ctrl_getpid(ctdb, TIMELIMIT(), options.pnn, &pid);
2196 DEBUG(DEBUG_ERR, ("Unable to get daemon pid from node %u\n", options.pnn));
2199 printf("Pid:%d\n", pid);
2204 static uint32_t ipreallocate_finished;
2207 handler for receiving the response to ipreallocate
2209 static void ip_reallocate_handler(struct ctdb_context *ctdb, uint64_t srvid,
2210 TDB_DATA data, void *private_data)
2212 ipreallocate_finished = 1;
2215 static void ctdb_every_second(struct event_context *ev, struct timed_event *te, struct timeval t, void *p)
2217 struct ctdb_context *ctdb = talloc_get_type(p, struct ctdb_context);
2219 event_add_timed(ctdb->ev, ctdb,
2220 timeval_current_ofs(1, 0),
2221 ctdb_every_second, ctdb);
2225 ask the recovery daemon on the recovery master to perform a ip reallocation
2227 static int control_ipreallocate(struct ctdb_context *ctdb, int argc, const char **argv)
2231 struct takeover_run_reply rd;
2233 struct ctdb_node_map *nodemap=NULL;
2235 struct timeval tv = timeval_current();
2237 /* we need some events to trigger so we can timeout and restart
2240 event_add_timed(ctdb->ev, ctdb,
2241 timeval_current_ofs(1, 0),
2242 ctdb_every_second, ctdb);
2244 rd.pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE);
2246 DEBUG(DEBUG_ERR, ("Failed to get pnn of local node\n"));
2249 rd.srvid = getpid();
2251 /* register a message port for receiveing the reply so that we
2252 can receive the reply
2254 ctdb_client_set_message_handler(ctdb, rd.srvid, ip_reallocate_handler, NULL);
2256 data.dptr = (uint8_t *)&rd;
2257 data.dsize = sizeof(rd);
2260 /* check that there are valid nodes available */
2261 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb, &nodemap) != 0) {
2262 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2265 for (i=0; i<nodemap->num;i++) {
2266 if ((nodemap->nodes[i].flags & (NODE_FLAGS_DELETED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)) == 0) {
2270 if (i==nodemap->num) {
2271 DEBUG(DEBUG_ERR,("No recmaster available, no need to wait for cluster convergence\n"));
2276 ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
2278 DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
2282 /* verify the node exists */
2283 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), recmaster, ctdb, &nodemap) != 0) {
2284 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2289 /* check tha there are nodes available that can act as a recmaster */
2290 for (i=0; i<nodemap->num; i++) {
2291 if (nodemap->nodes[i].flags & (NODE_FLAGS_DELETED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)) {
2296 if (i == nodemap->num) {
2297 DEBUG(DEBUG_ERR,("No possible nodes to host addresses.\n"));
2301 /* verify the recovery master is not STOPPED, nor BANNED */
2302 if (nodemap->nodes[recmaster].flags & (NODE_FLAGS_DELETED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)) {
2303 DEBUG(DEBUG_ERR,("No suitable recmaster found. Try again\n"));
2310 /* verify the recovery master is not STOPPED, nor BANNED */
2311 if (nodemap->nodes[recmaster].flags & (NODE_FLAGS_DELETED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)) {
2312 DEBUG(DEBUG_ERR,("No suitable recmaster found. Try again\n"));
2318 ipreallocate_finished = 0;
2319 ret = ctdb_client_send_message(ctdb, recmaster, CTDB_SRVID_TAKEOVER_RUN, data);
2321 DEBUG(DEBUG_ERR,("Failed to send ip takeover run request message to %u\n", options.pnn));
2325 tv = timeval_current();
2326 /* this loop will terminate when we have received the reply */
2327 while (timeval_elapsed(&tv) < 3.0) {
2328 event_loop_once(ctdb->ev);
2330 if (ipreallocate_finished == 1) {
2334 DEBUG(DEBUG_ERR,("Timed out waiting for recmaster ipreallocate. Trying again\n"));
2344 disable a remote node
2346 static int control_disable(struct ctdb_context *ctdb, int argc, const char **argv)
2349 struct ctdb_node_map *nodemap=NULL;
2351 /* check if the node is already disabled */
2352 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap) != 0) {
2353 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2356 if (nodemap->nodes[options.pnn].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
2357 DEBUG(DEBUG_ERR,("Node %d is already disabled.\n", options.pnn));
2362 ret = ctdb_ctrl_modflags(ctdb, TIMELIMIT(), options.pnn, NODE_FLAGS_PERMANENTLY_DISABLED, 0);
2364 DEBUG(DEBUG_ERR, ("Unable to disable node %u\n", options.pnn));
2370 /* read the nodemap and verify the change took effect */
2371 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap) != 0) {
2372 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2376 } while (!(nodemap->nodes[options.pnn].flags & NODE_FLAGS_PERMANENTLY_DISABLED));
2377 ret = control_ipreallocate(ctdb, argc, argv);
2379 DEBUG(DEBUG_ERR, ("IP Reallocate failed on node %u\n", options.pnn));
2387 enable a disabled remote node
2389 static int control_enable(struct ctdb_context *ctdb, int argc, const char **argv)
2393 struct ctdb_node_map *nodemap=NULL;
2396 /* check if the node is already enabled */
2397 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap) != 0) {
2398 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2401 if (!(nodemap->nodes[options.pnn].flags & NODE_FLAGS_PERMANENTLY_DISABLED)) {
2402 DEBUG(DEBUG_ERR,("Node %d is already enabled.\n", options.pnn));
2407 ret = ctdb_ctrl_modflags(ctdb, TIMELIMIT(), options.pnn, 0, NODE_FLAGS_PERMANENTLY_DISABLED);
2409 DEBUG(DEBUG_ERR, ("Unable to enable node %u\n", options.pnn));
2415 /* read the nodemap and verify the change took effect */
2416 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap) != 0) {
2417 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2421 } while (nodemap->nodes[options.pnn].flags & NODE_FLAGS_PERMANENTLY_DISABLED);
2423 ret = control_ipreallocate(ctdb, argc, argv);
2425 DEBUG(DEBUG_ERR, ("IP Reallocate failed on node %u\n", options.pnn));
2435 static int control_stop(struct ctdb_context *ctdb, int argc, const char **argv)
2438 struct ctdb_node_map *nodemap=NULL;
2441 ret = ctdb_ctrl_stop_node(ctdb, TIMELIMIT(), options.pnn);
2443 DEBUG(DEBUG_ERR, ("Unable to stop node %u try again\n", options.pnn));
2448 /* read the nodemap and verify the change took effect */
2449 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap) != 0) {
2450 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2454 } while (!(nodemap->nodes[options.pnn].flags & NODE_FLAGS_STOPPED));
2455 ret = control_ipreallocate(ctdb, argc, argv);
2457 DEBUG(DEBUG_ERR, ("IP Reallocate failed on node %u\n", options.pnn));
2465 restart a stopped remote node
2467 static int control_continue(struct ctdb_context *ctdb, int argc, const char **argv)
2471 struct ctdb_node_map *nodemap=NULL;
2474 ret = ctdb_ctrl_continue_node(ctdb, TIMELIMIT(), options.pnn);
2476 DEBUG(DEBUG_ERR, ("Unable to continue node %u\n", options.pnn));
2482 /* read the nodemap and verify the change took effect */
2483 if (ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap) != 0) {
2484 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2488 } while (nodemap->nodes[options.pnn].flags & NODE_FLAGS_STOPPED);
2489 ret = control_ipreallocate(ctdb, argc, argv);
2491 DEBUG(DEBUG_ERR, ("IP Reallocate failed on node %u\n", options.pnn));
2498 static uint32_t get_generation(struct ctdb_context *ctdb)
2500 struct ctdb_vnn_map *vnnmap=NULL;
2503 /* wait until the recmaster is not in recovery mode */
2505 uint32_t recmode, recmaster;
2507 if (vnnmap != NULL) {
2508 talloc_free(vnnmap);
2512 /* get the recmaster */
2513 ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, &recmaster);
2515 DEBUG(DEBUG_ERR, ("Unable to get recmaster from node %u\n", options.pnn));
2519 /* get recovery mode */
2520 ret = ctdb_ctrl_getrecmode(ctdb, ctdb, TIMELIMIT(), recmaster, &recmode);
2522 DEBUG(DEBUG_ERR, ("Unable to get recmode from node %u\n", options.pnn));
2526 /* get the current generation number */
2527 ret = ctdb_ctrl_getvnnmap(ctdb, TIMELIMIT(), recmaster, ctdb, &vnnmap);
2529 DEBUG(DEBUG_ERR, ("Unable to get vnnmap from recmaster (%u)\n", recmaster));
2533 if ((recmode == CTDB_RECOVERY_NORMAL)
2534 && (vnnmap->generation != 1)){
2535 return vnnmap->generation;
2542 ban a node from the cluster
2544 static int control_ban(struct ctdb_context *ctdb, int argc, const char **argv)
2547 struct ctdb_node_map *nodemap=NULL;
2548 struct ctdb_ban_time bantime;
2554 /* verify the node exists */
2555 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap);
2557 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2561 if (nodemap->nodes[options.pnn].flags & NODE_FLAGS_BANNED) {
2562 DEBUG(DEBUG_ERR,("Node %u is already banned.\n", options.pnn));
2566 bantime.pnn = options.pnn;
2567 bantime.time = strtoul(argv[0], NULL, 0);
2569 ret = ctdb_ctrl_set_ban(ctdb, TIMELIMIT(), options.pnn, &bantime);
2571 DEBUG(DEBUG_ERR,("Banning node %d for %d seconds failed.\n", bantime.pnn, bantime.time));
2575 ret = control_ipreallocate(ctdb, argc, argv);
2577 DEBUG(DEBUG_ERR, ("IP Reallocate failed on node %u\n", options.pnn));
2586 unban a node from the cluster
2588 static int control_unban(struct ctdb_context *ctdb, int argc, const char **argv)
2591 struct ctdb_node_map *nodemap=NULL;
2592 struct ctdb_ban_time bantime;
2594 /* verify the node exists */
2595 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap);
2597 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2601 if (!(nodemap->nodes[options.pnn].flags & NODE_FLAGS_BANNED)) {
2602 DEBUG(DEBUG_ERR,("Node %u is not banned.\n", options.pnn));
2606 bantime.pnn = options.pnn;
2609 ret = ctdb_ctrl_set_ban(ctdb, TIMELIMIT(), options.pnn, &bantime);
2611 DEBUG(DEBUG_ERR,("Unbanning node %d failed.\n", bantime.pnn));
2615 ret = control_ipreallocate(ctdb, argc, argv);
2617 DEBUG(DEBUG_ERR, ("IP Reallocate failed on node %u\n", options.pnn));
2626 show ban information for a node
2628 static int control_showban(struct ctdb_context *ctdb, int argc, const char **argv)
2631 struct ctdb_node_map *nodemap=NULL;
2632 struct ctdb_ban_time *bantime;
2634 /* verify the node exists */
2635 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap);
2637 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
2641 ret = ctdb_ctrl_get_ban(ctdb, TIMELIMIT(), options.pnn, ctdb, &bantime);
2643 DEBUG(DEBUG_ERR,("Showing ban info for node %d failed.\n", options.pnn));
2647 if (bantime->time == 0) {
2648 printf("Node %u is not banned\n", bantime->pnn);
2650 printf("Node %u is banned banned for %d seconds\n", bantime->pnn, bantime->time);
2659 static int control_shutdown(struct ctdb_context *ctdb, int argc, const char **argv)
2663 ret = ctdb_ctrl_shutdown(ctdb, TIMELIMIT(), options.pnn);
2665 DEBUG(DEBUG_ERR, ("Unable to shutdown node %u\n", options.pnn));
2675 static int control_recover(struct ctdb_context *ctdb, int argc, const char **argv)
2678 uint32_t generation, next_generation;
2680 /* record the current generation number */
2681 generation = get_generation(ctdb);
2683 ret = ctdb_ctrl_freeze_priority(ctdb, TIMELIMIT(), options.pnn, 1);
2685 DEBUG(DEBUG_ERR, ("Unable to freeze node\n"));
2689 ret = ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
2691 DEBUG(DEBUG_ERR, ("Unable to set recovery mode\n"));
2695 /* wait until we are in a new generation */
2697 next_generation = get_generation(ctdb);
2698 if (next_generation != generation) {
2709 display monitoring mode of a remote node
2711 static int control_getmonmode(struct ctdb_context *ctdb, int argc, const char **argv)
2716 ret = ctdb_ctrl_getmonmode(ctdb, TIMELIMIT(), options.pnn, &monmode);
2718 DEBUG(DEBUG_ERR, ("Unable to get monmode from node %u\n", options.pnn));
2721 if (!options.machinereadable){
2722 printf("Monitoring mode:%s (%d)\n",monmode==CTDB_MONITORING_ACTIVE?"ACTIVE":"DISABLED",monmode);
2725 printf(":%d:\n",monmode);
2732 display capabilities of a remote node
2734 static int control_getcapabilities(struct ctdb_context *ctdb, int argc, const char **argv)
2736 uint32_t capabilities;
2739 ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), options.pnn, &capabilities);
2741 DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", options.pnn));
2745 if (!options.machinereadable){
2746 printf("RECMASTER: %s\n", (capabilities&CTDB_CAP_RECMASTER)?"YES":"NO");
2747 printf("LMASTER: %s\n", (capabilities&CTDB_CAP_LMASTER)?"YES":"NO");
2748 printf("LVS: %s\n", (capabilities&CTDB_CAP_LVS)?"YES":"NO");
2749 printf("NATGW: %s\n", (capabilities&CTDB_CAP_NATGW)?"YES":"NO");
2751 printf(":RECMASTER:LMASTER:LVS:NATGW:\n");
2752 printf(":%d:%d:%d:%d:\n",
2753 !!(capabilities&CTDB_CAP_RECMASTER),
2754 !!(capabilities&CTDB_CAP_LMASTER),
2755 !!(capabilities&CTDB_CAP_LVS),
2756 !!(capabilities&CTDB_CAP_NATGW));
2762 display lvs configuration
2764 static int control_lvs(struct ctdb_context *ctdb, int argc, const char **argv)
2766 uint32_t *capabilities;
2767 struct ctdb_node_map *nodemap=NULL;
2769 int healthy_count = 0;
2771 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb, &nodemap);
2773 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
2777 capabilities = talloc_array(ctdb, uint32_t, nodemap->num);
2778 CTDB_NO_MEMORY(ctdb, capabilities);
2780 /* collect capabilities for all connected nodes */
2781 for (i=0; i<nodemap->num; i++) {
2782 if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
2785 if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
2789 ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), i, &capabilities[i]);
2791 DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", i));
2795 if (!(capabilities[i] & CTDB_CAP_LVS)) {
2799 if (!(nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY)) {
2804 /* Print all LVS nodes */
2805 for (i=0; i<nodemap->num; i++) {
2806 if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
2809 if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
2812 if (!(capabilities[i] & CTDB_CAP_LVS)) {
2816 if (healthy_count != 0) {
2817 if (nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY) {
2822 printf("%d:%s\n", i,
2823 ctdb_addr_to_str(&nodemap->nodes[i].addr));
2830 display who is the lvs master
2832 static int control_lvsmaster(struct ctdb_context *ctdb, int argc, const char **argv)
2834 uint32_t *capabilities;
2835 struct ctdb_node_map *nodemap=NULL;
2837 int healthy_count = 0;
2839 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb, &nodemap);
2841 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
2845 capabilities = talloc_array(ctdb, uint32_t, nodemap->num);
2846 CTDB_NO_MEMORY(ctdb, capabilities);
2848 /* collect capabilities for all connected nodes */
2849 for (i=0; i<nodemap->num; i++) {
2850 if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
2853 if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
2857 ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), i, &capabilities[i]);
2859 DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", i));
2863 if (!(capabilities[i] & CTDB_CAP_LVS)) {
2867 if (!(nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY)) {
2872 /* find and show the lvsmaster */
2873 for (i=0; i<nodemap->num; i++) {
2874 if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
2877 if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
2880 if (!(capabilities[i] & CTDB_CAP_LVS)) {
2884 if (healthy_count != 0) {
2885 if (nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY) {
2890 if (options.machinereadable){
2893 printf("Node %d is LVS master\n", i);
2898 printf("There is no LVS master\n");
2903 disable monitoring on a node
2905 static int control_disable_monmode(struct ctdb_context *ctdb, int argc, const char **argv)
2910 ret = ctdb_ctrl_disable_monmode(ctdb, TIMELIMIT(), options.pnn);
2912 DEBUG(DEBUG_ERR, ("Unable to disable monmode on node %u\n", options.pnn));
2915 printf("Monitoring mode:%s\n","DISABLED");
2921 enable monitoring on a node
2923 static int control_enable_monmode(struct ctdb_context *ctdb, int argc, const char **argv)
2928 ret = ctdb_ctrl_enable_monmode(ctdb, TIMELIMIT(), options.pnn);
2930 DEBUG(DEBUG_ERR, ("Unable to enable monmode on node %u\n", options.pnn));
2933 printf("Monitoring mode:%s\n","ACTIVE");
2939 display remote list of keys/data for a db
2941 static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
2943 const char *db_name;
2944 struct ctdb_db_context *ctdb_db;
2954 if (db_exists(ctdb, db_name)) {
2955 DEBUG(DEBUG_ERR,("Database '%s' does not exist\n", db_name));
2959 ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
2961 if (ctdb_db == NULL) {
2962 DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
2966 /* traverse and dump the cluster tdb */
2967 ret = ctdb_dump_db(ctdb_db, stdout);
2969 DEBUG(DEBUG_ERR, ("Unable to dump database\n"));
2970 DEBUG(DEBUG_ERR, ("Maybe try 'ctdb getdbstatus %s'"
2971 " and 'ctdb getvar AllowUnhealthyDBRead'\n",
2975 talloc_free(ctdb_db);
2977 printf("Dumped %d records\n", ret);
2983 fetch a record from a persistent database
2985 static int control_pfetch(struct ctdb_context *ctdb, int argc, const char **argv)
2987 const char *db_name;
2988 struct ctdb_db_context *ctdb_db;
2989 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
2990 struct ctdb_transaction_handle *h;
2995 talloc_free(tmp_ctx);
3002 if (db_exists(ctdb, db_name)) {
3003 DEBUG(DEBUG_ERR,("Database '%s' does not exist\n", db_name));
3004 talloc_free(tmp_ctx);
3008 ctdb_db = ctdb_attach(ctdb, db_name, true, 0);
3010 if (ctdb_db == NULL) {
3011 DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
3012 talloc_free(tmp_ctx);
3016 h = ctdb_transaction_start(ctdb_db, tmp_ctx);
3018 DEBUG(DEBUG_ERR,("Failed to start transaction on database %s\n", db_name));
3019 talloc_free(tmp_ctx);
3023 key.dptr = discard_const(argv[1]);
3024 key.dsize = strlen(argv[1]);
3025 ret = ctdb_transaction_fetch(h, tmp_ctx, key, &data);
3027 DEBUG(DEBUG_ERR,("Failed to fetch record\n"));
3028 talloc_free(tmp_ctx);
3032 if (data.dsize == 0 || data.dptr == NULL) {
3033 DEBUG(DEBUG_ERR,("Record is empty\n"));
3034 talloc_free(tmp_ctx);
3039 fd = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0600);
3041 DEBUG(DEBUG_ERR,("Failed to open output file %s\n", argv[2]));
3042 talloc_free(tmp_ctx);
3045 write(fd, data.dptr, data.dsize);
3048 write(1, data.dptr, data.dsize);
3051 /* abort the transaction */
3055 talloc_free(tmp_ctx);
3060 fetch a record from a tdb-file
3062 static int control_tfetch(struct ctdb_context *ctdb, int argc, const char **argv)
3064 const char *tdb_file;
3075 tdb = tdb_open(tdb_file, 0, 0, O_RDONLY, 0);
3077 DEBUG(DEBUG_ERR,("Failed to open TDB file %s\n", tdb_file));
3081 key.dptr = discard_const(argv[1]);
3082 key.dsize = strlen(argv[1]);
3083 data = tdb_fetch(tdb, key);
3084 if (data.dptr == NULL || data.dsize < sizeof(struct ctdb_ltdb_header)) {
3085 DEBUG(DEBUG_ERR,("Failed to read record %s from tdb %s\n", argv[1], tdb_file));
3093 fd = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0600);
3095 DEBUG(DEBUG_ERR,("Failed to open output file %s\n", argv[2]));
3098 write(fd, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
3101 write(1, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
3108 write a record to a persistent database
3110 static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv)
3112 const char *db_name;
3113 struct ctdb_db_context *ctdb_db;
3114 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
3115 struct ctdb_transaction_handle *h;
3121 talloc_free(tmp_ctx);
3125 fd = open(argv[2], O_RDONLY);
3127 DEBUG(DEBUG_ERR,("Failed to open file containing record data : %s %s\n", argv[2], strerror(errno)));
3128 talloc_free(tmp_ctx);
3132 ret = fstat(fd, &st);
3134 DEBUG(DEBUG_ERR,("fstat of file %s failed: %s\n", argv[2], strerror(errno)));
3136 talloc_free(tmp_ctx);
3140 if (!S_ISREG(st.st_mode)) {
3141 DEBUG(DEBUG_ERR,("Not a regular file %s\n", argv[2]));
3143 talloc_free(tmp_ctx);
3147 data.dsize = st.st_size;
3148 if (data.dsize == 0) {
3151 data.dptr = talloc_size(tmp_ctx, data.dsize);
3152 if (data.dptr == NULL) {
3153 DEBUG(DEBUG_ERR,("Failed to talloc %d of memory to store record data\n", (int)data.dsize));
3155 talloc_free(tmp_ctx);
3158 ret = read(fd, data.dptr, data.dsize);
3159 if (ret != data.dsize) {
3160 DEBUG(DEBUG_ERR,("Failed to read %d bytes of record data\n", (int)data.dsize));
3162 talloc_free(tmp_ctx);
3171 ctdb_db = ctdb_attach(ctdb, db_name, true, 0);
3173 if (ctdb_db == NULL) {
3174 DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
3175 talloc_free(tmp_ctx);
3179 h = ctdb_transaction_start(ctdb_db, tmp_ctx);
3181 DEBUG(DEBUG_ERR,("Failed to start transaction on database %s\n", db_name));
3182 talloc_free(tmp_ctx);
3186 key.dptr = discard_const(argv[1]);
3187 key.dsize = strlen(argv[1]);
3188 ret = ctdb_transaction_store(h, key, data);
3190 DEBUG(DEBUG_ERR,("Failed to store record\n"));
3191 talloc_free(tmp_ctx);
3195 ret = ctdb_transaction_commit(h);
3197 DEBUG(DEBUG_ERR,("Failed to commit transaction\n"));
3198 talloc_free(tmp_ctx);
3203 talloc_free(tmp_ctx);
3207 static void log_handler(struct ctdb_context *ctdb, uint64_t srvid,
3208 TDB_DATA data, void *private_data)
3210 DEBUG(DEBUG_ERR,("Log data received\n"));
3211 if (data.dsize > 0) {
3212 printf("%s", data.dptr);
3219 display a list of log messages from the in memory ringbuffer
3221 static int control_getlog(struct ctdb_context *ctdb, int argc, const char **argv)
3225 struct ctdb_get_log_addr log_addr;
3227 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
3232 DEBUG(DEBUG_ERR,("Invalid arguments\n"));
3233 talloc_free(tmp_ctx);
3237 log_addr.pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE);
3238 log_addr.srvid = getpid();
3239 if (isalpha(argv[0][0]) || argv[0][0] == '-') {
3240 log_addr.level = get_debug_by_desc(argv[0]);
3242 log_addr.level = strtol(argv[0], NULL, 0);
3246 data.dptr = (unsigned char *)&log_addr;
3247 data.dsize = sizeof(log_addr);
3249 DEBUG(DEBUG_ERR, ("Pulling logs from node %u\n", options.pnn));
3251 ctdb_client_set_message_handler(ctdb, log_addr.srvid, log_handler, NULL);
3254 DEBUG(DEBUG_ERR,("Listen for response on %d\n", (int)log_addr.srvid));
3256 ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_GET_LOG,
3257 0, data, tmp_ctx, NULL, &res, NULL, &errmsg);
3258 if (ret != 0 || res != 0) {
3259 DEBUG(DEBUG_ERR,("Failed to get logs - %s\n", errmsg));
3260 talloc_free(tmp_ctx);
3265 tv = timeval_current();
3266 /* this loop will terminate when we have received the reply */
3267 while (timeval_elapsed(&tv) < 3.0) {
3268 event_loop_once(ctdb->ev);
3271 DEBUG(DEBUG_INFO,("Timed out waiting for log data.\n"));
3273 talloc_free(tmp_ctx);
3278 clear the in memory log area
3280 static int control_clearlog(struct ctdb_context *ctdb, int argc, const char **argv)
3285 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
3287 ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_CLEAR_LOG,
3288 0, tdb_null, tmp_ctx, NULL, &res, NULL, &errmsg);
3289 if (ret != 0 || res != 0) {
3290 DEBUG(DEBUG_ERR,("Failed to clear logs\n"));
3291 talloc_free(tmp_ctx);
3295 talloc_free(tmp_ctx);
3302 display a list of the databases on a remote ctdb
3304 static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **argv)
3307 struct ctdb_dbid_map *dbmap=NULL;
3309 ret = ctdb_ctrl_getdbmap(ctdb, TIMELIMIT(), options.pnn, ctdb, &dbmap);
3311 DEBUG(DEBUG_ERR, ("Unable to get dbids from node %u\n", options.pnn));
3315 if(options.machinereadable){
3316 printf(":ID:Name:Path:Persistent:Unhealthy:\n");
3317 for(i=0;i<dbmap->num;i++){
3323 ctdb_ctrl_getdbpath(ctdb, TIMELIMIT(), options.pnn,
3324 dbmap->dbs[i].dbid, ctdb, &path);
3325 ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.pnn,
3326 dbmap->dbs[i].dbid, ctdb, &name);
3327 ctdb_ctrl_getdbhealth(ctdb, TIMELIMIT(), options.pnn,
3328 dbmap->dbs[i].dbid, ctdb, &health);
3329 persistent = dbmap->dbs[i].persistent;
3330 printf(":0x%08X:%s:%s:%d:%d:\n",
3331 dbmap->dbs[i].dbid, name, path,
3332 !!(persistent), !!(health));
3337 printf("Number of databases:%d\n", dbmap->num);
3338 for(i=0;i<dbmap->num;i++){
3344 ctdb_ctrl_getdbpath(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &path);
3345 ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &name);
3346 ctdb_ctrl_getdbhealth(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &health);
3347 persistent = dbmap->dbs[i].persistent;
3348 printf("dbid:0x%08x name:%s path:%s%s%s\n",
3349 dbmap->dbs[i].dbid, name, path,
3350 persistent?" PERSISTENT":"",
3351 health?" UNHEALTHY":"");
3358 display the status of a database on a remote ctdb
3360 static int control_getdbstatus(struct ctdb_context *ctdb, int argc, const char **argv)
3363 struct ctdb_dbid_map *dbmap=NULL;
3364 const char *db_name;
3372 ret = ctdb_ctrl_getdbmap(ctdb, TIMELIMIT(), options.pnn, ctdb, &dbmap);
3374 DEBUG(DEBUG_ERR, ("Unable to get dbids from node %u\n", options.pnn));
3378 for(i=0;i<dbmap->num;i++){
3384 ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &name);
3385 if (strcmp(name, db_name) != 0) {
3389 ctdb_ctrl_getdbpath(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &path);
3390 ctdb_ctrl_getdbhealth(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &health);
3391 persistent = dbmap->dbs[i].persistent;
3392 printf("dbid: 0x%08x\nname: %s\npath: %s\nPERSISTENT: %s\nHEALTH: %s\n",
3393 dbmap->dbs[i].dbid, name, path,
3394 persistent?"yes":"no",
3395 health?health:"OK");
3399 DEBUG(DEBUG_ERR, ("db %s doesn't exist on node %u\n", db_name, options.pnn));
3404 check if the local node is recmaster or not
3405 it will return 1 if this node is the recmaster and 0 if it is not
3406 or if the local ctdb daemon could not be contacted
3408 static int control_isnotrecmaster(struct ctdb_context *ctdb, int argc, const char **argv)
3410 uint32_t mypnn, recmaster;
3413 mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
3415 printf("Failed to get pnn of node\n");
3419 ret = ctdb_ctrl_getrecmaster(ctdb, ctdb, TIMELIMIT(), options.pnn, &recmaster);
3421 printf("Failed to get the recmaster\n");
3425 if (recmaster != mypnn) {
3426 printf("this node is not the recmaster\n");
3430 printf("this node is the recmaster\n");
3437 static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
3440 struct timeval tv = timeval_current();
3441 ret = ctdb_ctrl_ping(ctdb, options.pnn);
3443 printf("Unable to get ping response from node %u\n", options.pnn);
3446 printf("response from %u time=%.6f sec (%d clients)\n",
3447 options.pnn, timeval_elapsed(&tv), ret);
3456 static int control_getvar(struct ctdb_context *ctdb, int argc, const char **argv)
3467 ret = ctdb_ctrl_get_tunable(ctdb, TIMELIMIT(), options.pnn, name, &value);
3469 DEBUG(DEBUG_ERR, ("Unable to get tunable variable '%s'\n", name));
3473 printf("%-19s = %u\n", name, value);
3480 static int control_setvar(struct ctdb_context *ctdb, int argc, const char **argv)
3491 value = strtoul(argv[1], NULL, 0);
3493 ret = ctdb_ctrl_set_tunable(ctdb, TIMELIMIT(), options.pnn, name, value);
3495 DEBUG(DEBUG_ERR, ("Unable to set tunable variable '%s'\n", name));
3504 static int control_listvars(struct ctdb_context *ctdb, int argc, const char **argv)
3510 ret = ctdb_ctrl_list_tunables(ctdb, TIMELIMIT(), options.pnn, ctdb, &list, &count);
3512 DEBUG(DEBUG_ERR, ("Unable to list tunable variables\n"));
3516 for (i=0;i<count;i++) {
3517 control_getvar(ctdb, 1, &list[i]);
3526 display debug level on a node
3528 static int control_getdebug(struct ctdb_context *ctdb, int argc, const char **argv)
3533 ret = ctdb_ctrl_get_debuglevel(ctdb, options.pnn, &level);
3535 DEBUG(DEBUG_ERR, ("Unable to get debuglevel response from node %u\n", options.pnn));
3538 if (options.machinereadable){
3539 printf(":Name:Level:\n");
3540 printf(":%s:%d:\n",get_debug_by_level(level),level);
3542 printf("Node %u is at debug level %s (%d)\n", options.pnn, get_debug_by_level(level), level);
3549 display reclock file of a node
3551 static int control_getreclock(struct ctdb_context *ctdb, int argc, const char **argv)
3554 const char *reclock;
3556 ret = ctdb_ctrl_getreclock(ctdb, TIMELIMIT(), options.pnn, ctdb, &reclock);
3558 DEBUG(DEBUG_ERR, ("Unable to get reclock file from node %u\n", options.pnn));
3561 if (options.machinereadable){
3562 if (reclock != NULL) {
3563 printf("%s", reclock);
3566 if (reclock == NULL) {
3567 printf("No reclock file used.\n");
3569 printf("Reclock file:%s\n", reclock);
3577 set the reclock file of a node
3579 static int control_setreclock(struct ctdb_context *ctdb, int argc, const char **argv)
3582 const char *reclock;
3586 } else if (argc == 1) {
3592 ret = ctdb_ctrl_setreclock(ctdb, TIMELIMIT(), options.pnn, reclock);
3594 DEBUG(DEBUG_ERR, ("Unable to get reclock file from node %u\n", options.pnn));
3601 set the natgw state on/off
3603 static int control_setnatgwstate(struct ctdb_context *ctdb, int argc, const char **argv)
3606 uint32_t natgwstate;
3612 if (!strcmp(argv[0], "on")) {
3614 } else if (!strcmp(argv[0], "off")) {
3620 ret = ctdb_ctrl_setnatgwstate(ctdb, TIMELIMIT(), options.pnn, natgwstate);
3622 DEBUG(DEBUG_ERR, ("Unable to set the natgw state for node %u\n", options.pnn));
3630 set the lmaster role on/off
3632 static int control_setlmasterrole(struct ctdb_context *ctdb, int argc, const char **argv)
3635 uint32_t lmasterrole;
3641 if (!strcmp(argv[0], "on")) {
3643 } else if (!strcmp(argv[0], "off")) {
3649 ret = ctdb_ctrl_setlmasterrole(ctdb, TIMELIMIT(), options.pnn, lmasterrole);
3651 DEBUG(DEBUG_ERR, ("Unable to set the lmaster role for node %u\n", options.pnn));
3659 set the recmaster role on/off
3661 static int control_setrecmasterrole(struct ctdb_context *ctdb, int argc, const char **argv)
3664 uint32_t recmasterrole;
3670 if (!strcmp(argv[0], "on")) {
3672 } else if (!strcmp(argv[0], "off")) {
3678 ret = ctdb_ctrl_setrecmasterrole(ctdb, TIMELIMIT(), options.pnn, recmasterrole);
3680 DEBUG(DEBUG_ERR, ("Unable to set the recmaster role for node %u\n", options.pnn));
3688 set debug level on a node or all nodes
3690 static int control_setdebug(struct ctdb_context *ctdb, int argc, const char **argv)
3696 printf("You must specify the debug level. Valid levels are:\n");
3697 for (i=0; debug_levels[i].description != NULL; i++) {
3698 printf("%s (%d)\n", debug_levels[i].description, debug_levels[i].level);
3704 if (isalpha(argv[0][0]) || argv[0][0] == '-') {
3705 level = get_debug_by_desc(argv[0]);
3707 level = strtol(argv[0], NULL, 0);
3710 for (i=0; debug_levels[i].description != NULL; i++) {
3711 if (level == debug_levels[i].level) {
3715 if (debug_levels[i].description == NULL) {
3716 printf("Invalid debug level, must be one of\n");
3717 for (i=0; debug_levels[i].description != NULL; i++) {
3718 printf("%s (%d)\n", debug_levels[i].description, debug_levels[i].level);
3723 ret = ctdb_ctrl_set_debuglevel(ctdb, options.pnn, level);
3725 DEBUG(DEBUG_ERR, ("Unable to set debug level on node %u\n", options.pnn));
3734 static int control_thaw(struct ctdb_context *ctdb, int argc, const char **argv)
3740 priority = strtol(argv[0], NULL, 0);
3744 DEBUG(DEBUG_ERR,("Thaw by priority %u\n", priority));
3746 ret = ctdb_ctrl_thaw_priority(ctdb, TIMELIMIT(), options.pnn, priority);
3748 DEBUG(DEBUG_ERR, ("Unable to thaw node %u\n", options.pnn));
3755 attach to a database
3757 static int control_attach(struct ctdb_context *ctdb, int argc, const char **argv)
3759 const char *db_name;
3760 struct ctdb_db_context *ctdb_db;
3767 ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
3768 if (ctdb_db == NULL) {
3769 DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
3779 static int control_setdbprio(struct ctdb_context *ctdb, int argc, const char **argv)
3781 struct ctdb_db_priority db_prio;
3788 db_prio.db_id = strtoul(argv[0], NULL, 0);
3789 db_prio.priority = strtoul(argv[1], NULL, 0);
3791 ret = ctdb_ctrl_set_db_priority(ctdb, TIMELIMIT(), options.pnn, &db_prio);
3793 DEBUG(DEBUG_ERR,("Unable to set db prio\n"));
3803 static int control_getdbprio(struct ctdb_context *ctdb, int argc, const char **argv)
3805 uint32_t db_id, priority;
3812 db_id = strtoul(argv[0], NULL, 0);
3814 ret = ctdb_ctrl_get_db_priority(ctdb, TIMELIMIT(), options.pnn, db_id, &priority);
3816 DEBUG(DEBUG_ERR,("Unable to get db prio\n"));
3820 DEBUG(DEBUG_ERR,("Priority:%u\n", priority));
3826 run an eventscript on a node
3828 static int control_eventscript(struct ctdb_context *ctdb, int argc, const char **argv)
3834 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
3837 DEBUG(DEBUG_ERR,("Invalid arguments\n"));
3841 data.dptr = (unsigned char *)discard_const(argv[0]);
3842 data.dsize = strlen((char *)data.dptr) + 1;
3844 DEBUG(DEBUG_ERR, ("Running eventscripts with arguments \"%s\" on node %u\n", data.dptr, options.pnn));
3846 ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_RUN_EVENTSCRIPTS,
3847 0, data, tmp_ctx, NULL, &res, NULL, &errmsg);
3848 if (ret != 0 || res != 0) {
3849 DEBUG(DEBUG_ERR,("Failed to run eventscripts - %s\n", errmsg));
3850 talloc_free(tmp_ctx);
3853 talloc_free(tmp_ctx);
3857 #define DB_VERSION 1
3858 #define MAX_DB_NAME 64
3859 struct db_file_header {
3860 unsigned long version;
3862 unsigned long persistent;
3864 const char name[MAX_DB_NAME];
3867 struct backup_data {
3868 struct ctdb_marshall_buffer *records;
3871 bool traverse_error;
3874 static int backup_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *private)
3876 struct backup_data *bd = talloc_get_type(private, struct backup_data);
3877 struct ctdb_rec_data *rec;
3879 /* add the record */
3880 rec = ctdb_marshall_record(bd->records, 0, key, NULL, data);
3882 bd->traverse_error = true;
3883 DEBUG(DEBUG_ERR,("Failed to marshall record\n"));
3886 bd->records = talloc_realloc_size(NULL, bd->records, rec->length + bd->len);
3887 if (bd->records == NULL) {
3888 DEBUG(DEBUG_ERR,("Failed to expand marshalling buffer\n"));
3889 bd->traverse_error = true;
3892 bd->records->count++;
3893 memcpy(bd->len+(uint8_t *)bd->records, rec, rec->length);
3894 bd->len += rec->length;
3902 * backup a database to a file
3904 static int control_backupdb(struct ctdb_context *ctdb, int argc, const char **argv)
3907 struct ctdb_dbid_map *dbmap=NULL;
3908 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
3909 struct db_file_header dbhdr;
3910 struct ctdb_db_context *ctdb_db;
3911 struct backup_data *bd;
3914 const char *reason = NULL;
3917 DEBUG(DEBUG_ERR,("Invalid arguments\n"));
3921 ret = ctdb_ctrl_getdbmap(ctdb, TIMELIMIT(), options.pnn, tmp_ctx, &dbmap);
3923 DEBUG(DEBUG_ERR, ("Unable to get dbids from node %u\n", options.pnn));
3927 for(i=0;i<dbmap->num;i++){
3930 ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, tmp_ctx, &name);
3931 if(!strcmp(argv[0], name)){
3932 talloc_free(discard_const(name));
3935 talloc_free(discard_const(name));
3937 if (i == dbmap->num) {
3938 DEBUG(DEBUG_ERR,("No database with name '%s' found\n", argv[0]));
3939 talloc_free(tmp_ctx);
3943 ret = ctdb_ctrl_getdbhealth(ctdb, TIMELIMIT(), options.pnn,
3944 dbmap->dbs[i].dbid, tmp_ctx, &reason);
3946 DEBUG(DEBUG_ERR,("Unable to get dbhealth for database '%s'\n",
3948 talloc_free(tmp_ctx);
3952 uint32_t allow_unhealthy = 0;
3954 ctdb_ctrl_get_tunable(ctdb, TIMELIMIT(), options.pnn,
3955 "AllowUnhealthyDBRead",
3958 if (allow_unhealthy != 1) {
3959 DEBUG(DEBUG_ERR,("database '%s' is unhealthy: %s\n",
3962 DEBUG(DEBUG_ERR,("disallow backup : tunnable AllowUnhealthyDBRead = %u\n",
3964 talloc_free(tmp_ctx);
3968 DEBUG(DEBUG_WARNING,("WARNING database '%s' is unhealthy - see 'ctdb getdbstatus %s'\n",
3970 DEBUG(DEBUG_WARNING,("WARNING! allow backup of unhealthy database: "
3971 "tunnable AllowUnhealthyDBRead = %u\n",
3975 ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
3976 if (ctdb_db == NULL) {
3977 DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", argv[0]));
3978 talloc_free(tmp_ctx);
3983 ret = tdb_transaction_start(ctdb_db->ltdb->tdb);
3985 DEBUG(DEBUG_ERR,("Failed to start transaction\n"));
3986 talloc_free(tmp_ctx);
3991 bd = talloc_zero(tmp_ctx, struct backup_data);
3993 DEBUG(DEBUG_ERR,("Failed to allocate backup_data\n"));
3994 talloc_free(tmp_ctx);
3998 bd->records = talloc_zero(bd, struct ctdb_marshall_buffer);
3999 if (bd->records == NULL) {
4000 DEBUG(DEBUG_ERR,("Failed to allocate ctdb_marshall_buffer\n"));
4001 talloc_free(tmp_ctx);
4005 bd->len = offsetof(struct ctdb_marshall_buffer, data);
4006 bd->records->db_id = ctdb_db->db_id;
4007 /* traverse the database collecting all records */
4008 if (tdb_traverse_read(ctdb_db->ltdb->tdb, backup_traverse, bd) == -1 ||
4009 bd->traverse_error) {
4010 DEBUG(DEBUG_ERR,("Traverse error\n"));
4011 talloc_free(tmp_ctx);
4015 tdb_transaction_cancel(ctdb_db->ltdb->tdb);
4018 fh = open(argv[1], O_RDWR|O_CREAT, 0600);
4020 DEBUG(DEBUG_ERR,("Failed to open file '%s'\n", argv[1]));
4021 talloc_free(tmp_ctx);
4025 dbhdr.version = DB_VERSION;
4026 dbhdr.timestamp = time(NULL);
4027 dbhdr.persistent = dbmap->dbs[i].persistent;
4028 dbhdr.size = bd->len;
4029 if (strlen(argv[0]) >= MAX_DB_NAME) {
4030 DEBUG(DEBUG_ERR,("Too long dbname\n"));
4033 strncpy(discard_const(dbhdr.name), argv[0], MAX_DB_NAME);
4034 ret = write(fh, &dbhdr, sizeof(dbhdr));
4036 DEBUG(DEBUG_ERR,("write failed: %s\n", strerror(errno)));
4039 ret = write(fh, bd->records, bd->len);
4041 DEBUG(DEBUG_ERR,("write failed: %s\n", strerror(errno)));
4050 DEBUG(DEBUG_ERR,("close failed: %s\n", strerror(errno)));
4053 talloc_free(tmp_ctx);
4058 * restore a database from a file
4060 static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **argv)
4063 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
4066 struct db_file_header dbhdr;
4067 struct ctdb_db_context *ctdb_db;
4068 struct ctdb_node_map *nodemap=NULL;
4069 struct ctdb_vnn_map *vnnmap=NULL;
4071 struct ctdb_control_wipe_database w;
4073 uint32_t generation;
4078 if (argc < 1 || argc > 2) {
4079 DEBUG(DEBUG_ERR,("Invalid arguments\n"));
4083 fh = open(argv[0], O_RDONLY);
4085 DEBUG(DEBUG_ERR,("Failed to open file '%s'\n", argv[0]));
4086 talloc_free(tmp_ctx);
4090 read(fh, &dbhdr, sizeof(dbhdr));
4091 if (dbhdr.version != DB_VERSION) {
4092 DEBUG(DEBUG_ERR,("Invalid version of database dump. File is version %lu but expected version was %u\n", dbhdr.version, DB_VERSION));
4093 talloc_free(tmp_ctx);
4097 dbname = discard_const(dbhdr.name);
4099 dbname = discard_const(argv[1]);
4102 outdata.dsize = dbhdr.size;
4103 outdata.dptr = talloc_size(tmp_ctx, outdata.dsize);
4104 if (outdata.dptr == NULL) {
4105 DEBUG(DEBUG_ERR,("Failed to allocate data of size '%lu'\n", dbhdr.size));
4107 talloc_free(tmp_ctx);
4110 read(fh, outdata.dptr, outdata.dsize);
4113 tm = localtime(&dbhdr.timestamp);
4114 strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
4115 printf("Restoring database '%s' from backup @ %s\n",
4119 ctdb_db = ctdb_attach(ctdb, dbname, dbhdr.persistent, 0);
4120 if (ctdb_db == NULL) {
4121 DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbname));
4122 talloc_free(tmp_ctx);
4126 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb, &nodemap);
4128 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
4129 talloc_free(tmp_ctx);
4134 ret = ctdb_ctrl_getvnnmap(ctdb, TIMELIMIT(), options.pnn, tmp_ctx, &vnnmap);
4136 DEBUG(DEBUG_ERR, ("Unable to get vnnmap from node %u\n", options.pnn));
4137 talloc_free(tmp_ctx);
4141 /* freeze all nodes */
4142 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4143 for (i=1; i<=NUM_DB_PRIORITIES; i++) {
4144 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_FREEZE,
4150 DEBUG(DEBUG_ERR, ("Unable to freeze nodes.\n"));
4151 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4152 talloc_free(tmp_ctx);
4157 generation = vnnmap->generation;
4158 data.dptr = (void *)&generation;
4159 data.dsize = sizeof(generation);
4161 /* start a cluster wide transaction */
4162 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4163 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_TRANSACTION_START,
4165 TIMELIMIT(), false, data,
4168 DEBUG(DEBUG_ERR, ("Unable to start cluster wide transactions.\n"));
4173 w.db_id = ctdb_db->db_id;
4174 w.transaction_id = generation;
4176 data.dptr = (void *)&w;
4177 data.dsize = sizeof(w);
4179 /* wipe all the remote databases. */
4180 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4181 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_WIPE_DATABASE,
4183 TIMELIMIT(), false, data,
4186 DEBUG(DEBUG_ERR, ("Unable to wipe database.\n"));
4187 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4188 talloc_free(tmp_ctx);
4192 /* push the database */
4193 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4194 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_PUSH_DB,
4196 TIMELIMIT(), false, outdata,
4199 DEBUG(DEBUG_ERR, ("Failed to push database.\n"));
4200 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4201 talloc_free(tmp_ctx);
4205 data.dptr = (void *)&ctdb_db->db_id;
4206 data.dsize = sizeof(ctdb_db->db_id);
4208 /* mark the database as healthy */
4209 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4210 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_DB_SET_HEALTHY,
4212 TIMELIMIT(), false, data,
4215 DEBUG(DEBUG_ERR, ("Failed to mark database as healthy.\n"));
4216 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4217 talloc_free(tmp_ctx);
4221 data.dptr = (void *)&generation;
4222 data.dsize = sizeof(generation);
4224 /* commit all the changes */
4225 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_TRANSACTION_COMMIT,
4227 TIMELIMIT(), false, data,
4230 DEBUG(DEBUG_ERR, ("Unable to commit databases.\n"));
4231 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4232 talloc_free(tmp_ctx);
4237 /* thaw all nodes */
4238 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4239 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_THAW,
4245 DEBUG(DEBUG_ERR, ("Unable to thaw nodes.\n"));
4246 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4247 talloc_free(tmp_ctx);
4252 talloc_free(tmp_ctx);
4257 * dump a database backup from a file
4259 static int control_dumpdbbackup(struct ctdb_context *ctdb, int argc, const char **argv)
4261 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
4263 struct db_file_header dbhdr;
4267 struct ctdb_rec_data *rec = NULL;
4268 struct ctdb_marshall_buffer *m;
4271 DEBUG(DEBUG_ERR,("Invalid arguments\n"));
4275 fh = open(argv[0], O_RDONLY);
4277 DEBUG(DEBUG_ERR,("Failed to open file '%s'\n", argv[0]));
4278 talloc_free(tmp_ctx);
4282 read(fh, &dbhdr, sizeof(dbhdr));
4283 if (dbhdr.version != DB_VERSION) {
4284 DEBUG(DEBUG_ERR,("Invalid version of database dump. File is version %lu but expected version was %u\n", dbhdr.version, DB_VERSION));
4285 talloc_free(tmp_ctx);
4289 outdata.dsize = dbhdr.size;
4290 outdata.dptr = talloc_size(tmp_ctx, outdata.dsize);
4291 if (outdata.dptr == NULL) {
4292 DEBUG(DEBUG_ERR,("Failed to allocate data of size '%lu'\n", dbhdr.size));
4294 talloc_free(tmp_ctx);
4297 read(fh, outdata.dptr, outdata.dsize);
4299 m = (struct ctdb_marshall_buffer *)outdata.dptr;
4301 tm = localtime(&dbhdr.timestamp);
4302 strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
4303 printf("Backup of database name:'%s' dbid:0x%x08x from @ %s\n",
4304 dbhdr.name, m->db_id, tbuf);
4306 for (i=0; i < m->count; i++) {
4310 /* we do not want the header splitted, so we pass NULL*/
4311 rec = ctdb_marshall_loop_next(m, rec, &reqid,
4314 ctdb_dumpdb_record(ctdb, key, data, stdout);
4317 printf("Dumped %d records\n", i);
4318 talloc_free(tmp_ctx);
4323 * wipe a database from a file
4325 static int control_wipedb(struct ctdb_context *ctdb, int argc,
4329 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
4331 struct ctdb_db_context *ctdb_db;
4332 struct ctdb_node_map *nodemap = NULL;
4333 struct ctdb_vnn_map *vnnmap = NULL;
4335 struct ctdb_control_wipe_database w;
4337 uint32_t generation;
4338 struct ctdb_dbid_map *dbmap = NULL;
4341 DEBUG(DEBUG_ERR,("Invalid arguments\n"));
4345 ret = ctdb_ctrl_getdbmap(ctdb, TIMELIMIT(), options.pnn, tmp_ctx,
4348 DEBUG(DEBUG_ERR, ("Unable to get dbids from node %u\n",
4353 for(i=0;i<dbmap->num;i++){
4356 ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.pnn,
4357 dbmap->dbs[i].dbid, tmp_ctx, &name);
4358 if(!strcmp(argv[0], name)){
4359 talloc_free(discard_const(name));
4362 talloc_free(discard_const(name));
4364 if (i == dbmap->num) {
4365 DEBUG(DEBUG_ERR, ("No database with name '%s' found\n",
4367 talloc_free(tmp_ctx);
4371 ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
4372 if (ctdb_db == NULL) {
4373 DEBUG(DEBUG_ERR, ("Unable to attach to database '%s'\n",
4375 talloc_free(tmp_ctx);
4379 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb,
4382 DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n",
4384 talloc_free(tmp_ctx);
4388 ret = ctdb_ctrl_getvnnmap(ctdb, TIMELIMIT(), options.pnn, tmp_ctx,
4391 DEBUG(DEBUG_ERR, ("Unable to get vnnmap from node %u\n",
4393 talloc_free(tmp_ctx);
4397 /* freeze all nodes */
4398 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4399 for (i=1; i<=NUM_DB_PRIORITIES; i++) {
4400 ret = ctdb_client_async_control(ctdb, CTDB_CONTROL_FREEZE,
4407 DEBUG(DEBUG_ERR, ("Unable to freeze nodes.\n"));
4408 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn,
4409 CTDB_RECOVERY_ACTIVE);
4410 talloc_free(tmp_ctx);
4415 generation = vnnmap->generation;
4416 data.dptr = (void *)&generation;
4417 data.dsize = sizeof(generation);
4419 /* start a cluster wide transaction */
4420 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4421 ret = ctdb_client_async_control(ctdb, CTDB_CONTROL_TRANSACTION_START,
4423 TIMELIMIT(), false, data,
4427 DEBUG(DEBUG_ERR, ("Unable to start cluster wide "
4428 "transactions.\n"));
4432 w.db_id = ctdb_db->db_id;
4433 w.transaction_id = generation;
4435 data.dptr = (void *)&w;
4436 data.dsize = sizeof(w);
4438 /* wipe all the remote databases. */
4439 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4440 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_WIPE_DATABASE,
4442 TIMELIMIT(), false, data,
4445 DEBUG(DEBUG_ERR, ("Unable to wipe database.\n"));
4446 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4447 talloc_free(tmp_ctx);
4451 data.dptr = (void *)&ctdb_db->db_id;
4452 data.dsize = sizeof(ctdb_db->db_id);
4454 /* mark the database as healthy */
4455 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4456 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_DB_SET_HEALTHY,
4458 TIMELIMIT(), false, data,
4461 DEBUG(DEBUG_ERR, ("Failed to mark database as healthy.\n"));
4462 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4463 talloc_free(tmp_ctx);
4467 data.dptr = (void *)&generation;
4468 data.dsize = sizeof(generation);
4470 /* commit all the changes */
4471 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_TRANSACTION_COMMIT,
4473 TIMELIMIT(), false, data,
4476 DEBUG(DEBUG_ERR, ("Unable to commit databases.\n"));
4477 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4478 talloc_free(tmp_ctx);
4482 /* thaw all nodes */
4483 nodes = list_of_active_nodes(ctdb, nodemap, tmp_ctx, true);
4484 if (ctdb_client_async_control(ctdb, CTDB_CONTROL_THAW,
4490 DEBUG(DEBUG_ERR, ("Unable to thaw nodes.\n"));
4491 ctdb_ctrl_setrecmode(ctdb, TIMELIMIT(), options.pnn, CTDB_RECOVERY_ACTIVE);
4492 talloc_free(tmp_ctx);
4496 talloc_free(tmp_ctx);
4503 static int control_dumpmemory(struct ctdb_context *ctdb, int argc, const char **argv)
4509 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
4510 ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_DUMP_MEMORY,
4511 0, tdb_null, tmp_ctx, &data, &res, NULL, &errmsg);
4512 if (ret != 0 || res != 0) {
4513 DEBUG(DEBUG_ERR,("Failed to dump memory - %s\n", errmsg));
4514 talloc_free(tmp_ctx);
4517 write(1, data.dptr, data.dsize);
4518 talloc_free(tmp_ctx);
4523 handler for memory dumps
4525 static void mem_dump_handler(struct ctdb_context *ctdb, uint64_t srvid,
4526 TDB_DATA data, void *private_data)
4528 write(1, data.dptr, data.dsize);
4533 dump memory usage on the recovery daemon
4535 static int control_rddumpmemory(struct ctdb_context *ctdb, int argc, const char **argv)
4539 struct rd_memdump_reply rd;
4541 rd.pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE);
4543 DEBUG(DEBUG_ERR, ("Failed to get pnn of local node\n"));
4546 rd.srvid = getpid();
4548 /* register a message port for receiveing the reply so that we
4549 can receive the reply
4551 ctdb_client_set_message_handler(ctdb, rd.srvid, mem_dump_handler, NULL);
4554 data.dptr = (uint8_t *)&rd;
4555 data.dsize = sizeof(rd);
4557 ret = ctdb_client_send_message(ctdb, options.pnn, CTDB_SRVID_MEM_DUMP, data);
4559 DEBUG(DEBUG_ERR,("Failed to send memdump request message to %u\n", options.pnn));
4563 /* this loop will terminate when we have received the reply */
4565 event_loop_once(ctdb->ev);
4572 send a message to a srvid
4574 static int control_msgsend(struct ctdb_context *ctdb, int argc, const char **argv)
4576 unsigned long srvid;
4584 srvid = strtoul(argv[0], NULL, 0);
4586 data.dptr = (uint8_t *)discard_const(argv[1]);
4587 data.dsize= strlen(argv[1]);
4589 ret = ctdb_client_send_message(ctdb, CTDB_BROADCAST_CONNECTED, srvid, data);
4591 DEBUG(DEBUG_ERR,("Failed to send memdump request message to %u\n", options.pnn));
4599 handler for msglisten
4601 static void msglisten_handler(struct ctdb_context *ctdb, uint64_t srvid,
4602 TDB_DATA data, void *private_data)
4606 printf("Message received: ");
4607 for (i=0;i<data.dsize;i++) {
4608 printf("%c", data.dptr[i]);
4614 listen for messages on a messageport
4616 static int control_msglisten(struct ctdb_context *ctdb, int argc, const char **argv)
4622 /* register a message port and listen for messages
4624 ctdb_client_set_message_handler(ctdb, srvid, msglisten_handler, NULL);
4625 printf("Listening for messages on srvid:%d\n", (int)srvid);
4628 event_loop_once(ctdb->ev);
4635 list all nodes in the cluster
4636 we parse the nodes file directly
4638 static int control_listnodes(struct ctdb_context *ctdb, int argc, const char **argv)
4640 TALLOC_CTX *mem_ctx = talloc_new(NULL);
4641 struct pnn_node *pnn_nodes;
4642 struct pnn_node *pnn_node;
4644 pnn_nodes = read_nodes_file(mem_ctx);
4645 if (pnn_nodes == NULL) {
4646 DEBUG(DEBUG_ERR,("Failed to read nodes file\n"));
4647 talloc_free(mem_ctx);
4651 for(pnn_node=pnn_nodes;pnn_node;pnn_node=pnn_node->next) {
4652 ctdb_sock_addr addr;
4653 if (parse_ip(pnn_node->addr, NULL, 63999, &addr) == 0) {
4654 DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s' in nodes file\n", pnn_node->addr));
4655 talloc_free(mem_ctx);
4658 if (options.machinereadable){
4659 printf(":%d:%s:\n", pnn_node->pnn, pnn_node->addr);
4661 printf("%s\n", pnn_node->addr);
4664 talloc_free(mem_ctx);
4670 reload the nodes file on the local node
4672 static int control_reload_nodes_file(struct ctdb_context *ctdb, int argc, const char **argv)
4676 struct ctdb_node_map *nodemap=NULL;
4678 mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE);
4680 DEBUG(DEBUG_ERR, ("Failed to read pnn of local node\n"));
4684 ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, ctdb, &nodemap);
4686 DEBUG(DEBUG_ERR, ("Unable to get nodemap from local node\n"));
4690 /* reload the nodes file on all remote nodes */
4691 for (i=0;i<nodemap->num;i++) {
4692 if (nodemap->nodes[i].pnn == mypnn) {
4695 DEBUG(DEBUG_NOTICE, ("Reloading nodes file on node %u\n", nodemap->nodes[i].pnn));
4696 ret = ctdb_ctrl_reload_nodes_file(ctdb, TIMELIMIT(),
4697 nodemap->nodes[i].pnn);
4699 DEBUG(DEBUG_ERR, ("ERROR: Failed to reload nodes file on node %u. You MUST fix that node manually!\n", nodemap->nodes[i].pnn));
4703 /* reload the nodes file on the local node */
4704 DEBUG(DEBUG_NOTICE, ("Reloading nodes file on node %u\n", mypnn));
4705 ret = ctdb_ctrl_reload_nodes_file(ctdb, TIMELIMIT(), mypnn);
4707 DEBUG(DEBUG_ERR, ("ERROR: Failed to reload nodes file on node %u. You MUST fix that node manually!\n", mypnn));
4710 /* initiate a recovery */
4711 control_recover(ctdb, argc, argv);
4717 static const struct {
4719 int (*fn)(struct ctdb_context *, int, const char **);
4721 bool without_daemon; /* can be run without daemon running ? */
4724 } ctdb_commands[] = {
4726 { "version", control_version, true, false, "show version of ctdb" },
4728 { "status", control_status, true, false, "show node status" },
4729 { "uptime", control_uptime, true, false, "show node uptime" },
4730 { "ping", control_ping, true, false, "ping all nodes" },
4731 { "getvar", control_getvar, true, false, "get a tunable variable", "<name>"},
4732 { "setvar", control_setvar, true, false, "set a tunable variable", "<name> <value>"},
4733 { "listvars", control_listvars, true, false, "list tunable variables"},
4734 { "statistics", control_statistics, false, false, "show statistics" },
4735 { "statisticsreset", control_statistics_reset, true, false, "reset statistics"},
4736 { "stats", control_stats, false, false, "show rolling statistics", "[number of history records]" },
4737 { "ip", control_ip, false, false, "show which public ip's that ctdb manages" },
4738 { "ipinfo", control_ipinfo, true, false, "show details about a public ip that ctdb manages", "<ip>" },
4739 { "ifaces", control_ifaces, true, false, "show which interfaces that ctdb manages" },
4740 { "setifacelink", control_setifacelink, true, false, "set interface link status", "<iface> <status>" },
4741 { "process-exists", control_process_exists, true, false, "check if a process exists on a node", "<pid>"},
4742 { "getdbmap", control_getdbmap, true, false, "show the database map" },
4743 { "getdbstatus", control_getdbstatus, true, false, "show the status of a database", "<dbname>" },
4744 { "catdb", control_catdb, true, false, "dump a database" , "<dbname>"},
4745 { "getmonmode", control_getmonmode, true, false, "show monitoring mode" },
4746 { "getcapabilities", control_getcapabilities, true, false, "show node capabilities" },
4747 { "pnn", control_pnn, true, false, "show the pnn of the currnet node" },
4748 { "lvs", control_lvs, true, false, "show lvs configuration" },
4749 { "lvsmaster", control_lvsmaster, true, false, "show which node is the lvs master" },
4750 { "disablemonitor", control_disable_monmode,true, false, "set monitoring mode to DISABLE" },
4751 { "enablemonitor", control_enable_monmode, true, false, "set monitoring mode to ACTIVE" },
4752 { "setdebug", control_setdebug, true, false, "set debug level", "<EMERG|ALERT|CRIT|ERR|WARNING|NOTICE|INFO|DEBUG>" },
4753 { "getdebug", control_getdebug, true, false, "get debug level" },
4754 { "getlog", control_getlog, true, false, "get the log data from the in memory ringbuffer", "<level>" },
4755 { "clearlog", control_clearlog, true, false, "clear the log data from the in memory ringbuffer" },
4756 { "attach", control_attach, true, false, "attach to a database", "<dbname>" },
4757 { "dumpmemory", control_dumpmemory, true, false, "dump memory map to stdout" },
4758 { "rddumpmemory", control_rddumpmemory, true, false, "dump memory map from the recovery daemon to stdout" },
4759 { "getpid", control_getpid, true, false, "get ctdbd process ID" },
4760 { "disable", control_disable, true, false, "disable a nodes public IP" },
4761 { "enable", control_enable, true, false, "enable a nodes public IP" },
4762 { "stop", control_stop, true, false, "stop a node" },
4763 { "continue", control_continue, true, false, "re-start a stopped node" },
4764 { "ban", control_ban, true, false, "ban a node from the cluster", "<bantime|0>"},
4765 { "unban", control_unban, true, false, "unban a node" },
4766 { "showban", control_showban, true, false, "show ban information"},
4767 { "shutdown", control_shutdown, true, false, "shutdown ctdbd" },
4768 { "recover", control_recover, true, false, "force recovery" },
4769 { "sync", control_ipreallocate, true, false, "wait until ctdbd has synced all state changes" },
4770 { "ipreallocate", control_ipreallocate, true, false, "force the recovery daemon to perform a ip reallocation procedure" },
4771 { "thaw", control_thaw, true, false, "thaw databases", "[priority:1-3]" },
4772 { "isnotrecmaster", control_isnotrecmaster, false, false, "check if the local node is recmaster or not" },
4773 { "killtcp", kill_tcp, false, false, "kill a tcp connection.", "<srcip:port> <dstip:port>" },
4774 { "gratiousarp", control_gratious_arp, false, false, "send a gratious arp", "<ip> <interface>" },
4775 { "tickle", tickle_tcp, false, false, "send a tcp tickle ack", "<srcip:port> <dstip:port>" },
4776 { "gettickles", control_get_tickles, false, false, "get the list of tickles registered for this ip", "<ip> [<port>]" },
4777 { "addtickle", control_add_tickle, false, false, "add a tickle for this ip", "<ip>:<port> <ip>:<port>" },
4779 { "deltickle", control_del_tickle, false, false, "delete a tickle from this ip", "<ip>:<port> <ip>:<port>" },
4781 { "regsrvid", regsrvid, false, false, "register a server id", "<pnn> <type> <id>" },
4782 { "unregsrvid", unregsrvid, false, false, "unregister a server id", "<pnn> <type> <id>" },
4783 { "chksrvid", chksrvid, false, false, "check if a server id exists", "<pnn> <type> <id>" },
4784 { "getsrvids", getsrvids, false, false, "get a list of all server ids"},
4785 { "vacuum", ctdb_vacuum, false, false, "vacuum the databases of empty records", "[max_records]"},
4786 { "repack", ctdb_repack, false, false, "repack all databases", "[max_freelist]"},
4787 { "listnodes", control_listnodes, false, true, "list all nodes in the cluster"},
4788 { "reloadnodes", control_reload_nodes_file, false, false, "reload the nodes file and restart the transport on all nodes"},
4789 { "moveip", control_moveip, false, false, "move/failover an ip address to another node", "<ip> <node>"},
4790 { "addip", control_addip, true, false, "add a ip address to a node", "<ip/mask> <iface>"},
4791 { "delip", control_delip, false, false, "delete an ip address from a node", "<ip>"},
4792 { "eventscript", control_eventscript, true, false, "run the eventscript with the given parameters on a node", "<arguments>"},
4793 { "backupdb", control_backupdb, false, false, "backup the database into a file.", "<database> <file>"},
4794 { "restoredb", control_restoredb, false, false, "restore the database from a file.", "<file> [dbname]"},
4795 { "dumpdbbackup", control_dumpdbbackup, false, true, "dump database backup from a file.", "<file>"},
4796 { "wipedb", control_wipedb, false, false, "wipe the contents of a database.", "<dbname>"},
4797 { "recmaster", control_recmaster, false, false, "show the pnn for the recovery master."},
4798 { "scriptstatus", control_scriptstatus, false, false, "show the status of the monitoring scripts (or all scripts)", "[all]"},
4799 { "enablescript", control_enablescript, false, false, "enable an eventscript", "<script>"},
4800 { "disablescript", control_disablescript, false, false, "disable an eventscript", "<script>"},
4801 { "natgwlist", control_natgwlist, false, false, "show the nodes belonging to this natgw configuration"},
4802 { "xpnn", control_xpnn, true, true, "find the pnn of the local node without talking to the daemon (unreliable)" },
4803 { "getreclock", control_getreclock, false, false, "Show the reclock file of a node"},
4804 { "setreclock", control_setreclock, false, false, "Set/clear the reclock file of a node", "[filename]"},
4805 { "setnatgwstate", control_setnatgwstate, false, false, "Set NATGW state to on/off", "{on|off}"},
4806 { "setlmasterrole", control_setlmasterrole, false, false, "Set LMASTER role to on/off", "{on|off}"},
4807 { "setrecmasterrole", control_setrecmasterrole, false, false, "Set RECMASTER role to on/off", "{on|off}"},
4808 { "setdbprio", control_setdbprio, false, false, "Set DB priority", "<dbid> <prio:1-3>"},
4809 { "getdbprio", control_getdbprio, false, false, "Get DB priority", "<dbid>"},
4810 { "msglisten", control_msglisten, false, false, "Listen on a srvid port for messages", "<msg srvid>"},
4811 { "msgsend", control_msgsend, false, false, "Send a message to srvid", "<srvid> <message>"},
4812 { "sync", control_ipreallocate, false, false, "wait until ctdbd has synced all state changes" },
4813 { "pfetch", control_pfetch, false, false, "fetch a record from a persistent database", "<db> <key> [<file>]" },
4814 { "pstore", control_pstore, false, false, "write a record to a persistent database", "<db> <key> <file containing record>" },
4815 { "tfetch", control_tfetch, false, true, "fetch a record from a [c]tdb-file", "<tdb-file> <key> [<file>]" },
4821 static void usage(void)
4825 "Usage: ctdb [options] <control>\n" \
4827 " -n <node> choose node number, or 'all' (defaults to local node)\n"
4828 " -Y generate machinereadable output\n"
4829 " -v generate verbose output\n"
4830 " -t <timelimit> set timelimit for control in seconds (default %u)\n", options.timelimit);
4831 printf("Controls:\n");
4832 for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {
4833 printf(" %-15s %-27s %s\n",
4834 ctdb_commands[i].name,
4835 ctdb_commands[i].args?ctdb_commands[i].args:"",
4836 ctdb_commands[i].msg);
4842 static void ctdb_alarm(int sig)
4844 printf("Maximum runtime exceeded - exiting\n");
4851 int main(int argc, const char *argv[])
4853 struct ctdb_context *ctdb;
4854 char *nodestring = NULL;
4855 struct poptOption popt_options[] = {
4858 { "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0, "timelimit", "integer" },
4859 { "node", 'n', POPT_ARG_STRING, &nodestring, 0, "node", "integer|all" },
4860 { "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machinereadable output", NULL },
4861 { "verbose", 'v', POPT_ARG_NONE, &options.verbose, 0, "enable verbose output", NULL },
4862 { "maxruntime", 'T', POPT_ARG_INT, &options.maxruntime, 0, "die if runtime exceeds this limit (in seconds)", "integer" },
4866 const char **extra_argv;
4870 struct event_context *ev;
4871 const char *control;
4875 /* set some defaults */
4876 options.maxruntime = 0;
4877 options.timelimit = 3;
4878 options.pnn = CTDB_CURRENT_NODE;
4880 pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
4882 while ((opt = poptGetNextOpt(pc)) != -1) {
4885 DEBUG(DEBUG_ERR, ("Invalid option %s: %s\n",
4886 poptBadOption(pc, 0), poptStrerror(opt)));
4891 /* setup the remaining options for the main program to use */
4892 extra_argv = poptGetArgs(pc);
4895 while (extra_argv[extra_argc]) extra_argc++;
4898 if (extra_argc < 1) {
4902 if (options.maxruntime == 0) {
4903 const char *ctdb_timeout;
4904 ctdb_timeout = getenv("CTDB_TIMEOUT");
4905 if (ctdb_timeout != NULL) {
4906 options.maxruntime = strtoul(ctdb_timeout, NULL, 0);
4908 /* default timeout is 120 seconds */
4909 options.maxruntime = 120;
4913 signal(SIGALRM, ctdb_alarm);
4914 alarm(options.maxruntime);
4916 /* setup the node number to contact */
4917 if (nodestring != NULL) {
4918 if (strcmp(nodestring, "all") == 0) {
4919 options.pnn = CTDB_BROADCAST_ALL;
4921 options.pnn = strtoul(nodestring, NULL, 0);
4925 control = extra_argv[0];
4927 ev = event_context_init(NULL);
4929 DEBUG(DEBUG_ERR, ("Failed to initialize event system\n"));
4932 tevent_loop_allow_nesting(ev);
4934 for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {
4935 if (strcmp(control, ctdb_commands[i].name) == 0) {
4938 if (ctdb_commands[i].without_daemon == true) {
4942 /* initialise ctdb */
4943 ctdb = ctdb_cmdline_client(ev);
4945 if (ctdb_commands[i].without_daemon == false) {
4946 const char *socket_name;
4949 DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));
4953 /* initialize a libctdb connection as well */
4954 socket_name = ctdb_get_socketname(ctdb);
4955 ctdb_connection = ctdb_connect(socket_name,
4956 ctdb_log_file, stderr);
4957 if (ctdb_connection == NULL) {
4958 fprintf(stderr, "Failed to connect to daemon from libctdb\n");
4962 /* verify the node exists */
4965 if (options.pnn == CTDB_CURRENT_NODE) {
4967 pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
4975 if (ctdb_commands[i].auto_all &&
4976 options.pnn == CTDB_BROADCAST_ALL) {
4981 nodes = ctdb_get_connected_nodes(ctdb, TIMELIMIT(), ctdb, &num_nodes);
4982 CTDB_NO_MEMORY(ctdb, nodes);
4984 for (j=0;j<num_nodes;j++) {
4985 options.pnn = nodes[j];
4986 ret |= ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);
4990 ret = ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);
4996 if (i == ARRAY_SIZE(ctdb_commands)) {
4997 DEBUG(DEBUG_ERR, ("Unknown control '%s'\n", control));