Re: [PATCH 4/4] bhyve: add VNC password support

2020-05-06 Thread Fabian Freyer

On 6 May 2020, at 15:41, Daniel P. Berrangé wrote:
On Linux at least, providing passwords on the command line is 
considered

a security flaw, because any user can see the command line args of any
other process on the host.


Agreed. The only reason bhyve supports this is to support VNC clients 
that don’t support password-less authentication. Since it doesn’t 
have any configuration file, and stdin may be used by the client, I’m 
unsure what the alternative would be.


If CLI args of processes are similarly visible to other users on 
FreeBSD,

then this VNC password would be a security flaw.
They are by default, however FreeBSD does have a sysctl that disallows 
seeing other user’s processes. Since a few versions, users can easily 
configure this sysctl in the FreeBSD installer.


Of course VNC password auth scheme itself is a security flaw since it 
is

using Single-DES :-)


The bhyve(8) man page states that too:

This type of authentication is known to be cryptographically weak and 
is
not intended for use on untrusted networks.  Many implementations will 
want
to use stronger security, such as running the session over an 
encrypted

channel provided by IPsec or SSH.


(On a side note, it seems that Single-DES got even more broken recently: 
https://eprint.iacr.org/2020/523)


I guess this is something that should probably also be added to that man 
page.
Should we add a comment about this as well as the password being visible 
to the docs on libvirt’s side?





[PATCH 1/4] bhyve: support parsing fbuf PCI device

2020-05-06 Thread Fabian Freyer
Add a new helper function, bhyveParsePCIFbuf, to parse the bhyve-argv
parameters for a frame-buffer device to  and 
definitions.

For now, only the listen address, port, and vga mode are detected.
Unsupported parameters are silently skipped.

This involves upgrading the private API to expose the
virDomainGraphicsDefNew helper function, which is used by
bhyveParsePCIFbuf.

Signed-off-by: Fabian Freyer 
---
 src/bhyve/bhyve_parse_command.c   | 91 ++-
 src/libvirt_private.syms  |  1 +
 .../bhyveargv2xml-vnc-listen.args | 10 ++
 .../bhyveargv2xml-vnc-listen.xml  | 22 +
 .../bhyveargv2xml-vnc-vga-io.args | 10 ++
 .../bhyveargv2xml-vnc-vga-io.xml  | 22 +
 .../bhyveargv2xml-vnc-vga-off.args| 10 ++
 .../bhyveargv2xml-vnc-vga-off.xml | 23 +
 .../bhyveargv2xml-vnc-vga-on.args | 10 ++
 .../bhyveargv2xml-vnc-vga-on.xml  | 23 +
 .../bhyveargv2xmldata/bhyveargv2xml-vnc.args  | 10 ++
 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml | 22 +
 tests/bhyveargv2xmltest.c |  5 +
 13 files changed, 258 insertions(+), 1 deletion(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 76423730d9..39cce67ea9 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -4,7 +4,7 @@
  * Copyright (C) 2006-2016 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  * Copyright (c) 2011 NetApp, Inc.
- * Copyright (C) 2016 Fabian Freyer
+ * Copyright (C) 2020 Fabian Freyer
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -552,6 +552,93 @@ bhyveParsePCINet(virDomainDefPtr def,
 return -1;
 }
 
+static int
+bhyveParsePCIFbuf(virDomainDefPtr def,
+  virDomainXMLOptionPtr xmlopt,
+  unsigned caps G_GNUC_UNUSED,
+  unsigned bus,
+  unsigned slot,
+  unsigned function,
+  const char *config)
+{
+/* -s slot,fbuf,wait,vga=on|io|off,rfb=:port,w=width,h=height */
+
+virDomainVideoDefPtr video = NULL;
+virDomainGraphicsDefPtr graphics = NULL;
+char **params = NULL;
+char *param = NULL, *separator = NULL;
+size_t nparams = 0;
+unsigned int i = 0;
+
+if (!(video = virDomainVideoDefNew(xmlopt)))
+goto cleanup;
+
+if (!(graphics = virDomainGraphicsDefNew(xmlopt)))
+goto cleanup;
+
+graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
+video->info.addr.pci.bus = bus;
+video->info.addr.pci.slot = slot;
+video->info.addr.pci.function = function;
+
+if (!config)
+goto error;
+
+if (!(params = virStringSplitCount(config, ",", 0, &nparams)))
+goto error;
+
+for (i = 0; i < nparams; i++) {
+param = params[i];
+if (!video->driver && VIR_ALLOC(video->driver) < 0)
+goto error;
+
+if (STREQ(param, "vga=on"))
+video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_ON;
+
+if (STREQ(param, "vga=io"))
+video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_IO;
+
+if (STREQ(param, "vga=off"))
+video->driver->vgaconf = VIR_DOMAIN_VIDEO_VGACONF_OFF;
+
+if (STRPREFIX(param, "rfb=") || STRPREFIX(param, "tcp=")) {
+/* fortunately, this is the same length as "tcp=" */
+param += strlen("rfb=");
+
+if (!(separator = strchr(param, ':')))
+goto error;
+
+*separator = '\0';
+
+if (separator != param)
+virDomainGraphicsListenAppendAddress(graphics, param);
+else
+/* Default to 127.0.0.1, just like bhyve does */
+virDomainGraphicsListenAppendAddress(graphics, "127.0.0.1");
+
+param = ++separator;
+if (virStrToLong_i(param, NULL, 10, &graphics->data.vnc.port))
+goto error;
+}
+}
+
+ cleanup:
+if (VIR

[PATCH 0/4] bhyve: framebuffer resolution and VNC password

2020-05-06 Thread Fabian Freyer
Add support for setting the bhyve framebuffer resolution and probe
whether bhyve supports VNC password authentication. If it does, allow
setting the password.

While we're here, also add support for parsing bhyve's framebuffer
argument string.

Fabian Freyer (4):
  bhyve: support parsing fbuf PCI device
  bhyve: add support for setting fbuf resolution
  bhyve: probe for VNC password capability
  bhyve: add VNC password support

 docs/formatdomain.html.in |   2 +-
 docs/news.xml |  20 +++
 src/bhyve/bhyve_capabilities.c|  16 ++-
 src/bhyve/bhyve_capabilities.h|   1 +
 src/bhyve/bhyve_command.c |  36 --
 src/bhyve/bhyve_parse_command.c   | 116 +-
 src/libvirt_private.syms  |   1 +
 .../bhyveargv2xml-vnc-listen.args |  10 ++
 .../bhyveargv2xml-vnc-listen.xml  |  22 
 .../bhyveargv2xml-vnc-password.args   |  10 ++
 .../bhyveargv2xml-vnc-password.xml|  22 
 .../bhyveargv2xml-vnc-resolution.args |  10 ++
 .../bhyveargv2xml-vnc-resolution.xml  |  24 
 .../bhyveargv2xml-vnc-vga-io.args |  10 ++
 .../bhyveargv2xml-vnc-vga-io.xml  |  22 
 .../bhyveargv2xml-vnc-vga-off.args|  10 ++
 .../bhyveargv2xml-vnc-vga-off.xml |  23 
 .../bhyveargv2xml-vnc-vga-on.args |  10 ++
 .../bhyveargv2xml-vnc-vga-on.xml  |  23 
 .../bhyveargv2xmldata/bhyveargv2xml-vnc.args  |  10 ++
 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml |  22 
 tests/bhyveargv2xmltest.c |   9 +-
 .../bhyvexml2argv-vnc-password-comma.xml  |  26 
 .../bhyvexml2argv-vnc-password.args   |  12 ++
 .../bhyvexml2argv-vnc-password.ldargs |   1 +
 .../bhyvexml2argv-vnc-password.xml|  26 
 .../bhyvexml2argv-vnc-resolution.args |  10 ++
 .../bhyvexml2argv-vnc-resolution.ldargs   |   1 +
 .../bhyvexml2argv-vnc-resolution.xml  |  20 +++
 tests/bhyvexml2argvtest.c |   8 +-
 .../bhyvexml2xmlout-vnc-password.xml  |  41 +++
 .../bhyvexml2xmlout-vnc-resolution.xml|  28 +
 tests/bhyvexml2xmltest.c  |   2 +
 33 files changed, 588 insertions(+), 16 deletions(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-listen.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-io.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-off.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-vga-on.xml
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password-comma.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-password.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-resolution.xml

-- 
2.19.2




[PATCH 4/4] bhyve: add VNC password support

2020-05-06 Thread Fabian Freyer
Support setting a password for the VNC framebuffer using the passwd
attribute on the  element, if the driver has the
BHYVE_CAP_VNC_PASSWORD capability.

Note that virsh domxml-from-native does not output the password in the
generated XML, as VIR_DOMAIN_DEF_FORMAT_SECURE is not set when
formatting the domain definition.

Signed-off-by: Fabian Freyer 
---
 docs/news.xml | 11 +
 src/bhyve/bhyve_command.c | 33 ++-
 src/bhyve/bhyve_parse_command.c   |  5 +++
 .../bhyveargv2xml-vnc-password.args   | 10 +
 .../bhyveargv2xml-vnc-password.xml| 22 ++
 tests/bhyveargv2xmltest.c |  3 +-
 .../bhyvexml2argv-vnc-password-comma.xml  | 26 
 .../bhyvexml2argv-vnc-password.args   | 12 ++
 .../bhyvexml2argv-vnc-password.ldargs |  1 +
 .../bhyvexml2argv-vnc-password.xml| 26 
 tests/bhyvexml2argvtest.c |  7 +++-
 .../bhyvexml2xmlout-vnc-password.xml  | 41 +++
 tests/bhyvexml2xmltest.c  |  1 +
 13 files changed, 185 insertions(+), 13 deletions(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-password.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password-comma.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-password.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-password.xml

diff --git a/docs/news.xml b/docs/news.xml
index d728dfa93c..bd951c2e04 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -44,6 +44,17 @@
 
   
 
+  
+
+  bhyve: support VNC password authentication
+
+
+  libvirt can now probe whether the bhyve binary supports
+  VNC password authentication. In case it does, a VNC password
+  can now be passed using the passwd attribute on
+  the graphics element.
+
+  
   
 
   bhyve: support setting the framebuffer resolution
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index db35cb9bd8..369278214c 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -425,17 +425,6 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 goto error;
 }
 
-if (graphics->data.vnc.auth.passwd) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("vnc password auth not supported"));
-goto error;
-} else {
- /* Bhyve doesn't support VNC Auth yet, so print a warning about
-  * unauthenticated VNC sessions */
- VIR_WARN("%s", _("Security warning: currently VNC auth is not"
-  " supported."));
-}
-
 if (glisten->address) {
 escapeAddr = strchr(glisten->address, ':') != NULL;
 if (escapeAddr)
@@ -469,6 +458,28 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 goto error;
 }
 
+if (graphics->data.vnc.auth.passwd) {
+if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_VNC_PASSWORD)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("VNC Passwort authentication not supported "
+ "by bhyve"));
+goto error;
+}
+
+if (strchr(graphics->data.vnc.auth.passwd, ',')) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Password may not contain ',' character"));
+goto error;
+}
+
+virBufferAsprintf(&opt, ",password=%s", 
graphics->data.vnc.auth.passwd);
+} else {
+if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_VNC_PASSWORD))
+VIR_WARN("%s", _("Security warning: VNC auth is not supported."));
+else
+VIR_WARN("%s", _("Security warning: VNC is used without 
authentication."));
+}
+
 if (video->res)
 virBufferAsprintf(&opt, ",w=%d,h=%d", video->res->x, video->res->y);
 
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 0414cb1ef1..af990f8e51 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -640,6 +640,11 @@ bhyveParsePCIFbuf(virDomainDefPtr def,
 if (virStrToLong_uip(param, NULL, 10, &video->res->y))
 goto error;
 }
+
+if (STRPREFIX(param, "passwo

[PATCH 3/4] bhyve: probe for VNC password capability

2020-05-06 Thread Fabian Freyer
Introduces the BHYVE_CAP_VNC_PASSWORD capability, which is probed by
parsing the error message from the bhyve command. When it is not
supported, bhyve -s 0,fbuf,password= will return an error message.

Signed-off-by: Fabian Freyer 
---
 src/bhyve/bhyve_capabilities.c | 16 +++-
 src/bhyve/bhyve_capabilities.h |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index fb8829d571..59783f8576 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2014 Roman Bogorodskiy
  * Copyright (C) 2014 Semihalf
- * Copyright (C) 2016 Fabian Freyer
+ * Copyright (C) 2020 Fabian Freyer
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -323,6 +323,17 @@ bhyveProbeCapsXHCIController(unsigned int *caps, char 
*binary)
 }
 
 
+static int
+bhyveProbeCapsVNCPassword(unsigned int *caps, char *binary)
+{
+return bhyveProbeCapsDeviceHelper(caps, binary,
+  "-s",
+  "0,fbuf,password=",
+  "Invalid fbuf emulation \"password\"",
+  BHYVE_CAP_VNC_PASSWORD);
+}
+
+
 int
 virBhyveProbeCaps(unsigned int *caps)
 {
@@ -351,6 +362,9 @@ virBhyveProbeCaps(unsigned int *caps)
 if ((ret = bhyveProbeCapsXHCIController(caps, binary)))
 goto out;
 
+if ((ret = bhyveProbeCapsVNCPassword(caps, binary)))
+goto out;
+
  out:
 VIR_FREE(binary);
 return ret;
diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
index 12926cf423..89f4b0308e 100644
--- a/src/bhyve/bhyve_capabilities.h
+++ b/src/bhyve/bhyve_capabilities.h
@@ -49,6 +49,7 @@ typedef enum {
 BHYVE_CAP_FBUF = 1 << 4,
 BHYVE_CAP_XHCI = 1 << 5,
 BHYVE_CAP_CPUTOPOLOGY = 1 << 6,
+BHYVE_CAP_VNC_PASSWORD = 1 << 7,
 } virBhyveCapsFlags;
 
 int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps);
-- 
2.19.2




[PATCH 2/4] bhyve: add support for setting fbuf resolution

2020-05-06 Thread Fabian Freyer
The resolution of the VNC framebuffer can now be set via the resolution
definition introduced in 5.9.0.

Also, add "gop" to the list of model types  the 
sub-element is valid for.

Signed-off-by: Fabian Freyer 
---
 docs/formatdomain.html.in |  2 +-
 docs/news.xml |  9 ++
 src/bhyve/bhyve_command.c |  3 ++
 src/bhyve/bhyve_parse_command.c   | 20 +
 .../bhyveargv2xml-vnc-resolution.args | 10 +++
 .../bhyveargv2xml-vnc-resolution.xml  | 24 
 tests/bhyveargv2xmltest.c |  1 +
 .../bhyvexml2argv-vnc-resolution.args | 10 +++
 .../bhyvexml2argv-vnc-resolution.ldargs   |  1 +
 .../bhyvexml2argv-vnc-resolution.xml  | 20 +
 tests/bhyvexml2argvtest.c |  1 +
 .../bhyvexml2xmlout-vnc-resolution.xml| 28 +++
 tests/bhyvexml2xmltest.c  |  1 +
 13 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-resolution.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-resolution.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 23eb029234..06bbbf7fea 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -7543,7 +7543,7 @@ qemu-kvm -net nic,model=? /dev/null
 element may also have an optional resolution sub-element.
 The resolution element has attributes x and
 y to set the minimum resolution for the video device. This
-sub-element is valid for model types "vga", "qxl", "bochs", and
+sub-element is valid for model types "vga", "qxl", "bochs", "gop", and
 "virtio".
 
   
diff --git a/docs/news.xml b/docs/news.xml
index 4cef804aac..d728dfa93c 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -44,6 +44,15 @@
 
   
 
+  
+
+  bhyve: support setting the framebuffer resolution
+
+
+  libvirt can now set the framebuffer's "w" and "h" parameters
+  using the resolution element.
+
+  
 
 
 
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 5b1d80083a..db35cb9bd8 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -469,6 +469,9 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 goto error;
 }
 
+if (video->res)
+virBufferAsprintf(&opt, ",w=%d,h=%d", video->res->x, video->res->y);
+
 if (video->driver)
 virBufferAsprintf(&opt, ",vga=%s",
   
virDomainVideoVGAConfTypeToString(video->driver->vgaconf));
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 39cce67ea9..0414cb1ef1 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -620,6 +620,26 @@ bhyveParsePCIFbuf(virDomainDefPtr def,
 if (virStrToLong_i(param, NULL, 10, &graphics->data.vnc.port))
 goto error;
 }
+
+if (STRPREFIX(param, "w=")) {
+param += strlen("w=");
+
+if (video->res == NULL)
+video->res = g_new0(virDomainVideoResolutionDef, 1);
+
+if (virStrToLong_uip(param, NULL, 10, &video->res->x))
+goto error;
+}
+
+if (STRPREFIX(param, "h=")) {
+param += strlen("h=");
+
+if (video->res == NULL)
+video->res = g_new0(virDomainVideoResolutionDef, 1);
+
+if (virStrToLong_uip(param, NULL, 10, &video->res->y))
+goto error;
+}
 }
 
  cleanup:
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args 
b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
new file mode 100644
index 00..e5e2c0f2e8
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-l bootrom,/path/to/test.fd \
+-s 2:0,fbuf,tcp=127.0.0.1:5904,w=1920,h=1080 \
+-s 1,lpc bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml 
b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
new file mode 100644
index 00..f8fa0ed1ce
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-vnc-resolution.xml
@@ -0,0 +1,24 @

Re: [libvirt] [PATCH 0/3] bhyve: allow locking memory

2018-05-14 Thread Fabian Freyer
On 14 May 2018, at 8:51, Roman Bogorodskiy wrote:

>   Peter Krempa wrote:
>
>> On Sun, May 13, 2018 at 14:01:25 +0400, Roman Bogorodskiy wrote:
>>>   Fabian Freyer wrote:
>>
>> [...]
>>
>>>>  13 files changed, 134 insertions(+)
>>>>  create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-wired.args
>>>>  create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml
>>>>  create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.args
>>>>  create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs
>>>>  create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml
>>>>  create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml
>>>
>>> Thanks for the patches, I've pushed the series with some syntax-check
>>> fixes (trailing whitespaces, tabs instead of whitespaces) and added
>>> 'Signed-off-by' line which is mandatory now.
>>
>> Note that 'Signed-off-by' should _NOT_ be added without explicit consent
>> of the author of the patches. Otherwise it defeats the purpose of
>> certification that the author agrees and complies with the Developer
>> certificate of origin. Adding it without explicit consent makes the
>> Signed-off-by line just a useless piece of jewelery added to appease the
>> push hook.
>
> Oh, sorry about that. I assumed as Fabian is a long time contributor,
> he's familiar with the general project policies.
>
> Fabian, do you have any issue with that?
All good with me.

In case you need it from me, for the whole series:

Signed-off-by: Fabian Freyer 

signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] xenconfig: Remove references to my name and email

2018-05-09 Thread Fabian Freyer
On Wed, May 09, 2018 at 02:29:35PM +0300, David Kiarie wrote:
> We don't have a new company here. We have an almost four year old cat.

IANAL, but I think there's a precedent [1] for this, where at least a US court
ruled that "Specifically, the Copyright Office will not register works produced
by 'nature, animals, or plants' including, by specific example, a 'photograph
taken by a monkey.'". I think it would be difficult for your cat to
claim copyright.

(sorry for adding to the noise...)

[1] Naruto et al v. David Slater -
https://cases.justia.com/federal/district-courts/california/candce/3:2015cv04324/291324/45/0.pdf?ts=1454149106

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/3] bhyve: add tests for wiring memory

2018-05-08 Thread Fabian Freyer
---
 tests/bhyveargv2xmldata/bhyveargv2xml-wired.args   |  7 +
 tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml| 19 
 tests/bhyveargv2xmltest.c  |  1 +
 tests/bhyvexml2argvdata/bhyvexml2argv-wired.args   | 10 ++
 tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs |  3 ++
 tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml| 26 
 tests/bhyvexml2argvtest.c  |  1 +
 .../bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml  | 36 ++
 tests/bhyvexml2xmltest.c   |  1 +
 9 files changed, 104 insertions(+)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-wired.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml

diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-wired.args 
b/tests/bhyveargv2xmldata/bhyveargv2xml-wired.args
new file mode 100644
index 0..5d0ad765b
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-wired.args
@@ -0,0 +1,7 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-H \
+-P \
+-S \
+-s 0:0,hostbridge bhyve
diff --git a/tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml 
b/tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml
new file mode 100644
index 0..0f4cea544
--- /dev/null
+++ b/tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml
@@ -0,0 +1,19 @@
+
+  bhyve
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  
+
+  
+  1
+  
+hvm
+  
+  
+  destroy
+  destroy
+  destroy
+  
+  
+
diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c
index e5d78530c..d55236484 100644
--- a/tests/bhyveargv2xmltest.c
+++ b/tests/bhyveargv2xmltest.c
@@ -163,6 +163,7 @@ mymain(void)
 driver.bhyvecaps = BHYVE_CAP_RTC_UTC;
 
 DO_TEST("base");
+DO_TEST("wired");
 DO_TEST("oneline");
 DO_TEST("name");
 DO_TEST("console");
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-wired.args 
b/tests/bhyvexml2argvdata/bhyvexml2argv-wired.args
new file mode 100644
index 0..13d4f4909
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-wired.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-S \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:0,ahci,hd:/tmp/freebsd.img \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs 
b/tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs
new file mode 100644
index 0..32538b558
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs
@@ -0,0 +1,3 @@
+/usr/sbin/bhyveload \
+-m 214 \
+-d /tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml 
b/tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml
new file mode 100644
index 0..639e047dd
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml
@@ -0,0 +1,26 @@
+
+  bhyve
+  df3be7e7-a104-11e3-aeb0-50e5492bd3dc
+  219136
+  
+
+  
+  1
+  
+hvm
+  
+  
+
+  
+  
+  
+  
+
+
+  
+  
+  
+  
+
+  
+
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index 6f3b0c2eb..b08b1675f 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -179,6 +179,7 @@ mymain(void)
BHYVE_CAP_FBUF | BHYVE_CAP_XHCI;
 
 DO_TEST("base");
+DO_TEST("wired");
 DO_TEST("acpiapic");
 DO_TEST("disk-cdrom");
 DO_TEST("disk-virtio");
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml 
b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml
new file mode 100644
index 0..ed564e277
--- /dev/null
+++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml
@@ -0,0 +1,36 @@
+
+  bhyve
+  df3be7e7-a104-11e3-aeb0-50e5492bd3dc
+  219136
+  219136
+  
+
+  
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+
+  
+  
+  
+  
+
+
+
+  
+
+
+  
+  
+  
+  
+
+  
+
diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c
index 4d9c1681d..6aaeab741 100644
--- a/tests/bhyvexml2xmltest.c
+++ b/tests/bhyvexml2xmltest.c
@@ -84,6 +84,7 @@ mymain(void)
 
 DO_TEST_DIFFERENT("acpiapic");
 DO_TEST_DIFFERENT("base");
+DO_TEST_DIFFERENT("wired");
 DO_TEST_DIFFERENT("bhyveload-bootorder");
 DO_TEST_DIFFERENT("bhyveload-bootorder1");
 DO_TEST_DIFFERENT("bhyveload-bootorder2");
-- 
2.15.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/3] bhyve: add support for wiring memory

2018-05-08 Thread Fabian Freyer
The  element will now pass the
wired (-S) flag to the bhyve command.
---
 src/bhyve/bhyve_command.c   | 3 +++
 src/bhyve/bhyve_parse_command.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 9413ae5c1..e3f7ded7d 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -474,6 +474,9 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
 virCommandAddArgFormat(cmd, "%llu",
VIR_DIV_UP(virDomainDefGetMemoryInitial(def), 
1024));
 
+if (def->mem.locked)
+virCommandAddArg(cmd, "-S"); /* Wire guest memory */
+
 /* Options */
 if (def->features[VIR_DOMAIN_FEATURE_ACPI] == VIR_TRISTATE_SWITCH_ON)
 virCommandAddArg(cmd, "-A"); /* Create an ACPI table */
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index fcaaed275..27916c528 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -721,6 +721,9 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
 goto error;
 }
 break;
+   case 'S':
+   def->mem.locked = true;
+   break;
 }
 }
 
-- 
2.15.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/3] bhyve: document support for wiring guest memory

2018-05-08 Thread Fabian Freyer
---
 docs/drvbhyve.html.in | 14 ++
 docs/news.xml | 10 ++
 2 files changed, 24 insertions(+)

diff --git a/docs/drvbhyve.html.in b/docs/drvbhyve.html.in
index bde8298a5..5b5513d3d 100644
--- a/docs/drvbhyve.html.in
+++ b/docs/drvbhyve.html.in
@@ -430,6 +430,20 @@ supports Intel e1000 network adapter emulation. It's 
supported in libvirt
   
 
 ...
+
+
+Wiring guest memory
+
+Since 4.4.0, it's possible to specify that guest 
memory should
+be wired and cannot be swapped out as follows:
+
+
+...
+
+  
+
+...
+
 
 
   
diff --git a/docs/news.xml b/docs/news.xml
index 80181415c..5b7dd4c4a 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -35,6 +35,16 @@
 
   
 
+  
+
+  bhyve: Support locking guest memory 
+
+
+  Bhyve's guest memory may be wired using the
+  

+  element.
+
+  
 
 
 
-- 
2.15.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/3] bhyve: allow locking memory

2018-05-08 Thread Fabian Freyer
This patch series adds support for locking guest memory to the bhyve
driver using the following elements


  


When specified, the -S flag is passed to the bhyve binary.

Fabian Freyer (3):
  bhyve: add support for wiring memory
  bhyve: add tests for wiring memory
  bhyve: document support for wiring guest memory

 docs/drvbhyve.html.in  | 14 +
 docs/news.xml  | 10 ++
 src/bhyve/bhyve_command.c  |  3 ++
 src/bhyve/bhyve_parse_command.c|  3 ++
 tests/bhyveargv2xmldata/bhyveargv2xml-wired.args   |  7 +
 tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml| 19 
 tests/bhyveargv2xmltest.c  |  1 +
 tests/bhyvexml2argvdata/bhyvexml2argv-wired.args   | 10 ++
 tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs |  3 ++
 tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml| 26 
 tests/bhyvexml2argvtest.c  |  1 +
 .../bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml  | 36 ++
 tests/bhyvexml2xmltest.c   |  1 +
 13 files changed, 134 insertions(+)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-wired.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-wired.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-wired.xml
 create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-wired.xml

-- 
2.15.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] bhyve: add support for passing stdin to loader

2018-04-26 Thread Fabian Freyer


On 26 Apr 2018, at 18:38, John Ferlan wrote:

> On 04/13/2018 03:27 PM, Fabian Freyer wrote:
>> This commit adds the  node to the domain definition,
>> with the following semantics:
>>
>> To pass standard input verbatim to the bootloader, set
>>
>> some stdin
>>
>> Multiline standard input can be set using a CDATA tag:
>>
>> 
>>
>> Standard input can be read from a file as follows:
>>
>> 
>
> Not my area of expertise, but some feedback to hopefully help a bit
> seeing as there have been no other takes for 2 weeks.

Thanks!

> Personally this format over the other format would seem to be better
> although the attribute name would be "path" not "file".  IOW: That whole
> CDATA thing - not sure it passes by all the censors^W reviewers
> scrutiny.  Is there a particular reason to have this CDATA tag syntax?
The idea here is to be able to specify several lines of standard input,
especially for line-oriented command line interfaces, while not needing
to add a separate file.

> Parsing the line and making sure consumers provide a specific format is
> probably more hassle than it's worth and I would think presents an
> opportunity to insert things that may cause interesting errors. Any time
> you accept something from stdin like that you open up buffer overflows
> and buffer handling problems. Not that the same thing cannot be in the
> file, but at least you're then passing that off to something else to
> manage whether what's in a file is correctly formatted as you're not
> validating the contents of the file, just that it exists.

I’m not quite sure I comprehend the difference to a file here.

>>
>> Signed-off-by: Fabian Freyer 
>> ---
>>  docs/formatdomain.html.in  | 19 ++
>>  docs/schemas/domaincommon.rng  | 10 
>>  src/bhyve/bhyve_driver.c   | 10 
>>  src/bhyve/bhyve_parse_command.c| 70 
>> ++
>>  src/bhyve/bhyve_process.c  | 22 +++
>>  src/conf/domain_conf.c | 41 +
>>  src/conf/domain_conf.h | 11 
>>  .../bhyveargv2xml-loader-stdin-file.args   |  9 +++
>>  .../bhyveargv2xml-loader-stdin-file.xml| 19 ++
>>  .../bhyveargv2xml-loader-stdin-multiline.args  | 13 
>>  .../bhyveargv2xml-loader-stdin-multiline.xml   | 21 +++
>>  .../bhyveargv2xml-loader-stdin-oneline.args| 11 
>>  .../bhyveargv2xml-loader-stdin-oneline.xml | 19 ++
>>  tests/bhyveargv2xmltest.c  |  3 +
>>  .../bhyvexml2argv-grub-stdin-file.args |  9 +++
>>  .../bhyvexml2argv-grub-stdin-file.devmap   |  1 +
>>  .../bhyvexml2argv-grub-stdin-file.ldargs   |  4 ++
>>  .../bhyvexml2argv-grub-stdin-file.xml  | 25 
>>  .../bhyvexml2argv-grub-stdin-multiline.args|  9 +++
>>  .../bhyvexml2argv-grub-stdin-multiline.devmap  |  1 +
>>  .../bhyvexml2argv-grub-stdin-multiline.ldargs  |  4 ++
>>  .../bhyvexml2argv-grub-stdin-multiline.xml | 30 ++
>>  .../bhyvexml2argv-grub-stdin-oneline.args  |  9 +++
>>  .../bhyvexml2argv-grub-stdin-oneline.devmap|  1 +
>>  .../bhyvexml2argv-grub-stdin-oneline.ldargs|  4 ++
>>  .../bhyvexml2argv-grub-stdin-oneline.xml   | 25 
>>  tests/bhyvexml2argvtest.c  |  3 +
>>  .../bhyvexml2xmlout-grub-stdin-file.xml| 34 +++
>>  .../bhyvexml2xmlout-grub-stdin-multiline.xml   | 39 
>>  .../bhyvexml2xmlout-grub-stdin-oneline.xml | 34 +++
>>  tests/bhyvexml2xmltest.c   |  3 +
>>  31 files changed, 513 insertions(+)
>>  create mode 100644 
>> tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-file.args
>>  create mode 100644 
>> tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-file.xml
>>  create mode 100644 
>> tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-multiline.args
>>  create mode 100644 
>> tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-multiline.xml
>>  create mode 100644 
>> tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-oneline.args
>>  create mode 100644 
>> tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-oneline.xml
>>  create mode 100644 
>> tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-file.args
>>  create mode 100644 
>> tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-file.devmap
>>  cr

[libvirt] [PATCH] bhyve: add support for passing stdin to loader

2018-04-15 Thread Fabian Freyer
This commit adds the  node to the domain definition,
with the following semantics:

To pass standard input verbatim to the bootloader, set

some stdin

Multiline standard input can be set using a CDATA tag:



Standard input can be read from a file as follows:



Signed-off-by: Fabian Freyer 
---
 docs/formatdomain.html.in  | 19 ++
 docs/schemas/domaincommon.rng  | 10 
 src/bhyve/bhyve_driver.c   | 10 
 src/bhyve/bhyve_parse_command.c| 70 ++
 src/bhyve/bhyve_process.c  | 22 +++
 src/conf/domain_conf.c | 41 +
 src/conf/domain_conf.h | 11 
 .../bhyveargv2xml-loader-stdin-file.args   |  9 +++
 .../bhyveargv2xml-loader-stdin-file.xml| 19 ++
 .../bhyveargv2xml-loader-stdin-multiline.args  | 13 
 .../bhyveargv2xml-loader-stdin-multiline.xml   | 21 +++
 .../bhyveargv2xml-loader-stdin-oneline.args| 11 
 .../bhyveargv2xml-loader-stdin-oneline.xml | 19 ++
 tests/bhyveargv2xmltest.c  |  3 +
 .../bhyvexml2argv-grub-stdin-file.args |  9 +++
 .../bhyvexml2argv-grub-stdin-file.devmap   |  1 +
 .../bhyvexml2argv-grub-stdin-file.ldargs   |  4 ++
 .../bhyvexml2argv-grub-stdin-file.xml  | 25 
 .../bhyvexml2argv-grub-stdin-multiline.args|  9 +++
 .../bhyvexml2argv-grub-stdin-multiline.devmap  |  1 +
 .../bhyvexml2argv-grub-stdin-multiline.ldargs  |  4 ++
 .../bhyvexml2argv-grub-stdin-multiline.xml | 30 ++
 .../bhyvexml2argv-grub-stdin-oneline.args  |  9 +++
 .../bhyvexml2argv-grub-stdin-oneline.devmap|  1 +
 .../bhyvexml2argv-grub-stdin-oneline.ldargs|  4 ++
 .../bhyvexml2argv-grub-stdin-oneline.xml   | 25 
 tests/bhyvexml2argvtest.c  |  3 +
 .../bhyvexml2xmlout-grub-stdin-file.xml| 34 +++
 .../bhyvexml2xmlout-grub-stdin-multiline.xml   | 39 
 .../bhyvexml2xmlout-grub-stdin-oneline.xml | 34 +++
 tests/bhyvexml2xmltest.c   |  3 +
 31 files changed, 513 insertions(+)
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-file.args
 create mode 100644 tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-file.xml
 create mode 100644 
tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-multiline.args
 create mode 100644 
tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-multiline.xml
 create mode 100644 
tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-oneline.args
 create mode 100644 
tests/bhyveargv2xmldata/bhyveargv2xml-loader-stdin-oneline.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-file.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-file.devmap
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-file.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-file.xml
 create mode 100644 
tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-multiline.args
 create mode 100644 
tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-multiline.devmap
 create mode 100644 
tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-multiline.ldargs
 create mode 100644 
tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-multiline.xml
 create mode 100644 
tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-oneline.args
 create mode 100644 
tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-oneline.devmap
 create mode 100644 
tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-oneline.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-stdin-oneline.xml
 create mode 100644 
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-grub-stdin-file.xml
 create mode 100644 
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-grub-stdin-multiline.xml
 create mode 100644 
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-grub-stdin-oneline.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 5e99884dc..cea024235 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -245,6 +245,11 @@
 ...
 <bootloader>/usr/bin/pygrub</bootloader>
 <bootloader_args>--append single</bootloader_args>
+<bootloader_stdin><![CDATA[
+kernel (hd)/path/to/kernel
+initrd (host)/path/to/initrd
+boot
+]]>
 ...
 
 
@@ -259,6 +264,20 @@
 command line arguments to be passed to the bootloader.
 Since 0.2.3
 
+  bootloader_stdin
+  The optional bootloader_stdin element specifies
+standard input to be passed to the bootloader. To pass multiple
+lines of standard input to the bootloader, wrap the content in
+a CDATA tag. Instead of specifying the standard input in the
+domain XML, the path to a file to be read may be giv

[libvirt] [RFC] passing standard input to host bootloaders

2018-04-13 Thread Fabian Freyer
Hello list,

Some host boot loaders, e.g. grub-bhyve when using the bhyve
driver, take commands on stdin. While there is the
 tag to set arbitrary command line tags,
there is no  or similar to provide standard
input to the boot loader.

Typical input could be something along the lines of e.g. the
following grub commands:

kernel (cd)/path/to/vmlinuz some-cmdline
initrd (root)/path/to/host/initrd
boot

Using e.g. the (root) device is especially useful on the bhyve
driver when creating diskless VMs.

Before I start implementing this, I’d appreciate some feedback
on the following two points:

 1) should this be an attr on the  tag, e.g.

/path/to/bootloader

or rather, as there already exists a  tag
a separate  tag?

 2) should the input be passed verbatim in the domain def,
e.g. using a CDATA block or from a file? Should this be
user-specified, e.g. in an attr?







Regards,
Fabian

signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 5/5] Add travis build configuration

2017-04-08 Thread Fabian Freyer
On 8 Apr 2017, at 16:28, Roman Bogorodskiy wrote:
> This looks like the same problem I'm having on FreeBSD. Its ARG_MAX
> value is too low and not tunable, and the command line for syntax-check
> does not fit.
>
> I work around that by applying a patch to make ARG_MAX tunable on
> FreeBSD (haven't yet upstreamed that though), but not sure how to tweak
> that on macOS.

ARG_MAX on macOS is set to 256*1024 on macOS [1], and kern.argmax is also a 
readonly sysctl. Briefly looking over the xnu source tree leads me to believe 
that making ARG_MAX unable there is even more tricky than on FreeBSD. Just 
increasing ARG_MAX and recompiling xnu might work though. Then again, most 
apple boxes tend to not run self-compiled kernels, so I would just go with your 
second suggestion.

> Probably a better way would be to somehow reduce length of the command
> line.

Fabian Freyer

[1] 
https://github.com/opensource-apple/xnu/blob/53c5e2e62fc4182595609153d4b99648da577c39/bsd/sys/syslimits.h#L75



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/6] bhyve: virBhyveProbeCaps: BHYVE_CAP_LPC_BOOTROM

2017-03-08 Thread Fabian Freyer
On 08.03.2017 18:19, Michal Privoznik wrote:
> ACK, but we really need a better way to detect capabilites. For instance
> now, bhyve binary is executed 4 times just to find out whether it
> supports 4 capabilities. That's just madness. Maybe we can get in touch
> with bhyve developers and ask them? Maybe it could have a monitor just
> like qemu has, or something.
There's a patch[1] for it, but it would need to be moved along.
Unfortunately, we would still need to somehow fall back to this for
backwards compatibility...

Fabian

 [1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=210111
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v1 1/4] bhyve: detect 32 SATA devices per controller support

2017-01-24 Thread Fabian Freyer

On 24 Jan 2017, at 16:31, Laine Stump wrote:

+cmd = virCommandNew(binary);
+virCommandAddArgList(cmd, "-s", "0,ahci", NULL);
+virCommandSetErrorBuffer(cmd, &error);


Too bad there isn't some way you could learn both of these with a 
single run of the binary.



+if (virCommandRun(cmd, &exit) < 0) {
+ret = -1;
+goto out;
+}
+
+if (strstr(error, "pci slot 0:0: unknown device \"ahci\"") == 
NULL)

+*caps |= BHYVE_CAP_AHCI32SLOT;


That seems like a fairly fragile check. Are you certain there aren't 
older versions where the error string is different?


Anyway, lacking any better check, ACK.


AFAIR there is a patch in the queue for that upstream 
(https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=210111), but there 
hasn’t been much movement there.


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] bhyve: implement virConnectGetDomainCapabilities

2016-07-08 Thread Fabian Freyer
This patch adds virConnectGetDomainCapabilities support for bhyve.

---
 src/bhyve/bhyve_capabilities.c | 26 
 src/bhyve/bhyve_capabilities.h |  5 
 src/bhyve/bhyve_driver.c   | 56 ++
 3 files changed, 87 insertions(+)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index d0af4d9..10c33b9 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2014 Roman Bogorodskiy
  * Copyright (C) 2014 Semihalf
+ * 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
@@ -106,6 +107,31 @@ virBhyveCapsBuild(void)
 return NULL;
 }
 
+virDomainCapsPtr
+virBhyveDomainCapsBuild(const char *emulatorbin,
+const char *machine,
+virArch arch,
+virDomainVirtType virttype)
+{
+virDomainCapsPtr caps = NULL;
+
+if (!(caps = virDomainCapsNew(emulatorbin, machine, arch, virttype)))
+goto cleanup;
+
+caps->os.supported = true;
+caps->disk.supported = true;
+VIR_DOMAIN_CAPS_ENUM_SET(caps->disk.diskDevice,
+ VIR_DOMAIN_DISK_DEVICE_DISK,
+ VIR_DOMAIN_DISK_DEVICE_CDROM);
+
+VIR_DOMAIN_CAPS_ENUM_SET(caps->disk.bus,
+ VIR_DOMAIN_DISK_BUS_SATA,
+ VIR_DOMAIN_DISK_BUS_VIRTIO);
+
+ cleanup:
+return caps;
+}
+
 int
 virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps)
 {
diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
index 0eb22a4..85018cb 100644
--- a/src/bhyve/bhyve_capabilities.h
+++ b/src/bhyve/bhyve_capabilities.h
@@ -23,8 +23,13 @@
 # define _BHYVE_CAPABILITIES
 
 # include "capabilities.h"
+#include "conf/domain_capabilities.h"
 
 virCapsPtr virBhyveCapsBuild(void);
+virDomainCapsPtr virBhyveDomainCapsBuild(const char *emulatorbin,
+ const char *machine,
+ virArch arch,
+ virDomainVirtType virttype);
 
 /* These are bit flags: */
 typedef enum {
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 8036661..ae37a2d 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -53,6 +53,7 @@
 #include "nodeinfo.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
+#include "conf/domain_capabilities.h"
 
 #include "bhyve_device.h"
 #include "bhyve_driver.h"
@@ -1539,6 +1540,60 @@ bhyveConnectIsEncrypted(virConnectPtr conn 
ATTRIBUTE_UNUSED)
 return 0;
 }
 
+static char *
+bhyveConnectGetDomainCapabilities(virConnectPtr conn,
+  const char *emulatorbin,
+  const char *arch_str,
+  const char *machine,
+  const char *virttype_str,
+  unsigned int flags)
+{
+//bhyveConnPtr privconn = conn->privateData;
+virDomainCapsPtr caps = NULL;
+char *ret = NULL;
+int virttype = VIR_DOMAIN_VIRT_BHYVE;
+int arch = virArchFromHost(); /* virArch */
+
+virCheckFlags(0, ret);
+
+if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)
+return ret;
+
+if (virttype_str &&
+(virttype = virDomainVirtTypeFromString(virttype_str)) < 0) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("unknown virttype: %s"),
+   virttype_str);
+goto cleanup;
+}
+
+if (virttype != VIR_DOMAIN_VIRT_BHYVE) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("unknown virttype: %s"),
+   virttype_str);
+goto cleanup;
+}
+
+if (arch_str && (arch = virArchFromString(arch_str)) == VIR_ARCH_NONE) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("unknown architecture: %s"),
+   arch_str);
+goto cleanup;
+}
+
+if (emulatorbin == NULL)
+emulatorbin = "/usr/sbin/bhyve";
+
+if (!(caps = virBhyveDomainCapsBuild(emulatorbin, machine, arch, 
virttype)))
+goto cleanup;
+
+ret = virDomainCapsFormat(caps);
+
+ cleanup:
+virObjectUnref(caps);
+return ret;
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
 .name = "bhyve",
 .connectOpen = bhyveConnectOpen, /* 1.2.2 */
@@ -1592,6 +1647,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
 .connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */
 .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
+.connectGetDomainCapabilities

[libvirt] [PATCH v5 3/6] bhyve: implement virConnectDomainXMLFromNative

2016-07-08 Thread Fabian Freyer
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 
---
 po/POTFILES.in  |   1 +
 src/Makefile.am |   2 +
 src/bhyve/bhyve_driver.c|  41 ++
 src/bhyve/bhyve_parse_command.c | 276 
 src/bhyve/bhyve_parse_command.h |  30 +
 5 files changed, 350 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 ca07582..09e8177 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -16,6 +16,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 0214995..78c493c 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..c7afe7e 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,45 @@ 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)
+return NULL;
+
+capabilities = bhyveDriverGetCapabilities(privconn);
+if (!capabilities)
+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:
+virObjectUnref(capabilities);
+virDomainDefFree(def);
+return xml;
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
 .name = "bhyve",
 .connectOpen = bhyveConnectOpen, /* 1.2.2 */
@@ -1592,6 +1632,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
 .connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */
 .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
+.connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 2.1.0 */
 };
 
 
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
new file mode 100644
index 000..e3bc1eb
--- /dev/null
+++ b/src/bhyve/bhyve_parse_command.c
@@ -0,0 +1,276 @@
+/*
+ * 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.
+ *
+ * Y

[libvirt] [PATCH v5 6/6] Add some tests for bhyveParseCommandLineString

2016-07-08 Thread Fabian Freyer
---
 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  |  24 +++
 .../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, 1181 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

[libvirt] [PATCH v5 4/6] bhyve: implement bhyve argument parser

2016-07-08 Thread Fabian Freyer
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/nmdmA <-> /dev/nmdmB
* 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 
---
 src/bhyve/bhyve_parse_command.c | 514 +++-
 1 file changed, 512 insertions(+), 2 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index e3bc1eb..20b7fce 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 
+#include 
+#include 
 
 #include "bhyve_capabilities.h"
 #include "bhyve_command.h"
@@ -85,6 +88,36 @@ 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
@@ -231,10 +264,484 @@ 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->source.data.nmdm.master = NULL;
+chr->source.data.nmdm.slave = NULL;
+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.nmdm.master, 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.nmdm.master) - 1;
+switch (chr->source.data.file.path[last]) {
+cas

[libvirt] [PATCH v5 1/6] config-post.h: define __GNUC_PREREQ if not defined

2016-07-08 Thread Fabian Freyer
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..dd69197 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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


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

2016-07-08 Thread Fabian Freyer
Differences to v4:

  - fixed various memory leaks
  - various style improvements by Roman Bogorodskiy and fixes for his comments
on v4

Link to v4:
https://www.redhat.com/archives/libvir-list/2016-June/msg02138.html

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/msg1.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 |   2 +
 src/Makefile.am|   2 +
 src/bhyve/bhyve_driver.c   |  41 +
 src/bhyve/bhyve_parse_command.c| 903 +
 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  |  24 +
 .../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, 2181 insertions(+), 3 deletions(-)
 create

[libvirt] [PATCH v5 2/6] gnulib: add getopt module

2016-07-08 Thread Fabian Freyer
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 +++
 po/POTFILES.in  | 1 +
 3 files changed, 5 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])
 ])
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0539366..ca07582 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,6 +8,7 @@ daemon/remote.c
 daemon/remote_dispatch.h
 daemon/stream.c
 gnulib/lib/gai_strerror.c
+gnulib/lib/getopt.c
 gnulib/lib/regcomp.c
 src/access/viraccessdriverpolkit.c
 src/access/viraccessmanager.c
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v5 5/6] bhyve: implement argument parser for loader

2016-07-08 Thread Fabian Freyer
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 
---
 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 20b7fce..ff823b8 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -738,6 +738,116 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
 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;
+size_t i = 0;
+int ret = -1;
+
+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, "%s",
+   _("Failed to parse memory"));
+goto error;
+}
+if (def->mem.cur_balloon != 0 && def->mem.cur_balloon != memory) {
+virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+   _("Failed to parse 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, "%s",
+   _("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, "%s",
+   _("Failed to parse arguments: VM name mismatch"));
+goto error;
+}
+
+ret = 0;
+ error:
+VIR_FREE(parser);
+return ret;
+}
+
+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**) &am

[libvirt] [PATCH] tests: env perl shebang for test-wrap-argv.pl

2016-07-08 Thread Fabian Freyer
On some systems perl is not necessarily in /usr/bin/perl. Use the perl version
in the PATH instead.
---
 tests/test-wrap-argv.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test-wrap-argv.pl b/tests/test-wrap-argv.pl
index d66f5b4..b053f28 100755
--- a/tests/test-wrap-argv.pl
+++ b/tests/test-wrap-argv.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 #
 # Copyright (C) 2015 Red Hat, Inc.
 #
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 4/4] bhyve: Test cases for UEFI bhyvexml2argvtest

2016-06-29 Thread Fabian Freyer
---
 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.args  |  9 +
 .../bhyvexml2argvdata/bhyvexml2argv-nouefi.ldargs  |  1 +
 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.xml   | 23 ++
 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.args| 10 ++
 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.ldargs  |  1 +
 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.xml | 23 ++
 tests/bhyvexml2argvtest.c  | 13 ++--
 7 files changed, 78 insertions(+), 2 deletions(-)
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.xml

diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.args 
b/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.args
new file mode 100644
index 000..88de179
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.args
@@ -0,0 +1,9 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.ldargs 
b/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.ldargs
new file mode 100644
index 000..421376d
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.ldargs
@@ -0,0 +1 @@
+dummy
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.xml 
b/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.xml
new file mode 100644
index 000..eacae99
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.xml
@@ -0,0 +1,23 @@
+
+  bhyve
+  df3be7e7-a104-11e3-aeb0-50e5492bd3dc
+  219136
+  1
+  
+hvm
+test.fd
+  
+  
+
+  
+  
+  
+  
+
+
+  
+  
+  
+
+  
+
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.args 
b/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.args
new file mode 100644
index 000..3f6ef65
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.args
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 0:1,bootrom,test.fd \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.ldargs 
b/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.ldargs
new file mode 100644
index 000..421376d
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.ldargs
@@ -0,0 +1 @@
+dummy
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.xml 
b/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.xml
new file mode 100644
index 000..eacae99
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-uefi.xml
@@ -0,0 +1,23 @@
+
+  bhyve
+  df3be7e7-a104-11e3-aeb0-50e5492bd3dc
+  219136
+  1
+  
+hvm
+test.fd
+  
+  
+
+  
+  
+  
+  
+
+
+  
+  
+  
+
+  
+
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index 7a2d366..5137251 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -44,9 +44,13 @@ static int testCompareXMLToArgvFiles(const char *xml,
 conn->privateData = &driver;
 
 cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false);
-ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "",
+if (!vmdef->os.loader)
+ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "",
 &actualdm);
 
+if ((ldcmd == NULL) && (vmdef->os.loader))
+ldcmd = virCommandNew("dummy");
+
 if ((cmd == NULL) || (ldcmd == NULL)) {
 if (flags & FLAG_EXPECT_FAILURE) {
 ret = 0;
@@ -151,7 +155,7 @@ mymain(void)
 DO_TEST_FULL(name, FLAG_EXPECT_PARSE_ERROR)
 
 driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV;
-driver.bhyvecaps = BHYVE_CAP_RTC_UTC;
+driver.bhyvecaps = BHYVE_CAP_RTC_UTC | BHYVE_CAP_LPC_BOOTROM;
 
 DO_TEST("base");
 DO_TEST("acpiapic");
@@ -179,6 +183,11 @@ mymain(void)
 
 DO_TEST("serial-grub-nocons");
 
+DO_TEST("uefi");
+
+driver.bhyvecaps &= ~BHYVE_CAP_LPC_BOOTROM;
+DO_TEST_FAILURE("nouefi");
+
 virObjectUnref(driver.caps);
 virObjectUnref(driver.xmlopt);
 
-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/4] bhyve: UEFI bootrom support

2016-06-29 Thread Fabian Freyer
this series of patches adds support for specifying UEFI boot images for bhyve
virtual machines.

The old behaviour is kept; only when a loader pflash is specified the loader
command is omitted and adds a bootrom parameter to the bhyverun command.

Fabian Freyer (4):
  bhyve: Separate out checks from virBhyveProbeCaps
  bhyve: virBhyveProbeCaps: BHYVE_CAP_LPC_BOOTROM
  bhyve: add support for booting from UEFI
  bhyve: Test cases for UEFI bhyvexml2argvtest

 src/bhyve/bhyve_capabilities.c | 59 ++
 src/bhyve/bhyve_capabilities.h |  1 +
 src/bhyve/bhyve_command.c  |  6 +++
 src/bhyve/bhyve_driver.c   | 27 --
 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.args  |  9 
 .../bhyvexml2argvdata/bhyvexml2argv-nouefi.ldargs  |  1 +
 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.xml   | 23 +
 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.args| 10 
 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.ldargs  |  1 +
 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.xml | 23 +
 tests/bhyvexml2argvtest.c  | 13 -
 11 files changed, 158 insertions(+), 15 deletions(-)
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-nouefi.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-uefi.xml

-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/4] bhyve: add support for booting from UEFI

2016-06-29 Thread Fabian Freyer
---
 src/bhyve/bhyve_command.c |  6 ++
 src/bhyve/bhyve_driver.c  | 27 +++
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 9ad3f9b..a504788 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -281,6 +281,12 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
 virCommandAddArg(cmd, "-P"); /* vmexit from guest on pause */
 
 virCommandAddArgList(cmd, "-s", "0:0,hostbridge", NULL);
+if (def->os.bootloader == NULL &&
+def->os.loader &&
+(bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) != 0) {
+virCommandAddArg(cmd, "-s");
+virCommandAddArgFormat(cmd, "0:1,bootrom,%s", def->os.loader->path);
+}
 /* Devices */
 for (i = 0; i < def->nnets; i++) {
 virDomainNetDefPtr net = def->nets[i];
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 8036661..cd56a89 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -729,15 +729,34 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
 if (bhyveDomainAssignAddresses(def, NULL) < 0)
 goto cleanup;
 
-if (!(loadcmd = virBhyveProcessBuildLoadCmd(conn, def, "",
+if (def->os.bootloader == NULL &&
+def->os.loader) {
+
+if ((def->os.loader->readonly != VIR_TRISTATE_BOOL_YES)
+|| (def->os.loader->type != VIR_DOMAIN_LOADER_TYPE_PFLASH)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Only read-only pflash is supported."));
+goto cleanup;
+}
+
+if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) == 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Installed bhyve binary does not support "
+  "bootrom"));
+goto cleanup;
+}
+} else {
+if (!(loadcmd = virBhyveProcessBuildLoadCmd(conn, def, "",
 NULL)))
-goto cleanup;
+goto cleanup;
+
+virBufferAdd(&buf, virCommandToString(loadcmd), -1);
+virBufferAddChar(&buf, '\n');
+}
 
 if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, def, true)))
 goto cleanup;
 
-virBufferAdd(&buf, virCommandToString(loadcmd), -1);
-virBufferAddChar(&buf, '\n');
 virBufferAdd(&buf, virCommandToString(cmd), -1);
 
 if (virBufferCheckError(&buf) < 0)
-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/4] bhyve: Separate out checks from virBhyveProbeCaps

2016-06-29 Thread Fabian Freyer
At the moment this is just one check, but separating this out into a
separate function makes checks more modular, allowing for more readable
code once more checks are added. This also makes checks more easily
testable.
---
 src/bhyve/bhyve_capabilities.c | 31 ++-
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index d0af4d9..cf764c0 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -142,19 +142,13 @@ virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps)
 return ret;
 }
 
-int
-virBhyveProbeCaps(unsigned int *caps)
+static int
+bhyveProbeCapsRTC_UTC(unsigned int *caps, char *binary)
 {
-char *binary, *help;
+char *help;
 virCommandPtr cmd = NULL;
 int ret = 0, exit;
 
-binary = virFindFileInPath("bhyve");
-if (binary == NULL)
-goto out;
-if (!virFileIsExecutable(binary))
-goto out;
-
 cmd = virCommandNew(binary);
 virCommandAddArg(cmd, "-h");
 virCommandSetErrorBuffer(cmd, &help);
@@ -169,6 +163,25 @@ virBhyveProbeCaps(unsigned int *caps)
  out:
 VIR_FREE(help);
 virCommandFree(cmd);
+return ret;
+}
+
+int
+virBhyveProbeCaps(unsigned int *caps)
+{
+char *binary;
+int ret = 0;
+
+binary = virFindFileInPath("bhyve");
+if (binary == NULL)
+goto out;
+if (!virFileIsExecutable(binary))
+goto out;
+
+if ((ret = bhyveProbeCapsRTC_UTC(caps, binary)))
+goto out;
+
+ out:
 VIR_FREE(binary);
 return ret;
 }
-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/4] bhyve: virBhyveProbeCaps: BHYVE_CAP_LPC_BOOTROM

2016-06-29 Thread Fabian Freyer
Implement the BHACE_CAP_LPC_BOOTROM capability by checking the stderr
output of 'bhyve -l bootrom'. If the bootrom option is unsupported, this
will contain the following output:

bhyve: invalid lpc device configuration 'bootrom'

On newer bhyve versions that do support specifying a bootrom image, the
standard help will be printed.
---
 src/bhyve/bhyve_capabilities.c | 28 
 src/bhyve/bhyve_capabilities.h |  1 +
 2 files changed, 29 insertions(+)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index cf764c0..5d0485e 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -166,6 +166,31 @@ bhyveProbeCapsRTC_UTC(unsigned int *caps, char *binary)
 return ret;
 }
 
+static int
+bhyveProbeCapsLPC_Bootrom(unsigned int *caps, char *binary)
+{
+char *error;
+virCommandPtr cmd = NULL;
+int ret = 0, exit;
+
+cmd = virCommandNew(binary);
+virCommandAddArgList(cmd, "-l", "bootrom", NULL);
+virCommandSetErrorBuffer(cmd, &error);
+if (virCommandRun(cmd, &exit) < 0) {
+ret = -1;
+goto out;
+}
+
+if (strstr(error, "bhyve: invalid lpc device configuration 'bootrom'") == 
NULL)
+*caps |= BHYVE_CAP_LPC_BOOTROM;
+
+ out:
+VIR_FREE(error);
+virCommandFree(cmd);
+return ret;
+}
+
+
 int
 virBhyveProbeCaps(unsigned int *caps)
 {
@@ -181,6 +206,9 @@ virBhyveProbeCaps(unsigned int *caps)
 if ((ret = bhyveProbeCapsRTC_UTC(caps, binary)))
 goto out;
 
+if ((ret = bhyveProbeCapsLPC_Bootrom(caps, binary)))
+goto out;
+
  out:
 VIR_FREE(binary);
 return ret;
diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
index 0eb22a4..5ea3294 100644
--- a/src/bhyve/bhyve_capabilities.h
+++ b/src/bhyve/bhyve_capabilities.h
@@ -33,6 +33,7 @@ typedef enum {
 
 typedef enum {
 BHYVE_CAP_RTC_UTC = 1,
+BHYVE_CAP_LPC_BOOTROM = 2,
 } virBhyveCapsFlags;
 
 int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps);
-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 6/6] Add some tests for bhyveParseCommandLineString

2016-06-28 Thread Fabian Freyer


---
 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/

[libvirt] [PATCH 5/6] bhyve: implement argument parser for loader

2016-06-28 Thread Fabian Freyer


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 
---
 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
 bhyv

[libvirt] [PATCH 4/6] bhyve: implement bhyve argument parser

2016-06-28 Thread Fabian Freyer


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/nmdmA <-> /dev/nmdmB
* 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 
---
 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 
+#include 
+#include 

 #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

[libvirt] [PATCH 3/6] bhyve: implement virConnectDomainXMLFromNative

2016-06-28 Thread Fabian Freyer
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 
---
 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 000..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.
+ *
+ * Y

[libvirt] [PATCH 2/6] gnulib: add getopt module

2016-06-28 Thread Fabian Freyer


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






signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 1/6] config-post.h: define __GNUC_PREREQ if not defined

2016-06-28 Thread Fabian Freyer
(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






signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 1/6] config-post.h: define __GNUC_PREREQ if not defined

2016-06-28 Thread Fabian Freyer
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






signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

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

2016-06-28 Thread Fabian Freyer
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/msg1.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 +
 .../bhyvear

[libvirt] [PATCH v3 0/5] bhyve: virConnectDomainXMLFromNative

2016-06-23 Thread Fabian Freyer
Differences to v2:
  - style fixes (C-style comments, function naming)
  - removed unnecessary break
  - added commentary on why __GNU_C_PREREQ is defined
  - Set Domain virtType = VIR_DOMAIN_VIRT_BHYVE
  - Free domain definition on error in bhyveParseCommandLineString. This
should prevent an empty XML document to be returned.

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/msg1.html

Fabian Freyer (5):
  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

 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 | 877 
 src/bhyve/bhyve_parse_command.h |  30 ++
 8 files changed, 974 insertions(+)
 create mode 100644 src/bhyve/bhyve_parse_command.c
 create mode 100644 src/bhyve/bhyve_parse_command.h

-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 5/5] bhyve: implement argument parser for loader

2016-06-23 Thread Fabian Freyer
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 
---
 src/bhyve/bhyve_parse_command.c | 122 
 1 file changed, 122 insertions(+)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 2a64ba3..f00e7fe 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -711,6 +711,121 @@ 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 (virStrToLong_ul(parser->optarg, NULL, 10, &memory) < 0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("Failed to parse Memory."));
+goto error;
+}
+if (memory < 1024)
+memory *= 1024;
+else
+memory /= 1024UL;
+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.bootloa

[libvirt] [PATCH v3 3/5] bhyve: implement virConnectDomainXMLFromNative

2016-06-23 Thread Fabian Freyer
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 
---
 po/POTFILES.in  |   1 +
 src/Makefile.am |   2 +
 src/bhyve/bhyve_driver.c|  42 +++
 src/bhyve/bhyve_parse_command.c | 266 
 src/bhyve/bhyve_parse_command.h |  30 +
 5 files changed, 341 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 0d92448..b1580b7 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 12b66c2..d53c98f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -901,6 +901,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 c4051a1..c7abea4 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -55,6 +55,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"
@@ -1536,6 +1537,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 */
@@ -1589,6 +1630,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
 .connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */
 .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
+.connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 1.3.6 */
 };
 
 
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
new file mode 100644
index 000..b3064bc
--- /dev/null
+++ b/src/bhyve/bhyve_parse_command.c
@@ -0,0 +1,266 @@
+/*
+ * 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.
+

[libvirt] [PATCH v3 4/5] bhyve: implement bhyve argument parser

2016-06-23 Thread Fabian Freyer
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). This includes a capability check to see
  if this is actually supported by the bhyve version.
* 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/nmdmA <-> /dev/nmdmB
* 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 
---
 src/bhyve/bhyve_parse_command.c | 493 +++-
 1 file changed, 491 insertions(+), 2 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index b3064bc..2a64ba3 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -23,6 +23,7 @@
  */
 
 #include 
+#include 
 
 #include "bhyve_capabilities.h"
 #include "bhyve_command.h"
@@ -225,10 +226,495 @@ 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.file.path[last] = 'B';
+break;
+case 'B':
+chr->source.data.file.path[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_FR

[libvirt] [PATCH v3 1/5] config-post.h: define __GNUC_PREREQ if not defined

2016-06-23 Thread Fabian Freyer
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 2398d3d..9243d7d 100644
--- a/config-post.h
+++ b/config-post.h
@@ -67,3 +67,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.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 2/5] gnulib: add getopt module

2016-06-23 Thread Fabian Freyer
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.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 4/5] bhyve: implement bhyve argument parser

2016-06-23 Thread Fabian Freyer
On 12/06/16 15:29, Roman Bogorodskiy wrote:
>   Fabian Freyer wrote:
> 
>> 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). This includes a capability check to see
>>   if this is actually supported by the bhyve version.
>> * 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/nmdmA <-> /dev/nmdmB
>> * 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 
>> ---
>>  src/bhyve/bhyve_parse_command.c | 494 
>> +++-
>>  1 file changed, 492 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/bhyve/bhyve_parse_command.c 
>> b/src/bhyve/bhyve_parse_command.c
>> index 72367bb..be4ff2a 100644
>> --- a/src/bhyve/bhyve_parse_command.c
>> +++ b/src/bhyve/bhyve_parse_command.c
>> @@ -23,6 +23,7 @@
>>   */
>>  
>>  #include 
>> +#include 
>>  
>>  #include "bhyve_capabilities.h"
>>  #include "bhyve_command.h"
>> @@ -225,10 +226,496 @@ bhyveCommandLine2argv(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.file.path[last] = 'B';
>> +break;
>> +

Re: [libvirt] [PATCH v2 3/5] bhyve: implement virConnectDomainXMLFromNative

2016-06-23 Thread Fabian Freyer
On 12/06/16 16:03, Roman Bogorodskiy wrote:
>   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 
>> ---
>>  po/POTFILES.in  |   1 +
>>  src/Makefile.am |   2 +
>>  src/bhyve/bhyve_driver.c|  42 +++
>>  src/bhyve/bhyve_parse_command.c | 263 
>> 
>>  src/bhyve/bhyve_parse_command.h |  30 +
>>  5 files changed, 338 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 0d92448..b1580b7 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 12b66c2..d53c98f 100644
>> --- a/src/Makefile.am
>> +++ b/src/Makefile.am
>> @@ -901,6 +901,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 c4051a1..c7abea4 100644
>> --- a/src/bhyve/bhyve_driver.c
>> +++ b/src/bhyve/bhyve_driver.c
>> @@ -55,6 +55,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"
>> @@ -1536,6 +1537,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;
> 
> Nit: this chunk is over-indented by one space.
> 
>> +
>> +xml = virDomainDefFormat(def, capabilities, 0);
>> +
>> + cleanup:
>> +virObjectUnref(capabilities);
>> +virDomainDefFree(def);
>> +return xml;
>> +}
>> +
>>  static virHypervisorDriver bhyveHypervisorDriver = {
>>  .name = "bhyve",
>>  .connectOpen = bhyveConnectOpen, /* 1.2.2 */
>> @@ -1589,6 +1630,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
>>  .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
>> 

[libvirt] [PATCH v2 4/5] bhyve: implement bhyve argument parser

2016-06-12 Thread Fabian Freyer
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). This includes a capability check to see
  if this is actually supported by the bhyve version.
* 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/nmdmA <-> /dev/nmdmB
* 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 
---
 src/bhyve/bhyve_parse_command.c | 494 +++-
 1 file changed, 492 insertions(+), 2 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 72367bb..be4ff2a 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -23,6 +23,7 @@
  */
 
 #include 
+#include 
 
 #include "bhyve_capabilities.h"
 #include "bhyve_command.h"
@@ -225,10 +226,496 @@ bhyveCommandLine2argv(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.file.path[last] = 'B';
+break;
+case 'B':
+chr->source.data.file.path[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_FR

[libvirt] [PATCH v2 3/5] bhyve: implement virConnectDomainXMLFromNative

2016-06-12 Thread Fabian Freyer
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 
---
 po/POTFILES.in  |   1 +
 src/Makefile.am |   2 +
 src/bhyve/bhyve_driver.c|  42 +++
 src/bhyve/bhyve_parse_command.c | 263 
 src/bhyve/bhyve_parse_command.h |  30 +
 5 files changed, 338 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 0d92448..b1580b7 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 12b66c2..d53c98f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -901,6 +901,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 c4051a1..c7abea4 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -55,6 +55,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"
@@ -1536,6 +1537,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 */
@@ -1589,6 +1630,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
 .connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */
 .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
+.connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 1.3.6 */
 };
 
 
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
new file mode 100644
index 000..72367bb
--- /dev/null
+++ b/src/bhyve/bhyve_parse_command.c
@@ -0,0 +1,263 @@
+/*
+ * 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.
+

[libvirt] [PATCH v2 2/5] gnulib: add getopt module

2016-06-12 Thread Fabian Freyer
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.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 5/5] bhyve: implement argument parser for loader

2016-06-12 Thread Fabian Freyer
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 
---
 src/bhyve/bhyve_parse_command.c | 122 
 1 file changed, 122 insertions(+)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index be4ff2a..6600111 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -712,6 +712,121 @@ 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 (virStrToLong_ul(parser->optarg, NULL, 10, &memory) < 0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("Failed to parse Memory."));
+goto error;
+}
+if (memory < 1024)
+memory *= 1024;
+else
+memory /= 1024UL;
+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.bootloa

[libvirt] [PATCH v2 1/5] config-post.h: define __GNUC_PREREQ if not defined

2016-06-12 Thread Fabian Freyer
Several gnulib headers rely on feature.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 | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/config-post.h b/config-post.h
index 2398d3d..0aa8271 100644
--- a/config-post.h
+++ b/config-post.h
@@ -67,3 +67,14 @@
 # undef WITH_SECDRIVER_APPARMOR
 # undef WITH_CAPNG
 #endif /* LIBVIRT_NSS */
+
+#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.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 0/5] bhyve: virConnectDomainXMLFromNative

2016-06-12 Thread Fabian Freyer
Aaand I'm reposting this series again, in the hope that this time it will
consistently send to the mailing list. Again, very sorry for the noise.

Differences to v1:
  - use gnulib's reentrant getopt implementation. This is necessary for thread
safety.
  - config-post.h: __GNUC_PREREQ is defined here, since using gnulib's getopt
pulls in other gnulib headers, which rely on __GNUC_PREREQ, which doesn't
exist on FreeBSD.
This approach is open for discussion: I chose config-post.h as this would
likely always be the first header pulled in (through config.h).

Link to v1:
   https://www.redhat.com/archives/libvir-list/2016-June/msg1.html

Fabian Freyer (5):
  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

 bootstrap.conf  |   1 +
 config-post.h   |  11 +
 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 | 875 
 src/bhyve/bhyve_parse_command.h |  30 ++
 8 files changed, 965 insertions(+)
 create mode 100644 src/bhyve/bhyve_parse_command.c
 create mode 100644 src/bhyve/bhyve_parse_command.h

-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 Repost 0/5] bhyve: virConnectDomainXMLFromNative

2016-06-08 Thread Fabian Freyer
I'm reposting this series because I got the following two error messages from
the redhat.com MX:

  libvir-list@redhat.com
SMTP error from remote mail server after RCPT TO::
host mx1.redhat.com [209.132.183.28]: 554 5.7.1 :
Recipient address rejected: Access denied

: host int-mx.corp.redhat.com[10.4.122.10] said: 550
5.1.1 ... User unknown (in reply to RCPT TO
command)

Sorry for the noise.


Differences to v1:
  - use gnulib's reentrant getopt implementation. This is necessary for thread
safety.
  - config-post.h: __GNUC_PREREQ is defined here, since using gnulib's getopt
pulls in other gnulib headers, which rely on __GNUC_PREREQ, which doesn't
exist on FreeBSD.
This approach is open for discussion: I chose config-post.h as this would
likely always be the first header pulled in (through config.h).

Link to v1:
   https://www.redhat.com/archives/libvir-list/2016-June/msg1.html

Fabian Freyer (5):
  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

 bootstrap.conf  |   1 +
 config-post.h   |  11 +
 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 | 875 
 src/bhyve/bhyve_parse_command.h |  30 ++
 8 files changed, 965 insertions(+)
 create mode 100644 src/bhyve/bhyve_parse_command.c
 create mode 100644 src/bhyve/bhyve_parse_command.h

-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 4/5] bhyve: implement bhyve argument parser

2016-06-08 Thread Fabian Freyer
A simple 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). This includes a capability check to see
  if this is actually supported by the bhyve version.
* 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/nmdmA <-> /dev/nmdmB
* 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 
---
 src/bhyve/bhyve_parse_command.c | 494 +++-
 1 file changed, 492 insertions(+), 2 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 72367bb..be4ff2a 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -23,6 +23,7 @@
  */
 
 #include 
+#include 
 
 #include "bhyve_capabilities.h"
 #include "bhyve_command.h"
@@ -225,10 +226,496 @@ bhyveCommandLine2argv(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.file.path[last] = 'B';
+break;
+case 'B':
+chr->source.data.file.path[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_FR

[libvirt] [PATCH v2 5/5] bhyve: implement argument parser for loader

2016-06-08 Thread Fabian Freyer
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 
---
 src/bhyve/bhyve_parse_command.c | 122 
 1 file changed, 122 insertions(+)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index be4ff2a..6600111 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -712,6 +712,121 @@ 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 (virStrToLong_ul(parser->optarg, NULL, 10, &memory) < 0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("Failed to parse Memory."));
+goto error;
+}
+if (memory < 1024)
+memory *= 1024;
+else
+memory /= 1024UL;
+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.bootloa

[libvirt] [PATCH 2/5] gnulib: add getopt module

2016-06-08 Thread Fabian Freyer
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.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/5] config-post.h: define __GNUC_PREREQ if not defined

2016-06-08 Thread Fabian Freyer
Several gnulib headers rely on feature.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 | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/config-post.h b/config-post.h
index 2398d3d..0aa8271 100644
--- a/config-post.h
+++ b/config-post.h
@@ -67,3 +67,14 @@
 # undef WITH_SECDRIVER_APPARMOR
 # undef WITH_CAPNG
 #endif /* LIBVIRT_NSS */
+
+#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.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/3] bhyve: implement bhyve argument parser

2016-06-01 Thread Fabian Freyer
On 01/06/16 10:21, Fabian Freyer wrote:
> 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:

getopt is not thread safe, so can't use that here. There are a number of 
possible
solutions:

- use gnulib's getopt which provides a reentrant interface:
  https://lists.gnu.org/archive/html/bug-gnulib/2004-03/msg00018.html
- use string comparisons

I'll fix that in a v2.

> 
> * vm name
> * number of vcpus
> * memory size
> * the time offset (UTC or localtime). This includes a capability check to see
>   if this is actually supported by the bhyve version.
> * 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/nmdmA <-> /dev/nmdmB
> * 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 
> ---
>  src/bhyve/bhyve_parse_command.c | 491 
> +++-
>  1 file changed, 489 insertions(+), 2 deletions(-)
> 
> diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
> index 72367bb..0fadb6a 100644
> --- a/src/bhyve/bhyve_parse_command.c
> +++ b/src/bhyve/bhyve_parse_command.c
> @@ -23,6 +23,7 @@
>   */
>  
>  #include 
> +#include 
>  
>  #include "bhyve_capabilities.h"
>  #include "bhyve_command.h"
> @@ -225,10 +226,493 @@ bhyveCommandLine2argv(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.file.path[last] = 'B';
> +break;
> +case 'B':
> +chr->source.data.file.path[last] = 'A';
> +break;
> +default:
> +virReportError(VIR_ERR_OPERATION_FAILED,
> +  

[libvirt] [PATCH 3/3] bhyve: implement argument parser for loader

2016-06-01 Thread Fabian Freyer
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 
---
 src/bhyve/bhyve_parse_command.c | 119 
 1 file changed, 119 insertions(+)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 0fadb6a..1f7c096 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -709,6 +709,118 @@ 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;
+int opterr_saved = opterr;
+int i = 0;
+
+const char optstr[] = "CSc:d:e:h:l:m:";
+
+if (!argv)
+goto error;
+
+optind = 1;
+opterr = 0;
+while ((c = getopt(argc, argv, optstr)) != -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]), optarg)) {
+def->disks[i]->info.bootIndex = i;
+break;
+}
+}
+break;
+case 'm':
+arguments |= 2;
+if (virStrToLong_ul(optarg, NULL, 10, &memory) < 0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("Failed to parse Memory."));
+goto error;
+}
+if (memory < 1024)
+memory *= 1024;
+else
+memory /= 1024UL;
+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 != 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;
+}
+
+opterr = opterr_saved;
+return 0;
+error:
+opterr = opterr_saved;
+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;
+}
+
 virDomainDefPt

[libvirt] [PATCH 2/3] bhyve: implement bhyve argument parser

2016-06-01 Thread Fabian Freyer
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). This includes a capability check to see
  if this is actually supported by the bhyve version.
* 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/nmdmA <-> /dev/nmdmB
* 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 
---
 src/bhyve/bhyve_parse_command.c | 491 +++-
 1 file changed, 489 insertions(+), 2 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 72367bb..0fadb6a 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -23,6 +23,7 @@
  */
 
 #include 
+#include 
 
 #include "bhyve_capabilities.h"
 #include "bhyve_command.h"
@@ -225,10 +226,493 @@ bhyveCommandLine2argv(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.file.path[last] = 'B';
+break;
+case 'B':
+chr->source.data.file.path[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_FR

[libvirt] [PATCH 1/3] bhyve: implement virConnectDomainXMLFromNative

2016-06-01 Thread Fabian Freyer
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 
---
 po/POTFILES.in  |   1 +
 src/Makefile.am |   2 +
 src/bhyve/bhyve_driver.c|  42 +++
 src/bhyve/bhyve_parse_command.c | 263 
 src/bhyve/bhyve_parse_command.h |  30 +
 5 files changed, 338 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 0d92448..b1580b7 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 12b66c2..d53c98f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -901,6 +901,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 c4051a1..c7abea4 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -55,6 +55,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"
@@ -1536,6 +1537,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 */
@@ -1589,6 +1630,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
 .connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */
 .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
+.connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 1.3.6 */
 };
 
 
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
new file mode 100644
index 000..72367bb
--- /dev/null
+++ b/src/bhyve/bhyve_parse_command.c
@@ -0,0 +1,263 @@
+/*
+ * 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 sh

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

2016-06-01 Thread Fabian Freyer
The following series of patches implement virConnectDomainXMLFromNative. This
is mostly some boiler plate code generating argv-lists from the native command
string, and two getopt-based argument parsers for the /usr/sbin/bhyve and
/usr/sbin/bhyveload commands.

Since there is quite some string handling involved especially in the first
patch that I am not 100% sure about, I'd appreciate a thorough review.

Fabian Freyer (3):
  bhyve: implement virConnectDomainXMLFromNative
  bhyve: implement bhyve argument parser
  bhyve: implement argument parser for loader

 po/POTFILES.in  |   1 +
 src/Makefile.am |   2 +
 src/bhyve/bhyve_driver.c|  42 ++
 src/bhyve/bhyve_parse_command.c | 869 
 src/bhyve/bhyve_parse_command.h |  30 ++
 5 files changed, 944 insertions(+)
 create mode 100644 src/bhyve/bhyve_parse_command.c
 create mode 100644 src/bhyve/bhyve_parse_command.h

-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] conf: always format os.bootloaderArgs if set

2016-05-31 Thread Fabian Freyer
At the moment the bootloader arguments never get formatted if the bootloader is 
unset. However, in cases where the bootloader defaults to a default value when 
unset, specifying bootloader arguments does make sense.
---
 src/conf/domain_conf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 568c699..66bba6e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -22608,6 +22608,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
 if (def->os.bootloader) {
 virBufferEscapeString(buf, "%s\n",
   def->os.bootloader);
+}
+if (def->os.bootloaderArgs) {
 virBufferEscapeString(buf,
   "%s\n",
   def->os.bootloaderArgs);
-- 
2.7.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/2] bhyve: implement virConnectIsSecure

2016-05-17 Thread Fabian Freyer
Trivially return 1, since bhyve is considered a local connection that
should not be vulnerable to eavesdropping.
---
 src/bhyve/bhyve_driver.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 43c7183..441c666 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1523,6 +1523,13 @@ static int bhyveConnectIsAlive(virConnectPtr conn 
ATTRIBUTE_UNUSED)
 }
 
 static int
+bhyveConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+/* Trivially secure, since always inside the daemon */
+return 1;
+}
+
+static int
 bhyveConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 /* Not encrypted, but remote driver takes care of that */
@@ -1580,6 +1587,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .domainHasManagedSaveImage = bhyveDomainHasManagedSaveImage, /* 1.2.13 */
 .connectGetType = bhyveConnectGetType, /* 1.3.5 */
 .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
+.connectIsSecure = bhyveConnectIsSecure, /* 1.3.5 */
 .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
 };
 
-- 
2.7.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/2] bhyve: Implement virConnectIsEncrypted

2016-05-17 Thread Fabian Freyer
Being a local connection, bhyve does not support encryption. Therefore
trivially return 0.
---
 src/bhyve/bhyve_driver.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 8b41f7a..43c7183 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1522,6 +1522,13 @@ static int bhyveConnectIsAlive(virConnectPtr conn 
ATTRIBUTE_UNUSED)
 return 1;
 }
 
+static int
+bhyveConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+/* Not encrypted, but remote driver takes care of that */
+return 0;
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
 .name = "bhyve",
 .connectOpen = bhyveConnectOpen, /* 1.2.2 */
@@ -1573,6 +1580,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .domainHasManagedSaveImage = bhyveDomainHasManagedSaveImage, /* 1.2.13 */
 .connectGetType = bhyveConnectGetType, /* 1.3.5 */
 .connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
+.connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
 };
 
 
-- 
2.7.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/2] bhyve: implement virConnectIsEncrypted and virConnectIsSecure

2016-05-17 Thread Fabian Freyer
These patches implement some rather trivial missing calls in the bhyve driver.

Since the bhyve connection (Interaction through /dev/vmm as well as the 
bhyveload, bhyvectl user-space tools) is local, encryption is not applicable, 
but the connection is seen as not prone to eavesdropping.

Fabian Freyer (2):
  bhyve: Implement virConnectIsEncrypted
  bhyve: implement virConnectIsSecure

 src/bhyve/bhyve_driver.c | 16 
 1 file changed, 16 insertions(+)

-- 
2.7.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] bhyve: implement virConnectGetType

2016-05-13 Thread Fabian Freyer
On 13.05.2016 20:37, Cole Robinson wrote:
> ATTRIBUTED_UNUSED tells the compiler not to throw a warning if the parameter
> ('conn' in this case) isn't used in the function. So if the function _does_
> use the parameter, the annotation is incorrect.
> 
> That means that if you grabbed that pattern from any other GetType
> implementations, the ATTRIBUTE_UNUSED usage there may be incorrect as well. So
> more opportunity for patches :)

Done, submitted patch for the qemu driver as well.

Fabian

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] bhyve: implement virConnectIsAlive

2016-05-13 Thread Fabian Freyer
bhyve connections are local, and a "connection will be classed as alive
if it is [...] local".
---
 src/bhyve/bhyve_driver.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index c3c572e..8b41f7a 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1517,6 +1517,11 @@ bhyveConnectGetType(virConnectPtr conn)
 return "BHYVE";
 }
 
+static int bhyveConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+return 1;
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
 .name = "bhyve",
 .connectOpen = bhyveConnectOpen, /* 1.2.2 */
@@ -1567,6 +1572,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .connectDomainEventDeregisterAny = bhyveConnectDomainEventDeregisterAny, 
/* 1.2.5 */
 .domainHasManagedSaveImage = bhyveDomainHasManagedSaveImage, /* 1.2.13 */
 .connectGetType = bhyveConnectGetType, /* 1.3.5 */
+.connectIsAlive = bhyveConnectIsAlive, /* 1.3.5 */
 };
 
 
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] qemu: remove ATTRIBUTE_UNUSED in connectGetType

2016-05-13 Thread Fabian Freyer
This is not needed here, since the conn parameter is used in the ACL
checking calls, which were introduced in abf75aea2.
---
 src/qemu/qemu_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c4c4968..37d970e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1228,7 +1228,7 @@ qemuConnectSupportsFeature(virConnectPtr conn, int 
feature)
 }
 }
 
-static const char *qemuConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
+static const char *qemuConnectGetType(virConnectPtr conn) {
 if (virConnectGetTypeEnsureACL(conn) < 0)
 return NULL;
 
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] bhyve: implement virConnectGetType

2016-05-13 Thread Fabian Freyer
This implements virConnectGetType for the bhyve driver.

---
 src/bhyve/bhyve_driver.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 4fc504e..a853e94 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1508,6 +1508,15 @@ bhyveDomainHasManagedSaveImage(virDomainPtr domain, 
unsigned int flags)
 return ret;
 }
 
+static const char *
+bhyveConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+if (virConnectGetTypeEnsureACL(conn) < 0)
+return NULL;
+
+return "BHYVE";
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
 .name = "bhyve",
 .connectOpen = bhyveConnectOpen, /* 1.2.2 */
@@ -1557,6 +1566,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
 .connectDomainEventRegisterAny = bhyveConnectDomainEventRegisterAny, /* 
1.2.5 */
 .connectDomainEventDeregisterAny = bhyveConnectDomainEventDeregisterAny, 
/* 1.2.5 */
 .domainHasManagedSaveImage = bhyveDomainHasManagedSaveImage, /* 1.2.13 */
+.connectGetType = bhyveConnectGetType, /* 1.3.5 */
 };
 
 
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Introducing Fabian Freyer (GSoC 2016 student)

2016-05-11 Thread Fabian Freyer
Hi,

I'd also like to introduce myself.

My name is Fabian Freyer, and I'm very happy to be accepted as a GSoC
student this year. I currently study physics at the Technical University
of Berlin, but am working as a sysadmin in the FreeBSD world. Since my
project "Improving libvirt support for bhyve" has been detailed by my
mentor already, I won't go into more detail there. In the last weeks
I've been doing some research and preparation, and would like to start
submitting some first, rather trivial patches soon, to get into the
patch committing process.

For anyone looking to keep track of my progress, I have a wiki page [1]
for this project, where I am keeping track of my goals and progress, as
well as open questions that arise. When dealing with these, I'd
explicitely ask them on this list where applicable.

On that note, I have my first question: in the virHypervisorDriver
struct for different drivers, fields are commented by a version number.
For patches, what version number should be added there? I assume the
upcoming release (1.3.5)?

Fabian Freyer

[1]
https://wiki.freebsd.org/SummerOfCode2016/ImprovingLibvirtSupportForBhyve



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list