[dm-devel] better alternative to part multpath -l output?

Bryn M. Reeves bmr at redhat.com
Thu Jan 5 13:50:12 UTC 2012


On 01/05/2012 01:33 PM, Rudy Gevaert wrote:
> Hello,
> 
> Can anybody suggest a better alternative to parsing multpath -l
> <device> to get the underlying devices that are part of the
> multipath?
> 
> Thanks in advance,
> 
> Rudy

You could parse the output of dmsetup, either table or deps:

# dmsetup table mpath2
0 31457280 multipath 1 queue_if_no_path 1 emc 1 1 round-robin 0 2 1
8:32 1000 8:80 1000
^^^^      ^^^^
# dmsetup deps mpath2
2 dependencies	: (8, 80) (8, 32)
                   ^^^^^   ^^^^^
The lsblk command (or dmsetup ls --tree) will also display dependency
trees graphically but you probably wouldn't want to parse this (and it
operates bottom-up rather than top-down):

# lsblk /dev/sdc /dev/sdd
NAME                            MAJ:MIN RM   SIZE RO MOUNTPOINT
sdc                               8:32   0    15G  0
└─mpatha (dm-0)                 253:0    0    15G  0
  ├─mpathap1 (dm-1)             253:1    0   500M  0 /boot
  └─mpathap2 (dm-2)             253:2    0  14.5G  0
    ├─vg_pe19503-lv_root (dm-3) 253:3    0  10.6G  0 /
    └─vg_pe19503-lv_swap (dm-4) 253:4    0     4G  0 [SWAP]
sdd                               8:48   0    15G  0
└─mpatha (dm-0)                 253:0    0    15G  0
  ├─mpathap1 (dm-1)             253:1    0   500M  0 /boot
  └─mpathap2 (dm-2)             253:2    0  14.5G  0
    ├─vg_pe19503-lv_root (dm-3) 253:3    0  10.6G  0 /
    └─vg_pe19503-lv_swap (dm-4) 253:4    0     4G  0 [SWAP]

But probably the easiest and most direct way is to use the sysfs
holders/slaves directories:

# multipath -l mpath2
mpath2 (3600601608e661a01a50ff0fe2776e011) dm-1 DGC,RAID 5
[size=15G][features=1 queue_if_no_path][hwhandler=1 emc][rw]
\_ round-robin 0 [prio=0][active]
 \_ 1:0:0:0 sdc 8:32  [active][undef]
 \_ 2:0:0:0 sdf 8:80  [active][undef]

# ls /sys/block/dm-1/slaves/
sdc  sdf

The only niggle here is that you need to map the mpath device name to
it's device mapper minor number to obtain the sysfs path.

If you want to find out what's using the device rather than what it's
using change slaves to holders:

# ls /sys/block/dm-0/holders/
dm-1  dm-2

# dmsetup info /dev/dm-1
Name:              mpathap1
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        1
Event number:      0
Major, minor:      253, 1
Number of targets: 1
UUID: part1-mpath-3600601608e661a01a60ff0fe2776e011

etc.

Regards,
Bryn.




More information about the dm-devel mailing list