Blob Blame History Raw
From 923789a842239fa18e45f42f22126ef0f4aa6802 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 23 Jun 2016 13:27:09 +0100
Subject: [PATCH] v2v: Refuse to convert if < 1GB of free space in temporary
 directory (RHBZ#1316479).

The error you would see is:

  virt-v2v: error: insufficient free space in the conversion server temporary
  directory /var/tmp (853.8M).

  Either free up space in that directory, or set the LIBGUESTFS_CACHEDIR
  environment variable to point to another directory with more than 1GB of
  free space.

  See also the virt-v2v(1) manual, section "Minimum free space check in the
  host".

Also adds some documentation.

Thanks: Ming Xie and Xiaodai Wang
(cherry picked from commit 9221ef6f7959ae3b979fd05007363810bc66062b)
---
 v2v/Makefile.am  |  4 ++++
 v2v/v2v.ml       | 15 +++++++++++++++
 v2v/virt-v2v.pod | 19 +++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index a996e5d..e0d013a 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -117,6 +117,7 @@ SOURCES_ML = \
 SOURCES_C = \
 	../mllib/dev_t-c.c \
 	../mllib/mkdtemp-c.c \
+	../mllib/statvfs-c.c \
 	domainxml-c.c \
 	changeuid-c.c \
 	utils-c.c \
@@ -145,6 +146,7 @@ BOBJECTS = \
 	$(top_builddir)/mllib/regedit.cmo \
 	$(top_builddir)/mllib/mkdtemp.cmo \
 	$(top_builddir)/mllib/JSON.cmo \
+	$(top_builddir)/mllib/StatVFS.cmo \
 	$(top_builddir)/mllib/curl.cmo \
 	$(top_builddir)/customize/customize_utils.cmo \
 	$(top_builddir)/customize/firstboot.cmo \
@@ -192,6 +194,7 @@ virt_v2v_LINK = \
 
 virt_v2v_copy_to_local_SOURCES = \
 	../mllib/dev_t-c.c \
+	../mllib/statvfs-c.c \
 	domainxml-c.c \
 	utils-c.c \
 	xml-c.c
@@ -211,6 +214,7 @@ COPY_TO_LOCAL_BOBJECTS = \
 	$(top_builddir)/mllib/dev_t.cmo \
 	$(top_builddir)/mllib/common_utils.cmo \
 	$(top_builddir)/mllib/JSON.cmo \
+	$(top_builddir)/mllib/StatVFS.cmo \
 	$(top_builddir)/mllib/curl.cmo \
 	xml.cmo \
 	utils.cmo \
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index f3eae43..4b06bc1 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -49,6 +49,7 @@ let rec main () =
 
   let conversion_mode =
     if not cmdline.in_place then (
+      check_host_free_space ();
       let overlays = create_overlays source.s_disks in
       let targets = init_targets cmdline output source overlays in
       Copying (overlays, targets)
@@ -203,6 +204,20 @@ and amend_source cmdline source =
 
 and overlay_dir = (open_guestfs ())#get_cachedir ()
 
+(* Conversion can fail or hang if there is insufficient free space in
+ * the temporary directory used to store overlays on the host
+ * (RHBZ#1316479).  Although only a few hundred MB is actually
+ * required, make the minimum be 1 GB to allow for the possible 500 MB
+ * guestfs appliance which is also stored here.
+ *)
+and check_host_free_space () =
+  let free_space = StatVFS.free_space overlay_dir in
+  debug "check_host_free_space: overlay_dir=%s free_space=%Ld"
+        overlay_dir free_space;
+  if free_space < 1_073_741_824L then
+    error (f_"insufficient free space in the conversion server temporary directory %s (%s).\n\nEither free up space in that directory, or set the LIBGUESTFS_CACHEDIR environment variable to point to another directory with more than 1GB of free space.\n\nSee also the virt-v2v(1) manual, section \"Minimum free space check in the host\".")
+          overlay_dir (human_size free_space)
+
 (* Create a qcow2 v3 overlay to protect the source image(s). *)
 and create_overlays src_disks =
   message (f_"Creating an overlay to protect the source from being modified");
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 4ea02ab..c68bcb5 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -1495,6 +1495,8 @@ This temporarily places a full copy of the output disks in C<$TMPDIR>.
 
 =back
 
+See also L</Minimum free space check in the host> below.
+
 =head2 VMware vCenter resources
 
 Copying from VMware vCenter is currently quite slow, but we believe
@@ -1546,6 +1548,8 @@ prevent the guest from subsequently booting correctly.
 
 =head1 FREE SPACE FOR CONVERSION
 
+=head2 Free space in the guest
+
 Virt-v2v checks there is sufficient free space in the guest filesystem
 to perform the conversion.  Currently it checks:
 
@@ -1568,6 +1572,21 @@ Minimum free space: 10 MB
 
 =back
 
+=head2 Minimum free space check in the host
+
+You must have sufficient free space in the host directory used to
+store temporary overlays (except in [--in-place] mode).  To find out
+which directory this is, use:
+
+ $ df -h "`guestfish get-cachedir`"
+ Filesystem        Size  Used Avail Use% Mounted on
+ /dev/mapper/root   50G   40G  6.8G  86% /
+
+and look under the C<Avail> column.  Virt-v2v will refuse to do the
+conversion at all unless at least 1GB is available there.
+
+See also L</RESOURCE REQUIREMENTS> above.
+
 =head1 RUNNING VIRT-V2V AS ROOT OR NON-ROOT
 
 Nothing in virt-v2v inherently needs root access, and it will run just
-- 
2.7.4