[pve-devel] [PATCH v2 qemu-server 1/3] cloudinit: create disk if it does not exist on start

Mira Limbeck m.limbeck at proxmox.com
Fri Mar 29 16:32:03 CET 2019


create a fixed size cloudinit disk if it is referenced in config and
does not exist. the size of the disk created when first added to the
config is reduced to 4MiB to match the one created in
commit_cloudinit_disk.
maximum file size per snippet file (network, user, meta) is increased to 1MiB.
preparation for offline migration without the cloudinit disk (that is
always regenerated on start).

also fixes #1807, although a further patch is required to change the
vmid on restore

Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
Tested-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Qemu.pm            |  4 ++--
 PVE/QemuServer/Cloudinit.pm | 10 ++++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 99e37d8..a156117 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -156,8 +156,8 @@ my $create_disks = sub {
 	    }else{
 		$fmt = 'raw';
 	    }
-	    # FIXME: Reasonable size? qcow2 shouldn't grow if the space isn't used anyway?
-	    my $cloudinit_iso_size = 5; # in MB
+	    # Initial disk created with 4MB, every time it is regenerated the disk is aligned to 4MB again.
+	    my $cloudinit_iso_size = 4; # in MB
 	    my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, 
 						  $fmt, $name, $cloudinit_iso_size*1024);
 	    $disk->{file} = $volid;
diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
index 0f8fc7a..c3bbffd 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -30,9 +30,15 @@ sub commit_cloudinit_disk {
     my $storecfg = PVE::Storage::config();
     my $iso_path = PVE::Storage::path($storecfg, $drive->{file});
     my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+    my $format = PVE::QemuServer::qemu_img_format($scfg, $volname);
+    if (! -e $iso_path) {
+	$volname =~ m/(vm-$vmid-cloudinit(.(qcow2|raw))?)/;
+	my $name = $1;
+	my $d = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $name, 4 * 1024);
+    }
+
     my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
     $plugin->activate_volume($storeid, $scfg, $volname);
-    my $format = PVE::QemuServer::qemu_img_format($scfg, $volname);
 
     my $size = PVE::Storage::file_size_info($iso_path);
 
@@ -434,7 +440,7 @@ sub read_cloudinit_snippets_file {
 
     my ($full_path, undef, $type) = PVE::Storage::path($storage_conf, $volid);
     die "$volid is not in the snippets directory\n" if $type ne 'snippets';
-    return PVE::Tools::file_get_contents($full_path);
+    return PVE::Tools::file_get_contents($full_path, 1 * 1024 * 1024);
 }
 
 my $cloudinit_methods = {
-- 
2.11.0





More information about the pve-devel mailing list