[pve-devel] [PATCH v4 qemu-server 09/10] cloud-init: clone/move support

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Mar 1 12:44:16 CET 2018


move: don't error out with "you can't move a cdrom"
clone: always full-clone cloud-init images
  They get completely replaced anyway at the next start, so
  there's no point in keeping them.

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 PVE/API2/Qemu.pm  |  6 +++---
 PVE/QemuServer.pm | 12 +++++++++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index c39fc83..3aec4b7 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2601,10 +2601,10 @@ __PACKAGE__->register_method({
 		} elsif (PVE::QemuServer::is_valid_drivename($opt)) {
 		    my $drive = PVE::QemuServer::parse_drive($opt, $value);
 		    die "unable to parse drive options for '$opt'\n" if !$drive;
-		    if (PVE::QemuServer::drive_is_cdrom($drive)) {
+		    if (PVE::QemuServer::drive_is_cdrom($drive, 1)) {
 			$newconf->{$opt} = $value; # simply copy configuration
 		    } else {
-			if ($param->{full}) {
+			if ($param->{full} || PVE::QemuServer::drive_is_cloudinit($drive)) {
 			    die "Full clone feature is not supported for drive '$opt'\n"
 				if !PVE::Storage::volume_has_feature($storecfg, 'copy', $drive->{file}, $snapname, $running);
 			    $fullclone->{$opt} = 1;
@@ -2812,7 +2812,7 @@ __PACKAGE__->register_method({
 
 	    my $old_volid = $drive->{file} || die "disk '$disk' has no associated volume\n";
 
-	    die "you can't move a cdrom\n" if PVE::QemuServer::drive_is_cdrom($drive);
+	    die "you can't move a cdrom\n" if PVE::QemuServer::drive_is_cdrom($drive, 1);
 
 	    my $oldfmt;
 	    my ($oldstoreid, $oldvolname) = PVE::Storage::parse_volume_id($old_volid);
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 04b6cb8..3f7118d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6395,7 +6395,17 @@ sub clone_disk {
 	my ($size) = PVE::Storage::volume_size_info($storecfg, $drive->{file}, 3);
 
 	print "create full clone of drive $drivename ($drive->{file})\n";
-	$newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newvmid, $dst_format, undef, ($size/1024));
+	my $name = undef;
+	if (drive_is_cloudinit($drive)) {
+	    $name = "vm-$newvmid-cloudinit";
+	    # cloudinit only supports raw and qcow2 atm:
+	    if ($dst_format eq 'qcow2') {
+		$name .= '.qcow2';
+	    } elsif ($dst_format ne 'raw') {
+		die "clone: unhandled format for cloudinit image\n";
+	    }
+	}
+	$newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newvmid, $dst_format, $name, ($size/1024));
 	push @$newvollist, $newvolid;
 
 	PVE::Storage::activate_volumes($storecfg, [$newvolid]);
-- 
2.11.0





More information about the pve-devel mailing list