linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: xfs@oss.sgi.com
Cc: Josef Bacik <jbacik@fusionio.com>, linux-btrfs@vger.kernel.org
Subject: [patch 2/3] xfstests: btrfs/022: test sysfs exports of allocation and device membership info
Date: Tue, 29 Oct 2013 15:26:55 -0400	[thread overview]
Message-ID: <20131029192919.950862785@suse.com> (raw)
In-Reply-To: 20131029192653.194827430@suse.com

This tests the sysfs publishing for btrfs allocation and device
membership info under a number of different layouts, similar to the
btrfs replace test. We test the allocation files only for existence and
that they contain numerical values. We test the device membership
by mapping the devices used to create the file system to sysfs paths
and matching them against the paths used for the device membership
symlinks.

Since this is a new feature, it passes on kernels without
a /sys/fs/btrfs/<fsid> directory.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 common/config       |    1 
 tests/btrfs/022     |  190 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/022.out |    2 
 tests/btrfs/group   |    1 
 4 files changed, 194 insertions(+)
 create mode 100755 tests/btrfs/022
 create mode 100644 tests/btrfs/022.out

--- a/common/config	2013-10-29 15:06:44.556749046 -0400
+++ b/common/config	2013-10-29 15:07:27.952031225 -0400
@@ -209,6 +209,7 @@ case "$HOSTOS" in
         export MKFS_UDF_PROG="`set_prog_path mkudffs`"
         export MKFS_BTRFS_PROG="`set_btrfs_mkfs_prog_path_with_opts`"
         export BTRFS_UTIL_PROG="`set_prog_path btrfs`"
+        export UDEVADM_PROG="`set_prog_path udevadm`"
         export BTRFS_SHOW_SUPER_PROG="`set_prog_path btrfs-show-super`"
         export XFS_FSR_PROG="`set_prog_path xfs_fsr`"
         export MKFS_NFS_PROG="false"
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/tests/btrfs/022	2013-10-29 15:07:27.980030752 -0400
@@ -0,0 +1,190 @@
+#! /bin/bash
+# FS QA Test No. 022
+#
+# Test of the btrfs sysfs publishing
+#
+#-----------------------------------------------------------------------
+# Copyright (C) 2013 SUSE.  All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "== QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_need_to_be_root
+_supported_fs btrfs
+_require_scratch
+_require_scratch_dev_pool
+_require_command $UDEVADM_PROG
+
+rm -f $seqres.full
+rm -f $tmp.tmp
+
+check_file() {
+	local file=$1
+	base="$(echo "$file" | sed -e 's#/sys/fs/btrfs/[0-9a-f-][0-9a-f-]*/##')"
+	if [ ! -f "$file" ]; then
+		echo "$base missing."
+		return 0
+	else
+		value="$(cat $file)"
+		if [ -n "$(echo $value | tr -d 0-9)" ]; then
+			echo "ERROR: $base: numerical value expected" \
+			     "(got $value)"
+			return 0
+		fi
+	fi
+	return 1
+}
+
+check_chunk() {
+	path=$1
+	mkfs_options=$2
+	error=false
+
+	chunktype=$(basename $path)
+	if [ ! -d "$path" ]; then
+		echo "No $chunktype directory."
+		exit 1
+	fi
+
+	for file in bytes_may_use bytes_pinned bytes_reserved bytes_used \
+		    disk_total flags total_bytes total_bytes_pinned; do
+		if check_file "$path/$file"; then
+			error=true
+		fi
+	done
+
+	if [ "$chunktype" = "data" -o "$chunktype" = "mixed" ]; then
+		opt="-d"
+	elif [ "$chunktype" = "metadata" -o "$chunktype" = "system" ]; then
+		opt="-m"
+	fi
+
+	profile=$(echo $mkfs_options | sed -e "s/.*$opt \([[:alnum:]]*\).*/\1/")
+	if [ ! -d "$path/$profile" ]; then
+		echo "No $profile dir for $chunktype"
+		exit 1
+	fi
+
+	for file in total_bytes used_bytes; do
+		if check_file $path/$profile/$file; then
+			error=true
+		fi
+	done
+
+	$error && exit 1
+}
+
+check_dev_link() {
+	local dev=$1
+	DEV="/sys/$($UDEVADM_PROG info --query=path $dev)"
+	DEV="$(readlink -f $DEV)"
+	found=false
+	for link in $sysfs_base/devices/*; do
+		LINK="$(readlink -f $link)"
+		if [ "$LINK" = "$DEV" ]; then
+			found=true
+			break
+		fi
+	done
+	if ! $found; then
+		echo "Symlink for $dev missing in $sysfs_base/devices"
+		return 1
+	fi
+	return 0
+}
+
+workout()
+{
+	local mkfs_options="$1"
+	local num_devs4raid="$2"
+	local fssize
+
+	if [ "`echo $SCRATCH_DEV_POOL | wc -w`" -lt $num_devs4raid ]; then
+		echo "Skip workout $1 $2 $3 $4"
+		echo "Too few devices in SCRATCH_DEV_POOL $SCRATCH_DEV_POOL," \
+		     "required: $num_devs4raid"
+		echo "Skip workout $1 $2 $3 $4" >> $seqres.full
+		echo "Too few devices in SCRATCH_DEV_POOL $SCRATCH_DEV_POOL," \
+		     "required: $num_devs4raid" >> $seqres.full
+		return 0
+	fi
+
+	used_devs=$(echo $SCRATCH_DEV_POOL|tr '\t' ' '| \
+		    cut -d ' ' -f 1-$num_devs4raid)
+
+	_scratch_mkfs $mkfs_options $used_devs >> $seqres.full 2>&1 || \
+	_fail "mkfs failed"
+
+	_scratch_mount
+
+	# Check allocation
+	sysfs_base="/sys/fs/btrfs/$(_btrfs_get_fsid $SCRATCH_DEV)"
+
+	# Feature isn't present for testing
+	if [ ! -d "$sysfs_base" ]; then
+		echo "Skipping sysfs test: $sysfs_base not found." \
+		     >> $seqres.full
+		return
+	fi
+
+	mixed=false
+	case "$mkfs_options" in
+	*-M*)
+		mixed=true;
+		;;
+	esac
+
+	check_chunk "$sysfs_base/allocation/system" "$mkfs_options"
+	if $mixed; then
+		check_chunk "$sysfs_base/allocation/mixed" "$mkfs_options"
+	else
+		check_chunk "$sysfs_base/allocation/data" "$mkfs_options"
+		check_chunk "$sysfs_base/allocation/metadata" "$mkfs_options"
+	fi
+
+	for dev in $used_devs; do
+		check_dev_link $dev || exit 1
+	done
+
+	umount $SCRATCH_MNT > /dev/null 2>&1
+}
+
+workout "-m single -d single" 1
+workout "-m single -d single -M" 1
+workout "-m dup -d single" 1
+workout "-m dup -d dup -M" 1
+workout "-m raid0 -d raid0" 2
+workout "-m raid1 -d raid1" 2
+workout "-m raid5 -d raid5" 2
+workout "-m raid6 -d raid6" 3
+workout "-m raid10 -d raid10" 4
+
+echo "Silence is golden"
+status=0
+exit
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/tests/btrfs/022.out	2013-10-29 15:07:27.980030752 -0400
@@ -0,0 +1,2 @@
+== QA output created by 022
+Silence is golden
--- a/tests/btrfs/group	2013-10-29 15:07:23.292109479 -0400
+++ b/tests/btrfs/group	2013-10-29 15:09:25.545980210 -0400
@@ -24,3 +24,4 @@
 019 auto quick
 020 auto quick
 021 auto quick
+022 auto



  parent reply	other threads:[~2013-10-29 19:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-29 19:26 [patch 0/3] xfstests: for btrfs publishing/export patchset (v4) Jeff Mahoney
2013-10-29 19:26 ` [patch 1/3] xfstests: btrfs/021: test global metadata reservation reporting Jeff Mahoney
2013-10-29 19:26 ` Jeff Mahoney [this message]
2013-10-29 19:26 ` [patch 3/3] xfstests: btrfs/023,024,025: test feature ioctl and sysfs interfaces Jeff Mahoney
  -- strict thread matches above, loose matches on Subject: below --
2013-10-28 20:47 [patch 0/3] xfstests: for btrfs publishing/export patchset (v3) Jeff Mahoney
2013-10-28 20:47 ` [patch 2/3] xfstests: btrfs/022: test sysfs exports of allocation and device membership info Jeff Mahoney
2013-10-28 19:52 [PATCH 0/3] xfstests: for btrfs publishing/export patchset (v2) Jeff Mahoney
2013-10-28 19:52 ` [PATCH 2/3] xfstests: btrfs/022: test sysfs exports of allocation and device membership info Jeff Mahoney
2013-10-28 20:17   ` Jeff Mahoney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131029192919.950862785@suse.com \
    --to=jeffm@suse.com \
    --cc=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).