#!/bin/sh
# PCP QA Test No. 1532
# Test Linux ZFS PMDA against a live ZFS pool - part A (older stats files)
# See also qa/1309 for part B
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

[ $PCP_PLATFORM = linux ] || _notrun "Linux ZFS PMDA is Linux-specific (uses procfs)"
grep -q zfs /proc/filesystems || _notrun "ZFS filesystem unsupported by the running kernel"
which zpool > /dev/null || _notrun "zpool not found, please check your OpenZFS installation"

for file in arcstats dmu_tx xuio_stats zfetchstats zil
do
    [ -f /proc/spl/kstat/zfs/$file ] || _notrun "/proc/spl/kstat/zfs/$file is missing"
done

status=1
$sudo rm -rf $tmp.* $seq.full
trap "cd $here; $sudo rm -rf $tmp.*; exit \$status" 0 1 2 3 15

_filter()
{
    $here/src/sortinst \
    | sed -e '/inst /s/\[[01] /[0-or-1 /'
}

pmda=$PCP_PMDAS_DIR/zfs/pmda_zfs.so,zfs_init
pmns=$PCP_VAR_DIR/pmns/root_zfs
opts="-L -K clear -K add,153,$pmda -n $pmns"
export ZFS_PATH=
poolname=pmdazfs_test
root=$tmp.root
$sudo rm -f $PCP_VAR_DIR/config/pmda/153.*
$sudo rm -fr $root
mkdir $root || _fail "root in use when processing $tgz"
$sudo dd if=/dev/zero of=$root/disk.img bs=1024 count=65536 > /dev/null 2>&1
$sudo zpool create $poolname $root/disk.img
echo "== Checking metric count for ZFS ARC"
pminfo $opts -f zfs.arc |  grep '^ \+value ' | wc -l 2>&1
echo "== Checking metric count for ZFS DMU TX"
pminfo $opts -f zfs.dmu_tx |  grep '^ \+value ' | wc -l 2>&1
echo "== Checking metric count for ZFS XUIO"
pminfo $opts -f zfs.xuio |  grep '^ \+value ' | wc -l 2>&1
echo "== Checking metric count for ZFS ZFetch"
pminfo $opts -f zfs.zfetch |  grep '^ \+value ' | wc -l 2>&1
echo "== Checking metric count for ZFS ZIL"
pminfo $opts -f zfs.zil |  grep '^ \+value ' | wc -l 2>&1
echo "== Checking metric count for ZFS pool $poolname"
pminfo $opts -f zfs.pool | grep $poolname | wc -l 2>&1
echo && echo "== done" && echo
$sudo zpool destroy $poolname
$sudo rm $root/disk.img
# success, all done
status=0
exit
