diff options
-rw-r--r-- | tests/basic/quota-anon-fd-nfs.c | 47 | ||||
-rwxr-xr-x | tests/basic/quota-anon-fd-nfs.t | 32 | ||||
-rw-r--r-- | tests/include.rc | 2 | ||||
-rw-r--r-- | tests/nfs.rc | 6 |
4 files changed, 80 insertions, 7 deletions
diff --git a/tests/basic/quota-anon-fd-nfs.c b/tests/basic/quota-anon-fd-nfs.c new file mode 100644 index 00000000000..4cc0322e132 --- /dev/null +++ b/tests/basic/quota-anon-fd-nfs.c @@ -0,0 +1,47 @@ +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +int +file_write (char *filename, int filesize) +{ + int fd, ret = 0; + int i = 0; + char buf[1024] = {'a',}; + fd = open (filename, O_RDWR|O_CREAT|O_APPEND, 0600); + while (i < filesize) { + ret = write(fd, buf, sizeof(buf)); + if (ret == -1) { + close (fd); + return ret; + } + i += sizeof(buf); + ret = fdatasync(fd); + if (ret) { + close (fd); + return ret; + } + } + ret = close(fd); + if (ret) + return ret; + + return 0; +} + +int +main (int argc, char **argv) +{ + if (argc != 3) { + printf("Usage: %s <filename> <size(in bytes)>\n", argv[0]); + return EXIT_FAILURE; + } + + printf ("argv[2] is %s\n", argv[2]); + if (file_write (argv[1], atoi(argv[2])) == -1) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} diff --git a/tests/basic/quota-anon-fd-nfs.t b/tests/basic/quota-anon-fd-nfs.t index c0af918beb4..0f7a9aac52e 100755 --- a/tests/basic/quota-anon-fd-nfs.t +++ b/tests/basic/quota-anon-fd-nfs.t @@ -1,6 +1,14 @@ #!/bin/bash . $(dirname $0)/../include.rc +. $(dirname $0)/../nfs.rc + +function usage() +{ + local QUOTA_PATH=$1; + $CLI volume quota $V0 list $QUOTA_PATH | \ + grep "$QUOTA_PATH" | awk '{print $4}' +} cleanup; @@ -16,19 +24,29 @@ TEST $CLI volume set $V0 network.inode-lru-limit 1 TEST $CLI volume start $V0; EXPECT 'Started' volinfo_field $V0 'Status'; -TEST mount -t nfs localhost:/$V0 $N0 -sleep 10 +EXPECT_WITHIN $NFS_EXPORT_TIMEOUT 1 is_nfs_export_available +TEST mount_nfs $H0:/$V0 $N0 deep=/0/1/2/3/4/5/6/7/8/9 TEST mkdir -p $N0/$deep -TEST dd if=/dev/zero of=$N0/$deep/file bs=1K count=1M +TEST dd if=/dev/zero of=$N0/$deep/file bs=1k count=10240 TEST $CLI volume quota $V0 enable -TEST $CLI volume quota $V0 limit-usage / 2GB +TEST $CLI volume quota $V0 limit-usage / 20MB TEST $CLI volume quota $V0 soft-timeout 0 +TEST $CLI volume quota $V0 hard-timeout 0 + +TEST dd if=/dev/zero of=$N0/$deep/newfile_1 bs=512 count=10240 +# wait for write behind to complete. +EXPECT_WITHIN $MARKER_UPDATE_TIMEOUT "15.0MB" usage "/" + +# compile the test write program and run it +TEST $CC $(dirname $0)/quota-anon-fd-nfs.c -o $(dirname $0)/quota-anon-fd-nfs; +# Try to create a 100Mb file which should fail +TEST ! $(dirname $0)/quota-anon-fd-nfs $N0/$deep/newfile_2 "104857600" +TEST rm -f $N0/$deep/newfile_2 -sleep 10 -TEST dd if=/dev/zero of=$N0/$deep/newfile_1 bs=500 count=1M -TEST ! dd if=/dev/zero of=$N0/$deep/newfile_2 bs=1000 count=1M +## Before killing daemon to avoid deadlocks +umount_nfs $N0 cleanup; diff --git a/tests/include.rc b/tests/include.rc index 01da6041c65..8043d6090ad 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -8,6 +8,7 @@ H0=${H0:=`hostname --fqdn`}; # hostname DEBUG=${DEBUG:=0} # turn on debugging? statedumpdir=`gluster --print-statedumpdir`; # Default directory for statedump CLI="gluster --mode=script"; +CC=cc CHILD_UP_TIMEOUT=60 NFS_EXPORT_TIMEOUT=20 @@ -15,6 +16,7 @@ UMOUNT_TIMEOUT=5 PROCESS_UP_TIMEOUT=20 REBALANCE_TIMEOUT=120 HEAL_TIMEOUT=120 +MARKER_UPDATE_TIMEOUT=20 mkdir -p $B0; mkdir -p $M0 $M1; diff --git a/tests/nfs.rc b/tests/nfs.rc index e35b6852284..4b4a55e19e9 100644 --- a/tests/nfs.rc +++ b/tests/nfs.rc @@ -26,3 +26,9 @@ function mount_nfs () if [ ! -z "$opt" ]; then opt=",$opt"; fi mount -t nfs -o soft,intr,vers=3"$opt" $e $m } + +function umount_nfs () +{ + umount -f $1 + if [ $? -eq 0 ]; then echo "Y"; else echo "N"; fi +} |