[pve-devel] [PATCH qemu-server] WIP: upload disk image
Wolfgang Bumiller
w.bumiller at proxmox.com
Mon Feb 1 09:57:31 CET 2016
On Fri, Jan 29, 2016 at 06:43:32PM +0100, Timo Grodzinski wrote:
> 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
This seems to be backwards:
qemu-img(1):
-n Skip the creation of the target volume
So this reads: 'skip creation if "don't not create"'
One too many nots there ;-)
s/dont_create_target/create_target/
> 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');
Use 1 instead of a string, since a string makes it look like you can
also write 'create target' in there which will not do what is expected.
> +
> + ($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
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
More information about the pve-devel
mailing list