[pve-devel] [PATCH 2/2] qemu_img_convert: allow $path as src image
Alexandre Derumier
aderumier at odiso.com
Thu Jan 19 07:17:31 CET 2017
This allow to use a path as src image directly, without storeid.
We don't try to detect the src format ourself (vmware can export raw file with vmdk extension for example)
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer.pm | 67 ++++++++++++++++++++++++++++++-------------------------
1 file changed, 37 insertions(+), 30 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index b86a470..054394b 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5861,45 +5861,52 @@ sub qemu_img_convert {
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);
- if ($src_storeid && $dst_storeid) {
+ return if !$dst_storeid;
- PVE::Storage::activate_volumes($storecfg, [$src_volid], $snapname);
+ my $dst_scfg = PVE::Storage::storage_config($storecfg, $dst_storeid);
+ my $dst_format = qemu_img_format($dst_scfg, $dst_volname);
+ my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
- my $src_scfg = PVE::Storage::storage_config($storecfg, $src_storeid);
- my $dst_scfg = PVE::Storage::storage_config($storecfg, $dst_storeid);
+ my $src_format = undef;
+ my $src_path = undef;
- my $src_format = qemu_img_format($src_scfg, $src_volname);
- my $dst_format = qemu_img_format($dst_scfg, $dst_volname);
+ if ($src_storeid) {
- my $src_path = PVE::Storage::path($storecfg, $src_volid, $snapname);
- my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
+ PVE::Storage::activate_volumes($storecfg, [$src_volid], $snapname);
+ my $src_scfg = PVE::Storage::storage_config($storecfg, $src_storeid);
+ $src_format = qemu_img_format($src_scfg, $src_volname);
+ $src_path = PVE::Storage::path($storecfg, $src_volid, $snapname);
- my $cmd = [];
- push @$cmd, '/usr/bin/qemu-img', 'convert', '-p', '-n';
- push @$cmd, '-s', $snapname if($snapname && $src_format eq "qcow2");
- push @$cmd, '-f', $src_format, '-O', $dst_format, $src_path;
- if ($is_zero_initialized) {
- push @$cmd, "zeroinit:$dst_path";
- } else {
- push @$cmd, $dst_path;
- }
+ } else {
+ $src_path = $src_volid;
+ }
- my $parser = sub {
- my $line = shift;
- if($line =~ m/\((\S+)\/100\%\)/){
- my $percent = $1;
- my $transferred = int($size * $percent / 100);
- my $remaining = $size - $transferred;
+ my $cmd = [];
+ push @$cmd, '/usr/bin/qemu-img', 'convert', '-p', '-n';
+ push @$cmd, '-s', $snapname if($snapname && $src_format eq "qcow2");
+ push @$cmd, '-f', $src_format if $src_format;
+ push @$cmd, '-O', $dst_format, $src_path;
+ if ($is_zero_initialized) {
+ push @$cmd, "zeroinit:$dst_path";
+ } else {
+ push @$cmd, $dst_path;
+ }
- print "transferred: $transferred bytes remaining: $remaining bytes total: $size bytes progression: $percent %\n";
- }
+ my $parser = sub {
+ my $line = shift;
+ if($line =~ m/\((\S+)\/100\%\)/){
+ my $percent = $1;
+ my $transferred = int($size * $percent / 100);
+ my $remaining = $size - $transferred;
- };
+ print "transferred: $transferred bytes remaining: $remaining bytes total: $size bytes progression: $percent %\n";
+ }
- eval { run_command($cmd, timeout => undef, outfunc => $parser); };
- my $err = $@;
- die "copy failed: $err" if $err;
- }
+ };
+
+ eval { run_command($cmd, timeout => undef, outfunc => $parser); };
+ my $err = $@;
+ die "copy failed: $err" if $err;
}
sub qemu_img_format {
--
2.1.4
More information about the pve-devel
mailing list