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 <[email protected]>
---
 PVE/QemuServer/Cloudinit.pm | 32 +++++---------------------------
 1 file changed, 5 insertions(+), 27 deletions(-)

diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
index dd0be77..566c723 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -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 {
-- 
2.11.0


_______________________________________________
pve-devel mailing list
[email protected]
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to