[pve-devel] [PATCH 3/4] add qemu_img_convert
Alexandre Derumier
aderumier at odiso.com
Fri Oct 26 14:32:03 CEST 2012
implement qemu-img convert command
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer.pm | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2cb7deb..5c2b26b 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4031,4 +4031,33 @@ sub snapshot_delete {
lock_config($vmid, $updatefn);
}
+sub qemu_img_convert {
+ my ($src_volid, $dst_volid) = @_;
+
+ 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);
+
+ if ($src_storeid && $dst_storeid) {
+ my $src_scfg = PVE::Storage::storage_config($storecfg, $src_storeid);
+ my $dst_scfg = PVE::Storage::storage_config($storecfg, $dst_storeid);
+
+ my $src_format = qemu_img_format($src_scfg, $src_volname);
+ my $dst_format = qemu_img_format($dst_scfg, $dst_volname);
+
+ PVE::Storage::activate_volumes($storecfg, [ $dst_volid ]) if $dst_format =~ m/(host_device|iscsi)/;
+
+ my $src_path = PVE::Storage::path($storecfg, $src_volid);
+ my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
+
+ my $cmd = ['/usr/bin/qemu-img', 'convert', '-p', '-f', $src_format, '-O', $dst_format, $src_path, $dst_path];
+ #fixme, display progress percent while cmd is running
+ eval { run_command($cmd, timeout => undef); };
+ my $err = $@;
+ die "copy failed: $err" if $err;
+
+ }
+
+}
+
1;
--
1.7.10.4
More information about the pve-devel
mailing list