[pve-devel] [PATCH qemu-server 1/2] introduce one global cloudinit disk size variable
Mira Limbeck
m.limbeck at proxmox.com
Tue May 14 09:54:59 CEST 2019
On 5/14/19 9:01 AM, Thomas Lamprecht wrote:
> On 5/13/19 2:01 PM, Mira Limbeck wrote:
>> 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
> maybe we want to have this as constant, as else a module user could change
> it, which would result in confusing stuff happening..
>
> use constant CLOUDINIT_DISK_SIZE => 4 * 1024 * 1024; # 4MiB in bytes
>
>
> internal this effectively just produces a submethod with minimal syntax sugar.
> You could then use it CLOUDINIT_DISK_SIZE or MODULE::NAME::CLOUDINIT_DISK_SIZE,
> respectively. What you think?
Yes, a lot better. I looked into that but for some reason dismissed it.
Will take a look again.
>> +
>> 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});
>>
More information about the pve-devel
mailing list