4 Copyright (C) Amitay Isaacs 2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "system/network.h"
22 #include "system/filesys.h"
28 #include "lib/util/debug.h"
29 #include "ctdb_logging.h"
31 #include "protocol/protocol.h"
32 #include "protocol/protocol_api.h"
33 #include "client/client_private.h"
34 #include "client/client.h"
36 int list_of_nodes(struct ctdb_node_map *nodemap,
37 uint32_t flags_mask, uint32_t exclude_pnn,
38 TALLOC_CTX *mem_ctx, uint32_t **pnn_list)
44 /* Allocate the list of same number of nodes */
45 list = talloc_array(mem_ctx, uint32_t, nodemap->num);
50 for (i=0; i<nodemap->num; i++) {
51 if (nodemap->node[i].flags & flags_mask) {
54 if (nodemap->node[i].pnn == exclude_pnn) {
57 list[num_nodes] = nodemap->node[i].pnn;
65 int list_of_active_nodes(struct ctdb_node_map *nodemap, uint32_t exclude_pnn,
66 TALLOC_CTX *mem_ctx, uint32_t **pnn_list)
68 return list_of_nodes(nodemap, NODE_FLAGS_INACTIVE, exclude_pnn,
72 int list_of_connected_nodes(struct ctdb_node_map *nodemap,
74 TALLOC_CTX *mem_ctx, uint32_t **pnn_list)
76 return list_of_nodes(nodemap, NODE_FLAGS_DISCONNECTED, exclude_pnn,
80 int ctdb_ctrl_modflags(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
81 struct ctdb_client_context *client,
82 uint32_t destnode, struct timeval timeout,
83 uint32_t set, uint32_t clear)
85 struct ctdb_node_map *nodemap;
86 struct ctdb_node_flag_change flag_change;
87 struct ctdb_req_control request;
91 ret = ctdb_ctrl_get_nodemap(mem_ctx, ev, client, destnode,
92 tevent_timeval_zero(), &nodemap);
97 flag_change.pnn = destnode;
98 flag_change.old_flags = nodemap->node[destnode].flags;
99 flag_change.new_flags = flag_change.old_flags | set;
100 flag_change.new_flags &= ~clear;
102 count = list_of_connected_nodes(nodemap, -1, mem_ctx, &pnn_list);
107 ctdb_req_control_modify_flags(&request, &flag_change);
108 ret = ctdb_client_control_multi(mem_ctx, ev, client, pnn_list, count,
109 tevent_timeval_zero(), &request,
114 bool ctdb_server_id_equal(struct ctdb_server_id *sid1,
115 struct ctdb_server_id *sid2)
117 if (sid1->pid != sid2->pid) {
120 if (sid1->task_id != sid2->task_id) {
123 if (sid1->vnn != sid2->vnn) {
126 if (sid1->unique_id != sid2->unique_id) {
133 int ctdb_server_id_exists(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
134 struct ctdb_client_context *client,
135 struct ctdb_server_id *sid, bool *exists)
140 ret = ctdb_ctrl_check_srvids(mem_ctx, ev, client, sid->vnn,
141 tevent_timeval_zero(),
142 &sid->unique_id, 1, &result);
147 if (result[0] == 1) {