myfunctions-io.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2 of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public
  14. # License along with this program; if not, write to the
  15. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. # Boston, MA 021110-1307, USA.
  17. #
  18. # Copyright (C) 2008 Andrea Righi <righi.andrea@gmail.com>
  19. #
  20. # usage . myfunctions.sh
  21. setup()
  22. {
  23. # create testcase cgroups
  24. if [ -e /dev/blockioctl ]; then
  25. echo "WARN: /dev/blockioctl already exist! overwriting."
  26. cleanup
  27. fi
  28. mkdir /dev/blockioctl
  29. mount -t cgroup -o blockio cgroup /dev/blockioctl
  30. if [ $? -ne 0 ]; then
  31. echo "ERROR: could not mount cgroup filesystem " \
  32. " on /dev/blockioctl. Exiting test."
  33. cleanup
  34. exit 1
  35. fi
  36. for i in `seq 1 3`; do
  37. if [ -e /dev/blockioctl/cgroup-$i ]; then
  38. rmdir /dev/blockioctl/cgroup-$i
  39. echo "WARN: earlier cgroup-$i found and removed"
  40. fi
  41. mkdir /dev/blockioctl/cgroup-$i
  42. if [ $? -ne 0 ]; then
  43. echo "ERROR: could not create cgroup-$i" \
  44. "Check your permissions. Exiting test."
  45. cleanup
  46. exit 1
  47. fi
  48. done
  49. }
  50. cleanup()
  51. {
  52. echo "Cleanup called"
  53. for i in `seq 1 3`; do
  54. rmdir /dev/blockioctl/cgroup-$i
  55. rm -f /tmp/cgroup-$i.out
  56. done
  57. umount /dev/blockioctl
  58. rmdir /dev/blockioctl
  59. }