linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfstests: fix device lookup in btrfs/003
@ 2013-09-03 22:19 Jeff Mahoney
  2013-09-04 23:24 ` Dave Chinner
  2013-09-06 14:03 ` David Sterba
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff Mahoney @ 2013-09-03 22:19 UTC (permalink / raw)
  To: Linux FS Maling List, linux-btrfs

The DEVHTL lookup in btrfs/003 is broken. It can only handle full LUNs and
not partitions on a disk.

Rather than returning 2:0:0:0 for /dev/sdc7, it returns 'block' and we see:
./common/rc: line 2081: /sys/class/scsi_device/block/device/delete:
No such file or directory

If we look up the device by dev instead of by name, we can handle working
with full disks and partitions more easily and get the ability to use
any device name rather than just the ones that match sysfs.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 tests/btrfs/003 |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

--- a/tests/btrfs/003
+++ b/tests/btrfs/003
@@ -137,9 +137,21 @@ _test_replace()
 	#pick the 2nd last disk 
 	ds=${devs[@]:$(($n-1)):1}
 
-	# retrive the HTL for this scsi disk
-	d=`echo $ds|cut -d"/" -f3`
-	DEVHTL=`ls -l /sys/class/block/${d} | rev | cut -d "/" -f 3 | rev`
+	HEXMAJOR="$(stat -c "%t" "$ds")"
+	HEXMINOR="$(stat -c "%T" "$ds")"
+	if [ -z "$HEXMAJOR" -o -z "$HEXMINOR" ]; then
+		_fail "tr: HEXMAJOR and/or HEXMINOR is unset for $ds"
+	fi
+
+	DIR="/sys/dev/block/$(( 0x$HEXMAJOR )):$(( 0x$HEXMINOR ))"
+
+	if [ -L "$DIR/device" ]; then # whole disk
+		DEVHTL="$(basename $(readlink "$DIR/device"))"
+	elif [ -L "$DIR/../device" ]; then # partition
+		DEVHTL="$(basename $(readlink "$DIR/../device"))"
+	else
+		_fail "tr: Can't locate device backing $ds"
+	fi
 
 	#fail disk
 	_devmgt_remove ${DEVHTL}

--
Jeff Mahoney
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-06 14:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-03 22:19 [PATCH] xfstests: fix device lookup in btrfs/003 Jeff Mahoney
2013-09-04 23:24 ` Dave Chinner
2013-09-06 14:03 ` David Sterba
2013-09-06 14:41   ` Jeff Mahoney

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).