Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion scripts/crm-fence-peer.9.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ restrict_existing_constraint_further()
done
}

# From ocf-shellfuncs
# usage: ocf_version_cmp VER1 VER2
# version strings can contain digits, dots, and dashes
# must start and end with a digit
# returns:
# 0: VER1 smaller (older) than VER2
# 1: versions equal
# 2: VER1 greater (newer) than VER2
# 3: bad format
ocf_version_cmp() {
ocf_is_ver "$1" || return 3
ocf_is_ver "$2" || return 3
local v1=$1
local v2=$2

sort_version="sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n"
older=$( (echo "$v1"; echo "$v2") | $sort_version | head -1 )

if [[ "$v1" == "$v2" ]]; then
return 1
elif [[ "$v1" == "$older" ]]; then
return 0
else
return 2 # -1 would look funny in shell ;-)
fi
}

# set CIB_file= in environment, unless you want to grab the "live" one.
#
# I'd like to use the optional prefix filter on the constraint id,
Expand Down Expand Up @@ -691,6 +718,15 @@ existing_constraint_rejects_me()
setup_new_constraint()
{
new_constraint="<rsc_location rsc=\"$master_id\" id=\"$id_prefix-$master_id\">"$'\n'

if [[ -z "$role" ]]; then
if $OCF_1_1_SUPPORT ; then
role="Promoted"
else
role="Master"
fi
fi

# double negation: do not run but with my data.
new_constraint+=" <rule role=\"$role\" score=\"-INFINITY\" id=\"$id_prefix-rule-$master_id\">"$'\n'

Expand Down Expand Up @@ -1444,7 +1480,6 @@ fi
# apply defaults:
: "== fencing_attribute == ${fencing_attribute:="#uname"}"
: "== id_prefix == ${id_prefix:="drbd-fence-by-handler"}"
: "== role == ${role:="Master"}"

# defaults suitable for most cases
: "== net_hickup_time == ${net_hickup_time:=0}"
Expand All @@ -1455,6 +1490,12 @@ fi
: "== lock_file == ${lock_file}"
: "== lock_dir == ${lock_dir}"

OCF_1_1_SUPPORT=false
ocf_version_cmp "$crm_feature_set" "3.10.0"
res=$?
if [[ $res -eq 2 ]] || [[ $res -eq 1 ]]; then
OCF_1_1_SUPPORT=true
fi

# check envars normally passed in by drbdadm
# TODO DRBD_CONF is also passed in. we may need to use it in the
Expand Down
44 changes: 36 additions & 8 deletions scripts/drbd.ocf
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ if ! command -v ocf_is_true &> /dev/null ; then
}
fi

if ! command -v ocf_promotion_score &> /dev/null ; then
ocf_promotion_score() {
ocf_version_cmp "$OCF_RESKEY_crm_feature_set" "3.10.0"
res=$?
if [ $res -eq 2 ] || [ $res -eq 1 ] || ! have_binary "crm_master"; then
${HA_SBIN_DIR}/crm_attribute -p ${OCF_RESOURCE_INSTANCE} $@
else
${HA_SBIN_DIR}/crm_master -l reboot $@
fi
}
fi

# Defaults
OCF_RESKEY_drbdconf_default="/etc/drbd.conf"
OCF_RESKEY_unfence_extra_args_default="--quiet --flock-required --flock-timeout 0 --unfence-only-if-owner-match"
Expand Down Expand Up @@ -217,15 +229,32 @@ fi
# end of debugging aid
#######################################################################

# OCF 1.1 supports new role "promoted" and "unpromoted" instead of "Master" and "Slave"
#
OCF_1_1_SUPPORT=false
ocf_version_cmp "$OCF_RESKEY_crm_feature_set" "3.10.0"
res=$?
if [ $res -eq 2 ] || [ $res -eq 1 ]; then
OCF_1_1_SUPPORT=true
fi

meta_data() {
if $OCF_1_1_SUPPORT ; then
actions='<action name="monitor" timeout="20" interval="20" role="Unpromoted" />
<action name="monitor" timeout="20" interval="10" role="Promoted" />'
else
actions='<action name="monitor" timeout="20" interval="20" role="Slave" />
<action name="monitor" timeout="20" interval="10" role="Master" />'
fi

cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<!-- version attribute is version of this resource agent -->
<resource-agent name="drbd" version="LINBIT 1.4">
<resource-agent name="drbd" version="LINBIT 1.5">

<!-- Version number of the standard this agent complies with -->
<version>1.0</version>
<version>1.1</version>

<longdesc lang="en">
This resource agent manages a DRBD resource as a master/slave resource.
Expand Down Expand Up @@ -472,8 +501,7 @@ to be generated after the failover of a "healthy" DRBD.
<action name="demote" timeout="90" />
<action name="notify" timeout="90" />
<action name="stop" timeout="100" />
<action name="monitor" timeout="20" interval="20" role="Slave" />
<action name="monitor" timeout="20" interval="10" role="Master" />
$actions
<action name="meta-data" timeout="5" />
<action name="validate-all" />
</actions>
Expand Down Expand Up @@ -604,9 +632,9 @@ do_drbdadm() {
unset current_master_score
get_current_master_score()
{
# only call crm_master once
# only call get crm master once
[[ ${current_master_score+set} ]] ||
current_master_score=$(crm_master -q -l reboot -G 2>/dev/null)
current_master_score=$(ocf_promotion_score -q -G 2>/dev/null)
# return value of this function:
# true if master_score is present
# false if master_score is not present
Expand All @@ -619,13 +647,13 @@ set_master_score() {
if [[ $1 -le 0 ]]; then
remove_master_score
else
do_cmd_CRM_meta_timeout ${HA_SBIN_DIR}/crm_master -Q -l reboot -v $1 &&
do_cmd_CRM_meta_timeout ocf_promotion_score -Q -v $1 &&
current_master_score=$1
fi
}

remove_master_score() {
do_cmd_CRM_meta_timeout ${HA_SBIN_DIR}/crm_master -l reboot -D
do_cmd_CRM_meta_timeout ocf_promotion_score -D
current_master_score=""
}

Expand Down