[pve-devel] [PATCH qemu-server 1/2] introduce one global cloudinit disk size variable

Mira Limbeck m.limbeck at proxmox.com
Mon May 13 14:01:53 CEST 2019


this variable $CLOUDINIT_DISK_SIZE is to be used everywhere the size is
currently specified (as 4 * 1024 * 1024) so we can change it once for all
occurrences.
additionally make the swap from literal value to variable everywhere it's used.

Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
---
 PVE/API2/Qemu.pm            | 4 ++--
 PVE/QemuServer/Cloudinit.pm | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 62e6549..4264dfa 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -159,8 +159,8 @@ my $create_disks = sub {
 	    }
 
 	    # Initial disk created with 4 MB and aligned to 4MB on regeneration
-	    my $ci_size = 4 * 1024;
-	    my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, $name, $ci_size);
+	    my $ci_size = $PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE;
+	    my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, $name, $ci_size/1024);
 	    $disk->{file} = $volid;
 	    $disk->{media} = 'cdrom';
 	    push @$vollist, $volid;
diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
index f46f7fd..19815b7 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -11,6 +11,8 @@ use PVE::Tools qw(run_command file_set_contents);
 use PVE::Storage;
 use PVE::QemuServer;
 
+our $CLOUDINIT_DISK_SIZE = 4 * 1024 * 1024; # 4MiB in bytes
+
 sub commit_cloudinit_disk {
     my ($conf, $vmid, $drive, $volname, $storeid, $files, $label) = @_;
 
@@ -36,9 +38,9 @@ sub commit_cloudinit_disk {
     if ($size <= 0) {
 	$volname =~ m/(vm-$vmid-cloudinit(.\Q$format\E)?)/;
 	my $name = $1;
-	$size = 4 * 1024;
-	PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $name, $size);
-	$size *= 1024; # vdisk alloc takes KB, qemu-img dd's osize takes byte
+	$size = $CLOUDINIT_DISK_SIZE;
+	# vdisk alloc takes KB, qemu-img dd's osize takes byte
+	PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $name, $size/1024);
     }
 
     my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
-- 
2.11.0





More information about the pve-devel mailing list