criterion given by the flags
*/
static void ctdb_takeover_find_node(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap,
- int start_node, uint32_t mask_flags)
+ int node, uint32_t mask_flags)
{
+ static int start_node=0;
int j;
- for (j=(start_node+1)%nodemap->num;
- j != start_node;
- j=(j+1)%nodemap->num) {
+
+ j=start_node;
+ while (1) {
if (!(nodemap->nodes[j].flags & mask_flags) &&
ctdb_same_subnet(ctdb->nodes[j]->public_address,
- ctdb->nodes[start_node]->public_address,
+ ctdb->nodes[node]->public_address,
ctdb->nodes[j]->public_netmask_bits)) {
- ctdb->nodes[start_node]->takeover_vnn = nodemap->nodes[j].vnn;
+ ctdb->nodes[node]->takeover_vnn = nodemap->nodes[j].vnn;
+ /* We found a node to take over
+ also update the startnode so that we start at a
+ different node next time we are called.
+ */
+ start_node = (j+1)%nodemap->num;;
+ return;
+ }
+
+ /* Try the next node */
+ j=(j+1)%nodemap->num;
+
+ /* We tried all the nodes and got back to where we started,
+ there is no node that can take over
+ */
+ if (j == start_node) {
break;
}
}
+
+ /* No takeover node found */
+ return;
}