zfsonlinux/zfs — pull request #827 by behlendorf (2012-07-12 23:42:28+00:00)
Title: Issue 808

This is a reworked version of dechamps/zfs@2f301406b3b25a3d761ee1e08b0806f9 patch to move to partition rescanning from userspace to kernel. I had two primary concerns with the original patch.

1) It used symbols which were not available to us on all kernels, and older legacy APIs were not available.

2) Even if those symbols were available, they are not _quite_ what we need. Mainly using blkdev_get() to get the device is not 100% identical to vdev_bdev_open(). The former function does not properly claim the block device with a holder while the latter does. The only available API to do this requires that the device be opened by path.

This reworked (largely untested!) patch attempts to work around the above issues by using more common symbols. To do this we unlink the original device node, trigger the BLKRRPART, and then block waiting for the expected device to appear. Unfortunately, even this approach relies on the get\_gendisk() symbol which exists in RHEL6 but is not exported. So after implementing this I still don't much care for it.

Upon further reflection I believe the only safe and portable thing to do here is call back in to user space to rescan the devices. This should allow us to easily rescan the partition tables, trigger udev, and then block waiting for the required links to be created. The vdev\_elevator\_switch() function provides an example of how this can be done.

We can use either the `partprobe` or `hdparm -z` utilities to force the rescan and then rely on the `udevadm` utility to block until udev settles and the devices are available. Something like:

partprobe [device]; udevadm trigger; udevadm settle;

Comments? Suggestions?