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 7CD0166E94; Mon, 11 Jan 2021 12:14:46 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6DB351922A; Mon, 11 Jan 2021 12:14:45 +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 CD34119112; Mon, 11 Jan 2021 12:14:40 +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 980CB45F2F; Mon, 11 Jan 2021 12:14:40 +0100 (CET) From: Stefan Reiter To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Mon, 11 Jan 2021 12:14:05 +0100 Message-Id: <20210111111409.32385-8-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210111111409.32385-1-s.reiter@proxmox.com> References: <20210111111409.32385-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.041 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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 Subject: [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: Mon, 11 Jan 2021 11:14:46 -0000 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. Signed-off-by: Stefan Reiter --- PVE/QemuServer.pm | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) 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 { } sub config_to_command { - my ($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu) = @_; + my ($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu, + $pbs_backing) = @_; my $cmd = []; my $globalFlags = []; @@ -3521,6 +3522,32 @@ sub config_to_command { my $drive_cmd = print_drive_commandline_full($storecfg, $vmid, $drive); $drive_cmd .= ',readonly' if PVE::QemuConfig->is_template($conf); + if ($pbs_backing && defined($pbs_backing->{$ds})) { + my $pbs_conf = $pbs_backing->{$ds}; + my $pbs_name = "drive-$ds-pbs"; + + # add PBS block device to access snapshot from QEMU + my $blockdev = "driver=pbs,node-name=$pbs_name,read-only=on"; + $blockdev .= ",repository=$pbs_conf->{repository}"; + $blockdev .= ",snapshot=$pbs_conf->{snapshot}"; + $blockdev .= ",archive=$pbs_conf->{archive}"; + $blockdev .= ",keyfile=$pbs_conf->{keyfile}" if $pbs_conf->{keyfile}; + push @$devices, '-blockdev', $blockdev; + + # modify drive command to put the desired target file behind an + # 'alloc-track' node + $drive_cmd =~ s/file=([^,]+)/file.file.filename=$1/; + $drive_cmd =~ s/,format=([^,]+)/,file.driver=$1,format=alloc-track/; + $drive_cmd .= ",backing=$pbs_name"; + $drive_cmd .= ",auto-remove=on"; + + # note: 'cache' and 'aio' directly affect the 'drive' parameter, so + # we don't need to change them to 'file.', but 'detect-zeroes' works + # per blockdev and we want it to persist after the alloc-track is + # removed, so put it on 'file' directly + $drive_cmd =~ s/,detect-zeroes=([^,]+)/,file.detect-zeroes=$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 => in seconds # paused => start VM in paused state (backup) # resume => resume from hibernation +# pbs-backing => { +# sata0 => { +# repository +# snapshot +# keyfile +# archive +# }, +# virtio2 => ... +# } # migrate_opts: # nbd => volumes for NBD exports (vm_migrate_alloc_nbd_disks) # migratedfrom => source node @@ -4961,8 +4997,8 @@ sub vm_start_nolock { print "Resuming suspended VM\n"; } - my ($cmd, $vollist, $spice_port) = - config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu); + my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, + $conf, $defaults, $forcemachine, $forcecpu, $params->{'pbs-backing'}); my $migration_ip; my $get_migration_ip = sub { -- 2.20.1