[pve-devel] [PATCH storage] fix #1912: find the partition instead of guessing it

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Sep 14 10:30:41 CEST 2018


On Thu, Sep 13, 2018 at 04:56:26PM +0200, Dominik Csapak wrote:
> instead of using '$dev1' as partition,
> get the information from /sys/block/$dev
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  PVE/API2/Disks/Directory.pm | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/API2/Disks/Directory.pm b/PVE/API2/Disks/Directory.pm
> index 8e6118a..2e249c5 100644
> --- a/PVE/API2/Disks/Directory.pm
> +++ b/PVE/API2/Disks/Directory.pm
> @@ -220,7 +220,12 @@ __PACKAGE__->register_method ({
>  		print "# ", join(' ', @$cmd), "\n";
>  		run_command($cmd);
>  
> -		my $part = "${dev}1";
> +		my ($devname) = $dev =~ m|^/dev/(.*)$|;
> +		my $part = "/dev/";
> +		dir_glob_foreach("/sys/block/$devname", "$devname.+", sub {

While the code far outside the here visible context lines "knows" $dev
is an actual existing path in /dev, I'd still like to see \Q and \E
around the variable in the glob here. You may even want to use
qr/\Q$devname\E.+/ instead of quotes...

> +		    my ($partition) = @_;
> +		    $part .= $partition;
> +		});
>  
>  		# create filesystem
>  		$cmd = [$MKFS, '-t', $type, $part];
> -- 
> 2.11.0




More information about the pve-devel mailing list