ldb: Release ldb 1.3.0
[Samba.git] / ctdb / server / ipalloc_deterministic.c
blob097d8169da8277b03e63833a43437bb9146b0b8a
1 /*
2 ctdb ip takeover code
4 Copyright (C) Ronnie Sahlberg 2007
5 Copyright (C) Andrew Tridgell 2007
6 Copyright (C) Martin Schwenke 2011
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "replace.h"
23 #include "system/network.h"
25 #include "lib/util/debug.h"
26 #include "common/logging.h"
28 #include "server/ipalloc_private.h"
30 bool ipalloc_deterministic(struct ipalloc_state *ipalloc_state)
32 struct public_ip_list *t;
33 int i, numnodes;
35 numnodes = ipalloc_state->num;
37 DEBUG(DEBUG_NOTICE,("Deterministic IPs enabled. Resetting all ip allocations\n"));
38 /* Allocate IPs to nodes in a modulo fashion so that IPs will
39 * always be allocated the same way for a specific set of
40 * available/unavailable nodes.
43 for (i = 0, t = ipalloc_state->all_ips; t!= NULL; t = t->next, i++) {
44 t->pnn = i % numnodes;
47 /* IP failback doesn't make sense with deterministic
48 * IPs, since the modulo step above implicitly fails
49 * back IPs to their "home" node.
51 if (ipalloc_state->no_ip_failback) {
52 D_WARNING("WARNING: 'NoIPFailback' set but ignored - "
53 "incompatible with 'Deterministic IPs\n");
56 unassign_unsuitable_ips(ipalloc_state);
58 basic_allocate_unassigned(ipalloc_state);
60 /* No failback here! */
62 return true;