--- Begin Message ---
Signed-off-by: Alexandre Derumier <alexandre.derum...@groupe-cyllene.com>
---
src/PVE/Storage/Common.pm | 40 +++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm
index 25f5d28..11b5b94 100644
--- a/src/PVE/Storage/Common.pm
+++ b/src/PVE/Storage/Common.pm
@@ -241,4 +241,44 @@ sub qemu_img_info {
return $json;
}
+=pod
+
+=head3 qemu_img_measure
+
+ qemu_img_measure($size, $fmt, $timeout, $is_backed)
+
+Returns a json with the maximum size including all metadatas overhead for an
image with format C<$fmt> and original size C<$size>Kb.
+If the image is backed C<$is_backed>, we use different cluster size
informations.
+=cut
+
+sub qemu_img_measure {
+ my ($size, $fmt, $timeout, $is_backed) = @_;
+
+ die "format is missing" if !$fmt;
+
+ my $cmd = ['/usr/bin/qemu-img', 'measure', '--output=json', '--size',
"${size}K", '-O', $fmt];
+ if ($is_backed) {
+ my $options = $QCOW2_CLUSTERS->{backed};
+ push $cmd->@*, '-o', join(',', @$options) if @$options > 0;
+ }
+
+ my $json = '';
+ my $err_output = '';
+ eval {
+ run_command($cmd,
+ timeout => $timeout,
+ outfunc => sub { $json .= shift },
+ errfunc => sub { $err_output .= shift . "\n"},
+ );
+ };
+ warn $@ if $@;
+ if ($err_output) {
+ # if qemu did not output anything to stdout we die with stderr as an
error
+ die $err_output if !$json;
+ # otherwise we warn about it and try to parse the json
+ warn $err_output;
+ }
+ return $json;
+}
+
1;
--
2.39.5
--- End Message ---
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel