[pve-devel] [PATCH qemu-server 3/3] map vmid correctly for cloudinit on restore

Mira Limbeck m.limbeck at proxmox.com
Tue Mar 26 15:10:19 CET 2019


on restore the cloudinit disk is now changed to the correct vmid. in
addition targetstorage is taken into account as well.

Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
---
 PVE/QemuServer.pm | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e60aa28..87252cf 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6265,6 +6265,14 @@ sub restore_vma_archive {
 		$storage_limits{$storeid} = $bwlimit;
 
 		$virtdev_hash->{$virtdev} = $devinfo->{$devname};
+	    } elsif ($line =~ m/^(ide\d):\s*(\S*\/vm-\d+-cloudinit(.(qcow2|raw))?)\S+\s*$/) {
+		my ($virtdev, $volid, $format) = ($1, $2, $4);
+		my $d = {};
+		$d->{volid} = $volid;
+		$d->{format} = $format;
+		$d->{size} = 4 * 1024 * 1024;
+		$d->{storeid} = $opts->{storage} // PVE::Storage::parse_volume_id($volid);
+		$virtdev_hash->{$virtdev} = $d;
 	    }
 	}
 
@@ -6321,6 +6329,7 @@ sub restore_vma_archive {
 	my $map = {};
 	foreach my $virtdev (sort keys %$virtdev_hash) {
 	    my $d = $virtdev_hash->{$virtdev};
+	    my $is_cloudinit = $d->{volid} ? $d->{volid} =~ m/vm-\d+-cloudinit/ : 0;
 	    my $alloc_size = int(($d->{size} + 1024 - 1)/1024);
 	    my $storeid = $d->{storeid};
 	    my $scfg = PVE::Storage::storage_config($cfg, $storeid);
@@ -6335,8 +6344,13 @@ sub restore_vma_archive {
 	    my $supported = grep { $_ eq $d->{format} } @$validFormats;
 	    $d->{format} = $defFormat if !$supported;
 
+	    my $name = undef;
+	    if ($is_cloudinit) {
+		$name = "vm-$vmid-cloudinit";
+		$name .= ".qcow2" if $scfg->{path};
+	    }
 	    my $volid = PVE::Storage::vdisk_alloc($cfg, $storeid, $vmid,
-						  $d->{format}, undef, $alloc_size);
+						  $d->{format}, $name, $alloc_size);
 	    print STDERR "new volume ID is '$volid'\n";
 	    $d->{volid} = $volid;
 	    my $path = PVE::Storage::path($cfg, $volid);
@@ -6348,9 +6362,12 @@ sub restore_vma_archive {
 		$write_zeros = 0;
 	    }
 
-	    print $fifofh "${map_opts}format=$d->{format}:${write_zeros}:$d->{devname}=$path\n";
+	    if (!$is_cloudinit) { # $d->{devname} undefined if it is cloudinit
+		print $fifofh "${map_opts}format=$d->{format}:${write_zeros}:$d->{devname}=$path\n";
+
+		print "map '$d->{devname}' to '$path' (write zeros = ${write_zeros})\n";
+	    }
 
-	    print "map '$d->{devname}' to '$path' (write zeros = ${write_zeros})\n";
 	    $map->{$virtdev} = $volid;
 	}
 
-- 
2.11.0





More information about the pve-devel mailing list