+ /*
+ * Remove any previously existing symlink from a udev path to
+ * the device before labeling the disk. This makes
+ * zpool_label_disk_wait() truly wait for the new link to show
+ * up instead of returning if it finds an old link still in
+ * place. Otherwise there is a window between when udev
+ * deletes and recreates the link during which access attempts
+ * will fail with ENOENT.
+ */
+ zfs_append_partition(path, udevpath, sizeof (udevpath));
+ if ((strncmp(udevpath, UDISK_ROOT, strlen(UDISK_ROOT)) == 0) &&
+ (lstat64(udevpath, &statbuf) == 0) &&
+ S_ISLNK(statbuf.st_mode))
+ (void) unlink(udevpath);
+
+ diskname = strrchr(devpath, '/');