[pve-devel] applied: [PatchV2 storage 1/2] fix #1691: replace udev check

Thomas Lamprecht t.lamprecht at proxmox.com
Mon May 7 12:21:09 CEST 2018


Am 04/19/2018 um 08:39 AM schrieb Wolfgang Link:
> `zfs create` add the creation job in a worker queue,
> which should normally execute instantly. But there are circumstances
> where the job will take a while to get processed.
> If this is the case udev settle will see no dev in the queue and the program
> will continue without an allocated dev.
> 
> The busy waiting is not best practice but the only way to be sure,
> that the block device exists.
> ---
>   PVE/Storage/ZFSPoolPlugin.pm | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
> index e864a58..9680a94 100644
> --- a/PVE/Storage/ZFSPoolPlugin.pm
> +++ b/PVE/Storage/ZFSPoolPlugin.pm
> @@ -211,9 +211,14 @@ sub alloc_image {
>   	$class->zfs_create_zvol($scfg, $volname, $size);
>   	my $devname = "/dev/zvol/$scfg->{pool}/$volname";
>   
> -	run_command("udevadm trigger --subsystem-match block");
> -	system('udevadm', 'settle', '--timeout', '10', "--exit-if-exists=${devname}");
> +	my $timeout = 10;
> +	for (my $i = 1; $i <= $timeout; $i++) {
> +	    last if -b $devname;
> +	    die "Timeout: no zvol after $timeout sec found.\n"
> +		if $i == $timeout;
>   
> +	    sleep(1);

note: this isn't interrupt safe and may actually sleep less

as we have quite a few such constructs in our code base it
could make sense to add a helper doing this correctly to PVE::Tools
and replace the various, often not ideal, implementations of this...

> +	}
>       } elsif ( $fmt eq 'subvol') {
>   
>   	die "illegal name '$volname' - sould be 'subvol-$vmid-*'\n"
> 

applied both storage patches, will try to address the note above soon :)



More information about the pve-devel mailing list