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 4D9656C089; Thu, 28 Jan 2021 17:25:35 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 443EE2FA7C; Thu, 28 Jan 2021 17:25:35 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id 9FE7F2FA72; Thu, 28 Jan 2021 17:25:34 +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 6536A4613A; Thu, 28 Jan 2021 17:25:34 +0100 (CET) To: Proxmox VE development discussion , Stefan Reiter , pbs-devel@lists.proxmox.com References: <20210111111409.32385-1-s.reiter@proxmox.com> <20210111111409.32385-8-s.reiter@proxmox.com> From: Thomas Lamprecht Message-ID: <246fec98-7324-7af5-5cd4-e2ef539b287a@proxmox.com> Date: Thu, 28 Jan 2021 17:25:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Thunderbird/85.0 MIME-Version: 1.0 In-Reply-To: <20210111111409.32385-8-s.reiter@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL -0.064 Adjusted score from AWL reputation of From: address 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) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemuserver.pm] Subject: Re: [pve-devel] [PATCH qemu-server 07/11] cfg2cmd: allow PBS snapshots as backing files for drives 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: Thu, 28 Jan 2021 16:25:35 -0000 On 11.01.21 12:14, Stefan Reiter wrote: > Uses the custom 'alloc-track' filter node to redirect writes to the > original drives target, while unwritten blocks will be read from the > specified PBS snapshot. >=20 > Signed-off-by: Stefan Reiter > --- > PVE/QemuServer.pm | 42 +++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 39 insertions(+), 3 deletions(-) >=20 > diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm > index d517dae..6de6ff6 100644 > --- a/PVE/QemuServer.pm > +++ b/PVE/QemuServer.pm > @@ -3022,7 +3022,8 @@ sub query_understood_cpu_flags { > } > =20 > sub config_to_command { > - my ($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu) = =3D @_; > + my ($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu, > + $pbs_backing) =3D @_; > =20 > my $cmd =3D []; > my $globalFlags =3D []; > @@ -3521,6 +3522,32 @@ sub config_to_command { > my $drive_cmd =3D print_drive_commandline_full($storecfg, $vmid, $dri= ve); > $drive_cmd .=3D ',readonly' if PVE::QemuConfig->is_template($conf); > =20 > + if ($pbs_backing && defined($pbs_backing->{$ds})) { please avoid extending config_to_command to much, move to own method. > + my $pbs_conf =3D $pbs_backing->{$ds}; > + my $pbs_name =3D "drive-$ds-pbs"; > + > + # add PBS block device to access snapshot from QEMU > + my $blockdev =3D "driver=3Dpbs,node-name=3D$pbs_name,read-only=3D= on"; > + $blockdev .=3D ",repository=3D$pbs_conf->{repository}"; > + $blockdev .=3D ",snapshot=3D$pbs_conf->{snapshot}"; > + $blockdev .=3D ",archive=3D$pbs_conf->{archive}"; > + $blockdev .=3D ",keyfile=3D$pbs_conf->{keyfile}" if $pbs_conf->{k= eyfile}; > + push @$devices, '-blockdev', $blockdev; > + > + # modify drive command to put the desired target file behind an > + # 'alloc-track' node > + $drive_cmd =3D~ s/file=3D([^,]+)/file.file.filename=3D$1/; > + $drive_cmd =3D~ s/,format=3D([^,]+)/,file.driver=3D$1,format=3Dal= loc-track/; This seems really fragile and hacky, please avoid string replacements on = variables we assemble ourself. > + $drive_cmd .=3D ",backing=3D$pbs_name"; > + $drive_cmd .=3D ",auto-remove=3Don"; > + > + # note: 'cache' and 'aio' directly affect the 'drive' parameter, = so > + # we don't need to change them to 'file.', but 'detect-zeroes' wo= rks > + # per blockdev and we want it to persist after the alloc-track is= > + # removed, so put it on 'file' directly > + $drive_cmd =3D~ s/,detect-zeroes=3D([^,]+)/,file.detect-zeroes=3D= $1/; > + } > + > push @$devices, '-drive',$drive_cmd; > push @$devices, '-device', print_drivedevice_full( > $storecfg, $conf, $vmid, $drive, $bridges, $arch, $machine_type);= > @@ -4915,6 +4942,15 @@ sub vm_start { > # timeout =3D> in seconds > # paused =3D> start VM in paused state (backup) > # resume =3D> resume from hibernation > +# pbs-backing =3D> { > +# sata0 =3D> { > +# repository > +# snapshot > +# keyfile > +# archive > +# }, > +# virtio2 =3D> ... > +# } > # migrate_opts: > # nbd =3D> volumes for NBD exports (vm_migrate_alloc_nbd_disks) > # migratedfrom =3D> source node > @@ -4961,8 +4997,8 @@ sub vm_start_nolock { > print "Resuming suspended VM\n"; > } > =20 > - my ($cmd, $vollist, $spice_port) =3D > - config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine, = $forcecpu); > + my ($cmd, $vollist, $spice_port) =3D config_to_command($storecfg, = $vmid, > + $conf, $defaults, $forcemachine, $forcecpu, $params->{'pbs-backing'})= ; > =20 > my $migration_ip; > my $get_migration_ip =3D sub { >=20