diff options
author | Brian Behlendorf <[email protected]> | 2016-04-19 11:19:12 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-04-25 11:13:20 -0700 |
commit | 2d82ea8b111103b28b8c9ad0f69dd88736248804 (patch) | |
tree | c132339412ce0ed9b8f04c6ccb6471317755f59c /lib/libzfs/libzfs_pool.c | |
parent | 5b4136bd499a892f65c86af8fd39fa21e05c9148 (diff) |
Use udev for partition detection
When ZFS partitions a block device it must wait for udev to create
both a device node and all the device symlinks. This process takes
a variable length of time and depends on factors such how many links
must be created, the complexity of the rules, etc. Complicating
the situation further it is not uncommon for udev to create and
then remove a link multiple times while processing the udev rules.
Given the above, the existing scheme of waiting for an expected
partition to appear by name isn't 100% reliable. At this point
udev may still remove and recreate think link resulting in the
kernel modules being unable to open the device.
In order to address this the zpool_label_disk_wait() function
has been updated to use libudev. Until the registered system
device acknowledges that it in fully initialized the function
will wait. Once fully initialized all device links are checked
and allowed to settle for 50ms. This makes it far more likely
that all the device nodes will exist when the kernel modules
need to open them.
For systems without libudev an alternate zpool_label_disk_wait()
was updated to include a settle time. In addition, the kernel
modules were updated to include retry logic for this ENOENT case.
Due to the improved checks in the utilities it is unlikely this
logic will be invoked. However, if the rare event it is needed
it will prevent a failure.
Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: Tony Hutter <[email protected]>
Signed-off-by: Richard Laager <[email protected]>
Closes #4523
Closes #3708
Closes #4077
Closes #4144
Closes #4214
Closes #4517
Diffstat (limited to 'lib/libzfs/libzfs_pool.c')
-rw-r--r-- | lib/libzfs/libzfs_pool.c | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 214c57ab4..c405abe3e 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -4122,30 +4122,7 @@ find_start_block(nvlist_t *config) return (MAXOFFSET_T); } -int -zpool_label_disk_wait(char *path, int timeout) -{ - struct stat64 statbuf; - int i; - - /* - * Wait timeout miliseconds for a newly created device to be available - * from the given path. There is a small window when a /dev/ device - * will exist and the udev link will not, so we must wait for the - * symlink. Depending on the udev rules this may take a few seconds. - */ - for (i = 0; i < timeout; i++) { - usleep(1000); - - errno = 0; - if ((stat64(path, &statbuf) == 0) && (errno == 0)) - return (0); - } - - return (ENOENT); -} - -int +static int zpool_label_disk_check(char *path) { struct dk_gpt *vtoc; @@ -4310,12 +4287,11 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, char *name) (void) close(fd); efi_free(vtoc); - /* Wait for the first expected partition to appear. */ - (void) snprintf(path, sizeof (path), "%s/%s", DISK_ROOT, name); (void) zfs_append_partition(path, MAXPATHLEN); - rval = zpool_label_disk_wait(path, 3000); + /* Wait to udev to signal use the device has settled. */ + rval = zpool_label_disk_wait(path, DISK_LABEL_WAIT); if (rval) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "failed to " "detect device partitions on '%s': %d"), path, rval); |