Skip to content

Commit 0cfef41

Browse files
committed
portblock: derive state file from parameters instead of instance
The expected usage of this agent is to pair a "block" with an "unblock", and order startup and configuration of some service between these. The established idiom is to have two separate instances with inverse actions. To "reliably" report the status of "block" during a monitor action, it is not sufficient to check the existence of the blocking rule. It is also insufficient to rely on the pseudo resource state file of this instance only. To know our actual expectation, we need to check the state file of the "inverse" instance as well. Because we don't know the OCF_RESOURCE_INSTANCE value of the other instance, we override the state file name for both instances to something derived from our parameters. This should give use the same "global state" view as the "promotion score" does for the promotable clone variant of this agent.
1 parent f07425d commit 0cfef41

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

heartbeat/portblock

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ OCF_RESKEY_portno_default=""
3030
OCF_RESKEY_direction_default="in"
3131
OCF_RESKEY_action_default=""
3232
OCF_RESKEY_method_default="drop"
33-
OCF_RESKEY_status_check_default="rule"
3433
OCF_RESKEY_ip_default="0.0.0.0/0"
3534
OCF_RESKEY_reset_local_on_unblock_stop_default="false"
3635
OCF_RESKEY_tickle_dir_default=""
3736
OCF_RESKEY_sync_script_default=""
3837

38+
if ocf_is_ms; then
39+
OCF_RESKEY_status_check_default="rule"
40+
else
41+
OCF_RESKEY_status_check_default="pseudo"
42+
fi
43+
3944
: ${OCF_RESKEY_firewall=${OCF_RESKEY_firewall_default}}
4045
: ${OCF_RESKEY_protocol=${OCF_RESKEY_protocol_default}}
4146
: ${OCF_RESKEY_portno=${OCF_RESKEY_portno_default}}
@@ -474,8 +479,17 @@ PortStatus() {
474479
fi
475480
;;
476481
*)
477-
SayInactive $*
478-
rc=$OCF_NOT_RUNNING
482+
if [ "$OCF_RESKEY_status_check" != "rule" ] \
483+
&& test -e "$state_file" && test "$inverse_state_file" -nt "$state_file"; then
484+
# rule present, action=unblock, unblock statefile present,
485+
# block state file more recent.
486+
# apparently an unusual setup: unblock first, block later
487+
SayConsideredActive $*
488+
rc=$OCF_SUCCESS
489+
else
490+
SayInactive $*
491+
rc=$OCF_NOT_RUNNING
492+
fi
479493
;;
480494
esac
481495
elif [ "$OCF_RESKEY_status_check" = "rule" ]; then
@@ -497,7 +511,10 @@ PortStatus() {
497511
else
498512
case $5 in
499513
block)
500-
if ha_pseudo_resource "${OCF_RESOURCE_INSTANCE}" status; then
514+
if test -e "$state_file" && test "$inverse_state_file" -nt "$state_file"; then
515+
# rule NOT present, action=block, block state file present,
516+
# unblock state file more recent.
517+
# expected setup: block first, unblock later
501518
SayConsideredActive $*
502519
rc=$OCF_SUCCESS
503520
else
@@ -506,9 +523,10 @@ PortStatus() {
506523
fi
507524
;;
508525
*)
509-
if ha_pseudo_resource "${OCF_RESOURCE_INSTANCE}" status; then
526+
if test -e "$state_file" ; then
527+
# rule NOT present, action=unblock, unblock state file present
510528
SayActive $*
511-
#This is only run on real monitor events.
529+
# This is only run on real monitor events (state file present).
512530
save_tcp_connections
513531
rc=$OCF_SUCCESS
514532
else
@@ -646,7 +664,7 @@ PortUNBLOCK()
646664
#PortStart {udp|tcp} portno,portno ip {in|out|both} {block|unblock}
647665
PortStart()
648666
{
649-
ha_pseudo_resource "${OCF_RESOURCE_INSTANCE}" start
667+
ha_pseudo_resource "${OCF_RESOURCE_INSTANCE}" start "$state_file"
650668

651669
if [ "$FIREWALL" = "nft" ]; then
652670
$NFTABLES add table inet $TABLE || {
@@ -689,7 +707,7 @@ PortStart()
689707
#PortStop {udp|tcp} portno,portno ip {in|out|both} {block|unblock}
690708
PortStop()
691709
{
692-
ha_pseudo_resource "${OCF_RESOURCE_INSTANCE}" stop
710+
ha_pseudo_resource "${OCF_RESOURCE_INSTANCE}" stop "$state_file"
693711

694712
case $5 in
695713
block) PortUNBLOCK "$@"
@@ -940,6 +958,33 @@ fi
940958

941959
PortValidateAll
942960

961+
# State file name for ha_pseudo_resource
962+
#
963+
# The expected usage of this agent is to pair a "block" with an "unblock",
964+
# and order startup and configuration of some service between these.
965+
#
966+
# The established idiom is to have two separate instances with inverse actions.
967+
# To "reliably" report the status of "block" during a monitor action,
968+
# it is not sufficient to check the existence of the blocking rule.
969+
#
970+
# It is also insufficient to rely on the pseudo resource state file
971+
# of this instance only.
972+
#
973+
# To know our actual expectation, we need to check the state file of the
974+
# "inverse" instance as well.
975+
#
976+
# Because we don't know the OCF_RESOURCE_INSTANCE value of the other instance,
977+
# we override the state file name for both instances to something derived from
978+
# our parameters.
979+
#
980+
# This should give use the same "global state" view as the "promotion score"
981+
# does for the promotable clone variant of this agent.
982+
#
983+
[ "$action" = block ] && inverse_action=unblock || inverse_action=block
984+
state_file_base=$(echo "portblock_${protocol}_${portno}_${ip}_${direction}" | tr -c '[0-9a-zA-Z._\n]' _)
985+
state_file=${HA_RSCTMP}/${state_file_base}_${action}
986+
inverse_state_file=${HA_RSCTMP}/${state_file_base}_${inverse_action}
987+
943988
case $__OCF_ACTION in
944989
start)
945990
PortStart "$protocol" "$portno" "$ip" "$direction" "$action"

0 commit comments

Comments
 (0)