Use sysfs to list all block device paths

38 views
Skip to first unread message

Zhou Zheng Sheng

unread,
Dec 18, 2013, 9:33:43 AM12/18/13
to Project Kimchi, Aline Manera, Daniel Barboza, ShaoHe Feng
Hi all,

I find block device information in sysfs is accurate and complete.

Firstly run
lsblk -bPo NAME,MAJ:MIN

It shows
NAME="vda" MAJ:MIN="253:0"
NAME="vda1" MAJ:MIN="253:1"

When there is multipath, it shows
NAME="35000cca68ac8e2fd" MAJ:MIN="253:0"
NAME="35000cca68ac8e2fdp1" MAJ:MIN="253:1"

Then we parse the major and min, and cat the related sysfs uevent file
cat /sys/dev/block/253\:0/uevent

It shows
MAJOR=253
MINOR=0
DEVNAME=vda
DEVTYPE=disk

When there is multipath, it shows
MAJOR=253
MINOR=0
DEVNAME=dm-0
DEVTYPE=disk

The "DEVNAME=vda" or "DEVNAME=dm-0" is the device node name under the
"/dev/"
So there can be
/dev/vda
or
/dev/dm-0

In fact, on my machine, the multipath device node is a link to dm-0
/dev/mapper/35000cca68ac8e2fd -> ../dm-0

So we can show in front-end like following.
vda1 (/dev/vda1)
35000cca68ac8e2fd (/dev/dm-0)

The use mostly cares the name, the path is just supplement information.
User just asks front-end to use "vda1" or "35000cca68ac8e2fd" to create
pool, then we map the names to path.

In this way we don't need to blkid to determine the path, and can drop
the check on" blkid path being not None". Test on Fedora and Ubuntu.

Generally speaking, I also can accept a temp solution just assuming all
NAME listed by lsblk can be mapped to "/dev/NAME". We just need to check
if "/dev/NAME" does exist or not, if not, skip this device.

I'm afraid I have no time to finish a second version of the patch. Maybe
Aline or Daniel can help me. I feel very sorry to not have time to
finish the patch I started. Thanks very much!
--
Thanks and best regards!

Zhou Zheng Sheng / 锟斤拷锟斤拷锟斤拷
E-mail: zhsh...@linux.vnet.ibm.com
Telephone: 86-10-82454397

Reply all
Reply to author
Forward
0 new messages