zpool import order in /dev/disk/by-id

2

1

If I have a disk: sdi, and there are three entries of it in /dev/disk/by-id:

scsi-SATA_WDC_WD6001FSYZ-_WD-WXB1HB4SFS7W -> ../../sdi
ata-WDC_WD6001FSYZ-01SS7B0_WD-WXB1HB4SFS7W -> ../../sdi
wwn-0x50014ee004032d28 -> ../../sdi

Now I use zpool import -d /dev/disk/by-id zpoolname. How does zpool decide the order of the three entries? I execute the command and it choose ata-WDC_WD6001FSYZ-01SS7B0_WD-WXB1HB4SFS7W. But I want to know how.

I check the code: https://github.com/zfsonlinux/zfs/blob/master/lib/libzfs/libzfs_import.c#L1387

Seems it use readdir? But readdir doesn't guarantee the scan order, right? And I think this doesn't make sense.

Thanks.

黃健瑋

Posted 2016-03-10T09:29:32.673

Reputation: 133

Indeed readdir doesn't guarantee scan order, but ZFS doesn't really care about that. In fact, one of the big presentations when ZFS was released was that they would swap a dozen USB sticks and did an import, even though all device ID's changed. – mtak – 2016-03-10T09:35:08.963

Answers

1

Well, you've looked at the code, which does use readdir, which doesn't guarantee the order that entries are read out in.

But that last doesn't matter.

ZFS doesn't care if the device node is referred to in one way or another. What it does care about is whether the on-disk data is accessible through it or not. And if it's not, then that particular directory entry won't be a candidate for pool import anyway, so it doesn't make any difference.

The only reason why you'd care is if you want some specific name to show up in the zpool status output. And in that case, you shouldn't be importing from /dev/disk/by-id (which, as you have noted, have multiple ways of referring to the same partition), but instead setting up /etc/zfs/vdev_id.conf and then importing from /dev/disk/by-vdev. (You probably need to re-run udevadm trigger first.)

Generally, don't bother with implementation details unless you actually have some real use for the implementation details, because the next version might completely change the behavior you are looking at. Instead, use the documented interfaces for getting the effect you are after.

This could of course have been avoided had someone put the type into a separate path component, such that we'd have had something like /dev/disk/by-id/scsi/SATA_WDC_WD6001FSYZ-_WD-WXB1HB4SFS7W, /dev/disk/by-id/ata/WDC_WD6001FSYZ-01SS7B0_WD-WXB1HB4SFS7W and /dev/disk/by-id/wwn/0x50014ee004032d28 instead. But, alas. You could do that on your own system, but it would confuse everyone else and their scripts...

a CVn

Posted 2016-03-10T09:29:32.673

Reputation: 26 553

1can you explain how to " setting up /etc/zfs/vdev_id.conf and then importing from /dev/disk/by-vdev" – MikeP – 2019-10-12T19:45:34.543

@MikeP ZFS on Linux (and possibly other variants of ZFS as well) has a configuration file at /etc/zfs/vdev_id.conf that provides mappings from raw device names or hardware paths to more meaningful device names, which in turn are (can be) created in /dev/disk/by-vdev. It's simply a convenience mechanism. See man 5 vdev_id.conf for details. – a CVn – 2019-10-13T10:12:41.670