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 F083369A3F; Wed, 3 Mar 2021 10:57:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E7B93347E3; Wed, 3 Mar 2021 10:57:29 +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 D4195346FF; Wed, 3 Mar 2021 10:57:24 +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 87EB245827; Wed, 3 Mar 2021 10:57:24 +0100 (CET) From: Stefan Reiter To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Wed, 3 Mar 2021 10:56:08 +0100 Message-Id: <20210303095612.7475-8-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210303095612.7475-1-s.reiter@proxmox.com> References: <20210303095612.7475-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.025 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 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: [pbs-devel] [PATCH v2 qemu-server 07/11] cfg2cmd: allow PBS snapshots as backing files for drives X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2021 09:57:31 -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 --- v2: * build logic directly into print_drive_commandline_full, instead of string replacements in config_to_command * support "rbd:" storage paths as target PVE/QemuServer.pm | 77 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 0c39a6b..22edc2a 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -1514,28 +1514,31 @@ sub get_initiator_name { } sub print_drive_commandline_full { - my ($storecfg, $vmid, $drive) = @_; + my ($storecfg, $vmid, $drive, $pbs_name) = @_; my $path; my $volid = $drive->{file}; - my $format; + my $format = $drive->{format}; if (drive_is_cdrom($drive)) { $path = get_iso_path($storecfg, $vmid, $volid); + die "cannot back cdrom drive with PBS snapshot\n" if $pbs_name; } else { my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1); if ($storeid) { $path = PVE::Storage::path($storecfg, $volid); my $scfg = PVE::Storage::storage_config($storecfg, $storeid); - $format = qemu_img_format($scfg, $volname); + $format //= qemu_img_format($scfg, $volname); } else { $path = $volid; - $format = "raw"; + $format //= "raw"; } } + my $is_rbd = $path =~ m/^rbd:/; + my $opts = ''; - my @qemu_drive_options = qw(heads secs cyls trans media format cache rerror werror aio discard); + my @qemu_drive_options = qw(heads secs cyls trans media cache rerror werror aio discard); foreach my $o (@qemu_drive_options) { $opts .= ",$o=$drive->{$o}" if defined($drive->{$o}); } @@ -1568,7 +1571,13 @@ sub print_drive_commandline_full { } } - $opts .= ",format=$format" if $format && !$drive->{format}; + if ($pbs_name) { + $format = "rbd" if $is_rbd; + die "PBS backing requires a drive with known format\n" if !$format; + $opts .= ",format=alloc-track,file.driver=$format"; + } elsif ($format) { + $opts .= ",format=$format"; + } my $cache_direct = 0; @@ -1598,14 +1607,41 @@ sub print_drive_commandline_full { # This used to be our default with discard not being specified: $detectzeroes = 'on'; } - $opts .= ",detect-zeroes=$detectzeroes" if $detectzeroes; + + # note: 'detect-zeroes' works per blockdev and we want it to persist + # after the alloc-track is removed, so put it on 'file' directly + my $dz_param = $pbs_name ? "file.detect-zeroes" : "detect-zeroes"; + $opts .= ",$dz_param=$detectzeroes" if $detectzeroes; } - my $pathinfo = $path ? "file=$path," : ''; + if ($pbs_name) { + $opts .= ",backing=$pbs_name"; + $opts .= ",auto-remove=on"; + } + + # my $file_param = $pbs_name ? "file.file.filename" : "file"; + my $file_param = "file"; + if ($pbs_name) { + # non-rbd drivers require the underlying file to be a seperate block + # node, so add a second .file indirection + $file_param .= ".file" if !$is_rbd; + $file_param .= ".filename"; + } + my $pathinfo = $path ? "$file_param=$path," : ''; return "${pathinfo}if=none,id=drive-$drive->{interface}$drive->{index}$opts"; } +sub print_pbs_blockdev { + my ($pbs_conf, $pbs_name) = @_; + 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}; + return $blockdev; +} + sub print_netdevice_full { my ($vmid, $conf, $net, $netid, $bridges, $use_old_bios_files, $arch, $machine_type) = @_; @@ -3023,7 +3059,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 = []; @@ -3519,7 +3556,14 @@ sub config_to_command { $ahcicontroller->{$controller}=1; } - my $drive_cmd = print_drive_commandline_full($storecfg, $vmid, $drive); + my $pbs_conf = $pbs_backing->{$ds}; + my $pbs_name = undef; + if ($pbs_conf) { + $pbs_name = "drive-$ds-pbs"; + push @$devices, '-blockdev', print_pbs_blockdev($pbs_conf, $pbs_name); + } + + my $drive_cmd = print_drive_commandline_full($storecfg, $vmid, $drive, $pbs_name); $drive_cmd .= ',readonly' if PVE::QemuConfig->is_template($conf); push @$devices, '-drive',$drive_cmd; @@ -4923,6 +4967,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 @@ -4969,8 +5022,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