diff --git a/heartbeat/LVM b/heartbeat/LVM index 7ef1a7e31..6ca44a9d9 100755 --- a/heartbeat/LVM +++ b/heartbeat/LVM @@ -1,727 +1,458 @@ #!/bin/sh # # # LVM # # Description: Manages an LVM volume as an HA resource # # # Author: Alan Robertson # Support: users@clusterlabs.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. 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 "exclusive" is set on a non clustered volume group, this overrides the tag to be used. Exclusive activation tag - + If set, the volume group will be activated partially even with some physical volumes missing. It helps to set to true when using mirrored logical volumes. Activate VG partially when missing PVs EOF } # # methods: What methods/operations do we support? # LVM_methods() { cat < /dev/null 2>&1 - if [ $? -ne 0 ]; then - return - fi - - ## - # Now check to see if the initrd has been updated. - # If not, the machine could boot and activate the VG outside - # the control of pacemaker - ## - if [ "$(find /boot -name *.img -newer /etc/lvm/lvm.conf)" = "" ]; then - ocf_log warn "LVM: Improper setup detected" - ocf_log warn "* initrd image needs to be newer than lvm.conf" - - # While dangerous if not done the first time, there are many - # cases where we don't simply want to fail here. Instead, - # keep warning until the user remakes the initrd - or has - # it done for them by upgrading the kernel. - # - # initrd can be updated using this command. - # dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r) - # - fi -} - -## -# does this vg have our tag -## -check_tags() -{ - local owner=`vgs -o tags --noheadings $OCF_RESKEY_volgrpname | tr -d ' '` - - if [ -z "$owner" ]; then - # No-one owns this VG yet - return 1 - fi - - if [ "$OUR_TAG" = "$owner" ]; then - # yep, this is ours - return 0 - fi - - # some other tag is set on this vg - return 2 -} - -strip_tags() -{ - local i - - for i in `vgs --noheadings -o tags $OCF_RESKEY_volgrpname | sed s/","/" "/g`; do - ocf_log info "Stripping tag, $i" - - # LVM version 2.02.98 allows changing tags if PARTIAL - vgchange --deltag $i $OCF_RESKEY_volgrpname - done - - if [ ! -z `vgs -o tags --noheadings $OCF_RESKEY_volgrpname | tr -d ' '` ]; then - ocf_exit_reason "Failed to remove ownership tags from $OCF_RESKEY_volgrpname" - return $OCF_ERR_GENERIC - fi - - return $OCF_SUCCESS -} - -set_tags() -{ - check_tags - case $? in - 0) - # we already own it. - return $OCF_SUCCESS - ;; - 2) - # other tags are set, strip them before setting - if ! strip_tags; then - return $OCF_ERR_GENERIC - fi - ;; - *) - : ;; - esac - - vgchange --addtag $OUR_TAG $OCF_RESKEY_volgrpname - if [ $? -ne 0 ]; then - ocf_exit_reason "Failed to add ownership tag to $OCF_RESKEY_volgrpname" - return $OCF_ERR_GENERIC - fi - - ocf_log info "New tag \"$OUR_TAG\" added to $OCF_RESKEY_volgrpname" - return $OCF_SUCCESS + . ${OCF_FUNCTIONS_DIR}/lvm-${mode}.sh } # # Return LVM status (silently) # LVM_status() { local rc=1 loglevel="debug" # Set the log level of the error message if [ "X${2}" = "X" ]; then loglevel="err" if ocf_is_probe; then loglevel="warn" else if [ ${OP_METHOD} = "stop" ]; then loglevel="info" fi fi fi if [ -d /dev/$1 ]; then test "`cd /dev/$1 && ls`" != "" rc=$? if [ $rc -ne 0 ]; then ocf_exit_reason "VG $1 with no logical volumes is not supported by this RA!" fi fi if [ $rc -ne 0 ]; then ocf_log $loglevel "LVM Volume $1 is not available (stopped)" rc=$OCF_NOT_RUNNING else - case $(get_vg_mode) in - 1) # exclusive with tagging. - # If vg is running, make sure the correct tag is present. Otherwise we - # can not guarantee exclusive activation. - if ! check_tags; then - ocf_exit_reason "WARNING: $OCF_RESKEY_volgrpname is active without the cluster tag, \"$OUR_TAG\"" - rc=$OCF_ERR_GENERIC - fi - - # make sure the environment for tags activation is still valid - if ! verify_tags_environment; then - rc=$OCF_ERR_GENERIC - fi - # let the user know if their initrd is older than lvm.conf. - check_initrd_warning - ;; - *) - : ;; - esac + lvm_status + rc=$? fi if [ "X${2}" = "X" ]; then # status call return return $rc fi # Report on LVM volume status to stdout... if [ $rc -eq 0 ]; then echo "Volume $1 is available (running)" else echo "Volume $1 is not available (stopped)" fi return $rc } -get_activate_options() -{ - local options="-a" - - case $(get_vg_mode) in - 0) options="${options}ly";; - 1) options="${options}y --config activation{volume_list=[\"@${OUR_TAG}\"]}";; - 2) options="${options}ey";; - esac - - if ocf_is_true "$OCF_RESKEY_partial_activation" ; then - options="${options} --partial" - fi - - # for clones (clustered volume groups), we'll also have to force - # monitoring, even if disabled in lvm.conf. - if ocf_is_clone; then - options="$options --monitor y" - fi - - echo $options -} - -## -# Attempt to deactivate vg cluster wide and then start the vg exclusively -## -retry_exclusive_start() -{ - local vgchange_options="$(get_activate_options)" - - # Deactivate each LV in the group one by one cluster wide - set -- $(lvs -o name,attr --noheadings $OCF_RESKEY_volgrpname 2> /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_exit_reason "Unable to perform required deactivation of $OCF_RESKEY_volgrpname/$1 before starting" - return $OCF_ERR_GENERIC - fi - ;; - esac - shift 2 - done - - 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 # systemd drop-in to stop process before storage services during # shutdown/reboot if ps -p 1 | grep -q systemd ; then systemd_drop_in "99-LVM" "After" "blk-availability.service" fi # 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 --cache 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 [ $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 + lvm_pre_activate || exit + ocf_run vgchange $vgchange_activate_options $vg + lvm_post_activate $? if LVM_status $vg; then : OK Volume $vg activated just fine! return $OCF_SUCCESS else ocf_exit_reason "LVM: $vg did not activate correctly" return $OCF_NOT_RUNNING fi } # # Disable the LVM volume # LVM_stop() { 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 fi ocf_log info "Deactivating volume group $vg" - case $(get_vg_mode) in - 1) vgchange_options="-an" ;; - esac + lvm_pre_deactivate || exit for i in $(seq 10) do - ocf_run vgchange $vgchange_options $vg + ocf_run vgchange $vgchange_deactivate_options $vg res=$? if LVM_status $vg; then ocf_exit_reason "LVM: $vg did not stop correctly" res=1 fi if [ $res -eq 0 ]; then break fi 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 - case $(get_vg_mode) in - 1) - if [ $res -eq 0 ]; then - strip_tags - res=$? - fi - ;; - esac - - return $res + lvm_post_deactivate $res } # # Check whether the OCF instance parameters are valid # LVM_validate_all() { check_binary $AWK ## # lvmetad is a daemon that caches lvm metadata to improve the # performance of LVM commands. This daemon should never be used when # volume groups exist that are being managed by the cluster. The lvmetad # daemon introduces a response lag, where certain LVM commands look like # they have completed (like vg activation) when in fact the command # is still in progress by the lvmetad. This can cause reliability issues # when managing volume groups in the cluster. For Example, if you have a # volume group that is a dependency for another application, it is possible # the cluster will think the volume group is activated and attempt to start # the application before volume group is really accesible... lvmetad is bad. ## lvm dumpconfig global/use_lvmetad | grep 'use_lvmetad.*=.*1' > /dev/null 2>&1 if [ $? -eq 0 ]; then # for now warn users that lvmetad is enabled and that they should disable it. In the # future we may want to consider refusing to start, or killing the lvmetad daemon. ocf_log warn "Disable lvmetad in lvm.conf. lvmetad should never be enabled in a clustered environment. Set use_lvmetad=0 and kill the lvmetad process" fi ## # Off-the-shelf tests... ## VGOUT=`vgck ${VOLUME} 2>&1` if [ $? -ne 0 ]; then # Inconsistency might be due to missing physical volumes, which doesn't # automatically mean we should fail. If partial_activation=true then # we should let start try to handle it, or if no PVs are listed as # "unknown device" then another node may have marked a device missing # where we have access to all of them and can start without issue. if vgs -o pv_attr --noheadings $OCF_RESKEY_volgrpname 2>/dev/null | grep 'm' > /dev/null 2>&1; then case $(vgs -o attr --noheadings $OCF_RESKEY_volgrpname | tr -d ' ') in ???p??*) if ! ocf_is_true "$OCF_RESKEY_partial_activation" ; then # We are missing devices and cannot activate partially ocf_exit_reason "Volume group [$VOLUME] has devices missing. Consider partial_activation=true to attempt to activate partially" exit $OCF_ERR_GENERIC else # We are missing devices but are allowed to activate partially. # Assume that caused the vgck failure and carry on ocf_log warn "Volume group inconsistency detected with missing device(s) and partial_activation enabled. Proceeding with requested action." fi ;; esac # else the vg is partial but all devices are accounted for, so another # node must have marked the device missing. Proceed. else # vgck failure was for something other than missing devices ocf_exit_reason "Volume group [$VOLUME] does not exist or contains error! ${VGOUT}" exit $OCF_ERR_GENERIC fi 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_exit_reason "Volume group [$VOLUME] does not exist or contains error! ${VGOUT}" exit $OCF_ERR_GENERIC fi if lvs --noheadings -o segtype | grep -q "cache"; then if ! lvs --noheadings -o cache_mode "$OCF_RESKEY_volgrpname" | grep -q "writethrough"; then ocf_log warn "LVM CACHE IS NOT IN WRITETHROUGH MODE. THIS IS NOT A SUPPORTED CONFIGURATION." fi 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 + if ocf_is_clone && ocf_is_true "$OCF_RESKEY_exclusive"; then ocf_exit_reason "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 $(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_exit_reason "$OCF_RESKEY_volgrpname has the cluster attribute set, but 'clvmd' is not running" - exit $OCF_ERR_GENERIC - fi - ;; - *) - : ;; - esac - - return $OCF_SUCCESS + lvm_validate_all } # # '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_exit_reason "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_exit_reason "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 -if [ -n "$OCF_RESKEY_tag" ]; then - OUR_TAG=$OCF_RESKEY_tag +set_lvm_mode +lvm_init +if ocf_is_true "$OCF_RESKEY_partial_activation" ; then + vgchange_activate_options="${vgchange_activate_options} --partial" 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_status $VOLUME exit $?;; validate-all) LVM_validate_all ;; *) usage exit $OCF_ERR_UNIMPLEMENTED;; esac diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am index 0cb3864ca..7a2c1632a 100644 --- a/heartbeat/Makefile.am +++ b/heartbeat/Makefile.am @@ -1,179 +1,182 @@ # Makefile.am for OCF RAs # # Author: Sun Jing Dong # Copyright (C) 2004 IBM # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = $(ocf_SCRIPTS) $(ocfcommon_DATA) \ $(common_DATA) $(hb_DATA) $(dtd_DATA) \ README AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/linux-ha halibdir = $(libexecdir)/heartbeat ocfdir = $(OCF_RA_DIR_PREFIX)/heartbeat dtddir = $(datadir)/$(PACKAGE_NAME) dtd_DATA = ra-api-1.dtd metadata.rng if USE_IPV6ADDR_AGENT ocf_PROGRAMS = IPv6addr else ocf_PROGRAMS = endif if IPV6ADDR_COMPATIBLE halib_PROGRAMS = send_ua else halib_PROGRAMS = endif IPv6addr_SOURCES = IPv6addr.c IPv6addr_utils.c send_ua_SOURCES = send_ua.c IPv6addr_utils.c IPv6addr_LDADD = -lplumb $(LIBNETLIBS) send_ua_LDADD = $(LIBNETLIBS) ocf_SCRIPTS = AoEtarget \ AudibleAlarm \ ClusterMon \ CTDB \ Delay \ Dummy \ EvmsSCC \ Evmsd \ Filesystem \ ICP \ IPaddr \ IPaddr2 \ IPsrcaddr \ LVM \ LinuxSCSI \ lvmlockd \ MailTo \ ManageRAID \ ManageVE \ NodeUtilization \ Pure-FTPd \ Raid1 \ Route \ SAPDatabase \ SAPInstance \ SendArp \ ServeRAID \ SphinxSearchDaemon \ Squid \ Stateful \ SysInfo \ VIPArip \ VirtualDomain \ WAS \ WAS6 \ WinPopup \ Xen \ Xinetd \ ZFS \ anything \ apache \ asterisk \ aws-vpc-move-ip \ aws-vpc-route53 \ awseip \ awsvip \ clvm \ conntrackd \ db2 \ dhcpd \ dnsupdate \ docker \ eDir88 \ ethmonitor \ exportfs \ fio \ galera \ garbd \ iSCSILogicalUnit \ iSCSITarget \ ids \ iface-bridge \ iface-vlan \ iscsi \ jboss \ kamailio \ lxc \ minio \ mysql \ mysql-proxy \ nagios \ named \ nfsnotify \ nfsserver \ nginx \ oraasm \ oracle \ oralsnr \ ovsmonitor \ pgagent \ pgsql \ pingd \ portblock \ postfix \ pound \ proftpd \ rabbitmq-cluster \ redis \ rkt \ rsyncd \ rsyslog \ scsi2reservation \ sfex \ sg_persist \ slapd \ symlink \ syslog-ng \ tomcat \ varnish \ vmware \ vsftpd \ zabbixserver ocfcommondir = $(OCF_LIB_DIR_PREFIX)/heartbeat ocfcommon_DATA = ocf-shellfuncs \ ocf-binaries \ ocf-directories \ ocf-returncodes \ ocf-rarun \ ocf-distro \ apache-conf.sh \ http-mon.sh \ sapdb-nosha.sh \ sapdb.sh \ + lvm-clvm.sh \ + lvm-plain.sh \ + lvm-tag.sh \ ora-common.sh \ mysql-common.sh \ nfsserver-redhat.sh \ findif.sh # Legacy locations hbdir = $(sysconfdir)/ha.d hb_DATA = shellfuncs check: $(ocf_SCRIPTS:=.check) %.check: % OCF_ROOT=$(abs_srcdir) OCF_FUNCTIONS_DIR=$(abs_srcdir) ./$< meta-data | xmllint --path $(abs_srcdir) --noout --relaxng $(abs_srcdir)/metadata.rng - diff --git a/heartbeat/lvm-clvm.sh b/heartbeat/lvm-clvm.sh new file mode 100644 index 000000000..9bc0f7584 --- /dev/null +++ b/heartbeat/lvm-clvm.sh @@ -0,0 +1,86 @@ +# lvm-clvmd.sh +# +# Description: LVM management with clvmd +# +# +# Author: Resource agents contributors +# Interface to LVM by Dejan Muhamedagic +# Support: users@clusterlabs.org +# License: GNU General Public License (GPL) +# Copyright: (C) 2017 Dejan Muhamedagic +# + +## +# Attempt to deactivate vg cluster wide and then start the vg exclusively +## +retry_exclusive_start() +{ + # Deactivate each LV in the group one by one cluster wide + set -- $(lvs -o name,attr --noheadings $OCF_RESKEY_volgrpname 2> /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_exit_reason "Unable to perform required deactivation of $OCF_RESKEY_volgrpname/$1 before starting" + return $OCF_ERR_GENERIC + fi + ;; + esac + shift 2 + done + + ocf_run vgchange $vgchange_activate_options $OCF_RESKEY_volgrpname +} + +# +# the interface to the LVM RA +# + +lvm_init() { + vgchange_activate_options="-aey" + vgchange_deactivate_options="-an" +} + +lvm_validate_all() { + if ! ps -C clvmd > /dev/null 2>&1; then + ocf_exit_reason "$OCF_RESKEY_volgrpname has the cluster attribute set, but 'clvmd' is not running" + exit $OCF_ERR_GENERIC + fi +} + +lvm_status() { + return 0 +} + +lvm_pre_activate() { + return 0 +} + +lvm_post_activate() { + local rc=$1 + if [ $rc -ne 0 ]; then + # 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 + return $rc +} + +lvm_pre_deactivate() { + return 0 +} + +lvm_post_deactivate() { + local rc=$1 + return $rc +} + +# vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0 diff --git a/heartbeat/lvm-plain.sh b/heartbeat/lvm-plain.sh new file mode 100644 index 000000000..f53328584 --- /dev/null +++ b/heartbeat/lvm-plain.sh @@ -0,0 +1,62 @@ +# lvm-plain.sh +# +# Description: LVM management with no VG protection +# +# +# Author: Dejan Muhamedagic +# Support: users@clusterlabs.org +# License: GNU General Public License (GPL) +# Copyright: (C) 2017 Dejan Muhamedagic +# + +# +# interface to the LVM RA +# + +# apart from the standard vgchange options, +# this is mostly a template +# please copy and modify appropriately +# when adding new VG protection mechanisms + +# lvm_init sets the vgchange options: +# vgchange_activate_options +# vgchange_deactivate_options +# (for both activate and deactivate) + +lvm_init() { + vgchange_activate_options="-aly" + vgchange_deactivate_options="-aln" + # for clones (clustered volume groups), we'll also have to force + # monitoring, even if disabled in lvm.conf. + if ocf_is_clone; then + vgchange_activate_options="$vgchange_activate_options --monitor y" + fi +} + +lvm_validate_all() { + : nothing to validate +} + +lvm_status() { + return 0 +} + +lvm_pre_activate() { + return 0 +} + +lvm_post_activate() { + local rc=$1 + return $rc +} + +lvm_pre_deactivate() { + return 0 +} + +lvm_post_deactivate() { + local rc=$1 + return $rc +} + +# vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0 diff --git a/heartbeat/lvm-tag.sh b/heartbeat/lvm-tag.sh new file mode 100644 index 000000000..71f53b20b --- /dev/null +++ b/heartbeat/lvm-tag.sh @@ -0,0 +1,205 @@ +# lvm-tag.sh +# +# Description: LVM management with tags +# +# +# Author: David Vossel +# Interface to LVM by Dejan Muhamedagic +# Support: users@clusterlabs.org +# License: GNU General Public License (GPL) +# Copyright: (C) 2017 Dejan Muhamedagic +# + +## +# Verify tags setup +## + +verify_tags_environment() +{ + ## + # The volume_list must be initialized to something in order to + # guarantee our tag will be filtered on startup + ## + if ! lvm dumpconfig activation/volume_list; then + ocf_log err "LVM: Improper setup detected" + ocf_exit_reason "The volume_list filter must be initialized in lvm.conf for exclusive activation without clvmd" + return $OCF_ERR_GENERIC + fi + + ## + # Our tag must _NOT_ be in the volume_list. This agent + # overrides the volume_list during activation using the + # special tag reserved for cluster activation + ## + if lvm dumpconfig activation/volume_list | grep -e "\"@$OUR_TAG\"" -e "\"${OCF_RESKEY_volgrpname}\""; then + ocf_log err "LVM: Improper setup detected" + ocf_exit_reason "The volume_list in lvm.conf must not contain the cluster tag, \"$OUR_TAG\", or volume group, $OCF_RESKEY_volgrpname" + return $OCF_ERR_GENERIC + fi + + return $OCF_SUCCESS +} + +check_initrd_warning() +{ + # First check to see if there is an initrd img we can safely + # compare timestamps agaist. If not, don't even bother with + # this check. This is known to work in rhel/fedora distros + ls "/boot/*$(uname -r)*.img" > /dev/null 2>&1 + if [ $? -ne 0 ]; then + return + fi + + ## + # Now check to see if the initrd has been updated. + # If not, the machine could boot and activate the VG outside + # the control of pacemaker + ## + if [ "$(find /boot -name *.img -newer /etc/lvm/lvm.conf)" = "" ]; then + ocf_log warn "LVM: Improper setup detected" + ocf_log warn "* initrd image needs to be newer than lvm.conf" + + # While dangerous if not done the first time, there are many + # cases where we don't simply want to fail here. Instead, + # keep warning until the user remakes the initrd - or has + # it done for them by upgrading the kernel. + # + # initrd can be updated using this command. + # dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r) + # + fi +} + +## +# does this vg have our tag +## +check_tags() +{ + local owner=`vgs -o tags --noheadings $OCF_RESKEY_volgrpname | tr -d ' '` + + if [ -z "$owner" ]; then + # No-one owns this VG yet + return 1 + fi + + if [ "$OUR_TAG" = "$owner" ]; then + # yep, this is ours + return 0 + fi + + # some other tag is set on this vg + return 2 +} + +strip_tags() +{ + local i + + for i in `vgs --noheadings -o tags $OCF_RESKEY_volgrpname | sed s/","/" "/g`; do + ocf_log info "Stripping tag, $i" + + # LVM version 2.02.98 allows changing tags if PARTIAL + vgchange --deltag $i $OCF_RESKEY_volgrpname + done + + if [ ! -z `vgs -o tags --noheadings $OCF_RESKEY_volgrpname | tr -d ' '` ]; then + ocf_exit_reason "Failed to remove ownership tags from $OCF_RESKEY_volgrpname" + return $OCF_ERR_GENERIC + fi + + return $OCF_SUCCESS +} + +set_tags() +{ + check_tags + case $? in + 0) + # we already own it. + return $OCF_SUCCESS + ;; + 2) + # other tags are set, strip them before setting + if ! strip_tags; then + return $OCF_ERR_GENERIC + fi + ;; + *) + : ;; + esac + + vgchange --addtag $OUR_TAG $OCF_RESKEY_volgrpname + if [ $? -ne 0 ]; then + ocf_exit_reason "Failed to add ownership tag to $OCF_RESKEY_volgrpname" + return $OCF_ERR_GENERIC + fi + + ocf_log info "New tag \"$OUR_TAG\" added to $OCF_RESKEY_volgrpname" + return $OCF_SUCCESS +} + +# +# interface to LVM +# + +lvm_init() { + OUR_TAG="pacemaker" + if [ -n "$OCF_RESKEY_tag" ]; then + OUR_TAG=$OCF_RESKEY_tag + fi + vgchange_activate_options="aly --config activation{volume_list=[\"@${OUR_TAG}\"]}" + vgchange_deactivate_options="-aln" +} + +lvm_validate_all() { + if ! verify_tags_environment; then + exit $OCF_ERR_GENERIC + fi +} + +lvm_status() { + local rc=0 + + # If vg is running, make sure the correct tag is present. Otherwise we + # can not guarantee exclusive activation. + if ! check_tags; then + ocf_exit_reason "WARNING: $OCF_RESKEY_volgrpname is active without the cluster tag, \"$OUR_TAG\"" + rc=$OCF_ERR_GENERIC + fi + + # make sure the environment for tags activation is still valid + if ! verify_tags_environment; then + rc=$OCF_ERR_GENERIC + fi + # let the user know if their initrd is older than lvm.conf. + check_initrd_warning + + return $rc +} + +lvm_pre_activate() { + if ! set_tags; then + return $OCF_ERR_GENERIC + fi + return 0 +} + +lvm_post_activate() { + local rc=$1 + return $rc +} + +lvm_pre_deactivate() { + return 0 +} + +lvm_post_deactivate() { + local rc=$1 + if [ $rc -eq 0 ]; then + strip_tags + rc=$? + fi + return $rc +} + +# vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0