diff --git a/heartbeat/LVM b/heartbeat/LVM index ce9277b6b..67dd6e387 100755 --- a/heartbeat/LVM +++ b/heartbeat/LVM @@ -1,456 +1,630 @@ #!/bin/sh # # # LVM # # Description: Manages an LVM volume as an HA resource # # # Author: Alan Robertson # Support: linux-ha@lists.linux-ha.org # License: GNU General Public License (GPL) # Copyright: (C) 2002 - 2005 International Business Machines, Inc. # # This code significantly inspired by the LVM resource # in FailSafe by Lars Marowsky-Bree # # # An example usage in /etc/ha.d/haresources: # node1 10.0.0.170 ServeRAID::1::1 LVM::myvolname # # See usage() function below for more details... # # OCF parameters are as below: # OCF_RESKEY_volgrpname # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs ####################################################################### usage() { methods=`LVM_methods` methods=`echo $methods | tr ' ' '|'` cat < 1.0 Resource script for LVM. It manages an Linux Volume Manager volume (LVM) as an HA resource. Controls the availability of an LVM Volume Group The name of volume group. Volume group name -If set, the volume group will be activated exclusively. +If set, the volume group will be activated exclusively. This option works one of +two ways. If the volume group has the cluster attribute set, then the volume group +will be activated exclusively using clvmd across the cluster. If the cluster attribute +is not set, the volume group will be activated exclusively using a tag and the volume_list +filter. When the tag option is in use, the volume_list in lvm.con must be initialized. This +can be as simple as setting 'volume_list = []' depending on your setup. Exclusive activation If set, the volume group will be activated even only partial of the physical volumes available. It helps to set to true, when you are using mirroring logical volumes. Activate VG even with partial PV only EOF } # # methods: What methods/operations do we support? # LVM_methods() { cat < /dev/null) while [ $# -ge 2 ]; do case $2 in ????ao*) # open LVs cannot be deactivated. return $OCF_ERR_GENERIC;; *) if ! lvchange -an $OCF_RESKEY_volgrpname/$1; then ocf_log err "Unable to perform required deactivation of $OCF_RESKEY_volgrpname/$1 before starting" return $OCF_ERR_GENERIC fi ;; esac shift 2 done return ocf_run vgchange $vgchange_options $OCF_RESKEY_volgrpname } # # Enable LVM volume # LVM_start() { local vgchange_options=$(get_activate_options) local vg=$1 + local clvmd=0 # TODO: This MUST run vgimport as well ocf_log info "Activating volume group $vg" if [ "$LVM_MAJOR" -eq "1" ]; then ocf_run vgscan $vg else ocf_run vgscan fi + case $(get_vg_mode) in + 2) + clvmd=1 + ;; + 1) + if ! set_tags; then + return $OCF_ERR_GENERIC + fi + ;; + *) + : ;; + esac + if ! ocf_run vgchange $vgchange_options $vg; then - if ! ocf_is_true "$OCF_RESKEY_exclusive"; then + if [ $clvmd -eq 0 ]; then return $OCF_ERR_GENERIC fi # Failure to exclusively activate cluster vg.: # This could be caused by a remotely active LV, Attempt # to disable volume group cluster wide and try again. # Allow for some settling sleep 5 if ! retry_exclusive_start; then return $OCF_ERR_GENERIC fi fi if LVM_status $vg; then : OK Volume $vg activated just fine! return $OCF_SUCCESS else ocf_log err "LVM: $vg did not activate correctly" return $OCF_NOT_RUNNING fi } # # Disable the LVM volume # LVM_stop() { - local res - vgdisplay "$1" 2>&1 | grep 'Volume group .* not found' >/dev/null && { - ocf_log info "Volume group $1 not found" + local res=$OCF_ERR_GENERIC + local vgchange_options="-aln" + local vg=$1 + + if ! vgs $vg > /dev/null 2>&1; then + ocf_log info "Volume group $vg not found" return $OCF_SUCCESS - } - ocf_log info "Deactivating volume group $1" + fi + + ocf_log info "Deactivating volume group $vg" + + case $(get_vg_mode) in + 1) vgchange_options="-an" ;; + esac for i in $(seq 10) do - ocf_run vgchange -a ln $1 + ocf_run vgchange $vgchange_options $vg res=$? - if LVM_status $1; then - ocf_log err "LVM: $1 did not stop correctly" + if LVM_status $vg; then + ocf_log err "LVM: $vg did not stop correctly" res=1 fi if [ $res -eq 0 ]; then - return $OCF_SUCCESS + break fi - ocf_log warn "$1 still Active" - ocf_log info "Retry deactivating volume group $1" + res=$OCF_ERR_GENERIC + ocf_log warn "$vg still Active" + ocf_log info "Retry deactivating volume group $vg" sleep 1 which udevadm > /dev/null 2>&1 && udevadm settle --timeout=5 done - # TODO: This MUST run vgexport as well - return $OCF_ERR_GENERIC + case $(get_vg_mode) in + 1) + if [ $res -eq 0 ]; then + strip_tags + res=$? + fi + ;; + esac + + return $res } # # Check whether the OCF instance parameters are valid # LVM_validate_all() { check_binary $AWK ## # Off-the-shelf tests... ## VGOUT=`vgck ${VOLUME} 2>&1` if [ $? -ne 0 ]; then ocf_log err "Volume group [$VOLUME] does not exist or contains error! ${VGOUT}" exit $OCF_ERR_GENERIC fi ## # Does the Volume Group exist? ## if [ "$LVM_MAJOR" = "1" ]; then VGOUT=`vgdisplay ${VOLUME} 2>&1` else VGOUT=`vgdisplay -v ${VOLUME} 2>&1` fi if [ $? -ne 0 ]; then ocf_log err "Volume group [$VOLUME] does not exist or contains error! ${VGOUT}" exit $OCF_ERR_GENERIC fi ## # If exclusive activation is not enabled, then # further checking of proper setup is not necessary ## if ! ocf_is_true "$OCF_RESKEY_exclusive"; then return $OCF_SUCCESS; fi ## # Having cloned lvm resources with exclusive vg activation makes no sense at all. ## if ocf_is_clone; then ocf_log_err "cloned lvm resources can not be activated exclusively" exit $OCF_ERR_CONFIGURED fi ## # Make sure the cluster attribute is set and clvmd is up when exclusive # activation is enabled. Otherwise we can't exclusively activate the volume group. ## - case $(vgs -o attr --noheadings $OCF_RESKEY_volgrpname 2>/dev/null | tr -d ' ') in - ?????c*) - # Is clvmd running? + case $(get_vg_mode) in + 1) # exclusive activation using tags + if ! verify_tags_environment; then + exit $OCF_ERR_GENERIC + fi + ;; + 2) # exclusive activation with clvmd + ## + # verify is clvmd running + ## if ! ps -C clvmd > /dev/null 2>&1; then ocf_log err "$OCF_RESKEY_volgrpname has the cluster attribute set, but 'clvmd' is not running" exit $OCF_ERR_GENERIC fi - return $OCF_SUCCESS ;; *) - ocf_log err "Unable to exclusively activate $OCF_RESKEY_volgrpname becaues it is not a clusted volume group" - exit $OCF_ERR_GENERIC - ;; + : ;; esac return $OCF_SUCCESS } # # 'main' starts here... # if [ $# -ne 1 ] then usage exit $OCF_ERR_ARGS fi case $1 in meta-data) meta_data exit $OCF_SUCCESS;; methods) LVM_methods exit $?;; usage) usage exit $OCF_SUCCESS;; *) ;; esac if [ -z "$OCF_RESKEY_volgrpname" ] then ocf_log err "You must identify the volume group name!" exit $OCF_ERR_CONFIGURED fi # Get the LVM version number, for this to work we assume(thanks to panjiam): # # LVM1 outputs like this # # # vgchange --version # vgchange: Logical Volume Manager 1.0.3 # Heinz Mauelshagen, Sistina Software 19/02/2002 (IOP 10) # # LVM2 and higher versions output in this format # # # vgchange --version # LVM version: 2.00.15 (2004-04-19) # Library version: 1.00.09-ioctl (2004-03-31) # Driver version: 4.1.0 LVM_VERSION=`vgchange --version 2>&1 | \ $AWK '/Logical Volume Manager/ {print $5"\n"; exit; } /LVM version:/ {printf $3"\n"; exit;}'` rc=$? if ( [ $rc -ne 0 ] || [ -z "$LVM_VERSION" ] ) then ocf_log err "LVM: $1 could not determine LVM version. Try 'vgchange --version' manually and modify $0 ?" exit $OCF_ERR_INSTALLED fi LVM_MAJOR="${LVM_VERSION%%.*}" VOLUME=$OCF_RESKEY_volgrpname OP_METHOD=$1 + +OUR_TAG="pacemaker" +if [ -n "$OCF_RESKEY_tag" ]; then + OUR_TAG=$OCF_RESKEY_tag +fi + # What kind of method was invoked? case "$1" in start) LVM_validate_all LVM_start $VOLUME exit $?;; stop) LVM_stop $VOLUME exit $?;; status) LVM_status $VOLUME $1 exit $?;; - monitor) LVM_monitor $VOLUME + monitor) LVM_status $VOLUME exit $?;; validate-all) LVM_validate_all ;; *) usage exit $OCF_ERR_UNIMPLEMENTED;; esac