[Pkg-libvirt-commits] [libguestfs] 02/12: v2v: Introduce Types.mpstats struct storing mountpoint statistics.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:45:27 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.45-1
in repository libguestfs.

commit f084fec3817a8f53c16056d50dd080a62d000af6
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Sat Sep 13 14:54:39 2014 +0100

    v2v: Introduce Types.mpstats struct storing mountpoint statistics.
    
    This is just code refactoring.
---
 v2v/types.ml  |  6 ++++++
 v2v/types.mli |  7 +++++++
 v2v/v2v.ml    | 20 ++++++++++++++------
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/v2v/types.ml b/v2v/types.ml
index 315760f..19fd679 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -169,6 +169,12 @@ type inspect = {
   i_apps_map : Guestfs.application2 list StringMap.t;
 }
 
+type mpstat = {
+  mp_dev : string;
+  mp_path : string;
+  mp_statvfs : Guestfs.statvfs;
+}
+
 type guestcaps = {
   gcaps_block_bus : guestcaps_block_type;
   gcaps_net_bus : guestcaps_net_type;
diff --git a/v2v/types.mli b/v2v/types.mli
index 9f6d2a9..500900d 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -110,6 +110,13 @@ type inspect = {
 }
 (** Inspection information. *)
 
+type mpstat = {
+  mp_dev : string;                      (** Filesystem device (eg. /dev/sda1) *)
+  mp_path : string;                     (** Guest mountpoint (eg. /boot) *)
+  mp_statvfs : Guestfs.statvfs;         (** Free space stats. *)
+}
+(** Mountpoint stats, used for free space estimation. *)
+
 type guestcaps = {
   gcaps_block_bus : guestcaps_block_type;
   gcaps_net_bus : guestcaps_net_type;
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index cff5562..60cd461 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -179,9 +179,19 @@ let rec main () =
   msg (f_"Inspecting the overlay");
   let inspect = inspect_source g root_choice in
 
+  (* The guest free disk space check and the target free space
+   * estimation both require statvfs information from mountpoints, so
+   * get that information first.
+   *)
+  let mpstats = List.map (
+    fun (dev, path) ->
+      let statvfs = g#statvfs path in
+      { mp_dev = dev; mp_path = path; mp_statvfs = statvfs }
+  ) (g#mountpoints ()) in
+
   (* Check there is enough free space to perform conversion. *)
   msg (f_"Checking for sufficient free disk space in the guest");
-  check_free_space g;
+  check_free_space mpstats;
 
   (* Conversion. *)
   let guestcaps =
@@ -386,12 +396,10 @@ and inspect_source g root_choice =
  * (RHBZ#1139543).  To avoid this situation, check there is some
  * headroom.  Mainly we care about the root filesystem.
  *)
-and check_free_space g =
-  let mps = g#mountpoints () in
+and check_free_space mpstats =
   List.iter (
-    fun (_, mp) ->
+    fun { mp_path = mp; mp_statvfs = { G.bfree = bfree; bsize = bsize } } ->
       (* bfree = free blocks for root user *)
-      let { G.bfree = bfree; bsize = bsize } = g#statvfs mp in
       let free_bytes = bfree *^ bsize in
       let needed_bytes =
         match mp with
@@ -411,6 +419,6 @@ and check_free_space g =
       if free_bytes < needed_bytes then
         error (f_"not enough free space for conversion on filesystem '%s'.  %Ld bytes free < %Ld bytes needed")
           mp free_bytes needed_bytes
-  ) mps
+  ) mpstats
 
 let () = run_main_and_handle_errors ~prog main

-- 
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