[SCM] CTDB repository - branch 1.13 updated - ctdb-1.13-66-g41ee3cb
Ronnie Sahlberg
sahlberg at samba.org
Wed Mar 21 22:54:35 MDT 2012
The branch, 1.13 has been updated
via 41ee3cb65b63605ab968cf1eef05a75256d4db6c (commit)
via f6d4cf009d63605f8c1246c59c53b1f82989d2a1 (commit)
via 7d7488a49bc7e799f39f3da3fa81be7a2e14480a (commit)
via da2e9650a97f99e7d694659926d9958927edd8ad (commit)
via 0142729c96b8bfecfabe35439071557bcc6ed4da (commit)
via 1db9a533aacc6e02ddbadf76241429144a949e1c (commit)
via 299ce89fb3deeefcc7c01b20197dc6adee1e8194 (commit)
via 79eec235ac9b051333751186c32924d92e6ebeff (commit)
via 0fc20ab5207d4f812bf62b90a66c707f76742f84 (commit)
via 9c30bf7fd3d94884e27a258571a28dca5e460177 (commit)
via 6d4b4b1293ba960d8fdf81958d6e8dd23c9d771a (commit)
via 38396185effbcf313678c2e94d4bd20f534c4f03 (commit)
via d132a8f4a8c0573ac447713a71911f02b6f0d73c (commit)
via 236d572556e447e2d82d14d2c8a40ed8cb98944d (commit)
via 351ca413eec460330571ca8b01ad269728fe15df (commit)
via d4621277240721e6d130a930b0100506b64467ea (commit)
via bdb4cdaf2aed79c8de6a8db8c01685b242808310 (commit)
via d034845ecea66b47004bc73f2554914a397b1c9d (commit)
via ac2cd2a8cbed97348ceae54167ad83cb074ff6b3 (commit)
via 26292f362890ca6cb65d0028d50fa97458e0449f (commit)
via 8b8e17bea87a8c16f7c0f54fcfe29190f203f673 (commit)
via f4949b3c1b36949544e98c9fbb64447f94f9e432 (commit)
via 994492f79275fe84155d842f6bc288c1858217dd (commit)
via 93f90caf91246074d9359bf31a39b26212cccc42 (commit)
via 2a2ea6c61a05af2d0765e964abcc7ef04047431e (commit)
via 45c3476d12bf0f52966b72d286f101fce1382cd2 (commit)
via 0f7cbbb55f26cf3c953e98fe5e7eaa12f59fbf78 (commit)
via 97b0c138cb97e30db27c40b4ee1481109ae90c78 (commit)
via 270edc87e6bcfd6e76c526bf86df865e4d47d11c (commit)
via 35592e618cfd827b6978af6332f80504f232c46a (commit)
via c262c29773d1608e7ce04bdfb7f4469df0a9637b (commit)
via 668f3e88a9e5f598706952b7140547640c85a5ed (commit)
via 0ae2a46e37df8d84ce0c76b7a5d32d6e93af709b (commit)
via e6a8306257dece02313043274789b52cef1a5647 (commit)
via d0d98f7e45e5084b81335b004d50bddc80cdc219 (commit)
via cf96d6380de974c1abff7a33c62a7e31ac980551 (commit)
via 035c0d981bde8c0eee8b3f24ba8e2dc817e5b504 (commit)
via 1c976d83b1d7dac6f0ef81306774998e4c8b56a1 (commit)
via 05923a14bc8ae8e3c5cda28ff4e0fb0d473d5f7d (commit)
via c37aa6f3738693653f64c2fa015ace061da38b5a (commit)
via eafd7bbaaa5931546a96c8beae3cf9a39a49c925 (commit)
via 7d3931298e6477d92f43652c3006b0c426cb1307 (commit)
via af72f8bc05f78983f9624d81788f9d89af474b11 (commit)
via f06634951331232cddf0b48eac3552b92aca5b93 (commit)
via 68390cb1e8c7f30be034b8ca6c9215b40147305b (commit)
via fb00e1290fcea3386132a46c883994019a43799a (commit)
via a7ad2fb75f06791508dd928d2a0c305fc7f7b814 (commit)
via db69a39ca010b2c8853b13466e30792dda350cdb (commit)
via a0340a50c2acd9ccc281faef032a364254f7f95a (commit)
from 1d69f897ce525a9d8967a365718143a3a4dcf9a8 (commit)
http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=1.13
- Log -----------------------------------------------------------------
commit 41ee3cb65b63605ab968cf1eef05a75256d4db6c
Merge: f6d4cf009d63605f8c1246c59c53b1f82989d2a1 7d7488a49bc7e799f39f3da3fa81be7a2e14480a
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Thu Mar 22 15:40:55 2012 +1100
Merge remote branch 'martins/policy_routing' into 1.13
commit f6d4cf009d63605f8c1246c59c53b1f82989d2a1
Author: Martin Schwenke <martin at meltin.net>
Date: Thu Mar 22 15:27:25 2012 +1100
Undo damage done by d8d37493478a26c5f1809a5f3df89ffd6e149281
The implementation of DisableIPFailover got intermingled with
--nopublicipcheck. This just looks wrong - Ronnie must have been
having a bad day. :-)
Signed-off-by: Martin Schwenke <martin at meltin.net>
-----------------------------------------------------------------------
Summary of changes:
.gitignore | 2 +
Makefile.in | 6 +-
config/README | 6 -
config/events.d/13.per_ip_routing | 662 ++++++++------------
config/functions | 197 +++----
config/interface_modify.sh | 142 -----
include/ctdb_private.h | 1 +
packaging/RPM/ctdb.spec.in | 1 -
server/ctdb_recoverd.c | 2 +-
server/ctdbd.c | 4 +-
tests/eventscripts/common.sh | 188 ++++--
tests/eventscripts/etc-ctdb/public_addresses | 5 +
.../multievent/13.per_ip_routing.001.sh | 16 +
.../multievent/13.per_ip_routing.002.sh | 14 +
.../multievent/13.per_ip_routing.003.sh | 24 +
.../multievent/13.per_ip_routing.004.sh | 25 +
.../multievent/13.per_ip_routing.005.sh | 38 ++
.../multievent/13.per_ip_routing.006.sh | 38 ++
.../multievent/13.per_ip_routing.007.sh | 40 ++
.../multievent/13.per_ip_routing.008.sh | 42 ++
.../multievent/13.per_ip_routing.009.sh | 44 ++
.../multievent/13.per_ip_routing.010.sh | 52 ++
.../multievent/13.per_ip_routing.011.sh | 41 ++
.../multievent/13.per_ip_routing.012.sh | 48 ++
tests/eventscripts/run_tests.sh | 13 +
.../simple/10.interface.monitor.015.sh | 2 +-
.../eventscripts/simple/10.interface.takeip.003.sh | 6 +-
tests/eventscripts/stubs/ctdb | 208 +++++--
tests/eventscripts/stubs/ip | 598 +++++++++++++-----
tests/scripts/ctdb_test_env | 2 +
tests/scripts/ctdb_test_functions.bash | 8 +-
tests/simple/09_ctdb_ping.sh | 2 +-
..._ctdb_config_check_error_on_unreachable_ctdb.sh | 6 +-
tests/simple/72_update_record_persistent.sh | 89 +++
...only_loop.c => ctdb_update_record_persistent.c} | 91 ++--
tools/ctdb.c | 2 +-
36 files changed, 1658 insertions(+), 1007 deletions(-)
delete mode 100755 config/interface_modify.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.001.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.002.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.003.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.004.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.005.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.006.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.007.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.008.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.009.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.010.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.011.sh
create mode 100755 tests/eventscripts/multievent/13.per_ip_routing.012.sh
create mode 100755 tests/simple/72_update_record_persistent.sh
copy tests/src/{ctdb_fetch_readonly_loop.c => ctdb_update_record_persistent.c} (57%)
Changeset truncated at 500 lines:
diff --git a/.gitignore b/.gitignore
index ef8ae6a..77ffc3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,5 @@ tests/events.d/00.ctdb_test_trigger
tests/var
tests/takeover/ctdb_takeover.pyc
tests/eventscripts/var
+tests/eventscripts/etc/iproute2
+tests/eventscripts/etc-ctdb/policy_routing
diff --git a/Makefile.in b/Makefile.in
index 24283f3..90d7b08 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -85,6 +85,7 @@ TEST_BINS=tests/bin/ctdb_bench tests/bin/ctdb_fetch tests/bin/ctdb_fetch_one \
tests/bin/ctdb_randrec tests/bin/ctdb_persistent \
tests/bin/ctdb_traverse tests/bin/rb_test tests/bin/ctdb_transaction \
tests/bin/ctdb_takeover_tests tests/bin/ctdb_update_record \
+ tests/bin/ctdb_update_record_persistent \
tests/bin/ctdb_tool_libctdb tests/bin/ctdb_tool_stubby \
@INFINIBAND_BINS@
@@ -215,6 +216,10 @@ tests/bin/ctdb_update_record: $(CTDB_CLIENT_OBJ) tests/src/ctdb_update_record.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_update_record.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
+tests/bin/ctdb_update_record_persistent: $(CTDB_CLIENT_OBJ) tests/src/ctdb_update_record_persistent.o
+ @echo Linking $@
+ @$(CC) $(CFLAGS) -o $@ tests/src/ctdb_update_record_persistent.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
+
tests/bin/ctdb_store: $(CTDB_CLIENT_OBJ) tests/src/ctdb_store.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_store.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
@@ -310,7 +315,6 @@ install: all $(PMDA_INSTALL)
${INSTALLCMD} -m 644 include/ctdb_typesafe_cb.h $(DESTDIR)$(includedir)
${INSTALLCMD} -m 644 config/functions $(DESTDIR)$(etcdir)/ctdb
${INSTALLCMD} -m 755 config/statd-callout $(DESTDIR)$(etcdir)/ctdb
- ${INSTALLCMD} -m 755 config/interface_modify.sh $(DESTDIR)$(etcdir)/ctdb
${INSTALLCMD} -m 644 config/events.d/README $(DESTDIR)$(docdir)/ctdb/README.eventscripts
${INSTALLCMD} -m 644 doc/recovery-process.txt $(DESTDIR)$(docdir)/ctdb/recovery-process.txt
${INSTALLCMD} -m 755 config/events.d/00.ctdb $(DESTDIR)$(etcdir)/ctdb/events.d
diff --git a/config/README b/config/README
index f2457a7..ffbeb0e 100644
--- a/config/README
+++ b/config/README
@@ -14,12 +14,6 @@ Selected highlights:
Support functions, sourced by eventscripts and other scripts.
- interface_modify.sh
-
- Script to support add/remove IPs and other funky stuff. Not sure
- why this is separate... but it certainly allows easy wrapping by
- flock.
-
statd-callout
rpc.statd high-availability callout to support lock migration on
diff --git a/config/events.d/13.per_ip_routing b/config/events.d/13.per_ip_routing
index d8a0644..f51d5ed 100755
--- a/config/events.d/13.per_ip_routing
+++ b/config/events.d/13.per_ip_routing
@@ -3,492 +3,350 @@
. $CTDB_BASE/functions
loadconfig
-ctdb_setup_service_state_dir "per_ip_routing"
+# Do nothing if unconfigured
+[ -n "$CTDB_PER_IP_ROUTING_CONF" ] || exit 0
-[ -z "$CTDB_PER_IP_ROUTING_STATE" ] && {
- CTDB_PER_IP_ROUTING_STATE="$service_state_dir"
-}
+table_id_prefix="ctdb."
-AUTO_LINK_LOCAL="no"
-
-case "$CTDB_PER_IP_ROUTING_CONF" in
- __auto_link_local__)
- AUTO_LINK_LOCAL="yes"
- CTDB_PER_IP_ROUTING_CONF="$CTDB_PER_IP_ROUTING_STATE/auto_link_local.conf"
- ;;
- *)
- [ -z "$CTDB_PER_IP_ROUTING_CONF" ] && {
- #echo "No config file found. Nothing to do for 13.per_ip_routing"
- exit 0;
- }
- ;;
-esac
+[ -n "$CTDB_PER_IP_ROUTING_RULE_PREF" ] || \
+ die "error: CTDB_PER_IP_ROUTING_RULE_PREF not configured"
-_low=$CTDB_PER_IP_ROUTING_TABLE_ID_LOW
-_high=$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH
+[ "$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" -lt "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null || \
+ die "error: CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$CTDB_PER_IP_ROUTING_TABLE_ID_LOW] and/or CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH] improperly configured"
-test -z "$_low" && {
- echo "$0: CTDB_PER_IP_ROUTING_TABLE_ID_LOW not configured";
- exit 1;
-}
-test -z "$_high" && {
- echo "$0: CTDB_PER_IP_ROUTING_TABLE_ID_HIGH not configured";
- exit 1;
-}
-test "$_low" -ge "$_high" && {
- echo "$0: CTDB_PER_IP_ROUTING_TABLE_ID_LOW[$_low] needs to be below CTDB_PER_IP_ROUTING_TABLE_ID_HIGH[$_high]";
- exit 1;
-}
+######################################################################
-test -z "$CTDB_PER_IP_ROUTING_RULE_PREF" && {
- echo "$0: CTDB_PER_IP_ROUTING_RULE_PREF not configured";
- exit 1;
-}
-
-locknesting=0
-lock_root="$CTDB_PER_IP_ROUTING_STATE"
-host=`hostname`
-
-lock_debug()
+ipv4_is_valid_addr()
{
- echo -n ""
-}
-
-############################
-# grab a lock file. Not atomic, but close :)
-# tries to cope with NFS
-lock_file() {
- if [ -z "$lock_root" ]; then
- lock_root=`pwd`;
- fi
- lckf="$lock_root/$1"
- machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
- pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
-
- if [ "$pid" = "$$" ]; then
- locknesting=`expr $locknesting + 1`
- lock_debug "lock nesting now $locknesting"
- return 0
+ _ip="$1"
+
+ _count=0
+ # Get the shell to break up the address into 1 word per octet
+ for _o in $(export IFS="." ; echo $_ip) ; do
+ # The 2>/dev/null stops output from failures where an "octet"
+ # is not numeric. The test will still fail.
+ if ! [ 0 -le $_o -a $_o -le 255 ] 2>/dev/null ; then
+ return 1
fi
+ _count=$(($_count + 1))
+ done
- if test -f "$lckf"; then
- test $machine = $host || {
- lock_debug "lock file $lckf is valid for other machine $machine"
- stat -c%y "$lckf"
- return 1
- }
- kill -0 $pid && {
- lock_debug "lock file $lckf is valid for process $pid"
- stat -c%y "$lckf"
- return 1
- }
- lock_debug "stale lock file $lckf for $machine:$pid"
- cat "$lckf"
- rm -f "$lckf"
- fi
- echo "$host:$$" > "$lckf"
- return 0
+ # A valid IPv4 address has 4 octets
+ [ $_count -eq 4 ]
}
-############################
-# unlock a lock file
-unlock_file() {
- if [ -z "$lock_root" ]; then
- lock_root=`pwd`;
- fi
- if [ "$locknesting" != "0" ]; then
- locknesting=`expr $locknesting - 1`
- lock_debug "lock nesting now $locknesting"
- else
- lckf="$lock_root/$1"
- rm -f "$lckf"
- fi
-}
-
-generate_table_id () {
- local _ip=$1
- local _ipsdir="$CTDB_PER_IP_ROUTING_STATE/ips"
- local _ipdir="$_ipsdir/$_ip"
+ensure_ipv4_is_valid_addr ()
+{
+ _event="$1"
+ _ip="$2"
- mkdir -p $_ipdir
+ ipv4_is_valid_addr "$_ip" || {
+ echo "$0: $_event not an ipv4 address skipping IP:$_ip"
+ exit 0
+ }
+}
- #echo "generate_table_id $_ip"
+ipv4_host_addr_to_net ()
+{
+ _host="$1"
+ _maskbits="$2"
+
+ # Convert the host address to an unsigned long by splitting out
+ # the octets and doing the math.
+ _host_ul=0
+ for _o in $(export IFS="." ; echo $_host) ; do
+ _host_ul=$(( ($_host_ul << 8) + $_o)) # work around Emacs color bug
+ done
+
+ # Calculate the mask and apply it.
+ _mask_ul=$(( 0xffffffff << (32 - $_maskbits) ))
+ _net_ul=$(( $_host_ul & $_mask_ul ))
+
+ # Now convert to a network address one byte at a time.
+ _net=""
+ for _o in $(seq 1 4) ; do
+ _net="$(($_net_ul & 255))${_net:+.}${_net}"
+ _net_ul=$(($_net_ul >> 8))
+ done
+
+ echo "${_net}/${_maskbits}"
+}
- local _id=`cat $_ipdir/table_id 2>/dev/null| xargs`
- test -n "$_id" && {
- #echo "IP: $_ip => OLD TABLE: $_id"
- table_id=$_id
- return 0;
- }
+######################################################################
- local _low="$CTDB_PER_IP_ROUTING_TABLE_ID_LOW"
- local _high="$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH"
-
- local _newid=""
- for _id in `seq $_low $_high | xargs`; do
- local _table_lck="table_id_$_id.lock"
- lock_file $_table_lck 2>/dev/null || {
- continue;
- }
- local _taken=`grep "^$_id$" $_ipsdir/*/table_id 2>/dev/null| wc -l | xargs`
- test x"$_taken" != x"0" && {
- unlock_file $_table_lck
- #echo "tableid: $_id taken"
- continue
- }
- _newid=$_id;
- echo "$_newid" > $_ipdir/table_id
- unlock_file $_table_lck
- break;
+# Setup a table id to use for the given IP. We don't need to know it,
+# it just needs to exist in /etc/iproute2/rt_tables. Fail if no free
+# table id could be found in the configured range.
+ensure_table_id_for_ip ()
+{
+ _ip=$1
+
+ _f="$CTDB_ETCDIR/iproute2/rt_tables"
+ # This file should always exist, but...
+ if [ ! -f "$_f" ] ; then
+ mkdir -p $(dirname "$_f")
+ touch "$_f"
+ fi
+
+ # Maintain a table id for each IP address we've ever seen in
+ # rt_tables. We use a "ctdb." prefix on the label.
+ _label="${table_id_prefix}${_ip}"
+
+ # This finds either the table id corresponding to the label or a
+ # new unused one (that is greater than all the used ones in the
+ # range).
+ (
+ # Note that die() just gets us out of the subshell...
+ flock --timeout 30 0 || \
+ die "ensure_table_id_for_ip: failed to lock file $_f"
+
+ _new=$CTDB_PER_IP_ROUTING_TABLE_ID_LOW
+ while read _t _l ; do
+ # Skip comments
+ case "$_t" in
+ \#*) continue ;;
+ esac
+ # Found existing: done
+ if [ "$_l" = "$_label" ] ; then
+ return 0
+ fi
+ # Potentially update the new table id to be used. The
+ # redirect stops error spam for a non-numeric value.
+ if [ $_new -le $_t -a \
+ $_t -le $CTDB_PER_IP_ROUTING_TABLE_ID_HIGH ] 2>/dev/null ; then
+ _new=$(($_t + 1))
+ fi
done
- test -z "$_newid" && {
- echo "generate_table_id: out of table ids: $_low - $_high"
- exit 1;
- }
-
- #echo "IP: $_ip => NEW TABLE: $_newid"
- table_id=$_newid
- return 0;
+ # If the new table id is legal then add it to the file and
+ # print it.
+ if [ $_new -le $CTDB_PER_IP_ROUTING_TABLE_ID_HIGH ] ; then
+ printf "%d\t%s\n" "$_new" "$_label" >>"$_f"
+ return 0
+ else
+ return 1
+ fi
+ ) <"$_f"
}
-run_release_script_once()
+# Clean up all the table ids that we might own.
+clean_up_table_ids ()
{
- local _script=$1
-
- #echo "run_release_script_once[$_script]"
-
- test -x "$_script" && {
- #echo "run it: start"
- $_script || {
- echo "release_script: $_script - failed $?"
- return $?;
- }
- #echo "run it: end"
- }
-
- echo '#!/bin/sh' > $_script
- echo '#' >> $_script
- echo >> $_script
+ _f="$CTDB_ETCDIR/iproute2/rt_tables"
+ # Even if this didn't exist on the system, adding a route will
+ # have created it. What if we startup and immediately shutdown?
+ if [ ! -f "$_f" ] ; then
+ mkdir -p $(basename "$_f")
+ touch "$_f"
+ fi
+
+ (
+ # Note that die() just gets us out of the subshell...
+ flock --timeout 30 0 || \
+ die "clean_up_table_ids: failed to lock file $_f"
+
+ # Delete any items from the file that have a table id in our
+ # range or a label matching our label. Preserve comments.
+ _tmp="${_f}.$$.ctdb"
+ awk -v min="$CTDB_PER_IP_ROUTING_TABLE_ID_LOW" \
+ -v max="$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" \
+ -v pre="$table_id_prefix" \
+ '/^#/ || \
+ !(min <= $1 && $1 <= max) && \
+ !(index($2, pre) == 1) \
+ { print $0 }' "$_f" >"$_tmp"
+
+ mv "$_tmp" "$_f"
+ # The lock is gone - don't do anything else here
+ ) <"$_f"
+}
- chmod +x $_script
+######################################################################
- return 0;
+# This prints the config for an IP, which is either relevant entries
+# from the config file or, if set to the magic link local value, some
+# link local routing config for the IP.
+# NOTE: non-zero return indicates missing configuration file
+get_config_for_ip ()
+{
+ _ip="$1"
+
+ if [ "$CTDB_PER_IP_ROUTING_CONF" = "__auto_link_local__" ] ; then
+ # When parsing public_addresses also split on '/'. This means
+ # that we get the maskbits as item #2 without further parsing.
+ while IFS="/$IFS" read _i _maskbits _x ; do
+ if [ "$_ip" = "$_i" ] ; then
+ echo -n "$_ip "; ipv4_host_addr_to_net "$_ip" "$_maskbits"
+ fi
+ done <"${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE:-/dev/null}${CTDB:+/public_addresses}}"
+ else
+ [ -f "$CTDB_PER_IP_ROUTING_CONF" ] || return 1
+
+ while read _i _rest ; do
+ if [ "$_ip" = "$_i" ] ; then
+ printf "%s\t%s\n" "$_ip" "$_rest"
+ fi
+ done <"$CTDB_PER_IP_ROUTING_CONF"
+ fi
}
-generate_auto_link_local()
+ip_has_configuration ()
{
- local _ip=$1
- local _maskbits=$2
-
- #echo "generate_auto_link_local $_ip $_maskbits"
-
- local _netip=`ipv4_host_addr_to_net_addr $_ip $_maskbits`
-
- local _line="$_ip $_netip/$_maskbits"
-
- local _lockfile="$CTDB_PER_IP_ROUTING_CONF.lock"
- local _script="$CTDB_PER_IP_ROUTING_CONF.$$.sh"
-
- echo "#!/bin/sh" > $_script
- echo "#" >> $_script
- echo "" >> $_script
- echo "_config=\`cat $CTDB_PER_IP_ROUTING_CONF 2>/dev/null\`" >> $_script
- echo "_exact=\`echo -n \"\$_config\" | grep \"^$_line\$\" | wc -l | xargs\`" >> $_script
- echo "" >> $_script
-
- echo "test x\"\$_exact\" = x\"1\" && {" >> $_script
- echo " exit 0;" >> $_script
- echo "}" >> $_script
- echo "" >> $_script
-
- echo "_tmp=\"$CTDB_PER_IP_ROUTING_CONF.$$.tmp\"" >> $_script
- echo "echo -n \"\$_config\" | grep -v \"^$_ip \" | cat > \$_tmp || {" >> $_script
- echo " echo \"echo -n \\\"\$_config\\\" | grep -v \\\"^$_ip \\\" > \$_tmp - failed\"" >> $_script
- echo " exit 1;" >> $_script
- echo "}" >> $_script
- echo "echo \"$_line\" >> \$_tmp || {" >> $_script
- echo " echo \"echo \\\"$_line\\\" >> \$_tmp - failed\"" >> $_script
- echo " exit 1;" >> $_script
- echo "}" >> $_script
- echo "" >> $_script
-
- echo "mv \$_tmp $CTDB_PER_IP_ROUTING_CONF || {" >> $_script
- echo " echo \"mv \$_tmp $CTDB_PER_IP_ROUTING_CONF - failed\"" >> $_script
- echo " exit 1;" >> $_script
- echo "}" >> $_script
- echo "" >> $_script
-
- echo "echo \"Added '$_line' to $CTDB_PER_IP_ROUTING_CONF\"">> $_script
- echo "exit 0" >> $_script
-
- chmod +x $_script
-
- test -f $_lockfile || {
- touch $_lockfile
- }
+ _ip="$1"
- flock --timeout 30 $_lockfile $_script
- ret=$?
- rm $_script
- return $ret
+ _config="$(get_config_for_ip $_ip)" || \
+ die "error: CTDB_PER_IP_ROUTING_CONF=$CTDB_PER_IP_ROUTING_CONF file not found"
+ [ -n "$_config" ]
}
-generate_per_ip_routing()
+add_routing_for_ip ()
{
- local _ip=$1
- local _maskbits=$2
- local _iface=$3
- local _readonly=$4
- local _ipdir="$CTDB_PER_IP_ROUTING_STATE/ips/$_ip"
-
- table_id=""
- release_script="$_ipdir/per_ip_routing_release.sh"
- setup_script="$_ipdir/per_ip_routing_setup.sh"
-
- test x"$_readonly" = x"yes" && {
- test -d $_ipdir || {
- return 1;
- }
- return 0;
- }
+ _iface="$1"
+ _ip="$2"
- mkdir -p $_ipdir || {
- echo "mkdir -p $_ipdir failed"
- return 1;
- }
- echo "$_ip" > $_ipdir/ip
+ # Do nothing if no config for this IP.
+ ip_has_configuration "$_ip" || return 0
- generate_table_id $_ip
+ ensure_table_id_for_ip "$_ip" || \
+ die "add_routing_for_ip: out of table ids in range $CTDB_PER_IP_ROUTING_TABLE_ID_LOW - $CTDB_PER_IP_ROUTING_TABLE_ID_HIGH"
--
CTDB repository
More information about the samba-cvs
mailing list