diff options
author | David Teigland <teigland@redhat.com> | 2012-08-28 16:56:27 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2012-08-28 16:56:27 -0500 |
commit | db307d7727b9e218862ca27a56d7629f72fc237c (patch) | |
tree | 433796c468b344275011e07de49fb6e0023dd170 | |
parent | a444becc9744d04754a3d780df3884e71f18a84e (diff) | |
download | dct-stuff-db307d7727b9e218862ca27a56d7629f72fc237c.tar.gz dct-stuff-db307d7727b9e218862ca27a56d7629f72fc237c.tar.xz dct-stuff-db307d7727b9e218862ca27a56d7629f72fc237c.zip |
sanlvm: update
Signed-off-by: David Teigland <teigland@redhat.com>
-rwxr-xr-x | lvm/sanlvm | 197 |
1 files changed, 155 insertions, 42 deletions
@@ -1,12 +1,13 @@ #!/bin/bash host_id=0 -cmd="" -vgname="" -lvname="" -lock_mode="" -active_mode="" -offset="" +cmd= +vgname= +lvname= +lock_mode= +active_mode= +no_active= +offset= help() { vg="\$vg" @@ -33,6 +34,13 @@ help() { 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 vgcreate [options] $vg <devs>" + echo "sanlvm start" + echo "sanlvm [--na] lvcreate ..." + echo "sanlvm lvextend|lvreduce|lvremove ..." + echo "sanlvm --sh|ex lvchange -ay ..." + echo "sanlvm lvchange -an ..." exit 0 } @@ -42,13 +50,16 @@ fi arg1=$1 -if [[ $arg1 == "help" ]]; then +if [[ "$arg1" == "help" ]]; then help fi -if [[ $arg1 == "--ex" ]] || [[ $arg1 == "--sh" ]]; then +if [[ "$arg1" == "--ex" ]] || [[ "$arg1" == "--sh" ]]; then lock_mode=$arg1 cmd=$2 +elif [[ "$arg1" == "--na" ]]; then + no_active=$arg1 + cmd=$2 else cmd=$1 fi @@ -63,7 +74,7 @@ get_vg_name() { for i in $args do first=`expr substr $i 1 1` - if [ "$first" == "/" ]; then + if [[ "$first" == "/" ]]; then vgname=$prev return fi @@ -85,7 +96,7 @@ get_lv_name() { for i in $args do - if [[ $save_next == 1 ]] + if [[ $save_next == 1 ]]; then lvname=$i return fi @@ -104,7 +115,7 @@ get_vg_lv_name() { for i in $args do ind=`expr index $i /` - if [ "$ind" -gt 0 ]; then + if [ $ind -gt 0 ]; then lvname=`basename $i` dir=`dirname $i` vgname=`basename $dir` @@ -117,7 +128,7 @@ get_host_id() { host_id=`awk '/^host_id/ { print $2 }' < /etc/sanlvm.conf` if [[ $? -ne 0 ]]; then - echo no host_id found in /etc/sanlvm.conf + echo "no host_id found in /etc/sanlvm.conf" exit 1 fi } @@ -139,7 +150,7 @@ get_active_mode() { return fi - if [[ "$i" == "-a" ]] || [[ "$i == "--available" ]]; then + if [[ "$i" == "-a" ]] || [[ "$i" == "--available" ]]; then check_next=1 continue fi @@ -159,9 +170,13 @@ get_active_mode() { # get the offset value from the @sanlvm_offset_xyz tag on the lv get_lease_offset() { - tags=`lvs --noheadings -o lv_name,lv_tags $vgname | grep $lvname | awk '{print $2}'` + tags=`lvs --noheadings -o lv_name,lv_tags $vgname | grep $lvname | grep sanlvm_offset_ | awk '{print $2}'` - # FIXME: handle case where the lv has tags other than ours + if [[ "$tags" == "" ]]; then + return + fi + + # FIXME: handle case where the lv has tags in addition to ours offset=`echo $tags | cut --delimiter=_ --fields=3` } @@ -228,7 +243,7 @@ elif [[ "$cmd" == "_lvcreate" ]]; then # FIXME: get offset by searching leases lv for unused lease area offset=2097152 - # FIXME: add arg to disable activation + # FIXME: use recent lvcreate arg to disable activation # lvcreate lvm "$@" @@ -264,7 +279,13 @@ elif [[ "$cmd" == "lvcreate" ]]; then get_vg_name - sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c ./sanlvm _lvcreate "$@" + if [[ "$no_active" == "--na" ]]; then + echo "no activation lock" + shift + sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@" + else + sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c ./sanlvm _lvcreate "$@" + fi if [[ $? -ne 0 ]]; then exit 1 @@ -279,27 +300,56 @@ elif [[ "$cmd" == "_lvremove" ]]; then args=$* - get_vg_lv_name - get_lease_offset + vgname=$SANLVM_VGNAME + lvname=$SANLVM_LVNAME + offset=$SANLVM_OFFSET + + # refuse to remove the lv if the local + # host has the lv activated + + status=`sanlock client status | grep "r $vgname:$lvname"` - # lvremove, this will fail if the lv is in use + if [[ "$status" != "" ]]; then + echo "lv must be be deactivated before remove" + exit 1 + fi + + # acquire ex activation lock on the lv so + # we know that no hosts have it active + # FIXME: I don't think sanlock client acquire success/fail exit codes are always correct + + sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd` + + if [[ $? -ne 0 ]]; then + echo "lv lock failed, may be active on another host" + exit 1 + fi + + # lvremove lvm "$@" - # FIXME: release lv lease is there is one + sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd` - # FIXME: clear the lease area that was used for the lv activation - # lease, if there was one (there was an offset tag) + # 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 exit 0 elif [[ "$cmd" == "lvremove" ]]; then - # we need the multiple steps in _lvremove to all be wrapped in vglk - args=$* get_vg_lv_name + get_lease_offset - sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c ./sanlvm _lvremove "$@" + if [[ "$offset" == "" ]]; then + echo "no activation lock" + sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@" + else + export SANLVM_VGNAME=$vgname + export SANLVM_LVNAME=$lvname + export SANLVM_OFFSET=$offset + sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c ./sanlvm _lvremove "$@" + fi if [[ $? -ne 0 ]]; then exit 1 @@ -307,6 +357,67 @@ elif [[ "$cmd" == "lvremove" ]]; then exit 0 +elif [[ "$cmd" == "_lvextend" ]] || [[ "$cmd" == "_lvreduce" ]]; then + # wrapped by vglk + + shift + + args=$* + + vgname=$SANLVM_VGNAME + lvname=$SANLVM_LVNAME + offset=$SANLVM_OFFSET + + # refuse to extend/reduce the lv if the local + # host has the lv activated + # 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" + exit 1 + fi + + # 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` + + if [[ $? -ne 0 ]]; then + echo "lv lock failed, may be active on another host" + exit 1 + fi + + # lvextend/lvreduce + lvm "$@" + + sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd` + + exit 0; + + +elif [[ "$cmd" == "lvextend" ]] || [[ "$cmd" == "lvreduce" ]]; then + args=$* + + get_vg_lv_name + get_lease_offset + + if [[ "$offset" == "" ]]; then + echo "no activation lock" + sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@" + else + export SANLVM_VGNAME=$vgname + export SANLVM_LVNAME=$lvname + export SANLVM_OFFSET=$offset + sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm _$cmd "$@" + fi + + if [[ $? -ne 0 ]]; then + exit 1 + fi + + exit 0 elif [[ "$cmd" == "lvchange" ]]; then # sanlvmd is a process that sanlock views as owning the lv @@ -322,6 +433,11 @@ elif [[ "$cmd" == "lvchange" ]]; then get_active_mode get_lease_offset + if [[ "$offset" == "" ]]; then + echo "no activation lock, use lvchange directly" + exit 1 + fi + if [[ "$active_mode" == "y" ]]; then # acquire lease, then activate @@ -337,34 +453,31 @@ elif [[ "$cmd" == "lvchange" ]]; then sanlock client acquire -r $vgname:$lvname:/dev/$vgname/leases:$offset$suffix -p `pidof sanlvmd` # lvchange activate + shift lvm "$@" elif [[ "$active_mode" == "n" ]]; then # deactivate, then release lease + # lock mode is not used for lvchange -an, and shouldn't be + # provided, but ignore it if it is + + if [[ "$lock_mode" != "" ]]; then + shift + fi + # lvchange deactivate lvm "$@" sanlock client release -r $vgname:$lvname:/dev/$vgname/leases:$offset -p `pidof sanlvmd` else # non-activation related change to lv - # FIXME: do we also want to take ex lv lease? - sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@ - fi - - exit 0 - -elif [[ "$cmd" == "lvextend" ]] || [[ "$cmd" == "lvreduce" ]]; then - args=$* - - get_vg_lv_name - - # FIXME: do we also want to take ex lv lease? + # I don't know of any lv changes that would require either + # vglk or the lv lock + # sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@ - sanlock command -r $vgname:vglk:/dev/$vgname/leases:1048576 -c /sbin/lvm "$@" - - if [[ $? -ne 0 ]]; then - exit 1 + echo "no locks needed for this command" + lvm "$@" fi exit 0 |