[pve-devel] [PATCH qemu-server] WIP: upload disk image

Timo Grodzinski t.grodzinski at profihost.ag
Fri Jan 29 18:43:32 CET 2016


Signed-off-by: Timo Grodzinski <t.grodzinski at profihost.ag>
---
 PVE/QemuServer.pm | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 14a18f0..a0adca5 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6333,12 +6333,17 @@ sub is_template {
 }
 
 sub qemu_img_convert {
-    my ($src_volid, $dst_volid, $size, $snapname) = @_;
+    my ($src_volid, $dst_volid, $size, $snapname, $dont_create_target) = @_;
 
     my $storecfg = PVE::Storage::config();
     my ($src_storeid, $src_volname) = PVE::Storage::parse_volume_id($src_volid, 1);
     my ($dst_storeid, $dst_volname) = PVE::Storage::parse_volume_id($dst_volid, 1);
 
+    use Data::Dumper;
+    print 'qemu_img_convert: ' . Dumper( {
+        src_storeid => $src_storeid,
+        dst_storeid=>$dst_storeid,});
+
     if ($src_storeid && $dst_storeid) {
 
 	PVE::Storage::activate_volumes($storecfg, [$src_volid], $snapname);
@@ -6353,10 +6358,13 @@ sub qemu_img_convert {
 	my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
 
 	my $cmd = [];
-	push @$cmd, '/usr/bin/qemu-img', 'convert', '-t', 'writeback', '-p', '-n';
+	push @$cmd, '/usr/bin/qemu-img', 'convert', '-t', 'writeback', '-p';
+        push @$cmd, '-n' if !$dont_create_target; # XXX
 	push @$cmd, '-s', $snapname if($snapname && $src_format eq "qcow2");
 	push @$cmd, '-f', $src_format, '-O', $dst_format, $src_path, $dst_path;
 
+        print 'qemu_img_convert: ' . Dumper $cmd;
+
 	my $parser = sub {
 	    my $line = shift;
 	    if($line =~ m/\((\S+)\/100\%\)/){
@@ -6508,6 +6516,33 @@ sub clone_disk {
     return $disk;
 }
 
+sub import_disk {
+    my ($file, $storecfg, $vmid, $drive, $newvollist) = @_;
+
+    my $volid =  $drive->{file};
+
+    my ($size) = PVE::Storage::volume_size_info($storecfg, $file, 3);
+
+    print "import disk $file\n";
+    push @$newvollist, $volid;
+
+    PVE::Storage::activate_volumes($storecfg, $newvollist);
+
+    print 'import_disk: ' . Dumper { file=>$file,volid=>$volid,size=>$size };
+
+    qemu_img_convert($file, $volid, $size, undef, 'dont_create_target');
+
+    ($size) = PVE::Storage::volume_size_info($storecfg, $volid, 3);
+
+    my $disk = $drive;
+    $disk->{format} = undef;
+    $disk->{file} = $volid;
+    $disk->{size} = $size;
+
+    return $disk;
+}
+
+
 # this only works if VM is running
 sub get_current_qemu_machine {
     my ($vmid) = @_;
-- 
2.1.4




More information about the pve-devel mailing list