From 12e84ca523d41148230f50d98764c3e85f1052d1 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Sun, 7 Jul 2024 15:22:49 +0800 Subject: [PATCH 1/2] drbd.ocf: replace crm_master with ocf_promotion_score The crm_master command has been deprecated and replaced with a new crm_attribute --promotion option that defaults to --lifetime=reboot (example: crm_master -l reboot -v 10 becomes crm_attribute --promotion -v 10. The old command will still work for now, but the new one should be used if available. Also define ocf_promotion_score() as resource-agents/heartbeat/ocf-shellfuncs.in if it doesn't exist. Signed-off-by: Su Yue --- scripts/drbd.ocf | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/drbd.ocf b/scripts/drbd.ocf index 34d208f2..e3a77604 100755 --- a/scripts/drbd.ocf +++ b/scripts/drbd.ocf @@ -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" @@ -604,9 +616,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 @@ -619,13 +631,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="" } From d0540028f0f85aea6d265f8dbb59b3015674ddb0 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Mon, 17 Nov 2025 15:39:05 +0800 Subject: [PATCH 2/2] drbd.ocf: update for OCF 1.1 According to [1], the commit 1. Bumps drbd ocf version to 1.5. 2. Updates the element to 1.1 for declare support of OCF 1.1. 3. advertises new role names 'Unpromoted' and 'Unpromoted' instead of 'Master' and 'Slave' if crm_feature_set is newer than 3.9.0. Also update default role value in crm-fence-peer.9.sh. Links: https://projects.clusterlabs.org/w/development/update_resource_agent_for_ocf_1.1/ Signed-off-by: Su Yue --- scripts/crm-fence-peer.9.sh | 43 ++++++++++++++++++++++++++++++++++++- scripts/drbd.ocf | 24 +++++++++++++++++---- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/scripts/crm-fence-peer.9.sh b/scripts/crm-fence-peer.9.sh index b326a165..552d044c 100755 --- a/scripts/crm-fence-peer.9.sh +++ b/scripts/crm-fence-peer.9.sh @@ -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, @@ -691,6 +718,15 @@ existing_constraint_rejects_me() setup_new_constraint() { new_constraint=""$'\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+=" "$'\n' @@ -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}" @@ -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 diff --git a/scripts/drbd.ocf b/scripts/drbd.ocf index e3a77604..1872c1c9 100755 --- a/scripts/drbd.ocf +++ b/scripts/drbd.ocf @@ -229,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=' +' + else + actions=' +' + fi + cat < - + -1.0 +1.1 This resource agent manages a DRBD resource as a master/slave resource. @@ -484,8 +501,7 @@ to be generated after the failover of a "healthy" DRBD. - - +$actions