]> git.proxmox.com Git - qemu-server.git/commitdiff
cloudinit: create disk if it does not exist on start
authorMira Limbeck <m.limbeck@proxmox.com>
Fri, 29 Mar 2019 15:32:03 +0000 (16:32 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 29 Mar 2019 17:11:33 +0000 (18:11 +0100)
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@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuServer/Cloudinit.pm

index 99e37d8771888eaf2277435cc5f5824f4f26f878..a156117a6e42ea34dcc157f9fd64c6cd08726808 100644 (file)
@@ -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;
index e83c0db454adb0de455ed199a1d2fc698119d4df..445c777170a5b3c9ce4ef8e1904c70859ebfc15c 100644 (file)
@@ -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 = {