#!/bin/bash

. $(dirname $0)/../include.rc

cleanup;

# sleeps till the portmap registration of nfs services is done
# NOTE: may take some time for nfs to export all volumes, hence,
# showmount -e succeeding does NOT mean all volumes are available
# for mount. In this case, its a single single-brick volume,
# so no problem.
sleep_till_nfs_awakens ()
{
    while true
    do
        showmount -e 0 > /dev/null 2>&1;
        if [ $? -eq 0 ]; then
            return;
        else
            sleep 1;
        fi
    done
}

#1
TEST glusterd
TEST pidof glusterd

# gluster --mode=script volume create patchy host1.localdomain:/d/backends/patchy
TEST $CLI volume create $V0 $H0:$B0/$V0
TEST $CLI volume start $V0
sleep_till_nfs_awakens

# mount -t nfs -o vers=3,nolock,soft,intr host1.localdomain:/patchy /mnt/nfs/0
TEST mount -t nfs -o vers=3,soft,intr $H0:/$V0 $N0

dd if=/dev/random bs=1024 count=1 of=$N0/testfile 
TEST cp -f $N0/testfile $N0/testfile.2 
TEST chown root:root $N0/testfile
TEST chmod 0000 $N0/testfile
TEST chmod +srx $N0/testfile 
TEST mknod $N0/testdev c 1 3
TEST chmod 0755 $N0/testfile 
TEST ln -f -P $N0/testfile $N0/testfile.hardlink 
TEST ln -f -s $N0/testfile $N0/testfile.softlink
TEST cat $N0/testfile.softlink $N0/testfile.hardlink
TEST find $N0/ -type f -ls 
TEST mv $N0/testfile.hardlink $N0/testfile.hardlink.mv 
TEST rm -f $N0/testfile.hardlink.mv $N0/testfile.softlink
TEST cp $N0/testfile.2 /dev/null
TEST mkdir $N0/testdir 
TEST getfacl $N0/testdir 
TEST setfacl -m user:root:rwx $N0/testdir
TEST setfacl -d -m group:root:r-x $N0/testdir 

TEST umount $N0 
TEST $CLI volume stop $V0 
TEST $CLI volume delete $V0 
cleanup