From: Stephane Bunel <stephane.bunel@forumdesimages.fr>
To: linux-raid@vger.kernel.org
Subject: mdadm --detail showing annoying device
Date: Wed, 21 Oct 2009 16:17:16 +0200 [thread overview]
Message-ID: <4ADF17EC.6090606@forumdesimages.fr> (raw)
In-Reply-To: <alpine.DEB.2.00.0910210618210.10288@p34.internal.lan>
Hi,
I'm a newbie in the mdadm world. I defined some udev rules to make disk
staticly named according to the bus/host/target. I.e. /dev/sda become
/dev/raid_disk0. So nothing very special with that, it's just a convenient way
to assign disk name to it's physical location.
#ls -la /dev/raid*
brw-rw---- 1 root disk 8, 0 2009-10-16 18:12 /dev/raid_disk0
brw-rw---- 1 root disk 8, 16 2009-10-16 18:12 /dev/raid_disk1
A RAID1 (/dev/md0) is assembled over this two disk.
When looking for detailed information, mdadm show annoying device name in
place of /dev/raid_disk*:
---8x---
#mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Tue Oct 13 12:53:54 2009
Raid Level : raid1
Array Size : 488386496 (465.76 GiB 500.11 GB)
Used Dev Size : 488386496 (465.76 GiB 500.11 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Oct 21 15:16:09 2009
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
UUID : 3fea95a0:e1b8a341:3b119117:e416f62b
Events : 0.1526
Number Major Minor RaidDevice State
0 8 0 0 active sync /dev/char/21:0
1 8 16 1 active sync /dev/char/21:1
---8x---
Looking in the source code of mdadm I found that the device name selection
rule is (too) simply: select the shortest name in case of multiple
possibility. So '/dev/char/21:0' being shorter than '/dev/raid_disk0', mdadm
display '/dev/char...'. It's annoying for me to see a CHAR (/dev/char/...)
device to represent a hard disk (wich is is a block device of course). The
purpose of the following patch is to handle the directory part to always
prefere the name that is closer to /dev. In case of equality, the shorter name
wins.
---8x---
#./mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Tue Oct 13 12:53:54 2009
Raid Level : raid1
Array Size : 488386496 (465.76 GiB 500.11 GB)
Used Dev Size : 488386496 (465.76 GiB 500.11 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Oct 21 15:30:34 2009
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
UUID : 3fea95a0:e1b8a341:3b119117:e416f62b
Events : 0.1526
Number Major Minor RaidDevice State
0 8 0 0 active sync /dev/raid_disk0
1 8 16 1 active sync /dev/raid_disk1
---8x---
Fell free to refactor the code. The last time I wrote C code I still had hair
on my head ;-)
---8x---
--- /var/tmp/mdadm_snapshot/util.c 2009-10-20 04:50:23.000000000 +0200
+++ /var/tmp/mdadm_dirlevel/util.c 2009-10-20 13:13:32.000000000 +0200
@@ -507,6 +507,38 @@
#endif /* HAVE_FTW */
#endif /* HAVE_NFTW */
+char *select_by_directory_level(char *current, char *registered)
+{
+ unsigned int current_level = 0;
+ unsigned int registered_level = 0;
+
+ unsigned int level(char *pathname)
+ {
+ unsigned int count = 0;
+ char *p = pathname;
+
+ while ( (p = strchr( p, '/' )) ) {
+ count++;
+ p++;
+ }
+
+ return( count );
+ }
+
+ current_level = level( current );
+ registered_level = level( registered );
+
+ if ( current_level < registered_level )
+ return current;
+
+ if ( current_level == registered_level )
+ if ( strlen( strrchr( current, '/')) <
+ strlen( strrchr( registered,'/')) )
+ return current;
+
+ return registered;
+}
+
/*
* Find a block device with the right major/minor number.
* If we find multiple names, choose the shortest.
@@ -544,14 +576,18 @@
if (p->major == major &&
p->minor == minor) {
if (strncmp(p->name, "/dev/md/",8) == 0) {
- if (preferred == NULL ||
- strlen(p->name) < strlen(preferred))
- preferred = p->name;
- } else {
- if (regular == NULL ||
- strlen(p->name) < strlen(regular))
- regular = p->name;
- }
+ if (preferred == NULL)
+ preferred = p->name;
+ else
+ preferred =
select_by_directory_level(
+ p->name,
preferred );
+ } else {
+ if (regular == NULL )
+ regular = p->name;
+ else
+ regular = select_by_directory_level(
+ p->name, regular );
+ }
}
if (!regular && !preferred && !did_check) {
devlist_ready = 0;
---8x---
Stéphane Bunel.
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2009-10-21 14:17 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-17 22:34 2.6.31+2.6.31.4: XFS - All I/O locks up to D-state after 24-48 hours (sysrq-t+w available) Justin Piszcz
2009-10-18 20:17 ` Justin Piszcz
2009-10-19 3:04 ` Dave Chinner
2009-10-19 10:18 ` Justin Piszcz
2009-10-20 0:33 ` Dave Chinner
2009-10-20 8:33 ` Justin Piszcz
2009-10-21 10:19 ` Justin Piszcz
2009-10-21 14:17 ` Stephane Bunel [this message]
2009-10-21 21:46 ` mdadm --detail showing annoying device Neil Brown
2009-10-22 11:22 ` Stephane Bunel
2009-10-29 3:44 ` Neil Brown
2009-11-03 9:37 ` Stephane Bunel
2009-11-03 10:09 ` Beolach
2009-11-03 12:16 ` Stephane Bunel
2009-10-22 11:29 ` Mario 'BitKoenig' Holbe
2009-10-22 14:17 ` Stephane Bunel
2009-10-22 16:00 ` Stephane Bunel
2009-10-22 22:49 ` 2.6.31+2.6.31.4: XFS - All I/O locks up to D-state after 24-48 hours (sysrq-t+w available) Justin Piszcz
2009-10-22 23:00 ` Dave Chinner
2009-10-26 11:24 ` Justin Piszcz
2009-11-02 21:46 ` Justin Piszcz
2009-11-20 20:39 ` 2.6.31+2.6.31.4: XFS - All I/O locks up to D-state after 24-48 hours (sysrq-t+w available) - root cause found = asterisk Justin Piszcz
2009-11-20 23:44 ` Bug#557262: " Faidon Liambotis
2009-11-20 23:51 ` Justin Piszcz
2009-11-21 14:29 ` Roger Heflin
2009-11-24 13:08 ` Which kernel options should be enabled to find the root cause of this bug? Justin Piszcz
2009-11-24 15:14 ` Eric Sandeen
2009-11-24 16:20 ` Justin Piszcz
2009-11-24 16:23 ` Eric Sandeen
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=4ADF17EC.6090606@forumdesimages.fr \
--to=stephane.bunel@forumdesimages.fr \
--cc=linux-raid@vger.kernel.org \
/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).