quota_remount_test01.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) Jan Kara <jack@suse.cz>, 2008 ##
  5. ## Copyright (c) International Business Machines Corp., 2009 ##
  6. ## ##
  7. ## This program is free software; you can redistribute it and#or modify ##
  8. ## it under the terms of the GNU General Public License as published by ##
  9. ## the Free Software Foundation; either version 2 of the License, or ##
  10. ## (at your option) any later version. ##
  11. ## ##
  12. ## This program is distributed in the hope that it will be useful, but ##
  13. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  14. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  15. ## for more details. ##
  16. ## ##
  17. ## You should have received a copy of the GNU General Public License ##
  18. ## along with this program; if not, write to the Free Software ##
  19. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  20. ## ##
  21. ################################################################################
  22. # ##
  23. # File : quota_remount_test01.sh ##
  24. # ##
  25. # Description: Test whether kernel properly supports remounting read-only ##
  26. # with quota. This feature was added in kernel 2.6.26. Please ##
  27. # see: http://kernelnewbies.org/Linux_2_6_26, and ##
  28. # http://git.kernel.org/git/?p=linux/kernel/git/torvalds/ ##
  29. # linux-2.6.git;a=commit; ##
  30. # h=0ff5af8340aa6be44220d7237ef4a654314cf795 ##
  31. # for more info. ##
  32. # ##
  33. # Author: Jan Kara <jack@suse.cz>, ##
  34. # ##
  35. # History: Sep 18 2008 - Created - Jan Kara <jack@suse.cz>. ##
  36. # Feb 17 2009 - Ported to LTP, ##
  37. # Subrata Modak <subrata@linux.vnet.ibm.com> ##
  38. ################################################################################
  39. export TCID=quota_remount_test01
  40. export TST_TOTAL=1
  41. export TST_COUNT=0
  42. if [ -z $TMPDIR ]
  43. then
  44. TMPDIR=/tmp
  45. fi
  46. MNTDIR=$TMPDIR/mnt
  47. if tst_kvcmp -lt "2.6.25"; then
  48. tst_resm TCONF "Remounting with quotas enabled is not supported!"
  49. tst_resm TCONF "You should have kernel 2.6.26 and above running....."
  50. exit 32
  51. fi
  52. if [ ! -d /proc/sys/fs/quota ]; then
  53. tst_resm TCONF "Quota not supported in kernel!"
  54. exit 0
  55. fi
  56. if ! command -v quotacheck > /dev/null 2>&1; then
  57. tst_resm TCONF "'quotacheck' not found"
  58. exit 0
  59. fi
  60. if ! command -v quotaon > /dev/null 2>&1; then
  61. tst_resm TCONF "'quotaon' not found"
  62. exit 0
  63. fi
  64. die()
  65. {
  66. echo >&2 $2
  67. umount 2>/dev/null $MNTDIR
  68. rm 2>/dev/null $IMAGE
  69. rmdir 2>/dev/null $MNTDIR
  70. tst_resm TFAIL "Quota on Remount Failed"
  71. exit $1
  72. }
  73. cd $TMPDIR || die 2 "Cannot cd to $TMPDIR"
  74. IMAGE=ltp-$$-fs-image
  75. dd if=/dev/zero of=$IMAGE bs=4096 count=8000 2>/dev/null || die 2 "Cannot create filesystem image"
  76. mkfs.ext3 -q -F -b 4096 $IMAGE || die 2 "Could not create the filesystem"
  77. mkdir $MNTDIR || die 2 "Could not create the mountpoint"
  78. mount -t ext3 -o loop,usrquota,grpquota $IMAGE $MNTDIR || die 2 "Could not mount the filesystem"
  79. tst_resm TINFO "Successfully mounted the File System"
  80. # some distros (CentOS 6.x, for example) doesn't permit creating
  81. # of quota files in a directory with SELinux file_t type
  82. if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
  83. chcon -t tmp_t $MNTDIR || die 2 "Could not change SELinux file type"
  84. tst_resm TINFO "Successfully changed SELinux file type"
  85. fi
  86. quotacheck -cug $MNTDIR || die 2 "Could not create quota files"
  87. tst_resm TINFO "Successfully Created Quota Files"
  88. quotaon -ug $MNTDIR || die 2 "Could not turn quota on"
  89. tst_resm TINFO "Successfully Turned on Quota"
  90. echo "blah" >$MNTDIR/file || die 2 "Could not write to the filesystem"
  91. tst_resm TINFO "Successfully wrote to the filesystem"
  92. # Get current quota usage
  93. BLOCKS=`quota -f $MNTDIR -v -w | tail -n 1 | sed -e 's/ *[^ ]* *\([0-9]*\) .*/\1/'`
  94. mount -o remount,ro $MNTDIR || die 1 "Could not remount read-only"
  95. tst_resm TINFO "Successfully Remounted Read-Only FS"
  96. mount -o remount,rw $MNTDIR || die 2 "Could not remount read-write"
  97. tst_resm TINFO "Successfully Remounted Read-Write FS"
  98. rm $MNTDIR/file
  99. # Get quota usage after removing the file
  100. NEWBLOCKS=`quota -f $MNTDIR -v -w | tail -n 1 | sed -e 's/ *[^ ]* *\([0-9]*\) .*/\1/'`
  101. # Has quota usage changed properly?
  102. if [ $BLOCKS -eq $NEWBLOCKS ]; then
  103. die 1 "Usage did not change after remount"
  104. fi
  105. tst_resm TINFO "Usage successfully Changed after Remount"
  106. tst_resm TPASS "Quota on Remount Successfull"
  107. umount $MNTDIR || die 2 "Could not umount $MNTDIR"
  108. rmdir $MNTDIR || die 2 "Could not remove $MNTDIR"
  109. rm $IMAGE
  110. exit 0