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

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