summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2012-08-31 15:57:05 -0500
committerDavid Teigland <teigland@redhat.com>2012-08-31 15:57:05 -0500
commit5de0b6b9ec25d081b101980c2d5c8e9a1f829779 (patch)
treed404ee49bc3b28d4b0c868d7fe2076e662f7dcae
parent52a93f9d621deabac7d0d686c527771317d2ded9 (diff)
downloaddct-stuff-5de0b6b9ec25d081b101980c2d5c8e9a1f829779.tar.gz
dct-stuff-5de0b6b9ec25d081b101980c2d5c8e9a1f829779.tar.xz
dct-stuff-5de0b6b9ec25d081b101980c2d5c8e9a1f829779.zip
sanlvm: update
-rwxr-xr-xlvm/sanlvm525
1 files changed, 378 insertions, 147 deletions
diff --git a/lvm/sanlvm b/lvm/sanlvm
index 4594db9..b2650b7 100755
--- a/lvm/sanlvm
+++ b/lvm/sanlvm
@@ -1,18 +1,20 @@
#!/bin/bash
-host_id=0
cmd=
glpath=
vgname=
lvname=
+offset=
+suffix=
+sanlvmd=
+host_id=0
lock_mode=
-active_mode=
no_active=
-offset=
+active_mode=
-# sanlvmd is only needed when sanlvm is used with lv
-# activation leases. When sanlvm is only used to
-# serialize vg metadata changes, it's not needed.
+# sanlvmd is only needed when lv activation locks are used.
+# It is not needed for the vglk, which protects vg metadata
+# by serializing commands changing the vg.
#
# sanlvmd is a process that sanlock views as owning the lv
# activation leases. When a vg disappears/fails, sanlock
@@ -49,21 +51,13 @@ help() {
echo " host_id 1"
echo ""
echo "sanlvm vgcreate [options] $vg <devs>"
- echo " create vg, unprotected by sanlock,"
- echo " create and initialize storage in $vg for sanlock to use"
- echo " . vgcreate [options] $vg <devs>"
- echo " . lvcreate -n leases -L 1G $vg"
- echo " . sanlock direct init -s $vg:0:/dev/$vg/leases:0"
- echo " . sanlock direct init -r $vg:vglk:/dev/$vg/leases:1048576"
- echo " . vgchange --addtag @sanlvm $vg"
+ echo " create vg, create and initialize storage in $vg for sanlock to use"
echo ""
echo "sanlvm start"
- echo " start lockspaces for vgs @sanlvm, created above"
- echo " . sanlock add_lockspace -s $vg:$host_id:/dev/$vg/leases:0"
+ echo " start lockspaces for sanlvm vgs, created above"
echo ""
echo "sanlvm <lvmcmd> ..."
echo " lvm commands within $vg are serialized by sanlock"
- echo " . sanlock command -r $vg:vglk:/dev/$vg/leases:1048576 -c /sbin/lvm <lvmcmd> ..."
echo ""
echo "sanlvm [--na] lvcreate ..."
echo " create an lv with or without (--na) an associated lv"
@@ -83,26 +77,6 @@ help() {
exit 0
}
-if [[ $# == 0 ]]; then
- help
-fi
-
-arg1=$1
-
-if [[ "$arg1" == "help" ]]; then
- help
-fi
-
-if [[ "$arg1" == "--ex" ]] || [[ "$arg1" == "--sh" ]]; then
- lock_mode=$arg1
- cmd=$2
-elif [[ "$arg1" == "--na" ]]; then
- no_active=$arg1
- cmd=$2
-else
- cmd=$1
-fi
-
# vg name is the arg preceding the first pv path arg,
# or the last arg when no pv paths exist
# e.g. vgcreate, vgchange, vgextend, lvcreate
@@ -172,7 +146,7 @@ get_host_id() {
fi
}
-get_global_lease() {
+get_gl_path() {
glpath=`awk '/^global_lease_path/ { print $2 }' < /etc/sanlvm.conf`
if [[ $? -ne 0 ]]; then
@@ -180,7 +154,7 @@ get_global_lease() {
fi
}
-# search lvchange args for -a, ---available
+# search lvchange/vgchange args for -a, ---available
# if there's a "y" anywhere after the option, then active_mode="y"
# if there's a "n" anywhere after the option, then active_mode="n"
@@ -228,81 +202,135 @@ get_lease_offset() {
offset=`echo $tags | cut --delimiter=_ --fields=3`
}
-if [[ "$cmd" == "global_init" ]]; then
- get_global_lease
+check_vg_start() {
+ sanlock client status | grep 's $vgname'
- if [[ "$glpath" == "" ]]; then
+ if [[ $? -eq 0 ]]; then
+ # FIXME: just start the lockspace here?
+ echo "lockspace for $vgname must be started"
exit 1
fi
+}
- sanlock direct init -s sanlvm_global:0:$glpath:0
+vgcreate() {
+ lvm $get_args
if [[ $? -ne 0 ]]; then
exit 1
fi
- sanlock direct init -r sanlvm_global:lease:$glpath:1048576
+ lvm lvcreate -n leases -L 1G $vgname
if [[ $? -ne 0 ]]; then
exit 1
fi
- exit 0
+ sanlock direct init -s $vgname:0:/dev/$vgname/leases:0
-elif [[ "$cmd" == "start" ]]; then
- get_global_lease
- get_host_id
+ if [[ $? -ne 0 ]]; then
+ exit 1
+ fi
- if [[ "$glpath" != "" ]]; then
- lvm lvchange -a y $glpath
- sanlock add_lockspace -s sanlvm_global:$host_id:$glpath:0
+ sanlock direct init -r $vgname:vglk:/dev/$vgname/leases:1048576
+
+ if [[ $? -ne 0 ]]; then
+ exit 1
fi
- for vgname in `vgs @sanlvm --noheadings -o vg_name`; do
- # FIXME: do something to prevent sanlvm lv's from
- # automatically being activated by the system at
- # startup; then this vgchange -an is not needed.
- vgchange -an $vgname
+ lvm vgchange --addtag @sanlvm $vgname
- lvm lvchange -a y /dev/$vgname/leases
- echo adding lockspace $vgname, this may take minutes...
- sanlock add_lockspace -s $vgname:$host_id:/dev/$vgname/leases:0
- done
+ if [[ $? -ne 0 ]]; then
+ exit 1
+ fi
exit 0
+}
-elif [[ "$cmd" == "vgcreate" ]]; then
+lvchange() {
+ if [[ "$active_mode" == "y" ]]; then
- # FIXME: wrap this function in sanlvm_global:lease
+ sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset$suffix -p $sanlvmd
- get_args=$*
- get_vg_name
+ if [[ $? -ne 0 ]]; then
+ echo "lv lock failed for $vgname/$lvname, may be active on another host"
+ return
+ fi
- lvm "$@"
+ lvm lvchange -ay $vgname/$lvname
+ else
+ lvm lvchange -an $vgname/$lvname
- if [[ $? -ne 0 ]]; then
+ if [[ $? -ne 0 ]]; then
+ echo "deactivate failed for $vgname/$lvname, may be open"
+ return
+ fi
+
+ sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p $sanlvmd
+ fi
+}
+
+if [[ $# == 0 ]]; then
+ help
+fi
+
+arg1=$1
+
+if [[ "$arg1" == "help" ]]; then
+ help
+fi
+
+if [[ "$arg1" == "--ex" ]] || [[ "$arg1" == "--sh" ]]; then
+ lock_mode=$arg1
+ cmd=$2
+elif [[ "$arg1" == "--na" ]]; then
+ no_active=$arg1
+ cmd=$2
+else
+ cmd=$1
+fi
+
+if [[ "$cmd" == "vgcreate" ]] || [[ "$cmd" == "vgremove" ]] || [[ "$cmd" == "vgextend" ]]; then
+ get_gl_path
+
+ if [[ "$glpath" == "" ]]; then
+ echo "Warning: no global_lease_path found in /etc/sanlvm.conf"
+ echo "Concurrent vgcreate, vgremove, and vgextend commands"
+ echo "will not be properly synchronized among hosts."
+ echo "(Concurrent vgextend of the same vg will be proteted,"
+ echo "and operations within a vg will be protected.)"
+ fi
+fi
+
+if [[ "$cmd" == "global_init" ]] || [[ "$cmd" == "global_init_force" ]]; then
+ get_gl_path
+
+ if [[ "$glpath" == "" ]]; then
+ echo "no global_lease_path found in /etc/sanlvm.conf"
exit 1
fi
- lvm lvcreate -n leases -L 1G $vgname
+ sanlock client status | grep 's sanlvm_global'
- if [[ $? -ne 0 ]]; then
+ if [[ $? -eq 0 ]]; then
+ echo "$glpath already initialized and in use."
exit 1
fi
- sanlock direct init -s $vgname:0:/dev/$vgname/leases:0
+ sanlock direct read_id -s sanlvm_global:1:$glpath:0
- if [[ $? -ne 0 ]]; then
+ if [[ $? -eq 0 ]] && [[ "$cmd" == "global_init" ]]; then
+ echo "$glpath already initialized and may be in use."
+ echo "use sanlvm global_init_force to override."
exit 1
fi
- sanlock direct init -r $vgname:vglk:/dev/$vgname/leases:1048576
+ sanlock direct init -s sanlvm_global:0:$glpath:0
if [[ $? -ne 0 ]]; then
exit 1
fi
- lvm vgchange --addtag @sanlvm $vgname
+ sanlock direct init -r sanlvm_global:lease:$glpath:1048576
if [[ $? -ne 0 ]]; then
exit 1
@@ -310,16 +338,30 @@ elif [[ "$cmd" == "vgcreate" ]]; then
exit 0
-elif [[ "$cmd" == "vgextend" ]]; then
+elif [[ "$cmd" == "_start" ]]; then
+ # wrapped by shared sanlvm_global:lease
- get_args=$*
- get_vg_name
- get_glpath
+ vgname=$SANLVM_VGNAME
+ host_id=$SANLVM_HOST_ID
- # FIXME: take both global lease and vglk, e.g.
- # sanlock command -r sanlvm_global:lease:$glpath:1048576 -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@"
+ # Parallel starts among hosts with SH lease are ok.
+ # We don't want to start the vg/lockspace while another
+ # host is removing it with vgremove.
+ #
+ # vgcreate/vgremove/vgextend use the exclusive mode.
+ # We want to serialize this start with vgremove; vgremove
+ # holds the ex global lease and checks that the lockspace/vg
+ # is not added/in-use on any other hosts.
- sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@"
+ lvm lvchange -a y /dev/$vgname/leases
+
+ if [[ $? -ne 0 ]]; then
+ echo "failed to activate /dev/$vgname/leases"
+ exit 1
+ fi
+
+ echo "adding lockspace $vgname, this may take minutes..."
+ sanlock add_lockspace -s $vgname:$host_id:/dev/$vgname/leases:0
if [[ $? -ne 0 ]]; then
exit 1
@@ -327,37 +369,124 @@ elif [[ "$cmd" == "vgextend" ]]; then
exit 0
-elif [[ "$cmd" == "vgremove" ]]; then
+elif [[ "$cmd" == "start" ]]; then
+ get_gl_path
+ get_host_id
+ if [[ "$glpath" != "" ]]; then
+ sanlock client status | grep 's sanlvm_global'
- get_args=$*
- get_vg_name
- get_glpath
+ if [[ $? -eq 1 ]]; then
+ echo "starting lockspace sanlvm_global, this may take minutes..."
+ lvm lvchange -a y $glpath
+ sanlock add_lockspace -s sanlvm_global:$host_id:$glpath:0
+ fi
+ fi
- # It doesn't work to hold the vglk around vgremove, because
- # the vglk requires the leases lv to be open, which causes
- # the vgremove to fail. This is similar to the reason we can't
- # hold the vglk around vgcreate: the leases area for vglk doesn't
- # exist yet because it's inside the vg being created.
+ for vgname in `vgs @sanlvm --noheadings -o vg_name`; do
- # FIXME: we could do the lvremoves automatically,
- # but it looks messy
+ sanlock client status | grep 's $vgname'
- found=0
+ if [[ $? -eq 0 ]]; then
+ continue
+ fi
- for lvname in `lvs $vgname --noheadings -o lv_name`; do
- if [[ "$lvname" != "leases" ]]; then
- echo "run sanlvm lvremove $vgname/$lvname before vgremove"
- found=1
+ # FIXME: do something to prevent sanlvm lv's from
+ # automatically being activated by the system at
+ # startup; then this vgchange -an is not needed.
+
+ vgchange -an $vgname
+
+ if [[ "$glpath" == "" ]]; then
+ echo "no global lock"
+ lvm lvchange -a y /dev/$vgname/leases
+ echo "starting lockspace $vgname, this may take minutes..."
+ sanlock add_lockspace -s $vgname:$host_id:/dev/$vgname/leases:0
+ else
+ export SANLVM_VGNAME=$vgname
+ export SANLVM_HOST_ID=$host_id
+ sanlock command -r sanlvm_global:lease:$glpath:1048576:SH -c ./sanlvm _start "$@"
fi
done
- if [[ $found -eq 1 ]]; then
+ exit 0
+
+elif [[ "$cmd" == "stop" ]]; then
+ get_gl_path
+ get_host_id
+
+ # rem_lockspace will fail if any locks exist in it, i.e.
+ # if vglk is being used, or any lv's are activated with a lock
+
+ for vgname in `vgs @sanlvm --noheadings -o vg_name`; do
+ sanlock rem_lockspace -s $vgname:$host_id:/dev/$vgname/leases:0
+
+ if [[ $? -eq 0 ]]; then
+ lvm lvchange -an $vgname/leases
+ else
+ echo "cannot stop lockspace $vgname"
+ fi
+ done
+
+ sanlock rem_lockspace -s sanlvm_global:$host_id:$glpath:0
+
+ exit 0
+
+elif [[ "$cmd" == "_vgcreate" ]]; then
+ # wrapped by sanlvm_global:lease
+ shift
+
+ get_args=$*
+ vgname=$SANLVM_VGNAME
+
+ vgcreate
+
+elif [[ "$cmd" == "vgcreate" ]]; then
+
+ get_args=$*
+ get_vg_name
+
+ if [[ "$glpath" == "" ]]; then
+ echo "no global lock"
+ vgcreate
+ else
+ export SANLVM_VGNAME=$vgname
+ sanlock command -r sanlvm_global:lease:$glpath:1048576 -c ./sanlvm _vgcreate "$@"
+ fi
+
+ if [[ $? -ne 0 ]]; then
+ exit 1
+ fi
+
+ exit 0
+
+elif [[ "$cmd" == "_vgremove" ]]; then
+ # wrapped by sanlvm_global:lease
+ shift
+
+ vgname=$SANLVM_VGNAME
+
+ get_host_id
+
+ others=`sanlock client host_status -s $vgname | egrep -v -e ^$host_id -e 'timestamp 0'`
+
+ # NB this check can be inaccurate for a short time.
+ # after another host stops, it takes until our next
+ # renewal for us to notice and show timestamp 0.
+
+ if [[ $? -eq 0 ]]; then
+ echo "cannot remove vg, other hosts using vg $vgname require sanlvm stop:"
+ echo "$others"
exit 1
fi
- # FIXME: wrap vgremove in sanlvm_global:lease
+ sanlock rem_lockspace -s $vgname:$host_id:/dev/$vgname/leases:0
+
+ lvm lvchange -an $vgname/leases
+ lvm lvremove $vgname/leases
+
+ # vgremove
lvm "$@"
if [[ $? -ne 0 ]]; then
@@ -366,13 +495,20 @@ elif [[ "$cmd" == "vgremove" ]]; then
exit 0
-elif [[ "$cmd" == "vgchange" ]]; then
+elif [[ "$cmd" == "vgremove" ]]; then
- # FIXME: catch variations of vgchange -ay / -an
- # and either prohibit (require sanlvm lvchange), or
- # translate into sanlvm lvchange here.
+ get_args=$*
+ get_vg_name
- lvm "$@"
+ check_vg_start
+
+ if [[ "$glpath" == "" ]]; then
+ echo "no global lock"
+ lvm "$@"
+ else
+ export SANLVM_VGNAME=$vgname
+ sanlock command -r sanlvm_global:lease:$glpath:1048576 -c ./sanlvm _vgremove "$@"
+ fi
if [[ $? -ne 0 ]]; then
exit 1
@@ -380,6 +516,26 @@ elif [[ "$cmd" == "vgchange" ]]; then
exit 0
+elif [[ "$cmd" == "vgextend" ]]; then
+
+ get_args=$*
+ get_vg_name
+
+ check_vg_start
+
+ if [[ "$glpath" == "" ]]; then
+ echo "no global lock"
+ sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@"
+ else
+ sanlock command -r sanlvm_global:lease:$glpath:1048576 -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@"
+ fi
+
+ if [[ $? -ne 0 ]]; then
+ exit 1
+ fi
+
+ exit 0
+
elif [[ "$cmd" == "_lvcreate" ]]; then
# wrapped by vglk
shift
@@ -426,13 +582,14 @@ elif [[ "$cmd" == "_lvcreate" ]]; then
exit 0
elif [[ "$cmd" == "lvcreate" ]]; then
- # we need the multiple steps in _lvcreate to all be wrapped in vglk
get_args=$*
get_vg_name
+ check_vg_start
+
if [[ "$no_active" == "--na" ]]; then
- echo "no activation lock"
+ echo "creating lv without activation lock"
shift
sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@"
else
@@ -453,6 +610,13 @@ elif [[ "$cmd" == "_lvremove" ]]; then
lvname=$SANLVM_LVNAME
offset=$SANLVM_OFFSET
+ sanlvmd=`pidof sanlvmd`
+
+ if [[ $? -ne 0 ]]; then
+ echo "sanlvmd not found, required for lv locks"
+ exit 1
+ fi
+
# refuse to remove the lv if the local host has the lv activated
status=`sanlock client status | grep "r $vgname:$lvname"`
@@ -463,9 +627,8 @@ elif [[ "$cmd" == "_lvremove" ]]; then
fi
# acquire ex activation lock on the lv so we know that no hosts have it active
- # FIXME: I don't think sanlock acquire success/fail exit codes are always correct
- sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd`
+ sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset -p $sanlvmd
if [[ $? -ne 0 ]]; then
echo "lv lock failed, may be active on another host"
@@ -475,7 +638,7 @@ elif [[ "$cmd" == "_lvremove" ]]; then
# lvremove
lvm "$@"
- sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd`
+ sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p $sanlvmd
# clear the lease area that was used for the lv activation lease at offset
dd if=/dev/zero of=/dev/$vgname/leases seek=`expr $offset / 512` bs=512 count=2048
@@ -488,8 +651,10 @@ elif [[ "$cmd" == "lvremove" ]]; then
get_vg_lv_name
get_lease_offset
+ check_vg_start
+
if [[ "$offset" == "" ]]; then
- echo "no activation lock"
+ echo "no lv activation lock for $vgname/$lvname, only protecting vg"
sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@"
else
export SANLVM_VGNAME=$vgname
@@ -512,34 +677,38 @@ elif [[ "$cmd" == "_lvextend" ]] || [[ "$cmd" == "_lvreduce" ]] || [[ "$cmd" ==
lvname=$SANLVM_LVNAME
offset=$SANLVM_OFFSET
- # refuse to extend/reduce/convert the lv if the local
- # host has the lv activated
+ sanlvmd=`pidof sanlvmd`
+
+ if [[ $? -ne 0 ]]; then
+ echo "sanlvmd not found, required for lv locks"
+ exit 1
+ fi
+
+ # refuse to extend/reduce/convert the lv if the local host has the lv activate
# FIXME: allow extend of active lv, not reduce
status=`sanlock client status | grep "r $vgname:$lvname"`
if [[ "$status" != "" ]]; then
- echo "lv must be be deactivated before extend or reduce"
+ echo "lv must be be deactivated before extend/reduce/convert/resize"
exit 1
fi
- # acquire ex activation lock on the lv so
- # we know that no hosts have it active
+ # acquire ex activation lock on the lv so we know that no hosts have it active
- sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd`
+ sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset -p $sanlvmd
if [[ $? -ne 0 ]]; then
echo "lv lock failed, may be active on another host"
exit 1
fi
- # lvextend/lvreduce/lvconvert
+ # lvextend/lvreduce/lvconvert/lvresize
lvm "$@"
- sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd`
-
- exit 0;
+ sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p $sanlvmd
+ exit 0
elif [[ "$cmd" == "lvextend" ]] || [[ "$cmd" == "lvreduce" ]] || [[ "$cmd" == "lvconvert" ]] || [[ "$cmd" == "lvresize" ]]; then
@@ -547,8 +716,10 @@ elif [[ "$cmd" == "lvextend" ]] || [[ "$cmd" == "lvreduce" ]] || [[ "$cmd" == "l
get_vg_lv_name
get_lease_offset
+ check_vg_start
+
if [[ "$offset" == "" ]]; then
- echo "no activation lock"
+ echo "no lv activation lock for $vgname/$lvname, only protecting vg"
sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@"
else
export SANLVM_VGNAME=$vgname
@@ -570,50 +741,110 @@ elif [[ "$cmd" == "lvchange" ]]; then
get_active_mode
get_lease_offset
+ check_vg_start
+
+ if [[ "$active_mode" != "y" ]] && [[ "$active_mode" != "n" ]]; then
+ # non-activation related change to vg
+ # are there other vg changes that would require vglk?
+ echo "no locks needed for this command, use lvchange directly"
+ exit 1
+ fi
+
+ if [[ "$active_mode" == "y" ]] && [[ "$lock_mode" == "" ]]; then
+ echo "lock mode required, use sanlvm --ex|sh for vg/lv activation"
+ exit 1
+ fi
+
+ if [[ "$active_mode" == "y" ]] && [[ "$lock_mode" != "--sh" ]] && [[ "$lock_mode" != "--ex" ]]; then
+ echo "invalid lock mode, use sanlvm --ex|sh for vg/lv activation"
+ exit 1
+ fi
+
+ if [[ "$active_mode" == "n" ]] && [[ "$lock_mode" != "" ]]; then
+ echo "no lock mode required for vg/lv deactivation"
+ exit 1
+ fi
+
+ if [[ "$lock_mode" == "--sh" ]]; then
+ suffix=":SH"
+ fi
+
+ sanlvmd=`pidof sanlvmd`
+
+ if [[ $? -ne 0 ]]; then
+ echo "sanlvmd not found, required for lv locks"
+ exit 1
+ fi
+
if [[ "$offset" == "" ]]; then
- echo "no activation lock, use lvchange directly"
+ echo "no lv activation lock for $vgname/$lvname, use lvchange directly"
exit 1
fi
- if [[ "$active_mode" == "y" ]]; then
+ lvchange
- if [[ "$lock_mode" == "--sh" ]]; then
- suffix=":SH"
- elif [[ "$lock_mode" == "--ex" ]]; then
- suffix=""
- else
- echo "use sanlvm --ex|sh for lv activation"
- exit 1
- fi
+ if [[ $? -ne 0 ]]; then
+ exit 1
+ fi
- sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset$suffix -p `pidof sanlvmd`
+ exit 0
- # lvchange activate
- shift
- lvm "$@"
+elif [[ "$cmd" == "vgchange" ]]; then
- elif [[ "$active_mode" == "n" ]]; then
+ get_args=$*
+ get_vg_name
+ get_active_mode
- # lock mode is not used for lvchange -an,
- # ignore it if one was provided
+ check_vg_start
- if [[ "$lock_mode" != "" ]]; then
- shift
- fi
+ if [[ "$active_mode" != "y" ]] && [[ "$active_mode" != "n" ]]; then
+ # non-activation related change to vg
+ # are there other vg changes that would require vglk?
+ echo "no locks needed for this command, use vgchange directly"
+ exit 1
+ fi
- # lvchange deactivate
- lvm "$@"
+ if [[ "$active_mode" == "y" ]] && [[ "$lock_mode" == "" ]]; then
+ echo "lock mode required, use sanlvm --ex|sh for vg/lv activation"
+ exit 1
+ fi
- sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd`
- else
- # non-activation related change to lv
- # I don't know of any lv changes that would require either
- # vglk or the lv lock
+ if [[ "$active_mode" == "y" ]] && [[ "$lock_mode" != "--sh" ]] && [[ "$lock_mode" != "--ex" ]]; then
+ echo "invalid lock mode, use sanlvm --ex|sh for vg/lv activation"
+ exit 1
+ fi
- echo "no locks needed for this command"
- lvm "$@"
+ if [[ "$active_mode" == "n" ]] && [[ "$lock_mode" != "" ]]; then
+ echo "no lock mode required for vg/lv deactivation"
+ exit 1
fi
+ if [[ "$lock_mode" == "--sh" ]]; then
+ suffix=":SH"
+ fi
+
+ sanlvmd=`pidof sanlvmd`
+
+ if [[ $? -ne 0 ]]; then
+ echo "sanlvmd not found, required for lv locks"
+ exit 1
+ fi
+
+ for lvname in `lvs $vgname --noheadings -o lv_name`; do
+ if [[ "$lvname" == "leases" ]]; then
+ continue
+ fi
+
+ get_lease_offset
+
+ if [[ "$offset" == "" ]]; then
+ echo "no lv activation lock for $vgname/$lvname, use lvchange directly"
+ continue
+ fi
+
+ lvchange
+ done
+
exit 0
elif [[ "$cmd" == "vgmerge" ]] || [[ "$cmd" == "vgsplit" ]] || [[ "$cmd" == "vgrename" ]] || [[ "$cmd" == "lvrename" ]]; then