All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Turmel <philip@turmel.org>
To: Leslie Rhorer <lrhorer@satx.rr.com>
Cc: linux-raid@vger.kernel.org
Subject: Re: Determining which spindle is out of order
Date: Sat, 06 Nov 2010 11:12:08 -0400	[thread overview]
Message-ID: <4CD57048.4020107@turmel.org> (raw)
In-Reply-To: <30.2B.19545.E5C25DC4@cdptpa-omtalb.mail.rr.com>

On 11/06/2010 06:22 AM, Leslie Rhorer wrote:
> 
> 
>> -----Original Message-----
>> From: linux-raid-owner@vger.kernel.org [mailto:linux-raid-
>> owner@vger.kernel.org] On Behalf Of Phil Turmel
>> Sent: Wednesday, November 03, 2010 4:55 PM
>> To: Nat Makarevitch
>> Cc: linux-raid@vger.kernel.org
>> Subject: Re: Determining which spindle is out of order
>>
>> On 11/3/2010 2:13 PM, Nat Makarevitch wrote:
>>> Hi,
>>>
>>> After a spindle (physical hard disk, a "drive") failure in a "md" RAID
>> array,
>>> how can we know which spindle must be replaced?
>>>
>>> We want to avoid extracting a working spindle by mistakenly thinking it
>> is the
>>> faulty one...
>>
>> I wrote a little script that would tell me device name and serial number
>> for each host port on my motherboard, along with anything else that lists
>> a scsi host in sysfs.  Output like so:
>>
>> Controller device @ pci0000:00/0000:00:1c.1/0000:06:00.0 [ahci]
>>   RAID bus controller: Marvell Technology Group Ltd. 88SE6145 SATA II PCI-
>> E controller (rev a1)
>>     host4: [Empty]
>>     host5: /dev/sdd ATA WDC WD5000AAKS-7 {SN: WD-WMAWF1370668}
>>     host6: [Empty]
>>     host7: [Empty]
>>     host8: [Empty]
>> Controller device @ pci0000:00/0000:00:1f.1 [ata_piix]
>>   IDE interface: Intel Corporation 82801G (ICH7 Family) IDE Controller
>> (rev 01)
>>     host9: [Empty]
>>     host10: [Empty]
>> Controller device @ pci0000:00/0000:00:1f.2 [ahci]
>>   SATA controller: Intel Corporation 82801GR/GH (ICH7 Family) SATA AHCI
>> Controller (rev 01)
>>     host0: /dev/sda ATA ST31000333AS {SN: 9TE1LTW0}
>>     host1: /dev/sdb ATA ST31000333AS {SN: 9TE1MAJT}
>>     host2: /dev/sdc ATA ST31000333AS {SN: 9TE1MV1R}
>>     host3: /dev/sr0 HL-DT-ST BD-RE GBW-H20L
>>
>> Shows me my empty ports, too.  As long as I keep my cables straight to my
>> hot-swap bays, getting the right drive is a snap.
> 
> 	I haven't had a chance to dig into the script, but it doesn't
> produce any output when I run it on one of my servers, and on the other one
> it produces errors on line 7, but otherwise seems to work.
> 

Thanks for the feedback.  The script only looks in sysfs for controllers
implementing the scsi_host interface.  So it won't pick up anything using
the legacy IDE interface.  If that's not the case on the first server, I'd
like to see lspci -vvv for the controller in question.

As for the errors on line #7, that's likely to be the whitespace problem that
Roman pointed out.  Based on his comment, I've adjusted the script to be more
robust (a little faster, too).  Please give it a try:

#! /bin/bash
#
# Examine specific system host devices to identify the drives attached
#

function describe_controller () {
	unset SUBSYSTEM PCI_ID DEVICE PCI_SLOT_NAME Manufacturer Product Serial
	eval `udevadm info --query=all --path="$1" | \
		sed -rn -e 's/^E: (\w+)=(.+)$/\1="\2"/;T;p'`
	echo "Controller device @ ${1##/sys/devices/} [$DRIVER]"
	if [[ -n "$PCI_SLOT_NAME" ]] ; then
		echo -e "  `lspci -s $PCI_SLOT_NAME |cut -d\  -f2-`"
		return
	fi
	if [[ "${MODALIAS:0:4}" == "usb:" ]] ; then
		eval `lsusb -D ${DEVICE/proc/dev/} | \
			sed -rn -e 's% *i(Manufacturer|Product|Serial) +[0-9]+ +(.+) *$%\1="\2"%;T;p'`
		echo -e "  [$Manufacturer] $Product {SN: $Serial}"
		return
	fi
	echo -e "  $SUBSYSTEM $MODALIAS"
}

function describe_device () {
	targ=${1%/block/*}
	vnd="`cat $targ/vendor`"
	mdl=`cat $targ/model`
	rdev=`readlink -f "$1"`
	if [[ -d $rdev ]] ; then
		bdev="`basename $rdev`"
		sn="`sginfo -s /dev/$bdev | \
			sed -rn -e \"/Serial Number/{s%^.+' *(.+) *'.*\\\$%\\\\1%;p;q}\"`" &>/dev/null
		if [[ -n "$sn" ]] ; then
			echo -e "    $bhost: `echo /dev/$bdev $vnd $mdl {SN: $sn}`"
		else
			echo -e "    $bhost: `echo /dev/$bdev $vnd $mdl`"
		fi
	else
		echo -e "    $bhost: Unknown $rdev"
	fi
}

function check_host () {
	local found=0
	local pController=
	while read shost ; do
		host=`dirname "$shost"`
		controller=`dirname "$host"`
		bhost=`basename "$host"`
		if [[ "$controller" != "$pController" ]] ; then
			pController="$controller"
			describe_controller "$controller"
		fi
		for dev in $host/target*/*/block/* ; do
			if [[ "${dev: -1}" == '*' ]] ; then
				echo -e "    $bhost: [Empty]"
			else
				describe_device "$dev"
			fi
		done
	done
}

find /sys/devices/ -name scsi_host |check_host

  reply	other threads:[~2010-11-06 15:12 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-03 14:13 Determining which spindle is out of order Nat Makarevitch
2010-11-03 14:38 ` Roman Mamedov
2010-11-03 15:17   ` Graham Mitchell
2010-11-03 16:05     ` Roman Mamedov
2010-11-03 19:00       ` Jon Hardcastle
2010-11-03 14:43 ` John Robinson
2010-11-03 14:45 ` Tim Small
2010-11-03 15:59   ` Jon Hardcastle
2010-11-03 17:17     ` Bill Davidsen
2010-11-03 20:03       ` Tim Small
2010-11-03 15:29 ` Mikael Abrahamsson
2010-11-03 21:54 ` Phil Turmel
2010-11-03 22:26   ` Roman Mamedov
2010-11-04  9:29   ` Tom Carlson
2010-11-06 10:22   ` Leslie Rhorer
2010-11-06 15:12     ` Phil Turmel [this message]
     [not found]       ` <4CD57867.4010207@anonymous.org.uk>
2010-11-06 16:02         ` Phil Turmel
2010-11-06 16:11           ` Mathias Burén
2010-11-06 16:45           ` Jan Ceuleers
2010-11-06 19:39             ` Phil Turmel
2010-11-06 20:16               ` Leslie Rhorer
2010-11-06 20:23               ` Mr. James W. Laferriere
2010-11-07  7:51               ` Jan Ceuleers
2010-11-07 12:53           ` John Robinson
2010-11-07 13:21             ` Phil Turmel
2010-11-07 13:43               ` John Robinson
2010-11-07 14:43                 ` Phil Turmel
2010-11-07 15:04                   ` Mathias Burén
2010-11-07 15:19                   ` John Robinson
2010-11-07 18:39                     ` Phil Turmel
2010-11-07 20:46                       ` Leslie Rhorer
2010-11-07 21:22                         ` John Robinson
2010-11-08 18:59                           ` John Robinson
2010-11-07 21:24                       ` Andreas Dröscher
2010-11-08 21:05                   ` Mr. James W. Laferriere
2010-11-07 20:52                 ` Roman Mamedov
2010-11-09 14:40                   ` Phil Turmel
2010-11-06 19:58       ` Leslie Rhorer
2010-11-06 21:17       ` John Robinson

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=4CD57048.4020107@turmel.org \
    --to=philip@turmel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=lrhorer@satx.rr.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.