[pve-devel] [PATCH qemu-server 2/4] add function returning virtual size of disk image
Timo Grodzinski
t.grodzinski at profihost.ag
Mon Feb 15 14:33:47 CET 2016
Signed-off-by: Timo Grodzinski <t.grodzinski at profihost.ag>
---
PVE/QemuServer.pm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a130596..6fafa59 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6547,6 +6547,26 @@ sub clone_disk {
return $disk;
}
+sub get_image_size {
+ my ( $storecfg, $volid ) = @_;
+
+ my $path = PVE::Storage::path( $storecfg, $volid );
+
+ my @cmd = ( '/usr/bin/qemu-img', 'info', $path );
+ my $size;
+ my $parser = sub {
+ my ( $line ) = @_;
+ if ( $line =~ m/^virtual size: .*? \((\d+) bytes\)$/ ) {
+ $size = $1;
+ }
+ };
+
+ eval { run_command( \@cmd, timeout => undef, outfunc => $parser ); };
+ die "unable to get image size of volume id '$volid': $@" if $@;
+
+ return $size;
+}
+
# 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