├── .gitignore ├── AUTHORS ├── COPYING ├── COPYING.LIB ├── Makefile.am ├── README ├── bash ├── Makefile.am ├── README ├── test-complete-in-script.sh └── virt-p2v-make-disk ├── configure.ac ├── conversion.c ├── cpuid.c ├── dependencies.m4 ├── disks.c ├── docs ├── Makefile.am ├── p2v-building.pod ├── p2v-hacking.pod └── p2v-release-notes.pod ├── generate-p2v-authors.pl ├── generate-p2v-config.pl ├── gnulib └── lib │ ├── Makefile.am │ ├── assure.h │ ├── ignore-value.h │ ├── xstrtol.c │ ├── xstrtol.h │ └── xstrtoull.c ├── gui-gtk3-compat.h ├── gui.c ├── inhibit.c ├── issue ├── kernel-cmdline.c ├── kernel.c ├── kiwi-config.sh ├── kiwi-config.xml.in ├── launch-virt-p2v ├── libguestfs ├── README ├── cleanups.c ├── cleanups.h ├── guestfs-utils.c ├── guestfs-utils.h ├── libxml2-cleanups.c └── libxml2-writer-macros.h ├── m4 ├── p2v-bash-completion.m4 ├── p2v-c.m4 ├── p2v-libraries.m4 ├── p2v-progs.m4 └── p2v-tests.m4 ├── main.c ├── make-physical-machine.sh ├── miniexpect ├── README ├── miniexpect.c └── miniexpect.h ├── nbd.c ├── p2v.h ├── p2v.ks.in ├── p2v.service ├── physical-xml.c ├── podcheck.pl ├── podwrapper.pl.in ├── rtc.c ├── run.in ├── ssh.c ├── subdir-rules.mk ├── test-functions.sh ├── test-virt-p2v-cmdline.sh ├── test-virt-p2v-docs.sh ├── test-virt-p2v-nbdkit.sh ├── test-virt-p2v-pxe.sh ├── test-virt-p2v-pxe.sshd_config.in ├── test-virt-p2v-scp.sh ├── test-virt-p2v-ssh.sh ├── utils.c ├── valgrind-suppressions ├── virt-p2v-make-disk.in ├── virt-p2v-make-disk.pod ├── virt-p2v-make-kickstart.in ├── virt-p2v-make-kickstart.pod ├── virt-p2v-make-kiwi.in ├── virt-p2v-make-kiwi.pod └── virt-p2v.pod /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.la 3 | *.lo 4 | *.log 5 | *.o 6 | *.trs 7 | .deps 8 | .dirstamp 9 | .libs 10 | Makefile 11 | Makefile.in 12 | 13 | /about-authors.c 14 | /aclocal.m4 15 | /autom4te.cache/ 16 | /bash/virt-p2v-make-kickstart 17 | /bash/virt-p2v-make-kiwi 18 | /blank-part.img 19 | /build-aux/ 20 | /config.c 21 | /config.h 22 | /config.h.in 23 | /config.status 24 | /configure 25 | /dependencies.archlinux 26 | /dependencies.debian 27 | /dependencies.redhat 28 | /dependencies.suse 29 | /docs/p2v-building.1 30 | /docs/p2v-hacking.1 31 | /docs/p2v-release-notes.1 32 | /docs/stamp-p2v-building.pod 33 | /docs/stamp-p2v-hacking.pod 34 | /docs/stamp-p2v-release-notes.pod 35 | /fedora.img 36 | /kernel-config.c 37 | /libtool 38 | /m4/libtool.m4 39 | /m4/lt~obsolete.m4 40 | /m4/ltoptions.m4 41 | /m4/ltsugar.m4 42 | /m4/ltversion.m4 43 | /p2v-config.h 44 | /physical-machine.tmp.* 45 | /podwrapper.pl 46 | /run 47 | /stamp-h1 48 | /stamp-test-virt-p2v-pxe-data-files 49 | /stamp-test-virt-p2v-pxe-hostkey 50 | /stamp-test-virt-p2v-pxe-kernel 51 | /stamp-test-virt-p2v-pxe-userkey 52 | /stamp-virt-p2v.pod 53 | /stamp-virt-p2v-make-disk.pod 54 | /stamp-virt-p2v-make-kickstart.pod 55 | /stamp-virt-p2v-make-kiwi.pod 56 | /test-virt-p2v-pxe.authorized_keys 57 | /test-virt-p2v-pxe.id_rsa 58 | /test-virt-p2v-pxe.id_rsa.pub 59 | /test-virt-p2v-pxe.img 60 | /test-virt-p2v-pxe.initramfs 61 | /test-virt-p2v-pxe.sshd_config 62 | /test-virt-p2v-pxe.ssh_host_rsa_key 63 | /test-virt-p2v-pxe.ssh_host_rsa_key.pub 64 | /test-virt-p2v-pxe.vmlinuz 65 | /virt-p2v 66 | /virt-p2v.1 67 | /virt-p2v.i686 68 | /virt-p2v.img 69 | /virt-p2v-kernel-config.pod 70 | /virt-p2v-make-disk 71 | /virt-p2v-make-disk.1 72 | /virt-p2v-make-kickstart 73 | /virt-p2v-make-kickstart.1 74 | /virt-p2v-make-kiwi 75 | /virt-p2v-make-kiwi.1 76 | /virt-p2v.xz 77 | /website/*.html 78 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Cédric Bosdonnat 2 | John Eckersberg 3 | Junqin Zhou 4 | Kean Li 5 | Kun Wei 6 | Laura Bailey 7 | Matthew Booth 8 | Mike Latimer 9 | Ming Xie 10 | Pino Toscano 11 | Richard W.M. Jones 12 | Roman Kagan 13 | Shahar Havivi 14 | Tingting Zheng 15 | Xiang Hua Chen 16 | Yehuda Zimmerman 17 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Virt-p2v is a GUI interface to convert a physical machine to run 2 | as virtual machine on KVM. For more information see the home page: 3 | 4 | http://libguestfs.org/ 5 | 6 | For discussion, development, patches, etc. please use the mailing 7 | list: 8 | 9 | https://lists.libguestfs.org 10 | 11 | To find out how to build libguestfs from source, read: 12 | 13 | docs/p2v-building.pod 14 | http://libguestfs.org/p2v-building.1.html 15 | man docs/p2v-building.1 16 | 17 | Copyright (C) 2009-2024 Red Hat Inc. 18 | 19 | The library is distributed under the LGPLv2+. The programs are 20 | distributed under the GPLv2+. Please see the files COPYING and 21 | COPYING.LIB for full license information. The examples are under a 22 | very liberal license. 23 | -------------------------------------------------------------------------------- /bash/Makefile.am: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2013-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | include $(top_srcdir)/subdir-rules.mk 18 | 19 | scripts = \ 20 | virt-p2v-make-disk 21 | 22 | # Some of the scripts are simply symbolic links. 23 | symlinks = \ 24 | virt-p2v-make-kickstart \ 25 | virt-p2v-make-kiwi 26 | 27 | # Note: Don't distribute the symbolic links, only the real files. 28 | EXTRA_DIST = \ 29 | README \ 30 | $(scripts) \ 31 | $(TESTS) 32 | 33 | CLEANFILES += \ 34 | $(symlinks) 35 | 36 | $(symlinks): 37 | rm -f $@ 38 | $(LN_S) virt-p2v-make-disk $@ 39 | 40 | if HAVE_BASH_COMPLETION 41 | 42 | # Bash completion script. 43 | 44 | bashcompletiondir = $(BASH_COMPLETIONS_DIR) 45 | #bashcompletion_DATA = $(scripts) 46 | 47 | all-local: $(scripts) $(symlinks) 48 | -test $(srcdir) != $(builddir) && cd $(srcdir) && cp $(scripts) $(abs_builddir)/ 49 | 50 | install-data-local: 51 | $(mkdir_p) $(DESTDIR)$(bashcompletiondir) 52 | cp -d $(scripts) $(symlinks) $(DESTDIR)$(bashcompletiondir) 53 | 54 | clean-local: 55 | -test $(srcdir) != $(builddir) && rm -f $(scripts) 56 | 57 | endif 58 | 59 | # Tests. 60 | TESTS_ENVIRONMENT = \ 61 | scripts="$(scripts)" \ 62 | symlinks="$(scripts)" \ 63 | commands="$(scripts) $(symlinks)" \ 64 | $(top_builddir)/run --test 65 | 66 | TESTS = \ 67 | test-complete-in-script.sh 68 | -------------------------------------------------------------------------------- /bash/README: -------------------------------------------------------------------------------- 1 | This directory contains the scripts for tab-completing commands in 2 | bash. Note these new-style demand-loaded scripts require 3 | 'bash-completion' >= 1.99. 4 | 5 | Tip: To test the bash completions without having to install them, 6 | simply start a new shell and 'source ./virt-foo'. 7 | -------------------------------------------------------------------------------- /bash/test-complete-in-script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # libguestfs bash completion test script 3 | # Copyright (C) 2016 Red Hat Inc. 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # Test that the correct 'complete' command is included in the script. 19 | # Mainly prevents symlinking errors and some omissions. 20 | 21 | $TEST_FUNCTIONS 22 | skip_if_skipped 23 | 24 | if [ -z "$commands" ]; then 25 | echo "$0: \$commands is not defined. Use 'make check' to run this test." 26 | exit 1 27 | fi 28 | 29 | for cmd in $commands; do 30 | if [ ! -f $cmd ]; then 31 | echo "$0: script or symlink '$cmd' is missing" 32 | exit 1 33 | fi 34 | if ! grep "^complete.*$cmd\$" $cmd; then 35 | echo "$0: script or symlink '$cmd' does not have" 36 | echo "a 'complete' rule for '$cmd'" 37 | exit 1 38 | fi 39 | done 40 | -------------------------------------------------------------------------------- /bash/virt-p2v-make-disk: -------------------------------------------------------------------------------- 1 | # virt-p2v-make-disk bash completion script -*- shell-script -*- 2 | # Copyright (C) 2014-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | _p2v_options_only () 18 | { 19 | local cur prev words cword split 20 | local shortopts longopts tool="$1" 21 | 22 | _init_completion -s || return 23 | 24 | case "$cur" in 25 | --*) 26 | # --options 27 | longopts="$($tool --long-options)" 28 | COMPREPLY=( $(compgen -W "$longopts" -- "$cur") ) 29 | return ;; 30 | -*) 31 | # -o and --options 32 | shortopts="$($tool --short-options)" 33 | longopts="$($tool --long-options)" 34 | COMPREPLY=( $(compgen -W "$shortopts $longopts" -- "$cur") ) 35 | return ;; 36 | *) 37 | COMPREPLY=( $(compgen "$cur") ) 38 | return ;; 39 | esac 40 | } 41 | 42 | _virt_p2v_make_disk () 43 | { 44 | _p2v_options_only "virt-p2v-make-disk" 45 | } && 46 | complete -o default -F _virt_p2v_make_disk virt-p2v-make-disk 47 | 48 | _virt_p2v_make_kickstart () 49 | { 50 | _p2v_options_only "virt-p2v-make-kickstart" 51 | } && 52 | complete -o default -F _virt_p2v_make_kickstart virt-p2v-make-kickstart 53 | 54 | _virt_p2v_make_kiwi () 55 | { 56 | _p2v_options_only "virt-p2v-make-kiwi" 57 | } && 58 | complete -o default -F _virt_p2v_make_kiwi virt-p2v-make-kiwi 59 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # virt-p2v 2 | # Copyright (C) 2009-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # The major, minor, and release fields MUST be numbers. Packagers can 18 | # add extra information using --with-extra="..." which may be any 19 | # freeform string. 20 | m4_define([p2v_major], [1]) 21 | m4_define([p2v_minor], [42]) 22 | m4_define([p2v_release], [4]) 23 | 24 | AC_INIT([virt-p2v],p2v_major.p2v_minor.p2v_release) 25 | 26 | # Headings within the configure script output. 27 | m4_define([HEADING], 28 | [AS_ECHO 29 | AS_ECHO(["--- $1 ---"])]) 30 | 31 | AC_CONFIG_AUX_DIR([build-aux]) 32 | 33 | AC_USE_SYSTEM_EXTENSIONS 34 | 35 | dnl Initialize automake. 36 | AM_INIT_AUTOMAKE(foreign subdir-objects tar-pax) dnl NB: Do not [quote] this parameter. 37 | 38 | m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])]) 39 | AM_SILENT_RULES([yes]) # make --enable-silent-rules the default. 40 | 41 | AC_CONFIG_MACRO_DIR([m4]) 42 | 43 | dnl Initialize libtool. 44 | LT_INIT 45 | 46 | dnl Extra string, a freeform string defined by packagers. 47 | AC_ARG_WITH([extra], 48 | [AS_HELP_STRING([--with-extra], 49 | [extra version string (for use by packagers)])], 50 | [p2v_extra="$withval"], 51 | [p2v_extra=] 52 | ) 53 | 54 | AC_MSG_NOTICE([virt-p2v version p2v_major.p2v_minor.p2v_release$p2v_extra]) 55 | 56 | dnl Split up the version string. 57 | AC_DEFINE([PACKAGE_VERSION_MAJOR],[p2v_major],[Major version number.]) 58 | AC_DEFINE([PACKAGE_VERSION_MINOR],[p2v_minor],[Minor version number.]) 59 | AC_DEFINE([PACKAGE_VERSION_RELEASE],[p2v_release],[Release number.]) 60 | AC_DEFINE_UNQUOTED([PACKAGE_VERSION_EXTRA],["$p2v_extra"],[Extra version string.]) 61 | PACKAGE_VERSION_FULL="p2v_major.p2v_minor.p2v_release${p2v_extra}" 62 | AC_DEFINE_UNQUOTED([PACKAGE_VERSION_FULL],["$PACKAGE_VERSION_FULL"],[Full version string.]) 63 | AC_SUBST([PACKAGE_VERSION_FULL]) 64 | 65 | dnl Check for external programs required to either build or run 66 | dnl virt-p2v. 67 | HEADING([Checking for external programs]) 68 | m4_include([m4/p2v-progs.m4]) 69 | 70 | dnl The C compiler environment. 71 | HEADING([Checking for the C compiler environment]) 72 | m4_include([m4/p2v-c.m4]) 73 | 74 | dnl Any C libraries required by virt-p2v. 75 | HEADING([Checking for libraries used by virt-p2v]) 76 | m4_include([m4/p2v-libraries.m4]) 77 | 78 | dnl Bash completion. 79 | HEADING([Checking for bash completion]) 80 | m4_include([m4/p2v-bash-completion.m4]) 81 | 82 | dnl All the programs used for tests. 83 | HEADING([Checking for programs for tests]) 84 | m4_include([m4/p2v-tests.m4]) 85 | 86 | dnl Produce output files. 87 | HEADING([Generating output files]) 88 | 89 | AC_CONFIG_HEADERS([config.h]) 90 | 91 | dnl http://www.mail-archive.com/automake@gnu.org/msg10204.html 92 | AC_CONFIG_FILES([virt-p2v-make-disk], 93 | [chmod +x,-w virt-p2v-make-disk]) 94 | AC_CONFIG_FILES([virt-p2v-make-kickstart], 95 | [chmod +x,-w virt-p2v-make-kickstart]) 96 | AC_CONFIG_FILES([virt-p2v-make-kiwi], 97 | [chmod +x,-w virt-p2v-make-kiwi]) 98 | AC_CONFIG_FILES([podwrapper.pl], 99 | [chmod +x,-w podwrapper.pl]) 100 | AC_CONFIG_FILES([run], 101 | [chmod +x,-w run]) 102 | 103 | AC_CONFIG_FILES([Makefile 104 | bash/Makefile 105 | docs/Makefile 106 | gnulib/lib/Makefile]) 107 | 108 | AC_CONFIG_COMMANDS([p2v-config.h], 109 | [${ac_srcdir}/generate-p2v-config.pl --file=p2v-config.h --output=p2v-config.h]) 110 | 111 | dnl gnulib embedding hacks 112 | AC_TYPE_LONG_LONG_INT 113 | 114 | AC_OUTPUT 115 | -------------------------------------------------------------------------------- /cpuid.c: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2009-2019 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /** 19 | * Find CPU vendor, topology and some CPU flags. 20 | * 21 | * lscpu (from util-linux) provides CPU vendor, topology and flags. 22 | * 23 | * ACPI can be read by seeing if F exists. 24 | * 25 | * CPU model is essentially impossible to get without using libvirt, 26 | * but we cannot use libvirt for the reasons outlined in this message: 27 | * https://www.redhat.com/archives/libvirt-users/2017-March/msg00071.html 28 | * 29 | * Note that #vCPUs and amount of RAM is handled by F. 30 | */ 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "ignore-value.h" 43 | 44 | #include "p2v.h" 45 | 46 | static void 47 | free_cpu_config (struct cpu_config *cpu) 48 | { 49 | if (cpu->vendor) 50 | free (cpu->vendor); 51 | if (cpu->model) 52 | free (cpu->model); 53 | memset (cpu, 0, sizeof *cpu); 54 | } 55 | 56 | /** 57 | * Get the output of lscpu as a list of (key, value) pairs (as a 58 | * flattened list of strings). 59 | */ 60 | static char ** 61 | get_lscpu (void) 62 | { 63 | const char *cmd; 64 | CLEANUP_PCLOSE FILE *fp = NULL; 65 | CLEANUP_FREE char *line = NULL; 66 | ssize_t len; 67 | size_t buflen = 0; 68 | char **ret = NULL; 69 | size_t ret_size = 0; 70 | 71 | cmd = "lscpu"; 72 | 73 | fp = popen (cmd, "re"); 74 | if (fp == NULL) { 75 | perror (cmd); 76 | return NULL; 77 | } 78 | 79 | ret = malloc (sizeof (char *)); 80 | if (ret == NULL) error (EXIT_FAILURE, errno, "malloc"); 81 | ret[0] = NULL; 82 | 83 | while (errno = 0, (len = getline (&line, &buflen, fp)) != -1) { 84 | char *p; 85 | char *key, *value; 86 | 87 | if (len > 0 && line[len-1] == '\n') 88 | line[len-1] = '\0'; 89 | 90 | /* Split the line at the first ':' character. */ 91 | p = strchr (line, ':'); 92 | if (p == NULL) 93 | continue; 94 | 95 | *p = '\0'; 96 | key = strdup (line); 97 | /* Skip leading whitespace in the value. */ 98 | for (++p; *p && g_ascii_isspace (*p); ++p) 99 | ; 100 | value = strdup (p); 101 | 102 | /* Add key and value to the list, and trailing NULL pointer. */ 103 | ret_size += 2; 104 | ret = realloc (ret, (ret_size + 1) * sizeof (char *)); 105 | if (ret == NULL) error (EXIT_FAILURE, errno, "realloc"); 106 | ret[ret_size-2] = key; 107 | ret[ret_size-1] = value; 108 | ret[ret_size] = NULL; 109 | } 110 | 111 | if (errno) { 112 | perror (cmd); 113 | guestfs_int_free_string_list (ret); 114 | return NULL; 115 | } 116 | 117 | return ret; 118 | } 119 | 120 | /** 121 | * Read a single field from lscpu output. 122 | * 123 | * If the field does not exist, returns C. 124 | */ 125 | static const char * 126 | get_field (char **lscpu, const char *key) 127 | { 128 | size_t i; 129 | 130 | for (i = 0; lscpu[i] != NULL; i += 2) { 131 | if (STREQ (lscpu[i], key)) 132 | return lscpu[i+1]; 133 | } 134 | 135 | return NULL; 136 | } 137 | 138 | /** 139 | * Read the CPU vendor from lscpu output. 140 | */ 141 | static void 142 | get_vendor (char **lscpu, struct cpu_config *cpu) 143 | { 144 | const char *vendor = get_field (lscpu, "Vendor ID"); 145 | 146 | if (vendor) { 147 | /* Note this mapping comes from /usr/share/libvirt/cpu_map.xml */ 148 | if (STREQ (vendor, "GenuineIntel")) 149 | cpu->vendor = strdup ("Intel"); 150 | else if (STREQ (vendor, "AuthenticAMD")) 151 | cpu->vendor = strdup ("AMD"); 152 | /* Currently aarch64 lscpu has no Vendor ID XXX. */ 153 | } 154 | } 155 | 156 | /** 157 | * Read the CPU topology from a separate lscpu invocation. 158 | */ 159 | void 160 | get_cpu_topology (struct cpu_topo *topo) 161 | { 162 | 163 | CLEANUP_FREE_STRING_LIST char **lscpu = NULL; 164 | 165 | lscpu = get_lscpu (); 166 | 167 | if (lscpu != NULL) { 168 | const char *sockets, *cores, *threads; 169 | 170 | sockets = get_field (lscpu, "Socket(s)"); 171 | cores = get_field (lscpu, "Core(s) per socket"); 172 | threads = get_field (lscpu, "Thread(s) per core"); 173 | if (sockets && cores && threads) { 174 | ignore_value (sscanf (sockets, "%u", &topo->sockets)); 175 | ignore_value (sscanf (cores, "%u", &topo->cores)); 176 | ignore_value (sscanf (threads, "%u", &topo->threads)); 177 | return; 178 | } 179 | } 180 | topo->sockets = 1; 181 | topo->cores = 1; 182 | topo->threads = 1; 183 | } 184 | 185 | /** 186 | * Read some important flags from lscpu output. 187 | */ 188 | static void 189 | get_flags (char **lscpu, struct cpu_config *cpu) 190 | { 191 | const char *flags; 192 | 193 | flags = get_field (lscpu, "Flags"); 194 | if (flags) { 195 | cpu->apic = strstr (flags, " apic ") != NULL; 196 | cpu->pae = strstr (flags, " pae ") != NULL; 197 | 198 | /* aarch64 /proc/cpuinfo has a "Features" field, but lscpu does 199 | * not expose it. However aarch64 Features does not contain any 200 | * of the interesting flags above. 201 | */ 202 | } 203 | } 204 | 205 | /** 206 | * Find out if the system uses ACPI. 207 | */ 208 | static void 209 | get_acpi (struct cpu_config *cpu) 210 | { 211 | cpu->acpi = access ("/sys/firmware/acpi", F_OK) == 0; 212 | } 213 | 214 | void 215 | get_cpu_config (struct cpu_config *cpu) 216 | { 217 | CLEANUP_FREE_STRING_LIST char **lscpu = NULL; 218 | 219 | free_cpu_config (cpu); 220 | 221 | lscpu = get_lscpu (); 222 | if (lscpu != NULL) { 223 | get_vendor (lscpu, cpu); 224 | get_flags (lscpu, cpu); 225 | } 226 | 227 | get_acpi (cpu); 228 | } 229 | -------------------------------------------------------------------------------- /dependencies.m4: -------------------------------------------------------------------------------- 1 | dnl This is the list of distro packages which are required by 2 | dnl virt-p2v. 3 | dnl 4 | dnl This file is processed by m4 with only one of the following 5 | dnl symbols defined (depending on the target distro): 6 | dnl 7 | dnl REDHAT=1 Fedora, RHEL, CentOS, SL and workalikes 8 | dnl DEBIAN=1 Debian and Ubuntu 9 | dnl ARCHLINUX=1 Arch Linux 10 | dnl SUSE=1 SUSE, OpenSUSE 11 | dnl OPENMANDRIVA=1 OpenMandriva 12 | dnl 13 | dnl NB 1: Must be one package name per line. Blank lines are ignored. 14 | dnl 15 | dnl NB 2: This works differently from appliance/packagelist.in 16 | dnl because we don't care about the current DISTRO (the one on 17 | dnl which libguestfs is being compiled), since we can "cross-build" 18 | dnl the virt-p2v ISO to any other Linux distro. 19 | dnl 20 | dnl NB 3: libguestfs is not a dependency of virt-p2v. libguestfs 21 | dnl only runs on the virt-v2v conversion server. 22 | 23 | ifelse(REDHAT,1, 24 | dnl Used by the virt-p2v binary. 25 | pcre2 26 | libxml2 27 | librsvg2 28 | gtk3 29 | dbus-libs 30 | 31 | dnl Run as external programs by the p2v binary. 32 | /usr/bin/ssh 33 | nbdkit-server 34 | nbdkit-file-plugin 35 | which 36 | 37 | dnl Generally useful tools to use within xterm 38 | vim-minimal 39 | 40 | dnl Useful disk and diagnostic utilities. 41 | iscsi-initiator-utils 42 | 43 | dnl X11 environment 44 | /usr/bin/xinit 45 | /usr/bin/Xorg 46 | xorg-x11-drivers 47 | xorg-x11-fonts-Type1 48 | dejavu-sans-fonts 49 | dejavu-sans-mono-fonts 50 | mesa-dri-drivers 51 | metacity 52 | 53 | NetworkManager 54 | nm-connection-editor 55 | network-manager-applet 56 | dnl dbus is required by nm-applet, but not a dependency in Fedora 57 | dbus-x11 58 | dnl sysadmins prefer ifconfig 59 | net-tools 60 | 61 | dnl RHBZ#1157679 62 | @hardware-support 63 | 64 | dnl UEFI Boot (RHBZ#2038105) 65 | shim-x64 66 | grub2-efi-x64-cdboot 67 | ) 68 | 69 | ifelse(DEBIAN,1, 70 | libpcre2-8-0 71 | libxml2 72 | librsvg2-2 73 | libgtk-3-0 74 | libdbus-1-3 75 | openssh-client 76 | nbdkit 77 | debianutils 78 | vim-tiny 79 | open-iscsi 80 | xorg 81 | xserver-xorg-video-all 82 | fonts-dejavu 83 | metacity 84 | network-manager 85 | network-manager-gnome 86 | dbus-x11 87 | net-tools 88 | ) 89 | 90 | ifelse(ARCHLINUX,1, 91 | pcre2 92 | libxml2 93 | librsvg 94 | gtk3 95 | dbus 96 | openssh 97 | nbdkit 98 | which 99 | vim-tiny 100 | open-iscsi 101 | xorg-xinit 102 | xorg-server 103 | xf86-video-* 104 | ttf-dejavu 105 | metacity 106 | NetworkManager 107 | nm-connection-editor 108 | network-manager-applet 109 | dbus-x11 110 | net-tools 111 | ) 112 | 113 | ifelse(SUSE,1, 114 | pcre2 115 | libxml2 116 | librsvg 117 | gtk3 118 | libdbus-1-3 119 | nbdkit-server 120 | nbdkit-file-plugin 121 | openssh 122 | dnl /usr/bin/which is in util-linux on SUSE 123 | vim 124 | open-iscsi 125 | xinit 126 | xorg-x11-server 127 | xf86-video-* 128 | dejavu-fonts 129 | NetworkManager 130 | xf86-input-* 131 | icewm-lite 132 | dbus-1-x11 133 | yast2-network 134 | libyui-qt 135 | SuSEfirewall2 136 | ) 137 | 138 | ifelse(OPENMANDRIVA,1, 139 | dnl Used by the virt-p2v binary. 140 | pcre2 141 | libxml2 142 | librsvg 143 | gtk3 144 | dbus-libs 145 | 146 | dnl Run as external programs by the p2v binary. 147 | /usr/bin/ssh 148 | nbdkit-server 149 | nbdkit-file-plugin 150 | which 151 | 152 | dnl Generally useful tools to use within xterm 153 | vim-enhanced 154 | 155 | dnl X11 environment 156 | /usr/bin/xinit 157 | /usr/bin/Xorg 158 | xorg-x11-drivers 159 | xorg-x11-fonts-Type1 160 | dejavu-sans-fonts 161 | dejavu-sans-mono-fonts 162 | mesa-dri-drivers 163 | kwin_x11 164 | 165 | NetworkManager 166 | nm-connection-editor 167 | network-manager-applet 168 | dnl dbus is required by nm-applet, but not a dependency in Fedora 169 | dbus-x11 170 | dnl sysadmins prefer ifconfig 171 | net-tools 172 | ) 173 | 174 | dnl Run as external programs by the p2v binary. 175 | curl 176 | ethtool 177 | gawk 178 | lsscsi 179 | pciutils 180 | usbutils 181 | util-linux 182 | xterm 183 | 184 | dnl Generally useful tools to use within xterm 185 | less 186 | 187 | dnl The hwdata package contains PCI IDs, used by virt-p2v to display 188 | dnl network vendor information (RHBZ#855059). 189 | hwdata 190 | 191 | dnl Useful disk and diagnostic utilities. 192 | hdparm 193 | smartmontools 194 | -------------------------------------------------------------------------------- /disks.c: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2009-2022 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #if MAJOR_IN_MKDEV 32 | #include 33 | #elif MAJOR_IN_SYSMACROS 34 | #include 35 | /* else it's in sys/types.h, included above */ 36 | #endif 37 | 38 | #include "p2v.h" 39 | 40 | /** 41 | * Get parent device of a partition. 42 | * 43 | * Returns C<0> if no parent device could be found. 44 | */ 45 | static dev_t 46 | partition_parent (dev_t part_dev) 47 | { 48 | CLEANUP_FCLOSE FILE *fp = NULL; 49 | CLEANUP_FREE char *path = NULL, *content = NULL; 50 | size_t len = 0; 51 | unsigned parent_major, parent_minor; 52 | 53 | if (asprintf (&path, "/sys/dev/block/%ju:%ju/../dev", 54 | (uintmax_t) major (part_dev), 55 | (uintmax_t) minor (part_dev)) == -1) 56 | error (EXIT_FAILURE, errno, "asprintf"); 57 | 58 | fp = fopen (path, "r"); 59 | if (fp == NULL) 60 | return 0; 61 | 62 | if (getline (&content, &len, fp) == -1) 63 | error (EXIT_FAILURE, errno, "getline"); 64 | 65 | if (sscanf (content, "%u:%u", &parent_major, &parent_minor) != 2) 66 | return 0; 67 | 68 | return makedev (parent_major, parent_minor); 69 | } 70 | 71 | /** 72 | * Return true if the named device (eg. C) is a Removable Media 73 | * SCSI Disk with no media inserted. This covers floppy drives, but not CD-ROM 74 | * drives (intentionally). 75 | */ 76 | static int 77 | device_has_no_media (const char *dev) 78 | { 79 | int ret; 80 | gchar *sysfs_pathname; 81 | gchar *sysfs_contents; 82 | gsize sysfs_size; 83 | gchar *dev_pathname; 84 | int dev_fd; 85 | 86 | ret = 0; 87 | 88 | if (!STRPREFIX (dev, "sd")) 89 | return ret; 90 | 91 | sysfs_pathname = g_strdup_printf ("/sys/block/%s/removable", dev); 92 | 93 | if (!g_file_get_contents (sysfs_pathname, &sysfs_contents, &sysfs_size, NULL)) 94 | goto free_sysfs_pathname; 95 | 96 | if (sysfs_size < 2 || sysfs_contents[0] != '1' || sysfs_contents[1] != '\n') 97 | goto free_sysfs_contents; 98 | 99 | dev_pathname = g_strdup_printf ("/dev/%s", dev); 100 | 101 | dev_fd = open (dev_pathname, O_RDONLY | O_CLOEXEC); 102 | if (dev_fd == -1) { 103 | if (errno == ENOMEDIUM) 104 | ret = 1; 105 | 106 | goto free_dev_pathname; 107 | } 108 | close (dev_fd); 109 | 110 | free_dev_pathname: 111 | g_free (dev_pathname); 112 | 113 | free_sysfs_contents: 114 | g_free (sysfs_contents); 115 | 116 | free_sysfs_pathname: 117 | g_free (sysfs_pathname); 118 | 119 | return ret; 120 | } 121 | 122 | /** 123 | * Return true if the named device (eg. C) contains the 124 | * root filesystem. C is the major:minor of the root 125 | * filesystem (eg. C<8:1> if the root filesystem was F). 126 | * 127 | * This doesn't work for LVs and so on. However we only really care 128 | * if this test works on the P2V ISO where the root device is a 129 | * regular partition. 130 | */ 131 | static int 132 | device_contains (const char *dev, dev_t root_device) 133 | { 134 | struct stat statbuf; 135 | CLEANUP_FREE char *dev_name = NULL; 136 | dev_t root_device_parent; 137 | 138 | if (asprintf (&dev_name, "/dev/%s", dev) == -1) 139 | error (EXIT_FAILURE, errno, "asprintf"); 140 | 141 | if (stat (dev_name, &statbuf) == -1) 142 | return 0; 143 | 144 | /* See if dev is the root_device. */ 145 | if (statbuf.st_rdev == root_device) 146 | return 1; 147 | 148 | /* See if dev is the parent device of the root_device. */ 149 | root_device_parent = partition_parent (root_device); 150 | if (root_device_parent == 0) 151 | return 0; 152 | if (statbuf.st_rdev == root_device_parent) 153 | return 1; 154 | 155 | return 0; 156 | } 157 | 158 | /** 159 | * Enumerate all disks in F and return them in the C and 160 | * C arrays. 161 | */ 162 | void 163 | find_all_disks (char ***disks, char ***removable) 164 | { 165 | DIR *dir; 166 | struct dirent *d; 167 | size_t nr_disks = 0, nr_removable = 0; 168 | char **ret_disks = NULL, **ret_removable = NULL; 169 | dev_t root_device = 0; 170 | struct stat statbuf; 171 | 172 | if (stat ("/", &statbuf) == 0) 173 | root_device = statbuf.st_dev; 174 | 175 | /* The default list of disks is everything in /sys/block which 176 | * matches the common patterns for disk names. 177 | */ 178 | dir = opendir ("/sys/block"); 179 | if (!dir) 180 | error (EXIT_FAILURE, errno, "opendir"); 181 | 182 | for (;;) { 183 | errno = 0; 184 | d = readdir (dir); 185 | if (!d) break; 186 | 187 | if (STRPREFIX (d->d_name, "cciss!") || 188 | STRPREFIX (d->d_name, "hd") || 189 | STRPREFIX (d->d_name, "nvme") || 190 | STRPREFIX (d->d_name, "sd") || 191 | STRPREFIX (d->d_name, "ubd") || 192 | STRPREFIX (d->d_name, "vd")) { 193 | char *p; 194 | /* Skip SCSI disk drives with removable media that have no media inserted 195 | * -- effectively, empty floppy drives. Note that SCSI CD-ROMs are named 196 | * C and thus handled on the other branch. 197 | */ 198 | if (device_has_no_media (d->d_name)) 199 | continue; 200 | 201 | /* Skip the device containing the root filesystem. */ 202 | if (device_contains (d->d_name, root_device)) 203 | continue; 204 | 205 | nr_disks++; 206 | ret_disks = realloc (ret_disks, sizeof (char *) * (nr_disks + 1)); 207 | if (!ret_disks) 208 | error (EXIT_FAILURE, errno, "realloc"); 209 | 210 | ret_disks[nr_disks-1] = strdup (d->d_name); 211 | 212 | /* cciss device /dev/cciss/c0d0 will be /sys/block/cciss!c0d0 */ 213 | p = strchr (ret_disks[nr_disks-1], '!'); 214 | if (p) *p = '/'; 215 | 216 | ret_disks[nr_disks] = NULL; 217 | } 218 | else if (STRPREFIX (d->d_name, "sr")) { 219 | nr_removable++; 220 | ret_removable = realloc (ret_removable, 221 | sizeof (char *) * (nr_removable + 1)); 222 | if (!ret_removable) 223 | error (EXIT_FAILURE, errno, "realloc"); 224 | ret_removable[nr_removable-1] = strdup (d->d_name); 225 | ret_removable[nr_removable] = NULL; 226 | } 227 | } 228 | 229 | /* Check readdir didn't fail */ 230 | if (errno != 0) 231 | error (EXIT_FAILURE, errno, "readdir: %s", "/sys/block"); 232 | 233 | /* Close the directory handle */ 234 | if (closedir (dir) == -1) 235 | error (EXIT_FAILURE, errno, "closedir: %s", "/sys/block"); 236 | 237 | if (ret_disks) 238 | qsort (ret_disks, nr_disks, sizeof (char *), compare_strings); 239 | if (ret_removable) 240 | qsort (ret_removable, nr_removable, sizeof (char *), compare_strings); 241 | 242 | *disks = ret_disks; 243 | *removable = ret_removable; 244 | } 245 | -------------------------------------------------------------------------------- /docs/Makefile.am: -------------------------------------------------------------------------------- 1 | # libguestfs documentation 2 | # Copyright (C) 2010-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | include $(top_srcdir)/subdir-rules.mk 18 | 19 | EXTRA_DIST = \ 20 | p2v-building.pod \ 21 | p2v-hacking.pod \ 22 | p2v-release-notes.pod 23 | 24 | man_MANS = \ 25 | p2v-building.1 \ 26 | p2v-hacking.1 \ 27 | p2v-release-notes.1 28 | noinst_DATA = \ 29 | $(top_builddir)/website/p2v-building.1.html \ 30 | $(top_builddir)/website/p2v-hacking.1.html \ 31 | $(top_builddir)/website/p2v-release-notes.1.html 32 | 33 | p2v-building.1 $(top_builddir)/website/p2v-building.1.html: stamp-p2v-building.pod 34 | 35 | stamp-p2v-building.pod: p2v-building.pod 36 | $(PODWRAPPER) \ 37 | --section 1 \ 38 | --man p2v-building.1 \ 39 | --html $(top_builddir)/website/p2v-building.1.html \ 40 | --license LGPLv2+ \ 41 | $< 42 | touch $@ 43 | 44 | p2v-hacking.1 $(top_builddir)/website/p2v-hacking.1.html: stamp-p2v-hacking.pod 45 | 46 | stamp-p2v-hacking.pod: p2v-hacking.pod 47 | $(PODWRAPPER) \ 48 | --section 1 \ 49 | --man p2v-hacking.1 \ 50 | --html $(top_builddir)/website/p2v-hacking.1.html \ 51 | --license LGPLv2+ \ 52 | $< 53 | touch $@ 54 | 55 | p2v-release-notes.1 $(top_builddir)/website/p2v-release-notes.1.html: stamp-p2v-release-notes.pod 56 | 57 | stamp-p2v-release-notes.pod: p2v-release-notes.pod 58 | $(PODWRAPPER) \ 59 | --section 1 \ 60 | --man p2v-release-notes.1 \ 61 | --html $(top_builddir)/website/p2v-release-notes.1.html \ 62 | --license GPLv2+ \ 63 | $< 64 | touch $@ 65 | -------------------------------------------------------------------------------- /docs/p2v-building.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | p2v-building - How to build virt-p2v from source 4 | 5 | =head1 DESCRIPTION 6 | 7 | This manual page describes how to build virt-p2v from source. 8 | 9 | The main steps are: 10 | 11 | =over 4 12 | 13 | =item * 14 | 15 | Install the requirements. 16 | 17 | =item * 18 | 19 | Build, either from the git repository or from a tarball. 20 | 21 | =item * 22 | 23 | Run the tests. 24 | 25 | =item * 26 | 27 | Run the tools from the source directory, or install. 28 | 29 | =back 30 | 31 | =head1 REQUIREMENTS 32 | 33 | =head2 Full list of requirements 34 | 35 | =over 4 36 | 37 | =item qemu-img E 2.2.0 38 | 39 | I. 40 | 41 | =item Gcc or Clang 42 | 43 | I. We use C<__attribute__((cleanup))> which is a GCC 44 | extension also supported by Clang. 45 | 46 | =item Perl 47 | 48 | I. Various build steps and tests are written in Perl. Perl 49 | is not needed at runtime. 50 | 51 | =item Perl C 52 | 53 | =item Perl C 54 | 55 | I. Part of Perl core. 56 | 57 | =item autoconf 58 | 59 | =item automake 60 | 61 | I if compiling from git. 62 | Optional if compiling from tarball. 63 | 64 | =item Perl-compatible Regular Expressions (PCRE2) library 65 | 66 | I. 67 | 68 | =item libxml2 69 | 70 | I. 71 | 72 | =item xz 73 | 74 | I. 75 | 76 | =item nbdkit 77 | 78 | Optional. 79 | 80 | L requires nbdkit, but it only needs to be present on the 81 | virt-p2v ISO, it does not need to be installed at compile time. 82 | 83 | =item Glib E 2.56 84 | 85 | I. 86 | 87 | =item Gtk E 3.22 88 | 89 | I. 90 | 91 | =item D-Bus 92 | 93 | Optional. 94 | 95 | If the D-Bus low level C API is available, virt-p2v can send a D-Bus 96 | message to logind to inhibit power saving (sleep, suspend, etc) during 97 | P2V conversions. 98 | 99 | If this API is not available at build time, then very long conversions 100 | might be interrupted if the physical machine goes to sleep. 101 | 102 | =item valgrind 103 | 104 | Optional. For testing memory problems. 105 | 106 | =item bash-completion 107 | 108 | Optional. For tab-completion of commands in bash. 109 | 110 | =back 111 | 112 | =head1 BUILDING FROM GIT 113 | 114 | You will need to install additional dependencies C, 115 | and C when building from git. 116 | 117 | git clone https://github.com/libguestfs/virt-p2v 118 | cd virt-p2v 119 | autoreconf -i 120 | ./configure 121 | make 122 | 123 | =head1 BUILDING FROM TARBALLS 124 | 125 | Tarballs are downloaded from L. 126 | Stable tarballs are signed with the GnuPG key for C, 127 | see 128 | L. 129 | The fingerprint is C. 130 | 131 | Download and unpack the tarball. 132 | 133 | cd virt-p2v-1.xx.yy 134 | ./configure 135 | make 136 | 137 | =head1 RUNNING THE TESTS 138 | 139 | B Virt-p2v can be built and tested as 140 | non-root. Running the tests as root could even be dangerous, don't do 141 | it. 142 | 143 | To run the tests, do: 144 | 145 | make check 146 | 147 | There are many more tests you can run. See L 148 | for details. 149 | 150 | =head1 INSTALLING 151 | 152 | B!> You'll end up with conflicting versions 153 | of virt-p2v installed, and this causes constant headaches for users. 154 | See the next section for how to use the F<./run> script instead. 155 | 156 | Distro packagers can use: 157 | 158 | make DESTDIR=[temp-build-dir] install 159 | 160 | =head1 THE ./run SCRIPT 161 | 162 | You can test L and the other tools without needing 163 | to install them by using the F<./run> script in the top directory. 164 | This script works by setting several environment variables. 165 | 166 | For example: 167 | 168 | ./run virt-p2v-make-disk [usual virt-p2v-make-disk args ...] 169 | 170 | The F<./run> script adds every virt-p2v binary to the C<$PATH>, so 171 | the above example run virt-p2v-make-disk from the build directory 172 | (not the globally installed virt-p2v-make-disk if there is one). 173 | 174 | =head1 SELECTED ./configure SETTINGS 175 | 176 | There are many C<./configure> options. Use: 177 | 178 | ./configure --help 179 | 180 | to list them all. This section covers some of the more important 181 | ones. 182 | 183 | =over 4 184 | 185 | =item B<--enable-werror> 186 | 187 | This turns compiler warnings into errors (ie. C<-Werror>). Use this 188 | for development, especially when submitting patches. It should 189 | generally I be used for production or distro builds. 190 | 191 | =item B<--with-extra=">I=I,...B<"> 192 | 193 | =item B<--with-extra="local"> 194 | 195 | This option appends a text to the version of the virt-p2v tools. 196 | It is a free text field, but a good idea is to encode a 197 | comma-separated list of facts such as the distro name and version, 198 | and anything else that may help with debugging problems raised 199 | by users. 200 | 201 | For custom and/or local builds, this can be set to C to 202 | indicate this is I a distro build. 203 | 204 | =back 205 | 206 | =head1 USING CLANG (LLVM) INSTEAD OF GCC 207 | 208 | export CC=clang 209 | ./configure 210 | make 211 | 212 | =head1 BUILDING i686 32 BIT VIRT-P2V 213 | 214 | I<(This section only applies on the x86-64 architecture.)> 215 | 216 | Building a 32 bit virt-p2v (i686) binary improves compatibility with 217 | older hardware. See L for details. Although 218 | virt-p2v is a simple Gtk application, it is not especially easy to 219 | build just virt-p2v as a 32 bit application on a 64 bit host. Usually 220 | the simplest way is to use a 32 bit chroot or even a 32 bit virtual 221 | machine to build virt-p2v. 222 | 223 | On Fedora you can use the L tool. For example: 224 | 225 | fedpkg mockbuild --root fedora-23-i386 226 | 227 | This will result in a F file which can be 228 | unpacked to extract the 32 bit virt-p2v binary. 229 | 230 | The binary may be compressed to either F, or 231 | F<$libdir/virt-p2v/virt-p2v.i686.xz> or 232 | F<$VIRT_P2V_DATA_DIR/virt-p2v.i686.xz> as appropriate. This enables 233 | the L I<--arch> option. 234 | 235 | =head1 SEE ALSO 236 | 237 | L, 238 | L, 239 | L. 240 | 241 | =head1 AUTHORS 242 | 243 | Richard W.M. Jones (C) 244 | 245 | =head1 COPYRIGHT 246 | 247 | Copyright (C) 2009-2019 Red Hat Inc. 248 | -------------------------------------------------------------------------------- /docs/p2v-hacking.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | p2v-hacking - extending and contributing to virt-p2v 4 | 5 | =head1 DESCRIPTION 6 | 7 | This manual page is for hackers who want to extend virt-p2v itself. 8 | 9 | Virt-p2v is a front end on virt-v2v. ie. All it does is act as a GUI 10 | front end, and it calls out to virt-v2v to perform the actual 11 | conversion. Therefore most of the C code 12 | is Gtk (GUI) code, or supporting code for talking to the remote 13 | conversion server. There is no special support for physical machines 14 | in virt-v2v. They are converted in the same way as foreign VMs. 15 | 16 | =head1 THE SOURCE CODE 17 | 18 | Virt-p2v source is located in the github repository 19 | L 20 | 21 | Virt-p2v uses an autotools-based build system, with the main files 22 | being F and F. See L. 23 | 24 | To build from source, first read the L. 25 | 26 | =head2 SOURCE CODE SUBDIRECTORIES 27 | 28 | The majority of the source code is directly in the top level directory 29 | of the sources. There are also some subdirectories that contain some 30 | specific sub-parts of virt-p2v. 31 | 32 | =over 4 33 | 34 | =item F 35 | 36 | Bash tab-completion scripts. 37 | 38 | =item F 39 | 40 | Various build scripts used by autotools. 41 | 42 | =item F 43 | 44 | A copy of the miniexpect library from 45 | L. 46 | 47 | =item F 48 | 49 | Outside contributions, experimental parts. 50 | 51 | =item F 52 | 53 | Miscellaneous manual pages. 54 | 55 | =item F 56 | 57 | Some sources (mostly with utilities) copied from libguestfs. Changes 58 | to the sources there ought to be forwarded to libguestfs as well. 59 | 60 | =item F 61 | 62 | M4 macros used by autoconf. See L. 63 | 64 | =item F 65 | 66 | The virt-p2v files of the L website. 67 | 68 | =back 69 | 70 | =head2 THE BUILD SYSTEM 71 | 72 | Virt-p2v uses the GNU autotools build system (autoconf, automake). 73 | 74 | The F<./configure> script is generated from F and 75 | F. Most of the configure script is split over many 76 | m4 macro files by topic, for example F deals 77 | with the libraries required by virt-p2v. 78 | 79 | F is included in every F (top level and 80 | subdirectories). 81 | 82 | =head2 UNDERSTANDING THE CODE 83 | 84 | I L 85 | 86 | There are two paths through the code, GUI or non-GUI (parsing the 87 | kernel command line): 88 | 89 | main.c ──────┬─────▶ gui.c ──────┬─────▶ conversion.c 90 | │ │ 91 | │ │ 92 | └────▶ kernel.c ────┘ 93 | 94 | but both paths call back to the F function 95 | C to run the remote virt-v2v. 96 | 97 | The main task of F/F is to populate the virt-v2v 98 | configuration (F). 99 | 100 | During conversion, we need to establish ssh connections, and that is 101 | done using two libraries: 102 | 103 | conversion.c ──────▶ ssh.c ──────▶ miniexpect.c 104 | 105 | where F is responsible for managing ssh connections overall, 106 | and F implements "expect-like" functionality for talking 107 | interactively to the remote virt-v2v conversion server. 108 | 109 | (Note that miniexpect is a separate library with its own upstream, so 110 | if you patch miniexpect.c, then please make sure the changes get 111 | reflected in miniexpect’s upstream too: 112 | F) 113 | 114 | =head1 RUNNING VIRT-P2V 115 | 116 | You can run the F binary directly, but it will try to 117 | convert your machine’s real F which is unlikely to work 118 | well. However virt-p2v also has a test mode in which you can supply a 119 | test disk: 120 | 121 | make run-virt-p2v-directly 122 | 123 | This is a wrapper around the L I<--test-disk> option. 124 | You can control the "physical machine" disk by setting 125 | C to point to a disk image. 126 | 127 | A more realistic test is to run virt-p2v inside a VM on the local 128 | machine. To do that, do: 129 | 130 | make run-virt-p2v-in-a-vm 131 | make run-virt-p2v-in-an-nvme-vm 132 | 133 | These also run qemu with the "physical machine" disk (which you can 134 | set by setting C), a virtual CD, and a variety of 135 | network cards for testing. The second target exposes the "physical 136 | machine" disk as an NVMe controller, plus adds two blank disks as 137 | distinct namespaces of another NVMe controller. You can change the 138 | qemu binary and add extra qemu options by setting C and/or 139 | C on the make commandline. 140 | 141 | A third way to run virt-p2v simulates fairly accurately the program 142 | being downloaded over PXE and then doing an automatic conversion of 143 | the source physical machine (the non-GUI path -- see next section 144 | below): 145 | 146 | make run-virt-p2v-non-gui-conversion 147 | 148 | =head1 EXTENDING VIRT-P2V 149 | 150 | =head2 FORMATTING CODE 151 | 152 | Our C source code generally adheres to some basic code-formatting 153 | conventions. The existing code base is not totally consistent on this 154 | front, but we do prefer that contributed code be formatted similarly. 155 | In short, use spaces-not-TABs for indentation, use 2 spaces for each 156 | indentation level, and other than that, follow the K&R style. 157 | 158 | If you use Emacs, add the following to one of your start-up files 159 | (e.g., ~/.emacs), to help ensure that you get indentation right: 160 | 161 | ;;; In virt-p2v, indent with spaces everywhere (not TABs). 162 | ;;; Exceptions: Makefile and ChangeLog modes. 163 | (add-hook 'find-file-hook 164 | '(lambda () (if (and buffer-file-name 165 | (string-match "/virt-p2v\\>" 166 | (buffer-file-name)) 167 | (not (string-equal mode-name "Change Log")) 168 | (not (string-equal mode-name "Makefile"))) 169 | (setq indent-tabs-mode nil)))) 170 | 171 | ;;; When editing C sources in virt-p2v, use this style. 172 | (defun virt-p2v-c-mode () 173 | "C mode with adjusted defaults for use with virt-p2v." 174 | (interactive) 175 | (c-set-style "K&R") 176 | (setq c-indent-level 2) 177 | (setq c-basic-offset 2)) 178 | (add-hook 'c-mode-hook 179 | '(lambda () (if (string-match "/virt-p2v\\>" 180 | (buffer-file-name)) 181 | (virt-p2v-c-mode)))) 182 | 183 | =head2 TESTING YOUR CHANGES 184 | 185 | Turn warnings into errors when developing to make warnings hard to 186 | ignore: 187 | 188 | ./configure --enable-werror 189 | 190 | Useful targets are: 191 | 192 | =over 4 193 | 194 | =item C 195 | 196 | Runs the regular test suite. 197 | 198 | This is implemented using the regular automake C target. See 199 | the automake documentation for details. 200 | 201 | =item C 202 | 203 | Runs a subset of the test suite under valgrind. 204 | 205 | =item C 206 | 207 | Runs some slow/long-running tests which are not run by default. 208 | 209 | To mark a test as slow/long-running: 210 | 211 | =over 4 212 | 213 | =item * 214 | 215 | Add it to the list of C in the F, just like a 216 | normal test. 217 | 218 | =item * 219 | 220 | Modify the test so it checks if the C environment variable is 221 | set, and if I set it skips (ie. returns with exit code 77). If 222 | using C<$TEST_FUNCTIONS>, you can call the function C for 223 | this. 224 | 225 | =item * 226 | 227 | Add a variable C to the F listing the slow 228 | tests. 229 | 230 | =item * 231 | 232 | Add a rule to the F: 233 | 234 | check-slow: 235 | $(MAKE) check TESTS="$(SLOW_TESTS)" SLOW=1 236 | 237 | =back 238 | 239 | =back 240 | 241 | =head2 VALGRIND 242 | 243 | When you do C, it searches for any F 244 | in the tree that has a C target and runs it. 245 | 246 | Writing the F and tests correctly to use valgrind and 247 | working with automake parallel tests is subtle. 248 | 249 | If your tests are run via a shell script wrapper, then in the wrapper 250 | use: 251 | 252 | $VG virt-foo 253 | 254 | and in the F use: 255 | 256 | check-valgrind: 257 | make VG="@VG@" check 258 | 259 | However, if your binaries run directly from the C rule, you 260 | have to modify the F like this: 261 | 262 | LOG_COMPILER = $(VG) 263 | 264 | check-valgrind: 265 | make VG="@VG@" check 266 | 267 | In either case, check that the right program is being tested by 268 | examining the F log files carefully. 269 | 270 | =head2 SUBMITTING PATCHES 271 | 272 | Submit patches to the mailing list: 273 | L 274 | and CC to L. 275 | 276 | You do not need to subscribe to the mailing list if you don’t want to. 277 | There may be a short delay while your message is moderated. 278 | 279 | =head1 SEE ALSO 280 | 281 | L, 282 | L, 283 | L. 284 | 285 | =head1 AUTHORS 286 | 287 | Richard W.M. Jones (C) 288 | 289 | =head1 COPYRIGHT 290 | 291 | Copyright (C) 2009-2019 Red Hat Inc. 292 | -------------------------------------------------------------------------------- /docs/p2v-release-notes.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | p2v-release-notes - virt-p2v Release Notes 4 | 5 | =begin comment 6 | 7 | UPDATED TO 43b6c03d3b10d7ed425969574fc2dc24816ee450 8 | 9 | =end comment 10 | 11 | =begin comment 12 | 13 | 17 | 18 | =end comment 19 | 20 | =head1 RELEASE NOTES FOR VIRT-P2V 1.42.0 21 | 22 | These release notes only cover the differences from the previous 23 | version. For detailed changelogs, please see the git repository. 24 | 25 | =over 4 26 | 27 | =item 28 | 29 | The C output mode of virt-v2v is not listed as output 30 | driver, as virt-p2v does not provide all the GUI elements to properly 31 | use it (Pino Toscano). 32 | 33 | =item 34 | 35 | Virt-v2v is checked as requirement for the functional tests, in 36 | addition to guestfish, and virt-customize (Pino Toscano). 37 | 38 | =item 39 | 40 | Virt-p2v-make-disk now sets C as hostname in the generated disk 41 | image (Pino Toscano). 42 | 43 | =item 44 | 45 | Document C as initial password for the root user on the disk image 46 | generated by virt-p2v-make-disk, virt-p2v-make-kickstart, and 47 | virt-p2v-make-kiwi (Pino Toscano). 48 | 49 | =back 50 | 51 | =for comment ################################################################ 52 | 53 | =head1 RELEASE NOTES FOR VIRT-P2V 1.41.0 54 | 55 | This is the first standalone release of virt-p2v, split from the 56 | libguestfs sources. 57 | 58 | There are no functionality changes compared to virt-p2v shipped as 59 | part of libguestfs 1.40. 60 | 61 | =head1 RELEASE NOTES FOR HISTORICAL VERSIONS OF VIRT-P2V 62 | 63 | Before 1.41.0 virt-p2v was released as part of libguestfs. Therefore, 64 | release notes for these older versions are found as part of the 65 | L. 66 | 67 | =head1 SEE ALSO 68 | 69 | L, 70 | L 71 | 72 | =head1 AUTHOR 73 | 74 | Richard W.M. Jones 75 | 76 | =head1 COPYRIGHT 77 | 78 | Copyright (C) 2009-2019 Red Hat Inc. 79 | -------------------------------------------------------------------------------- /generate-p2v-authors.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # Copyright (C) 2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | use strict; 18 | use warnings; 19 | 20 | # Clean up the program name. 21 | my $progname = $0; 22 | $progname =~ s{.*/}{}; 23 | 24 | my $filename = shift or die "$progname: missing filename"; 25 | 26 | open(my $fh, '<', $filename) or die "Unable to open file '$filename': $!"; 27 | 28 | print <<"EOF"; 29 | /* libguestfs generated file 30 | * WARNING: THIS FILE IS GENERATED FROM THE FOLLOWING FILES: 31 | * $filename 32 | * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. 33 | */ 34 | 35 | #include 36 | 37 | #include "p2v.h" 38 | 39 | /* Authors involved with virt-v2v and virt-p2v directly. */ 40 | const char *authors[] = { 41 | EOF 42 | 43 | while (<$fh>) { 44 | chomp $_; 45 | printf " \"%s\",\n", $_; 46 | } 47 | 48 | print <<"EOF"; 49 | NULL 50 | }; 51 | EOF 52 | 53 | close($fh); 54 | -------------------------------------------------------------------------------- /gnulib/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2017-2022 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | 18 | # This directory contains some dependencies originally from gnulib. 19 | # The aim is for everything in this directory to eventually go away. 20 | 21 | include $(top_srcdir)/subdir-rules.mk 22 | 23 | noinst_LTLIBRARIES = libgnu.la 24 | libgnu_la_SOURCES = \ 25 | assure.h \ 26 | ignore-value.h \ 27 | xstrtol.c \ 28 | xstrtol.h \ 29 | xstrtoull.c 30 | libgnu_la_CFLAGS = \ 31 | $(WARN_CFLAGS) $(WERROR_CFLAGS) \ 32 | $(GCC_VISIBILITY_HIDDEN) 33 | -------------------------------------------------------------------------------- /gnulib/lib/assure.h: -------------------------------------------------------------------------------- 1 | /* Run-time assert-like macros. 2 | 3 | Copyright (C) 2014-2019 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | /* Written by Paul Eggert. */ 19 | 20 | #ifndef _GL_ASSURE_H 21 | #define _GL_ASSURE_H 22 | 23 | #include 24 | 25 | /* Check E's value at runtime, and report an error and abort if not. 26 | However, do nothing if NDEBUG is defined. 27 | 28 | Unlike standard 'assert', this macro always compiles E even when NDEBUG 29 | is defined, so as to catch typos and avoid some GCC warnings. */ 30 | 31 | #ifdef NDEBUG 32 | # define assure(E) ((void) (0 && (E))) 33 | #else 34 | # define assure(E) assert (E) 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /gnulib/lib/ignore-value.h: -------------------------------------------------------------------------------- 1 | /* ignore a function return without a compiler warning. -*- coding: utf-8 -*- 2 | 3 | Copyright (C) 2008-2019 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | /* Written by Jim Meyering, Eric Blake and Pádraig Brady. */ 19 | 20 | /* Use "ignore_value" to avoid a warning when using a function declared with 21 | gcc's warn_unused_result attribute, but for which you really do want to 22 | ignore the result. Traditionally, people have used a "(void)" cast to 23 | indicate that a function's return value is deliberately unused. However, 24 | if the function is declared with __attribute__((warn_unused_result)), 25 | gcc issues a warning even with the cast. 26 | 27 | Caution: most of the time, you really should heed gcc's warning, and 28 | check the return value. However, in those exceptional cases in which 29 | you're sure you know what you're doing, use this function. 30 | 31 | For the record, here's one of the ignorable warnings: 32 | "copy.c:233: warning: ignoring return value of 'fchown', 33 | declared with attribute warn_unused_result". */ 34 | 35 | #ifndef _GL_IGNORE_VALUE_H 36 | #define _GL_IGNORE_VALUE_H 37 | 38 | /* Normally casting an expression to void discards its value, but GCC 39 | versions 3.4 and newer have __attribute__ ((__warn_unused_result__)) 40 | which may cause unwanted diagnostics in that case. Use __typeof__ 41 | and __extension__ to work around the problem, if the workaround is 42 | known to be needed. */ 43 | #if 3 < __GNUC__ + (4 <= __GNUC_MINOR__) 44 | # define ignore_value(x) \ 45 | (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) 46 | #else 47 | # define ignore_value(x) ((void) (x)) 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /gnulib/lib/xstrtol.c: -------------------------------------------------------------------------------- 1 | /* A more useful interface to strtol. 2 | 3 | Copyright (C) 1995-1996, 1998-2001, 2003-2007, 2009-2019 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | /* Written by Jim Meyering. */ 20 | 21 | #ifndef __strtol 22 | # define __strtol strtol 23 | # define __strtol_t long int 24 | # define __xstrtol xstrtol 25 | # define STRTOL_T_MINIMUM LONG_MIN 26 | # define STRTOL_T_MAXIMUM LONG_MAX 27 | #endif 28 | 29 | #include 30 | 31 | #include "xstrtol.h" 32 | 33 | /* Some pre-ANSI implementations (e.g. SunOS 4) 34 | need stderr defined if assertion checking is enabled. */ 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "assure.h" 44 | 45 | #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) 46 | 47 | static strtol_error 48 | bkm_scale (__strtol_t *x, int scale_factor) 49 | { 50 | if (TYPE_SIGNED (__strtol_t) && *x < STRTOL_T_MINIMUM / scale_factor) 51 | { 52 | *x = STRTOL_T_MINIMUM; 53 | return LONGINT_OVERFLOW; 54 | } 55 | if (STRTOL_T_MAXIMUM / scale_factor < *x) 56 | { 57 | *x = STRTOL_T_MAXIMUM; 58 | return LONGINT_OVERFLOW; 59 | } 60 | *x *= scale_factor; 61 | return LONGINT_OK; 62 | } 63 | 64 | static strtol_error 65 | bkm_scale_by_power (__strtol_t *x, int base, int power) 66 | { 67 | strtol_error err = LONGINT_OK; 68 | while (power--) 69 | err |= bkm_scale (x, base); 70 | return err; 71 | } 72 | 73 | /* FIXME: comment. */ 74 | 75 | strtol_error 76 | __xstrtol (const char *s, char **ptr, int strtol_base, 77 | __strtol_t *val, const char *valid_suffixes) 78 | { 79 | char *t_ptr; 80 | char **p; 81 | __strtol_t tmp; 82 | strtol_error err = LONGINT_OK; 83 | 84 | assure (0 <= strtol_base && strtol_base <= 36); 85 | 86 | p = (ptr ? ptr : &t_ptr); 87 | 88 | errno = 0; 89 | 90 | if (! TYPE_SIGNED (__strtol_t)) 91 | { 92 | const char *q = s; 93 | unsigned char ch = *q; 94 | while (isspace (ch)) 95 | ch = *++q; 96 | if (ch == '-') 97 | return LONGINT_INVALID; 98 | } 99 | 100 | tmp = __strtol (s, p, strtol_base); 101 | 102 | if (*p == s) 103 | { 104 | /* If there is no number but there is a valid suffix, assume the 105 | number is 1. The string is invalid otherwise. */ 106 | if (valid_suffixes && **p && strchr (valid_suffixes, **p)) 107 | tmp = 1; 108 | else 109 | return LONGINT_INVALID; 110 | } 111 | else if (errno != 0) 112 | { 113 | if (errno != ERANGE) 114 | return LONGINT_INVALID; 115 | err = LONGINT_OVERFLOW; 116 | } 117 | 118 | /* Let valid_suffixes == NULL mean "allow any suffix". */ 119 | /* FIXME: update all callers except the ones that allow suffixes 120 | after the number, changing last parameter NULL to "". */ 121 | if (!valid_suffixes) 122 | { 123 | *val = tmp; 124 | return err; 125 | } 126 | 127 | if (**p != '\0') 128 | { 129 | int base = 1024; 130 | int suffixes = 1; 131 | strtol_error overflow; 132 | 133 | if (!strchr (valid_suffixes, **p)) 134 | { 135 | *val = tmp; 136 | return err | LONGINT_INVALID_SUFFIX_CHAR; 137 | } 138 | 139 | switch (**p) 140 | { 141 | case 'E': case 'G': case 'g': case 'k': case 'K': case 'M': case 'm': 142 | case 'P': case 'T': case 't': case 'Y': case 'Z': 143 | 144 | /* The "valid suffix" '0' is a special flag meaning that 145 | an optional second suffix is allowed, which can change 146 | the base. A suffix "B" (e.g. "100MB") stands for a power 147 | of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for 148 | a power of 1024. If no suffix (e.g. "100M"), assume 149 | power-of-1024. */ 150 | 151 | if (strchr (valid_suffixes, '0')) 152 | switch (p[0][1]) 153 | { 154 | case 'i': 155 | if (p[0][2] == 'B') 156 | suffixes += 2; 157 | break; 158 | 159 | case 'B': 160 | case 'D': /* 'D' is obsolescent */ 161 | base = 1000; 162 | suffixes++; 163 | break; 164 | } 165 | } 166 | 167 | switch (**p) 168 | { 169 | case 'b': 170 | overflow = bkm_scale (&tmp, 512); 171 | break; 172 | 173 | case 'B': 174 | /* This obsolescent first suffix is distinct from the 'B' 175 | second suffix above. E.g., 'tar -L 1000B' means change 176 | the tape after writing 1000 KiB of data. */ 177 | overflow = bkm_scale (&tmp, 1024); 178 | break; 179 | 180 | case 'c': 181 | overflow = LONGINT_OK; 182 | break; 183 | 184 | case 'E': /* exa or exbi */ 185 | overflow = bkm_scale_by_power (&tmp, base, 6); 186 | break; 187 | 188 | case 'G': /* giga or gibi */ 189 | case 'g': /* 'g' is undocumented; for compatibility only */ 190 | overflow = bkm_scale_by_power (&tmp, base, 3); 191 | break; 192 | 193 | case 'k': /* kilo */ 194 | case 'K': /* kibi */ 195 | overflow = bkm_scale_by_power (&tmp, base, 1); 196 | break; 197 | 198 | case 'M': /* mega or mebi */ 199 | case 'm': /* 'm' is undocumented; for compatibility only */ 200 | overflow = bkm_scale_by_power (&tmp, base, 2); 201 | break; 202 | 203 | case 'P': /* peta or pebi */ 204 | overflow = bkm_scale_by_power (&tmp, base, 5); 205 | break; 206 | 207 | case 'T': /* tera or tebi */ 208 | case 't': /* 't' is undocumented; for compatibility only */ 209 | overflow = bkm_scale_by_power (&tmp, base, 4); 210 | break; 211 | 212 | case 'w': 213 | overflow = bkm_scale (&tmp, 2); 214 | break; 215 | 216 | case 'Y': /* yotta or 2**80 */ 217 | overflow = bkm_scale_by_power (&tmp, base, 8); 218 | break; 219 | 220 | case 'Z': /* zetta or 2**70 */ 221 | overflow = bkm_scale_by_power (&tmp, base, 7); 222 | break; 223 | 224 | default: 225 | *val = tmp; 226 | return err | LONGINT_INVALID_SUFFIX_CHAR; 227 | } 228 | 229 | err |= overflow; 230 | *p += suffixes; 231 | if (**p) 232 | err |= LONGINT_INVALID_SUFFIX_CHAR; 233 | } 234 | 235 | *val = tmp; 236 | return err; 237 | } 238 | -------------------------------------------------------------------------------- /gnulib/lib/xstrtol.h: -------------------------------------------------------------------------------- 1 | /* A more useful interface to strtol. 2 | 3 | Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2019 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #ifndef XSTRTOL_H_ 20 | # define XSTRTOL_H_ 1 21 | 22 | # include 23 | 24 | # ifndef _STRTOL_ERROR 25 | enum strtol_error 26 | { 27 | LONGINT_OK = 0, 28 | 29 | /* These two values can be ORed together, to indicate that both 30 | errors occurred. */ 31 | LONGINT_OVERFLOW = 1, 32 | LONGINT_INVALID_SUFFIX_CHAR = 2, 33 | 34 | LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR 35 | | LONGINT_OVERFLOW), 36 | LONGINT_INVALID = 4 37 | }; 38 | typedef enum strtol_error strtol_error; 39 | # endif 40 | 41 | # define _DECLARE_XSTRTOL(name, type) \ 42 | strtol_error name (const char *, char **, int, type *, const char *); 43 | _DECLARE_XSTRTOL (xstrtol, long int) 44 | _DECLARE_XSTRTOL (xstrtoul, unsigned long int) 45 | _DECLARE_XSTRTOL (xstrtoimax, intmax_t) 46 | _DECLARE_XSTRTOL (xstrtoumax, uintmax_t) 47 | 48 | #if HAVE_LONG_LONG_INT 49 | _DECLARE_XSTRTOL (xstrtoll, long long int) 50 | _DECLARE_XSTRTOL (xstrtoull, unsigned long long int) 51 | #endif 52 | 53 | #endif /* not XSTRTOL_H_ */ 54 | -------------------------------------------------------------------------------- /gnulib/lib/xstrtoull.c: -------------------------------------------------------------------------------- 1 | #define __strtol strtoull 2 | #define __strtol_t unsigned long long int 3 | #define __xstrtol xstrtoull 4 | #define STRTOL_T_MINIMUM 0 5 | #define STRTOL_T_MAXIMUM ULLONG_MAX 6 | #include "xstrtol.c" 7 | -------------------------------------------------------------------------------- /gui-gtk3-compat.h: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2009-2019 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* Backwards compatibility for some deprecated functions in Gtk 3. */ 19 | #define hbox_new(box, homogeneous, spacing) \ 20 | do { \ 21 | (box) = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, spacing); \ 22 | if (homogeneous) \ 23 | gtk_box_set_homogeneous (GTK_BOX (box), TRUE); \ 24 | } while (0) 25 | #define vbox_new(box, homogeneous, spacing) \ 26 | do { \ 27 | (box) = gtk_box_new (GTK_ORIENTATION_VERTICAL, spacing); \ 28 | if (homogeneous) \ 29 | gtk_box_set_homogeneous (GTK_BOX (box), TRUE); \ 30 | } while (0) 31 | 32 | /* Copy this enum from GtkTable, as when building without deprecated 33 | * functions this is not automatically pulled in. 34 | */ 35 | typedef enum 36 | { 37 | GTK_EXPAND = 1 << 0, 38 | GTK_SHRINK = 1 << 1, 39 | GTK_FILL = 1 << 2 40 | } GtkAttachOptions; 41 | /* GtkGrid is sufficiently similar to GtkTable that we can just 42 | * redefine these functions. 43 | */ 44 | #define table_new(grid, rows, columns) \ 45 | (grid) = gtk_grid_new () 46 | #define table_attach(grid, child, left, right, top, xoptions, yoptions, xpadding, ypadding) \ 47 | do { \ 48 | if (((xoptions) & GTK_EXPAND) != 0) \ 49 | gtk_widget_set_hexpand ((child), TRUE); \ 50 | if (((xoptions) & GTK_FILL) != 0) \ 51 | gtk_widget_set_halign ((child), GTK_ALIGN_FILL); \ 52 | if (((yoptions) & GTK_EXPAND) != 0) \ 53 | gtk_widget_set_vexpand ((child), TRUE); \ 54 | if (((yoptions) & GTK_FILL) != 0) \ 55 | gtk_widget_set_valign ((child), GTK_ALIGN_FILL); \ 56 | set_padding ((child), (xpadding), (ypadding)); \ 57 | gtk_grid_attach (GTK_GRID (grid), (child), \ 58 | (left), (top), (right)-(left), 1); \ 59 | } while (0) 60 | 61 | #define scrolled_window_add_with_viewport(container, child) \ 62 | gtk_container_add (GTK_CONTAINER (container), child) 63 | 64 | #undef GTK_STOCK_DIALOG_WARNING 65 | #define GTK_STOCK_DIALOG_WARNING "dialog-warning" 66 | #define gtk_image_new_from_stock gtk_image_new_from_icon_name 67 | 68 | #define set_padding(widget, xpad, ypad) \ 69 | do { \ 70 | if ((xpad) != 0) { \ 71 | gtk_widget_set_margin_start ((widget), (xpad)); \ 72 | gtk_widget_set_margin_end ((widget), (xpad)); \ 73 | } \ 74 | if ((ypad) != 0) { \ 75 | gtk_widget_set_margin_top ((widget), (ypad)); \ 76 | gtk_widget_set_margin_bottom ((widget), (ypad)); \ 77 | } \ 78 | } while (0) 79 | #define set_alignment(widget, xalign, yalign) \ 80 | do { \ 81 | if ((xalign) == 0.) \ 82 | gtk_widget_set_halign ((widget), GTK_ALIGN_START); \ 83 | else if ((xalign) == 1.) \ 84 | gtk_widget_set_halign ((widget), GTK_ALIGN_END); \ 85 | else \ 86 | gtk_widget_set_halign ((widget), GTK_ALIGN_CENTER); \ 87 | if ((yalign) == 0.) \ 88 | gtk_widget_set_valign ((widget), GTK_ALIGN_START); \ 89 | else if ((xalign) == 1.) \ 90 | gtk_widget_set_valign ((widget), GTK_ALIGN_END); \ 91 | else \ 92 | gtk_widget_set_valign ((widget), GTK_ALIGN_CENTER); \ 93 | } while (0) 94 | -------------------------------------------------------------------------------- /inhibit.c: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2016 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /** 19 | * This file is used to inhibit power saving, sleep, suspend etc during 20 | * the conversion. 21 | * 22 | * The method it uses is to send a D-Bus message to logind, as 23 | * described here: 24 | * 25 | * https://www.freedesktop.org/wiki/Software/systemd/inhibit/ 26 | * 27 | * If virt-p2v is compiled without D-Bus support then this does nothing. 28 | */ 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #if defined(HAVE_DBUS) 37 | #include 38 | #endif 39 | 40 | #include "p2v.h" 41 | 42 | /** 43 | * Inhibit all forms of power saving. A file descriptor is returned, 44 | * and when the file descriptor is closed the inhibit is stopped. 45 | * 46 | * If the function returns C<-1> then C operation could not 47 | * be performed (eg. if we are compiled without D-Bus support, or there 48 | * is some error contacting logind). This is not usually fatal from 49 | * the point of view of the caller, conversion can continue. 50 | */ 51 | int 52 | inhibit_power_saving (void) 53 | { 54 | #if defined(HAVE_DBUS) && defined(DBUS_TYPE_UNIX_FD) 55 | DBusError err; 56 | DBusConnection *conn = NULL; 57 | DBusMessage *msg = NULL; 58 | DBusMessageIter args; 59 | DBusPendingCall *pending = NULL; 60 | const char *what = "shutdown:sleep:idle"; 61 | const char *who = "virt-p2v"; 62 | const char *why = "virt-p2v conversion is running"; 63 | const char *mode = "block"; 64 | int fd = -1; 65 | 66 | dbus_error_init (&err); 67 | 68 | conn = dbus_bus_get (DBUS_BUS_SYSTEM, &err); 69 | if (dbus_error_is_set (&err)) { 70 | fprintf (stderr, "inhibit_power_saving: dbus: cannot connect to system bus: %s\n", err.message); 71 | goto out; 72 | } 73 | if (conn == NULL) 74 | goto out; 75 | 76 | msg = dbus_message_new_method_call ("org.freedesktop.login1", 77 | "/org/freedesktop/login1", 78 | "org.freedesktop.login1.Manager", 79 | "Inhibit"); 80 | if (msg == NULL) { 81 | fprintf (stderr, "inhibit_power_saving: dbus: cannot create message\n"); 82 | goto out; 83 | } 84 | 85 | dbus_message_iter_init_append (msg, &args); 86 | if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &what) || 87 | !dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &who) || 88 | !dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &why) || 89 | !dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &mode)) { 90 | fprintf (stderr, "inhibit_power_saving: dbus: cannot add message arguments\n"); 91 | goto out; 92 | } 93 | 94 | if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { 95 | fprintf (stderr, "inhibit_power_saving: dbus: cannot send Inhibit message to logind\n"); 96 | goto out; 97 | } 98 | if (pending == NULL) 99 | goto out; 100 | dbus_connection_flush (conn); 101 | 102 | dbus_message_unref (msg); 103 | msg = NULL; 104 | 105 | dbus_pending_call_block (pending); 106 | msg = dbus_pending_call_steal_reply (pending); 107 | if (msg == NULL) { 108 | fprintf (stderr, "inhibit_power_saving: dbus: could not read message reply\n"); 109 | goto out; 110 | } 111 | 112 | dbus_pending_call_unref (pending); 113 | pending = NULL; 114 | 115 | if (!dbus_message_iter_init (msg, &args)) { 116 | fprintf (stderr, "inhibit_power_saving: dbus: message reply has no return value\n"); 117 | goto out; 118 | } 119 | 120 | if (dbus_message_iter_get_arg_type (&args) != DBUS_TYPE_UNIX_FD) { 121 | fprintf (stderr, "inhibit_power_saving: dbus: message reply is not a file descriptor\n"); 122 | goto out; 123 | } 124 | 125 | dbus_message_iter_get_basic (&args, &fd); 126 | 127 | #ifdef DEBUG_STDERR 128 | fprintf (stderr, "inhibit_power_saving: dbus: Inhibit() call returned file descriptor %d\n", fd); 129 | #endif 130 | 131 | out: 132 | if (pending != NULL) 133 | dbus_pending_call_unref (pending); 134 | if (msg != NULL) 135 | dbus_message_unref (msg); 136 | 137 | /* This is the system bus connection, so unref-ing it does not 138 | * actually close it. 139 | */ 140 | if (conn != NULL) 141 | dbus_connection_unref (conn); 142 | 143 | dbus_error_free (&err); 144 | 145 | return fd; 146 | 147 | #else /* !dbus */ 148 | #ifdef DEBUG_STDERR 149 | fprintf (stderr, "warning: virt-p2v compiled without D-Bus support.\n"); 150 | #endif 151 | return -1; 152 | #endif 153 | } 154 | -------------------------------------------------------------------------------- /issue: -------------------------------------------------------------------------------- 1 | virt-p2v - Convert a physical machine to use KVM. 2 | 3 | *** 4 | The root password is "p2v" (without quotes). 5 | 6 | To see the status of virt-p2v, do: 7 | 8 | systemctl status p2v -l 9 | 10 | Virt-p2v may take some time to start up. If virt-p2v is not running 11 | after a few minutes, you can start it by typing: 12 | 13 | launch-virt-p2v 14 | 15 | *** 16 | 17 | -------------------------------------------------------------------------------- /kernel-cmdline.c: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2015 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /** 19 | * Mini library to read and parse C. 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "p2v.h" 32 | 33 | static void 34 | add_null (char ***argv, size_t *lenp) 35 | { 36 | (*lenp)++; 37 | *argv = realloc (*argv, *lenp * sizeof (char *)); 38 | if (*argv == NULL) 39 | error (EXIT_FAILURE, errno, "realloc"); 40 | (*argv)[(*lenp)-1] = NULL; 41 | } 42 | 43 | static void 44 | add_string (char ***argv, size_t *lenp, const char *str, size_t len) 45 | { 46 | add_null (argv, lenp); 47 | (*argv)[(*lenp)-1] = strndup (str, len); 48 | if ((*argv)[(*lenp)-1] == NULL) 49 | error (EXIT_FAILURE, errno, "strndup"); 50 | } 51 | 52 | /** 53 | * Read and parse C. 54 | * 55 | * We only support double quoting, consistent with the Linux 56 | * documentation. 57 | * L 58 | * 59 | * systemd supports single and double quoting and single character 60 | * escaping, but we don't support all that. 61 | * 62 | * Returns a list of key, value pairs, terminated by C. 63 | */ 64 | char ** 65 | parse_cmdline_string (const char *cmdline) 66 | { 67 | char **ret = NULL; 68 | size_t len = 0; 69 | const char *p, *key = NULL, *value = NULL; 70 | enum { 71 | KEY_START = 0, 72 | KEY, 73 | VALUE_START, 74 | VALUE, 75 | VALUE_QUOTED 76 | } state = 0; 77 | 78 | for (p = cmdline; *p; p++) { 79 | switch (state) { 80 | case KEY_START: /* looking for the start of a key */ 81 | if (*p == ' ') continue; 82 | key = p; 83 | state = KEY; 84 | break; 85 | 86 | case KEY: /* reading key */ 87 | if (*p == ' ') { 88 | add_string (&ret, &len, key, p-key); 89 | add_string (&ret, &len, "", 0); 90 | state = KEY_START; 91 | } 92 | else if (*p == '=') { 93 | add_string (&ret, &len, key, p-key); 94 | state = VALUE_START; 95 | } 96 | break; 97 | 98 | case VALUE_START: /* looking for the start of a value */ 99 | if (*p == ' ') { 100 | add_string (&ret, &len, "", 0); 101 | state = KEY_START; 102 | } 103 | else if (*p == '"') { 104 | value = p+1; 105 | state = VALUE_QUOTED; 106 | } 107 | else { 108 | value = p; 109 | state = VALUE; 110 | } 111 | break; 112 | 113 | case VALUE: /* reading unquoted value */ 114 | if (*p == ' ') { 115 | add_string (&ret, &len, value, p-value); 116 | state = KEY_START; 117 | } 118 | break; 119 | 120 | case VALUE_QUOTED: /* reading quoted value */ 121 | if (*p == '"') { 122 | add_string (&ret, &len, value, p-value); 123 | state = KEY_START; 124 | } 125 | break; 126 | } 127 | } 128 | 129 | switch (state) { 130 | case KEY_START: break; 131 | case KEY: /* key followed by end of string */ 132 | add_string (&ret, &len, key, p-key); 133 | add_string (&ret, &len, "", 0); 134 | break; 135 | case VALUE_START: /* key= followed by end of string */ 136 | add_string (&ret, &len, "", 0); 137 | break; 138 | case VALUE: /* key=value followed by end of string */ 139 | add_string (&ret, &len, value, p-value); 140 | break; 141 | case VALUE_QUOTED: /* unterminated key="value" */ 142 | fprintf (stderr, "%s: warning: unterminated quoted string on kernel command line\n", 143 | g_get_prgname ()); 144 | add_string (&ret, &len, value, p-value); 145 | } 146 | 147 | add_null (&ret, &len); 148 | 149 | return ret; 150 | } 151 | 152 | char ** 153 | parse_proc_cmdline (void) 154 | { 155 | CLEANUP_FCLOSE FILE *fp = NULL; 156 | CLEANUP_FREE char *cmdline = NULL; 157 | size_t len = 0; 158 | 159 | fp = fopen ("/proc/cmdline", "re"); 160 | if (fp == NULL) { 161 | perror ("/proc/cmdline"); 162 | return NULL; 163 | } 164 | 165 | if (getline (&cmdline, &len, fp) == -1) { 166 | perror ("getline"); 167 | return NULL; 168 | } 169 | 170 | /* 'len' is not the length of the string, but the length of the 171 | * buffer. We need to chomp the string. 172 | */ 173 | len = strlen (cmdline); 174 | 175 | if (len >= 1 && cmdline[len-1] == '\n') 176 | cmdline[len-1] = '\0'; 177 | 178 | return parse_cmdline_string (cmdline); 179 | } 180 | 181 | const char * 182 | get_cmdline_key (char **argv, const char *key) 183 | { 184 | size_t i; 185 | 186 | for (i = 0; argv[i] != NULL; i += 2) { 187 | if (STREQ (argv[i], key)) 188 | return argv[i+1]; 189 | } 190 | 191 | /* Not found. */ 192 | return NULL; 193 | } 194 | -------------------------------------------------------------------------------- /kernel.c: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2009-2019 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /** 19 | * Kernel-driven, non-interactive configuration of virt-p2v. 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "p2v.h" 38 | 39 | static void notify_ui_callback (int type, const char *data); 40 | static void run_command (const char *stage, const char *command); 41 | 42 | /* Perform conversion using the kernel method. */ 43 | void 44 | kernel_conversion (struct config *config, char **cmdline, int cmdline_source) 45 | { 46 | const char *p; 47 | 48 | /* Pre-conversion command. */ 49 | p = get_cmdline_key (cmdline, "p2v.pre"); 50 | if (p) 51 | run_command ("p2v.pre", p); 52 | 53 | /* Connect to and interrogate virt-v2v on the conversion server. */ 54 | p = get_cmdline_key (cmdline, "p2v.skip_test_connection"); 55 | if (!p) { 56 | wait_network_online (config); 57 | if (test_connection (config) == -1) { 58 | const char *err = get_ssh_error (); 59 | 60 | error (EXIT_FAILURE, 0, 61 | "error opening control connection to %s:%d: %s", 62 | config->remote.server, config->remote.port, err); 63 | } 64 | } 65 | 66 | /* Some disks must have been specified for conversion. */ 67 | if (config->disks == NULL || guestfs_int_count_strings (config->disks) == 0) 68 | error (EXIT_FAILURE, 0, 69 | "no non-removable disks were discovered on this machine.\n" 70 | "virt-p2v looked in /sys/block and in p2v.disks on the kernel command line.\n" 71 | "This is a fatal error and virt-p2v cannot continue."); 72 | 73 | /* Perform the conversion in text mode. */ 74 | if (start_conversion (config, notify_ui_callback) == -1) { 75 | const char *err = get_conversion_error (); 76 | 77 | fprintf (stderr, "%s: error during conversion: %s\n", 78 | g_get_prgname (), err); 79 | 80 | p = get_cmdline_key (cmdline, "p2v.fail"); 81 | if (p) 82 | run_command ("p2v.fail", p); 83 | 84 | exit (EXIT_FAILURE); 85 | } 86 | 87 | ansi_green (stdout); 88 | printf ("Conversion finished successfully."); 89 | ansi_restore (stdout); 90 | putchar ('\n'); 91 | 92 | p = get_cmdline_key (cmdline, "p2v.post"); 93 | if (!p) { 94 | if (geteuid () == 0 && cmdline_source == CMDLINE_SOURCE_PROC_CMDLINE) 95 | p = "poweroff"; 96 | } 97 | if (p) 98 | run_command ("p2v.post", p); 99 | } 100 | 101 | static void 102 | notify_ui_callback (int type, const char *data) 103 | { 104 | switch (type) { 105 | case NOTIFY_LOG_DIR: 106 | ansi_magenta (stdout); 107 | printf ("%s: remote log directory location: ", g_get_prgname ()); 108 | ansi_red (stdout); 109 | fputs (data, stdout); 110 | ansi_restore (stdout); 111 | putchar ('\n'); 112 | break; 113 | 114 | case NOTIFY_REMOTE_MESSAGE: 115 | printf ("%s", data); 116 | break; 117 | 118 | case NOTIFY_STATUS: 119 | ansi_magenta (stdout); 120 | printf ("%s: %s", g_get_prgname (), data); 121 | ansi_restore (stdout); 122 | putchar ('\n'); 123 | break; 124 | 125 | default: 126 | ansi_red (stdout); 127 | printf ("%s: unknown message during conversion: type=%d data=%s", 128 | g_get_prgname (), type, data); 129 | ansi_restore (stdout); 130 | putchar ('\n'); 131 | } 132 | 133 | fflush (stdout); 134 | } 135 | 136 | static void 137 | run_command (const char *stage, const char *command) 138 | { 139 | int r; 140 | 141 | if (STREQ (command, "")) 142 | return; 143 | 144 | #if DEBUG_STDERR 145 | fprintf (stderr, "%s\n", command); 146 | fflush (stderr); 147 | #endif 148 | 149 | r = system (command); 150 | if (r == -1) 151 | error (EXIT_FAILURE, errno, "system: %s", command); 152 | if ((WIFEXITED (r) && WEXITSTATUS (r) != 0) || !WIFEXITED (r)) 153 | error (EXIT_FAILURE, 0, 154 | "%s: unexpected failure of external command", stage); 155 | } 156 | -------------------------------------------------------------------------------- /kiwi-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #================ 3 | # FILE : config.sh 4 | #---------------- 5 | # PROJECT : OpenSuSE KIWI Image System 6 | # COPYRIGHT : (c) 2006 SUSE LINUX Products GmbH. All rights reserved 7 | # : 8 | # AUTHOR : Marcus Schaefer 9 | #====================================== 10 | # Functions... 11 | #-------------------------------------- 12 | test -f /.kconfig && . /.kconfig 13 | test -f /.profile && . /.profile 14 | 15 | #====================================== 16 | # Greeting... 17 | #-------------------------------------- 18 | echo "Configure image: [$kiwi_iname]..." 19 | 20 | #====================================== 21 | # Mount system filesystems 22 | #-------------------------------------- 23 | baseMount 24 | 25 | #====================================== 26 | # Setup baseproduct link 27 | #-------------------------------------- 28 | suseSetupProduct 29 | 30 | #====================================== 31 | # Add missing gpg keys to rpm 32 | #-------------------------------------- 33 | suseImportBuildKey 34 | 35 | #====================================== 36 | # Activate services 37 | #-------------------------------------- 38 | suseInsertService p2v 39 | 40 | #====================================== 41 | # Setup default target, multi-user 42 | #-------------------------------------- 43 | baseSetRunlevel 3 44 | 45 | #========================================== 46 | # remove package docs 47 | #------------------------------------------ 48 | rm -rf /usr/share/doc/packages/* 49 | rm -rf /usr/share/doc/manual/* 50 | rm -rf /opt/kde* 51 | 52 | # Update the default getty target to login automatically as root without 53 | # prompting for a password 54 | sed -i 's/^ExecStart=\(.*\)/ExecStart=\1 -a root/' \ 55 | /usr/lib/systemd/system/getty@.service 56 | 57 | # Reserve tty1 as a getty so we can document it clearly 58 | echo ReserveVT=1 >> /etc/systemd/logind.conf 59 | 60 | sed -i 's/^ROOT_USES_LANG=.*$/ROOT_USES_LANG="yes"/' \ 61 | /etc/sysconfig/language 62 | 63 | #====================================== 64 | # SuSEconfig 65 | #-------------------------------------- 66 | suseConfig 67 | 68 | #====================================== 69 | # Umount kernel filesystems 70 | #-------------------------------------- 71 | baseCleanMount 72 | 73 | exit 0 74 | -------------------------------------------------------------------------------- /kiwi-config.xml.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Marcus Schäfer 5 | ms@suse.com 6 | P2V __PACKAGE_VERSION__ 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | __PACKAGE_VERSION__ 15 | zypper 16 | en_US 17 | us.map.gz 18 | utc 19 | __BRANDING__ 20 | __BRANDING__ 21 | true 22 | false 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /launch-virt-p2v: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # (C) Copyright 2014-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # This normally runs from systemd which deals with logging. 18 | 19 | # Are we running in GUI or non-GUI mode? This is controlled by the 20 | # presence of "p2v.server" on the kernel command line. 21 | cmdline=$( macros to simplify temporary 21 | * allocations. They are implemented using the 22 | * C<__attribute__((cleanup))> feature of gcc and clang. Typical 23 | * usage is: 24 | * 25 | * fn () 26 | * { 27 | * CLEANUP_FREE char *str = NULL; 28 | * str = safe_asprintf (g, "foo"); 29 | * // str is freed automatically when the function returns 30 | * } 31 | * 32 | * There are a few catches to be aware of with the cleanup mechanism: 33 | * 34 | * =over 4 35 | * 36 | * =item * 37 | * 38 | * If a cleanup variable is not initialized, then you can end up 39 | * calling L with an undefined value, resulting in the 40 | * program crashing. For this reason, you should usually initialize 41 | * every cleanup variable with something, eg. C 42 | * 43 | * =item * 44 | * 45 | * Don't mark variables holding return values as cleanup variables. 46 | * 47 | * =item * 48 | * 49 | * The C function shouldn't use cleanup variables since it is 50 | * normally exited by calling L, and that doesn't call the 51 | * cleanup handlers. 52 | * 53 | * =back 54 | * 55 | * The functions in this file are used internally by the C 56 | * macros. Don't call them directly. 57 | */ 58 | 59 | #include 60 | 61 | #include 62 | #include 63 | 64 | #define PCRE2_CODE_UNIT_WIDTH 8 65 | #include 66 | 67 | #include "guestfs-utils.h" 68 | 69 | /* Stdlib cleanups. */ 70 | 71 | void 72 | guestfs_int_cleanup_free (void *ptr) 73 | { 74 | free (* (void **) ptr); 75 | } 76 | 77 | void 78 | guestfs_int_cleanup_fclose (void *ptr) 79 | { 80 | FILE *f = * (FILE **) ptr; 81 | 82 | if (f) 83 | fclose (f); 84 | } 85 | 86 | void 87 | guestfs_int_cleanup_pclose (void *ptr) 88 | { 89 | FILE *f = * (FILE **) ptr; 90 | 91 | if (f) 92 | pclose (f); 93 | } 94 | 95 | void 96 | guestfs_int_cleanup_free_string_list (char ***ptr) 97 | { 98 | guestfs_int_free_string_list (*ptr); 99 | } 100 | 101 | void 102 | guestfs_int_cleanup_pcre2_match_data_free (void *ptr) 103 | { 104 | pcre2_match_data *match_data = * (pcre2_match_data **) ptr; 105 | pcre2_match_data_free (match_data); 106 | } 107 | 108 | void 109 | guestfs_int_cleanup_pcre2_substring_free (void *ptr) 110 | { 111 | PCRE2_UCHAR *str = * (PCRE2_UCHAR **) ptr; 112 | pcre2_substring_free (str); 113 | } 114 | -------------------------------------------------------------------------------- /libguestfs/cleanups.h: -------------------------------------------------------------------------------- 1 | /* libguestfs 2 | * Copyright (C) 2013-2019 Red Hat Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef GUESTFS_CLEANUPS_H_ 20 | #define GUESTFS_CLEANUPS_H_ 21 | 22 | #ifdef HAVE_ATTRIBUTE_CLEANUP 23 | #define CLEANUP_FREE \ 24 | __attribute__((cleanup(guestfs_int_cleanup_free))) 25 | #define CLEANUP_FCLOSE \ 26 | __attribute__((cleanup(guestfs_int_cleanup_fclose))) 27 | #define CLEANUP_PCLOSE \ 28 | __attribute__((cleanup(guestfs_int_cleanup_pclose))) 29 | #define CLEANUP_FREE_STRING_LIST \ 30 | __attribute__((cleanup(guestfs_int_cleanup_free_string_list))) 31 | #define CLEANUP_XMLFREE \ 32 | __attribute__((cleanup(guestfs_int_cleanup_xmlFree))) 33 | #define CLEANUP_XMLBUFFERFREE \ 34 | __attribute__((cleanup(guestfs_int_cleanup_xmlBufferFree))) 35 | #define CLEANUP_XMLFREEDOC \ 36 | __attribute__((cleanup(guestfs_int_cleanup_xmlFreeDoc))) 37 | #define CLEANUP_XMLFREEURI \ 38 | __attribute__((cleanup(guestfs_int_cleanup_xmlFreeURI))) 39 | #define CLEANUP_XMLFREETEXTWRITER \ 40 | __attribute__((cleanup(guestfs_int_cleanup_xmlFreeTextWriter))) 41 | #define CLEANUP_XMLXPATHFREECONTEXT \ 42 | __attribute__((cleanup(guestfs_int_cleanup_xmlXPathFreeContext))) 43 | #define CLEANUP_XMLXPATHFREEOBJECT \ 44 | __attribute__((cleanup(guestfs_int_cleanup_xmlXPathFreeObject))) 45 | #define CLEANUP_PCRE2_MATCH_DATA \ 46 | __attribute__((cleanup(guestfs_int_cleanup_pcre2_match_data_free))) 47 | #define CLEANUP_PCRE2_SUBSTRING_FREE \ 48 | __attribute__((cleanup(guestfs_int_cleanup_pcre2_substring_free))) 49 | #else 50 | #define CLEANUP_FREE 51 | #define CLEANUP_FCLOSE 52 | #define CLEANUP_PCLOSE 53 | #define CLEANUP_FREE_STRING_LIST 54 | #define CLEANUP_XMLFREE 55 | #define CLEANUP_XMLBUFFERFREE 56 | #define CLEANUP_XMLFREEDOC 57 | #define CLEANUP_XMLFREEURI 58 | #define CLEANUP_XMLFREETEXTWRITER 59 | #define CLEANUP_XMLXPATHFREECONTEXT 60 | #define CLEANUP_XMLXPATHFREEOBJECT 61 | #define CLEANUP_PCRE2_MATCH_DATA 62 | #define CLEANUP_PCRE2_SUBSTRING_FREE 63 | #endif 64 | 65 | /* These functions are used internally by the CLEANUP_* macros. 66 | * Don't call them directly. 67 | */ 68 | extern void guestfs_int_cleanup_free (void *ptr); 69 | extern void guestfs_int_cleanup_fclose (void *ptr); 70 | extern void guestfs_int_cleanup_pclose (void *ptr); 71 | extern void guestfs_int_cleanup_free_string_list (char ***ptr); 72 | extern void guestfs_int_cleanup_xmlFree (void *ptr); 73 | extern void guestfs_int_cleanup_xmlBufferFree (void *ptr); 74 | extern void guestfs_int_cleanup_xmlFreeDoc (void *ptr); 75 | extern void guestfs_int_cleanup_xmlFreeURI (void *ptr); 76 | extern void guestfs_int_cleanup_xmlFreeTextWriter (void *ptr); 77 | extern void guestfs_int_cleanup_xmlXPathFreeContext (void *ptr); 78 | extern void guestfs_int_cleanup_xmlXPathFreeObject (void *ptr); 79 | extern void guestfs_int_cleanup_pcre2_match_data_free (void *ptr); 80 | extern void guestfs_int_cleanup_pcre2_substring_free (void *ptr); 81 | 82 | #endif /* GUESTFS_CLEANUPS_H_ */ 83 | -------------------------------------------------------------------------------- /libguestfs/guestfs-utils.c: -------------------------------------------------------------------------------- 1 | /* libguestfs 2 | * Copyright (C) 2009-2019 Red Hat Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "guestfs-utils.h" 30 | 31 | void 32 | guestfs_int_free_string_list (char **argv) 33 | { 34 | size_t i; 35 | 36 | if (argv == NULL) 37 | return; 38 | 39 | for (i = 0; argv[i] != NULL; ++i) 40 | free (argv[i]); 41 | free (argv); 42 | } 43 | 44 | size_t 45 | guestfs_int_count_strings (char *const *argv) 46 | { 47 | size_t r; 48 | 49 | for (r = 0; argv[r]; ++r) 50 | ; 51 | 52 | return r; 53 | } 54 | 55 | char ** 56 | guestfs_int_copy_string_list (char *const *argv) 57 | { 58 | const size_t n = guestfs_int_count_strings (argv); 59 | size_t i, j; 60 | char **ret; 61 | 62 | ret = malloc ((n+1) * sizeof (char *)); 63 | if (ret == NULL) 64 | return NULL; 65 | ret[n] = NULL; 66 | 67 | for (i = 0; i < n; ++i) { 68 | ret[i] = strdup (argv[i]); 69 | if (ret[i] == NULL) { 70 | for (j = 0; j < i; ++j) 71 | free (ret[j]); 72 | free (ret); 73 | return NULL; 74 | } 75 | } 76 | 77 | return ret; 78 | } 79 | 80 | char * 81 | guestfs_int_join_strings (const char *sep, char *const *argv) 82 | { 83 | size_t i, len, seplen, rlen; 84 | char *r; 85 | 86 | seplen = strlen (sep); 87 | 88 | len = 0; 89 | for (i = 0; argv[i] != NULL; ++i) { 90 | if (i > 0) 91 | len += seplen; 92 | len += strlen (argv[i]); 93 | } 94 | len++; /* for final \0 */ 95 | 96 | r = malloc (len); 97 | if (r == NULL) 98 | return NULL; 99 | 100 | rlen = 0; 101 | for (i = 0; argv[i] != NULL; ++i) { 102 | if (i > 0) { 103 | memcpy (&r[rlen], sep, seplen); 104 | rlen += seplen; 105 | } 106 | len = strlen (argv[i]); 107 | memcpy (&r[rlen], argv[i], len); 108 | rlen += len; 109 | } 110 | r[rlen] = '\0'; 111 | 112 | return r; 113 | } 114 | 115 | /** 116 | * Split string at separator character C, returning the list of 117 | * strings. Returns C on memory allocation failure. 118 | * 119 | * Note (assuming C is C<:>): 120 | * 121 | * =over 4 122 | * 123 | * =item C 124 | * 125 | * aborts 126 | * 127 | * =item C 128 | * 129 | * returns C<[]> 130 | * 131 | * =item C 132 | * 133 | * returns C<["abc"]> 134 | * 135 | * =item C 136 | * 137 | * returns C<["", ""]> 138 | * 139 | * =back 140 | */ 141 | char ** 142 | guestfs_int_split_string (char sep, const char *str) 143 | { 144 | size_t i, n, c; 145 | const size_t len = strlen (str); 146 | char reject[2] = { sep, '\0' }; 147 | char **ret; 148 | 149 | /* We have to handle the empty string case differently else the code 150 | * below will return [""]. 151 | */ 152 | if (str[0] == '\0') { 153 | ret = malloc (1 * sizeof (char *)); 154 | if (!ret) 155 | return NULL; 156 | ret[0] = NULL; 157 | return ret; 158 | } 159 | 160 | for (n = i = 0; i < len; ++i) 161 | if (str[i] == sep) 162 | n++; 163 | 164 | /* We always return a list of length 1 + (# separator characters). 165 | * We also have to add a trailing NULL. 166 | */ 167 | ret = malloc ((n+2) * sizeof (char *)); 168 | if (!ret) 169 | return NULL; 170 | ret[n+1] = NULL; 171 | 172 | for (n = i = 0; i <= len; ++i, ++n) { 173 | c = strcspn (&str[i], reject); 174 | ret[n] = strndup (&str[i], c); 175 | if (ret[n] == NULL) { 176 | for (i = 0; i < n; ++i) 177 | free (ret[i]); 178 | free (ret); 179 | return NULL; 180 | } 181 | i += c; 182 | if (str[i] == '\0') /* end of string? */ 183 | break; 184 | } 185 | 186 | return ret; 187 | } 188 | 189 | /** 190 | * Return a random string of characters. 191 | * 192 | * Notes: 193 | * 194 | * =over 4 195 | * 196 | * =item * 197 | * 198 | * The C buffer must have length C in order to store the 199 | * final C<\0> character. 200 | * 201 | * =item * 202 | * 203 | * There is about 5 bits of randomness per output character (so about 204 | * C<5*len> bits of randomness in the resulting string). 205 | * 206 | * =back 207 | */ 208 | int 209 | guestfs_int_random_string (char *ret, size_t len) 210 | { 211 | int fd; 212 | size_t i; 213 | unsigned char c; 214 | int saved_errno; 215 | 216 | fd = open ("/dev/urandom", O_RDONLY|O_CLOEXEC); 217 | if (fd == -1) 218 | return -1; 219 | 220 | for (i = 0; i < len; ++i) { 221 | if (read (fd, &c, 1) != 1) { 222 | saved_errno = errno; 223 | close (fd); 224 | errno = saved_errno; 225 | return -1; 226 | } 227 | /* Do not change this! */ 228 | ret[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[c % 36]; 229 | } 230 | ret[len] = '\0'; 231 | 232 | if (close (fd) == -1) 233 | return -1; 234 | 235 | return 0; 236 | } 237 | 238 | /** 239 | * This turns a drive index (eg. C<27>) into a drive name 240 | * (eg. C<"ab">). 241 | * 242 | * Drive indexes count from C<0>. The return buffer has to be large 243 | * enough for the resulting string, and the returned pointer points to 244 | * the *end* of the string. 245 | * 246 | * L 247 | */ 248 | char * 249 | guestfs_int_drive_name (size_t index, char *ret) 250 | { 251 | if (index >= 26) 252 | ret = guestfs_int_drive_name (index/26 - 1, ret); 253 | index %= 26; 254 | *ret++ = 'a' + index; 255 | *ret = '\0'; 256 | return ret; 257 | } 258 | 259 | /** 260 | * Similar to C. 261 | */ 262 | int 263 | guestfs_int_is_true (const char *str) 264 | { 265 | if (STREQ (str, "1") || 266 | STRCASEEQ (str, "true") || 267 | STRCASEEQ (str, "t") || 268 | STRCASEEQ (str, "yes") || 269 | STRCASEEQ (str, "y") || 270 | STRCASEEQ (str, "on")) 271 | return 1; 272 | 273 | if (STREQ (str, "0") || 274 | STRCASEEQ (str, "false") || 275 | STRCASEEQ (str, "f") || 276 | STRCASEEQ (str, "no") || 277 | STRCASEEQ (str, "n") || 278 | STRCASEEQ (str, "off")) 279 | return 0; 280 | 281 | return -1; 282 | } 283 | -------------------------------------------------------------------------------- /libguestfs/guestfs-utils.h: -------------------------------------------------------------------------------- 1 | /* libguestfs 2 | * Copyright (C) 2013-2019 Red Hat Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef GUESTFS_UTILS_H_ 20 | #define GUESTFS_UTILS_H_ 21 | 22 | #include 23 | 24 | #include "cleanups.h" 25 | 26 | #define _(str) dgettext(PACKAGE, (str)) 27 | 28 | #define STREQ(a,b) (strcmp((a),(b)) == 0) 29 | #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) 30 | #define STRNEQ(a,b) (strcmp((a),(b)) != 0) 31 | #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) 32 | 33 | /* A simple (indeed, simplistic) way to build up short lists of 34 | * arguments. Your code must define MAX_ARGS to a suitable "larger 35 | * than could ever be needed" value. (If the value is exceeded then 36 | * your code will abort). For more complex needs, use something else 37 | * more suitable. 38 | */ 39 | #define ADD_ARG(argv,i,v) \ 40 | do { \ 41 | if ((i) >= MAX_ARGS) { \ 42 | fprintf (stderr, "%s: %d: internal error: exceeded MAX_ARGS (%zu) when constructing the command line\n", __FILE__, __LINE__, (size_t) MAX_ARGS); \ 43 | abort (); \ 44 | } \ 45 | (argv)[(i)++] = (v); \ 46 | } while (0) 47 | 48 | extern void guestfs_int_free_string_list (char **); 49 | extern size_t guestfs_int_count_strings (char *const *); 50 | extern char **guestfs_int_copy_string_list (char *const *); 51 | extern char *guestfs_int_join_strings (const char *sep, char *const *); 52 | extern char **guestfs_int_split_string (char sep, const char *); 53 | extern int guestfs_int_random_string (char *ret, size_t len); 54 | extern char *guestfs_int_drive_name (size_t index, char *ret); 55 | extern int guestfs_int_is_true (const char *str); 56 | 57 | /* ANSI colours. These are defined as macros so that we don't have to 58 | * define the force_colour global variable in the library. 59 | */ 60 | #define ansi_green(fp) \ 61 | do { \ 62 | if (force_colour || isatty (fileno (fp))) \ 63 | fputs ("\033[0;32m", (fp)); \ 64 | } while (0) 65 | #define ansi_red(fp) \ 66 | do { \ 67 | if (force_colour || isatty (fileno (fp))) \ 68 | fputs ("\033[1;31m", (fp)); \ 69 | } while (0) 70 | #define ansi_blue(fp) \ 71 | do { \ 72 | if (force_colour || isatty (fileno (fp))) \ 73 | fputs ("\033[1;34m", (fp)); \ 74 | } while (0) 75 | #define ansi_magenta(fp) \ 76 | do { \ 77 | if (force_colour || isatty (fileno (fp))) \ 78 | fputs ("\033[1;35m", (fp)); \ 79 | } while (0) 80 | #define ansi_restore(fp) \ 81 | do { \ 82 | if (force_colour || isatty (fileno (fp))) \ 83 | fputs ("\033[0m", (fp)); \ 84 | } while (0) 85 | 86 | #endif /* GUESTFS_UTILS_H_ */ 87 | -------------------------------------------------------------------------------- /libguestfs/libxml2-cleanups.c: -------------------------------------------------------------------------------- 1 | /* libguestfs 2 | * Copyright (C) 2013-2019 Red Hat Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "cleanups.h" 32 | 33 | void 34 | guestfs_int_cleanup_xmlFree (void *ptr) 35 | { 36 | xmlChar *buf = * (xmlChar **) ptr; 37 | 38 | if (buf) 39 | xmlFree (buf); 40 | } 41 | 42 | void 43 | guestfs_int_cleanup_xmlBufferFree (void *ptr) 44 | { 45 | xmlBufferPtr xb = * (xmlBufferPtr *) ptr; 46 | 47 | if (xb) 48 | xmlBufferFree (xb); 49 | } 50 | 51 | void 52 | guestfs_int_cleanup_xmlFreeDoc (void *ptr) 53 | { 54 | xmlDocPtr doc = * (xmlDocPtr *) ptr; 55 | 56 | if (doc) 57 | xmlFreeDoc (doc); 58 | } 59 | 60 | void 61 | guestfs_int_cleanup_xmlFreeURI (void *ptr) 62 | { 63 | xmlURIPtr uri = * (xmlURIPtr *) ptr; 64 | 65 | if (uri) 66 | xmlFreeURI (uri); 67 | } 68 | 69 | void 70 | guestfs_int_cleanup_xmlFreeTextWriter (void *ptr) 71 | { 72 | xmlTextWriterPtr xo = * (xmlTextWriterPtr *) ptr; 73 | 74 | if (xo) 75 | xmlFreeTextWriter (xo); 76 | } 77 | 78 | void 79 | guestfs_int_cleanup_xmlXPathFreeContext (void *ptr) 80 | { 81 | xmlXPathContextPtr ctx = * (xmlXPathContextPtr *) ptr; 82 | 83 | if (ctx) 84 | xmlXPathFreeContext (ctx); 85 | } 86 | 87 | void 88 | guestfs_int_cleanup_xmlXPathFreeObject (void *ptr) 89 | { 90 | xmlXPathObjectPtr obj = * (xmlXPathObjectPtr *) ptr; 91 | 92 | if (obj) 93 | xmlXPathFreeObject (obj); 94 | } 95 | -------------------------------------------------------------------------------- /libguestfs/libxml2-writer-macros.h: -------------------------------------------------------------------------------- 1 | /* libguestfs 2 | * Copyright (C) 2009-2019 Red Hat Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /** 20 | * These macros make it easier to write XML. To use them correctly 21 | * you must be aware of these assumptions: 22 | * 23 | * =over 4 24 | * 25 | * =item * 26 | * 27 | * The C is called C. It is used implicitly 28 | * by all the macros. 29 | * 30 | * =item * 31 | * 32 | * On failure, a function called C is called which you must 33 | * define (usually as a macro). You must use C macros in 34 | * your functions if you want correct cleanup of local variables along 35 | * the error path. 36 | * 37 | * =item * 38 | * 39 | * All the "bad" casting is hidden inside the macros. 40 | * 41 | * =back 42 | */ 43 | 44 | #ifndef GUESTFS_LIBXML2_WRITER_MACROS_H_ 45 | #define GUESTFS_LIBXML2_WRITER_MACROS_H_ 46 | 47 | #include 48 | 49 | /** 50 | * To define an XML element use: 51 | * 52 | * start_element ("name") { 53 | * ... 54 | * } end_element (); 55 | * 56 | * which produces C<<< ... >>> 57 | */ 58 | #define start_element(element) \ 59 | if (xmlTextWriterStartElement (xo, BAD_CAST (element)) == -1) { \ 60 | xml_error ("xmlTextWriterStartElement"); \ 61 | } \ 62 | do 63 | 64 | #define end_element() \ 65 | while (0); \ 66 | do { \ 67 | if (xmlTextWriterEndElement (xo) == -1) { \ 68 | xml_error ("xmlTextWriterEndElement"); \ 69 | } \ 70 | } while (0) 71 | 72 | /** 73 | * To define an empty element: 74 | * 75 | * empty_element ("name"); 76 | * 77 | * which produces C<<< >>> 78 | */ 79 | #define empty_element(element) \ 80 | do { start_element ((element)) {} end_element (); } while (0) 81 | 82 | /** 83 | * To define a single element with no attributes containing some text: 84 | * 85 | * single_element ("name", text); 86 | * 87 | * which produces C<<< text >>> 88 | */ 89 | #define single_element(element,str) \ 90 | do { \ 91 | start_element ((element)) { \ 92 | string ((str)); \ 93 | } end_element (); \ 94 | } while (0) 95 | 96 | /** 97 | * To define a single element with no attributes containing some text 98 | * using a format string: 99 | * 100 | * single_element_format ("cores", "%d", nr_cores); 101 | * 102 | * which produces C<<< 4 >>> 103 | */ 104 | #define single_element_format(element,fs,...) \ 105 | do { \ 106 | start_element ((element)) { \ 107 | string_format ((fs), ##__VA_ARGS__); \ 108 | } end_element (); \ 109 | } while (0) 110 | 111 | /** 112 | * To define an XML element with attributes, use: 113 | * 114 | * start_element ("name") { 115 | * attribute ("foo", "bar"); 116 | * attribute_format ("count", "%d", count); 117 | * ... 118 | * } end_element (); 119 | * 120 | * which produces C<<< ... >>> 121 | */ 122 | #define attribute(key,value) \ 123 | do { \ 124 | if (xmlTextWriterWriteAttribute (xo, BAD_CAST (key), \ 125 | BAD_CAST (value)) == -1) { \ 126 | xml_error ("xmlTextWriterWriteAttribute"); \ 127 | } \ 128 | } while (0) 129 | 130 | #define attribute_format(key,fs,...) \ 131 | do { \ 132 | if (xmlTextWriterWriteFormatAttribute (xo, BAD_CAST (key), \ 133 | fs, ##__VA_ARGS__) == -1) { \ 134 | xml_error ("xmlTextWriterWriteFormatAttribute"); \ 135 | } \ 136 | } while (0) 137 | 138 | /** 139 | * C defines a 140 | * namespaced attribute. 141 | */ 142 | #define attribute_ns(prefix,key,namespace_uri,value) \ 143 | do { \ 144 | if (xmlTextWriterWriteAttributeNS (xo, BAD_CAST (prefix), \ 145 | BAD_CAST (key), \ 146 | BAD_CAST (namespace_uri), \ 147 | BAD_CAST (value)) == -1) { \ 148 | xml_error ("xmlTextWriterWriteAttribute"); \ 149 | } \ 150 | } while (0) 151 | 152 | /** 153 | * To define a verbatim string, use: 154 | * 155 | * string ("hello"); 156 | */ 157 | #define string(str) \ 158 | do { \ 159 | if (xmlTextWriterWriteString (xo, BAD_CAST(str)) == -1) { \ 160 | xml_error ("xmlTextWriterWriteString"); \ 161 | } \ 162 | } while (0) 163 | 164 | /** 165 | * To define a verbatim string using a format string, use: 166 | * 167 | * string ("%s, world", greeting); 168 | */ 169 | #define string_format(fs,...) \ 170 | do { \ 171 | if (xmlTextWriterWriteFormatString (xo, fs, ##__VA_ARGS__) == -1) { \ 172 | xml_error ("xmlTextWriterWriteFormatString"); \ 173 | } \ 174 | } while (0) 175 | 176 | /** 177 | * To write a string encoded as base64: 178 | * 179 | * base64 (data, size); 180 | */ 181 | #define base64(data, size) \ 182 | do { \ 183 | if (xmlTextWriterWriteBase64 (xo, (data), 0, (size)) == -1) { \ 184 | xml_error ("xmlTextWriterWriteBase64"); \ 185 | } \ 186 | } while (0) 187 | 188 | /** 189 | * To define a comment in the XML, use: 190 | * 191 | * comment ("number of items = %d", nr_items); 192 | */ 193 | #define comment(fs,...) \ 194 | do { \ 195 | if (xmlTextWriterWriteFormatComment (xo, fs, ##__VA_ARGS__) == -1) { \ 196 | xml_error ("xmlTextWriterWriteFormatComment"); \ 197 | } \ 198 | } while (0) 199 | 200 | #endif /* GUESTFS_LIBXML2_WRITER_MACROS_H_ */ 201 | -------------------------------------------------------------------------------- /m4/p2v-bash-completion.m4: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2009-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | dnl Bash completion. 18 | PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], [ 19 | bash_completion=yes 20 | AC_MSG_CHECKING([for bash-completions directory]) 21 | BASH_COMPLETIONS_DIR="`pkg-config --variable=completionsdir bash-completion`" 22 | AC_MSG_RESULT([$BASH_COMPLETIONS_DIR]) 23 | AC_SUBST([BASH_COMPLETIONS_DIR]) 24 | ],[ 25 | bash_completion=no 26 | AC_MSG_WARN([bash-completion not installed]) 27 | ]) 28 | AM_CONDITIONAL([HAVE_BASH_COMPLETION],[test "x$bash_completion" = "xyes"]) 29 | -------------------------------------------------------------------------------- /m4/p2v-c.m4: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2009-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | dnl The C compiler environment. 18 | dnl Define the host CPU architecture (defines 'host_cpu') 19 | AC_CANONICAL_HOST 20 | 21 | dnl Check for basic C environment. 22 | AC_PROG_CC_STDC 23 | AC_PROG_INSTALL 24 | AC_PROG_CPP 25 | 26 | AC_C_PROTOTYPES 27 | test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant]) 28 | 29 | AM_PROG_CC_C_O 30 | 31 | AC_ARG_ENABLE([werror], 32 | [AS_HELP_STRING([--enable-werror], 33 | [turn on lots of GCC warnings (for developers)])], 34 | [case $enableval in 35 | yes|no) ;; 36 | *) AC_MSG_ERROR([bad value $enableval for werror option]) ;; 37 | esac 38 | gcc_warnings=$enableval], 39 | [gcc_warnings=no] 40 | ) 41 | WARN_CFLAGS="-Wall -Wextra -Wshadow -Wno-unused-parameter" 42 | AC_SUBST([WARN_CFLAGS]) 43 | if test "x$gcc_warnings" = "xyes"; then 44 | WERROR_CFLAGS="-Werror" 45 | fi 46 | AC_SUBST([WERROR_CFLAGS]) 47 | 48 | # Provide a global place to set CFLAGS. (Note that setting AM_CFLAGS 49 | # is no use because it doesn't override target_CFLAGS). 50 | #--- 51 | # Kill -fstrict-overflow which is a license for the C compiler to make 52 | # dubious and often unsafe optimizations, in a time-wasting attempt to 53 | # deal with CPU architectures that do not exist. 54 | CFLAGS="$CFLAGS -fno-strict-overflow -Wno-strict-overflow" 55 | 56 | dnl Check support for 64 bit file offsets. 57 | AC_SYS_LARGEFILE 58 | 59 | dnl Check sizeof long. 60 | AC_CHECK_SIZEOF([long]) 61 | 62 | dnl Check if __attribute__((cleanup(...))) works. 63 | dnl Set -Werror, otherwise gcc will only emit a warning for attributes 64 | dnl that it doesn't understand. 65 | acx_nbdkit_save_CFLAGS="${CFLAGS}" 66 | CFLAGS="${CFLAGS} -Werror" 67 | AC_MSG_CHECKING([if __attribute__((cleanup(...))) works with this compiler]) 68 | AC_COMPILE_IFELSE([ 69 | AC_LANG_SOURCE([[ 70 | #include 71 | #include 72 | 73 | void 74 | freep (void *ptr) 75 | { 76 | exit (EXIT_SUCCESS); 77 | } 78 | 79 | void 80 | test (void) 81 | { 82 | __attribute__((cleanup(freep))) char *ptr = malloc (100); 83 | } 84 | 85 | int 86 | main (int argc, char *argv[]) 87 | { 88 | test (); 89 | exit (EXIT_FAILURE); 90 | } 91 | ]]) 92 | ],[ 93 | AC_MSG_RESULT([yes]) 94 | AC_DEFINE([HAVE_ATTRIBUTE_CLEANUP],[1],[Define to 1 if '__attribute__((cleanup(...)))' works with this compiler.]) 95 | ],[ 96 | AC_MSG_WARN( 97 | ['__attribute__((cleanup(...)))' does not work. 98 | 99 | You may not be using a sufficiently recent version of GCC or CLANG, or 100 | you may be using a C compiler which does not support this attribute, 101 | or the configure test may be wrong. 102 | 103 | The code will still compile, but is likely to leak memory and other 104 | resources when it runs.])]) 105 | dnl restore CFLAGS 106 | CFLAGS="${acx_nbdkit_save_CFLAGS}" 107 | -------------------------------------------------------------------------------- /m4/p2v-libraries.m4: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2009-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | dnl Any C libraries required by virt-p2v. 18 | 19 | dnl Define a C symbol for the host CPU architecture. 20 | AC_DEFINE_UNQUOTED([host_cpu],["$host_cpu"],[Host architecture.]) 21 | 22 | dnl Headers. 23 | AC_CHECK_HEADERS([\ 24 | linux/rtc.h]) 25 | 26 | dnl Which header file defines major, minor, makedev. 27 | AC_HEADER_MAJOR 28 | 29 | dnl Check for PCRE2 (required) 30 | PKG_CHECK_MODULES([PCRE2], [libpcre2-8]) 31 | 32 | dnl libxml2 (required) 33 | PKG_CHECK_MODULES([LIBXML2], [libxml-2.0]) 34 | 35 | dnl Check for the Glib 2 and Gtk 3 libraries, used by virt-p2v (required). 36 | PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= 2.56]) 37 | PKG_CHECK_MODULES([GTK3], [gtk+-3.0 >= 3.22]) 38 | 39 | dnl D-Bus is an optional dependency of virt-p2v. 40 | PKG_CHECK_MODULES([DBUS], [dbus-1], [ 41 | AC_SUBST([DBUS_CFLAGS]) 42 | AC_SUBST([DBUS_LIBS]) 43 | AC_DEFINE([HAVE_DBUS],[1],[D-Bus found at compile time.]) 44 | ],[ 45 | AC_MSG_WARN([D-Bus not found, virt-p2v will not be able to inhibit power saving during P2V conversions]) 46 | ]) 47 | -------------------------------------------------------------------------------- /m4/p2v-progs.m4: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2009-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # Check for external programs required to either build or run 18 | # virt-p2v. 19 | # 20 | # AC_CHECK_PROG(S) or AC_PATH_PROG(S)? 21 | # 22 | # Use AC_CHECK_PROG(S) for programs which are only used during build. 23 | # 24 | # Use AC_PATH_PROG(S) for program names which are compiled into the 25 | # binary and used at run time. The reason is so that we know which 26 | # programs the binary actually uses. 27 | 28 | # Define $(SED). 29 | m4_ifdef([AC_PROG_SED],[ 30 | AC_PROG_SED 31 | ],[ 32 | dnl ... else hope for the best 33 | AC_SUBST([SED], "sed") 34 | ]) 35 | 36 | # Define $(AWK). 37 | AC_PROG_AWK 38 | 39 | AC_PROG_LN_S 40 | 41 | dnl Check for perl (required). 42 | AC_CHECK_PROG([PERL],[perl],[perl],[no]) 43 | test "x$PERL" = "xno" && 44 | AC_MSG_ERROR([perl must be installed]) 45 | 46 | dnl Check for Pod::Man, Pod::Simple (for man pages). 47 | AC_MSG_CHECKING([for Pod::Man]) 48 | if ! $PERL -MPod::Man -e1 >&AS_MESSAGE_LOG_FD 2>&1; then 49 | AC_MSG_ERROR([perl Pod::Man must be installed]) 50 | else 51 | AC_MSG_RESULT([yes]) 52 | fi 53 | AC_MSG_CHECKING([for Pod::Simple]) 54 | if ! $PERL -MPod::Simple -e1 >&AS_MESSAGE_LOG_FD 2>&1; then 55 | AC_MSG_ERROR([perl Pod::Simple must be installed]) 56 | else 57 | AC_MSG_RESULT([yes]) 58 | fi 59 | 60 | dnl Check for List::Util, used by generate-p2v-config.pl 61 | AC_MSG_CHECKING([for List::Util]) 62 | if ! $PERL -MList::Util=1.33 -e1 >&AS_MESSAGE_LOG_FD 2>&1; then 63 | AC_MSG_ERROR([perl List::Util@1.33 must be installed]) 64 | else 65 | AC_MSG_RESULT([yes]) 66 | fi 67 | 68 | dnl Define the path to the podwrapper program. 69 | PODWRAPPER="\$(guestfs_am_v_podwrapper)$PERL $(pwd)/podwrapper.pl" 70 | AC_SUBST([PODWRAPPER]) 71 | -------------------------------------------------------------------------------- /m4/p2v-tests.m4: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2009-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | dnl Check libguestfs tools. 18 | AC_CHECK_PROG([GUESTFISH],[guestfish],[guestfish],[no]) 19 | AC_CHECK_PROG([VIRT_BUILDER],[virt-builder],[virt-builder],[no]) 20 | AC_CHECK_PROG([VIRT_V2V],[virt-v2v],[virt-v2v],[no]) 21 | AM_CONDITIONAL([HAVE_LIBGUESTFS], 22 | [test "x$GUESTFISH" != "xno" && test "x$VIRT_BUILDER" != "xno" && test "x$VIRT_V2V" != "xno"]) 23 | 24 | dnl Check for valgrind 25 | AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind],[no]) 26 | AS_IF([test "x$VALGRIND" != "xno"],[ 27 | # Substitute the whole valgrind command. 28 | # --read-inline-info=no is a temporary workaround for RHBZ#1662656. 29 | VG='$(VALGRIND) --vgdb=no --leak-check=full --error-exitcode=119 --suppressions=$(abs_top_srcdir)/valgrind-suppressions --trace-children=no --child-silent-after-fork=yes --run-libc-freeres=no --read-inline-info=no' 30 | ],[ 31 | # No valgrind, so substitute VG with something that will break. 32 | VG=VALGRIND_IS_NOT_INSTALLED 33 | ]) 34 | AC_SUBST([VG]) 35 | AM_SUBST_NOTMAKE([VG]) 36 | -------------------------------------------------------------------------------- /make-physical-machine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # Copyright (C) 2022 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | set -e -u -C 18 | 19 | base_image=fedora-41 20 | 21 | # The array below open-codes the partition:filesystem layout of the 22 | # virt-builder disk template used above. Whenever you bump the Fedora 23 | # version, update the array below as needed. 24 | # 25 | # We cannot use inspection either before or after the filesystem UUID 26 | # changes: 27 | # 28 | # - the UUID of a mounted filesystem cannot be changed (at least with 29 | # - XFS); 30 | # 31 | # - right after the UUID changes, inspection does not work correctly, 32 | # as the new fs UUIDs are out of sync with the UUID references in 33 | # those config files that inspection relies upon. 34 | # 35 | # Note that the order of entries is important too: the mount points 36 | # must be listed in dependency order (put the dependees first, the 37 | # dependants last). 38 | fsdevs=(/dev/sda3:/ /dev/sda2:/boot) 39 | 40 | GUESTFISH_PID= 41 | disk= 42 | 43 | cleanup() 44 | { 45 | set +e 46 | if test -n "$GUESTFISH_PID"; then 47 | guestfish --remote -- exit >/dev/null 2>&1 48 | GUESTFISH_PID= 49 | fi 50 | if test -n "$disk"; then 51 | rm -f -- "$disk" 52 | disk= 53 | fi 54 | } 55 | 56 | trap cleanup EXIT 57 | 58 | output=$1 59 | outdir=$(dirname -- "$output") 60 | disk=$(mktemp -p "$outdir" physical-machine.tmp.XXXXXXXXXX) 61 | # Delay the SELinux relabeling. 62 | virt-builder --format raw -o "$disk" --root-password password:p2v-phys \ 63 | --no-selinux-relabel $base_image 64 | 65 | # Start a guestfish server on the disk image, so that each of the 66 | # several UUID-manipulation commands below not need a separate 67 | # guestfish launch. 68 | guestfish_set_pid=$(guestfish --listen --format=raw --add "$disk") 69 | eval "$guestfish_set_pid" 70 | guestfish --remote -- run 71 | 72 | # For each filesystem: 73 | # 74 | # - regenerate the UUID, 75 | # 76 | # - produce a sed command (scriptlet) that performs the same UUID 77 | # replacement in a text file, 78 | # 79 | # - mount the filesystem. 80 | # 81 | # Note that later we're going to rely on the fact that the generated 82 | # sed commands *require no quoting* on the shell command line. 83 | declare -a sed_script 84 | sed_idx=0 85 | for fsdev in "${fsdevs[@]}"; do 86 | device=${fsdev%:*} 87 | mountpoint=${fsdev#*:} 88 | 89 | old_uuid=$(guestfish --remote -- get-uuid "$device") 90 | guestfish --remote -- set-uuid-random "$device" 91 | new_uuid=$(guestfish --remote -- get-uuid "$device") 92 | 93 | sed_script[sed_idx++]=-e 94 | sed_script[sed_idx++]=s/$old_uuid/$new_uuid/ig 95 | 96 | guestfish --remote -- mount "$device" "$mountpoint" 97 | done 98 | 99 | # Prepare the UUID replacement shell command for the appliance. 100 | refresh_uuid_refs=(find /boot /etc -type f -print0 '|' 101 | xargs -0 -r -- sed -i "${sed_script[@]}" --) 102 | 103 | # Passing the shell command to the appliance is where we rely on the 104 | # fact that the sed commands for replacing UUIDs require no quoting. 105 | guestfish --remote -- sh "${refresh_uuid_refs[*]}" 106 | 107 | # Tear down the guestfish server before we use virt-customize. 108 | waitpid=$GUESTFISH_PID 109 | guestfish --remote -- exit 110 | GUESTFISH_PID= 111 | while kill -s 0 -- "$waitpid" 2>/dev/null; do 112 | sleep 1 113 | done 114 | 115 | # Reapply the SELinux labels now. Use virt-customize for this, rather 116 | # than guestfish's "selinux-relabel", as virt-customize contains some 117 | # heavy logic related to "specfile". Inspection does work here, 118 | # because the config files are in sync again with the filesystem 119 | # UUIDs. 120 | virt-customize --format raw --add "$disk" --selinux-relabel 121 | 122 | # We're done; rename the temporary disk image to the expected output 123 | # file. 124 | mv -- "$disk" "$output" 125 | disk= 126 | -------------------------------------------------------------------------------- /miniexpect/README: -------------------------------------------------------------------------------- 1 | Miniexpect is a very simple expect-like library 2 | 3 | Expect (https://core.tcl-lang.org/expect/index) is a venerable Tcl 4 | program for automating interactive services, often for automating 5 | logins over telnet, ftp, ssh, etc. 6 | 7 | Miniexpect is a C library which has a saner interface than libexpect, 8 | and doesn't depend on Tcl. It is also thread safe, const-correct and 9 | uses modern C standards. 10 | 11 | Miniexpect is standalone, except that it requires the PCRE2 (Perl 12 | Compatible Regular Expressions) library from http://www.pcre.org/. 13 | The PCRE2 dependency is fundamental because we want to offer the most 14 | powerful regular expression syntax to match on, but more importantly 15 | because PCRE2 has a convenient way to detect partial matches which 16 | made miniexpect very simple to implement. 17 | 18 | License 19 | ------- 20 | 21 | The library was written by Richard W.M. Jones 22 | and is licensed under the Library GPL (LGPL) version 2 or above. 23 | 24 | Source is available from: http://git.annexia.org/?p=miniexpect.git;a=summary 25 | 26 | Using the library 27 | ----------------- 28 | 29 | If you wanted to copy the library into your own code (instead of 30 | linking to it as a dependency), you only need to copy the two files: 31 | miniexpect.h, miniexpect.c. 32 | 33 | The API is documented in the manual page (miniexpect.pod / miniexpect.3). 34 | 35 | For examples of how to use the API in reality, see the examples and 36 | tests in the source directory. 37 | -------------------------------------------------------------------------------- /miniexpect/miniexpect.h: -------------------------------------------------------------------------------- 1 | /* miniexpect 2 | * Copyright (C) 2014-2022 Red Hat Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* ** NOTE ** All API documentation is in the manual page. 20 | * 21 | * To read the manual page from the source directory, do: 22 | * man ./miniexpect.3 23 | * If you have installed miniexpect, do: 24 | * man 3 miniexpect 25 | * 26 | * The source for the manual page is miniexpect.pod. 27 | */ 28 | 29 | #ifndef MINIEXPECT_H_ 30 | #define MINIEXPECT_H_ 31 | 32 | #include 33 | #include 34 | 35 | #define PCRE2_CODE_UNIT_WIDTH 8 36 | #include 37 | 38 | /* This handle is created per subprocess that is spawned. */ 39 | struct mexp_h { 40 | int fd; 41 | pid_t pid; 42 | int timeout; 43 | char *buffer; 44 | size_t len; 45 | size_t alloc; 46 | ssize_t next_match; 47 | size_t read_size; 48 | int pcre_error; 49 | FILE *debug_fp; 50 | void *user1; 51 | void *user2; 52 | void *user3; 53 | }; 54 | typedef struct mexp_h mexp_h; 55 | 56 | /* Methods to access (some) fields in the handle. */ 57 | #define mexp_get_fd(h) ((h)->fd) 58 | #define mexp_get_pid(h) ((h)->pid) 59 | #define mexp_get_timeout_ms(h) ((h)->timeout) 60 | #define mexp_set_timeout_ms(h, ms) ((h)->timeout = (ms)) 61 | /* If secs == -1, then this sets h->timeout to -1000, but the main 62 | * code handles this since it only checks for h->timeout < 0. 63 | */ 64 | #define mexp_set_timeout(h, secs) ((h)->timeout = 1000 * (secs)) 65 | #define mexp_get_read_size(h) ((h)->read_size) 66 | #define mexp_set_read_size(h, size) ((h)->read_size = (size)) 67 | #define mexp_get_pcre_error(h) ((h)->pcre_error) 68 | #define mexp_set_debug_file(h, fp) ((h)->debug_fp = (fp)) 69 | #define mexp_get_debug_file(h) ((h)->debug_fp) 70 | 71 | /* Spawn a subprocess. */ 72 | extern mexp_h *mexp_spawnvf (unsigned flags, const char *file, char **argv); 73 | extern mexp_h *mexp_spawnlf (unsigned flags, const char *file, const char *arg, ...); 74 | #define mexp_spawnv(file,argv) mexp_spawnvf (0, (file), (argv)) 75 | #define mexp_spawnl(file,...) mexp_spawnlf (0, (file), __VA_ARGS__) 76 | 77 | #define MEXP_SPAWN_KEEP_SIGNALS 1 78 | #define MEXP_SPAWN_KEEP_FDS 2 79 | #define MEXP_SPAWN_COOKED_MODE 4 80 | #define MEXP_SPAWN_RAW_MODE 0 81 | 82 | /* Close the handle. */ 83 | extern int mexp_close (mexp_h *h); 84 | 85 | /* Expect. */ 86 | struct mexp_regexp { 87 | int r; 88 | const pcre2_code *re; 89 | int options; 90 | }; 91 | typedef struct mexp_regexp mexp_regexp; 92 | 93 | enum mexp_status { 94 | MEXP_EOF = 0, 95 | MEXP_ERROR = -1, 96 | MEXP_PCRE_ERROR = -2, 97 | MEXP_TIMEOUT = -3, 98 | }; 99 | 100 | extern int mexp_expect (mexp_h *h, const mexp_regexp *regexps, 101 | pcre2_match_data *match_data); 102 | 103 | /* Sending commands, keypresses. */ 104 | extern int mexp_printf (mexp_h *h, const char *fs, ...) 105 | __attribute__((format(printf,2,3))); 106 | extern int mexp_printf_password (mexp_h *h, const char *fs, ...) 107 | __attribute__((format(printf,2,3))); 108 | extern int mexp_send_interrupt (mexp_h *h); 109 | 110 | #endif /* MINIEXPECT_H_ */ 111 | -------------------------------------------------------------------------------- /p2v.h: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2009-2019 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #ifndef P2V_H 19 | #define P2V_H 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | /* Send various debug information to stderr. Harmless and useful, so 27 | * can be left enabled in production builds. 28 | */ 29 | #define DEBUG_STDERR 1 30 | 31 | #include "miniexpect.h" 32 | #include "p2v-config.h" 33 | 34 | #include "guestfs-utils.h" 35 | 36 | #if defined(__GNUC__) && !defined(__clang__) 37 | # define P2V_GCC_VERSION \ 38 | (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 39 | #else 40 | # define P2V_GCC_VERSION 0 41 | #endif 42 | 43 | /* All network interfaces discovered when the program started. Do not change 44 | * this. 45 | */ 46 | extern char **all_interfaces; 47 | 48 | /* True if running inside the virt-p2v ISO environment. Various 49 | * dangerous functions such as the "Reboot" button are disabled if 50 | * this is false. 51 | */ 52 | extern int is_iso_environment; 53 | 54 | /* True if virt-v2v supports the --colours option. */ 55 | extern int feature_colours_option; 56 | 57 | /* virt-p2v --colours option (used by ansi_* macros). */ 58 | extern int force_colour; 59 | 60 | /* cpuid.c */ 61 | struct cpu_topo { 62 | unsigned sockets; 63 | unsigned cores; 64 | unsigned threads; 65 | }; 66 | extern void get_cpu_topology (struct cpu_topo *topo); 67 | extern void get_cpu_config (struct cpu_config *); 68 | 69 | /* disks.c */ 70 | extern void find_all_disks (char ***disks, char ***removable); 71 | 72 | /* rtc.c */ 73 | extern void get_rtc_config (struct rtc_config *); 74 | 75 | /* kernel-cmdline.c */ 76 | extern char **parse_cmdline_string (const char *cmdline); 77 | extern char **parse_proc_cmdline (void); 78 | extern const char *get_cmdline_key (char **cmdline, const char *key); 79 | 80 | #define CMDLINE_SOURCE_COMMAND_LINE 1 /* --cmdline */ 81 | #define CMDLINE_SOURCE_PROC_CMDLINE 2 /* /proc/cmdline */ 82 | 83 | /* kernel-config.c */ 84 | extern void update_config_from_kernel_cmdline (struct config *config, char **cmdline); 85 | 86 | /* kernel.c */ 87 | extern void kernel_conversion (struct config *, char **cmdline, int cmdline_source); 88 | 89 | /* gui.c */ 90 | extern void gui_conversion (struct config *config, 91 | const char * const *disks, 92 | const char * const *removable); 93 | 94 | /* conversion.c */ 95 | struct data_conn { /* Data per NBD connection / physical disk. */ 96 | mexp_h *h; /* miniexpect handle to ssh */ 97 | pid_t nbd_pid; /* NBD server PID */ 98 | int nbd_remote_port; /* remote NBD port on conversion server */ 99 | }; 100 | 101 | extern int start_conversion (struct config *, void (*notify_ui) (int type, const char *data)); 102 | #define NOTIFY_LOG_DIR 1 /* location of remote log directory */ 103 | #define NOTIFY_REMOTE_MESSAGE 2 /* log message from remote virt-v2v */ 104 | #define NOTIFY_STATUS 3 /* stage in conversion process */ 105 | extern const char *get_conversion_error (void); 106 | extern void cancel_conversion (void); 107 | extern int conversion_is_running (void); 108 | 109 | /* physical-xml.c */ 110 | extern void generate_physical_xml (struct config *, struct data_conn *, const char *filename); 111 | 112 | /* inhibit.c */ 113 | extern int inhibit_power_saving (void); 114 | 115 | /* ssh.c */ 116 | extern int test_connection (struct config *); 117 | extern mexp_h *open_data_connection (struct config *, int local_port, int *remote_port); 118 | extern mexp_h *start_remote_connection (struct config *, const char *remote_dir); 119 | extern const char *get_ssh_error (void); 120 | extern int scp_file (struct config *config, const char *target, const char *local, ...) __attribute__((sentinel)); 121 | 122 | /* nbd.c */ 123 | extern void test_nbd_server (void); 124 | extern pid_t start_nbd_server (int *port, const char *device); 125 | const char *get_nbd_error (void); 126 | 127 | /* utils.c */ 128 | extern uint64_t get_blockdev_size (const char *dev); 129 | extern char *get_blockdev_model (const char *dev); 130 | extern char *get_blockdev_serial (const char *dev); 131 | extern char *get_if_addr (const char *if_name); 132 | extern char *get_if_vendor (const char *if_name, int truncate); 133 | extern void wait_network_online (const struct config *); 134 | extern int compare_strings (const void *vp1, const void *vp2); 135 | 136 | /* virt-v2v version and features (read from remote). */ 137 | extern char *v2v_version; 138 | 139 | /* input and output drivers (read from remote). */ 140 | extern char **input_drivers; 141 | extern char **output_drivers; 142 | 143 | /* about-authors.c */ 144 | extern const char *authors[]; 145 | extern const char *qa[]; 146 | extern const char *documenters[]; 147 | extern const char *others[]; 148 | 149 | #endif /* P2V_H */ 150 | -------------------------------------------------------------------------------- /p2v.ks.in: -------------------------------------------------------------------------------- 1 | # Kickstart file for creating the virt-p2v ISO. 2 | # (C) Copyright 2014-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # Generated by virt-p2v-make-kickstart __PACKAGE_VERSION_FULL__ 18 | 19 | lang en_US.UTF-8 20 | keyboard us 21 | timezone --utc GMT 22 | 23 | rootpw --plaintext p2v 24 | 25 | selinux --enforcing 26 | firewall --enabled 27 | 28 | # Make sure that systemd doesn't rename the network device. We have 29 | # to tell Anaconda we're using eth0, *and* we have to pass 30 | # net.ifnames=0 on the kernel command line. 31 | network --bootproto=dhcp --device=eth0 32 | bootloader --location=mbr --append="console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH net.ifnames=0" 33 | 34 | zerombr 35 | clearpart --all --initlabel 36 | part / --size 3000 --fstype ext4 37 | 38 | reboot 39 | 40 | # Repository lines: 41 | __REPOS__ 42 | 43 | # Packages to install in the ISO. For dependencies, see 44 | # p2v/Makefile.am. Note that libguestfs is NOT required by virt-p2v. 45 | 46 | %packages __PACKAGES_OPTIONS__ 47 | 48 | @core 49 | 50 | # rpm must be installed, else you'll hit RHBZ#1089566. 51 | rpm 52 | 53 | # Note you must have a kernel, else the boot menu won't work: 54 | kernel 55 | 56 | # This is required in order for RHEL to set the root password. 57 | passwd 58 | 59 | # RHEL needs this in order to get networking. 60 | NetworkManager 61 | 62 | # Required to run firewall --enabled kickstart command: 63 | firewalld 64 | 65 | # Needed by post script to unpack the blobs. 66 | /usr/bin/base64 67 | /usr/bin/gzip 68 | 69 | # Work around https://bugzilla.redhat.com/show_bug.cgi?id=1182362 70 | tar 71 | 72 | # https://bugzilla.redhat.com/show_bug.cgi?id=1168223 73 | dracut-live 74 | 75 | # The dependencies of virt-p2v. 76 | __DEPENDENCIES__ 77 | 78 | # Extra packages requested by the user via the virt-p2v-make-kickstart 79 | # --install option (if any). 80 | __EXTRA_PACKAGES__ 81 | 82 | %end 83 | 84 | # Post-install configuration. 85 | 86 | %post 87 | 88 | # Base64-decoding of SSH Identity. 89 | 90 | base64 -d -i > /var/tmp/id_rsa << EOF 91 | __BASE64_SSH_IDENTITY__ 92 | EOF 93 | if test -s /var/tmp/id_rsa; then 94 | chmod 0600 /var/tmp/id_rsa 95 | else 96 | rm /var/tmp/id_rsa 97 | fi 98 | 99 | # Base64-decoding of /etc/issue 100 | 101 | base64 -d -i > /etc/issue << EOF 102 | __BASE64_ISSUE__ 103 | EOF 104 | 105 | cp /etc/issue /etc/issue.net 106 | 107 | # Base64-decoding of launch-virt-p2v 108 | 109 | base64 -d -i > /usr/bin/launch-virt-p2v < /etc/systemd/system/p2v.service < /usr/bin/virt-p2v 125 | __BASE64_VIRT_P2V__ 126 | EOF 127 | 128 | chmod 0755 /usr/bin/virt-p2v 129 | 130 | # Update the default getty target to login automatically as root without 131 | # prompting for a password 132 | sed -i 's/^ExecStart=\(.*\)/ExecStart=\1 -a root/' \ 133 | /usr/lib/systemd/system/getty@.service 134 | 135 | # Reserve tty1 as a getty so we can document it clearly 136 | echo ReserveVT=1 >> /etc/systemd/logind.conf 137 | 138 | # Force text mode 139 | systemctl set-default multi-user.target 140 | 141 | # Start p2v service 142 | systemctl enable p2v.service 143 | 144 | # Disable ssh service (RHBZ#1248678) 145 | systemctl disable sshd.service 146 | 147 | %end 148 | 149 | %post --nochroot 150 | 151 | PRODUCT='Virt P2V' 152 | PRODUCT_SHORT='virt-p2v' 153 | PACKAGE='__PACKAGE_NAME__' 154 | VERSION='__PACKAGE_VERSION__' 155 | 156 | echo "Customizing boot menu" 157 | sed -i -e ' 158 | # Put product information at the top of the file 159 | 1 { 160 | i '"say $PRODUCT $VERSION"' 161 | i '"menu title $PRODUCT_SHORT $VERSION"' 162 | } 163 | 164 | # Remove any existing menu title 165 | /^menu title .*/d 166 | 167 | # Set the default timeout to 60 seconds 168 | s/^timeout .*/timeout 600/ 169 | ' $LIVE_ROOT/isolinux/isolinux.cfg 170 | 171 | # store image version info in the ISO 172 | cat > $LIVE_ROOT/isolinux/version < $INSTALL_ROOT/etc/$PACKAGE-release <. 16 | 17 | # NB: This cannot be called "virt-p2v.service" because on Fedora the 18 | # virt- prefix will cause it to get the wrong SELinux label. 19 | 20 | [Unit] 21 | Description=p2v service 22 | # For the GUI, we cannot necessarily wait for the network to come 23 | # online, since that may require the "Configure Network" dialog. For 24 | # the command line, we would like the network to be online, but we 25 | # test that within virt-p2v itself. Therefore use network.target 26 | # here, not network-online.target. 27 | After=network.target 28 | 29 | [Service] 30 | Type=oneshot 31 | ExecStart=/usr/bin/launch-virt-p2v 32 | RemainAfterExit=yes 33 | StandardOutput=journal+console 34 | StandardError=inherit 35 | 36 | [Install] 37 | WantedBy=multi-user.target 38 | -------------------------------------------------------------------------------- /podcheck.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # podcheck.pl 3 | # Copyright (C) 2016 Red Hat Inc. 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | use warnings; 19 | use strict; 20 | 21 | use Pod::Usage; 22 | use Getopt::Long; 23 | use Pod::Man; 24 | 25 | =head1 NAME 26 | 27 | podcheck.pl - Compare man page and tools to check all arguments are documented 28 | 29 | =head1 SYNOPSIS 30 | 31 | podcheck.pl virt-foo.pod ./virt-foo [--ignore=--arg,--arg,...] 32 | 33 | =head1 DESCRIPTION 34 | 35 | This script compares a manual page (eg. C) and the 36 | corresponding tool (eg. C<./virt-foo>) and checks that each command 37 | line argument is documented in the manual, and that there is no rogue 38 | documentation for arguments which do not exist. It works by running 39 | the tool with the standard C<--long-options> and C<--short-options> 40 | parameters and comparing their output with the man page. 41 | 42 | You can also ignore options, in case this script gets things wrong or 43 | if there are options that you don't intend to document. 44 | 45 | =head1 OPTIONS 46 | 47 | =over 4 48 | 49 | =cut 50 | 51 | my $help; 52 | 53 | =item B<--help> 54 | 55 | Display brief help. 56 | 57 | =cut 58 | 59 | my $ignore = ""; 60 | 61 | =item B<--ignore=--arg,--arg,...> 62 | 63 | Ignore the comma-separated list of arguments given. 64 | 65 | =cut 66 | 67 | my @inserts; 68 | 69 | =item B<--insert filename:__PATTERN__> 70 | 71 | This works like the L I<--insert> option and should be 72 | used where the POD includes patterns which podwrapper would substitute. 73 | 74 | =cut 75 | 76 | my @verbatims; 77 | 78 | =item B<--verbatim filename:__PATTERN__> 79 | 80 | This works like the podwrapper I<--verbatim> option and should be 81 | used where the POD includes patterns which podwrapper would substitute. 82 | 83 | =cut 84 | 85 | # Clean up the program name. 86 | my $progname = $0; 87 | $progname =~ s{.*/}{}; 88 | 89 | # Parse options. 90 | GetOptions ("help|?" => \$help, 91 | "ignore=s" => \$ignore, 92 | "insert=s" => \@inserts, 93 | "verbatim=s" => \@verbatims, 94 | ) or pod2usage (2); 95 | pod2usage (1) if $help; 96 | 97 | die "$progname: missing argument: podcheck.pl input.pod tool\n" 98 | unless @ARGV == 2; 99 | my $input = $ARGV[0]; 100 | my $tool = $ARGV[1]; 101 | 102 | my %ignore = (); 103 | $ignore{$_} = 1 foreach (split /,/, $ignore); 104 | 105 | # Open the man page and slurp it in. 106 | my $content = read_whole_file ($input); 107 | 108 | # Perform @inserts. 109 | foreach (@inserts) { 110 | my @a = split /:/, $_, 2; 111 | die "$progname: $input: no colon in parameter of --insert\n" unless @a >= 2; 112 | my $replacement = read_whole_file ($a[0]); 113 | my $oldcontent = $content; 114 | $content =~ s/$a[1]/$replacement/ge; 115 | die "$progname: $input: could not find pattern '$a[1]' in input file\n" 116 | if $content eq $oldcontent; 117 | } 118 | 119 | # Perform @verbatims. 120 | foreach (@verbatims) { 121 | my @a = split /:/, $_, 2; 122 | die "$progname: $input: no colon in parameter of --verbatim\n" unless @a >= 2; 123 | my $replacement = read_verbatim_file ($a[0]); 124 | my $oldcontent = $content; 125 | $content =~ s/$a[1]/$replacement/ge; 126 | die "$progname: $input: could not find pattern '$a[1]' in input file\n" 127 | if $content eq $oldcontent; 128 | } 129 | 130 | # Run the tool with --long-options and --short-options. 131 | my @tool_options = (); 132 | open PIPE, "$tool --long-options |" 133 | or die "$progname: $tool --long-options: $!"; 134 | while () { 135 | chomp; 136 | push @tool_options, $_; 137 | } 138 | close PIPE; 139 | open PIPE, "$tool --short-options |" 140 | or die "$progname: $tool --short-options: $!"; 141 | while () { 142 | chomp; 143 | push @tool_options, $_; 144 | } 145 | close PIPE; 146 | 147 | my %tool_option_exists = (); 148 | $tool_option_exists{$_} = 1 foreach @tool_options; 149 | 150 | # There are some tool options which we automatically ignore. 151 | delete $tool_option_exists{"--color"}; 152 | delete $tool_option_exists{"--colour"}; 153 | delete $tool_option_exists{"--debug-gc"}; 154 | 155 | # Run the tool with --help. 156 | my $help_content; 157 | open PIPE, "LANG=C $tool --help |" 158 | or die "$progname: $tool --help: $!"; 159 | { 160 | local $/ = undef; 161 | $help_content = ; 162 | } 163 | close PIPE; 164 | 165 | # Do the tests. 166 | my $errors = 0; 167 | 168 | # Check each option exists in the manual. 169 | my $tool_options_checked = 0; 170 | 171 | foreach (sort keys %tool_option_exists) { 172 | unless ($ignore{$_}) { 173 | $tool_options_checked++; 174 | unless ($content =~ /^=item.*B<$_(?:=.*)?>/m) { 175 | $errors++; 176 | warn "$progname: $input does not define $_\n"; 177 | } 178 | } 179 | } 180 | 181 | # Check there are no extra options defined in the manual which 182 | # don't exist in the tool. 183 | my $pod_options_checked = 0; 184 | 185 | my %pod_options = (); 186 | $pod_options{$_} = 1 foreach ( $content =~ /^=item.*B<(-[-\w]+)(?:=.*)?>/gm ); 187 | foreach (sort keys %pod_options) { 188 | unless ($ignore{$_}) { 189 | $pod_options_checked++; 190 | unless (exists $tool_option_exists{$_}) { 191 | $errors++; 192 | warn "$progname: $input defines option $_ which does not exist in the tool\n" 193 | } 194 | } 195 | } 196 | 197 | # Check the tool's --help output mentions all the options. (For OCaml 198 | # tools this is a waste of time since the --help output is generated, 199 | # but for C tools it is a genuine test). 200 | my $help_options_checked = 0; 201 | 202 | my %help_options = (); 203 | $help_options{$_} = 1 foreach ( $help_content =~ /(? 0; 232 | 233 | printf "$progname: $tool: checked $tool_options_checked tool options, $pod_options_checked documented options, $help_options_checked help options\n"; 234 | 235 | exit 0; 236 | 237 | sub read_whole_file 238 | { 239 | my $input = shift; 240 | local $/ = undef; 241 | 242 | open FILE, $input or die "$progname: $input: $!"; 243 | $_ = ; 244 | close FILE; 245 | $_; 246 | } 247 | 248 | sub read_verbatim_file 249 | { 250 | my $input = shift; 251 | my $r = ""; 252 | 253 | open FILE, $input or die "$progname: $input: $!"; 254 | while () { 255 | $r .= " $_"; 256 | } 257 | close FILE; 258 | $r; 259 | } 260 | 261 | =head1 SEE ALSO 262 | 263 | L, 264 | libguestfs.git/README. 265 | 266 | =head1 AUTHOR 267 | 268 | Richard W.M. Jones. 269 | 270 | =head1 COPYRIGHT 271 | 272 | Copyright (C) 2016 Red Hat Inc. 273 | -------------------------------------------------------------------------------- /rtc.c: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2017 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /** 19 | * Try to calculate Real Time Clock (RTC) offset from UTC in seconds. 20 | * For example if the RTC is 1 hour ahead of UTC, this will return 21 | * C<3600>. This is stored in Crtc_offset>. 22 | */ 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #ifdef HAVE_LINUX_RTC_H 38 | #include 39 | #endif 40 | 41 | #include "ignore-value.h" 42 | 43 | #include "p2v.h" 44 | 45 | #ifndef HAVE_LINUX_RTC_H 46 | void 47 | get_rtc_config (struct rtc_config *rtc) 48 | { 49 | fprintf (stderr, "%s: RTC: compiled without support for /dev/rtc\n", 50 | g_get_prgname ()); 51 | 52 | rtc->offset = 0; 53 | rtc->basis = BASIS_UTC; 54 | } 55 | 56 | #else /* HAVE_LINUX_RTC_H */ 57 | 58 | /** 59 | * Return RTC offset from UTC in seconds, positive numbers meaning 60 | * that the RTC is running ahead of UTC. 61 | * 62 | * In the error case, Coffset> is updated with 0 and 63 | * Cbasis> is set to C. 64 | */ 65 | void 66 | get_rtc_config (struct rtc_config *rtc) 67 | { 68 | int fd; 69 | struct rtc_time rtm; 70 | struct tm tm; 71 | time_t rtc_time; 72 | time_t system_time; 73 | double rf; 74 | 75 | rtc->basis = BASIS_UNKNOWN; 76 | rtc->offset = 0; 77 | 78 | fd = open ("/dev/rtc", O_RDONLY); 79 | if (fd == -1) { 80 | perror ("/dev/rtc"); 81 | return; 82 | } 83 | 84 | if (ioctl (fd, RTC_RD_TIME, &rtm) == -1) { 85 | perror ("ioctl: RTC_RD_TIME"); 86 | close (fd); 87 | return; 88 | } 89 | 90 | close (fd); 91 | 92 | #ifdef DEBUG_STDERR 93 | fprintf (stderr, "%s: RTC: %04d-%02d-%02d %02d:%02d:%02d\n", 94 | g_get_prgname (), 95 | rtm.tm_year + 1900, rtm.tm_mon + 1, rtm.tm_mday, 96 | rtm.tm_hour, rtm.tm_min, rtm.tm_sec); 97 | #endif 98 | 99 | /* Convert this to seconds since the epoch. */ 100 | tm.tm_sec = rtm.tm_sec; 101 | tm.tm_min = rtm.tm_min; 102 | tm.tm_hour = rtm.tm_hour; 103 | tm.tm_mday = rtm.tm_mday; 104 | tm.tm_mon = rtm.tm_mon; 105 | tm.tm_year = rtm.tm_year; 106 | tm.tm_isdst = 0; /* Ignore DST when calculating. */ 107 | rtc_time = timegm (&tm); 108 | if (rtc_time == -1) 109 | return; /* Not representable as a Unix time. */ 110 | 111 | /* Get system time in UTC. */ 112 | system_time = time (NULL); 113 | 114 | /* Calculate the difference, rounded to the nearest 15 minutes. */ 115 | rf = rtc_time - system_time; 116 | 117 | #ifdef DEBUG_STDERR 118 | fprintf (stderr, "%s: RTC: %ld system time: %ld difference: %g\n", 119 | g_get_prgname (), 120 | (long) rtc_time, (long) system_time, rf); 121 | #endif 122 | 123 | rf /= 15*60; 124 | rf = round (rf); 125 | rf *= 15*60; 126 | 127 | /* If it's obviously out of range then print an error and return. */ 128 | if (rf < -12*60*60 || rf > 14*60*60) { 129 | fprintf (stderr, 130 | "%s: RTC: offset of RTC from UTC is out of range (%g).\n", 131 | g_get_prgname (), rf); 132 | return; 133 | } 134 | 135 | rtc->offset = (int) rf; 136 | 137 | #ifdef DEBUG_STDERR 138 | fprintf (stderr, "%s: RTC: offset of RTC from UTC = %d secs\n", 139 | g_get_prgname (), rtc->offset); 140 | #endif 141 | 142 | /* Is the hardware clock set to localtime? 143 | * 144 | * Unfortunately it's not possible to distinguish between UTC and 145 | * localtime in timezones that lie along the Greenwich Meridian 146 | * (obviously including the UK), when daylight savings time is not 147 | * in effect. In that case, prefer UTC. 148 | */ 149 | localtime_r (&system_time, &tm); 150 | if (tm.tm_gmtoff != 0 && tm.tm_gmtoff != rtc->offset) 151 | rtc->basis = BASIS_UTC; 152 | else { 153 | rtc->basis = BASIS_LOCALTIME; 154 | rtc->offset = 0; 155 | #ifdef DEBUG_STDERR 156 | fprintf (stderr, "%s: RTC time is localtime\n", g_get_prgname ()); 157 | #endif 158 | } 159 | 160 | return; 161 | } 162 | 163 | #endif /* HAVE_LINUX_RTC_H */ 164 | -------------------------------------------------------------------------------- /run.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # libguestfs 'run' programs locally script 3 | # Copyright (C) 2011-2019 Red Hat Inc. 4 | # 5 | # @configure_input@ 6 | # 7 | # This library is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Lesser General Public 9 | # License as published by the Free Software Foundation; either 10 | # version 2 of the License, or (at your option) any later version. 11 | # 12 | # This library is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with this program. If not, see . 19 | 20 | #---------------------------------------------------------------------- 21 | 22 | # With this script you can run all the virt tools without needing to 23 | # install them first. You just have to do for example: 24 | # 25 | # ./run virt-inspector [args ...] 26 | # 27 | # This works for any C program, virt tools, and most non-C bindings 28 | # and programs in the libguestfs distribution. 29 | # 30 | # For lots more ways to use this script, see the libguestfs 31 | # p2v-building(1) man page. 32 | # 33 | # The script should also be used for tests like this: 34 | # 35 | # TESTS_ENVIRONMENT = ... $(top_builddir)/run --test 36 | # 37 | # The --test parameter introduces a timeout, stopping tests from 38 | # running forever. 39 | 40 | #---------------------------------------------------------------------- 41 | 42 | if [ "$1" = "--test" ]; then 43 | timeout_mode=1 44 | shift 45 | fi 46 | 47 | # Function to intelligently prepend a path to an environment variable. 48 | # See http://stackoverflow.com/a/9631350 49 | prepend() 50 | { 51 | eval $1="$2\${$1:+:\$$1}" 52 | } 53 | 54 | # Source and build directories (absolute paths so this works from any 55 | # directory). 56 | s="$(cd @abs_srcdir@ && pwd)" 57 | b="$(cd @abs_builddir@ && pwd)" 58 | 59 | prepend PATH "$b" 60 | export PATH 61 | 62 | # virt-p2v-make-* data directory. 63 | if [ -z "$VIRT_P2V_DATA_DIR" ]; then 64 | VIRT_P2V_DATA_DIR="$s" 65 | export VIRT_P2V_DATA_DIR 66 | fi 67 | 68 | # This is a cheap way to find some use-after-free and uninitialized 69 | # read problems when using glibc. But if we are valgrinding then 70 | # don't use this because it can stop valgrind from working. 71 | if [ -z "$VG" ]; then 72 | random_val="$(@AWK@ 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)" 73 | LD_PRELOAD="${LD_PRELOAD:+"$LD_PRELOAD:"}libc_malloc_debug.so.0" 74 | GLIBC_TUNABLES=glibc.malloc.check=1:glibc.malloc.perturb=$random_val 75 | export LD_PRELOAD GLIBC_TUNABLES 76 | fi 77 | 78 | # Avoid GNOME keyring stupidity 79 | export GNOME_KEYRING_CONTROL= 80 | export GNOME_KEYRING_PID= 81 | 82 | # Run the program. 83 | if [ -z "$timeout_mode" ]; then 84 | exec "$@" 85 | fi 86 | 87 | # For tests (./run --test): 88 | # - timeout if the test takes too long to run 89 | 90 | # Originally 1h, but that is not long enough to run the C API 91 | # tests on Koji. 92 | timeout_period=4h 93 | timeout_kill=30s 94 | 95 | # Must use the --foreground option (RHBZ#1025269). 96 | if timeout --foreground 2 sleep 0 >/dev/null 2>&1; then 97 | # Does this version of timeout have the -k option? (Not on RHEL 6) 98 | if timeout -k 10s 10s true >/dev/null 2>&1; then 99 | timeout="timeout --foreground -k $timeout_kill $timeout_period" 100 | fi 101 | fi 102 | 103 | $timeout "$@" 104 | fail=$? 105 | if [ "$fail" -eq 0 ]; then 106 | # Test successful. 107 | : 108 | elif [ "$fail" -eq 77 ]; then 109 | # Tests return 77 to mean skipped. 110 | : 111 | elif [ "$fail" -eq 124 ]; then 112 | # Timed out. 113 | echo "$b/run: command timed out after $timeout_period" 114 | else 115 | # Test failed. 116 | echo "$b/run: command failed with exit code $fail" 117 | fi 118 | exit $fail 119 | -------------------------------------------------------------------------------- /subdir-rules.mk: -------------------------------------------------------------------------------- 1 | # libguestfs 2 | # Copyright (C) 2013 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # subdir-rules.mk should be included in every *subdirectory* Makefile.am. 18 | 19 | # Editor backup files 20 | CLEANFILES = *~ *.bak 21 | 22 | # Patch original and reject files. 23 | CLEANFILES += *.orig *.rej 24 | 25 | # Manual pages - these are all generated from *.pod, so the 26 | # pages themselves should all be removed by 'make clean'. 27 | CLEANFILES += *.1 *.3 *.5 *.8 28 | 29 | # Stamp files used when generating man pages. 30 | CLEANFILES += stamp-*.pod 31 | 32 | # Files that should be universally removed by 'make distclean'. 33 | DISTCLEANFILES = stamp-* 34 | 35 | # custom silent rules 36 | guestfs_am_v_podwrapper = $(guestfs_am_v_podwrapper_@AM_V@) 37 | guestfs_am_v_podwrapper_ = $(guestfs_am_v_podwrapper_@AM_DEFAULT_V@) 38 | guestfs_am_v_podwrapper_0 = @echo " POD " $@; 39 | 40 | # Test shell scripts should use '$TEST_FUNCTIONS' to get a predefined 41 | # set of helper functions for running tests (see 42 | # tests/test-functions.sh). 43 | # 44 | # Notes: 45 | # 46 | # (1) This is in fact a single command all on one line. The variables 47 | # are evaluated in test-functions.sh. 48 | # 49 | # (2) We use absolute paths here and in test-functions.sh so that the 50 | # test can change directory freely. But we also include the 51 | # non-absolute values so they can be used by the test script itself. 52 | export TEST_FUNCTIONS := \ 53 | source $(abs_top_srcdir)/test-functions.sh \ 54 | abs_srcdir="$(abs_srcdir)" \ 55 | abs_builddir="$(abs_builddir)" \ 56 | top_srcdir="$(top_srcdir)" \ 57 | top_builddir="$(top_builddir)" \ 58 | abs_top_srcdir="$(abs_top_srcdir)" \ 59 | abs_top_builddir="$(abs_top_builddir)" 60 | -------------------------------------------------------------------------------- /test-functions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # libguestfs 3 | # Copyright (C) 2014-2019 Red Hat Inc. 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # Most of the tests written in shell script source this file for 19 | # useful functions. 20 | # 21 | # To include this file, the test must do: 22 | # 23 | # $TEST_FUNCTIONS 24 | # 25 | # (this macro is defined in subdir-rules.mk). 26 | 27 | # Clean up the environment in every test script. 28 | unset CDPATH 29 | export LANG=C 30 | 31 | # When test-functions.sh is invoked, a list of variables is passed as 32 | # parameters, so we eval those to define the variables. 33 | while [ $# -ge 1 ]; do eval "$1"; shift; done 34 | 35 | # Skip if $SKIP_ environment variable is set. 36 | # Every test should call this function first. 37 | skip_if_skipped () 38 | { 39 | local v 40 | if [ -n "$1" ]; then 41 | v="SKIP_$(basename $1 | tr a-z.- A-Z__)" 42 | else 43 | v="SKIP_$(basename $0 | tr a-z.- A-Z__)" 44 | fi 45 | if [ -n "${!v}" ]; then 46 | echo "$(basename $0): test skipped because \$$v is set" 47 | exit 77 48 | fi 49 | echo "$(basename $0): info: you can skip this test by setting $v=1" 50 | } 51 | 52 | # Skip if the current libguestfs backend is $1. 53 | # eg. skip_if_backend uml 54 | skip_if_backend () 55 | { 56 | local b="$(guestfish get-backend)" 57 | case "$1" in 58 | # Some magic happens for $1 == libvirt. 59 | libvirt) 60 | if [ "$b" = "libvirt" ] || [[ "$b" =~ ^libvirt: ]]; then 61 | echo "$(basename $0): test skipped because the current backend is $b" 62 | exit 77 63 | fi 64 | ;; 65 | *) 66 | if [ "$b" = "$1" ]; then 67 | echo "$(basename $0): test skipped because the current backend is $b" 68 | exit 77 69 | fi 70 | ;; 71 | esac 72 | } 73 | 74 | # Skip if the current arch != $1. 75 | skip_unless_arch () 76 | { 77 | local m="$(uname -m)" 78 | case "$1" in 79 | # Some magic happens for some architectures. 80 | arm) 81 | if [[ ! "$m" =~ ^arm ]]; then 82 | echo "$(basename $0): test skipped because the current architecture ($m) is not arm (32 bit)" 83 | exit 77 84 | fi 85 | ;; 86 | i?86) 87 | if [[ ! "$m" =~ ^i?86 ]]; then 88 | echo "$(basename $0): test skipped because the current architecture ($m) is not $1" 89 | exit 77 90 | fi 91 | ;; 92 | *) 93 | if [ "$m" != "$1" ]; then 94 | echo "$(basename $0): test skipped because the current architecture ($m) is not $1" 95 | exit 77 96 | fi 97 | ;; 98 | esac 99 | } 100 | 101 | # Run an external command and skip if the command fails. This can be 102 | # used to test if a command exists. Normally you should use 103 | # `cmd --help' or `cmd --version' or similar. 104 | skip_unless () 105 | { 106 | if ! "$@"; then 107 | echo "$(basename $0): test skipped because $1 is not available" 108 | exit 77 109 | fi 110 | } 111 | 112 | # Slow tests should always call this function. (See p2v-hacking(1)). 113 | slow_test () 114 | { 115 | if [ -z "$SLOW" ]; then 116 | echo "$(basename $0): use 'make check-slow' to run this test" 117 | exit 77 118 | fi 119 | } 120 | -------------------------------------------------------------------------------- /test-virt-p2v-cmdline.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # libguestfs virt-p2v test script 3 | # Copyright (C) 2015 Red Hat Inc. 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # Test virt-p2v command line parsing in non-GUI mode. 19 | 20 | set -e 21 | 22 | $TEST_FUNCTIONS 23 | skip_if_skipped 24 | 25 | out=test-virt-p2v-cmdline.out 26 | rm -f $out 27 | 28 | # The Linux kernel command line. 29 | P2V_OPTS=( 30 | p2v.server=localhost 31 | p2v.port=123 32 | p2v.username=user 33 | p2v.password=secret 34 | p2v.skip_test_connection 35 | p2v.name=test 36 | p2v.vcpu.cores=4 37 | p2v.memory=1G 38 | p2v.disks=sda,sdb,sdc 39 | p2v.removable=sdd 40 | p2v.interfaces=eth0,eth1 41 | p2v.o=local 42 | p2v.oa=sparse 43 | p2v.oc=qemu:///session 44 | p2v.of=raw 45 | p2v.os=/var/tmp 46 | p2v.oo=opt1=val1,opt2=val2 47 | p2v.network=em1:wired,other 48 | p2v.dump_config_and_exit 49 | ) 50 | $VG virt-p2v --cmdline="${P2V_OPTS[*]}" > $out 51 | 52 | # For debugging purposes. 53 | cat $out 54 | 55 | # Check the output contains what we expect. 56 | grep "^remote\.server.*localhost" $out 57 | grep "^remote\.port.*123" $out 58 | grep "^auth\.username.*user" $out 59 | grep "^auth\.sudo.*false" $out 60 | grep "^guestname.*test" $out 61 | grep "^vcpu.phys_topo.*false" $out 62 | grep "^vcpu.cores.*4" $out 63 | grep "^memory.*"$((1024*1024*1024)) $out 64 | grep "^disks.*sda sdb sdc" $out 65 | grep "^removable.*sdd" $out 66 | grep "^interfaces.*eth0 eth1" $out 67 | grep "^network_map.*em1:wired other" $out 68 | grep "^output\.type.*local" $out 69 | grep "^output\.allocation.*sparse" $out 70 | grep "^output\.connection.*qemu:///session" $out 71 | grep "^output\.format.*raw" $out 72 | grep "^output\.storage.*/var/tmp" $out 73 | grep "^output\.misc.*opt1=val1 opt2=val2" $out 74 | 75 | rm $out 76 | -------------------------------------------------------------------------------- /test-virt-p2v-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # libguestfs 3 | # Copyright (C) 2016 Red Hat Inc. 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | set -e 19 | 20 | $TEST_FUNCTIONS 21 | skip_if_skipped 22 | 23 | $top_srcdir/podcheck.pl $srcdir/virt-p2v.pod virt-p2v 24 | -------------------------------------------------------------------------------- /test-virt-p2v-nbdkit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # libguestfs virt-p2v test script 3 | # Copyright (C) 2014-2019 Red Hat Inc. 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # Test virt-p2v in non-GUI mode. 19 | 20 | set -e 21 | 22 | $TEST_FUNCTIONS 23 | skip_if_skipped 24 | skip_if_backend uml 25 | skip_unless nbdkit file --version 26 | skip_unless test -f fedora.img 27 | skip_unless test -f blank-part.img 28 | 29 | f1="$abs_builddir/fedora.img" 30 | f2="$abs_builddir/blank-part.img" 31 | 32 | d=test-virt-p2v-nbdkit.d 33 | rm -rf $d 34 | mkdir $d 35 | 36 | # We don't want the program under test to run real 'ssh' or 'scp'. 37 | # They won't work. Therefore create dummy 'ssh' and 'scp' binaries. 38 | pushd $d 39 | ln -sf "$abs_srcdir/test-virt-p2v-ssh.sh" ssh 40 | ln -sf "$abs_srcdir/test-virt-p2v-scp.sh" scp 41 | popd 42 | export PATH=$d:$PATH 43 | 44 | # Note that the PATH already contains the local virt-p2v & virt-v2v 45 | # binaries under test (because of the ./run script). 46 | 47 | # The Linux kernel command line. 48 | cmdline="p2v.server=localhost p2v.name=fedora p2v.disks=$f1,$f2 p2v.o=local p2v.os=$(pwd)/$d p2v.network=em1:wired,other p2v.post=" 49 | 50 | $VG virt-p2v --cmdline="$cmdline" 51 | 52 | # Test the libvirt XML metadata and a disk was created. 53 | test -f $d/fedora.xml 54 | test -f $d/fedora-sda 55 | test -f $d/fedora-sdb 56 | 57 | rm -r $d 58 | -------------------------------------------------------------------------------- /test-virt-p2v-pxe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # libguestfs virt-p2v test script 3 | # Copyright (C) 2014-2019 Red Hat Inc. 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # Test virt-p2v in non-GUI mode with something resembling the 19 | # PXE boot code path. This tests: 20 | # * virt-p2v-make-disk 21 | # * systemd p2v.service 22 | # * launch-virt-p2v 23 | # * networking 24 | # * virt-p2v in kernel command-line mode 25 | 26 | set -e 27 | 28 | $TEST_FUNCTIONS 29 | slow_test 30 | skip_if_skipped 31 | skip_if_backend uml 32 | skip_unless_arch x86_64 33 | 34 | qemu=qemu-system-x86_64 35 | skip_unless $qemu -help 36 | 37 | img="test-virt-p2v-pxe.img" 38 | if ! test -f $img; then 39 | echo "$0: test skipped because $img was not created" 40 | exit 77 41 | fi 42 | 43 | skip_unless test -f fedora.img 44 | f="$abs_builddir/fedora.img" 45 | 46 | d=test-virt-p2v-pxe.d 47 | rm -rf $d 48 | mkdir $d 49 | 50 | # Start the ssh server. Kill it if the script exits for any reason. 51 | # Note you must use an absolute path to exec sshd. 52 | `which sshd` -f test-virt-p2v-pxe.sshd_config -D -e & 53 | sshd_pid=$! 54 | cleanup () 55 | { 56 | kill $sshd_pid 57 | } 58 | trap cleanup INT QUIT TERM EXIT ERR 59 | 60 | # Get the randomly assigned sshd port number. 61 | port="$(grep ^Port test-virt-p2v-pxe.sshd_config | awk '{print $2}')" 62 | 63 | # Connect as the local user. 64 | username="$(id -un)" 65 | 66 | # Output storage path. 67 | os="$(cd $d; pwd)" 68 | 69 | # The Linux kernel command line. 70 | cmdline="root=/dev/sda4 ro console=ttyS0 printk.time=1 p2v.server=10.0.2.2 p2v.port=$port p2v.username=$username p2v.identity=file:///var/tmp/id_rsa p2v.name=fedora p2v.o=local p2v.os=$os" 71 | 72 | # Run virt-p2v inside qemu. 73 | $qemu \ 74 | -no-user-config \ 75 | -display none \ 76 | -machine accel=kvm:tcg \ 77 | -m 2048 \ 78 | -kernel test-virt-p2v-pxe.vmlinuz \ 79 | -initrd test-virt-p2v-pxe.initramfs \ 80 | -append "$cmdline" \ 81 | -boot c \ 82 | -device virtio-scsi-pci,id=scsi \ 83 | -drive file=$img,format=raw,snapshot=on,if=none,index=0,id=hd0 \ 84 | -device scsi-hd,drive=hd0 \ 85 | -drive file=$f,format=raw,snapshot=on,if=none,index=1,id=hd1 \ 86 | -device scsi-hd,drive=hd1 \ 87 | -netdev user,id=usernet \ 88 | -device virtio-net-pci,netdev=usernet \ 89 | -serial stdio 90 | 91 | # Test the libvirt XML metadata and a disk was created. 92 | test -f $d/fedora.xml 93 | test -f $d/fedora-sda 94 | 95 | rm -r $d 96 | -------------------------------------------------------------------------------- /test-virt-p2v-pxe.sshd_config.in: -------------------------------------------------------------------------------- 1 | # libguestfs virt-p2v test script 2 | # Copyright (C) 2014-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # Minimal sshd_config used by test-virt-p2v-pxe.ssh when it runs 18 | # a captive sshd. 19 | # 20 | # This file is processed by awk. See p2v/Makefile.am. 21 | 22 | # Choose a random high port number. 23 | Port __RANDOM_PORT__ 24 | 25 | # Only allow connections from loopback. 26 | ListenAddress [::1] 27 | ListenAddress 127.0.0.1 28 | 29 | # Privilege separation breaks non-root usage of sshd. 30 | UsePrivilegeSeparation no 31 | 32 | # Use local files instead of inaccessible global configuration. 33 | PidFile __abs_builddir__/test-virt-p2v-pxe.sshd.pid 34 | HostKey __abs_builddir__/test-virt-p2v-pxe.ssh_host_rsa_key 35 | 36 | AuthorizedKeysFile __abs_builddir__/test-virt-p2v-pxe.authorized_keys 37 | 38 | # Don't check file permissions. 39 | StrictModes no 40 | 41 | # Allow the environment to be set in the authorized_keys file above. 42 | PermitUserEnvironment yes 43 | -------------------------------------------------------------------------------- /test-virt-p2v-scp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # Copyright (C) 2014-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # This is an scp substitute used by test-virt-p2v-nbdkit.sh. 18 | 19 | TEMP=`getopt \ 20 | -o 'o:P:' \ 21 | -- "$@"` 22 | if [ $? != 0 ]; then 23 | echo "$0: problem parsing the command line arguments" 24 | exit 1 25 | fi 26 | eval set -- "$TEMP" 27 | 28 | while true ; do 29 | case "$1" in 30 | # Regular arguments that we can just ignore. 31 | -o|-P) 32 | shift 2 33 | ;; 34 | 35 | --) 36 | shift 37 | break 38 | ;; 39 | *) 40 | echo "$0: internal error ($1)" 41 | exit 1 42 | ;; 43 | esac 44 | done 45 | 46 | # Hopefully there are >= two arguments left, the source (local) 47 | # file(s) and a remote file of the form user@server:remote. 48 | if [ $# -lt 2 ]; then 49 | echo "$0: incorrect number of arguments found:" "$@" 50 | exit 1 51 | fi 52 | 53 | # https://stackoverflow.com/questions/1853946/getting-the-last-argument-passed-to-a-shell-script/1854031#1854031 54 | remote="${@: -1}" 55 | # https://stackoverflow.com/questions/20398499/remove-last-argument-from-argument-list-of-shell-script-bash/26163980#26163980 56 | set -- "${@:1:$(($#-1))}" 57 | 58 | remote="$(echo $remote | awk -F: '{print $2}')" 59 | 60 | # Use the copy command. 61 | exec cp "$@" "$remote" 62 | -------------------------------------------------------------------------------- /test-virt-p2v-ssh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # Copyright (C) 2014 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # This is an ssh substitute used by test-virt-p2v-nbdkit.sh. 18 | 19 | TEMP=`getopt \ 20 | -o 'l:No:p:R:' \ 21 | -- "$@"` 22 | if [ $? != 0 ]; then 23 | echo "$0: problem parsing the command line arguments" 24 | exit 1 25 | fi 26 | eval set -- "$TEMP" 27 | 28 | while true ; do 29 | case "$1" in 30 | # Regular arguments that we can just ignore. 31 | -N) 32 | shift 33 | ;; 34 | -l|-o|-p) 35 | shift 2 36 | ;; 37 | 38 | # ssh -R 0:localhost: (port forwarding). Don't actually 39 | # port forward, just return the original port number here so that 40 | # the conversion process connects directly to nbdkit. 41 | -R) 42 | arg="$2" 43 | port="$(echo $arg | awk -F: '{print $3}')" 44 | echo "Allocated port" $port "for remote forward" 45 | shift 2 46 | ;; 47 | 48 | --) 49 | shift 50 | break 51 | ;; 52 | *) 53 | echo "$0: internal error ($1)" 54 | exit 1 55 | ;; 56 | esac 57 | done 58 | 59 | # Now run the interactive shell. 60 | exec bash --norc 61 | -------------------------------------------------------------------------------- /utils.c: -------------------------------------------------------------------------------- 1 | /* virt-p2v 2 | * Copyright (C) 2015 Red Hat Inc. 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "ignore-value.h" 32 | 33 | #include "p2v.h" 34 | 35 | #define CHOMP(line,len) \ 36 | do { \ 37 | if ((len) > 0 && (line)[(len)-1] == '\n') { \ 38 | (line)[(len)-1] = '\0'; \ 39 | len--; \ 40 | } \ 41 | } while (0) 42 | 43 | /** 44 | * Return size of a block device, from F/size>. 45 | * 46 | * This function always succeeds, or else exits (since we expect 47 | * C to always be valid and the C file to always exist). 48 | */ 49 | uint64_t 50 | get_blockdev_size (const char *dev) 51 | { 52 | CLEANUP_FCLOSE FILE *fp = NULL; 53 | CLEANUP_FREE char *path = NULL; 54 | CLEANUP_FREE char *size_str = NULL; 55 | size_t len; 56 | uint64_t size; 57 | 58 | if (asprintf (&path, "/sys/block/%s/size", dev) == -1) 59 | error (EXIT_FAILURE, errno, "asprintf"); 60 | 61 | fp = fopen (path, "r"); 62 | if (fp == NULL) 63 | error (EXIT_FAILURE, errno, "fopen: %s", path); 64 | if (getline (&size_str, &len, fp) == -1) 65 | error (EXIT_FAILURE, errno, "getline: %s", path); 66 | 67 | if (sscanf (size_str, "%" SCNu64, &size) != 1) 68 | error (EXIT_FAILURE, 0, "cannot parse %s: %s", path, size_str); 69 | 70 | size /= 2*1024*1024; /* size from kernel is given in sectors? */ 71 | return size; 72 | } 73 | 74 | /** 75 | * Return model of a block device, from F/device/model>. 76 | * 77 | * Returns C if the file was not found. The caller must 78 | * free the returned string. 79 | */ 80 | char * 81 | get_blockdev_model (const char *dev) 82 | { 83 | CLEANUP_FCLOSE FILE *fp = NULL; 84 | CLEANUP_FREE char *path = NULL; 85 | char *model = NULL; 86 | size_t len = 0; 87 | ssize_t n; 88 | 89 | if (asprintf (&path, "/sys/block/%s/device/model", dev) == -1) 90 | error (EXIT_FAILURE, errno, "asprintf"); 91 | fp = fopen (path, "r"); 92 | if (fp == NULL) { 93 | perror (path); 94 | return NULL; 95 | } 96 | if ((n = getline (&model, &len, fp)) == -1) { 97 | perror (path); 98 | free (model); 99 | return NULL; 100 | } 101 | CHOMP (model, n); 102 | return model; 103 | } 104 | 105 | /** 106 | * Return the serial number of a block device. 107 | * 108 | * This is found using the lsblk command. 109 | * 110 | * Returns C if we could not get the serial number. The caller 111 | * must free the returned string. 112 | */ 113 | char * 114 | get_blockdev_serial (const char *dev) 115 | { 116 | CLEANUP_PCLOSE FILE *fp = NULL; 117 | CLEANUP_FREE char *cmd = NULL; 118 | char *serial = NULL; 119 | size_t len = 0; 120 | ssize_t n; 121 | 122 | if (asprintf (&cmd, "lsblk -o serial /dev/%s --nodeps --noheadings", 123 | dev) == -1) 124 | error (EXIT_FAILURE, errno, "asprintf"); 125 | fp = popen (cmd, "r"); 126 | if (fp == NULL) { 127 | perror (cmd); 128 | return NULL; 129 | } 130 | if ((n = getline (&serial, &len, fp)) == -1) { 131 | perror (cmd); 132 | free (serial); 133 | return NULL; 134 | } 135 | CHOMP (serial, n); 136 | return serial; 137 | } 138 | 139 | /** 140 | * Return contents of F/address> (if found). 141 | */ 142 | char * 143 | get_if_addr (const char *if_name) 144 | { 145 | CLEANUP_FCLOSE FILE *fp = NULL; 146 | CLEANUP_FREE char *path = NULL; 147 | char *content = NULL; 148 | size_t len = 0; 149 | ssize_t n; 150 | 151 | if (asprintf (&path, "/sys/class/net/%s/address", if_name) == -1) 152 | error (EXIT_FAILURE, errno, "asprintf"); 153 | fp = fopen (path, "r"); 154 | if (fp == NULL) 155 | return NULL; 156 | if ((n = getline (&content, &len, fp)) == -1) { 157 | perror (path); 158 | free (content); 159 | return NULL; 160 | } 161 | CHOMP (content, n); 162 | return content; 163 | } 164 | 165 | /** 166 | * Return contents of F/device/vendor> (if 167 | * found), mapped to the PCI vendor. See: 168 | * L 169 | */ 170 | char * 171 | get_if_vendor (const char *if_name, int truncate) 172 | { 173 | CLEANUP_FCLOSE FILE *fp = NULL; 174 | CLEANUP_FREE char *path = NULL; 175 | char *line = NULL; 176 | size_t len = 0; 177 | ssize_t n; 178 | char vendor[5]; 179 | 180 | if (asprintf (&path, "/sys/class/net/%s/device/vendor", if_name) == -1) 181 | error (EXIT_FAILURE, errno, "asprintf"); 182 | fp = fopen (path, "r"); 183 | if (fp == NULL) { 184 | perror (path); 185 | return NULL; 186 | } 187 | if ((n = getline (&line, &len, fp)) == -1) { 188 | perror (path); 189 | free (line); 190 | return NULL; 191 | } 192 | 193 | /* Vendor is (always?) a 16 bit quantity (as defined by PCI), 194 | * something like "0x8086" (for Intel Corp). 195 | */ 196 | CHOMP (line, n); 197 | if (line[0] != '0' || line[1] != 'x' || strlen (&line[2]) != 4) { 198 | free (line); 199 | return NULL; 200 | } 201 | 202 | strcpy (vendor, &line[2]); 203 | 204 | fclose (fp); 205 | fp = fopen ("/usr/share/hwdata/pci.ids", "r"); 206 | if (fp == NULL) { 207 | perror ("/usr/share/hwdata/pci.ids"); 208 | free (line); 209 | return NULL; 210 | } 211 | while ((n = getline (&line, &len, fp)) != -1) { 212 | CHOMP (line, n); 213 | if (STRPREFIX (line, vendor)) { 214 | /* Find the start of the name after the vendor ID and whitespace. */ 215 | size_t i = 4; 216 | n -= 4; 217 | 218 | while (n > 0 && isspace (line[i])) { 219 | i++; 220 | n--; 221 | } 222 | 223 | memmove (&line[0], &line[i], n+1 /* copy trailing \0 */); 224 | 225 | /* Truncate? */ 226 | if (truncate > 0 && n > truncate) 227 | line[n] = '\0'; 228 | 229 | return line; 230 | } 231 | } 232 | 233 | free (line); 234 | return NULL; 235 | } 236 | 237 | /* XXX We could make this configurable. */ 238 | #define NETWORK_ONLINE_COMMAND "nm-online -t 30" 239 | 240 | /** 241 | * Wait for the network to come online, but don't error out if that 242 | * fails. The caller will call C immediately after 243 | * this which will fail if the network didn't come online. 244 | */ 245 | void 246 | wait_network_online (const struct config *config) 247 | { 248 | #ifdef DEBUG_STDERR 249 | fprintf (stderr, "waiting for the network to come online ...\n"); 250 | fprintf (stderr, "%s\n", NETWORK_ONLINE_COMMAND); 251 | fflush (stderr); 252 | #endif 253 | 254 | ignore_value (system (NETWORK_ONLINE_COMMAND)); 255 | } 256 | 257 | int 258 | compare_strings (const void *vp1, const void *vp2) 259 | { 260 | char * const *p1 = (char * const *) vp1; 261 | char * const *p2 = (char * const *) vp2; 262 | return strcmp (*p1, *p2); 263 | } 264 | -------------------------------------------------------------------------------- /valgrind-suppressions: -------------------------------------------------------------------------------- 1 | # virt-p2v 2 | # Copyright (C) 2009-2019 Red Hat Inc. 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # Valgrind suppressions used when testing only. There are no known 18 | # resource leaks in virt-p2v. This file is only for leaks in 19 | # libraries that virt-p2v uses. 20 | 21 | # ld-*.so 22 | { 23 | ld_leak 24 | Memcheck:Leak 25 | ... 26 | fun:_dl_init 27 | } 28 | 29 | # Gtk 30 | { 31 | glib_leak_1 32 | Memcheck:Leak 33 | ... 34 | fun:g_type_register_static 35 | } 36 | 37 | { 38 | glib_leak_2 39 | Memcheck:Leak 40 | ... 41 | fun:g_type_class_ref 42 | } 43 | 44 | { 45 | glib_leak_3 46 | Memcheck:Leak 47 | ... 48 | fun:g_bus_get_sync 49 | fun:g_daemon_vfs_init 50 | } 51 | 52 | { 53 | atk_leak 54 | Memcheck:Leak 55 | ... 56 | fun:atk_bridge_adaptor_init 57 | } 58 | 59 | # These appeared in glibc 2.35. 60 | # See also nbdkit commit f6409b4137c1aeb97d01eef5753f22033d64bfd4 61 | { 62 | glibc_leak_4 63 | Memcheck:Leak 64 | ... 65 | fun:dlopen@@* 66 | } 67 | -------------------------------------------------------------------------------- /virt-p2v-make-disk.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | virt-p2v-make-disk - Build the virt-p2v disk using virt-builder 4 | 5 | =head1 SYNOPSIS 6 | 7 | virt-p2v-make-disk -o /dev/sdX [os-version] 8 | 9 | =head1 DESCRIPTION 10 | 11 | L converts a physical machine to run virtualized on KVM, 12 | managed by libvirt, OpenStack, oVirt, Red Hat Enterprise 13 | Virtualisation (RHEV), or one of the other targets supported by 14 | L. 15 | 16 | virt-p2v-make-disk is a script which creates a bootable disk image or 17 | USB key containing virt-p2v. It uses L to do this, 18 | and is just a small shell script around virt-builder. 19 | 20 | The required I<-o> parameter specifies where the output should go, for 21 | example to a USB key (eg. C<-o /dev/sdX>) or to a file. If you pass a 22 | device name, then B. 23 | 24 | The root user on the disk image uses C as its initial password. 25 | 26 | =head2 C parameter 27 | 28 | The optional C parameter is the base Linux distro to use 29 | for the operating system on the ISO. If you don't set this parameter, 30 | the script tries to choose a suitable default for you. Most users 31 | should I use the C parameter. 32 | 33 | The base OS selected for virt-p2v is not related in any way to the OS 34 | of the physical machine that you are trying to convert. 35 | 36 | To list possible C combinations, do: 37 | 38 | virt-builder -l 39 | 40 | =head1 EXAMPLES 41 | 42 | Write a virt-p2v bootable USB key on F (any existing content 43 | on F is erased): 44 | 45 | virt-p2v-make-disk -o /dev/sdX 46 | 47 | Write a virt-p2v bootable virtual disk image, and boot it under qemu: 48 | 49 | virt-p2v-make-disk -o /var/tmp/p2v.img 50 | qemu-kvm -m 1024 -boot c \ 51 | -drive file=/var/tmp/p2v.img,if=virtio,index=0 \ 52 | -drive file=/var/tmp/guest.img,if=virtio,index=1 53 | 54 | where F would be the disk image of some guest that 55 | you want to convert (for testing only). 56 | 57 | =head1 ADDING EXTRA PACKAGES 58 | 59 | You can install extra packages using the I<--install> option. This 60 | can be useful for making a more fully-featured virt-p2v disk with 61 | extra tools for debugging and troubleshooting. Give a list of 62 | packages, separated by commas. For example: 63 | 64 | virt-p2v-make-disk -o /var/tmp/p2v.img --install tcpdump,traceroute 65 | 66 | =head1 ADDING AN SSH IDENTITY 67 | 68 | You can inject an SSH identity (private key) file to the image using 69 | the I<--inject-ssh-identity> option. 70 | 71 | First create a key pair. It must have an empty passphrase: 72 | 73 | ssh-keygen -t rsa -N '' -f id_rsa 74 | 75 | This creates a private key (C) and a public key 76 | (C) pair. The public key should be appended to the 77 | C file on the virt-v2v conversion server (usually to 78 | C). 79 | 80 | The private key should be injected into the disk image and then 81 | discarded: 82 | 83 | virt-p2v-make-disk [...] --inject-ssh-identity id_rsa 84 | rm id_rsa 85 | 86 | When booting virt-p2v, specify the URL of the injected file like this: 87 | 88 | │ User name: [root_____________________________] │ 89 | │ │ 90 | │ Password: [ ] │ 91 | │ │ 92 | │ SSH Identity URL: [file:///var/tmp/id_rsa___________] │ 93 | 94 | or if using the kernel command line, add: 95 | 96 | p2v.identity=file:///var/tmp/id_rsa 97 | 98 | For more information, see L. 99 | 100 | =head1 32 BIT VIRT-P2V 101 | 102 | For improved compatibility with older hardware, virt-p2v-make-disk has 103 | an I<--arch> option. The most useful setting (on x86-64 hosts) is 104 | I<--arch i686>, which builds a 32 bit virt-p2v environment that will 105 | work on older hardware. 32 bit virt-p2v can convert 64 bit physical 106 | machines and can interoperate with 64 bit virt-v2v and 64 bit 107 | hypervisors. 108 | 109 | This option requires that you have built F (ie. 110 | usually F) by some means, and that you install it next 111 | to the ordinary F binary (eg. in F<$libdir/virt-p2v/> or 112 | C<$VIRT_V2V_DATA_DIR>). This is outside the scope of this manual 113 | page, but you can find some tips in 114 | L. 115 | 116 | =head1 OPTIONS 117 | 118 | =over 4 119 | 120 | =item B<--help> 121 | 122 | Display help. 123 | 124 | =item B<--arch> ARCH 125 | 126 | Set the architecture of the virt-p2v ISO. See L above. 127 | 128 | If this option is not supplied, then the default is to use the same 129 | architecture as the host that is running virt-p2v-make-disk. 130 | 131 | =item B<--inject-ssh-identity> id_rsa 132 | 133 | Add an SSH identity (private key) file into the image. 134 | See L above. 135 | 136 | =item B<--install> pkg,pkg,... 137 | 138 | Add extra packages to the image. 139 | See L above. 140 | 141 | =item B<--no-warn-if-partition> 142 | 143 | Normally you should not write to a partition on a USB drive (ie. don’t 144 | use S>, use S> to make a bootable USB 145 | drive). If you do this, virt-builder prints a warning. This option 146 | suppresses that warning. 147 | 148 | =item B<-o> OUTPUT 149 | 150 | =item B<--output> OUTPUT 151 | 152 | Write output to C, which can be a local file or block device. 153 | B. 154 | 155 | =item B<-v> 156 | 157 | =item B<--verbose> 158 | 159 | Enable verbose output. Use this if you need to debug problems with 160 | the script or if you are filing a bug. 161 | 162 | =item B<-V> 163 | 164 | =item B<--version> 165 | 166 | Display version number and exit. 167 | 168 | =back 169 | 170 | =head1 FILES 171 | 172 | =over 4 173 | 174 | =item F<$libdir/virt-p2v/virt-p2v.xz> 175 | 176 | The L binary which is copied into the bootable disk 177 | image. 178 | 179 | The location of the binary can be changed by setting the 180 | C environment variable. 181 | 182 | =item F<$datadir/virt-p2v/issue> 183 | 184 | =item F<$datadir/virt-p2v/launch-virt-p2v.in> 185 | 186 | =item F<$datadir/virt-p2v/p2v.service> 187 | 188 | Various data files that are copied into the bootable disk image. 189 | 190 | The location of these files can be changed by setting the 191 | C environment variable. 192 | 193 | =back 194 | 195 | =head1 ENVIRONMENT VARIABLES 196 | 197 | =over 4 198 | 199 | =item C 200 | 201 | The directory where virt-p2v-make-disk looks for data files (see 202 | L above). If not set, a compiled-in location is used. 203 | 204 | =back 205 | 206 | =head1 SEE ALSO 207 | 208 | L, 209 | L, 210 | L, 211 | L, 212 | L. 213 | 214 | =head1 AUTHORS 215 | 216 | Richard W.M. Jones L 217 | 218 | =head1 COPYRIGHT 219 | 220 | Copyright (C) 2009-2019 Red Hat Inc. 221 | -------------------------------------------------------------------------------- /virt-p2v-make-kiwi.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash - 2 | # @configure_input@ 3 | # virt-p2v-make-kiwi 4 | # Copyright (C) 2016 SUSE. 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | unset CDPATH 20 | 21 | program="virt-p2v-make-kiwi" 22 | version="@PACKAGE_VERSION@" 23 | prefix="@prefix@" 24 | exec_prefix="@exec_prefix@" 25 | datarootdir="@datarootdir@" 26 | 27 | # Parse the command line arguments. 28 | shortopts=o:V 29 | longopts=help,inject-ssh-identity:,long-options,output:,short-options,version 30 | TEMP=`getopt \ 31 | -o "$shortopts" \ 32 | --long "$longopts" \ 33 | -n $program -- "$@"` 34 | if [ $? != 0 ]; then 35 | echo "$program: problem parsing the command line arguments" 36 | exit 1 37 | fi 38 | eval set -- "$TEMP" 39 | 40 | usage () 41 | { 42 | echo "Usage:" 43 | echo " $program [--options] [-o kiwi-folder]" 44 | echo 45 | echo "Read $program(1) man page for more information." 46 | exit $1 47 | } 48 | 49 | output=p2v.kiwi 50 | ssh_identity= 51 | 52 | while true; do 53 | case "$1" in 54 | --inject-ssh-identity) 55 | ssh_identity="$2" 56 | shift 2;; 57 | -o|--output) 58 | output="$2" 59 | shift 2;; 60 | 61 | # help etc. 62 | --help) 63 | usage 0;; 64 | -V|--version) 65 | echo "$program $version" 66 | exit 0;; 67 | --short-options) 68 | echo -n "$shortopts" | 69 | @SED@ -e 's/://g' -e 's/\(.\)/-\1\n/g' 70 | exit 0;; 71 | --long-options) 72 | echo "$longopts" | 73 | @SED@ -e 's/,/\n/g' -e 's/:$//mg' -e 's/\(.*\)/--\1/mg' | 74 | grep -v -E -- "--(short|long)-options" 75 | exit 0;; 76 | --) 77 | shift 78 | break;; 79 | *) 80 | echo "internal error ($1)" 81 | exit 1;; 82 | esac 83 | done 84 | 85 | set -e 86 | 87 | if [ -n "$VIRT_P2V_DATA_DIR" ]; then 88 | datadir="$VIRT_P2V_DATA_DIR" 89 | libdir="$VIRT_P2V_DATA_DIR" 90 | else 91 | datadir="@datadir@/virt-p2v" 92 | libdir="@libdir@/virt-p2v" 93 | fi 94 | 95 | # Dependencies. Since kiwi is SUSE-specific, only include 96 | # dependencies.suse here. 97 | depsfile="$datadir/dependencies.suse" 98 | if [ ! -f "$depsfile" ]; then 99 | echo "$0: cannot find dependencies file ($depsfile)" 100 | exit 1 101 | fi 102 | dependencies= 103 | while read line; do 104 | if [ -n "$line" ]; then 105 | depname=$(echo $line | awk '{gsub(/ /, "", $0); print}') 106 | pkg=" " 107 | if [ -z "$dependencies" ]; then 108 | dependencies="$pkg" 109 | else 110 | dependencies="$dependencies 111 | $pkg" 112 | fi 113 | fi 114 | done < $depsfile 115 | 116 | # Compute the distro-dependent pieces for kiwi 117 | branding= 118 | release_pkg= 119 | base_pattern= 120 | kiwi_boot= 121 | repos= 122 | . /etc/os-release 123 | case "$NAME" in 124 | SLES) 125 | branding="SLE" 126 | release_pkg="sles-release" 127 | base_pattern="patterns-sles-Minimal" 128 | case "$VERSION_ID" in 129 | 12) 130 | kiwi_boot="SLES12" 131 | repos="http://download.suse.de/ibs/SUSE:/SLE-12:/Update/standard 132 | http://download.suse.de/ibs/SUSE:/SLE-12:/GA/standard" 133 | ;; 134 | 12.1) 135 | kiwi_boot="SLES12" 136 | repos="http://download.suse.de/ibs/SUSE:/SLE-12-SP1:/Update/standard 137 | http://download.suse.de/ibs/SUSE:/SLE-12-SP1:/GA/standard 138 | http://download.suse.de/ibs/SUSE:/SLE-12:/Update/standard 139 | http://download.suse.de/ibs/SUSE:/SLE-12:/GA/standard" 140 | ;; 141 | *) 142 | echo "Unsupported distribution $NAME $VERSION_ID" 143 | exit 1;; 144 | esac;; 145 | openSUSE*) 146 | branding="openSUSE" 147 | release_pkg="openSUSE-release" 148 | base_pattern="patterns-openSUSE-base" 149 | case "$VERSION" in 150 | 13.1\ *) 151 | kiwi_boot="13.1" 152 | repos="obs://13.1/repo/oss" 153 | ;; 154 | 13.2\ *) 155 | kiwi_boot="13.2" 156 | repos="obs://13.2/repo/oss" 157 | ;; 158 | 42.1) 159 | kiwi_boot="leap42.1" 160 | repos="obs://leap/42.1/repo/oss" 161 | ;; 162 | *\ \(Tumbleweed\)) 163 | kiwi_boot="leap42.1" 164 | repos="obs://openSUSE:Factory/standard" 165 | ;; 166 | *) 167 | echo "Unsupported distribution $NAME $VERSION_ID" 168 | exit 1;; 169 | esac;; 170 | *) 171 | echo "Unsupported distribution $NAME $VERSION" 172 | exit 1;; 173 | esac 174 | 175 | # Compute the repos 176 | repos_xml= 177 | for repo in $repos; do 178 | repos_xml=" \n \n \n$repos_xml" 179 | done 180 | 181 | mkdir $output 182 | cp $datadir/kiwi-config.sh $output/config.sh 183 | 184 | mkdir -p $output/root/etc/sysconfig/network 185 | cat >$output/root/etc/sysconfig/network/ifcfg-eth0 << EOF 186 | BOOTPROTO='dhcp' 187 | MTU='' 188 | REMOTE_IPADDR='' 189 | STARTMODE='onboot' 190 | EOF 191 | 192 | mkdir -p $output/root/etc/systemd/system 193 | cp $datadir/p2v.service $output/root/etc/systemd/system 194 | 195 | mkdir -p $output/root/etc/udev/rules.d 196 | cat >$output/root/etc/udev/rules.d/70-persistent-net.rules < $output/root/usr/bin/virt-p2v 205 | 206 | if test "z$ssh_identity" != "z"; then 207 | mkdir -p $output/root/var/tmp 208 | cp $ssh_identity $output/root/var/tmp/id_rsa 209 | chmod 0600 $output/root/var/tmp/id_rsa 210 | fi 211 | 212 | # Now generate the final kiwi config, substituting as necessary. 213 | @AWK@ \ 214 | -v "dependencies=$dependencies" \ 215 | -v "md5sum_virt_p2v=$md5sum_virt_p2v" \ 216 | -v "branding=$branding" \ 217 | -v "release_pkg=$release_pkg" \ 218 | -v "base_pattern=$base_pattern" \ 219 | -v "kiwi_boot=$kiwi_boot" \ 220 | -v "repos=$repos_xml" \ 221 | '{ 222 | gsub (/__PACKAGE_NAME__/, "@PACKAGE_NAME@"); 223 | gsub (/__PACKAGE_VERSION__/, "@PACKAGE_VERSION@"); 224 | gsub (/__PACKAGE_VERSION_FULL__/, "@PACKAGE_VERSION_FULL@"); 225 | gsub (//, dependencies); 226 | gsub (/__BRANDING__/, branding); 227 | gsub (/__RELEASE_PKG__/, release_pkg); 228 | gsub (/__BASE_PATTERN__/, base_pattern); 229 | gsub (/__KIWI_BOOT__/, kiwi_boot); 230 | gsub (//, repos); 231 | print; 232 | }' \ 233 | $datadir/kiwi-config.xml.in > $output/config.xml 234 | 235 | echo "kiwi config folder written to $output" 236 | -------------------------------------------------------------------------------- /virt-p2v-make-kiwi.pod: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | virt-p2v-make-kiwi - Build the virt-p2v kiwi configuration 4 | 5 | =head1 SYNOPSIS 6 | 7 | virt-p2v-make-kiwi [--inject-ssh-identity path] [-o kiwi-folder] 8 | 9 | =head1 DESCRIPTION 10 | 11 | L converts a physical machine to run virtualized on KVM, 12 | managed by libvirt, OpenStack, oVirt, Red Hat Enterprise 13 | Virtualisation (RHEV), or one of the other targets supported by 14 | L. 15 | 16 | Kiwi is a tool used mainly by SUSE Linux Enterprise and openSUSE to 17 | build live CDs, make appliances and so on. It is driven by a few files 18 | including an xml description of the machine. 19 | 20 | virt-p2v-make-kiwi builds a folder containing all the pieces needed for 21 | kiwi to build a bootable P2V live CD ISO, USB key, or PXE image. This tool 22 | only builds the kiwi configuration, but this manual page describes some of 23 | the ways you can use the kiwi configuration. 24 | 25 | The root user on the disk image uses C as its initial password. 26 | 27 | =head1 BUILDING THE KIWI CONFIGURATION 28 | 29 | Using virt-p2v-make-kiwi is very simple: 30 | 31 | virt-p2v-make-kiwi 32 | 33 | will build a kiwi configuration based on the current machine’s distribution. 34 | 35 | To control the name of the output folder, use the I<-o> parameter. 36 | 37 | =head1 BUILDING A LIVE CD / ISO 38 | 39 | Once you have the kiwi configuration folder, you can use L to make a 40 | live CD: 41 | 42 | sudo kiwi --build p2v.kiwi -d build --type iso 43 | 44 | Before running this, you may have to tweak the C file 45 | to change the locale and keyboard mapping to the one you need. 46 | 47 | If running on a SUSE Linux Entreprise Server, add the path to your packages repositories 48 | using the C<--ignore-repos> and C<--add-repo> kiwi parameters. 49 | 50 | The generated ISO image will be placed in the C folder. 51 | 52 | =head1 BUILDING A BOOTABLE USB KEY 53 | 54 | Use the L program to write the ISO created above to a USB key: 55 | 56 | sudo dd if=path/to/p2v.iso of=/dev/sdX 57 | 58 | =head1 BUILDING A PXE BOOT IMAGE 59 | 60 | To create a PXE boot image, run kiwi in such a way: 61 | 62 | sudo kiwi --build $PWD/p2v.kiwi -d build --add-profile netboot --type pxe 63 | 64 | For more details on how to use the generated image, report to the kiwi documentation 65 | on PXE images: L 66 | 67 | =head1 ADDING AN SSH IDENTITY 68 | 69 | You can inject an SSH identity (private key) file to the kiwi config and 70 | hence into the ISO using the I<--inject-ssh-identity> option. Note 71 | that you I inject a key once the ISO has been built. 72 | 73 | First create a key pair. It must have an empty passphrase: 74 | 75 | ssh-keygen -t rsa -N '' -f id_rsa 76 | 77 | This creates a private key (C) and a public key 78 | (C) pair. The public key should be appended to the 79 | C file on the virt-v2v conversion server (usually to 80 | C). 81 | 82 | The private key should be added to the kiwi config and then 83 | discarded: 84 | 85 | virt-p2v-make-kiwi [...] --inject-ssh-identity id_rsa 86 | rm id_rsa 87 | 88 | The ISO can then be built from the kickstart in the usual way (see 89 | above), and it will contain the embedded SSH identity 90 | (F). 91 | 92 | When booting virt-p2v, specify the URL of the injected file like this: 93 | 94 | │ User name: [root_____________________________] │ 95 | │ │ 96 | │ Password: [ ] │ 97 | │ │ 98 | │ SSH Identity URL: [file:///var/tmp/id_rsa___________] │ 99 | 100 | or if using the kernel command line, add: 101 | 102 | p2v.identity=file:///var/tmp/id_rsa 103 | 104 | For more information, see L. 105 | 106 | =head1 OPTIONS 107 | 108 | =over 4 109 | 110 | =item B<--help> 111 | 112 | Display help. 113 | 114 | =item B<--inject-ssh-identity> id_rsa 115 | 116 | Add an SSH identity (private key) file into the kickstart. 117 | See L above. 118 | 119 | =item B<-o> OUTPUT 120 | 121 | =item B<--output> OUTPUT 122 | 123 | Write kiwi configuration to the C folder. If not specified, the default is 124 | F in the current directory. 125 | 126 | =item B<-V> 127 | 128 | =item B<--version> 129 | 130 | Display version number and exit. 131 | 132 | =back 133 | 134 | =head1 FILES 135 | 136 | =over 4 137 | 138 | =item F<$libdir/virt-p2v/virt-p2v.xz> 139 | 140 | The L binary which is copied into the kiwi configuration. 141 | 142 | The location of the binary can be changed by setting the 143 | C environment variable. 144 | 145 | =item F<$datadir/virt-p2v/issue> 146 | 147 | =item F<$datadir/virt-p2v/launch-virt-p2v.in> 148 | 149 | =item F<$datadir/virt-p2v/kiwi> 150 | 151 | =item F<$datadir/virt-p2v/p2v.service> 152 | 153 | Various data files that are used to make the kiwi appliance. 154 | 155 | The location of these files can be changed by setting the 156 | C environment variable. 157 | 158 | =back 159 | 160 | =head1 ENVIRONMENT VARIABLES 161 | 162 | =over 4 163 | 164 | =item C 165 | 166 | The directory where virt-p2v-make-kiwi looks for data files and 167 | the virt-p2v binary (see L above). If not set, a compiled-in 168 | location is used. 169 | 170 | =back 171 | 172 | =head1 SEE ALSO 173 | 174 | L, 175 | L, 176 | L, 177 | L, 178 | L. 179 | 180 | =head1 AUTHORS 181 | 182 | Cédric Bosdonnat 183 | 184 | =head1 COPYRIGHT 185 | 186 | Copyright (C) 2016 SUSE Ltd. 187 | --------------------------------------------------------------------------------