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 "common/logging.h"
30 #include "lib/util/debug.h"
32 #include "protocol/protocol.h"
33 #include "protocol/protocol_api.h"
34 #include "client/client_private.h"
35 #include "client/client.h"
37 int list_of_nodes(struct ctdb_node_map
*nodemap
,
38 uint32_t flags_mask
, uint32_t exclude_pnn
,
39 TALLOC_CTX
*mem_ctx
, uint32_t **pnn_list
)
45 /* Allocate the list of same number of nodes */
46 list
= talloc_array(mem_ctx
, uint32_t, nodemap
->num
);
51 for (i
=0; i
<nodemap
->num
; i
++) {
52 if (nodemap
->node
[i
].flags
& flags_mask
) {
55 if (nodemap
->node
[i
].pnn
== exclude_pnn
) {
58 list
[num_nodes
] = nodemap
->node
[i
].pnn
;
66 int list_of_active_nodes(struct ctdb_node_map
*nodemap
, uint32_t exclude_pnn
,
67 TALLOC_CTX
*mem_ctx
, uint32_t **pnn_list
)
69 return list_of_nodes(nodemap
, NODE_FLAGS_INACTIVE
, exclude_pnn
,
73 int list_of_connected_nodes(struct ctdb_node_map
*nodemap
,
75 TALLOC_CTX
*mem_ctx
, uint32_t **pnn_list
)
77 return list_of_nodes(nodemap
, NODE_FLAGS_DISCONNECTED
, exclude_pnn
,
81 int ctdb_ctrl_modflags(TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
,
82 struct ctdb_client_context
*client
,
83 uint32_t destnode
, struct timeval timeout
,
84 uint32_t set
, uint32_t clear
)
86 struct ctdb_node_map
*nodemap
;
87 struct ctdb_node_flag_change flag_change
;
88 struct ctdb_req_control request
;
92 ret
= ctdb_ctrl_get_nodemap(mem_ctx
, ev
, client
, destnode
,
93 tevent_timeval_zero(), &nodemap
);
98 flag_change
.pnn
= destnode
;
99 flag_change
.old_flags
= nodemap
->node
[destnode
].flags
;
100 flag_change
.new_flags
= flag_change
.old_flags
| set
;
101 flag_change
.new_flags
&= ~clear
;
103 count
= list_of_connected_nodes(nodemap
, -1, mem_ctx
, &pnn_list
);
108 ctdb_req_control_modify_flags(&request
, &flag_change
);
109 ret
= ctdb_client_control_multi(mem_ctx
, ev
, client
, pnn_list
, count
,
110 tevent_timeval_zero(), &request
,
115 struct ctdb_server_id
ctdb_client_get_server_id(
116 struct ctdb_client_context
*client
,
119 struct ctdb_server_id sid
;
122 sid
.task_id
= task_id
;
123 sid
.vnn
= ctdb_client_pnn(client
);
124 sid
.unique_id
= task_id
;
125 sid
.unique_id
= (sid
.unique_id
<< 32) | sid
.pid
;
130 bool ctdb_server_id_equal(struct ctdb_server_id
*sid1
,
131 struct ctdb_server_id
*sid2
)
133 if (sid1
->pid
!= sid2
->pid
) {
136 if (sid1
->task_id
!= sid2
->task_id
) {
139 if (sid1
->vnn
!= sid2
->vnn
) {
142 if (sid1
->unique_id
!= sid2
->unique_id
) {
149 int ctdb_server_id_exists(TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
,
150 struct ctdb_client_context
*client
,
151 struct ctdb_server_id
*sid
, bool *exists
)
156 ret
= ctdb_ctrl_check_srvids(mem_ctx
, ev
, client
, sid
->vnn
,
157 tevent_timeval_zero(),
158 &sid
->unique_id
, 1, &result
);
163 if (result
[0] == 1) {