[Pkg-libvirt-commits] [libguestfs] 11/35: v2v: -o rhev/vdsm: Fix ovf:size and ovf:actual_size fields (RHBZ#1142008).

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:46:40 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.49-1
in repository libguestfs.

commit fe36b2ce950d214aa198daf86188e8fdbe41f43f
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Sep 17 12:49:00 2014 +0100

    v2v: -o rhev/vdsm: Fix ovf:size and ovf:actual_size fields (RHBZ#1142008).
    
    These are integers in gigabytes (2^30).
    
    Thanks: Shahar Havivi.
---
 v2v/lib_ovf.ml | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/v2v/lib_ovf.ml b/v2v/lib_ovf.ml
index cac1012..5dd0f58 100644
--- a/v2v/lib_ovf.ml
+++ b/v2v/lib_ovf.ml
@@ -326,22 +326,27 @@ and add_disks targets guestcaps output_alloc sd_uuid image_uuid vol_uuids ovf =
 
       let fileref = image_uuid // vol_uuid in
 
-      let size_gb =
-        Int64.to_float ov.ov_virtual_size /. 1024. /. 1024. /. 1024. in
-      let usage_gb =
+      (* ovf:size and ovf:actual_size fields are integer GBs.  If you
+       * use floating point numbers then RHEV will fail to parse them.
+       * In case the size is just below a gigabyte boundary, round up.
+       *)
+      let bytes_to_gb b =
+        let b = roundup64 b 1073741824L in
+        b /^ 1073741824L
+      in
+      let size_gb = bytes_to_gb ov.ov_virtual_size in
+      let actual_size_gb =
         if Sys.file_exists t.target_file then (
-          let usage_mb = du_m t.target_file in
-          if usage_mb > 0L then (
-            let usage_gb = Int64.to_float usage_mb /. 1024. in
-            Some usage_gb
-          ) else None
+          let actual_size = du t.target_file in
+          if actual_size > 0L then Some (bytes_to_gb actual_size)
+          else None
         ) else (
           (* In the --no-copy case the target file does not exist.  In
            * that case we use the estimated size.
            *)
           match t.target_estimated_size with
           | None -> None
-          | Some size -> Some (Int64.to_float size /. 1024. /. 1024. /. 1024.)
+          | Some size -> Some (bytes_to_gb size)
         ) in
 
       let format_for_rhev =
@@ -361,7 +366,7 @@ and add_disks targets guestcaps output_alloc sd_uuid image_uuid vol_uuids ovf =
         e "File" [
           "ovf:href", fileref;
           "ovf:id", vol_uuid;
-          "ovf:size", Int64.to_string ov.ov_virtual_size;
+          "ovf:size", Int64.to_string ov.ov_virtual_size; (* NB: in bytes *)
           "ovf:description", title;
         ] [] in
       append_child disk references;
@@ -370,7 +375,7 @@ and add_disks targets guestcaps output_alloc sd_uuid image_uuid vol_uuids ovf =
       let disk =
         let attrs = [
           "ovf:diskId", vol_uuid;
-          "ovf:size", sprintf "%.1f" size_gb;
+          "ovf:size", Int64.to_string size_gb;
           "ovf:fileRef", fileref;
           "ovf:parentRef", "";
           "ovf:vm_snapshot_id", uuidgen ~prog ();
@@ -384,10 +389,10 @@ and add_disks targets guestcaps output_alloc sd_uuid image_uuid vol_uuids ovf =
           "ovf:boot", if is_boot_drive then "True" else "False";
         ] in
         let attrs =
-          match usage_gb with
+          match actual_size_gb with
           | None -> attrs
-          | Some usage_gb ->
-            ("ovf:actual_size", sprintf "%.1f" usage_gb) :: attrs in
+          | Some actual_size_gb ->
+            ("ovf:actual_size", Int64.to_string actual_size_gb) :: attrs in
         e "Disk" attrs [] in
       append_child disk disk_section;
 
@@ -409,11 +414,11 @@ and add_disks targets guestcaps output_alloc sd_uuid image_uuid vol_uuids ovf =
       append_child item virtualhardware_section;
   ) (List.combine targets vol_uuids)
 
-and du_m filename =
-  (* There's no OCaml binding for st_blocks, so run coreutils 'du -m'
-   * to get the used size in megabytes.
+and du filename =
+  (* There's no OCaml binding for st_blocks, so run coreutils 'du'
+   * to get the used size in bytes.
    *)
-  let cmd = sprintf "du -m %s | awk '{print $1}'" (quote filename) in
+  let cmd = sprintf "du -b %s | awk '{print $1}'" (quote filename) in
   let lines = external_command ~prog cmd in
   (* We really don't want the metadata generation to fail because
    * of some silly usage information, so ignore errors here.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list