[libvirt] [PATCH 0/6] bhyve: virConnectDomainXMLFromNative

Differences to v3: functional changes: - Throw an error when there is no bhyverun command (bhyve_argv == NULL) - Parse the memory size in the same way bhyve does it, and adapt the relevant code (vm_parse_memsize) from the FreeBSD source tree. Here I'm a bit unsure about attribution; the original function comes from a BSD 2-Clause Licenced file, and I'm not sure if I also have to include the BSD disclaimer to the header. - Removed capability check for clock offset - Fix a mixup of NMDM master and slave - Fixed numbering of disks. When >25 disks are given, disks after vdz/sdz no longer get added. - Fail completely should parsing fail. bugfixes: - Fix a possible Null-Pointer dereference in bhyveParseCommandLineString when no loader command is given. - Fix an off-by-one in the string allocation (bhyve_parse_command.c:60) style: - Fix some indentation - Move else-clauses on the same line as the closing bracket from the if Link to v3: https://www.redhat.com/archives/libvir-list/2016-June/msg01741.html Link to v2: https://www.redhat.com/archives/libvir-list/2016-June/msg00728.html Link to v1: https://www.redhat.com/archives/libvir-list/2016-June/msg00001.html Fabian Freyer (6): config-post.h: define __GNUC_PREREQ if not defined gnulib: add getopt module bhyve: implement virConnectDomainXMLFromNative bhyve: implement bhyve argument parser bhyve: implement argument parser for loader Add some tests for bhyveParseCommandLineString bootstrap.conf | 1 + config-post.h | 18 + m4/virt-driver-bhyve.m4 | 3 + po/POTFILES.in | 1 + src/Makefile.am | 2 + src/bhyve/bhyve_driver.c | 42 + src/bhyve/bhyve_parse_command.c | 892 +++++++++++++++++++++ src/bhyve/bhyve_parse_command.h | 30 + tests/Makefile.am | 23 +- .../bhyveargv2xmldata/bhyveargv2xml-acpiapic.args | 9 + tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.xml | 20 + tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.xml | 21 + tests/bhyveargv2xmldata/bhyveargv2xml-base.args | 7 + tests/bhyveargv2xmldata/bhyveargv2xml-base.xml | 16 + .../bhyveargv2xml-bhyveload-bootorder.args | 13 + .../bhyveargv2xml-bhyveload-bootorder.xml | 27 + .../bhyveargv2xml-bhyveload-custom.args | 11 + .../bhyveargv2xml-bhyveload-custom.xml | 18 + .../bhyveargv2xml-bhyveload-mem-mismatch.args | 12 + .../bhyveargv2xml-bhyveload-memsize-fail.args | 12 + .../bhyveargv2xml-bhyveload-name-mismatch.args | 12 + .../bhyveargv2xml-bhyveload-vda.args | 12 + .../bhyveargv2xml-bhyveload-vda.xml | 21 + .../bhyveargv2xml-bhyverun-mem-mismatch.args | 12 + .../bhyveargv2xml-bhyverun-name-mismatch.args | 12 + tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.xml | 21 + tests/bhyveargv2xmldata/bhyveargv2xml-console.args | 10 + tests/bhyveargv2xmldata/bhyveargv2xml-console.xml | 28 + .../bhyveargv2xmldata/bhyveargv2xml-console2.args | 10 + tests/bhyveargv2xmldata/bhyveargv2xml-console2.xml | 15 + .../bhyveargv2xmldata/bhyveargv2xml-console3.args | 11 + tests/bhyveargv2xmldata/bhyveargv2xml-console3.xml | 27 + .../bhyveargv2xmldata/bhyveargv2xml-console4.args | 10 + tests/bhyveargv2xmldata/bhyveargv2xml-console4.xml | 15 + .../bhyveargv2xml-custom-loader.args | 8 + .../bhyveargv2xml-custom-loader.xml | 18 + .../bhyveargv2xml-disk-toomany.args | 34 + .../bhyveargv2xml-disk-toomany.xml | 146 ++++ .../bhyveargv2xmldata/bhyveargv2xml-extraargs.args | 8 + .../bhyveargv2xml-memsize-fail.args | 7 + .../bhyveargv2xml-memsize-human.args | 7 + .../bhyveargv2xml-memsize-human.xml | 16 + .../bhyveargv2xml-memsize-large.args | 7 + .../bhyveargv2xml-memsize-large.xml | 16 + tests/bhyveargv2xmldata/bhyveargv2xml-name.args | 7 + tests/bhyveargv2xmldata/bhyveargv2xml-name.xml | 16 + tests/bhyveargv2xmldata/bhyveargv2xml-oneline.args | 1 + tests/bhyveargv2xmldata/bhyveargv2xml-oneline.xml | 16 + tests/bhyveargv2xmldata/bhyveargv2xml-utc.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-utc.xml | 16 + tests/bhyveargv2xmldata/bhyveargv2xml-uuid.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-uuid.xml | 16 + tests/bhyveargv2xmldata/bhyveargv2xml-uuid2.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.args | 7 + tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.xml | 16 + .../bhyveargv2xml-virtio-blk.args | 8 + .../bhyveargv2xmldata/bhyveargv2xml-virtio-blk.xml | 21 + .../bhyveargv2xml-virtio-net.args | 9 + .../bhyveargv2xmldata/bhyveargv2xml-virtio-net.xml | 26 + .../bhyveargv2xml-virtio-net2.args | 8 + .../bhyveargv2xml-virtio-net2.xml | 16 + .../bhyveargv2xml-virtio-net3.args | 8 + .../bhyveargv2xml-virtio-net3.xml | 16 + .../bhyveargv2xml-virtio-net4.args | 8 + .../bhyveargv2xml-virtio-net4.xml | 21 + tests/bhyveargv2xmlmock.c | 27 + tests/bhyveargv2xmltest.c | 213 +++++ 69 files changed, 2174 insertions(+), 3 deletions(-) create mode 100644 src/bhyve/bhyve_parse_command.c create mode 100644 src/bhyve/bhyve_parse_command.h create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-base.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-base.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-mem-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-memsize-fail.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-name-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-mem-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-name-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console2.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console2.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console3.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console3.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console4.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console4.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-extraargs.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-fail.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-name.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-name.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-oneline.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-oneline.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-utc.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-utc.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-uuid.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-uuid.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-uuid2.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.xml create mode 100644 tests/bhyveargv2xmlmock.c create mode 100644 tests/bhyveargv2xmltest.c -- 2.5.5

Several gnulib headers rely on features.h being included by ctype.h to provide __GNUC_PREREQ, but on systems without glibc, this is not provided. In these cases __GNUC_PREREQ gets redefined to 0, which causes build errors from checks in src/internal.h. Therefore, define __GNUC_PREREQ as early as possible. config.h is probably the first header that is included, before any other headers. --- config-post.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/config-post.h b/config-post.h index f43521b..74d7bf2 100644 --- a/config-post.h +++ b/config-post.h @@ -69,3 +69,21 @@ # undef WITH_SECDRIVER_APPARMOR # undef WITH_CAPNG #endif /* LIBVIRT_NSS */ + +/* + * Define __GNUC__ to a sane default if it isn't yet defined. + * This is done here so that it's included as early as possible; gnulib relies + * on this to be defined in features.h, which should be included from ctype.h. + * This doesn't happen on many non-glibc systems. + * When __GNUC__ is not defined, gnulib defines it to 0, which breaks things. + */ +#ifdef __GNUC__ +# ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +# endif +#endif -- 2.5.5

(resent due to mail client line mangling) Several gnulib headers rely on features.h being included by ctype.h to provide __GNUC_PREREQ, but on systems without glibc, this is not provided. In these cases __GNUC_PREREQ gets redefined to 0, which causes build errors from checks in src/internal.h. Therefore, define __GNUC_PREREQ as early as possible. config.h is probably the first header that is included, before any other headers. --- config-post.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/config-post.h b/config-post.h index f43521b..74d7bf2 100644 --- a/config-post.h +++ b/config-post.h @@ -69,3 +69,21 @@ # undef WITH_SECDRIVER_APPARMOR # undef WITH_CAPNG #endif /* LIBVIRT_NSS */ + +/* + * Define __GNUC__ to a sane default if it isn't yet defined. + * This is done here so that it's included as early as possible; gnulib relies + * on this to be defined in features.h, which should be included from ctype.h. + * This doesn't happen on many non-glibc systems. + * When __GNUC__ is not defined, gnulib defines it to 0, which breaks things. + */ +#ifdef __GNUC__ +# ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +# endif +#endif -- 2.5.5

Fabian Freyer wrote:
(resent due to mail client line mangling)
Several gnulib headers rely on features.h being included by ctype.h to provide __GNUC_PREREQ, but on systems without glibc, this is not provided. In these cases __GNUC_PREREQ gets redefined to 0, which causes build errors from checks in src/internal.h. Therefore, define __GNUC_PREREQ as early as possible. config.h is probably the first header that is included, before any other headers. --- config-post.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/config-post.h b/config-post.h index f43521b..74d7bf2 100644 --- a/config-post.h +++ b/config-post.h @@ -69,3 +69,21 @@ # undef WITH_SECDRIVER_APPARMOR # undef WITH_CAPNG #endif /* LIBVIRT_NSS */ + +/* + * Define __GNUC__ to a sane default if it isn't yet defined. + * This is done here so that it's included as early as possible; gnulib relies + * on this to be defined in features.h, which should be included from ctype.h. + * This doesn't happen on many non-glibc systems. + * When __GNUC__ is not defined, gnulib defines it to 0, which breaks things. + */
Nit: there was a trailing whitespace here. ACK Please don't forget to report this issue to bug-gnulib@gnu.org.
+#ifdef __GNUC__ +# ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +# endif +#endif -- 2.5.5
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Roman Bogorodskiy

Unconditionally use gnulib's getopt module. This is needed by the bhyve driver to provide a reentrant interface for getopt. --- bootstrap.conf | 1 + m4/virt-driver-bhyve.m4 | 3 +++ 2 files changed, 4 insertions(+) diff --git a/bootstrap.conf b/bootstrap.conf index 0db6b62..edea8c3 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -54,6 +54,7 @@ func getaddrinfo getcwd-lgpl gethostname +getopt-posix getpass getpeername getsockname diff --git a/m4/virt-driver-bhyve.m4 b/m4/virt-driver-bhyve.m4 index c65b15d..bbdd8b2 100644 --- a/m4/virt-driver-bhyve.m4 +++ b/m4/virt-driver-bhyve.m4 @@ -52,6 +52,9 @@ AC_DEFUN([LIBVIRT_DRIVER_CHECK_BHYVE],[ AM_CONDITIONAL([WITH_BHYVE], [test "$with_bhyve" = "yes"]) ]) +dnl Build with gnulib's getopt which contains a reentrant interface +AC_DEFUN([gl_REPLACE_GETOPT_ALWAYS], []) + AC_DEFUN([LIBVIRT_DRIVER_RESULT_BHYVE],[ AC_MSG_NOTICE([ Bhyve: $with_bhyve]) ]) -- 2.5.5

Fabian Freyer wrote:
Unconditionally use gnulib's getopt module. This is needed by the bhyve driver to provide a reentrant interface for getopt. --- bootstrap.conf | 1 + m4/virt-driver-bhyve.m4 | 3 +++ 2 files changed, 4 insertions(+)
diff --git a/bootstrap.conf b/bootstrap.conf index 0db6b62..edea8c3 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -54,6 +54,7 @@ func getaddrinfo getcwd-lgpl gethostname +getopt-posix getpass getpeername getsockname diff --git a/m4/virt-driver-bhyve.m4 b/m4/virt-driver-bhyve.m4 index c65b15d..bbdd8b2 100644 --- a/m4/virt-driver-bhyve.m4 +++ b/m4/virt-driver-bhyve.m4 @@ -52,6 +52,9 @@ AC_DEFUN([LIBVIRT_DRIVER_CHECK_BHYVE],[ AM_CONDITIONAL([WITH_BHYVE], [test "$with_bhyve" = "yes"]) ])
+dnl Build with gnulib's getopt which contains a reentrant interface +AC_DEFUN([gl_REPLACE_GETOPT_ALWAYS], []) + AC_DEFUN([LIBVIRT_DRIVER_RESULT_BHYVE],[ AC_MSG_NOTICE([ Bhyve: $with_bhyve]) ]) -- 2.5.5
This misses gnulib/lib/getopt.c in po/POTFILES.in, otherwise ACK. Roman Bogorodskiy

First, remove escaped newlines and split up the string into an argv-list for the bhyve and loader commands, respectively. This is done by iterating over the string splitting it by newlines, and then re-iterating over each line, splitting it by spaces. Since this code reuses part of the code of qemu_parse_command.c (in bhyveCommandLine2argv), add the appropriate copyright notices. Signed-off-by: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> --- po/POTFILES.in | 1 + src/Makefile.am | 2 + src/bhyve/bhyve_driver.c | 42 +++++++ src/bhyve/bhyve_parse_command.c | 267 ++++++++++++++++++++++++++++++++++++++++ src/bhyve/bhyve_parse_command.h | 30 +++++ 5 files changed, 342 insertions(+) create mode 100644 src/bhyve/bhyve_parse_command.c create mode 100644 src/bhyve/bhyve_parse_command.h diff --git a/po/POTFILES.in b/po/POTFILES.in index f44a501..18a651d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -15,6 +15,7 @@ src/bhyve/bhyve_command.c src/bhyve/bhyve_device.c src/bhyve/bhyve_driver.c src/bhyve/bhyve_monitor.c +src/bhyve/bhyve_parse_command.c src/bhyve/bhyve_process.c src/conf/capabilities.c src/conf/cpu_conf.c diff --git a/src/Makefile.am b/src/Makefile.am index 275bfc7..7af985c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -912,6 +912,8 @@ BHYVE_DRIVER_SOURCES = \ bhyve/bhyve_capabilities.h \ bhyve/bhyve_command.c \ bhyve/bhyve_command.h \ + bhyve/bhyve_parse_command.c \ + bhyve/bhyve_parse_command.h \ bhyve/bhyve_device.c \ bhyve/bhyve_device.h \ bhyve/bhyve_domain.c \ diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 8036661..97bba9a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -57,6 +57,7 @@ #include "bhyve_device.h" #include "bhyve_driver.h" #include "bhyve_command.h" +#include "bhyve_parse_command.h" #include "bhyve_domain.h" #include "bhyve_process.h" #include "bhyve_capabilities.h" @@ -1539,6 +1540,46 @@ bhyveConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) return 0; } +static char * +bhyveConnectDomainXMLFromNative(virConnectPtr conn, + const char *nativeFormat, + const char *nativeConfig, + unsigned int flags) +{ + char *xml = NULL; + virDomainDefPtr def = NULL; + bhyveConnPtr privconn = conn->privateData; + virCapsPtr capabilities = NULL; + unsigned caps = bhyveDriverGetCaps(conn); + + virCheckFlags(0, NULL); + + if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0) + goto cleanup; + + capabilities = bhyveDriverGetCapabilities(privconn); + + if (!capabilities) + goto cleanup; + + if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) { + virReportError(VIR_ERR_INVALID_ARG, + _("unsupported config type %s"), nativeFormat); + goto cleanup; + } + + def = bhyveParseCommandLineString(nativeConfig, caps, privconn->xmlopt); + if (def == NULL) + goto cleanup; + + xml = virDomainDefFormat(def, capabilities, 0); + +cleanup: + virObjectUnref(capabilities); + virDomainDefFree(def); + return xml; +} + static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", .connectOpen = bhyveConnectOpen, /* 1.2.2 */ @@ -1592,6 +1633,7 @@ static virHypervisorDriver bhyveHypervisorDriver = { .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */ .connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */ .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */ + .connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 2.0.1 */ }; diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c new file mode 100644 index 0000000..0c4d3f5 --- /dev/null +++ b/src/bhyve/bhyve_parse_command.c @@ -0,0 +1,267 @@ +/* + * bhyve_parse_command.c: Bhyve command parser + * + * Copyright (C) 2006-2016 Red Hat, Inc. + * Copyright (C) 2006 Daniel P. Berrange + * Copyright (C) 2016 Fabian Freyer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> + */ + +#include <config.h> + +#include "bhyve_capabilities.h" +#include "bhyve_command.h" +#include "bhyve_parse_command.h" +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" +#include "virutil.h" +#include "c-ctype.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +VIR_LOG_INIT("bhyve.bhyve_parse_command"); + +/* + * This function takes a string representation of the command line and removes + * all newline characters, if they are prefixed by a backslash. The result + * should be a string with one command per line. + * + * NB: command MUST be NULL-Terminated. + */ +static char * +bhyveParseCommandLineUnescape(const char *command) +{ + size_t len = strlen(command); + char *unescaped = NULL; + char *curr_src = NULL; + char *curr_dst = NULL; + + /* Since we are only removing characters, allocating a buffer of the same + * size as command shouldn't be a problem here */ + if (VIR_ALLOC_N(unescaped, len+1) < 0) + return NULL; + + /* Iterate over characters in the command, skipping "\\\n", "\\\r" as well + * as "\\\r\n". */ + for (curr_src = (char*) command, curr_dst = unescaped; *curr_src != '\0'; + curr_src++, curr_dst++) { + if (*curr_src == '\\') { + switch (*(curr_src + 1)) { + case '\n': /* \LF */ + curr_src++; + curr_dst--; + break; + case '\r': /* \CR */ + curr_src++; + curr_dst--; + if (*curr_src == '\n') /* \CRLF */ + curr_src++; + break; + default: + *curr_dst = '\\'; + } + } else + *curr_dst = *curr_src; + } + + return unescaped; +} + +/* + * Try to extract loader and bhyve argv lists from a command line string. + */ +static int +bhyveCommandLineToArgv(const char *nativeConfig, + int *loader_argc, + char ***loader_argv, + int *bhyve_argc, + char ***bhyve_argv) +{ + const char *curr = NULL; + char *nativeConfig_unescaped = NULL; + const char *start; + const char *next; + char *line; + char **lines = NULL; + size_t line_count = 0; + size_t lines_alloc = 0; + char **_bhyve_argv = NULL; + char **_loader_argv = NULL; + + nativeConfig_unescaped = bhyveParseCommandLineUnescape(nativeConfig); + if (nativeConfig_unescaped == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to unescape command line string")); + goto error; + } + + curr = nativeConfig_unescaped; + + /* Iterate over string, splitting on sequences of '\n' */ + while (curr && *curr != '\0') { + start = curr; + next = strchr(curr, '\n'); + + if (VIR_STRNDUP(line, curr, next ? next - curr : -1) < 0) + goto error; + + if (VIR_RESIZE_N(lines, lines_alloc, line_count, 2) < 0) { + VIR_FREE(line); + goto error; + } + + if (*line) + lines[line_count++] = line; + lines[line_count] = NULL; + + while (next && (*next == '\n' || *next == '\r' + || STRPREFIX(next, "\r\n"))) + next++; + + curr = next; + } + + for (int i = 0; i < line_count; i++) { + curr = lines[i]; + int j; + char **arglist = NULL; + size_t args_count = 0; + size_t args_alloc = 0; + + /* iterate over each line, splitting on sequences of ' '. This code is + * adapted from qemu/qemu_parse_command.c. */ + while (curr && *curr != '\0') { + char *arg; + start = curr; + + if (*start == '\'') { + if (start == curr) + curr++; + next = strchr(start + 1, '\''); + } else if (*start == '"') { + if (start == curr) + curr++; + next = strchr(start + 1, '"'); + } else { + next = strchr(start, ' '); + } + + if (VIR_STRNDUP(arg, curr, next ? next - curr : -1) < 0) + goto error; + + if (next && (*next == '\'' || *next == '"')) + next++; + + if (VIR_RESIZE_N(arglist, args_alloc, args_count, 2) < 0) { + VIR_FREE(arg); + goto error; + } + + arglist[args_count++] = arg; + arglist[args_count] = NULL; + + while (next && c_isspace(*next)) + next++; + + curr = next; + } + + /* To prevent a memory leak here, only set the argument lists when + * the first matching command is found. This shouldn't really be a + * problem, since usually no multiple loaders or bhyverun commands + * are specified (this wouldn't really be valid anyways). + * Otherwise, later argument lists may be assigned to _argv without + * freeing the earlier ones. */ + if (!_bhyve_argv && STREQ(arglist[0], "/usr/sbin/bhyve")) { + if ((VIR_REALLOC_N(_bhyve_argv, args_count + 1) < 0) + || (!bhyve_argc)) + goto error; + for (j = 0; j < args_count; j++) + _bhyve_argv[j] = arglist[j]; + _bhyve_argv[j] = NULL; + *bhyve_argc = args_count-1; + } else if (!_loader_argv) { + if ((VIR_REALLOC_N(_loader_argv, args_count + 1) < 0) + || (!loader_argc)) + goto error; + for (j = 0; j < args_count; j++) + _loader_argv[j] = arglist[j]; + _loader_argv[j] = NULL; + *loader_argc = args_count-1; + } else + /* To prevent a use-after-free here, only free the argument list + * when it is definitely not going to be used */ + virStringFreeList(arglist); + } + + *loader_argv = _loader_argv; + if (!(*bhyve_argv = _bhyve_argv)) + goto error; + + virStringFreeList(lines); + return 0; + + error: + VIR_FREE(_loader_argv); + VIR_FREE(_bhyve_argv); + virStringFreeList(lines); + return -1; +} + +virDomainDefPtr +bhyveParseCommandLineString(const char* nativeConfig, + unsigned caps ATTRIBUTE_UNUSED, + virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED) +{ + virDomainDefPtr def = NULL; + int bhyve_argc = 0; + char **bhyve_argv = NULL; + int loader_argc = 0; + char **loader_argv = NULL; + + if (!(def = virDomainDefNew())) + goto cleanup; + + /* Initialize defaults. */ + def->virtType = VIR_DOMAIN_VIRT_BHYVE; + if (virUUIDGenerate(def->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to generate uuid")); + VIR_FREE(def); + goto cleanup; + } + def->id = -1; + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; + + if (bhyveCommandLineToArgv(nativeConfig, + &loader_argc, &loader_argv, + &bhyve_argc, &bhyve_argv)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to convert the command string to argv-lists..")); + goto error; + } + +cleanup: + virStringFreeList(loader_argv); + virStringFreeList(bhyve_argv); + return def; +error: + VIR_FREE(def); + goto cleanup; +} diff --git a/src/bhyve/bhyve_parse_command.h b/src/bhyve/bhyve_parse_command.h new file mode 100644 index 0000000..7ffe26c --- /dev/null +++ b/src/bhyve/bhyve_parse_command.h @@ -0,0 +1,30 @@ +/* + * bhyve_parse_command.h: Bhyve command parser + * + * Copyright (C) 2016 Fabian Freyer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> + */ + +#ifndef __BHYVE_PARSE_COMMAND_H__ +#define __BHYVE_PARSE_COMMAND_H__ + +virDomainDefPtr bhyveParseCommandLineString(const char* nativeConfig, + unsigned caps, + virDomainXMLOptionPtr xmlopt); + +#endif /* __BHYVE_PARSE_COMMAND_H__*/ -- 2.5.5

Fabian Freyer wrote:
First, remove escaped newlines and split up the string into an argv-list for the bhyve and loader commands, respectively. This is done by iterating over the string splitting it by newlines, and then re-iterating over each line, splitting it by spaces.
Since this code reuses part of the code of qemu_parse_command.c (in bhyveCommandLine2argv), add the appropriate copyright notices.
Signed-off-by: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> --- po/POTFILES.in | 1 + src/Makefile.am | 2 + src/bhyve/bhyve_driver.c | 42 +++++++ src/bhyve/bhyve_parse_command.c | 267 ++++++++++++++++++++++++++++++++++++++++ src/bhyve/bhyve_parse_command.h | 30 +++++ 5 files changed, 342 insertions(+) create mode 100644 src/bhyve/bhyve_parse_command.c create mode 100644 src/bhyve/bhyve_parse_command.h
diff --git a/po/POTFILES.in b/po/POTFILES.in index f44a501..18a651d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -15,6 +15,7 @@ src/bhyve/bhyve_command.c src/bhyve/bhyve_device.c src/bhyve/bhyve_driver.c src/bhyve/bhyve_monitor.c +src/bhyve/bhyve_parse_command.c src/bhyve/bhyve_process.c src/conf/capabilities.c src/conf/cpu_conf.c diff --git a/src/Makefile.am b/src/Makefile.am index 275bfc7..7af985c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -912,6 +912,8 @@ BHYVE_DRIVER_SOURCES = \ bhyve/bhyve_capabilities.h \ bhyve/bhyve_command.c \ bhyve/bhyve_command.h \ + bhyve/bhyve_parse_command.c \ + bhyve/bhyve_parse_command.h \ bhyve/bhyve_device.c \ bhyve/bhyve_device.h \ bhyve/bhyve_domain.c \ diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 8036661..97bba9a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -57,6 +57,7 @@ #include "bhyve_device.h" #include "bhyve_driver.h" #include "bhyve_command.h" +#include "bhyve_parse_command.h" #include "bhyve_domain.h" #include "bhyve_process.h" #include "bhyve_capabilities.h" @@ -1539,6 +1540,46 @@ bhyveConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) return 0; }
+static char * +bhyveConnectDomainXMLFromNative(virConnectPtr conn, + const char *nativeFormat, + const char *nativeConfig, + unsigned int flags) +{ + char *xml = NULL; + virDomainDefPtr def = NULL; + bhyveConnPtr privconn = conn->privateData; + virCapsPtr capabilities = NULL; + unsigned caps = bhyveDriverGetCaps(conn); + + virCheckFlags(0, NULL); + + if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0) + goto cleanup; + + capabilities = bhyveDriverGetCapabilities(privconn); + + if (!capabilities) + goto cleanup;
Nothing to clean up before this point, could be just "return NULL";
+ + if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) { + virReportError(VIR_ERR_INVALID_ARG, + _("unsupported config type %s"), nativeFormat); + goto cleanup; + } + + def = bhyveParseCommandLineString(nativeConfig, caps, privconn->xmlopt); + if (def == NULL) + goto cleanup; + + xml = virDomainDefFormat(def, capabilities, 0); + +cleanup:
One space required before label.
+ virObjectUnref(capabilities); + virDomainDefFree(def); + return xml; +} + static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", .connectOpen = bhyveConnectOpen, /* 1.2.2 */ @@ -1592,6 +1633,7 @@ static virHypervisorDriver bhyveHypervisorDriver = { .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */ .connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */ .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */ + .connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 2.0.1 */
This should be 2.1.0.
};
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c new file mode 100644 index 0000000..0c4d3f5 --- /dev/null +++ b/src/bhyve/bhyve_parse_command.c @@ -0,0 +1,267 @@ +/* + * bhyve_parse_command.c: Bhyve command parser + * + * Copyright (C) 2006-2016 Red Hat, Inc. + * Copyright (C) 2006 Daniel P. Berrange + * Copyright (C) 2016 Fabian Freyer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> + */ + +#include <config.h> + +#include "bhyve_capabilities.h" +#include "bhyve_command.h" +#include "bhyve_parse_command.h" +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" +#include "virutil.h" +#include "c-ctype.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +VIR_LOG_INIT("bhyve.bhyve_parse_command"); + +/* + * This function takes a string representation of the command line and removes + * all newline characters, if they are prefixed by a backslash. The result + * should be a string with one command per line. + * + * NB: command MUST be NULL-Terminated. + */ +static char * +bhyveParseCommandLineUnescape(const char *command) +{ + size_t len = strlen(command); + char *unescaped = NULL; + char *curr_src = NULL; + char *curr_dst = NULL; + + /* Since we are only removing characters, allocating a buffer of the same + * size as command shouldn't be a problem here */ + if (VIR_ALLOC_N(unescaped, len+1) < 0) + return NULL; + + /* Iterate over characters in the command, skipping "\\\n", "\\\r" as well + * as "\\\r\n". */ + for (curr_src = (char*) command, curr_dst = unescaped; *curr_src != '\0'; + curr_src++, curr_dst++) { + if (*curr_src == '\\') { + switch (*(curr_src + 1)) { + case '\n': /* \LF */ + curr_src++; + curr_dst--; + break; + case '\r': /* \CR */ + curr_src++; + curr_dst--; + if (*curr_src == '\n') /* \CRLF */ + curr_src++; + break; + default: + *curr_dst = '\\'; + } + } else + *curr_dst = *curr_src;
Style: if using {} for the first part, have to use {} for the second one as well.
+ } + + return unescaped; +} + +/* + * Try to extract loader and bhyve argv lists from a command line string. + */ +static int +bhyveCommandLineToArgv(const char *nativeConfig, + int *loader_argc, + char ***loader_argv, + int *bhyve_argc, + char ***bhyve_argv) +{ + const char *curr = NULL; + char *nativeConfig_unescaped = NULL; + const char *start; + const char *next; + char *line; + char **lines = NULL; + size_t line_count = 0; + size_t lines_alloc = 0; + char **_bhyve_argv = NULL; + char **_loader_argv = NULL; + + nativeConfig_unescaped = bhyveParseCommandLineUnescape(nativeConfig); + if (nativeConfig_unescaped == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to unescape command line string"));
Messages without formatting are not allowed (syntax-checks shows that).
+ goto error; + } + + curr = nativeConfig_unescaped; + + /* Iterate over string, splitting on sequences of '\n' */ + while (curr && *curr != '\0') { + start = curr; + next = strchr(curr, '\n'); + + if (VIR_STRNDUP(line, curr, next ? next - curr : -1) < 0) + goto error; + + if (VIR_RESIZE_N(lines, lines_alloc, line_count, 2) < 0) { + VIR_FREE(line); + goto error; + } + + if (*line) + lines[line_count++] = line; + lines[line_count] = NULL; + + while (next && (*next == '\n' || *next == '\r' + || STRPREFIX(next, "\r\n"))) + next++; + + curr = next; + } + + for (int i = 0; i < line_count; i++) { size_t + declare outside the loop.
+ curr = lines[i]; + int j;
site_t
+ char **arglist = NULL; + size_t args_count = 0; + size_t args_alloc = 0; + + /* iterate over each line, splitting on sequences of ' '. This code is + * adapted from qemu/qemu_parse_command.c. */ + while (curr && *curr != '\0') { + char *arg; + start = curr; + + if (*start == '\'') { + if (start == curr) + curr++; + next = strchr(start + 1, '\''); + } else if (*start == '"') { + if (start == curr) + curr++; + next = strchr(start + 1, '"'); + } else { + next = strchr(start, ' '); + } + + if (VIR_STRNDUP(arg, curr, next ? next - curr : -1) < 0) + goto error; + + if (next && (*next == '\'' || *next == '"')) + next++; + + if (VIR_RESIZE_N(arglist, args_alloc, args_count, 2) < 0) { + VIR_FREE(arg); + goto error; + } + + arglist[args_count++] = arg; + arglist[args_count] = NULL; + + while (next && c_isspace(*next)) + next++; + + curr = next; + } + + /* To prevent a memory leak here, only set the argument lists when + * the first matching command is found. This shouldn't really be a + * problem, since usually no multiple loaders or bhyverun commands + * are specified (this wouldn't really be valid anyways). + * Otherwise, later argument lists may be assigned to _argv without + * freeing the earlier ones. */ + if (!_bhyve_argv && STREQ(arglist[0], "/usr/sbin/bhyve")) { + if ((VIR_REALLOC_N(_bhyve_argv, args_count + 1) < 0) + || (!bhyve_argc)) + goto error; + for (j = 0; j < args_count; j++) + _bhyve_argv[j] = arglist[j]; + _bhyve_argv[j] = NULL; + *bhyve_argc = args_count-1; + } else if (!_loader_argv) { + if ((VIR_REALLOC_N(_loader_argv, args_count + 1) < 0) + || (!loader_argc)) + goto error; + for (j = 0; j < args_count; j++) + _loader_argv[j] = arglist[j]; + _loader_argv[j] = NULL; + *loader_argc = args_count-1; + } else + /* To prevent a use-after-free here, only free the argument list + * when it is definitely not going to be used */ + virStringFreeList(arglist);
Same style thing with {}.
+ } + + *loader_argv = _loader_argv; + if (!(*bhyve_argv = _bhyve_argv)) + goto error; + + virStringFreeList(lines); + return 0; + + error: + VIR_FREE(_loader_argv); + VIR_FREE(_bhyve_argv); + virStringFreeList(lines); + return -1; +} + +virDomainDefPtr +bhyveParseCommandLineString(const char* nativeConfig, + unsigned caps ATTRIBUTE_UNUSED, + virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED) +{ + virDomainDefPtr def = NULL; + int bhyve_argc = 0; + char **bhyve_argv = NULL; + int loader_argc = 0; + char **loader_argv = NULL; + + if (!(def = virDomainDefNew())) + goto cleanup; + + /* Initialize defaults. */ + def->virtType = VIR_DOMAIN_VIRT_BHYVE; + if (virUUIDGenerate(def->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to generate uuid")); + VIR_FREE(def); + goto cleanup; + } + def->id = -1; + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; + + if (bhyveCommandLineToArgv(nativeConfig, + &loader_argc, &loader_argv, + &bhyve_argc, &bhyve_argv)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to convert the command string to argv-lists.."));
Formatting + indent; double dot removed.
+ goto error; + } + +cleanup: + virStringFreeList(loader_argv); + virStringFreeList(bhyve_argv); + return def; +error: + VIR_FREE(def); + goto cleanup; +} diff --git a/src/bhyve/bhyve_parse_command.h b/src/bhyve/bhyve_parse_command.h new file mode 100644 index 0000000..7ffe26c --- /dev/null +++ b/src/bhyve/bhyve_parse_command.h @@ -0,0 +1,30 @@ +/* + * bhyve_parse_command.h: Bhyve command parser + * + * Copyright (C) 2016 Fabian Freyer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> + */ + +#ifndef __BHYVE_PARSE_COMMAND_H__ +#define __BHYVE_PARSE_COMMAND_H__
Not properly indented (should be # define).
+ +virDomainDefPtr bhyveParseCommandLineString(const char* nativeConfig, + unsigned caps, + virDomainXMLOptionPtr xmlopt); + +#endif /* __BHYVE_PARSE_COMMAND_H__*/ -- 2.5.5
Roman Bogorodskiy

A simpe getopt-based argument parser is added for the /usr/sbin/bhyve command, loosely based on its argument parser, which reads the following from the bhyve command line string: * vm name * number of vcpus * memory size * the time offset (UTC or localtime) * features: * acpi * ioapic: While this flag is deprecated in FreeBSD r257423, keep checking for it for backwards compatibiility. * the domain UUID; if not explicitely given, one will be generated. * lpc devices: for now only the com1 and com2 are supported. It is required for these to be /dev/nmdm[\d+][AB], and the slave devices are automatically inferred from these to be the corresponding end of the virtual null-modem cable: /dev/nmdm<N>A <-> /dev/nmdm<N>B * PCI devices: * Disks: these are numbered in the order they are found, for virtio and ahci disks separately. The destination is set to sdX or vdX with X='a'+index; therefore only 'z'-'a' disks are supported. Disks are considered to be block devices if the path starts with /dev, otherwise they are considered to be files. * Networks: only tap devices are supported. Since it isn't possible to tell the type of the network, VIR_DOMAIN_NET_TYPE_ETHERNET is assumed, since it is the most generic. If no mac is specified, one will be generated. Signed-off-by: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> --- src/bhyve/bhyve_parse_command.c | 512 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 510 insertions(+), 2 deletions(-) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c index 0c4d3f5..fa11443 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -3,6 +3,7 @@ * * Copyright (C) 2006-2016 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange + * Copyright (c) 2011 NetApp, Inc. * Copyright (C) 2016 Fabian Freyer * * This library is free software; you can redistribute it and/or @@ -23,6 +24,8 @@ */ #include <config.h> +#include <libutil.h> +#include <getopt_int.h> #include "bhyve_capabilities.h" #include "bhyve_command.h" @@ -84,6 +87,35 @@ bhyveParseCommandLineUnescape(const char *command) } /* + * This function is adapted from vm_parse_memsize in + * /lib/libvmmapi/vmmapi.c in the FreeBSD Source tree. + */ +static int +bhyveParseMemsize(const char *arg, size_t *ret_memsize) +{ + size_t val; + int error; + + if (virStrToLong_ul(arg, NULL, 10, &val) == 0) { + /* + * For the sake of backward compatibility if the memory size + * specified on the command line is less than a megabyte then + * it is interpreted as being in units of MB. + */ + if (val < 1024 * 1024UL) + val *= 1024 * 1024UL; + *ret_memsize = val; + error = 0; + } else + error = expand_number(arg, ret_memsize); + + /* use memory in KiB here */ + *ret_memsize /= 1024UL; + + return error; +} + +/* * Try to extract loader and bhyve argv lists from a command line string. */ static int @@ -224,10 +256,483 @@ bhyveCommandLineToArgv(const char *nativeConfig, return -1; } +static int +bhyveParseBhyveLPCArg(virDomainDefPtr def, + unsigned caps ATTRIBUTE_UNUSED, + const char *arg) +{ + /* -l emulation[,config] */ + const char *separator = NULL; + const char *param = NULL; + size_t last = 0; + virDomainChrDefPtr chr = NULL; + char *type = NULL; + + separator = strchr(arg, ','); + param = separator + 1; + + if (!separator) + goto error; + + if (VIR_STRNDUP(type, arg, separator - arg) < 0) + goto error; + + /* Only support com%d */ + if (STRPREFIX(type, "com") && type[4] == 0) { + if (!(chr = virDomainChrDefNew())) + goto error; + + chr->source.type = VIR_DOMAIN_CHR_TYPE_NMDM; + chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; + + if (!STRPREFIX(param, "/dev/nmdm")) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to set com port %s: does not start with " + "'/dev/nmdm'."), type); + goto error; + } + + if (VIR_STRDUP(chr->source.data.file.path, param) < 0) { + virDomainChrDefFree(chr); + goto error; + } + + if (VIR_STRDUP(chr->source.data.nmdm.slave, chr->source.data.file.path) + < 0) { + virDomainChrDefFree(chr); + goto error; + } + + /* If the last character of the master is 'A', the slave will be 'B' + * and vice versa */ + last = strlen(chr->source.data.file.path) - 1; + switch (chr->source.data.file.path[last]) { + case 'A': + chr->source.data.nmdm.slave[last] = 'B'; + break; + case 'B': + chr->source.data.nmdm.slave[last] = 'A'; + break; + default: + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to set slave for %s: last letter not " + "'A' or 'B'"), + chr->source.data.file.path); + goto error; + } + + switch (type[3]-'0') { + case 1: + case 2: + chr->target.port = type[3] - '1'; + break; + default: + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse %s: only com1 and com2" + "supported."), type); + virDomainChrDefFree(chr); + goto error; + break; + } + + if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) { + virDomainChrDefFree(chr); + goto error; + } + } + + VIR_FREE(type); + return 0; + +error: + VIR_FREE(chr); + VIR_FREE(type); + return -1; +} + +static int +bhyveParsePCISlot(const char *slotdef, + unsigned *pcislot, + unsigned *bus, + unsigned *function) +{ + /* slot[:function] | bus:slot:function */ + const char *curr = NULL; + const char *next = NULL; + unsigned values[3]; + int i; + + curr = slotdef; + for (i = 0; i < 3; i++) { + char *val = NULL; + + next = strchr(curr, ':'); + + if (VIR_STRNDUP(val, curr, next? next - curr : -1) < 0) + goto error; + + if (virStrToLong_ui(val, NULL, 10, &values[i]) < 0) + goto error; + + VIR_FREE(val); + + if (!next) + break; + + curr = next +1; + } + + *bus = 0; + *pcislot = 0; + *function = 0; + + switch (i + 1) { + case 2: + /* pcislot[:function] */ + *function = values[1]; + case 1: + *pcislot = values[0]; + break; + case 3: + /* bus:pcislot:function */ + *bus = values[0]; + *pcislot = values[1]; + *function = values[2]; + break; + } + + return 0; +error: + return -1; +} + +static int +bhyveParsePCIDisk(virDomainDefPtr def, + unsigned caps ATTRIBUTE_UNUSED, + unsigned pcislot, + unsigned pcibus, + unsigned function, + int bus, + int device, + unsigned *nvirtiodisk, + unsigned *nahcidisk, + char *config) +{ + /* -s slot,virtio-blk|ahci-cd|ahci-hd,/path/to/file */ + const char *separator = NULL; + int index = -1; + virDomainDiskDefPtr disk = NULL; + + if (VIR_ALLOC(disk) < 0) + goto cleanup; + if (VIR_ALLOC(disk->src) < 0) + goto error; + + disk->bus = bus; + disk->device = device; + + disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + disk->info.addr.pci.slot = pcislot; + disk->info.addr.pci.bus = pcibus; + disk->info.addr.pci.function = function; + + if (STRPREFIX(config, "/dev/")) + disk->src->type = VIR_STORAGE_TYPE_BLOCK; + else + disk->src->type = VIR_STORAGE_TYPE_FILE; + + if (!config) + goto error; + + separator = strchr(config, ','); + if (VIR_STRNDUP(disk->src->path, config, + separator? separator - config : -1) < 0) + goto error; + + if (bus == VIR_DOMAIN_DISK_BUS_VIRTIO) { + index = *nvirtiodisk; + *nvirtiodisk += 1; + if (VIR_STRDUP(disk->dst, "vda") < 0) + goto error; + } else if (bus == VIR_DOMAIN_DISK_BUS_SATA) { + index = *nahcidisk; + *nahcidisk += 1; + if (VIR_STRDUP(disk->dst, "sda") < 0) + goto error; + } + + if (index > 'z' - 'a') { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("too many disks")); + goto error; + } + + disk->dst[2] = 'a' + index; + + if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) + goto error; + +cleanup: + return 0; + +error: + virDomainDiskDefFree(disk); + return -1; +} + +static int +bhyveParsePCINet(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, + unsigned caps ATTRIBUTE_UNUSED, + unsigned pcislot, + unsigned pcibus, + unsigned function, + const char *config) +{ + /* -s slot,virtio-net,tapN[,mac=xx:xx:xx:xx:xx:xx] */ + + virDomainNetDefPtr net = NULL; + const char *separator = NULL; + const char *mac = NULL; + + if (VIR_ALLOC(net) < 0) + goto cleanup; + + /* Let's just assume it is VIR_DOMAIN_NET_TYPE_ETHERNET, it could also be + * a bridge, but this is the most generic option. */ + net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; + + net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + net->info.addr.pci.slot = pcislot; + net->info.addr.pci.bus = pcibus; + net->info.addr.pci.function = function; + + if (!config) + goto error; + + if (!STRPREFIX(config, "tap")) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Only tap devices supported.")); + goto error; + } + + separator = strchr(config, ','); + if (VIR_STRNDUP(net->ifname, config, + separator? separator - config : -1) < 0) + goto error; + + if (!separator) + goto cleanup; + + if (!STRPREFIX(++separator, "mac=")) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Only mac option can be specified for virt-net")); + goto error; + } + mac = separator + 4; + + if (virMacAddrParse(mac, &net->mac) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to parse mac address '%s'"), + mac); + goto cleanup; + } + +cleanup: + if (!mac) + virDomainNetGenerateMAC(xmlopt, &net->mac); + + if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) + goto error; + return 0; + +error: + virDomainNetDefFree(net); + return -1; +} + +static int +bhyveParseBhyvePCIArg(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, + unsigned caps, + unsigned *nvirtiodisk, + unsigned *nahcidisk, + const char *arg) +{ + /* -s slot,emulation[,conf] */ + const char *separator = NULL; + char *slotdef = NULL; + char *emulation = NULL; + char *conf = NULL; + unsigned pcislot, bus, function; + + separator = strchr(arg, ','); + + if (!separator) + goto error; + else + separator++; /* Skip comma */ + + if (VIR_STRNDUP(slotdef, arg, separator - arg - 1) < 0) + goto error; + + conf = strchr(separator+1, ','); + if (conf) + conf++; /* Skip initial comma */ + + if (VIR_STRNDUP(emulation, separator, conf? conf - separator - 1 : -1) < 0) + goto error; + + if (bhyveParsePCISlot(slotdef, &pcislot, &bus, &function) < 0) + goto error; + + if (STREQ(emulation, "ahci-cd")) + bhyveParsePCIDisk(def, caps, pcislot, bus, function, + VIR_DOMAIN_DISK_BUS_SATA, + VIR_DOMAIN_DISK_DEVICE_CDROM, + nvirtiodisk, + nahcidisk, + conf); + else if (STREQ(emulation, "ahci-hd")) + bhyveParsePCIDisk(def, caps, pcislot, bus, function, + VIR_DOMAIN_DISK_BUS_SATA, + VIR_DOMAIN_DISK_DEVICE_DISK, + nvirtiodisk, + nahcidisk, + conf); + else if (STREQ(emulation, "virtio-blk")) + bhyveParsePCIDisk(def, caps, pcislot, bus, function, + VIR_DOMAIN_DISK_BUS_VIRTIO, + VIR_DOMAIN_DISK_DEVICE_DISK, + nvirtiodisk, + nahcidisk, + conf); + else if (STREQ(emulation, "virtio-net")) + bhyveParsePCINet(def, xmlopt, caps, pcislot, bus, function, conf); + + VIR_FREE(emulation); + VIR_FREE(slotdef); + return 0; +error: + VIR_FREE(emulation); + VIR_FREE(slotdef); + return -1; +} + +/* + * Parse the /usr/sbin/bhyve command line. + */ +static int +bhyveParseBhyveCommandLine(virDomainDefPtr def, + virDomainXMLOptionPtr xmlopt, + unsigned caps, + int argc, char **argv) +{ + int c; + const char optstr[] = "abehuwxACHIPSWYp:g:c:s:m:l:U:"; + int vcpus = 1; + size_t memory = 0; + unsigned nahcidisks = 0; + unsigned nvirtiodisks = 0; + struct _getopt_data *parser; + + if (!argv) + goto error; + + if (VIR_ALLOC(parser) < 0) + goto error; + + while ((c = _getopt_internal_r(argc, argv, optstr, + NULL, NULL, 0, parser, 0)) != -1) { + switch (c) { + case 'A': + def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON; + break; + case 'c': + if (virStrToLong_i(parser->optarg, NULL, 10, &vcpus) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse number of vCPUs.")); + goto error; + } + if (virDomainDefSetVcpusMax(def, vcpus) < 0) + goto error; + if (virDomainDefSetVcpus(def, vcpus) < 0) + goto error; + break; + case 'l': + if (bhyveParseBhyveLPCArg(def, caps, parser->optarg)) + goto error; + break; + case 's': + if (bhyveParseBhyvePCIArg(def, + xmlopt, + caps, + &nahcidisks, + &nvirtiodisks, + parser->optarg)) + goto error; + break; + case 'm': + if (bhyveParseMemsize(parser->optarg, &memory)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse Memory.")); + goto error; + } + if (def->mem.cur_balloon != 0 && def->mem.cur_balloon != memory) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse Memory: Memory size mismatch.")); + goto error; + } + def->mem.cur_balloon = memory; + virDomainDefSetMemoryTotal(def, memory); + break; + case 'I': + /* While this flag was deprecated in FreeBSD r257423, keep checking + * for it for backwards compatibility. */ + def->features[VIR_DOMAIN_FEATURE_APIC] = VIR_TRISTATE_SWITCH_ON; + break; + case 'u': + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC; + break; + case 'U': + if (virUUIDParse(parser->optarg, def->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, \ + _("cannot parse UUID '%s'"), parser->optarg); + goto error; + } + break; + } + } + + if (argc != parser->optind) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse arguments for bhyve command.")); + goto error; + } + + if (def->name == NULL) { + if (VIR_STRDUP(def->name, argv[argc]) < 0) + goto error; + } else if (STRNEQ(def->name, argv[argc])) { + /* the vm name of the loader and the bhyverun command differ, throw an + * error here */ + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse arguments: VM name mismatch.")); + goto error; + } + + VIR_FREE(parser); + return 0; + +error: + VIR_FREE(parser); + return -1; +} + virDomainDefPtr bhyveParseCommandLineString(const char* nativeConfig, - unsigned caps ATTRIBUTE_UNUSED, - virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED) + unsigned caps, + virDomainXMLOptionPtr xmlopt) { virDomainDefPtr def = NULL; int bhyve_argc = 0; @@ -257,6 +762,9 @@ bhyveParseCommandLineString(const char* nativeConfig, goto error; } + if (bhyveParseBhyveCommandLine(def, xmlopt, caps, bhyve_argc, bhyve_argv)) + goto error; + cleanup: virStringFreeList(loader_argv); virStringFreeList(bhyve_argv); -- 2.5.5

A simple getopt-based argument parser is added for the /usr/sbin/bhyveload command, loosely based on its argument parser. The boot disk is guessed by iterating over all disks and matching their sources. If any non-default arguments are found, def->os.bootloaderArgs is set accordingly, and the bootloader is treated as a custom bootloader. Custom bootloader are supported by setting the def->os.bootloader and def->os.bootloaderArgs accordingly grub-bhyve is also treated as a custom bootloader. Since we don't get the device map in the native format anyways, we can't reconstruct the complete boot order. While it is possible to check what type the grub boot disk is by checking if the --root argument is "cd" or "hd0,msdos1", and then just use the first disk found, implementing the grub-bhyve argument parser as-is in the grub-bhyve source would mean adding a dependency to argp or duplicating lots of the code of argp. Therefore it's not really worth implementing that now. Signed-off-by: Fabian Freyer <fabian.freyer@physik.tu-berlin.de> --- src/bhyve/bhyve_parse_command.c | 117 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c index fa11443..d3a9bb7 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -729,6 +729,116 @@ error: return -1; } +/* + * Parse the /usr/sbin/bhyveload command line. + */ +static int +bhyveParseBhyveLoadCommandLine(virDomainDefPtr def, + int argc, char **argv) +{ + int c; + /* bhyveload called with default arguments when only -m and -d are given. + * Store this in a bit field and check if only those two options are given + * later */ + unsigned arguments = 0; + size_t memory = 0; + struct _getopt_data *parser; + int i = 0; + + const char optstr[] = "CSc:d:e:h:l:m:"; + + if (!argv) + goto error; + + if (VIR_ALLOC(parser) < 0) + goto error; + + while ((c = _getopt_internal_r(argc, argv, optstr, + NULL, NULL, 0, parser, 0)) != -1) { + switch (c) { + case 'd': + arguments |= 1; + /* Iterate over the disks of the domain trying to match up the + * source */ + for (i = 0; i < def->ndisks; i++) { + if (STREQ(virDomainDiskGetSource(def->disks[i]), + parser->optarg)) { + def->disks[i]->info.bootIndex = i; + break; + } + } + break; + case 'm': + arguments |= 2; + if (bhyveParseMemsize(parser->optarg, &memory)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse Memory.")); + goto error; + } + if (def->mem.cur_balloon != 0 && def->mem.cur_balloon != memory) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse Memory: Memory size mismatch.")); + goto error; + } + def->mem.cur_balloon = memory; + virDomainDefSetMemoryTotal(def, memory); + break; + default: + arguments |= 4; + } + } + + if (arguments != 3) { + /* Set os.bootloader since virDomainDefFormatInternal will only format + * the bootloader arguments if os->bootloader is set. */ + if (VIR_STRDUP(def->os.bootloader, argv[0]) < 0) + goto error; + + def->os.bootloaderArgs = virStringJoin((const char**) &argv[1], " "); + } + + if (argc != parser->optind) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse arguments for bhyveload command.")); + goto error; + } + + if (def->name == NULL) { + if (VIR_STRDUP(def->name, argv[argc]) < 0) + goto error; + } else if (STRNEQ(def->name, argv[argc])) { + /* the vm name of the loader and the bhyverun command differ, throw an + * error here */ + virReportError(VIR_ERR_OPERATION_FAILED, + _("Failed to parse arguments: VM name mismatch.")); + goto error; + } + + VIR_FREE(parser); + return 0; +error: + VIR_FREE(parser); + return -1; +} + +static int +bhyveParseCustomLoaderCommandLine(virDomainDefPtr def, + int argc ATTRIBUTE_UNUSED, + char **argv) +{ + if (!argv) + goto error; + + if (VIR_STRDUP(def->os.bootloader, argv[0]) < 0) + goto error; + + def->os.bootloaderArgs = virStringJoin((const char**) &argv[1], " "); + + return 0; +error: + return -1; +} + virDomainDefPtr bhyveParseCommandLineString(const char* nativeConfig, unsigned caps, @@ -764,6 +874,13 @@ bhyveParseCommandLineString(const char* nativeConfig, if (bhyveParseBhyveCommandLine(def, xmlopt, caps, bhyve_argc, bhyve_argv)) goto error; + if (loader_argv && STREQ(loader_argv[0], "/usr/sbin/bhyveload")) { + if (bhyveParseBhyveLoadCommandLine(def, loader_argc, loader_argv)) + goto error; + } + else if (loader_argv) + if (bhyveParseCustomLoaderCommandLine(def, loader_argc, loader_argv)) + goto error; cleanup: virStringFreeList(loader_argv); -- 2.5.5

--- tests/Makefile.am | 23 ++- .../bhyveargv2xmldata/bhyveargv2xml-acpiapic.args | 9 + tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.xml | 20 ++ tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.xml | 21 ++ tests/bhyveargv2xmldata/bhyveargv2xml-base.args | 7 + tests/bhyveargv2xmldata/bhyveargv2xml-base.xml | 16 ++ .../bhyveargv2xml-bhyveload-bootorder.args | 13 ++ .../bhyveargv2xml-bhyveload-bootorder.xml | 27 +++ .../bhyveargv2xml-bhyveload-custom.args | 11 ++ .../bhyveargv2xml-bhyveload-custom.xml | 18 ++ .../bhyveargv2xml-bhyveload-mem-mismatch.args | 12 ++ .../bhyveargv2xml-bhyveload-memsize-fail.args | 12 ++ .../bhyveargv2xml-bhyveload-name-mismatch.args | 12 ++ .../bhyveargv2xml-bhyveload-vda.args | 12 ++ .../bhyveargv2xml-bhyveload-vda.xml | 21 ++ .../bhyveargv2xml-bhyverun-mem-mismatch.args | 12 ++ .../bhyveargv2xml-bhyverun-name-mismatch.args | 12 ++ tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.xml | 21 ++ tests/bhyveargv2xmldata/bhyveargv2xml-console.args | 10 + tests/bhyveargv2xmldata/bhyveargv2xml-console.xml | 28 +++ .../bhyveargv2xmldata/bhyveargv2xml-console2.args | 10 + tests/bhyveargv2xmldata/bhyveargv2xml-console2.xml | 15 ++ .../bhyveargv2xmldata/bhyveargv2xml-console3.args | 11 ++ tests/bhyveargv2xmldata/bhyveargv2xml-console3.xml | 27 +++ .../bhyveargv2xmldata/bhyveargv2xml-console4.args | 10 + tests/bhyveargv2xmldata/bhyveargv2xml-console4.xml | 15 ++ .../bhyveargv2xml-custom-loader.args | 8 + .../bhyveargv2xml-custom-loader.xml | 18 ++ .../bhyveargv2xml-disk-toomany.args | 34 ++++ .../bhyveargv2xml-disk-toomany.xml | 146 ++++++++++++++ .../bhyveargv2xmldata/bhyveargv2xml-extraargs.args | 8 + .../bhyveargv2xml-memsize-fail.args | 7 + .../bhyveargv2xml-memsize-human.args | 7 + .../bhyveargv2xml-memsize-human.xml | 16 ++ .../bhyveargv2xml-memsize-large.args | 7 + .../bhyveargv2xml-memsize-large.xml | 16 ++ tests/bhyveargv2xmldata/bhyveargv2xml-name.args | 7 + tests/bhyveargv2xmldata/bhyveargv2xml-name.xml | 16 ++ tests/bhyveargv2xmldata/bhyveargv2xml-oneline.args | 1 + tests/bhyveargv2xmldata/bhyveargv2xml-oneline.xml | 16 ++ tests/bhyveargv2xmldata/bhyveargv2xml-utc.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-utc.xml | 16 ++ tests/bhyveargv2xmldata/bhyveargv2xml-uuid.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-uuid.xml | 16 ++ tests/bhyveargv2xmldata/bhyveargv2xml-uuid2.args | 8 + tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.args | 7 + tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.xml | 16 ++ .../bhyveargv2xml-virtio-blk.args | 8 + .../bhyveargv2xmldata/bhyveargv2xml-virtio-blk.xml | 21 ++ .../bhyveargv2xml-virtio-net.args | 9 + .../bhyveargv2xmldata/bhyveargv2xml-virtio-net.xml | 26 +++ .../bhyveargv2xml-virtio-net2.args | 8 + .../bhyveargv2xml-virtio-net2.xml | 16 ++ .../bhyveargv2xml-virtio-net3.args | 8 + .../bhyveargv2xml-virtio-net3.xml | 16 ++ .../bhyveargv2xml-virtio-net4.args | 8 + .../bhyveargv2xml-virtio-net4.xml | 21 ++ tests/bhyveargv2xmlmock.c | 27 +++ tests/bhyveargv2xmltest.c | 213 +++++++++++++++++++++ 61 files changed, 1185 insertions(+), 3 deletions(-) create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-base.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-base.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-mem-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-memsize-fail.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-name-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-mem-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-name-mismatch.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console2.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console2.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console3.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console3.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console4.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-console4.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-extraargs.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-fail.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-name.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-name.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-oneline.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-oneline.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-utc.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-utc.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-uuid.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-uuid.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-uuid2.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.xml create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.args create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.xml create mode 100644 tests/bhyveargv2xmlmock.c create mode 100644 tests/bhyveargv2xmltest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 444e0fd..34e46c3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -86,6 +86,7 @@ MOCKLIBS_LIBS = \ EXTRA_DIST = \ .valgrind.supp \ bhyvexml2argvdata \ + bhyveargv2xmldata \ bhyvexml2xmloutdata \ capabilityschemadata \ commanddata \ @@ -284,7 +285,7 @@ test_programs += vmwarevertest endif WITH_VMWARE if WITH_BHYVE -test_programs += bhyvexml2argvtest bhyvexml2xmltest +test_programs += bhyvexml2argvtest bhyvexml2xmltest bhyveargv2xmltest endif WITH_BHYVE if WITH_CIL @@ -415,7 +416,7 @@ test_libraries += libqemumonitortestutils.la \ endif WITH_QEMU if WITH_BHYVE -test_libraries += bhyvexml2argvmock.la +test_libraries += bhyvexml2argvmock.la bhyveargv2xmlmock.la endif WITH_BHYVE if WITH_DBUS @@ -741,6 +742,12 @@ bhyvexml2argvmock_la_CFLAGS = $(AM_CFLAGS) bhyvexml2argvmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) bhyvexml2argvmock_la_LIBADD = $(MOCKLIBS_LIBS) +bhyveargv2xmlmock_la_SOURCES = \ + bhyveargv2xmlmock.c +bhyveargv2xmlmock_la_CFLAGS = $(AM_CFLAGS) +bhyveargv2xmlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) +bhyveargv2xmlmock_la_LIBADD = $(MOCKLIBS_LIBS) + bhyve_LDADDS = ../src/libvirt_driver_bhyve_impl.la if WITH_STORAGE bhyve_LDADDS += ../src/libvirt_driver_storage_impl.la @@ -755,8 +762,18 @@ bhyvexml2xmltest_SOURCES = \ bhyvexml2xmltest.c \ testutils.c testutils.h bhyvexml2xmltest_LDADD = $(bhyve_LDADDS) + +bhyveargv2xmltest_SOURCES = \ + bhyveargv2xmltest.c \ + testutils.c testutils.h +bhyveargv2xmltest_LDADD = $(bhyve_LDADDS) else ! WITH_BHYVE -EXTRA_DIST += bhyvexml2argvtest.c bhyvexml2xmltest.c bhyvexml2argvmock.c +EXTRA_DIST += \ + bhyvexml2argvtest.c \ + bhyveargv2xmltest.c \ + bhyvexml2xmltest.c \ + bhyvexml2argvmock.c \ + bhyveargv2xmlmock.c endif ! WITH_BHYVE networkxml2xmltest_SOURCES = \ diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.args b/tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.args new file mode 100644 index 0000000..cf3ec61 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.args @@ -0,0 +1,9 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-A \ +-I \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.xml new file mode 100644 index 0000000..d6c940f --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-acpiapic.xml @@ -0,0 +1,20 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <features> + <acpi/> + <apic/> + </features> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.args b/tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.args new file mode 100644 index 0000000..9924203 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,ahci-hd,/tmp/freebsd.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.xml new file mode 100644 index 0000000..fcf0fee --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-ahci-hd.xml @@ -0,0 +1,21 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='sda' bus='sata'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-base.args b/tests/bhyveargv2xmldata/bhyveargv2xml-base.args new file mode 100644 index 0000000..1334030 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-base.args @@ -0,0 +1,7 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-base.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-base.xml new file mode 100644 index 0000000..68d9f10 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-base.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.args new file mode 100644 index 0000000..aefa827 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.args @@ -0,0 +1,13 @@ +/usr/sbin/bhyveload \ +-m 214 \ +-d /tmp/disk2.img \ +bhyve +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/disk1.img \ +-s 3:0,virtio-blk,/tmp/disk2.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.xml new file mode 100644 index 0000000..3d7a67e --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-bootorder.xml @@ -0,0 +1,27 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/tmp/disk1.img'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/disk2.img'/> + <target dev='vdb' bus='virtio'/> + <boot order='1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </disk> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.args new file mode 100644 index 0000000..0185b83 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.args @@ -0,0 +1,11 @@ +/usr/sbin/bhyveload \ +-m 214 \ +-S \ +bhyve +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.xml new file mode 100644 index 0000000..077c089 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-custom.xml @@ -0,0 +1,18 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <bootloader>/usr/sbin/bhyveload</bootloader> + <bootloader_args>-m 214 -S bhyve</bootloader_args> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-mem-mismatch.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-mem-mismatch.args new file mode 100644 index 0000000..a87ccd7 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-mem-mismatch.args @@ -0,0 +1,12 @@ +/usr/sbin/bhyveload \ +-m 412 \ +-d /tmp/freebsd.img \ +bhyve +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-memsize-fail.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-memsize-fail.args new file mode 100644 index 0000000..11b1799 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-memsize-fail.args @@ -0,0 +1,12 @@ +/usr/sbin/bhyveload \ +-m bogus \ +-d /tmp/freebsd.img \ +bhyve +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-name-mismatch.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-name-mismatch.args new file mode 100644 index 0000000..dbd9a22 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-name-mismatch.args @@ -0,0 +1,12 @@ +/usr/sbin/bhyveload \ +-m 214 \ +-d /tmp/freebsd.img \ +bhyve +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +othervm diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.args new file mode 100644 index 0000000..7535f86 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.args @@ -0,0 +1,12 @@ +/usr/sbin/bhyveload \ +-m 214 \ +-d /tmp/freebsd.img \ +bhyve +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.xml new file mode 100644 index 0000000..adbf7f1 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyveload-vda.xml @@ -0,0 +1,21 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-mem-mismatch.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-mem-mismatch.args new file mode 100644 index 0000000..d666b02 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-mem-mismatch.args @@ -0,0 +1,12 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 412 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +bhyve +/usr/sbin/bhyveload \ +-m 214 \ +-d /tmp/freebsd.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-name-mismatch.args b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-name-mismatch.args new file mode 100644 index 0000000..52e8b7b --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-bhyverun-name-mismatch.args @@ -0,0 +1,12 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +bhyve +/usr/sbin/bhyveload \ +-m 214 \ +-d /tmp/freebsd.img \ +othervm diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.args b/tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.args new file mode 100644 index 0000000..0c3178e --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,ahci-cd,/tmp/freebsd.iso \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.xml new file mode 100644 index 0000000..b42b79b --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-cdrom.xml @@ -0,0 +1,21 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='cdrom'> + <source file='/tmp/freebsd.iso'/> + <target dev='sda' bus='sata'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console.args b/tests/bhyveargv2xmldata/bhyveargv2xml-console.args new file mode 100644 index 0000000..40617a6 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console.args @@ -0,0 +1,10 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1,lpc \ +-l com1,/dev/nmdm0A \ +-l com2,/dev/nmdm1B \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-console.xml new file mode 100644 index 0000000..916db9f --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console.xml @@ -0,0 +1,28 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <serial type='nmdm'> + <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/> + <target port='0'/> + </serial> + <serial type='nmdm'> + <source master='/dev/nmdm1B' slave='/dev/nmdm1A'/> + <target port='1'/> + </serial> + <console type='nmdm'> + <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/> + <target type='serial' port='0'/> + </console> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console2.args b/tests/bhyveargv2xmldata/bhyveargv2xml-console2.args new file mode 100644 index 0000000..fd86c40 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console2.args @@ -0,0 +1,10 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1,lpc \ +-l com1,/dev/nmdm0C \ +-l com2,/dev/nmdm1D \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console2.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-console2.xml new file mode 100644 index 0000000..12467e9 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console2.xml @@ -0,0 +1,15 @@ +<domain type='bhyve'> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console3.args b/tests/bhyveargv2xmldata/bhyveargv2xml-console3.args new file mode 100644 index 0000000..2e428c4 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console3.args @@ -0,0 +1,11 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1,lpc \ +-l com1,/dev/nmdm0A \ +-l com2,/dev/nmdm1B \ +-l com3,/dev/nmdm2B \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console3.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-console3.xml new file mode 100644 index 0000000..2aea6c4 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console3.xml @@ -0,0 +1,27 @@ +<domain type='bhyve'> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <serial type='nmdm'> + <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/> + <target port='0'/> + </serial> + <serial type='nmdm'> + <source master='/dev/nmdm1B' slave='/dev/nmdm1A'/> + <target port='1'/> + </serial> + <console type='nmdm'> + <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/> + <target type='serial' port='0'/> + </console> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console4.args b/tests/bhyveargv2xmldata/bhyveargv2xml-console4.args new file mode 100644 index 0000000..f02ef71 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console4.args @@ -0,0 +1,10 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1,lpc \ +-l com1,/dev/whatever0A \ +-l com2,/dev/whatever1B \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-console4.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-console4.xml new file mode 100644 index 0000000..12467e9 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-console4.xml @@ -0,0 +1,15 @@ +<domain type='bhyve'> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.args b/tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.args new file mode 100644 index 0000000..ed6398b --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.args @@ -0,0 +1,8 @@ +/usr/bin/custom-loader with several arguments +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.xml new file mode 100644 index 0000000..3e9bd29 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-custom-loader.xml @@ -0,0 +1,18 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <bootloader>/usr/bin/custom-loader</bootloader> + <bootloader_args>with several arguments</bootloader_args> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.args b/tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.args new file mode 100644 index 0000000..5cdefb6 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.args @@ -0,0 +1,34 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1:0,virtio-blk,/tmp/freebsd.img \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +-s 3:0,virtio-blk,/tmp/freebsd.img \ +-s 4:0,virtio-blk,/tmp/freebsd.img \ +-s 5:0,virtio-blk,/tmp/freebsd.img \ +-s 6:0,virtio-blk,/tmp/freebsd.img \ +-s 7:0,virtio-blk,/tmp/freebsd.img \ +-s 8:0,virtio-blk,/tmp/freebsd.img \ +-s 9:0,virtio-blk,/tmp/freebsd.img \ +-s 10:0,virtio-blk,/tmp/freebsd.img \ +-s 11:0,virtio-blk,/tmp/freebsd.img \ +-s 12:0,virtio-blk,/tmp/freebsd.img \ +-s 13:0,virtio-blk,/tmp/freebsd.img \ +-s 14:0,virtio-blk,/tmp/freebsd.img \ +-s 15:0,virtio-blk,/tmp/freebsd.img \ +-s 16:0,virtio-blk,/tmp/freebsd.img \ +-s 17:0,virtio-blk,/tmp/freebsd.img \ +-s 18:0,virtio-blk,/tmp/freebsd.img \ +-s 19:0,virtio-blk,/tmp/freebsd.img \ +-s 20:0,virtio-blk,/tmp/freebsd.img \ +-s 21:0,virtio-blk,/tmp/freebsd.img \ +-s 22:0,virtio-blk,/tmp/freebsd.img \ +-s 23:0,virtio-blk,/tmp/freebsd.img \ +-s 24:0,virtio-blk,/tmp/freebsd.img \ +-s 25:0,virtio-blk,/tmp/freebsd.img \ +-s 26:0,virtio-blk,/tmp/freebsd.img \ +-s 27:0,virtio-blk,/tmp/freebsd.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.xml new file mode 100644 index 0000000..6e0c06c --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-disk-toomany.xml @@ -0,0 +1,146 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdb' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdc' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdd' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vde' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdf' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdg' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdh' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdi' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdj' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdk' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdl' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdm' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0d' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdn' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0e' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdo' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x0f' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdp' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdq' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x11' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdr' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x12' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vds' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x13' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdt' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x14' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdu' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x15' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdv' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x16' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdw' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x17' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdx' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x18' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdy' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x19' function='0x0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vdz' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x1a' function='0x0'/> + </disk> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-extraargs.args b/tests/bhyveargv2xmldata/bhyveargv2xml-extraargs.args new file mode 100644 index 0000000..1c3d7c6 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-extraargs.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve \ +bogus diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-fail.args b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-fail.args new file mode 100644 index 0000000..9e5c02c --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-fail.args @@ -0,0 +1,7 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m bogus \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.args b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.args new file mode 100644 index 0000000..f31343e --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.args @@ -0,0 +1,7 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214M \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.xml new file mode 100644 index 0000000..68d9f10 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-human.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.args b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.args new file mode 100644 index 0000000..ffdc4f0 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.args @@ -0,0 +1,7 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 224395264 \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.xml new file mode 100644 index 0000000..68d9f10 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-memsize-large.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-name.args b/tests/bhyveargv2xmldata/bhyveargv2xml-name.args new file mode 100644 index 0000000..f08d93a --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-name.args @@ -0,0 +1,7 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +name diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-name.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-name.xml new file mode 100644 index 0000000..e241f2b --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-name.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>name</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-oneline.args b/tests/bhyveargv2xmldata/bhyveargv2xml-oneline.args new file mode 100644 index 0000000..d7e5434 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-oneline.args @@ -0,0 +1 @@ +/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-oneline.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-oneline.xml new file mode 100644 index 0000000..68d9f10 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-oneline.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-utc.args b/tests/bhyveargv2xmldata/bhyveargv2xml-utc.args new file mode 100644 index 0000000..0f8b963 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-utc.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-u \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-utc.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-utc.xml new file mode 100644 index 0000000..8e4e1a3 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-utc.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-uuid.args b/tests/bhyveargv2xmldata/bhyveargv2xml-uuid.args new file mode 100644 index 0000000..841ec3e --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-uuid.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-U 2a793ea6-8e52-440a-8458-355e98492e17 \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-uuid.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-uuid.xml new file mode 100644 index 0000000..2a1dd9f --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-uuid.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>2a793ea6-8e52-440a-8458-355e98492e17</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-uuid2.args b/tests/bhyveargv2xmldata/bhyveargv2xml-uuid2.args new file mode 100644 index 0000000..5925404 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-uuid2.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-U garbage \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.args b/tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.args new file mode 100644 index 0000000..1fb2bc6 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.args @@ -0,0 +1,7 @@ +/usr/sbin/bhyve \ +-c 4 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.xml new file mode 100644 index 0000000..1b83940 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vcpus.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>4</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.args b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.args new file mode 100644 index 0000000..c6c6f77 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,virtio-blk,/tmp/freebsd.img \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.xml new file mode 100644 index 0000000..adbf7f1 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-blk.xml @@ -0,0 +1,21 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='/tmp/freebsd.img'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.args b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.args new file mode 100644 index 0000000..db7929e --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.args @@ -0,0 +1,9 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1:0,virtio-net,tap0 \ +-s 1:1,virtio-net,tap1,mac=FE:ED:AD:EA:DF:15 \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.xml new file mode 100644 index 0000000..09cc79b --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net.xml @@ -0,0 +1,26 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <interface type='ethernet'> + <mac address='52:54:00:00:00:00'/> + <target dev='tap0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> + </interface> + <interface type='ethernet'> + <mac address='fe:ed:ad:ea:df:15'/> + <target dev='tap1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </interface> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.args b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.args new file mode 100644 index 0000000..f4488c8 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1:0,virtio-net,notatap \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.xml new file mode 100644 index 0000000..68d9f10 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net2.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.args b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.args new file mode 100644 index 0000000..e873587 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1:1,virtio-net,tap1,notamac \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.xml new file mode 100644 index 0000000..68d9f10 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net3.xml @@ -0,0 +1,16 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.args b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.args new file mode 100644 index 0000000..0b7921b --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.args @@ -0,0 +1,8 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 1:1,virtio-net,tap1,mac=garbage \ +bhyve diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.xml b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.xml new file mode 100644 index 0000000..e1bda46 --- /dev/null +++ b/tests/bhyveargv2xmldata/bhyveargv2xml-virtio-net4.xml @@ -0,0 +1,21 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>hvm</type> + </os> + <clock offset='localtime'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>destroy</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <interface type='ethernet'> + <mac address='00:00:00:00:00:00'/> + <target dev='tap1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </interface> + </devices> +</domain> diff --git a/tests/bhyveargv2xmlmock.c b/tests/bhyveargv2xmlmock.c new file mode 100644 index 0000000..1f08beb --- /dev/null +++ b/tests/bhyveargv2xmlmock.c @@ -0,0 +1,27 @@ +#include <config.h> + +#include "virnetdev.h" +#include "internal.h" +#include "util/viruuid.h" + +#define VIR_FROM_THIS VIR_FROM_BHYVE + +void +virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN], + virMacAddrPtr addr) +{ + addr->addr[0] = prefix[0]; + addr->addr[1] = prefix[1]; + addr->addr[2] = prefix[2]; + addr->addr[3] = 0; + addr->addr[4] = 0; + addr->addr[5] = 0; +} + +int +virUUIDGenerate(unsigned char *uuid) +{ + if (virUUIDParse("c7a5fdbd-edaf-9455-926a-d65c16db1809", uuid) < 0) + return -1; + return 0; +} diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c new file mode 100644 index 0000000..bbcd0a6 --- /dev/null +++ b/tests/bhyveargv2xmltest.c @@ -0,0 +1,213 @@ +#include <config.h> + +#include "testutils.h" + +#ifdef WITH_BHYVE + +# include "datatypes.h" + +# include "util/viruuid.h" +# include "bhyve/bhyve_driver.h" +# include "bhyve/bhyve_capabilities.h" +# include "bhyve/bhyve_utils.h" +# include "bhyve/bhyve_parse_command.h" + +# define VIR_FROM_THIS VIR_FROM_BHYVE + +static bhyveConn driver; + +typedef enum { + FLAG_EXPECT_FAILURE = 1, + FLAG_EXPECT_PARSE_ERROR = 2, + FLAG_EXPECT_WARNING = 4, +} virBhyveArgv2XMLTestFlags; + +static int +testCompareXMLToArgvFiles(const char *xmlfile, + const char *cmdfile, + unsigned int flags) + +{ + char *actualxml = NULL; + char *cmd = NULL; + char *log = NULL; + int ret = -1; + virDomainDefPtr vmdef = NULL; + + if (virTestLoadFile(cmdfile, &cmd) < 0) + goto fail; + + if (!(vmdef = bhyveParseCommandLineString(cmd, driver.bhyvecaps, + driver.xmlopt))) { + if ((flags & FLAG_EXPECT_FAILURE) && !virTestOOMActive()) { + VIR_TEST_DEBUG("Got expected failure from " + "bhyveParseCommandLineString.\n"); + } else + goto fail; + } else if ((flags & FLAG_EXPECT_FAILURE) && !virTestOOMActive()) { + VIR_TEST_DEBUG("Did not get expected failure from " + "bhyveParseCommandLineString.\n"); + goto fail; + } + + if (!virTestOOMActive()) { + if ((log = virTestLogContentAndReset()) == NULL) + goto fail; + if (flags & FLAG_EXPECT_WARNING) { + if (*log) { + VIR_TEST_DEBUG("Got expected warning from " + "bhyveParseCommandLineString:\n%s", + log); + } else { + VIR_TEST_DEBUG("bhyveParseCommandLineString " + "should have logged a warning\n"); + goto fail; + } + } else { /* didn't expect a warning */ + if (*log) { + VIR_TEST_DEBUG("Got unexpected warning from " + "bhyveParseCommandLineString:\n%s", + log); + goto fail; + } + } + } + + if (vmdef && !virDomainDefCheckABIStability(vmdef, vmdef)) { + VIR_TEST_DEBUG("ABI stability check failed on %s", xmlfile); + goto fail; + } + + if (vmdef && !(actualxml = virDomainDefFormat(vmdef, driver.caps, 0))) + goto fail; + + if (vmdef && virTestCompareToFile(actualxml, xmlfile) < 0) + goto fail; + + ret = 0; + + fail: + VIR_FREE(actualxml); + VIR_FREE(cmd); + VIR_FREE(log); + virDomainDefFree(vmdef); + return ret; +} + +struct testInfo { + const char *name; + unsigned int flags; +}; + +static int +testCompareXMLToArgvHelper(const void *data) +{ + int result = -1; + const struct testInfo *info = data; + char *xml = NULL; + char *args = NULL; + + if (virAsprintf(&xml, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.xml", + abs_srcdir, info->name) < 0 || + virAsprintf(&args, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.args", + abs_srcdir, info->name) < 0) + goto cleanup; + + result = testCompareXMLToArgvFiles(xml, args, info->flags); + + cleanup: + VIR_FREE(xml); + VIR_FREE(args); + return result; +} + +static int +mymain(void) +{ + int ret = 0; + + if ((driver.caps = virBhyveCapsBuild()) == NULL) + return EXIT_FAILURE; + + if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)) == NULL) + return EXIT_FAILURE; + +# define DO_TEST_FULL(name, flags) \ + do { \ + static struct testInfo info = { \ + name, (flags) \ + }; \ + if (virTestRun("BHYVE ARGV-2-XML " name, \ + testCompareXMLToArgvHelper, &info) < 0) \ + ret = -1; \ + } while (0) + +# define DO_TEST(name) \ + DO_TEST_FULL(name, 0) + +# define DO_TEST_FAIL(name) \ + DO_TEST_FULL(name, 5) + +# define DO_TEST_WARN(name) \ + DO_TEST_FULL(name, 4) + +# define DO_TEST_FAIL_SILENT(name) \ + DO_TEST_FULL(name, 1) + +# define DO_TEST_PARSE_ERROR(name) \ + DO_TEST_FULL(name, 2) + + driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV; + driver.bhyvecaps = BHYVE_CAP_RTC_UTC; + + DO_TEST("base"); + DO_TEST("oneline"); + DO_TEST("name"); + DO_TEST("console"); + DO_TEST_FAIL("console2"); + DO_TEST_FAIL("console3"); + DO_TEST_FAIL("console4"); + DO_TEST("acpiapic"); + DO_TEST("utc"); + DO_TEST("vcpus"); + DO_TEST("cdrom"); + DO_TEST("ahci-hd"); + DO_TEST("virtio-blk"); + DO_TEST("virtio-net"); + DO_TEST_WARN("virtio-net2"); + DO_TEST_WARN("virtio-net3"); + DO_TEST_WARN("virtio-net4"); + DO_TEST_WARN("disk-toomany"); + DO_TEST("uuid"); + DO_TEST_FAIL("uuid2"); + DO_TEST("memsize-large"); + DO_TEST("memsize-human"); + DO_TEST_FAIL("memsize-fail"); + DO_TEST("custom-loader"); + DO_TEST("bhyveload-custom"); + DO_TEST("bhyveload-vda"); + DO_TEST_FAIL("bhyveload-name-mismatch"); + DO_TEST_FAIL("bhyverun-name-mismatch"); + DO_TEST_FAIL("bhyveload-mem-mismatch"); + DO_TEST_FAIL("bhyverun-mem-mismatch"); + DO_TEST_FAIL("bhyveload-mem-mismatch"); + DO_TEST_FAIL("bhyveload-memsize-fail"); + DO_TEST("bhyveload-bootorder"); + DO_TEST_FAIL("extraargs"); + + virObjectUnref(driver.caps); + virObjectUnref(driver.xmlopt); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyveargv2xmlmock.so") + +#else + +int main(void) +{ + return EXIT_AM_SKIP; +} + +#endif /* WITH_BHYVE */ -- 2.5.5
participants (2)
-
Fabian Freyer
-
Roman Bogorodskiy