[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Tue Oct 10 14:18:02 UTC 2023


The branch, master has been updated
       via  a6b66661c75 ctdb: Add "home_nodes" file to deterministic IP allocation
       via  ea9cbbd8309 ctdb: setup $CTDB_BASE for deterministic ip alloc tests
       via  23ccb1c0ca5 ctdb: Align variable signedness
       via  ce3243d7b20 ctdb: Reduce indentation in get_tunable_values()
       via  58ec800928b ctdb: Fix whitespace
      from  633a3ee6894 s3: smbd: Ignore fstat() error on deleted stream in fd_close().

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a6b66661c754f8ecf7c6c8a43ff015257adf5d0a
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 4 14:47:51 2023 +0200

    ctdb: Add "home_nodes" file to deterministic IP allocation
    
    With a file "home_nodes" next to "public_addresses" you can assign
    public IPs to specific nodes when using the deterministic allocation
    algorithm. Whenever the "home node" is up, the IP address will be
    assigned to that node, independent of any other deterministic
    calculation. The line
    
    192.168.21.254 2
    
    in the file "home_nodes" assigns the IP address to node 2. Only when
    node 2 is not able to host IP addresses, 192.168.21.254 undergoes the
    normal deterministic IP allocation algorithm.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    
    add home_nodes
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Tue Oct 10 14:17:19 UTC 2023 on atb-devel-224

commit ea9cbbd8309fd8514e4a9a4aa80749e8adfff0bc
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Oct 5 17:11:51 2023 +0200

    ctdb: setup $CTDB_BASE for deterministic ip alloc tests
    
    ipalloc_deterministic() will require it in the next patch
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 23ccb1c0ca53f2e46238eece186ac7726af9b96d
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 4 15:35:46 2023 +0200

    ctdb: Align variable signedness
    
    ipalloc_state->num_nodes is uint32_t
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit ce3243d7b2095970d00e5c59c880ebf81f2bf9ed
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 28 15:55:36 2023 +0200

    ctdb: Reduce indentation in get_tunable_values()
    
    Use an early return tvals; review with "git sh -b".
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 58ec800928bdda2f1260ee24eeca8a0018931a68
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 28 15:50:28 2023 +0200

    ctdb: Fix whitespace
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/doc/ctdb-tunables.7.xml                       |  11 ++
 ctdb/server/ipalloc_deterministic.c                | 130 ++++++++++++++++++++-
 ctdb/tests/UNIT/takeover/det.001.sh                |   2 +
 ctdb/tests/UNIT/takeover/det.002.sh                |   2 +
 ctdb/tests/UNIT/takeover/det.003.sh                |   2 +
 .../tests/UNIT/takeover/{det.003.sh => det.004.sh} |  17 ++-
 .../tests/UNIT/takeover/{det.002.sh => det.005.sh} |  18 ++-
 .../tests/UNIT/takeover/{det.001.sh => det.006.sh} |  16 ++-
 ctdb/tests/src/ctdb_takeover_tests.c               |  45 +++----
 9 files changed, 212 insertions(+), 31 deletions(-)
 copy ctdb/tests/UNIT/takeover/{det.003.sh => det.004.sh} (63%)
 copy ctdb/tests/UNIT/takeover/{det.002.sh => det.005.sh} (66%)
 copy ctdb/tests/UNIT/takeover/{det.001.sh => det.006.sh} (71%)


Changeset truncated at 500 lines:

diff --git a/ctdb/doc/ctdb-tunables.7.xml b/ctdb/doc/ctdb-tunables.7.xml
index 725c781e47e..e4f7ce0b96a 100644
--- a/ctdb/doc/ctdb-tunables.7.xml
+++ b/ctdb/doc/ctdb-tunables.7.xml
@@ -283,6 +283,17 @@ MonitorInterval=20
 	      with care when addresses are defined across multiple
 	      networks.
 	    </para>
+	    <para>
+	      You can override automatic the "home" node allocation by
+	      creating a file "home_nodes" next to the
+	      "public_addresses" file. As an example the following
+	      "home_nodes" file assigns the address 192.168.1.1 to
+	      node 0 and 192.168.1.2 to node 2:
+	    </para>
+	    <screen format="linespecific">
+	      192.168.1.1 0
+	      192.168.1.2 2
+            </screen>
 	  </listitem>
 	</varlistentry>
 	<varlistentry>
diff --git a/ctdb/server/ipalloc_deterministic.c b/ctdb/server/ipalloc_deterministic.c
index 097d8169da8..43680ba5c2f 100644
--- a/ctdb/server/ipalloc_deterministic.c
+++ b/ctdb/server/ipalloc_deterministic.c
@@ -24,13 +24,120 @@
 
 #include "lib/util/debug.h"
 #include "common/logging.h"
+#include "common/path.h"
+
+#include "protocol/protocol_util.h"
+#include "lib/util/smb_strtox.h"
+#include "lib/util/memory.h"
 
 #include "server/ipalloc_private.h"
 
+struct home_node {
+	ctdb_sock_addr addr;
+	uint32_t pnn;
+};
+
+static struct home_node *ipalloc_get_home_nodes(TALLOC_CTX *mem_ctx)
+{
+	char *line = NULL;
+	size_t len = 0;
+	char *fname = NULL;
+	FILE *fp = NULL;
+	struct home_node *result = NULL;
+
+	fname = path_etcdir_append(mem_ctx, "home_nodes");
+	if (fname == NULL) {
+		goto fail;
+	}
+
+	fp = fopen(fname, "r");
+	if (fp == NULL) {
+		goto fail;
+	}
+	TALLOC_FREE(fname);
+
+	while (true) {
+		size_t num_nodes = talloc_array_length(result);
+		char *saveptr = NULL, *addrstr = NULL, *nodestr = NULL;
+		struct home_node hn = {
+			.pnn = CTDB_UNKNOWN_PNN,
+		};
+		struct home_node *tmp = NULL;
+		ssize_t n = 0;
+		int ret;
+
+		n = getline(&line, &len, fp);
+		if (n < 0) {
+			if (!feof(fp)) {
+				/* real error */
+				goto fail;
+			}
+			break;
+		}
+		if ((n > 0) && (line[n - 1] == '\n')) {
+			line[n - 1] = '\0';
+		}
+
+		addrstr = strtok_r(line, " \t", &saveptr);
+		if (addrstr == NULL) {
+			continue;
+		}
+		nodestr = strtok_r(NULL, " \t", &saveptr);
+		if (nodestr == NULL) {
+			continue;
+		}
+
+		ret = ctdb_sock_addr_from_string(addrstr, &hn.addr, false);
+		if (ret != 0) {
+			DBG_WARNING("Could not parse %s: %s\n",
+				    addrstr,
+				    strerror(ret));
+			goto fail;
+		}
+
+		hn.pnn = smb_strtoul(nodestr,
+				     NULL,
+				     10,
+				     &ret,
+				     SMB_STR_FULL_STR_CONV);
+		if (ret != 0) {
+			DBG_WARNING("Could not parse \"%s\"\n", nodestr);
+			goto fail;
+		}
+
+		tmp = talloc_realloc(mem_ctx,
+				     result,
+				     struct home_node,
+				     num_nodes + 1);
+		if (tmp == NULL) {
+			goto fail;
+		}
+		result = tmp;
+		result[num_nodes] = hn;
+	}
+
+	fclose(fp);
+	fp = NULL;
+	return result;
+
+fail:
+	if (fp != NULL) {
+		fclose(fp);
+		fp = NULL;
+	}
+	SAFE_FREE(line);
+	TALLOC_FREE(fname);
+	TALLOC_FREE(result);
+	return NULL;
+}
+
 bool ipalloc_deterministic(struct ipalloc_state *ipalloc_state)
 {
+	struct home_node *home_nodes = ipalloc_get_home_nodes(ipalloc_state);
+	size_t num_home_nodes = talloc_array_length(home_nodes);
 	struct public_ip_list *t;
-	int i, numnodes;
+	int i;
+	uint32_t numnodes;
 
 	numnodes = ipalloc_state->num;
 
@@ -41,7 +148,26 @@ bool ipalloc_deterministic(struct ipalloc_state *ipalloc_state)
 	*/
 
 	for (i = 0, t = ipalloc_state->all_ips; t!= NULL; t = t->next, i++) {
+		size_t j;
+
 		t->pnn = i % numnodes;
+
+		for (j = 0; j < num_home_nodes; j++) {
+			struct home_node *hn = &home_nodes[j];
+
+			if (ctdb_sock_addr_same_ip(&t->addr, &hn->addr)) {
+
+				if (hn->pnn >= numnodes) {
+					DBG_WARNING("pnn %" PRIu32
+						    " too large\n",
+						    hn->pnn);
+					break;
+				}
+
+				t->pnn = hn->pnn;
+				break;
+			}
+		}
 	}
 
 	/* IP failback doesn't make sense with deterministic
@@ -59,5 +185,7 @@ bool ipalloc_deterministic(struct ipalloc_state *ipalloc_state)
 
 	/* No failback here! */
 
+	TALLOC_FREE(home_nodes);
+
 	return true;
 }
diff --git a/ctdb/tests/UNIT/takeover/det.001.sh b/ctdb/tests/UNIT/takeover/det.001.sh
index ead8f211b0d..ad50287e782 100755
--- a/ctdb/tests/UNIT/takeover/det.001.sh
+++ b/ctdb/tests/UNIT/takeover/det.001.sh
@@ -2,6 +2,8 @@
 
 . "${TEST_SCRIPTS_DIR}/unit.sh"
 
+setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc"
+
 define_test "3 nodes, 1 healthy"
 
 required_result <<EOF
diff --git a/ctdb/tests/UNIT/takeover/det.002.sh b/ctdb/tests/UNIT/takeover/det.002.sh
index c411d144497..b54edea69a8 100755
--- a/ctdb/tests/UNIT/takeover/det.002.sh
+++ b/ctdb/tests/UNIT/takeover/det.002.sh
@@ -2,6 +2,8 @@
 
 . "${TEST_SCRIPTS_DIR}/unit.sh"
 
+setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc"
+
 define_test "3 nodes, 2 healthy"
 
 required_result <<EOF
diff --git a/ctdb/tests/UNIT/takeover/det.003.sh b/ctdb/tests/UNIT/takeover/det.003.sh
index b40e2183b94..931c498bfa4 100755
--- a/ctdb/tests/UNIT/takeover/det.003.sh
+++ b/ctdb/tests/UNIT/takeover/det.003.sh
@@ -2,6 +2,8 @@
 
 . "${TEST_SCRIPTS_DIR}/unit.sh"
 
+setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc"
+
 define_test "3 nodes, 1 -> all healthy"
 
 required_result <<EOF
diff --git a/ctdb/tests/UNIT/takeover/det.003.sh b/ctdb/tests/UNIT/takeover/det.004.sh
similarity index 63%
copy from ctdb/tests/UNIT/takeover/det.003.sh
copy to ctdb/tests/UNIT/takeover/det.004.sh
index b40e2183b94..3673cc17590 100755
--- a/ctdb/tests/UNIT/takeover/det.003.sh
+++ b/ctdb/tests/UNIT/takeover/det.004.sh
@@ -2,17 +2,26 @@
 
 . "${TEST_SCRIPTS_DIR}/unit.sh"
 
-define_test "3 nodes, 1 -> all healthy"
+setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc"
+
+define_test "3 nodes, all healthy with home_nodes"
+
+home_nodes="$CTDB_BASE"/home_nodes
+
+cat > "$home_nodes" <<EOF
+192.168.21.254 2
+192.168.20.251 1
+EOF
 
 required_result <<EOF
 ${TEST_DATE_STAMP}Deterministic IPs enabled. Resetting all ip allocations
-192.168.21.254 0
+192.168.21.254 2
 192.168.21.253 1
 192.168.21.252 2
 192.168.20.254 0
 192.168.20.253 1
 192.168.20.252 2
-192.168.20.251 0
+192.168.20.251 1
 192.168.20.250 1
 192.168.20.249 2
 EOF
@@ -28,3 +37,5 @@ simple_test 0,0,0 <<EOF
 192.168.21.253 1
 192.168.21.254 1
 EOF
+
+rm "$home_nodes"
diff --git a/ctdb/tests/UNIT/takeover/det.002.sh b/ctdb/tests/UNIT/takeover/det.005.sh
similarity index 66%
copy from ctdb/tests/UNIT/takeover/det.002.sh
copy to ctdb/tests/UNIT/takeover/det.005.sh
index c411d144497..aaa5e0fe2aa 100755
--- a/ctdb/tests/UNIT/takeover/det.002.sh
+++ b/ctdb/tests/UNIT/takeover/det.005.sh
@@ -2,18 +2,28 @@
 
 . "${TEST_SCRIPTS_DIR}/unit.sh"
 
-define_test "3 nodes, 2 healthy"
+setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc"
+
+define_test "3 nodes, 2 healthy with home_nodes"
+
+home_nodes="$CTDB_BASE"/home_nodes
+
+cat > "$home_nodes" <<EOF
+192.168.21.254 2
+192.168.20.251 1
+EOF
 
 required_result <<EOF
 ${TEST_DATE_STAMP}Deterministic IPs enabled. Resetting all ip allocations
 ${TEST_DATE_STAMP}Unassign IP: 192.168.21.253 from 1
 ${TEST_DATE_STAMP}Unassign IP: 192.168.20.253 from 1
+${TEST_DATE_STAMP}Unassign IP: 192.168.20.251 from 1
 ${TEST_DATE_STAMP}Unassign IP: 192.168.20.250 from 1
-192.168.21.254 0
+192.168.21.254 2
 192.168.21.253 0
 192.168.21.252 2
 192.168.20.254 0
-192.168.20.253 2
+192.168.20.253 0
 192.168.20.252 2
 192.168.20.251 0
 192.168.20.250 0
@@ -31,3 +41,5 @@ simple_test 0,2,0 <<EOF
 192.168.21.253 1
 192.168.21.254 2
 EOF
+
+rm "$home_nodes"
diff --git a/ctdb/tests/UNIT/takeover/det.001.sh b/ctdb/tests/UNIT/takeover/det.006.sh
similarity index 71%
copy from ctdb/tests/UNIT/takeover/det.001.sh
copy to ctdb/tests/UNIT/takeover/det.006.sh
index ead8f211b0d..504c43018a1 100755
--- a/ctdb/tests/UNIT/takeover/det.001.sh
+++ b/ctdb/tests/UNIT/takeover/det.006.sh
@@ -2,15 +2,23 @@
 
 . "${TEST_SCRIPTS_DIR}/unit.sh"
 
-define_test "3 nodes, 1 healthy"
+setup_ctdb_base "$CTDB_TEST_TMP_DIR" "ctdb-etc"
+
+define_test "3 nodes, 1 healthy with home_nodes"
+
+home_nodes="$CTDB_BASE"/home_nodes
+
+cat > "$home_nodes" <<EOF
+192.168.21.254 2
+192.168.20.251 1
+EOF
 
 required_result <<EOF
 ${TEST_DATE_STAMP}Deterministic IPs enabled. Resetting all ip allocations
-${TEST_DATE_STAMP}Unassign IP: 192.168.21.254 from 0
 ${TEST_DATE_STAMP}Unassign IP: 192.168.21.253 from 1
 ${TEST_DATE_STAMP}Unassign IP: 192.168.20.254 from 0
 ${TEST_DATE_STAMP}Unassign IP: 192.168.20.253 from 1
-${TEST_DATE_STAMP}Unassign IP: 192.168.20.251 from 0
+${TEST_DATE_STAMP}Unassign IP: 192.168.20.251 from 1
 ${TEST_DATE_STAMP}Unassign IP: 192.168.20.250 from 1
 192.168.21.254 2
 192.168.21.253 2
@@ -34,3 +42,5 @@ simple_test 2,2,0 <<EOF
 192.168.21.253 1
 192.168.21.254 2
 EOF
+
+rm "$home_nodes"
diff --git a/ctdb/tests/src/ctdb_takeover_tests.c b/ctdb/tests/src/ctdb_takeover_tests.c
index cc6b4416dd9..ad7d7ee9e50 100644
--- a/ctdb/tests/src/ctdb_takeover_tests.c
+++ b/ctdb/tests/src/ctdb_takeover_tests.c
@@ -1,4 +1,4 @@
-/* 
+/*
    Tests for ctdb_takeover.c
 
    Copyright (C) Martin Schwenke 2011
@@ -7,12 +7,12 @@
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
@@ -84,24 +84,27 @@ static uint32_t *get_tunable_values(TALLOC_CTX *tmp_ctx,
 	uint32_t *tvals = talloc_zero_array(tmp_ctx, uint32_t, numnodes);
 	char *t = getenv(tunable);
 
-	if (t) {
-		if (strcmp(t, "1") == 0) {
-			for (i=0; i<numnodes; i++) {
-				tvals[i] = 1;
-			}
-		} else {
-			tok = strtok(t, ",");
-			i = 0;
-			while (tok != NULL) {
-				tvals[i] =
-					(uint32_t) strtol(tok, NULL, 0);
-				i++;
-				tok = strtok(NULL, ",");
-			}
-			if (i != numnodes) {
-				fprintf(stderr, "ERROR: Wrong number of values in %s\n", tunable);
-				exit(1);
-			}
+	if (t == NULL) {
+		return tvals;
+	}
+
+	if (strcmp(t, "1") == 0) {
+		for (i = 0; i < numnodes; i++) {
+			tvals[i] = 1;
+		}
+	} else {
+		tok = strtok(t, ",");
+		i = 0;
+		while (tok != NULL) {
+			tvals[i] = (uint32_t)strtol(tok, NULL, 0);
+			i++;
+			tok = strtok(NULL, ",");
+		}
+		if (i != numnodes) {
+			fprintf(stderr,
+				"ERROR: Wrong number of values in %s\n",
+				tunable);
+			exit(1);
 		}
 	}
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list