This tool can be used to estimate the disk space needed before doing a virt-v2v conversion. It is a replacement for the old --print-estimate option which was dropped in virt-v2v 2.0 (commit 5828c9c7d5 "v2v: Remove --print-estimate option"). In Kubernetes and tools like Kubevirt, it's not possible to create some disks and attach to them (in order to populate them with data) in one step. This makes virt-v2v conversions awkward because ideally we would like the output mode (-o kubevirt) to both create the target disks and populate them at the same time. To work around this problem, we need a tool which can inspect the virt-v2v source hypervisor before we do the conversion in order to find out how many disks are needed and their sizes. Then we can create the target disks, and then we can run a second container with virt-v2v attached to the disks to do the conversion and populate the output. This new tool essentially uses the same -i* options as virt-v2v (and no -o* options) and outputs various useful metadata. Example: $ virt-v2v-inspector --quiet -i disk fedora-32.img virt-v2v-inspector: The QEMU Guest Agent will be installed for this guest at first boot. virt-v2v-inspector: warning: /files/boot/grub2/device.map/hd0 references unknown device "vda". You may have to fix this entry manually after conversion. <?xml version='1.0' encoding='utf-8'?> <v2v-inspection> <!-- generated by virt-v2v-inspector 2.1.9local,libvirt --> <program>virt-v2v-inspector</program> <package>virt-v2v</package> <version>2.1.9</version> <disks> <disk index='0'> <virtual-size>6442450944</virtual-size> <allocated estimated='true'>1400897536</allocated> </disk> </disks> <operatingsystem> <name>linux</name> <distro>fedora</distro> <osinfo>fedora32</osinfo> <arch>x86_64</arch> <major_version>32</major_version> <minor_version>0</minor_version> <package_format>rpm</package_format> <package_management>dnf</package_management> <product_name>Fedora 32 (Thirty Two)</product_name> </operatingsystem> </v2v-inspection> There should be sufficient information in the <disks> section to allocate target disks, plus additional information is printed which might be useful. Note that we do a full conversion in order to generate this information. In particular it's not possible to generate the <allocated/> estimate without this. It's plausible we could have a --no-convert option, but I'm not sure it's worthwhile: it would only save a little time, but would make everything less accurate, plus maybe it is a good idea to find out if conversion is going to work before we create the target disks? I chose XML instead of JSON for output. XML allows us to annotate elements with attributes like "estimated='true'". It also lets us represent 64 bit number accurately, where JSON cannot represent such numbers. The output can be written to stdout (the default, or you can use "-O -"), but for use from another program it is usually better to write the output to a file using "-O output.xml". Acked-by: Laszlo Ersek <lersek at redhat.com>
133 lines
4.1 KiB
Bash
Executable File
133 lines
4.1 KiB
Bash
Executable File
#!/bin/bash -
|
|
# libguestfs 'run' programs locally script
|
|
# Copyright (C) 2011-2020 Red Hat Inc.
|
|
#
|
|
# @configure_input@
|
|
#
|
|
# This library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2 of the License, or (at your option) any later version.
|
|
#
|
|
# This library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with this library; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# With this script you can run all the virt tools without needing to
|
|
# install them first. You just have to do for example:
|
|
#
|
|
# ./run virt-inspector [args ...]
|
|
#
|
|
# This works for any C program, virt tools, and most non-C bindings
|
|
# and programs in the libguestfs distribution.
|
|
#
|
|
# For lots more ways to use this script, see the libguestfs
|
|
# guestfs-building(1) man page.
|
|
#
|
|
# The script should also be used for tests like this:
|
|
#
|
|
# TESTS_ENVIRONMENT = ... $(top_builddir)/run --test
|
|
#
|
|
# The --test parameter introduces a timeout, stopping tests from
|
|
# running forever.
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
if [ "$1" = "--test" ]; then
|
|
timeout_mode=1
|
|
shift
|
|
fi
|
|
|
|
# Function to intelligently prepend a path to an environment variable.
|
|
# See http://stackoverflow.com/a/9631350
|
|
prepend()
|
|
{
|
|
eval $1="$2\${$1:+:\$$1}"
|
|
}
|
|
|
|
# Source and build directories (absolute paths so this works from any
|
|
# directory).
|
|
s="$(cd @abs_srcdir@ && pwd)"
|
|
b="$(cd @abs_builddir@ && pwd)"
|
|
|
|
# Set tmpdir and cachedir so the appliance doesn't conflict with
|
|
# globally installed libguestfs.
|
|
#
|
|
# We set it to a subdirectory ('tmp') so that we can label this
|
|
# subdirectory to make libvirt + sVirt + SELinux enforcing work.
|
|
export LIBGUESTFS_TMPDIR="$b/tmp"
|
|
export LIBGUESTFS_CACHEDIR="$b/tmp"
|
|
mkdir -p "$b/tmp"
|
|
chcon --reference=/tmp "$b/tmp" 2>/dev/null ||:
|
|
|
|
# Set the PATH to contain the virt-v2v and other binaries.
|
|
prepend PATH "$b/v2v"
|
|
prepend PATH "$b/in-place"
|
|
prepend PATH "$b/inspector"
|
|
export PATH
|
|
|
|
# This is a cheap way to find some use-after-free and uninitialized
|
|
# read problems when using glibc. But if we are valgrinding then
|
|
# don't use this because it can stop valgrind from working.
|
|
if [ -z "$VG" ]; then
|
|
random_val="$(@AWK@ 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)"
|
|
LD_PRELOAD="${LD_PRELOAD:+"$LD_PRELOAD:"}libc_malloc_debug.so.0"
|
|
GLIBC_TUNABLES=glibc.malloc.check=1:glibc.malloc.perturb=$random_val
|
|
export LD_PRELOAD GLIBC_TUNABLES
|
|
fi
|
|
|
|
# Do we have libtool? If we have it then we can use it to make
|
|
# running valgrind simpler. However don't depend on it.
|
|
if libtool --help >/dev/null 2>&1; then
|
|
libtool="libtool --mode=execute"
|
|
fi
|
|
|
|
# Avoid GNOME keyring stupidity
|
|
export GNOME_KEYRING_CONTROL=
|
|
export GNOME_KEYRING_PID=
|
|
|
|
# Run the program.
|
|
if [ -z "$timeout_mode" ]; then
|
|
exec $libtool "$@"
|
|
fi
|
|
|
|
# For tests (./run --test):
|
|
# - timeout if the test takes too long to run
|
|
|
|
# Originally 1h, but that is not long enough to run the C API
|
|
# tests on Koji.
|
|
timeout_period=4h
|
|
timeout_kill=30s
|
|
|
|
# Must use the --foreground option (RHBZ#1025269).
|
|
if timeout --foreground 2 sleep 0 >/dev/null 2>&1; then
|
|
# Does this version of timeout have the -k option? (Not on RHEL 6)
|
|
if timeout -k 10s 10s true >/dev/null 2>&1; then
|
|
timeout="timeout --foreground -k $timeout_kill $timeout_period"
|
|
fi
|
|
fi
|
|
|
|
$timeout $libtool "$@"
|
|
fail=$?
|
|
if [ "$fail" -eq 0 ]; then
|
|
# Test successful.
|
|
:
|
|
elif [ "$fail" -eq 77 ]; then
|
|
# Tests return 77 to mean skipped.
|
|
:
|
|
elif [ "$fail" -eq 124 ]; then
|
|
# Timed out.
|
|
echo "$b/run: command timed out after $timeout_period"
|
|
else
|
|
# Test failed.
|
|
echo "$b/run: command failed with exit code $fail"
|
|
fi
|
|
exit $fail
|