Combine ICU libraries icu-i18n and icu-uc into a single dependency
[samba.git] / ctdb / client / client_util.c
blob35323ff9eac34a3616c599e885f1777a565e7621
1 /*
2 CTDB client code
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/>.
20 #include "replace.h"
21 #include "system/network.h"
22 #include "system/filesys.h"
24 #include <talloc.h>
25 #include <tevent.h>
26 #include <tdb.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"
36 #include "client/client_sync.h"
38 int list_of_nodes(struct ctdb_node_map *nodemap,
39 uint32_t flags_mask, uint32_t exclude_pnn,
40 TALLOC_CTX *mem_ctx, uint32_t **pnn_list)
42 int num_nodes = 0;
43 uint32_t *list;
44 unsigned int i;
46 /* Allocate the list of same number of nodes */
47 list = talloc_array(mem_ctx, uint32_t, nodemap->num);
48 if (list == NULL) {
49 return -1;
52 for (i=0; i<nodemap->num; i++) {
53 if (nodemap->node[i].flags & flags_mask) {
54 continue;
56 if (nodemap->node[i].pnn == exclude_pnn) {
57 continue;
59 list[num_nodes] = nodemap->node[i].pnn;
60 num_nodes++;
63 *pnn_list = list;
64 return num_nodes;
67 int list_of_active_nodes(struct ctdb_node_map *nodemap, uint32_t exclude_pnn,
68 TALLOC_CTX *mem_ctx, uint32_t **pnn_list)
70 return list_of_nodes(nodemap, NODE_FLAGS_INACTIVE, exclude_pnn,
71 mem_ctx, pnn_list);
74 int list_of_connected_nodes(struct ctdb_node_map *nodemap,
75 uint32_t exclude_pnn,
76 TALLOC_CTX *mem_ctx, uint32_t **pnn_list)
78 return list_of_nodes(nodemap, NODE_FLAGS_DISCONNECTED, exclude_pnn,
79 mem_ctx, pnn_list);
82 struct ctdb_server_id ctdb_client_get_server_id(
83 struct ctdb_client_context *client,
84 uint32_t task_id)
86 struct ctdb_server_id sid;
88 sid.pid = getpid();
89 sid.task_id = task_id;
90 sid.vnn = ctdb_client_pnn(client);
91 sid.unique_id = task_id;
92 sid.unique_id = (sid.unique_id << 32) | sid.pid;
94 return sid;
97 bool ctdb_server_id_equal(struct ctdb_server_id *sid1,
98 struct ctdb_server_id *sid2)
100 if (sid1->pid != sid2->pid) {
101 return false;
103 if (sid1->task_id != sid2->task_id) {
104 return false;
106 if (sid1->vnn != sid2->vnn) {
107 return false;
109 if (sid1->unique_id != sid2->unique_id) {
110 return false;
113 return true;
116 int ctdb_server_id_exists(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
117 struct ctdb_client_context *client,
118 struct ctdb_server_id *sid, bool *exists)
120 int result;
121 int ret;
123 ret = ctdb_ctrl_process_exists(mem_ctx, ev, client, sid->vnn,
124 tevent_timeval_zero(),
125 sid->pid, &result);
126 if (ret != 0) {
127 return ret;
130 if (result == 1) {
131 *exists = true;
132 } else {
133 *exists = false;
136 return 0;