Skip to contentSkip to conversation

xfstests: fix device lookup in btrfs/003

PATCH In review Jeff Mahoney 3 participants 4 messages Sep 3, 2013 – Sep 6, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfstests: fix device lookup in btrfs/003

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.

---
 tests/btrfs/003 |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tests/btrfs/003 +15 -3
@@ -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

#1 lore raw

Add [email protected] to the cc list.

Quoted 52 lines · Jeff Mahoney

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.

---
 tests/btrfs/003 |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tests/btrfs/003 +15 -4
@@ -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
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw
In reply to Jeff Mahoney
Quoted 26 lines · Jeff Mahoney

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.

tests/btrfs/003 +8 -3
@@ -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 ))"
+

tests/btrfs/003 _test_replace() · line 157

Quoted 10 lines
tests/btrfs/003 +7 -0
+	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}

The test assumes tha SCRATCH_DEV_POOL consists of standalone devices and more strongly that they can be removed from the system by

$ echo 1 > /sys/class/scsi_device/sdx/device/delete

via _devmgt_remove. Ordinary sdX devices are ok, but eg. MD devices are not because they do not have a corresponding "2:0:0:0"-like entry (I haven't checked device-mapper devices).

Looks like the tests have to do more fine grained checks of the devices in SCRATCH_DEV_POOL because eg. the 'device replace' test btrfs/011 is just fine with partitions.

david

#3 lore raw
Quoted 43 lines · David Sterba
Quoted 26 lines · Jeff Mahoney

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.

tests/btrfs/003 +8 -3
@@ -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 ))"
+

tests/btrfs/003 _test_replace() · line 157

Quoted 10 lines
tests/btrfs/003 +7 -0
+	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}

The test assumes tha SCRATCH_DEV_POOL consists of standalone devices and more strongly that they can be removed from the system by

$ echo 1 > /sys/class/scsi_device/sdx/device/delete
Quoted 7 lines

via _devmgt_remove. Ordinary sdX devices are ok, but eg. MD devices are not because they do not have a corresponding "2:0:0:0"-like entry (I haven't checked device-mapper devices).

Looks like the tests have to do more fine grained checks of the devices in SCRATCH_DEV_POOL because eg. the 'device replace' test btrfs/011 is just fine with partitions.

Yeah. It doesn't work with any type of device that doesn't present a SCSI-style host interface with a delete sysfs entry. I wasn't looking to make it work everywhere, just allow it to work with the types of devices it was originally targeting in a slightly less fragile way.

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs