die "error: CTDB_PER_IP_ROUTING_CONF=$CTDB_PER_IP_ROUTING_CONF file not found"
fi
+service_state_dir=$(ctdb_setup_service_state_dir) || exit $?
+
######################################################################
ipv4_is_valid_addr()
ensure_rt_tables ()
{
rt_tables="$CTDB_SYS_ETCDIR/iproute2/rt_tables"
+ rt_tables_lock="${service_state_dir}/rt_tables_lock"
# This file should always exist. Even if this didn't exist on the
# system, adding a route will have created it. What if we startup
# range).
(
# Note that die() just gets us out of the subshell...
- flock --timeout 30 0 || \
+ flock --timeout 30 9 || \
die "ensure_table_id_for_ip: failed to lock file $rt_tables"
_new="$CTDB_PER_IP_ROUTING_TABLE_ID_LOW"
"$_t" -le "$CTDB_PER_IP_ROUTING_TABLE_ID_HIGH" ] 2>/dev/null ; then
_new=$((_t + 1))
fi
- done
+ done <"$rt_tables"
# If the new table id is legal then add it to the file and
# print it.
else
return 1
fi
- ) <"$rt_tables"
+ ) 9>"$rt_tables_lock"
}
# Clean up all the table ids that we might own.
(
# Note that die() just gets us out of the subshell...
- flock --timeout 30 0 || \
+ flock --timeout 30 9 || \
die "clean_up_table_ids: failed to lock file $rt_tables"
# Delete any items from the file that have a table id in our
{ print $0 }' "$rt_tables" >"$_tmp"
mv "$_tmp" "$rt_tables"
- # The lock is gone - don't do anything else here
- ) <"$rt_tables"
+ ) 9>"$rt_tables_lock"
}
######################################################################
ctdb_reconfigure_take_lock ()
{
- _ctdb_service_reconfigure_common
- _lock="${_d}/reconfigure_lock"
- mkdir -p "${_lock%/*}" # dirname
- touch "$_lock"
-
- (
- flock 0
- # This is overkill but will work if we need to extend this to
- # allow certain events to run multiple times in parallel
- # (e.g. takeip) and write multiple PIDs to the file.
- read _locker_event
- if [ -n "$_locker_event" ] ; then
- while read _pid ; do
- if [ -n "$_pid" -a "$_pid" != $$ ] && \
- kill -0 "$_pid" 2>/dev/null ; then
- exit 1
- fi
- done
- fi
+ _ctdb_service_reconfigure_common
+ _lock="${_d}/reconfigure_lock"
+ mkdir -p "${_lock%/*}" # dirname
+ touch "$_lock"
- printf "%s\n%s\n" "$event_name" $$ >"$_lock"
- exit 0
- ) <"$_lock"
+ (
+ flock 9
+ # This is overkill but will work if we need to extend
+ # this to allow certain events to run multiple times
+ # in parallel (e.g. takeip) and write multiple PIDs to
+ # the file.
+ {
+ read _locker_event
+ if [ -n "$_locker_event" ] ; then
+ while read _pid ; do
+ if [ -n "$_pid" -a "$_pid" != $$ ] && \
+ kill -0 "$_pid" 2>/dev/null ; then
+ exit 1
+ fi
+ done
+ fi
+ } <"$_lock"
+
+ printf "%s\n%s\n" "$event_name" $$ >"$_lock"
+ exit 0
+ ) 9>"${_lock}.flock"
}
ctdb_reconfigure_release_lock ()