mdadm --detail showing annoying device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux