Blame SOURCES/0038-v2v-Increase-required-free-space-in-Windows-to-100-M.patch

62f9b7
From 90e0e0cfe7d90bb9b8cc4a8eb9225266b1622453 Mon Sep 17 00:00:00 2001
62f9b7
From: "Richard W.M. Jones" <rjones@redhat.com>
62f9b7
Date: Thu, 15 Apr 2021 16:52:36 +0100
62f9b7
Subject: [PATCH] v2v: Increase required free space in Windows to 100 MB
62f9b7
62f9b7
With an increasing number of drivers being installed in Windows the
62f9b7
existing limit (20 MB) was far too low.  In fact we found that a guest
62f9b7
with 63 MB of free space would sometimes run out of space.
62f9b7
62f9b7
This commit increases the required space to 100 MB for Windows.
62f9b7
62f9b7
There are also a couple of smaller fixes:
62f9b7
62f9b7
 - We now properly distinguish between / as a Linux boot drive,
62f9b7
   and Windows.
62f9b7
62f9b7
 - The error message has been improved to display MBs instead of bytes.
62f9b7
62f9b7
Reported-by: Ming Xie
62f9b7
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1949147
62f9b7
(cherry picked from commit dfcf60c916a986a352938b432231a36558a3bc05)
62f9b7
---
62f9b7
 docs/virt-v2v.pod |  8 +++++++-
62f9b7
 v2v/v2v.ml        | 46 +++++++++++++++++++++++++---------------------
62f9b7
 2 files changed, 32 insertions(+), 22 deletions(-)
62f9b7
62f9b7
diff --git a/docs/virt-v2v.pod b/docs/virt-v2v.pod
62f9b7
index 50b0bc8e..4016c724 100644
62f9b7
--- a/docs/virt-v2v.pod
62f9b7
+++ b/docs/virt-v2v.pod
62f9b7
@@ -1288,7 +1288,7 @@ to perform the conversion.  Currently it checks:
62f9b7
 
62f9b7
 =over 4
62f9b7
 
62f9b7
-=item Linux root filesystem or Windows C<C:> drive
62f9b7
+=item Linux root filesystem
62f9b7
 
62f9b7
 Minimum free space: 20 MB
62f9b7
 
62f9b7
@@ -1299,6 +1299,12 @@ Minimum free space: 50 MB
62f9b7
 This is because we need to build a new initramfs for some Enterprise
62f9b7
 Linux conversions.
62f9b7
 
62f9b7
+=item Windows C<C:> drive
62f9b7
+
62f9b7
+Minimum free space: 100 MB
62f9b7
+
62f9b7
+We may have to copy in many virtio drivers and guest agents.
62f9b7
+
62f9b7
 =item Any other mountable filesystem
62f9b7
 
62f9b7
 Minimum free space: 10 MB
62f9b7
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
62f9b7
index 1f8d0138..bde51885 100644
62f9b7
--- a/v2v/v2v.ml
62f9b7
+++ b/v2v/v2v.ml
62f9b7
@@ -108,7 +108,7 @@ let rec main () =
62f9b7
   let inspect = Inspect_source.inspect_source cmdline.root_choice g in
62f9b7
 
62f9b7
   let mpstats = get_mpstats g in
62f9b7
-  check_guest_free_space mpstats;
62f9b7
+  check_guest_free_space inspect mpstats;
62f9b7
 
62f9b7
   (* Estimate space required on target for each disk.  Note this is a max. *)
62f9b7
   (match conversion_mode with
62f9b7
@@ -377,27 +377,28 @@ and print_mpstat chan { mp_dev = dev; mp_path = path;
62f9b7
  *
62f9b7
  * Also make sure filesystems have available inodes. (RHBZ#1764569)
62f9b7
  *)
62f9b7
-and check_guest_free_space mpstats =
62f9b7
+and check_guest_free_space inspect mpstats =
62f9b7
   message (f_"Checking for sufficient free disk space in the guest");
62f9b7
 
62f9b7
   (* Check whether /boot has its own mount point. *)
62f9b7
   let has_boot = List.exists (fun { mp_path } -> mp_path = "/boot") mpstats in
62f9b7
+  let is_windows = inspect.i_distro = "windows" in
62f9b7
 
62f9b7
-  let needed_bytes_for_mp = function
62f9b7
-    | "/boot"
62f9b7
-    | "/" when not has_boot ->
62f9b7
-      (* We usually regenerate the initramfs, which has a
62f9b7
-       * typical size of 20-30MB.  Hence:
62f9b7
-       *)
62f9b7
-      50_000_000L
62f9b7
-    | "/" ->
62f9b7
-      (* We may install some packages, and they would usually go
62f9b7
-       * on the root filesystem.
62f9b7
-       *)
62f9b7
-      20_000_000L
62f9b7
-    | _ ->
62f9b7
-      (* For everything else, just make sure there is some free space. *)
62f9b7
-      10_000_000L
62f9b7
+  let needed_megabytes_for_mp = function
62f9b7
+    (* We usually regenerate the initramfs, which has a
62f9b7
+     * typical size of 20-30MB.  Hence:
62f9b7
+     *)
62f9b7
+    | "/boot" | "/" when not has_boot && not is_windows -> 50
62f9b7
+    (* We may install some packages, and they would usually go
62f9b7
+     * on the root filesystem.
62f9b7
+     *)
62f9b7
+    | "/" when not is_windows -> 20
62f9b7
+    (* Windows requires copying in many device drivers and possibly
62f9b7
+     * guest agents, so we need more space.  (RHBZ#1949147).
62f9b7
+     *)
62f9b7
+    | "/" (* when is_windows *) -> 100
62f9b7
+    (* For everything else, just make sure there is some free space. *)
62f9b7
+    | _ -> 10
62f9b7
   in
62f9b7
 
62f9b7
   (* Reasonable headroom for conversion operations. *)
62f9b7
@@ -407,10 +408,13 @@ and check_guest_free_space mpstats =
62f9b7
     fun { mp_path; mp_statvfs = { G.bfree; bsize; files; ffree } } ->
62f9b7
       (* bfree = free blocks for root user *)
62f9b7
       let free_bytes = bfree *^ bsize in
62f9b7
-      let needed_bytes = needed_bytes_for_mp mp_path in
62f9b7
-      if free_bytes < needed_bytes then
62f9b7
-        error (f_"not enough free space for conversion on filesystem ‘%s’.  %Ld bytes free < %Ld bytes needed")
62f9b7
-          mp_path free_bytes needed_bytes;
62f9b7
+      let needed_megabytes = needed_megabytes_for_mp mp_path in
62f9b7
+      let needed_bytes = Int64.of_int needed_megabytes *^ 1024L *^ 1024L in
62f9b7
+      if free_bytes < needed_bytes then (
62f9b7
+        let mb i = Int64.to_float i /. 1024. /. 1024. in
62f9b7
+        error (f_"not enough free space for conversion on filesystem ‘%s’.  %.1f MB free < %d MB needed")
62f9b7
+          mp_path (mb free_bytes) needed_megabytes
62f9b7
+      );
62f9b7
       (* Not all the filesystems have inode counts. *)
62f9b7
       if files > 0L && ffree < needed_inodes then
62f9b7
         error (f_"not enough available inodes for conversion on filesystem ‘%s’.  %Ld inodes available < %Ld inodes needed")
62f9b7
-- 
0602f3
2.31.1
62f9b7