From 3db6e4ab708b29e9e59572efd8e44558c84bad6d Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 23 Feb 2018 10:27:30 +0100 Subject: [PATCH] cloud-init: use qemu-img dd instead of nbd 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 --- PVE/QemuServer/Cloudinit.pm | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index dd0be779..566c723b 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]); + my $size = PVE::Storage::file_size_info($iso_path); - 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; + 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 {