From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 278AB96DA2
 for <pve-devel@lists.proxmox.com>; Tue, 16 Apr 2024 15:10:58 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 0E7441B7AE
 for <pve-devel@lists.proxmox.com>; Tue, 16 Apr 2024 15:10:58 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Tue, 16 Apr 2024 15:10:53 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8C5244501A
 for <pve-devel@lists.proxmox.com>; Tue, 16 Apr 2024 15:10:53 +0200 (CEST)
Message-ID: <4c1b5a09-8242-4044-a2d6-d29c2c70c639@proxmox.com>
Date: Tue, 16 Apr 2024 15:10:52 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Mira Limbeck <m.limbeck@proxmox.com>
References: <20240416114509.112693-1-m.limbeck@proxmox.com>
Content-Language: en-US
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20240416114509.112693-1-m.limbeck@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.070 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH v2 storage] fix insecure migration failing
 if waiting on lock
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 16 Apr 2024 13:10:58 -0000

Am 16.04.24 um 13:45 schrieb Mira Limbeck:
> +	    my $handle_insecure_migration = sub {
> +		my $line = shift;
> +
> +		if (!$ip) {
> +		    ($ip) = $line =~ /^($PVE::Tools::IPRE)$/ # untaint
> +			or die "no tunnel IP received, got '$line'\n";
> +		} elsif (!$port) {
> +		    ($port) = $line =~ /^(\d+)$/ # untaint
> +			or die "no tunnel port received, got '$line'\n";
> +
> +		    # create socket, run command
> +		    $socket = IO::Socket::IP->new(PeerHost => $ip, PeerPort => $port, Type => SOCK_STREAM)

While the line too long style nits are pre-existing, it gets slightly
worse with the added indentation, so let's fix them.

Style nit: line too long (and we'll need to turn the "or die" into a
separate statement "die ... if !$socket" since we only want the "or die"
for one-liners)

> +			or die "failed to connect to tunnel at $ip:$port\n";
> +		    # we won't be reading from the socket
> +		    shutdown($socket, 0);
> +
> +		    eval { run_command($cmds, output => '>&'.fileno($socket), errfunc => $match_volid_and_log); };

Style nit: line too long

> +		    $send_error = $@;
> +
> +		    # don't close the connection entirely otherwise the receiving end
> +		    # might not get all buffered data (and fails with 'connection reset by peer')
> +		    shutdown($socket, 1);
> +		} else {
> +		    $match_volid_and_log->("[$target_sshinfo->{name}] $line");
> +		}
> +	    };
>  
> -	    # now close the socket
> -	    close($socket);
> -	    if (!close($info)) { # does waitpid()
> -		die "import failed: $!\n" if $!;
> -		die "import failed: exit code ".($?>>8)."\n";
> +	    eval { run_command($recv, outfunc => $handle_insecure_migration, errfunc => $match_volid_and_log); };

Style nit: line too long

To stay consistent with current output, we should also add the
"[$target_sshinfo->{name}]" prefix in the errfunc. Probably fits as an
in-line sub { ... } after splitting the line ;)

If we do not need the chomp below (do we?), the code between here

> +	    if (my $err = $@) {
> +		close($socket) if $socket;
> +
> +		chomp($err);
> +		die "failed to run insecure migration: $err\n";
>  	    }
>  
> +	    # now close the socket
> +	    close($socket) if $socket;

and here could also just become

my $err = $@;
close($socket) if $socket;
die "failed to run insecure migration: $err" if $err;

Or maybe even call it $recv_error for consistency with $send_error.

>  	    die $send_error if $send_error;
>  	} else {
>  	    push @$cmds, $recv;