[pve-devel] [PATCH storage 2/3] Ensure $volname is defined before using it

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Sep 26 15:36:15 CEST 2019


On 9/25/19 10:28 AM, Daniel Berteaud wrote:
> extract_volname can return an undef $volname
> 

thanks for noticing, the proposed change would've worked just fine, but
I like return-early style a bit more, also saw a missed opportunity to
reuse a variable in the $extract_volname call, so I pushed out this:

----8<----
diff --git a/PVE/Storage/LunCmd/LIO.pm b/PVE/Storage/LunCmd/LIO.pm
index f246dbb..486c606 100644
--- a/PVE/Storage/LunCmd/LIO.pm
+++ b/PVE/Storage/LunCmd/LIO.pm
@@ -205,7 +205,9 @@ my $list_view = sub {
     my $lun = undef;
 
     my $object = $params[0];
-    my $volname = $extract_volname->($scfg, $params[0]);
+    my $volname = $extract_volname->($scfg, $object);
+
+    return undef if !defined($volname); # nothing to search for..
 
     foreach my $lun (@{$SETTINGS->{target}->{luns}}) {
        if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
--

sorry if I went a bit over your head here :)

> Signed-off-by: Daniel Berteaud <daniel at firewall-services.com>
> ---
>  PVE/Storage/LunCmd/LIO.pm | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/PVE/Storage/LunCmd/LIO.pm b/PVE/Storage/LunCmd/LIO.pm
> index 5f9794d..5d7a21d 100644
> --- a/PVE/Storage/LunCmd/LIO.pm
> +++ b/PVE/Storage/LunCmd/LIO.pm
> @@ -224,9 +224,11 @@ my $list_lun = sub {
>      my $object = $params[0];
>      my $volname = $extract_volname->($scfg, $params[0]);
>  
> -    foreach my $lun (@{$SETTINGS->{$scfg->{portal}.$scfg->{target}}->{luns}}) {
> -	if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
> -	    return $object;
> +    if ($volname) {
> +	foreach my $lun (@{$SETTINGS->{$scfg->{portal}.$scfg->{target}}->{luns}}) {
> +	    if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
> +		return $object;
> +	    }
>  	}
>      }
>  
> 





More information about the pve-devel mailing list