[pve-devel] [PATCH v4 qemu-server 04/10] cloud-init: use qemu-img dd instead of nbd

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Mar 1 12:44:11 CET 2018


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 at proxmox.com>
---
 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





More information about the pve-devel mailing list