Pino Toscano
2019-Jul-01 16:51 UTC
[Libguestfs] [PATCH 0/6] p2v: start making it independent
As preliminary steps in splitting virt-p2v to an own repository, start making p2v more independent within libguestfs. This is accomplished by the following changes: - generate the p2v kernel config sources & docs at build time using a Perl script, rather than the generator (so no need for OCaml when building from git, and no generated sources in dist tarballs) - create two local test images: instead of a phony Windows image there is a real Fedora guest, to avoid requiring hivex (for Windows) or more copied phony test data (for Fedora) - create an own .gitignore for p2v This is still not complete, although it does a number of important changes, and it still makes p2v usable within libguestfs. Pino Toscano (6): p2v: move kernel config to perl script p2v: move kernel config POD docs to perl script generator: remove p2v_config p2v: split gitignore p2v: tests: switch windows image with local fedora one p2v: tests: use a local blank-part disk image .gitignore | 37 -- configure.ac | 5 + docs/C_SOURCE_FILES | 3 - generator/Makefile.am | 3 - generator/main.ml | 9 - generator/p2v_config.ml | 835 -------------------------------- generator/p2v_config.mli | 22 - p2v/.gitignore | 48 ++ p2v/Makefile.am | 36 +- p2v/generate-p2v-config.pl | 915 ++++++++++++++++++++++++++++++++++++ p2v/test-virt-p2v-nbdkit.sh | 18 +- p2v/test-virt-p2v-pxe.sh | 16 +- p2v/test-virt-p2v.sh | 18 +- 13 files changed, 1014 insertions(+), 951 deletions(-) delete mode 100644 generator/p2v_config.ml delete mode 100644 generator/p2v_config.mli create mode 100644 p2v/.gitignore create mode 100755 p2v/generate-p2v-config.pl -- 2.21.0
Pino Toscano
2019-Jul-01 16:51 UTC
[Libguestfs] [PATCH 1/6] p2v: move kernel config to perl script
Instead of generating the p2v kernel config using the OCaml generator, create a Perl script to do this job, mostly at build time. This is done to rely less on the generator for p2v, and because the generation of these sources is quick enough that it can be done at build time (instead of shipping the generated sources in dist tarballs). The generate-p2v-config.pl mimics what generator/p2v_config.ml -- namings, and general structure are kept close to that for comparison. The two C sources are created at build time by the script; however, the p2v-config.h header is generated at configure time: this is done because p2v-config.h is included by p2v.h (another header), which in turn is included by all the p2v C sources -- automake is not able to properly resolve the dependency, and thus it would not be generated properly. --- configure.ac | 5 + docs/C_SOURCE_FILES | 3 - generator/main.ml | 6 - p2v/Makefile.am | 16 +- p2v/generate-p2v-config.pl | 649 +++++++++++++++++++++++++++++++++++++ 5 files changed, 665 insertions(+), 14 deletions(-) create mode 100755 p2v/generate-p2v-config.pl diff --git a/configure.ac b/configure.ac index 6b701bef2..46bb7684a 100644 --- a/configure.ac +++ b/configure.ac @@ -376,6 +376,11 @@ AC_CONFIG_FILES([Makefile v2v/test-harness/Makefile v2v/test-harness/META website/index.html]) + +if test "x$HAVE_P2V_TRUE" = "x"; then + AC_CONFIG_COMMANDS([p2v/p2v-config.h], [${ac_srcdir}/p2v/generate-p2v-config.pl --file=p2v-config.h --output=p2v/p2v-config.h]) +fi + AC_OUTPUT dnl Produce summary. diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES index 519acedd5..20a38162c 100644 --- a/docs/C_SOURCE_FILES +++ b/docs/C_SOURCE_FILES @@ -356,7 +356,6 @@ ocaml/guestfs-c-errnos.c ocaml/guestfs-c.c ocaml/guestfs-c.h p2v/about-authors.c -p2v/config.c p2v/conversion.c p2v/cpuid.c p2v/gui-gtk2-compat.h @@ -364,11 +363,9 @@ p2v/gui-gtk3-compat.h p2v/gui.c p2v/inhibit.c p2v/kernel-cmdline.c -p2v/kernel-config.c p2v/kernel.c p2v/main.c p2v/nbd.c -p2v/p2v-config.h p2v/p2v.h p2v/physical-xml.c p2v/rtc.c diff --git a/generator/main.ml b/generator/main.ml index 7974550c5..e5edc42e7 100644 --- a/generator/main.ml +++ b/generator/main.ml @@ -363,12 +363,6 @@ Run it from the top source directory using the command output_to "customize/customize-options.pod" Customize.generate_customize_options_pod; - output_to "p2v/p2v-config.h" - P2v_config.generate_p2v_config_h; - output_to "p2v/config.c" - P2v_config.generate_p2v_config_c; - output_to "p2v/kernel-config.c" - P2v_config.generate_p2v_kernel_config_c; output_to "p2v/virt-p2v-kernel-config.pod" P2v_config.generate_p2v_kernel_config_pod; diff --git a/p2v/Makefile.am b/p2v/Makefile.am index 92e2c5050..972cf22f5 100644 --- a/p2v/Makefile.am +++ b/p2v/Makefile.am @@ -19,9 +19,6 @@ include $(top_srcdir)/subdir-rules.mk generator_built = \ about-authors.c \ - config.c \ - kernel-config.c \ - p2v-config.h \ virt-p2v-kernel-config.pod BUILT_SOURCES = \ @@ -53,6 +50,7 @@ EXTRA_DIST = \ # consume system entropy to regenerate. CLEANFILES += \ $(dependencies_files) \ + $(generated_sources) \ stamp-test-virt-p2v-pxe-data-files \ stamp-test-virt-p2v-pxe-kernel \ test-virt-p2v-pxe.authorized_keys \ @@ -82,7 +80,6 @@ noinst_PROGRAMS = virt-p2v virt_p2v_SOURCES = \ about-authors.c \ - config.c \ conversion.c \ cpuid.c \ gui.c \ @@ -91,7 +88,6 @@ virt_p2v_SOURCES = \ inhibit.c \ kernel.c \ kernel-cmdline.c \ - kernel-config.c \ main.c \ nbd.c \ p2v.h \ @@ -102,6 +98,13 @@ virt_p2v_SOURCES = \ utils.c \ whole-file.c +generated_sources = \ + config.c \ + kernel-config.c + +nodist_virt_p2v_SOURCES = \ + $(generated_sources) + virt_p2v_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ @@ -127,6 +130,9 @@ virt_p2v_LDADD = \ ../gnulib/lib/libgnu.la \ -lm +$(generated_sources): $(srcdir)/generate-p2v-config.pl + $(AM_V_GEN)rm -f $@ $@-t && $(PERL) $(<) --file=$@ --output=$@-t && mv $@-t $@ + # Scripts to build the disk image, USB key, or kickstart. bin_SCRIPTS = virt-p2v-make-disk virt-p2v-make-kickstart virt-p2v-make-kiwi diff --git a/p2v/generate-p2v-config.pl b/p2v/generate-p2v-config.pl new file mode 100755 index 000000000..dc36abbda --- /dev/null +++ b/p2v/generate-p2v-config.pl @@ -0,0 +1,649 @@ +#!/usr/bin/env perl +# Copyright (C) 2019 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; + +use Class::Struct; +use Getopt::Long; +use List::Util qw(any); + +struct ConfigSection => +{ + name => '$', + elements => '@', +}; + +struct ConfigString => +{ + name => '$', +}; + +struct ConfigInt => +{ + name => '$', + value => '$', +}; + +struct ConfigBool => +{ + name => '$', +}; + +struct ConfigUInt64 => +{ + name => '$', +}; + +struct ConfigUnsigned => +{ + name => '$', +}; + +struct ConfigEnum => +{ + name => '$', + enum => '$', +}; + +struct ConfigStringList => +{ + name => '$', +}; + +# Enums. +my @enums = ( + ["basis", ( + ["BASIS_UNKNOWN", "unknown", "RTC could not be read"], + ["BASIS_UTC", "utc", "RTC is either UTC or an offset from UTC"], + ["BASIS_LOCALTIME", "localtime", "RTC is localtime"], + )], + ["output_allocation", ( + ["OUTPUT_ALLOCATION_NONE", "none", "output allocation not set"], + ["OUTPUT_ALLOCATION_SPARSE", "sparse", "sparse"], + ["OUTPUT_ALLOCATION_PREALLOCATED", "preallocated", "preallocated"], + )], +); + +# Configuration fields. +my @fields = [ + ConfigSection->new( + name => 'remote', + elements => [ + ConfigString->new(name => 'server'), + ConfigInt->new(name => 'port', value => 22), + ], + ), + ConfigSection->new( + name => 'auth', + elements => [ + ConfigString->new(name => 'username'), + ConfigString->new(name => 'password'), + ConfigSection->new( + name => 'identity', + elements => [ + ConfigString->new(name => 'url'), + ConfigString->new(name => 'file'), + ConfigBool->new(name => 'file_needs_update'), + ], + ), + ConfigBool->new(name => 'sudo'), + ], + ), + ConfigString->new(name => 'guestname'), + ConfigInt->new(name => 'vcpus', value => 0), + ConfigUInt64->new(name => 'memory'), + ConfigSection->new( + name => 'cpu', + elements => [ + ConfigString->new(name => 'vendor'), + ConfigString->new(name => 'model'), + ConfigUnsigned->new(name => 'sockets'), + ConfigUnsigned->new(name => 'cores'), + ConfigUnsigned->new(name => 'threads'), + ConfigBool->new(name => 'acpi'), + ConfigBool->new(name => 'apic'), + ConfigBool->new(name => 'pae'), + ], + ), + ConfigSection->new( + name => 'rtc', + elements => [ + ConfigEnum->new(name => 'basis', enum => 'basis'), + ConfigInt->new(name => 'offset', value => 0), + ], + ), + ConfigStringList->new(name => 'disks'), + ConfigStringList->new(name => 'removable'), + ConfigStringList->new(name => 'interfaces'), + ConfigStringList->new(name => 'network_map'), + ConfigSection->new( + name => 'output', + elements => [ + ConfigString->new(name => 'type'), + ConfigEnum->new(name => 'allocation', enum => 'output_allocation'), + ConfigString->new(name => 'connection'), + ConfigString->new(name => 'format'), + ConfigString->new(name => 'storage'), + ], + ), +]; + +# Some /proc/cmdline p2v.* options were renamed when we introduced +# the generator. This map creates backwards compatibility mappings +# for these. +my @cmdline_aliases = ( + ["p2v.remote.server", "p2v.server"], + ["p2v.remote.port", "p2v.port"], + ["p2v.auth.username", "p2v.username"], + ["p2v.auth.password", "p2v.password"], + ["p2v.auth.identity.url", "p2v.identity"], + ["p2v.auth.sudo", "p2v.sudo"], + ["p2v.guestname", "p2v.name"], + ["p2v.network_map", "p2v.network"], + ["p2v.output.type", "p2v.o"], + ["p2v.output.allocation", "p2v.oa"], + ["p2v.output.connection", "p2v.oc"], + ["p2v.output.format", "p2v.of"], + ["p2v.output.storage", "p2v.os"], +); + +# Some config entries are not exposed on the kernel command line. +my @cmdline_ignore = ( + "p2v.auth.identity.file", + "p2v.auth.identity.file_needs_update", +); + +# Clean up the program name. +my $progname = $0; +$progname =~ s{.*/}{}; + +my $filename; +my $output; + +GetOptions( + 'file=s' => \$filename, + 'output=s' => \$output, + 'help' => sub { pod2usage(1); }, +) or pod2usage(2); +die "$progname: Option --file not specified.\n" unless $filename; +# die "$progname: Option --output not specified.\n" unless $output; + +sub print_generated_header { + my $fh = shift; + print $fh <<"EOF"; +/* libguestfs generated file + * WARNING: THIS FILE IS GENERATED FROM THE FOLLOWING FILES: + * $filename + * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. + */ + +EOF +} + +sub generate_config_struct { + my ($fh, $name, $fields) = @_; + # If there are any ConfigSection (sub-structs) in any of the + # fields then output those first. + foreach my $field (@$fields) { + if (ref($field) eq 'ConfigSection') { + generate_config_struct($fh, $field->name . "_config", $field->elements); + } + } + + # Now generate this struct. + print $fh "struct $name {\n"; + foreach my $field (@$fields) { + my $type = ref($field); + if ($type eq 'ConfigSection') { + printf $fh " struct %s_config %s;\n", $field->name, $field->name; + } elsif ($type eq 'ConfigString') { + printf $fh " char *%s;\n", $field->name; + } elsif ($type eq 'ConfigInt') { + printf $fh " int %s;\n", $field->name; + } elsif ($type eq 'ConfigBool') { + printf $fh " bool %s;\n", $field->name; + } elsif ($type eq 'ConfigUInt64') { + printf $fh " uint64_t %s;\n", $field->name; + } elsif ($type eq 'ConfigUnsigned') { + printf $fh " unsigned %s;\n", $field->name; + } elsif ($type eq 'ConfigEnum') { + printf $fh " enum %s %s;\n", $field->enum, $field->name; + } elsif ($type eq 'ConfigStringList') { + printf $fh " char **%s;\n", $field->name; + } + } + print $fh "};\n"; + print $fh "\n" +} + +sub generate_p2v_config_h { + my $fh = shift; + print_generated_header($fh); + print $fh <<"EOF"; +#ifndef GUESTFS_P2V_CONFIG_H +#define GUESTFS_P2V_CONFIG_H + +#include <stdbool.h> +#include <stdint.h> + +EOF + + # Generate enums. + foreach my $enum (@enums) { + my $name = shift @$enum; + print $fh "enum $name {\n"; + foreach my $items (@$enum) { + my ($n, $foo, $comment) = @$items; + printf $fh " %-25s /* %s */\n", ($n . ","), $comment; + } + print $fh "};\n"; + print $fh "\n" + } + + # Generate struct config. + generate_config_struct($fh, "config", @fields); + + print $fh <<'EOF'; +extern struct config *new_config (void); +extern struct config *copy_config (struct config *); +extern void free_config (struct config *); +extern void print_config (struct config *, FILE *); + +#endif /* GUESTFS_P2V_CONFIG_H */ +EOF +} + +sub generate_field_initialization { + my ($fh, $v, $fields) = @_; + foreach my $field (@$fields) { + my $type = ref($field); + if ($type eq 'ConfigSection') { + my $lv = $v . $field->name . '.'; + generate_field_initialization($fh, $lv, $field->elements); + } elsif ($type eq 'ConfigInt') { + if ($field->value > 0) { + printf $fh " %s%s = %d;\n", $v, $field->name, $field->value; + } + } + } +} + +sub generate_field_copy { + my ($fh, $v, $fields) = @_; + foreach my $field (@$fields) { + my $type = ref($field); + if ($type eq 'ConfigSection') { + my $lv = $v . $field->name . '.'; + generate_field_copy($fh, $lv, $field->elements); + } elsif ($type eq 'ConfigString') { + printf $fh " if (%s%s) {\n", $v, $field->name; + printf $fh " %s%s = strdup (%s%s);\n", $v, $field->name, $v, $field->name; + printf $fh " if (%s%s == NULL)\n", $v, $field->name; + printf $fh " error (EXIT_FAILURE, errno, \"strdup: %%s\", \"%s\");\n", $field->name; + printf $fh " }\n"; + } elsif ($type eq 'ConfigStringList') { + printf $fh " if (%s%s) {\n", $v, $field->name; + printf $fh " %s%s = guestfs_int_copy_string_list (%s%s);\n", $v, $field->name, $v, $field->name; + printf $fh " if (%s%s == NULL)\n", $v, $field->name; + printf $fh " error (EXIT_FAILURE, errno, \"copy string list: %%s\", \"%s\");\n", $field->name; + printf $fh " }\n"; + } + } +} + +sub generate_field_free { + my ($fh, $v, $fields) = @_; + foreach my $field (@$fields) { + my $type = ref($field); + if ($type eq 'ConfigSection') { + my $lv = $v . $field->name . '.'; + generate_field_free($fh, $lv, $field->elements); + } elsif ($type eq 'ConfigString') { + printf $fh " free (%s%s);\n", $v, $field->name; + } elsif ($type eq 'ConfigStringList') { + printf $fh " guestfs_int_free_string_list (%s%s);\n", $v, $field->name; + } + } +} + +sub generate_field_print { + my ($fh, $prefix, $v, $fields) = @_; + foreach my $field (@$fields) { + my $type = ref($field); + my $printable_name = defined($prefix) + ? $prefix . '.' . $field->name + : $field->name; + if ($type eq 'ConfigSection') { + my $lv = $v . $field->name . '.'; + generate_field_print($fh, $printable_name, $lv, $field->elements); + } elsif ($type eq 'ConfigString') { + print $fh " fprintf (fp, \"%-20s %s\\n\",\n"; + printf $fh " \"%s\", %s%s ? %s%s : \"(none)\");\n", + $printable_name, $v, $field->name, $v, $field->name; + } elsif ($type eq 'ConfigInt') { + print $fh " fprintf (fp, \"%-20s %d\\n\",\n"; + printf $fh " \"%s\", %s%s);\n", $printable_name, $v, $field->name; + } elsif ($type eq 'ConfigBool') { + print $fh " fprintf (fp, \"%-20s %s\\n\",\n"; + printf $fh " \"%s\", %s%s ? \"true\" : \"false\");\n", + $printable_name, $v, $field->name; + } elsif ($type eq 'ConfigUInt64') { + print $fh " fprintf (fp, \"%-20s %\" PRIu64 \"\\n\",\n"; + printf $fh " \"%s\", %s%s);\n", $printable_name, $v, $field->name; + } elsif ($type eq 'ConfigUnsigned') { + print $fh " fprintf (fp, \"%-20s %u\\n\",\n"; + printf $fh " \"%s\", %s%s);\n", $printable_name, $v, $field->name; + } elsif ($type eq 'ConfigEnum') { + printf $fh " fprintf (fp, \"%%-20s \", \"%s\");\n", $printable_name; + printf $fh " print_%s (%s%s, fp);\n", $field->enum, $v, $field->name; + print $fh " fprintf (fp, \"\\n\");\n"; + } elsif ($type eq 'ConfigStringList') { + printf $fh " fprintf (fp, \"%%-20s\", \"%s\");\n", $printable_name; + printf $fh " if (%s%s) {\n", $v, $field->name; + printf $fh " for (i = 0; %s%s[i] != NULL; ++i)\n", $v, $field->name; + printf $fh " fprintf (fp, \" %%s\", %s%s[i]);\n", $v, $field->name; + print $fh " }\n"; + print $fh " else\n"; + print $fh " fprintf (fp, \" (none)\\n\");\n"; + print $fh " fprintf (fp, \"\\n\");\n"; + } + } +} + +sub generate_p2v_config_c { + my $fh = shift; + print_generated_header($fh); + print $fh <<"EOF"; +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdbool.h> +#include <inttypes.h> +#include <errno.h> +#include <error.h> + +#include "p2v.h" +#include "p2v-config.h" + +/** + * Allocate a new config struct. + */ +struct config * +new_config (void) +{ + struct config *c; + + c = calloc (1, sizeof *c); + if (c == NULL) + error (EXIT_FAILURE, errno, "calloc"); + +EOF + + generate_field_initialization($fh, "c->", @fields); + + print $fh <<"EOF"; + + return c; +} + +/** + * Copy a config struct. + */ +struct config * +copy_config (struct config *old) +{ + struct config *c = new_config (); + + memcpy (c, old, sizeof *c); + + /* Need to deep copy strings and string lists. */ +EOF + + generate_field_copy($fh, "c->", @fields); + + print $fh <<"EOF"; + + return c; +} + +/** + * Free a config struct. + */ +void +free_config (struct config *c) +{ + if (c == NULL) + return; + +EOF + + generate_field_free($fh, "c->", @fields); + + print $fh <<"EOF"; +} + +EOF + + foreach my $enum (@enums) { + my $name = shift @$enum; + print $fh "static void\n"; + printf $fh "print_%s (enum %s v, FILE *fp)\n", $name, $name; + print $fh "{\n"; + printf $fh " switch (v) {\n"; + foreach my $items (@$enum) { + my ($n, $cmdline, $foo) = @$items; + printf $fh " case %s:\n", $n; + printf $fh " fprintf (fp, \"%s\");\n", $cmdline; + print $fh " break;\n"; + } + print $fh " }\n"; + print $fh "}\n"; + print $fh "\n" + } + + print $fh <<"EOF"; +/** + * Print the conversion parameters and other important information. + */ +void +print_config (struct config *c, FILE *fp) +{ + size_t i; + + fprintf (fp, \"%-20s %s\\n\", \"local version\", PACKAGE_VERSION_FULL); + fprintf (fp, \"%-20s %s\\n\", \"remote version\", + v2v_version ? v2v_version : \"unknown\"); +EOF + + generate_field_print($fh, undef, "c->", @fields); + + print $fh <<"EOF"; +} +EOF +} + +sub find_alias { + my $name = shift; + foreach my $alias (@cmdline_aliases) { + if ($name eq @$alias[0]) { + return @$alias[1]; + } + } + return; +} + +sub find_enum { + my $name = shift; + foreach my $enum (@enums) { + my $n = shift @$enum; + if ($n eq $name) { + return @$enum; + } + } + return; +} + +sub generate_field_config { + my ($fh, $prefix, $v, $fields) = @_; + + foreach my $field (@$fields) { + my $type = ref($field); + if ($type eq 'ConfigSection') { + my $lprefix = $prefix . '.' . $field->name; + my $lv = $v . $field->name . '.'; + generate_field_config($fh, $lprefix, $lv, $field->elements); + } else { + my $key = $prefix . '.' . $field->name; + + if (not (any { $_ eq $key } @cmdline_ignore)) { + # Is there an alias for this field? + my $alias = find_alias($key); + + printf $fh " if ((p = get_cmdline_key (cmdline, \"%s\")) != NULL", $key; + if (defined($alias)) { + print $fh " ||\n"; + printf $fh " (p = get_cmdline_key (cmdline, \"%s\")) != NULL", $alias; + } + print $fh ") {\n"; + + # Parse the field. + if ($type eq 'ConfigString') { + printf $fh " free (%s%s);\n", $v, $field->name; + printf $fh " %s%s = strdup (p);\n", $v, $field->name; + printf $fh " if (%s%s == NULL)\n", $v, $field->name; + print $fh " error (EXIT_FAILURE, errno, \"strdup\");\n"; + } elsif ($type eq 'ConfigInt') { + printf $fh " if (sscanf (p, \"%%d\", &%s%s) != 1)\n", $v, $field->name; + print $fh " error (EXIT_FAILURE, errno,\n"; + print $fh " \"cannot parse %s=%s from the kernel command line\",\n"; + printf $fh " \"%s\", p);\n", $key; + } elsif ($type eq 'ConfigBool') { + printf $fh " %s%s = guestfs_int_is_true (p) || STREQ (p, \"\");\n", $v, $field->name; + } elsif ($type eq 'ConfigUInt64') { + print $fh " xerr = xstrtoull (p, NULL, 0, &ull, \"0kKMGTPEZY\");\n"; + print $fh " if (xerr != LONGINT_OK)\n"; + print $fh " error (EXIT_FAILURE, 0,\n"; + print $fh " \"cannot parse %s=%s from the kernel command line\",\n"; + printf $fh " \"%s\", p);\n", $key; + printf $fh " %s%s = ull;\n", $v, $field->name; + } elsif ($type eq 'ConfigUnsigned') { + printf $fh " if (sscanf (p, \"%%u\", &%s%s) != 1)\n", $v, $field->name; + print $fh " error (EXIT_FAILURE, errno,\n"; + print $fh " \"cannot parse %s=%s from the kernel command line\",\n"; + printf $fh " \"%s\", p);\n", $key; + } elsif ($type eq 'ConfigEnum') { + my @enum_choices = find_enum($field->enum) or die "cannot find ConfigEnum $field->enum"; + printf $fh " "; + foreach my $items (@enum_choices) { + my ($n, $cmdline, $foo) = @$items; + printf $fh "if (STREQ (p, \"%s\"))\n", $cmdline; + printf $fh " %s%s = %s;\n", $v, $field->name, $n; + print $fh " else "; + } + print $fh "{\n"; + print $fh " error (EXIT_FAILURE, 0,\n"; + print $fh " \"invalid value %s=%s from the kernel command line\",\n"; + printf $fh " \"%s\", p);\n", $key; + print $fh " }\n"; + } elsif ($type eq 'ConfigStringList') { + printf $fh " guestfs_int_free_string_list (%s%s);\n", $v, $field->name; + printf $fh " %s%s = guestfs_int_split_string (',', p);\n", $v, $field->name; + printf $fh " if (%s%s == NULL)\n", $v, $field->name; + print $fh " error (EXIT_FAILURE, errno, \"strdup\");\n"; + } + + print $fh " }\n"; + print $fh "\n"; + } + } + } +} + +sub generate_p2v_kernel_config_c { + my $fh = shift; + print_generated_header($fh); + print $fh <<"EOF"; +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <inttypes.h> +#include <unistd.h> +#include <errno.h> +#include <error.h> + +#include "xstrtol.h" + +#include "p2v.h" +#include "p2v-config.h" + +/** + * Read the kernel command line and parse out any C<p2v.*> fields that + * we understand into the config struct. + */ +void +update_config_from_kernel_cmdline (struct config *c, char **cmdline) +{ + const char *p; + strtol_error xerr; + unsigned long long ull; + +EOF + + generate_field_config($fh, "p2v", "c->", @fields); + + print $fh <<"EOF"; + if (c->auth.identity.url != NULL) + c->auth.identity.file_needs_update = 1; + + /* Undocumented command line parameter used for testing command line + * parsing. + */ + p = get_cmdline_key (cmdline, "p2v.dump_config_and_exit"); + if (p) { + print_config (c, stdout); + exit (EXIT_SUCCESS); + } +} +EOF +} + +sub write_to { + my $fn = shift; + if (defined($output)) { + open(my $fh, '>', $output) or die "Could not open file '$output': $!"; + $fn->($fh, @_); + close($fh); + } else { + $fn->(*STDOUT, @_); + } +} + +if ($filename eq 'config.c') { + write_to(\&generate_p2v_config_c); +} elsif ($filename eq 'kernel-config.c') { + write_to(\&generate_p2v_kernel_config_c); +} elsif ($filename eq 'p2v-config.h') { + write_to(\&generate_p2v_config_h); +} else { + die "$progname: unrecognized output file '$filename'\n"; +} -- 2.21.0
Pino Toscano
2019-Jul-01 16:51 UTC
[Libguestfs] [PATCH 2/6] p2v: move kernel config POD docs to perl script
Copy from generator/p2v_config.ml also the bits for POD documentation, adding them to generate-p2v-config.pl; this way, virt-p2v-kernel-config.pod can be generated at build time directly, instead of statically shipped as generator output. --- generator/main.ml | 3 - p2v/Makefile.am | 8 +- p2v/generate-p2v-config.pl | 266 +++++++++++++++++++++++++++++++++++++ 3 files changed, 270 insertions(+), 7 deletions(-) diff --git a/generator/main.ml b/generator/main.ml index e5edc42e7..187821647 100644 --- a/generator/main.ml +++ b/generator/main.ml @@ -363,9 +363,6 @@ Run it from the top source directory using the command output_to "customize/customize-options.pod" Customize.generate_customize_options_pod; - output_to "p2v/virt-p2v-kernel-config.pod" - P2v_config.generate_p2v_kernel_config_pod; - (* Generate the list of files generated -- last. *) printf "generated %d lines of code\n" (get_lines_generated ()); let files = List.sort compare (get_files_generated ()) in diff --git a/p2v/Makefile.am b/p2v/Makefile.am index 972cf22f5..2cd5235e3 100644 --- a/p2v/Makefile.am +++ b/p2v/Makefile.am @@ -18,8 +18,7 @@ include $(top_srcdir)/subdir-rules.mk generator_built = \ - about-authors.c \ - virt-p2v-kernel-config.pod + about-authors.c BUILT_SOURCES = \ $(generator_built) @@ -59,6 +58,7 @@ CLEANFILES += \ test-virt-p2v-pxe.initramfs \ test-virt-p2v-pxe.sshd_config \ virt-p2v.img \ + virt-p2v-kernel-config.pod \ virt-p2v.xz # Although virt-p2v is a regular binary, it is not usually installed @@ -130,7 +130,7 @@ virt_p2v_LDADD = \ ../gnulib/lib/libgnu.la \ -lm -$(generated_sources): $(srcdir)/generate-p2v-config.pl +$(generated_sources) virt-p2v-kernel-config.pod: $(srcdir)/generate-p2v-config.pl $(AM_V_GEN)rm -f $@ $@-t && $(PERL) $(<) --file=$@ --output=$@-t && mv $@-t $@ # Scripts to build the disk image, USB key, or kickstart. @@ -178,7 +178,7 @@ stamp-virt-p2v.pod: virt-p2v.pod virt-p2v-kernel-config.pod $(PODWRAPPER) \ --man virt-p2v.1 \ --html $(top_builddir)/website/virt-p2v.1.html \ - --insert $(srcdir)/virt-p2v-kernel-config.pod:__KERNEL_CONFIG__ \ + --insert virt-p2v-kernel-config.pod:__KERNEL_CONFIG__ \ --license GPLv2+ \ --warning safe \ $< diff --git a/p2v/generate-p2v-config.pl b/p2v/generate-p2v-config.pl index dc36abbda..01387e04b 100755 --- a/p2v/generate-p2v-config.pl +++ b/p2v/generate-p2v-config.pl @@ -65,6 +65,12 @@ struct ConfigStringList => name => '$', }; +struct manual_entry => +{ + shortopt => '$', + description => '$', +}; + # Enums. my @enums = ( ["basis", ( @@ -168,6 +174,219 @@ my @cmdline_ignore = ( "p2v.auth.identity.file_needs_update", ); +# Man page snippets for each kernel command line setting. +my %cmdline_manual = ( + "p2v.remote.server" => manual_entry->new( + shortopt => "SERVER", + description => " +The name or IP address of the conversion server. + +This is always required if you are using the kernel configuration +method. If virt-p2v does not find this on the kernel command line +then it switches to the GUI (interactive) configuration method.", + ), + "p2v.remote.port" => manual_entry->new( + shortopt => "PORT", + description => " +The SSH port number on the conversion server (default: C<22>).", + ), + "p2v.auth.username" => manual_entry->new( + shortopt => "USERNAME", + description => " +The SSH username that we log in as on the conversion server +(default: C<root>).", + ), + "p2v.auth.password" => manual_entry->new( + shortopt => "PASSWORD", + description => " +The SSH password that we use to log in to the conversion server. + +The default is to try with no password. If this fails then virt-p2v +will ask the user to type the password (probably several times during +conversion). + +This setting is ignored if C<p2v.auth.identity.url> is present.", + ), + "p2v.auth.identity.url" => manual_entry->new( + shortopt => "URL", + description => " +Provide a URL pointing to an SSH identity (private key) file. The URL +is interpreted by L<curl(1)> so any URL that curl supports can be used +here, including C<https://> and C<file://>. For more information on +using SSH identities, see L</SSH IDENTITIES> below. + +If C<p2v.auth.identity.url> is present, it overrides C<p2v.auth.password>. +There is no fallback.", + ), + "p2v.auth.sudo" => manual_entry->new( + shortopt => "", # ignored for booleans + description => " +Use C<p2v.sudo> to tell virt-p2v to use L<sudo(8)> to gain root +privileges on the conversion server after logging in as a non-root +user (default: do not use sudo).", + ), + "p2v.guestname" => manual_entry->new( + shortopt => "GUESTNAME", + description => " +The name of the guest that is created. The default is to try to +derive a name from the physical machine?s hostname (if possible) else +use a randomly generated name.", + ), + "p2v.vcpus" => manual_entry->new( + shortopt => "N", + description => " +The number of virtual CPUs to give to the guest. The default is to +use the same as the number of physical CPUs.", + ), + "p2v.memory" => manual_entry->new( + shortopt => "n(M|G)", + description => " +The size of the guest memory. You must specify the unit such as +megabytes or gigabytes by using for example C<p2v.memory=1024M> or +C<p2v.memory=1G>. + +The default is to use the same amount of RAM as on the physical +machine.", + ), + "p2v.cpu.vendor" => manual_entry->new( + shortopt => "VENDOR", + description => " +The vCPU vendor, eg. \"Intel\" or \"AMD\". The default is to use +the same CPU vendor as the physical machine.", + ), + "p2v.cpu.model" => manual_entry->new( + shortopt => "MODEL", + description => " +The vCPU model, eg. \"IvyBridge\". The default is to use the same +CPU model as the physical machine.", + ), + "p2v.cpu.sockets" => manual_entry->new( + shortopt => "N", + description => " +Number of vCPU sockets to use. The default is to use the same as the +physical machine.", + ), + "p2v.cpu.cores" => manual_entry->new( + shortopt => "N", + description => " +Number of vCPU cores to use. The default is to use the same as the +physical machine.", + ), + "p2v.cpu.threads" => manual_entry->new( + shortopt => "N", + description => " +Number of vCPU hyperthreads to use. The default is to use the same +as the physical machine.", + ), + "p2v.cpu.acpi" => manual_entry->new( + shortopt => "", # ignored for booleans + description => " +Whether to enable ACPI in the remote virtual machine. The default is +to use the same as the physical machine.", + ), + "p2v.cpu.apic" => manual_entry->new( + shortopt => "", # ignored for booleans + description => " +Whether to enable APIC in the remote virtual machine. The default is +to use the same as the physical machine.", + ), + "p2v.cpu.pae" => manual_entry->new( + shortopt => "", # ignored for booleans + description => " +Whether to enable PAE in the remote virtual machine. The default is +to use the same as the physical machine.", + ), + "p2v.rtc.basis" => manual_entry->new( + shortopt => "", # ignored for enums + description => " +Set the basis of the Real Time Clock in the virtual machine. The +default is to try to detect this setting from the physical machine.", + ), + "p2v.rtc.offset" => manual_entry->new( + shortopt => "[+|-]HOURS", + description => " +The offset of the Real Time Clock from UTC. The default is to try +to detect this setting from the physical machine.", + ), + "p2v.disks" => manual_entry->new( + shortopt => "sda,sdb,...", + description => " +A list of physical hard disks to convert, for example: + + p2v.disks=sda,sdc + +The default is to convert all local hard disks that are found.", + ), + "p2v.removable" => manual_entry->new( + shortopt => "sra,srb,...", + description => " +A list of removable media to convert. The default is to create +virtual removable devices for every physical removable device found. +Note that the content of removable media is never copied over.", + ), + "p2v.interfaces" => manual_entry->new( + shortopt => "em1,...", + description => " +A list of network interfaces to convert. The default is to create +virtual network interfaces for every physical network interface found.", + ), + "p2v.network_map" => manual_entry->new( + shortopt => "interface:target,...", + description => " +Controls how network interfaces are connected to virtual networks on +the target hypervisor. The default is to connect all network +interfaces to the target C<default> network. + +You give a comma-separated list of C<interface:target> pairs, plus +optionally a default target. For example: + + p2v.network=em1:ovirtmgmt + +maps interface C<em1> to target network C<ovirtmgmt>. + + p2v.network=em1:ovirtmgmt,em2:management,other + +maps interface C<em1> to C<ovirtmgmt>, and C<em2> to C<management>, +and any other interface that is found to C<other>.", + ), + "p2v.output.type" => manual_entry->new( + shortopt => "(libvirt|local|...)", + description => " +Set the output mode. This is the same as the virt-v2v I<-o> option. +See L<virt-v2v(1)/OPTIONS>. + +If not specified, the default is C<local>, and the converted guest is +written to F</var/tmp>.", + ), + "p2v.output.allocation" => manual_entry->new( + shortopt => "", # ignored for enums + description => " +Set the output allocation mode. This is the same as the virt-v2v +I<-oa> option. See L<virt-v2v(1)/OPTIONS>.", + ), + "p2v.output.connection" => manual_entry->new( + shortopt => "URI", + description => " +Set the output connection libvirt URI. This is the same as the +virt-v2v I<-oc> option. See L<virt-v2v(1)/OPTIONS> and +L<http://libvirt.org/uri.html>", + ), + "p2v.output.format" => manual_entry->new( + shortopt => "(raw|qcow2|...)", + description => " +Set the output format. This is the same as the virt-v2v I<-of> +option. See L<virt-v2v(1)/OPTIONS>.", + ), + "p2v.output.storage" => manual_entry->new( + shortopt => "STORAGE", + description => " +Set the output storage. This is the same as the virt-v2v I<-os> +option. See L<virt-v2v(1)/OPTIONS>. + +If not specified, the default is F</var/tmp> (on the conversion server).", + ), +); + # Clean up the program name. my $progname = $0; $progname =~ s{.*/}{}; @@ -627,6 +846,51 @@ EOF EOF } +sub generate_field_config_pod { + my ($fh, $prefix, $fields) = @_; + + foreach my $field (@$fields) { + my $type = ref($field); + if ($type eq 'ConfigSection') { + my $lprefix = $prefix . '.' . $field->name; + generate_field_config_pod($fh, $lprefix, $field->elements); + } else { + my $key = $prefix . '.' . $field->name; + + if (not (any { $_ eq $key } @cmdline_ignore)) { + # Is there an alias for this field? + my $manual_entry = $cmdline_manual{$key} or die "missing manual entry for $key"; + + # For booleans there is no shortopt field. For enums + # we generate it. + my $shortopt; + if ($type eq 'ConfigBool') { + die "non-empty shortopt for $field->name" if $manual_entry->shortopt ne ''; + $shortopt = ''; + } elsif ($type eq 'ConfigEnum') { + die "non-empty shortopt for $field->name" if $manual_entry->shortopt ne ''; + my @enum_choices = find_enum($field->enum) or die "cannot find ConfigEnum $field->enum"; + $shortopt = "=(" . join('|', map { $_->[1] } @enum_choices) . ")"; + } else { + $shortopt = "=" . $manual_entry->shortopt; + } + + # The description must not end with \n + die "description of $key must not end with \\n" if $manual_entry->description =~ /\n\z/; + + # Is there an alias for this field? + my $alias = find_alias($key); + printf $fh "=item B<%s%s>\n\n", $key, $shortopt; + if (defined($alias)) { + printf $fh "=item B<%s%s>\n\n", $alias, $shortopt; + } + + printf $fh "%s\n\n", $manual_entry->description; + } + } + } +} + sub write_to { my $fn = shift; if (defined($output)) { @@ -644,6 +908,8 @@ if ($filename eq 'config.c') { write_to(\&generate_p2v_kernel_config_c); } elsif ($filename eq 'p2v-config.h') { write_to(\&generate_p2v_config_h); +} elsif ($filename eq 'virt-p2v-kernel-config.pod') { + write_to(\&generate_field_config_pod, "p2v", @fields); } else { die "$progname: unrecognized output file '$filename'\n"; } -- 2.21.0
No more used now, as this configuration is generated within p2v itself at build time. --- generator/Makefile.am | 3 - generator/p2v_config.ml | 835 --------------------------------------- generator/p2v_config.mli | 22 -- 3 files changed, 860 deletions(-) delete mode 100644 generator/p2v_config.ml delete mode 100644 generator/p2v_config.mli diff --git a/generator/Makefile.am b/generator/Makefile.am index 07872d49c..0322a7561 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -101,8 +101,6 @@ sources = \ proc_nr.mli \ python.ml \ python.mli \ - p2v_config.ml \ - p2v_config.mli \ ruby.ml \ ruby.mli \ structs.ml \ @@ -167,7 +165,6 @@ objects = \ errnostring.cmo \ customize.cmo \ UEFI.cmo \ - p2v_config.cmo \ main.cmo EXTRA_DIST = $(sources) files-generated.txt diff --git a/generator/p2v_config.ml b/generator/p2v_config.ml deleted file mode 100644 index 11aec5ee3..000000000 --- a/generator/p2v_config.ml +++ /dev/null @@ -1,835 +0,0 @@ -(* libguestfs - * Copyright (C) 2018 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - *) - -(* Please read generator/README first. *) - -open Printf - -open Std_utils -open Docstrings -open Pr - -let generate_header = generate_header ~inputs:["generator/p2v_config.ml"] - -type enum_choice = string * string * string (* name, cmdline, comment *) -type enum = string * enum_choice list - -type config_entry - | ConfigString of string - | ConfigInt of string * int (* field name, initial value *) - | ConfigUnsigned of string - | ConfigUInt64 of string - | ConfigEnum of string * string (* field name, enum *) - | ConfigBool of string - | ConfigStringList of string - | ConfigSection of string * config_entry list - -type manual_entry = { - shortopt : string; - description : string; -} - -(* Enums. *) -let enums = [ - "basis", [ - "BASIS_UNKNOWN", "unknown", "RTC could not be read"; - "BASIS_UTC", "utc", "RTC is either UTC or an offset from UTC"; - "BASIS_LOCALTIME", "localtime", "RTC is localtime"; - ]; - "output_allocation", [ - "OUTPUT_ALLOCATION_NONE", "none", "output allocation not set"; - "OUTPUT_ALLOCATION_SPARSE", "sparse", "sparse"; - "OUTPUT_ALLOCATION_PREALLOCATED", "preallocated", "preallocated"; - ]; -] - -(* Configuration fields. *) -let fields = [ - ConfigSection ("remote", [ - ConfigString "server"; - ConfigInt ("port", 22); - ]); - ConfigSection ("auth", [ - ConfigString "username"; - ConfigString "password"; - ConfigSection ("identity", [ - ConfigString "url"; - ConfigString "file"; - ConfigBool "file_needs_update"; - ]); - ConfigBool "sudo"; - ]); - ConfigString "guestname"; - ConfigInt ("vcpus", 0); - ConfigUInt64 "memory"; - ConfigSection ("cpu", [ - ConfigString "vendor"; - ConfigString "model"; - ConfigUnsigned "sockets"; - ConfigUnsigned "cores"; - ConfigUnsigned "threads"; - ConfigBool "acpi"; - ConfigBool "apic"; - ConfigBool "pae"; - ]); - ConfigSection ("rtc", [ - ConfigEnum ("basis", "basis"); - ConfigInt ("offset", 0); - ]); - ConfigStringList "disks"; - ConfigStringList "removable"; - ConfigStringList "interfaces"; - ConfigStringList "network_map"; - ConfigSection ("output", [ - ConfigString "type"; - ConfigEnum ("allocation", "output_allocation"); - ConfigString "connection"; - ConfigString "format"; - ConfigString "storage"; - ]); -] - -(* Some /proc/cmdline p2v.* options were renamed when we introduced - * the generator. This map creates backwards compatibility mappings - * for these. - *) -let cmdline_aliases = [ - "p2v.remote.server", ["p2v.server"]; - "p2v.remote.port", ["p2v.port"]; - "p2v.auth.username", ["p2v.username"]; - "p2v.auth.password", ["p2v.password"]; - "p2v.auth.identity.url", ["p2v.identity"]; - "p2v.auth.sudo", ["p2v.sudo"]; - "p2v.guestname", ["p2v.name"]; - "p2v.network_map", ["p2v.network"]; - "p2v.output.type", ["p2v.o"]; - "p2v.output.allocation", ["p2v.oa"]; - "p2v.output.connection", ["p2v.oc"]; - "p2v.output.format", ["p2v.of"]; - "p2v.output.storage", ["p2v.os"]; -] - -(* Some config entries are not exposed on the kernel command line. *) -let cmdline_ignore = [ - "p2v.auth.identity.file"; - "p2v.auth.identity.file_needs_update"; -] - -(* Man page snippets for each kernel command line setting. *) -let cmdline_manual = [ - "p2v.remote.server", { - shortopt = "SERVER"; - description = " -The name or IP address of the conversion server. - -This is always required if you are using the kernel configuration -method. If virt-p2v does not find this on the kernel command line -then it switches to the GUI (interactive) configuration method."; - }; - "p2v.remote.port", { - shortopt = "PORT"; - description = " -The SSH port number on the conversion server (default: C<22>)."; - }; - "p2v.auth.username", { - shortopt = "USERNAME"; - description = " -The SSH username that we log in as on the conversion server -(default: C<root>)."; - }; - "p2v.auth.password", { - shortopt = "PASSWORD"; - description = " -The SSH password that we use to log in to the conversion server. - -The default is to try with no password. If this fails then virt-p2v -will ask the user to type the password (probably several times during -conversion). - -This setting is ignored if C<p2v.auth.identity.url> is present."; - }; - "p2v.auth.identity.url", { - shortopt = "URL"; - description = " -Provide a URL pointing to an SSH identity (private key) file. The URL -is interpreted by L<curl(1)> so any URL that curl supports can be used -here, including C<https://> and C<file://>. For more information on -using SSH identities, see L</SSH IDENTITIES> below. - -If C<p2v.auth.identity.url> is present, it overrides C<p2v.auth.password>. -There is no fallback."; - }; - "p2v.auth.sudo", { - shortopt = ""; (* ignored for booleans *) - description = " -Use C<p2v.sudo> to tell virt-p2v to use L<sudo(8)> to gain root -privileges on the conversion server after logging in as a non-root -user (default: do not use sudo)."; - }; - "p2v.guestname", { - shortopt = "GUESTNAME"; - description = " -The name of the guest that is created. The default is to try to -derive a name from the physical machine?s hostname (if possible) else -use a randomly generated name."; - }; - "p2v.vcpus", { - shortopt = "N"; - description = " -The number of virtual CPUs to give to the guest. The default is to -use the same as the number of physical CPUs."; - }; - "p2v.memory", { - shortopt = "n(M|G)"; - description = " -The size of the guest memory. You must specify the unit such as -megabytes or gigabytes by using for example C<p2v.memory=1024M> or -C<p2v.memory=1G>. - -The default is to use the same amount of RAM as on the physical -machine."; - }; - "p2v.cpu.vendor", { - shortopt = "VENDOR"; - description = " -The vCPU vendor, eg. \"Intel\" or \"AMD\". The default is to use -the same CPU vendor as the physical machine."; - }; - "p2v.cpu.model", { - shortopt = "MODEL"; - description = " -The vCPU model, eg. \"IvyBridge\". The default is to use the same -CPU model as the physical machine."; - }; - "p2v.cpu.sockets", { - shortopt = "N"; - description = " -Number of vCPU sockets to use. The default is to use the same as the -physical machine."; - }; - "p2v.cpu.cores", { - shortopt = "N"; - description = " -Number of vCPU cores to use. The default is to use the same as the -physical machine."; - }; - "p2v.cpu.threads", { - shortopt = "N"; - description = " -Number of vCPU hyperthreads to use. The default is to use the same -as the physical machine."; - }; - "p2v.cpu.acpi", { - shortopt = ""; (* ignored for booleans *) - description = " -Whether to enable ACPI in the remote virtual machine. The default is -to use the same as the physical machine."; - }; - "p2v.cpu.apic", { - shortopt = ""; (* ignored for booleans *) - description = " -Whether to enable APIC in the remote virtual machine. The default is -to use the same as the physical machine."; - }; - "p2v.cpu.pae", { - shortopt = ""; (* ignored for booleans *) - description = " -Whether to enable PAE in the remote virtual machine. The default is -to use the same as the physical machine."; - }; - "p2v.rtc.basis", { - shortopt = ""; (* ignored for enums. *) - description = " -Set the basis of the Real Time Clock in the virtual machine. The -default is to try to detect this setting from the physical machine."; - }; - "p2v.rtc.offset", { - shortopt = "[+|-]HOURS"; - description = " -The offset of the Real Time Clock from UTC. The default is to try -to detect this setting from the physical machine."; - }; - "p2v.disks", { - shortopt = "sda,sdb,..."; - description = " -A list of physical hard disks to convert, for example: - - p2v.disks=sda,sdc - -The default is to convert all local hard disks that are found."; - }; - "p2v.removable", { - shortopt = "sra,srb,..."; - description = " -A list of removable media to convert. The default is to create -virtual removable devices for every physical removable device found. -Note that the content of removable media is never copied over."; - }; - "p2v.interfaces", { - shortopt = "em1,..."; - description = " -A list of network interfaces to convert. The default is to create -virtual network interfaces for every physical network interface found."; - }; - "p2v.network_map", { - shortopt = "interface:target,..."; - description = " -Controls how network interfaces are connected to virtual networks on -the target hypervisor. The default is to connect all network -interfaces to the target C<default> network. - -You give a comma-separated list of C<interface:target> pairs, plus -optionally a default target. For example: - - p2v.network=em1:ovirtmgmt - -maps interface C<em1> to target network C<ovirtmgmt>. - - p2v.network=em1:ovirtmgmt,em2:management,other - -maps interface C<em1> to C<ovirtmgmt>, and C<em2> to C<management>, -and any other interface that is found to C<other>."; - }; - "p2v.output.type", { - shortopt = "(libvirt|local|...)"; - description = " -Set the output mode. This is the same as the virt-v2v I<-o> option. -See L<virt-v2v(1)/OPTIONS>. - -If not specified, the default is C<local>, and the converted guest is -written to F</var/tmp>."; - }; - "p2v.output.allocation", { - shortopt = ""; (* ignored for enums *) - description = " -Set the output allocation mode. This is the same as the virt-v2v -I<-oa> option. See L<virt-v2v(1)/OPTIONS>."; - }; - "p2v.output.connection", { - shortopt = "URI"; - description = " -Set the output connection libvirt URI. This is the same as the -virt-v2v I<-oc> option. See L<virt-v2v(1)/OPTIONS> and -L<http://libvirt.org/uri.html>"; - }; - "p2v.output.format", { - shortopt = "(raw|qcow2|...)"; - description = " -Set the output format. This is the same as the virt-v2v I<-of> -option. See L<virt-v2v(1)/OPTIONS>."; - }; - "p2v.output.storage", { - shortopt = "STORAGE"; - description = " -Set the output storage. This is the same as the virt-v2v I<-os> -option. See L<virt-v2v(1)/OPTIONS>. - -If not specified, the default is F</var/tmp> (on the conversion server)."; - }; -] - -let name_of_config_entry = function - | ConfigString n - | ConfigInt (n, _) - | ConfigUnsigned n - | ConfigUInt64 n - | ConfigEnum (n, _) - | ConfigBool n - | ConfigStringList n - | ConfigSection (n, _) -> n - -let rec generate_p2v_config_h () - generate_header CStyle GPLv2plus; - - pr "\ -#ifndef GUESTFS_P2V_CONFIG_H -#define GUESTFS_P2V_CONFIG_H - -#include <stdbool.h> -#include <stdint.h> - -"; - - (* Generate enums. *) - List.iter ( - fun (name, fields) -> - pr "enum %s {\n" name; - List.iter ( - fun (n, _, comment) -> - pr " %-25s /* %s */\n" (n ^ ",") comment - ) fields; - pr "};\n"; - pr "\n" - ) enums; - - (* Generate struct config. *) - generate_config_struct "config" fields; - - pr "\ -extern struct config *new_config (void); -extern struct config *copy_config (struct config *); -extern void free_config (struct config *); -extern void print_config (struct config *, FILE *); - -#endif /* GUESTFS_P2V_CONFIG_H */ -" - -and generate_config_struct name fields - (* If there are any ConfigSection (sub-structs) in any of the - * fields then output those first. - *) - List.iter ( - function - | ConfigSection (name, fields) -> - generate_config_struct (name ^ "_config") fields - | _ -> () - ) fields; - - (* Now generate this struct. *) - pr "struct %s {\n" name; - List.iter ( - function - | ConfigString n -> pr " char *%s;\n" n - | ConfigInt (n, _) -> pr " int %s;\n" n - | ConfigUnsigned n -> pr " unsigned %s;\n" n - | ConfigUInt64 n -> pr " uint64_t %s;\n" n - | ConfigEnum (n, enum) -> pr " enum %s %s;\n" enum n - | ConfigBool n -> pr " bool %s;\n" n - | ConfigStringList n -> pr " char **%s;\n" n - | ConfigSection (n, _) -> pr " struct %s_config %s;\n" n n - ) fields; - pr "};\n"; - pr "\n" - -let rec generate_p2v_config_c () - generate_header CStyle GPLv2plus; - - pr "\ -#include <config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdint.h> -#include <stdbool.h> -#include <inttypes.h> -#include <errno.h> -#include <error.h> - -#include \"p2v.h\" -#include \"p2v-config.h\" - -/** - * Allocate a new config struct. - */ -struct config * -new_config (void) -{ - struct config *c; - - c = calloc (1, sizeof *c); - if (c == NULL) - error (EXIT_FAILURE, errno, \"calloc\"); - -"; - - generate_field_initialization "c->" fields; - - pr "\ - - return c; -} - -/** - * Copy a config struct. - */ -struct config * -copy_config (struct config *old) -{ - struct config *c = new_config (); - - memcpy (c, old, sizeof *c); - - /* Need to deep copy strings and string lists. */ -"; - - generate_field_copy "c->" fields; - - pr "\ - - return c; -} - -/** - * Free a config struct. - */ -void -free_config (struct config *c) -{ - if (c == NULL) - return; - -"; - - generate_field_free "c->" fields; - -pr "\ -} - -"; - - List.iter ( - fun (name, fields) -> - pr "static void\n"; - pr "print_%s (enum %s v, FILE *fp)\n" name name; - pr "{\n"; - pr " switch (v) {\n"; - List.iter ( - fun (n, cmdline, _) -> - pr " case %s:\n" n; - pr " fprintf (fp, \"%s\");\n" cmdline; - pr " break;\n"; - ) fields; - pr " }\n"; - pr "}\n"; - pr "\n"; - ) enums; - - pr "\ -/** - * Print the conversion parameters and other important information. - */ -void -print_config (struct config *c, FILE *fp) -{ - size_t i; - - fprintf (fp, \"%%-20s %%s\\n\", \"local version\", PACKAGE_VERSION_FULL); - fprintf (fp, \"%%-20s %%s\\n\", \"remote version\", - v2v_version ? v2v_version : \"unknown\"); -"; - - generate_field_print None "c->" fields; - -pr "\ -} -" - -and generate_field_initialization v fields - List.iter ( - function - | ConfigInt (_, 0) -> () - | ConfigInt (n, i) -> - pr " %s%s = %d;\n" v n i - - | ConfigString _ - | ConfigUnsigned _ - | ConfigUInt64 _ - | ConfigEnum _ - | ConfigBool _ - | ConfigStringList _ -> () - - | ConfigSection (n, fields) -> - let v = sprintf "%s%s." v n in - generate_field_initialization v fields - ) fields - -and generate_field_copy v fields - List.iter ( - function - | ConfigString n -> - pr " if (%s%s) {\n" v n; - pr " %s%s = strdup (%s%s);\n" v n v n; - pr " if (%s%s == NULL)\n" v n; - pr " error (EXIT_FAILURE, errno, \"strdup: %%s\", \"%s\");\n" n; - pr " }\n"; - | ConfigStringList n -> - pr " if (%s%s) {\n" v n; - pr " %s%s = guestfs_int_copy_string_list (%s%s);\n" v n v n; - pr " if (%s%s == NULL)\n" v n; - pr " error (EXIT_FAILURE, errno, \"copy string list: %%s\", \"%s\");\n" n; - pr " }\n"; - - | ConfigInt _ - | ConfigUnsigned _ - | ConfigUInt64 _ - | ConfigEnum _ - | ConfigBool _ -> () - - | ConfigSection (n, fields) -> - let v = sprintf "%s%s." v n in - generate_field_copy v fields - ) fields - -and generate_field_free v fields - List.iter ( - function - | ConfigString n -> - pr " free (%s%s);\n" v n - | ConfigStringList n -> - pr " guestfs_int_free_string_list (%s%s);\n" v n - - | ConfigInt _ - | ConfigUnsigned _ - | ConfigUInt64 _ - | ConfigEnum _ - | ConfigBool _ -> () - - | ConfigSection (n, fields) -> - let v = sprintf "%s%s." v n in - generate_field_free v fields - ) fields - -and generate_field_print prefix v fields - List.iter ( - fun field -> - let printable_name - match prefix with - | None -> name_of_config_entry field - | Some prefix -> prefix ^ "." ^ name_of_config_entry field in - - match field with - | ConfigString n -> - pr " fprintf (fp, \"%%-20s %%s\\n\",\n"; - pr " \"%s\", %s%s ? %s%s : \"(none)\");\n" - printable_name v n v n - | ConfigInt (n, _) -> - pr " fprintf (fp, \"%%-20s %%d\\n\",\n"; - pr " \"%s\", %s%s);\n" printable_name v n - | ConfigUnsigned n -> - pr " fprintf (fp, \"%%-20s %%u\\n\",\n"; - pr " \"%s\", %s%s);\n" printable_name v n - | ConfigUInt64 n -> - pr " fprintf (fp, \"%%-20s %%\" PRIu64 \"\\n\",\n"; - pr " \"%s\", %s%s);\n" printable_name v n - | ConfigEnum (n, enum) -> - pr " fprintf (fp, \"%%-20s \", \"%s\");\n" printable_name; - pr " print_%s (%s%s, fp);\n" enum v n; - pr " fprintf (fp, \"\\n\");\n" - | ConfigBool n -> - pr " fprintf (fp, \"%%-20s %%s\\n\",\n"; - pr " \"%s\", %s%s ? \"true\" : \"false\");\n" - printable_name v n - | ConfigStringList n -> - pr " fprintf (fp, \"%%-20s\", \"%s\");\n" printable_name; - pr " if (%s%s) {\n" v n; - pr " for (i = 0; %s%s[i] != NULL; ++i)\n" v n; - pr " fprintf (fp, \" %%s\", %s%s[i]);\n" v n; - pr " }\n"; - pr " else\n"; - pr " fprintf (fp, \" (none)\\n\");\n"; - pr " fprintf (fp, \"\\n\");\n" - - | ConfigSection (n, fields) -> - let v = sprintf "%s%s." v n in - generate_field_print (Some printable_name) v fields - ) fields - -let rec generate_p2v_kernel_config_c () - generate_header CStyle GPLv2plus; - - pr "\ -#include <config.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <inttypes.h> -#include <unistd.h> -#include <errno.h> -#include <error.h> - -#include \"xstrtol.h\" - -#include \"p2v.h\" -#include \"p2v-config.h\" - -/** - * Read the kernel command line and parse out any C<p2v.*> fields that - * we understand into the config struct. - */ -void -update_config_from_kernel_cmdline (struct config *c, char **cmdline) -{ - const char *p; - strtol_error xerr; - unsigned long long ull; - -"; - - generate_field_config "p2v" "c->" fields; - - pr " if (c->auth.identity.url != NULL) - c->auth.identity.file_needs_update = 1; - - /* Undocumented command line parameter used for testing command line - * parsing. - */ - p = get_cmdline_key (cmdline, \"p2v.dump_config_and_exit\"); - if (p) { - print_config (c, stdout); - exit (EXIT_SUCCESS); - } -} -" - -and generate_field_config prefix v fields - List.iter ( - function - | ConfigSection (n, fields) -> - let prefix = sprintf "%s.%s" prefix n in - let v = sprintf "%s%s." v n in - generate_field_config prefix v fields - - | field -> - let n = name_of_config_entry field in - let key = sprintf "%s.%s" prefix n in - - if not (List.mem key cmdline_ignore) then ( - (* Is there an alias for this field? *) - let aliases - try List.assoc key cmdline_aliases - with Not_found -> [] in - - pr " if ((p = get_cmdline_key (cmdline, \"%s\")) != NULL" key; - List.iter ( - fun alias -> - pr " ||\n"; - pr " (p = get_cmdline_key (cmdline, \"%s\")) != NULL" alias; - ) aliases; - pr ") {\n"; - - (* Parse the field. *) - (match field with - | ConfigString n -> - pr " free (%s%s);\n" v n; - pr " %s%s = strdup (p);\n" v n; - pr " if (%s%s == NULL)\n" v n; - pr " error (EXIT_FAILURE, errno, \"strdup\");\n" - | ConfigStringList n -> - pr " guestfs_int_free_string_list (%s%s);\n" v n; - pr " %s%s = guestfs_int_split_string (',', p);\n" v n; - pr " if (%s%s == NULL)\n" v n; - pr " error (EXIT_FAILURE, errno, \"strdup\");\n" - | ConfigInt (n, _) -> - pr " if (sscanf (p, \"%%d\", &%s%s) != 1)\n" v n; - pr " error (EXIT_FAILURE, errno,\n"; - pr " \"cannot parse %%s=%%s from the kernel command line\",\n"; - pr " %S, p);\n" key - | ConfigUnsigned n -> - pr " if (sscanf (p, \"%%u\", &%s%s) != 1)\n" v n; - pr " error (EXIT_FAILURE, errno,\n"; - pr " \"cannot parse %%s=%%s from the kernel command line\",\n"; - pr " %S, p);\n" key - | ConfigUInt64 n -> - pr " xerr = xstrtoull (p, NULL, 0, &ull, \"0kKMGTPEZY\");\n"; - pr " if (xerr != LONGINT_OK)\n"; - pr " error (EXIT_FAILURE, 0,\n"; - pr " \"cannot parse %%s=%%s from the kernel command line\",\n"; - pr " %S, p);\n" key; - pr " %s%s = ull;\n" v n - | ConfigEnum (n, enum) -> - let enum_choices - try List.assoc enum enums - with Not_found -> failwithf "cannot find ConfigEnum %s" enum in - pr " "; - List.iter ( - fun (name, cmdline, _) -> - pr "if (STREQ (p, \"%s\"))\n" cmdline; - pr " %s%s = %s;\n" v n name; - pr " else "; - ) enum_choices; - pr "{\n"; - pr " error (EXIT_FAILURE, 0,\n"; - pr " \"invalid value %%s=%%s from the kernel command line\",\n"; - pr " %S, p);\n" key; - pr " }\n" - | ConfigBool n -> - pr " %s%s = guestfs_int_is_true (p) || STREQ (p, \"\");\n" v n - - | ConfigSection _ -> assert false (* see above *) - ); - - pr " }\n"; - pr "\n"; - ) - ) fields - -let rec generate_p2v_kernel_config_pod () - generate_field_config_pod "p2v" fields - -and generate_field_config_pod prefix fields - List.iter ( - function - | ConfigSection (n, fields) -> - let prefix = sprintf "%s.%s" prefix n in - generate_field_config_pod prefix fields - - | field -> - let n = name_of_config_entry field in - let key = sprintf "%s.%s" prefix n in - - if not (List.mem key cmdline_ignore) then ( - let manual_entry - try List.assoc key cmdline_manual - with Not_found -> - failwithf "generator/p2v_config.ml: missing manual entry for %s" - key in - - (* For booleans there is no shortopt field. For enums - * we generate it. - *) - let shortopt - match field with - | ConfigBool _ -> - assert (manual_entry.shortopt = ""); - "" - | ConfigEnum (_, enum) -> - assert (manual_entry.shortopt = ""); - - let enum_choices - try List.assoc enum enums - with Not_found -> failwithf "cannot find ConfigEnum %s" enum in - "=(" ^ - String.concat "|" - (List.map (fun (_, cmdline, _) -> cmdline) - enum_choices) ^ - ")" - | ConfigString _ - | ConfigInt _ - | ConfigUnsigned _ - | ConfigUInt64 _ - | ConfigStringList _ - | ConfigSection _ -> "=" ^ manual_entry.shortopt in - - (* The description must not end with \n *) - if String.is_suffix manual_entry.description "\n" then - failwithf "generator/p2v_config.ml: description of %s must not end with \\n" - key; - - (* Is there an alias for this field? *) - let aliases - try List.assoc key cmdline_aliases - with Not_found -> [] in - List.iter ( - fun k -> pr "=item B<%s%s>\n\n" k shortopt - ) (key :: aliases); - - pr "%s\n\n" manual_entry.description - ) - ) fields diff --git a/generator/p2v_config.mli b/generator/p2v_config.mli deleted file mode 100644 index 0027ae221..000000000 --- a/generator/p2v_config.mli +++ /dev/null @@ -1,22 +0,0 @@ -(* libguestfs - * Copyright (C) 2009-2019 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - *) - -val generate_p2v_config_h : unit -> unit -val generate_p2v_config_c : unit -> unit -val generate_p2v_kernel_config_c : unit -> unit -val generate_p2v_kernel_config_pod : unit -> unit -- 2.21.0
Move (or copy the general ones) all the p2v entries in the top-level .gitignore file to a new file specific for p2v. This will make it easier to keep them when splitting p2v. --- .gitignore | 37 ------------------------------------- p2v/.gitignore | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 p2v/.gitignore diff --git a/.gitignore b/.gitignore index d62d5a0a0..7d0073828 100644 --- a/.gitignore +++ b/.gitignore @@ -436,43 +436,6 @@ Makefile.in /ocaml/stamp-mlguestfs /ocaml/t/*.bc /ocaml/t/*.opt -/p2v/about-authors.c -/p2v/config.c -/p2v/dependencies.archlinux -/p2v/dependencies.debian -/p2v/dependencies.redhat -/p2v/dependencies.suse -/p2v/kernel-config.c -/p2v/p2v-config.h -/p2v/stamp-test-virt-p2v-pxe-data-files -/p2v/stamp-test-virt-p2v-pxe-hostkey -/p2v/stamp-test-virt-p2v-pxe-kernel -/p2v/stamp-test-virt-p2v-pxe-userkey -/p2v/stamp-virt-p2v.pod -/p2v/stamp-virt-p2v-make-disk.pod -/p2v/stamp-virt-p2v-make-kickstart.pod -/p2v/stamp-virt-p2v-make-kiwi.pod -/p2v/test-virt-p2v-pxe.authorized_keys -/p2v/test-virt-p2v-pxe.id_rsa -/p2v/test-virt-p2v-pxe.id_rsa.pub -/p2v/test-virt-p2v-pxe.img -/p2v/test-virt-p2v-pxe.initramfs -/p2v/test-virt-p2v-pxe.sshd_config -/p2v/test-virt-p2v-pxe.ssh_host_rsa_key -/p2v/test-virt-p2v-pxe.ssh_host_rsa_key.pub -/p2v/test-virt-p2v-pxe.vmlinuz -/p2v/virt-p2v -/p2v/virt-p2v.1 -/p2v/virt-p2v.i686 -/p2v/virt-p2v.img -/p2v/virt-p2v-kernel-config.pod -/p2v/virt-p2v-make-disk -/p2v/virt-p2v-make-disk.1 -/p2v/virt-p2v-make-kickstart -/p2v/virt-p2v-make-kickstart.1 -/p2v/virt-p2v-make-kiwi -/p2v/virt-p2v-make-kiwi.1 -/p2v/virt-p2v.xz /perl/_build /perl/bindtests.pl /perl/blib diff --git a/p2v/.gitignore b/p2v/.gitignore new file mode 100644 index 000000000..7ed707cea --- /dev/null +++ b/p2v/.gitignore @@ -0,0 +1,46 @@ +*~ +*.log +*.o +*.trs +.deps +.libs +Makefile +Makefile.in + +/about-authors.c +/config.c +/dependencies.archlinux +/dependencies.debian +/dependencies.redhat +/dependencies.suse +/kernel-config.c +/p2v-config.h +/stamp-test-virt-p2v-pxe-data-files +/stamp-test-virt-p2v-pxe-hostkey +/stamp-test-virt-p2v-pxe-kernel +/stamp-test-virt-p2v-pxe-userkey +/stamp-virt-p2v.pod +/stamp-virt-p2v-make-disk.pod +/stamp-virt-p2v-make-kickstart.pod +/stamp-virt-p2v-make-kiwi.pod +/test-virt-p2v-pxe.authorized_keys +/test-virt-p2v-pxe.id_rsa +/test-virt-p2v-pxe.id_rsa.pub +/test-virt-p2v-pxe.img +/test-virt-p2v-pxe.initramfs +/test-virt-p2v-pxe.sshd_config +/test-virt-p2v-pxe.ssh_host_rsa_key +/test-virt-p2v-pxe.ssh_host_rsa_key.pub +/test-virt-p2v-pxe.vmlinuz +/virt-p2v +/virt-p2v.1 +/virt-p2v.i686 +/virt-p2v.img +/virt-p2v-kernel-config.pod +/virt-p2v-make-disk +/virt-p2v-make-disk.1 +/virt-p2v-make-kickstart +/virt-p2v-make-kickstart.1 +/virt-p2v-make-kiwi +/virt-p2v-make-kiwi.1 +/virt-p2v.xz -- 2.21.0
Pino Toscano
2019-Jul-01 16:51 UTC
[Libguestfs] [PATCH 5/6] p2v: tests: switch windows image with local fedora one
Instead of using the "global" Windows test image, use a local Fedora image created with virt-builder. --- p2v/.gitignore | 1 + p2v/Makefile.am | 9 ++++++--- p2v/test-virt-p2v-nbdkit.sh | 14 ++++++-------- p2v/test-virt-p2v-pxe.sh | 16 +++++----------- p2v/test-virt-p2v.sh | 14 ++++++-------- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/p2v/.gitignore b/p2v/.gitignore index 7ed707cea..673e8ad83 100644 --- a/p2v/.gitignore +++ b/p2v/.gitignore @@ -13,6 +13,7 @@ Makefile.in /dependencies.debian /dependencies.redhat /dependencies.suse +/fedora.img /kernel-config.c /p2v-config.h /stamp-test-virt-p2v-pxe-data-files diff --git a/p2v/Makefile.am b/p2v/Makefile.am index 2cd5235e3..b4b57db91 100644 --- a/p2v/Makefile.am +++ b/p2v/Makefile.am @@ -220,7 +220,10 @@ stamp-virt-p2v-make-kiwi.pod: virt-p2v-make-kiwi.pod # Run virt-p2v locally either directly or in a VM. # See guestfs-hacking(1) section "Running virt-p2v" -PHYSICAL_MACHINE = $(abs_top_builddir)/test-data/phony-guests/windows.img +PHYSICAL_MACHINE = $(abs_builddir)/fedora.img + +check_DATA = \ + $(PHYSICAL_MACHINE) run-virt-p2v-directly: $(PHYSICAL_MACHINE) $(top_builddir)/run virt-p2v --test-disk=$(PHYSICAL_MACHINE) @@ -247,8 +250,8 @@ run-virt-p2v-in-a-vm: virt-p2v.img $(PHYSICAL_MACHINE) run-virt-p2v-non-gui-conversion: stamp-test-virt-p2v-pxe-data-files SLOW=1 $(top_builddir)/run ./test-virt-p2v-pxe.sh -$(abs_top_builddir)/test-data/phony-guests/windows.img: - $(MAKE) -C $(top_builddir)/test-data/phony-guests windows.img +$(PHYSICAL_MACHINE): + $(top_builddir)/run virt-builder --format raw -o $@ fedora-30 virt-p2v.img: \ dependencies.m4 \ diff --git a/p2v/test-virt-p2v-nbdkit.sh b/p2v/test-virt-p2v-nbdkit.sh index 58037d799..6e7ae2129 100755 --- a/p2v/test-virt-p2v-nbdkit.sh +++ b/p2v/test-virt-p2v-nbdkit.sh @@ -24,14 +24,12 @@ $TEST_FUNCTIONS skip_if_skipped skip_if_backend uml skip_unless nbdkit file --version -skip_unless_phony_guest windows.img +skip_unless test -f fedora.img skip_unless_phony_guest blank-part.img -f1="$abs_top_builddir/test-data/phony-guests/windows.img" +f1="$abs_builddir/fedora.img" f2="$abs_top_builddir/test-data/phony-guests/blank-part.img" -export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" - d=test-virt-p2v-nbdkit.d rm -rf $d mkdir $d @@ -48,14 +46,14 @@ export PATH=$d:$PATH # binaries under test (because of the ./run script). # The Linux kernel command line. -cmdline="p2v.server=localhost p2v.name=windows p2v.disks=$f1,$f2 p2v.o=local p2v.os=$(pwd)/$d p2v.network=em1:wired,other p2v.post=" +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=" # Only use nbdkit, disable qemu-nbd. $VG virt-p2v --cmdline="$cmdline" --nbd=nbdkit,nbdkit-no-sa # Test the libvirt XML metadata and a disk was created. -test -f $d/windows.xml -test -f $d/windows-sda -test -f $d/windows-sdb +test -f $d/fedora.xml +test -f $d/fedora-sda +test -f $d/fedora-sdb rm -r $d diff --git a/p2v/test-virt-p2v-pxe.sh b/p2v/test-virt-p2v-pxe.sh index 360853f8a..bad41886e 100755 --- a/p2v/test-virt-p2v-pxe.sh +++ b/p2v/test-virt-p2v-pxe.sh @@ -41,14 +41,8 @@ if ! test -f $img; then exit 77 fi -skip_unless_phony_guest windows.img -f="$top_builddir/test-data/phony-guests/windows.img" - -virt_tools_data_dir=${VIRT_TOOLS_DATA_DIR:-/usr/share/virt-tools} -if ! test -r $virt_tools_data_dir/rhsrvany.exe; then - echo "$0: test skipped because rhsrvany.exe is not installed" - exit 77 -fi +skip_unless test -f fedora.img +f="$abs_builddir/fedora.img" d=test-virt-p2v-pxe.d rm -rf $d @@ -74,7 +68,7 @@ username="$(id -un)" os="$(cd $d; pwd)" # The Linux kernel command line. -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=windows p2v.o=local p2v.os=$os" +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" # Run virt-p2v inside qemu. $qemu \ @@ -96,7 +90,7 @@ $qemu \ -serial stdio # Test the libvirt XML metadata and a disk was created. -test -f $d/windows.xml -test -f $d/windows-sda +test -f $d/fedora.xml +test -f $d/fedora-sda rm -r $d diff --git a/p2v/test-virt-p2v.sh b/p2v/test-virt-p2v.sh index b9c53971d..5d3cda448 100755 --- a/p2v/test-virt-p2v.sh +++ b/p2v/test-virt-p2v.sh @@ -23,14 +23,12 @@ set -e $TEST_FUNCTIONS skip_if_skipped skip_if_backend uml -skip_unless_phony_guest windows.img +skip_unless test -f fedora.img skip_unless_phony_guest blank-part.img -f1="$abs_top_builddir/test-data/phony-guests/windows.img" +f1="$abs_builddir/fedora.img" f2="$abs_top_builddir/test-data/phony-guests/blank-part.img" -export VIRT_TOOLS_DATA_DIR="$top_srcdir/test-data/fake-virt-tools" - d=test-virt-p2v.d rm -rf $d mkdir $d @@ -47,13 +45,13 @@ export PATH=$d:$PATH # binaries under test (because of the ./run script). # The Linux kernel command line. -cmdline="p2v.server=localhost p2v.name=windows p2v.disks=$f1,$f2 p2v.o=local p2v.os=$(pwd)/$d p2v.network=em1:wired,other p2v.post=" +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=" $VG virt-p2v --cmdline="$cmdline" # Test the libvirt XML metadata and a disk was created. -test -f $d/windows.xml -test -f $d/windows-sda -test -f $d/windows-sdb +test -f $d/fedora.xml +test -f $d/fedora-sda +test -f $d/fedora-sdb rm -r $d -- 2.21.0
Pino Toscano
2019-Jul-01 16:51 UTC
[Libguestfs] [PATCH 6/6] p2v: tests: use a local blank-part disk image
Instead of using the "global" blank-part test image, use a local version of it created with guestfish. --- p2v/.gitignore | 1 + p2v/Makefile.am | 7 ++++++- p2v/test-virt-p2v-nbdkit.sh | 4 ++-- p2v/test-virt-p2v.sh | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/p2v/.gitignore b/p2v/.gitignore index 673e8ad83..8495f6c2f 100644 --- a/p2v/.gitignore +++ b/p2v/.gitignore @@ -8,6 +8,7 @@ Makefile Makefile.in /about-authors.c +/blank-part.img /config.c /dependencies.archlinux /dependencies.debian diff --git a/p2v/Makefile.am b/p2v/Makefile.am index b4b57db91..5ee9d97d5 100644 --- a/p2v/Makefile.am +++ b/p2v/Makefile.am @@ -221,9 +221,11 @@ stamp-virt-p2v-make-kiwi.pod: virt-p2v-make-kiwi.pod # See guestfs-hacking(1) section "Running virt-p2v" PHYSICAL_MACHINE = $(abs_builddir)/fedora.img +BLANK_DISK = blank-part.img check_DATA = \ - $(PHYSICAL_MACHINE) + $(PHYSICAL_MACHINE) \ + $(BLANK_DISK) run-virt-p2v-directly: $(PHYSICAL_MACHINE) $(top_builddir)/run virt-p2v --test-disk=$(PHYSICAL_MACHINE) @@ -253,6 +255,9 @@ run-virt-p2v-non-gui-conversion: stamp-test-virt-p2v-pxe-data-files $(PHYSICAL_MACHINE): $(top_builddir)/run virt-builder --format raw -o $@ fedora-30 +$(BLANK_DISK): + $(top_builddir)/run guestfish -N $@=part exit + virt-p2v.img: \ dependencies.m4 \ issue \ diff --git a/p2v/test-virt-p2v-nbdkit.sh b/p2v/test-virt-p2v-nbdkit.sh index 6e7ae2129..5c635bb03 100755 --- a/p2v/test-virt-p2v-nbdkit.sh +++ b/p2v/test-virt-p2v-nbdkit.sh @@ -25,10 +25,10 @@ skip_if_skipped skip_if_backend uml skip_unless nbdkit file --version skip_unless test -f fedora.img -skip_unless_phony_guest blank-part.img +skip_unless test -f blank-part.img f1="$abs_builddir/fedora.img" -f2="$abs_top_builddir/test-data/phony-guests/blank-part.img" +f2="$abs_builddir/blank-part.img" d=test-virt-p2v-nbdkit.d rm -rf $d diff --git a/p2v/test-virt-p2v.sh b/p2v/test-virt-p2v.sh index 5d3cda448..121bf12eb 100755 --- a/p2v/test-virt-p2v.sh +++ b/p2v/test-virt-p2v.sh @@ -24,10 +24,10 @@ $TEST_FUNCTIONS skip_if_skipped skip_if_backend uml skip_unless test -f fedora.img -skip_unless_phony_guest blank-part.img +skip_unless test -f blank-part.img f1="$abs_builddir/fedora.img" -f2="$abs_top_builddir/test-data/phony-guests/blank-part.img" +f2="$abs_builddir/blank-part.img" d=test-virt-p2v.d rm -rf $d -- 2.21.0
Richard W.M. Jones
2019-Jul-02 09:53 UTC
Re: [Libguestfs] [PATCH 6/6] p2v: tests: use a local blank-part disk image
ACK series. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2019-Aug-20 18:17 UTC
Re: [Libguestfs] [PATCH 1/6] p2v: move kernel config to perl script
Unfortunately this breaks RHEL 7 builds :-( On Mon, Jul 01, 2019 at 06:51:17PM +0200, Pino Toscano wrote:> diff --git a/p2v/generate-p2v-config.pl b/p2v/generate-p2v-config.pl > new file mode 100755 > index 000000000..dc36abbda > --- /dev/null > +++ b/p2v/generate-p2v-config.pl> +use List::Util qw(any);GEN p2v-config.h "any" is not exported by the List::Util module Can't continue after import errors at generate-p2v-config.pl line 23. BEGIN failed--compilation aborted at generate-p2v-config.pl line 23. I tried to write a replacement "any" function since it seems like it would be easy but I couldn't get anything to work. It seems as if the RHEL 7 perl interpreter is more fussy about some of the later code in a way that I couldn't work out. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Seemingly Similar Threads
- p2v: Various cleanups.
- [PATCH 1/6] p2v: move kernel config to perl script
- [PATCH 0/2] Remove virt-p2v from libguestfs
- [p2v PATCH 02/11] Introduce "p2v.output.misc" for passing "-oo" options to virt-v2v
- [p2v PATCH 00/11] Expose virt-v2v's "-oo"; re-enable openstack