]> git.proxmox.com Git - qemu-server.git/commitdiff
cloud-init: use qemu-img dd instead of nbd
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 23 Feb 2018 09:27:30 +0000 (10:27 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Mar 2018 08:11:31 +0000 (09:11 +0100)
We now have a patch on top of qemu to allow 'qemu-img dd'
to read from stdin when specifying input and output sizes,
as well as a way to tell it that the size of the source is
not known.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
PVE/QemuServer/Cloudinit.pm

index dd0be779eca2a8ae08fd28ae6a76e61ef77b4909..566c723b4a1542ba3423a0db85a98b1c82116a72 100644 (file)
@@ -11,36 +11,14 @@ use PVE::Tools qw(run_command file_set_contents);
 use PVE::Storage;
 use PVE::QemuServer;
 
-sub nbd_stop {
-    my ($vmid) = @_;
-
-    PVE::QemuServer::vm_mon_cmd($vmid, 'nbd-server-stop');
-}
-
-sub next_free_nbd_dev {
-    for(my $i = 0;;$i++) {
-       my $dev = "/dev/nbd$i";
-       last if ! -b $dev;
-       next if -f "/sys/block/nbd$i/pid"; # busy
-       return $dev;
-    }
-    die "unable to find free nbd device\n";
-}
-
 sub commit_cloudinit_disk {
     my ($file_path, $iso_path, $format) = @_;
 
-    my $nbd_dev = next_free_nbd_dev();
-    run_command(['qemu-nbd', '-c', $nbd_dev, $iso_path, '-f', $format]);
-
-    eval {
-       run_command([['genisoimage', '-R', '-V', 'config-2', $file_path],
-                    ['dd', "of=$nbd_dev", 'conv=fsync']]);
-    };
-    my $err = $@;
-    eval { run_command(['qemu-nbd', '-d', $nbd_dev]); };
-    warn $@ if $@;
-    die $err if $err;
+    my $size = PVE::Storage::file_size_info($iso_path);
+
+    run_command([['genisoimage', '-R', '-V', 'config-2', $file_path],
+                ['qemu-img', 'dd', '-f', 'raw', '-O', $format,
+                 'isize=0', "osize=$size", "of=$iso_path"]]);
 }
 
 sub generate_cloudinitconfig {