lvm-manage 909 B

123456789101112131415161718192021222324252627
  1. # This is to include LVM-requiring tests in Travis-CI
  2. if [ "$1" = "setup-lvm" -a -n "$2" ]; then
  3. POOL_PATH=$2
  4. VG_NAME=`echo $POOL_PATH | cut -f 1 -d /`
  5. POOL_NAME=`echo $POOL_PATH | cut -f 2 -d /`
  6. if lvs $VG_NAME >/dev/null 2>&1 || lvs $POOL_PATH >/dev/null 2>&1; then
  7. echo "WARNING: either VG '$VG_NAME' or thin pool '$POOL_PATH' already exists, not reusing" >&2
  8. exit 1
  9. fi
  10. set -e
  11. loop_file=`mktemp`
  12. truncate -s 1G $loop_file
  13. loop_dev=`losetup -f --show $loop_file`
  14. # auto cleanup
  15. rm -f $loop_file
  16. vgcreate "$VG_NAME" $loop_dev
  17. lvcreate --thinpool "$POOL_NAME" --type thin-pool -L 960M "$VG_NAME"
  18. exit 0
  19. elif [ "$1" = "cleanup-lvm" -a -n "$2" ]; then
  20. VG_NAME=`echo $2 | cut -f 1 -d /`
  21. set -e
  22. pvs=`vgs --noheadings -o pv_name $VG_NAME | tr -d ' '`
  23. lvremove -f "$2"
  24. vgremove "$VG_NAME"
  25. losetup -d $pvs
  26. exit 0
  27. fi