[pve-devel] applied: [RFC storage] pvesm import: allow to pass a tcp://<IP> as file
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Jul 11 10:17:11 CEST 2019
applied with minor fixup
On Thu, Jun 27, 2019 at 04:16:09PM +0200, Thomas Lamprecht wrote:
> To allow getting closer to finally drop "pvecm mtunnel".
> Code parts taken from pipe_socket_to_command
>
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
> PVE/CLI/pvesm.pm | 34 +++++++++++++++++++++++++++++++++-
> PVE/Storage.pm | 10 ++++------
> 2 files changed, 37 insertions(+), 7 deletions(-)
>
> diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
> index 0432450..330d748 100755
> --- a/PVE/CLI/pvesm.pm
> +++ b/PVE/CLI/pvesm.pm
> @@ -269,7 +269,9 @@ __PACKAGE__->register_method ({
> enum => $KNOWN_EXPORT_FORMATS,
> },
> filename => {
> - description => "Source file name",
> + description => "Source file name. For '-' stdin is used, the " .
> + "tcp://<IP-or-CIDR> format allows to use a TCP connection as input. " .
> + "Else, the file is treated as common file.",
> type => 'string',
> },
> base => {
> @@ -304,6 +306,36 @@ __PACKAGE__->register_method ({
> my $infh;
> if ($filename eq '-') {
> $infh = \*STDIN;
> + } elsif ($filename =~ m!^tcp://((.+)(/\d+)?)$!) {
Used ([^/]+) as (.+) always ate up the (/\d+) part breaking it when
there was actually a CIDR in there.
> + my ($cidr, $ip, $subnet) = ($1, $2, $3);
> + if ($subnet) { # got real CIDR notation, not just IP
> + $ip = PVE::Cluster::get_local_migration_ip($cidr);
> + }
> + my $family = PVE::Tools::get_host_address_family($ip);
> + my $port = PVE::Tools::next_migrate_port($family, $ip);
> +
> + my $sock_params = {
> + Listen => 1,
> + ReuseAddr => 1,
> + Proto => &Socket::IPPROTO_TCP,
> + GetAddrInfoFlags => 0,
> + LocalAddr => $ip,
> + LocalPort => $port,
> + };
> + my $socket = IO::Socket::IP->new(%$sock_params)
> + or die "failed to open socket: $!\n";
> +
> + print "$ip\n$port\n"; # tell remote where to connect
> + *STDOUT->flush();
> +
> + my $prev_alarm = alarm 0;
> + local $SIG{ALRM} = sub { die "timed out waiting for client\n" };
> + alarm 30;
> + my $client = $socket->accept; # Wait for a client
> + alarm $prev_alarm;
> + close($socket);
> +
> + $infh = \*$client;
> } else {
> sysopen($infh, $filename, O_RDONLY)
> or die "open($filename): $!\n";
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index 0ce942a..5925c69 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -590,17 +590,15 @@ sub storage_migrate {
> die "cannot migrate from storage type '$scfg->{type}' to '$tcfg->{type}'\n" if !@formats;
> my $format = $formats[0];
>
> - my @insecurecmd;
> + my $import_fn = '-'; # let pvesm import read from stdin per default
> if ($insecure) {
> - @insecurecmd = ('pvecm', 'mtunnel', '-run-command', 1);
> - if (my $network = $target_sshinfo->{network}) {
> - push @insecurecmd, '-migration_network', $network;
> - }
> + my $net = $target_sshinfo->{network} // $target_sshinfo->{ip};
> + $import_fn = "tcp://$net";
> }
>
> $with_snapshots = $with_snapshots ? 1 : 0; # sanitize for passing as cli parameter
> my $send = ['pvesm', 'export', $volid, $format, '-', '-with-snapshots', $with_snapshots];
> - my $recv = [@$ssh, @insecurecmd, '--', 'pvesm', 'import', $volid, $format, '-', '-with-snapshots', $with_snapshots];
> + my $recv = [@$ssh, '--', 'pvesm', 'import', $volid, $format, $import_fn, '-with-snapshots', $with_snapshots];
> if (defined($snapshot)) {
> push @$send, '-snapshot', $snapshot
> }
> --
> 2.20.1
More information about the pve-devel
mailing list