From: "Torbjørn Skagestad" <torbjorn@itpas.no>
To: Phil Turmel <philip@turmel.org>
Cc: linux-raid@vger.kernel.org, Roman Mamedov <roman@rm.pp.ru>,
John Robinson <john.robinson@anonymous.org.uk>
Subject: Re: Storage device enumeration script
Date: Thu, 26 May 2011 11:45:30 +0200 [thread overview]
Message-ID: <1306403130.9437.109.camel@torbjorn> (raw)
In-Reply-To: <4DDDC301.7090608@turmel.org>
[-- Attachment #1.1: Type: text/plain, Size: 1506 bytes --]
Hi,
Great tool, thanks for sharing.
I had to add some error handling to get it to work properly.
Currently it runs on Ubuntu 10.04, 10.10 and 11.04.
Added the check John Robinson asked for as well.
Attached patch for those interested.
--
Thanks
Torbjørn
On Wed, 2011-05-25 at 23:03 -0400, Phil Turmel wrote:
> Hi All,
>
> Last November, I shared a shell script that helped me keep track of the specific hot-swap drives I had in the various slots of my servers. Although encouraged by Roman and John, I declined to make a project out of it.
>
> I've since kicked it around some more, and thought a bit about supporting more than just the SCSI subsystem. The latest and greatest is still built around some standard executables: blkid, lspci, lsusb, sginfo, and smartctl. The original was similar to "lsscsi", but with controller details and device serial numbers.
>
> New features:
> Supports non-SCSI storage devices
> Describes layered block devices
> MD raid
> LVM
> generic device mapper
> loop (partial)
> Shows UUIDs
> Shows mountpoints
> Avoids repeating subtrees when enumerating raid devices
>
> I struggled with the last item, until I gave up on bash. I needed to pass data to subroutines by reference, and bash is sorely lacking in that area. The new script is in python. I'm releasing this one under the GPL version 2.
>
> Please give it a whirl.
>
> Phil
--
Torbjørn Skagestad
Idé Til Produkt AS
torborn@itpas.no
[-- Attachment #1.2: lsdrv.patch --]
[-- Type: text/x-patch, Size: 1821 bytes --]
--- lsdrv 2011-05-26 11:06:44.000000000 +0200
+++ lsdrv.py 2011-05-26 11:34:50.000000000 +0200
@@ -47,7 +47,12 @@
def runx(*args, **kwargs):
kwargs['stdout'] = PIPE
kwargs['stderr'] = PIPE
- sub = Popen(*args, **kwargs)
+ try:
+ sub = Popen(*args, **kwargs)
+ except OSError as e:
+ print "Unable to execute " + str(args[0][0])
+ print e
+ exit()
out, err = sub.communicate()
return out
@@ -166,9 +171,12 @@
devpath = os.path.realpath(devpathlink)
if devpath in phydevs:
return phydevs[devpath]
- phy = Struct(dpath=devpath, node=nodestr,
- vendor=io.FileIO(devpath+'/vendor').read().split("\n",1)[0].strip(),
- model=io.FileIO(devpath+'/model').read().split("\n",1)[0].strip())
+ try:
+ phy = Struct(dpath=devpath, node=nodestr,
+ vendor=io.FileIO(devpath+'/vendor').read().split("\n",1)[0].strip(),
+ model=io.FileIO(devpath+'/model').read().split("\n",1)[0].strip())
+ except IOError:
+ return None
if os.path.exists(devpath+'/unique_id'):
phy.serial = io.FileIO(devpath+'/unique_id').read().split("\n",1)[0].strip()
if not phy.serial:
@@ -189,6 +197,8 @@
blockbyname=dict()
blockbynode=dict()
sysclassblock="/sys/class/block/"
+if(not os.path.exists(sysclassblock)):
+ sysclassblock = "/sys/block/"
for x in os.listdir(sysclassblock):
nodestr=io.FileIO(sysclassblock+x+'/dev').read().split("\n")[0]
sizestr=sect2size(io.FileIO(sysclassblock+x+'/size').read().split("\n")[0])
@@ -250,7 +260,10 @@
devstat = os.stat(mdev)
nodestr="%d:%d" % (os.major(devstat.st_rdev), os.minor(devstat.st_rdev))
if nodestr in blockbynode:
- mntstat = os.statvfs(mnt)
+ try:
+ mntstat = os.statvfs(mnt)
+ except OSError:
+ mntstat = None
dev = blockbynode[nodestr]
dev.mountdev = mdev
dev.mountpoint = mnt
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2011-05-26 9:45 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-26 3:03 Storage device enumeration script Phil Turmel
2011-05-26 3:10 ` Mathias Burén
2011-05-26 3:21 ` Phil Turmel
2011-05-26 3:25 ` Mathias Burén
2011-05-26 5:25 ` Roman Mamedov
2011-05-26 8:24 ` CoolCold
2011-05-26 12:00 ` Phil Turmel
2011-05-31 18:51 ` Simon McNair
2011-05-31 21:21 ` CoolCold
2011-06-01 3:58 ` Phil Turmel
2011-05-26 6:14 ` Leslie Rhorer
2011-05-26 6:16 ` Mathias Burén
2011-05-26 11:41 ` Phil Turmel
2011-05-27 0:13 ` Leslie Rhorer
2011-05-27 0:16 ` Brad Campbell
2011-05-27 3:58 ` Roman Mamedov
2011-05-27 10:45 ` Gordon Henderson
2011-05-27 11:26 ` Torbjørn Skagestad
2011-05-27 11:42 ` Gordon Henderson
2011-05-27 12:06 ` Phil Turmel
2011-05-26 8:11 ` CoolCold
2011-05-26 9:27 ` John Robinson
2011-05-26 9:45 ` Torbjørn Skagestad [this message]
2011-05-26 9:59 ` John Robinson
2011-05-26 11:49 ` Phil Turmel
2011-05-26 12:05 ` Torbjørn Skagestad
2011-05-27 9:15 ` John Robinson
2011-05-27 9:44 ` John Robinson
2011-05-27 11:23 ` Phil Turmel
2011-06-01 3:43 ` Phil Turmel
2011-05-26 11:39 ` Phil Turmel
2011-05-26 11:52 ` Torbjørn Skagestad
2011-05-26 17:46 ` Phil Turmel
2011-05-26 17:51 ` Mathias Burén
2011-05-26 17:54 ` Roman Mamedov
2011-05-26 18:02 ` Phil Turmel
2011-05-26 18:12 ` Roman Mamedov
2011-05-26 18:22 ` Phil Turmel
2011-05-26 18:42 ` Torbjørn Skagestad
2011-05-26 18:58 ` CoolCold
2011-05-26 19:16 ` Phil Turmel
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=1306403130.9437.109.camel@torbjorn \
--to=torbjorn@itpas.no \
--cc=john.robinson@anonymous.org.uk \
--cc=linux-raid@vger.kernel.org \
--cc=philip@turmel.org \
--cc=roman@rm.pp.ru \
/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).