From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 14B6F613FA for ; Fri, 4 Feb 2022 13:49:22 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D1E2C31AD8 for ; Fri, 4 Feb 2022 13:49:21 +0100 (CET) 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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0B75A31ACE for ; Fri, 4 Feb 2022 13:49:21 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id DE08C44C0E for ; Fri, 4 Feb 2022 13:49:20 +0100 (CET) Message-ID: <73162aa5-faab-94b2-cef2-9b954b61d2dc@proxmox.com> Date: Fri, 4 Feb 2022 13:49:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: pve-devel@lists.proxmox.com, =?UTF-8?Q?Fabian_Gr=c3=bcnbichler?= References: <20220203124143.1931377-1-f.gruenbichler@proxmox.com> <20220203124143.1931377-4-f.gruenbichler@proxmox.com> From: Fabian Ebner In-Reply-To: <20220203124143.1931377-4-f.gruenbichler@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.137 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH v4 guest-common 3/3] add storage tunnel module X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Feb 2022 12:49:22 -0000 Am 03.02.22 um 13:41 schrieb Fabian Grünbichler: > +sub storage_migrate { > + my ($tunnel, $storecfg, $volid, $local_vmid, $remote_vmid, $opts, $log) = @_; > + > + my $targetsid = $opts->{targetsid}; > + my $bwlimit = $opts->{bwlimit}; > + > + # JSONSchema and get_bandwidth_limit use kbps - storage_migrate bps > + $bwlimit = $bwlimit * 1024 if defined($bwlimit); > + > + # adapt volume name for import call > + my ($sid, undef) = PVE::Storage::parse_volume_id($volid); > + my (undef, $name, $owner, undef, undef, undef, $format) = PVE::Storage::parse_volname($storecfg, $volid); > + my $scfg = PVE::Storage::storage_config($storecfg, $sid); > + PVE::Storage::activate_volumes($storecfg, [$volid]); > + > + die "failed to determine owner of volume '$volid'\n" if !defined($owner); > + $log->('warn', "volume '$volid' owner by VM/CT '$owner', not '$local_vmid'\n") s/owner by/owned by/ > + if $owner != $local_vmid; > + > + if ($owner != $remote_vmid) { > + $name =~ s/-$owner-/-$remote_vmid-/g; > + $name =~ s/^$owner\///; # re-added on target if dir-based storage > + } > + > + my $with_snapshots = $opts->{snapshots} ? 1 : 0; > + my $snapshot; > + my $migration_snapshot = PVE::Storage::storage_migrate_snapshot($storecfg, $sid); > + if ($migration_snapshot) { > + $snapshot = '__migration__'; > + $with_snapshots = 1; > + } > + > + my @export_formats = PVE::Storage::volume_export_formats($storecfg, $volid, $snapshot, $snapshot, $with_snapshots); Why set the base_snapshot argument to $snapshot? > + die "no export formats for '$volid' - check storage plugin support!\n" > + if !@export_formats; > + > + my $disk_import_opts = { > + format => $format, > + storage => $targetsid, > + snapshot => $snapshot, > + migration_snapshot => $migration_snapshot, > + with_snapshots => $with_snapshots, > + allow_rename => !$opts->{is_vmstate}, > + export_formats => join(",", @export_formats), > + volname => $name, > + }; > + my $res = PVE::Tunnel::write_tunnel($tunnel, 600, 'disk-import', $disk_import_opts); > + my $local = "/run/qemu-server/$local_vmid.storage"; > + if (!$tunnel->{forwarded}->{$local}) { > + PVE::Tunnel::forward_unix_socket($tunnel, $local, $res->{socket}); > + } > + my $socket = IO::Socket::UNIX->new(Peer => $local, Type => SOCK_STREAM()) > + or die "failed to connect to websocket tunnel at $local\n"; > + # we won't be reading from the socket > + shutdown($socket, 0); > + > + my $disk_export_opts = { > + snapshot => $snapshot, > + migration_snapshot => $migration_snapshot, > + with_snapshots => $with_snapshots, > + ratelimit_bps => $bwlimit, > + cmd => { > + output => '>&'.fileno($socket), > + }, > + }; > + > + eval { > + PVE::Storage::volume_export_start( > + $storecfg, > + $volid, > + $res->{format}, > + sub { $log->('info', shift) }, > + $disk_export_opts, > + ); > + }; > + my $send_error = $@; > + warn "$send_error\n" if $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); > + > + # wait for the remote process to finish > + my $new_volid; > + while ($res = PVE::Tunnel::write_tunnel($tunnel, 10, 'query-disk-import')) { > + if ($res->{status} eq 'pending') { > + if (my $msg = $res->{msg}) { > + $log->('info', "disk-import: $msg\n"); > + } else { > + $log->('info', "waiting for disk import to finish..\n"); > + } > + sleep(1) > + } elsif ($res->{status} eq 'complete') { > + $new_volid = $res->{volid}; > + last; > + } else { > + $log->('err', "unknown query-disk-import result: $res->{status}\n"); > + last; > + } > + } > + > + # now close the socket > + close($socket); > + if ($snapshot) { In the other storage_migrate(), the decision is based on $migration_snapshot (as is the decision of whether to create a snapshot in volume_export_prepare()), so we might do the same here too. That way, we don't have to remember to switch once we allow passing along an option for an already existing snapshot (which shouldn't be cleaned up). > + eval { PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snapshot, 0) }; > + warn "could not remove source snapshot: $@\n" if $@; > + } > + die $send_error if $send_error; > + die "disk import failed - see log above\n" if !$new_volid; > + > + return $new_volid; > +} > +