[libvirt] [PATCH 2/2] Add ccw test cases to qemu hotplug

2016-07-08 Thread Tomasz Flendrich
These tests verify that qemu hotplug is working properly with ccw
devices. There are both simple tests and more complex ones,
like adding a second ccw device or removing the first out of two ccw
devices.
---
 tests/qemuhotplugtest.c | 37 +
 1 file changed, 37 insertions(+)

diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index f2e7567..a493200 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -73,6 +73,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
 
 virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI);
 virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE);
+virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW);
 if (event)
 virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT);
 
@@ -523,6 +524,42 @@ mymain(void)
"device_del", QMP_OK,
"chardev-remove", QMP_OK);
 
+DO_TEST_ATTACH("base-ccw-live", "ccw-virtio", false, true,
+   "human-monitor-command", HMP("OK\\r\\n"),
+   "device_add", QMP_OK);
+DO_TEST_DETACH("base-ccw-live", "ccw-virtio", false, false,
+   "device_del", QMP_OK,
+   "human-monitor-command", HMP(""));
+
+DO_TEST_ATTACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2", false, 
true,
+   "human-monitor-command", HMP("OK\\r\\n"),
+   "device_add", QMP_OK);
+
+DO_TEST_DETACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2", false, 
false,
+   "device_del", QMP_OK,
+   "human-monitor-command", HMP(""));
+
+DO_TEST_ATTACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2-explicit", 
false, true,
+   "human-monitor-command", HMP("OK\\r\\n"),
+   "device_add", QMP_OK);
+
+DO_TEST_DETACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2-explicit", 
false, false,
+   "device_del", QMP_OK,
+   "human-monitor-command", HMP(""));
+
+/* Attach a second device, then detach the first one. Then attach the 
first one again. */
+DO_TEST_ATTACH("base-ccw-live-with-ccw-virtio", "ccw-virtio-2-explicit", 
false, true,
+   "human-monitor-command", HMP("OK\\r\\n"),
+   "device_add", QMP_OK);
+
+DO_TEST_DETACH("base-ccw-live-with-2-ccw-virtio", "ccw-virtio-1-explicit", 
false, true,
+   "device_del", QMP_OK,
+   "human-monitor-command", HMP(""));
+
+DO_TEST_ATTACH("base-ccw-live-with-2-ccw-virtio", 
"ccw-virtio-1-explicit-reverse", false, false,
+   "human-monitor-command", HMP("OK\\r\\n"),
+   "device_add", QMP_OK);
+
 qemuTestDriverFree();
 return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
1.9.1

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


[libvirt] [PATCH 1/2] Add qemu hotplug test files

2016-07-08 Thread Tomasz Flendrich
---
 .../qemuhotplug-ccw-virtio-1-explicit-reverse.xml  |  8 +++
 .../qemuhotplug-ccw-virtio-1-explicit.xml  |  8 +++
 .../qemuhotplug-ccw-virtio-2-explicit.xml  |  8 +++
 .../qemuhotplug-ccw-virtio-2.xml   |  8 +++
 .../qemuhotplug-ccw-virtio.xml |  8 +++
 .../qemuhotplug-base-ccw-live+ccw-virtio.xml   | 63 +++
 ...-2-ccw-virtio+ccw-virtio-1-explicit-reverse.xml | 73 ++
 ...ive-with-2-ccw-virtio+ccw-virtio-1-explicit.xml | 73 ++
 ...qemuhotplug-base-ccw-live-with-2-ccw-virtio.xml | 63 +++
 ...-live-with-ccw-virtio+ccw-virtio-2-explicit.xml | 73 ++
 ...-base-ccw-live-with-ccw-virtio+ccw-virtio-2.xml | 73 ++
 .../qemuhotplug-base-ccw-live-with-ccw-virtio.xml  | 63 +++
 .../qemuhotplug-base-ccw-live.xml  | 53 
 13 files changed, 574 insertions(+)
 create mode 100644 
tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit-reverse.xml
 create mode 100644 
tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit.xml
 create mode 100644 
tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2-explicit.xml
 create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2.xml
 create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live+ccw-virtio.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio+ccw-virtio-1-explicit-reverse.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio+ccw-virtio-1-explicit.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-ccw-virtio+ccw-virtio-2-explicit.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-ccw-virtio+ccw-virtio-2.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-ccw-virtio.xml
 create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live.xml

diff --git 
a/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit-reverse.xml 
b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit-reverse.xml
new file mode 100644
index 000..7cf469e
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit-reverse.xml
@@ -0,0 +1,8 @@
+
+  
+  
+  
+  
+  
+  
+
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit.xml 
b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit.xml
new file mode 100644
index 000..74bd6a9
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit.xml
@@ -0,0 +1,8 @@
+
+  
+  
+  
+  
+  
+  
+
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2-explicit.xml 
b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2-explicit.xml
new file mode 100644
index 000..b5e94c2
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2-explicit.xml
@@ -0,0 +1,8 @@
+
+  
+  
+  
+  
+  
+  
+
\ No newline at end of file
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2.xml 
b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2.xml
new file mode 100644
index 000..ebcbfa0
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2.xml
@@ -0,0 +1,8 @@
+
+  
+  
+  
+  
+  
+  
+
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio.xml 
b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio.xml
new file mode 100644
index 000..7cf469e
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio.xml
@@ -0,0 +1,8 @@
+
+  
+  
+  
+  
+  
+  
+
diff --git 
a/tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live+ccw-virtio.xml 
b/tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live+ccw-virtio.xml
new file mode 100644
index 000..2a27e11
--- /dev/null
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live+ccw-virtio.xml
@@ -0,0 +1,63 @@
+
+  hotplug
+  d091ea82-29e6-2e34-3005-f02617b36e87
+  4194304
+  4194304
+  4
+  
+hvm
+
+  
+  
+
+
+
+  
+  
+  destroy
+  restart
+  restart
+  
+/usr/libexec/qemu-kvm
+
+  
+  
+  
+  
+  
+  
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+
+  
+
+
+  
+  
+
+
+  
+
+
+  
+
+
+  
+
+
+  
+  
+
diff --git 
a/tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio+ccw-virtio-1-explicit-reverse.xml
 
b/tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio+ccw-virtio-1-explicit-reverse.xml
new file mode 100644
index 000..e03473c
--- /dev/null
+++ 

[libvirt] [PATCH 0/2] Add qemu hotplug tests with ccw devices

2016-07-08 Thread Tomasz Flendrich
These changes require another patch, or else there would be conflicts:
[libvirt] [PATCH 0/3] Clean up qemuhotplugtest xml files
https://www.redhat.com/archives/libvir-list/2016-July/msg00202.html


Hotplugging ccw devices was previously not tested, so I decided
to add some testcases because I plan on making changes to different
address types and want to make sure regression won't happen.

Please let me know if you think that the filenames are too long.

I know that some device files are duplicated. It is (right now) required
because of the way qemuhotplugtest.c calculates the expected xml
filenames. I plan on changing that to explicitly stating the basis
xml, the device xml, and the expected xml, so that there would
be no duplicates. It will also make filenames shorter.
In another patch, I will add testcases that verify attaching a device
to the persistent config. Explicitly stating the expected xml
will be even more useful then.

Tomasz Flendrich (2):
  Add qemu hotplug test files
  Add ccw test cases to qemu hotplug

 tests/qemuhotplugtest.c| 37 +++
 .../qemuhotplug-ccw-virtio-1-explicit-reverse.xml  |  8 +++
 .../qemuhotplug-ccw-virtio-1-explicit.xml  |  8 +++
 .../qemuhotplug-ccw-virtio-2-explicit.xml  |  8 +++
 .../qemuhotplug-ccw-virtio-2.xml   |  8 +++
 .../qemuhotplug-ccw-virtio.xml |  8 +++
 .../qemuhotplug-base-ccw-live+ccw-virtio.xml   | 63 +++
 ...-2-ccw-virtio+ccw-virtio-1-explicit-reverse.xml | 73 ++
 ...ive-with-2-ccw-virtio+ccw-virtio-1-explicit.xml | 73 ++
 ...qemuhotplug-base-ccw-live-with-2-ccw-virtio.xml | 63 +++
 ...-live-with-ccw-virtio+ccw-virtio-2-explicit.xml | 73 ++
 ...-base-ccw-live-with-ccw-virtio+ccw-virtio-2.xml | 73 ++
 .../qemuhotplug-base-ccw-live-with-ccw-virtio.xml  | 63 +++
 .../qemuhotplug-base-ccw-live.xml  | 53 
 14 files changed, 611 insertions(+)
 create mode 100644 
tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit-reverse.xml
 create mode 100644 
tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-1-explicit.xml
 create mode 100644 
tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2-explicit.xml
 create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio-2.xml
 create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ccw-virtio.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live+ccw-virtio.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio+ccw-virtio-1-explicit-reverse.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio+ccw-virtio-1-explicit.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-2-ccw-virtio.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-ccw-virtio+ccw-virtio-2-explicit.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-ccw-virtio+ccw-virtio-2.xml
 create mode 100644 
tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live-with-ccw-virtio.xml
 create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-ccw-live.xml

-- 
1.9.1

--
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 = bhyveConnectGetDomainCapabilities, /* 
2.1.0 */
 };
 
 
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com

[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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * 

[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 

[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, ) == 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]) {
+case 'A':
+chr->source.data.nmdm.slave[last] = 'B';
+break;
+case 'B':
+chr->source.data.nmdm.slave[last] = 'A';
+  

[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, )) {
+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**) [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**) [1], " ");
+
+return 0;
+ error:
+return -1;
+}
+
 virDomainDefPtr
 bhyveParseCommandLineString(const char* nativeConfig,
 unsigned caps,
@@ -774,6 +884,13 @@ bhyveParseCommandLineString(const 

[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


Re: [libvirt] [PATCH] libvirt.spec.in: soft-static allocation of qemu and kvm groups

2016-07-08 Thread Andrea Bolognani
On Thu, 2016-07-07 at 17:41 +0200, Jaroslav Suchanek wrote:
> Follow the same logic for adding qemu user also for kvm and qemu groups. As
> is described in https://fedoraproject.org/wiki/Packaging:UsersAndGroups
> document there should be preallocated UIDs and GIDs for libvirt. A check for
> required group id was added prior groupadd execution.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1351792
> ---
>  libvirt.spec.in | 16 ++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/libvirt.spec.in b/libvirt.spec.in
> index 2b98836..3dc3193 100644
> --- a/libvirt.spec.in
> +++ b/libvirt.spec.in
> @@ -1464,8 +1464,20 @@ fi
>  # We want soft static allocation of well-known ids, as disk images
>  # are commonly shared across NFS mounts by id rather than name; see
>  # https://fedoraproject.org/wiki/Packaging:UsersAndGroups
> -getent group kvm >/dev/null || groupadd -f -g 36 -r kvm
> -getent group qemu >/dev/null || groupadd -f -g 107 -r qemu
> +if ! getent group kvm >/dev/null; then
> +  if ! getent group 36 >/dev/null; then
> +groupadd -f -g 36 -r kvm
> +  else
> +groupadd -f -r kvm
> +  fi
> +fi
> +if ! getent group qemu >/dev/null; then
> +  if ! getent group 107 >/dev/null; then
> +groupadd -f -g 107 -r qemu
> +  else
> +groupadd -f -r qemu
> +  fi
> +fi
>  if ! getent passwd qemu >/dev/null; then
>if ! getent passwd 107 >/dev/null; then
>  useradd -r -u 107 -g qemu -G kvm -d / -s /sbin/nologin -c "qemu user" 
>qemu

There's no need to do that, as groupadd's -f flag already
does what you want in this situation:

  When used with -g, and the specified GID already exists,
  another (unique) GID is chosen

The commit that fixed the allocation issue is

  commit a2584d58f6f7d941b960f996c8e26df8294b79b9
  Author: Eric Blake 
  Date:   Wed May 1 14:28:43 2013 -0600

  spec: proper soft static allocation of qemu uid

  https://bugzilla.redhat.com/show_bug.cgi?id=924501 tracks a
  problem that occurs if uid 107 is already in use at the time
  libvirt is first installed.  In response that problem, Fedora
  packaging guidelines were recently updated.  This fixes the
  spec file to comply with the new guidelines:
  https://fedoraproject.org/wiki/Packaging:UsersAndGroups

  * libvirt.spec.in (daemon): Follow updated Fedora guidelines.

  Signed-off-by: Eric Blake 

  v1.0.5-35-ga2584d5

which has been backported to the v0.10.2-maint branch as
well. So downstream just need to pick up that commit :)

NACK

-- 
Andrea Bolognani / Red Hat / Virtualization

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

Re: [libvirt] [PATCH 05/11] tests: qemuxml2xml: Format status XML header dynamically

2016-07-08 Thread Michal Privoznik
On 07.07.2016 15:41, Peter Krempa wrote:
> Status XML tests were done by prepending a constant string to an
> existing XML. With the planned changes the header will depend on data
> present in the definition rather than just on the data that was parsed.
> 
> The first dynamic element in the header will be the vcpu thread list.
> Reuse and rename qemuXML2XMLPreFormatCallback for gathering the relevant
> data when checking the active XML parsing and formating and pass the
> bitmap to a newly crated header generator.
> ---
>  tests/qemuxml2xmltest.c | 72 
> +
>  1 file changed, 61 insertions(+), 11 deletions(-)
> 
> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
> index ae328c2..a672fbb 100644
> --- a/tests/qemuxml2xmltest.c
> +++ b/tests/qemuxml2xmltest.c
> @@ -33,13 +33,21 @@ struct testInfo {
>  char *outActiveName;
>  char *outInactiveName;
> 
> +virBitmapPtr activeVcpus;
> +
>  virQEMUCapsPtr qemuCaps;
>  };
> 
>  static int
> -qemuXML2XMLPreFormatCallback(virDomainDefPtr def ATTRIBUTE_UNUSED,
> - const void *opaque ATTRIBUTE_UNUSED)
> +qemuXML2XMLActivePreFormatCallback(virDomainDefPtr def,
> +   const void *opaque)
>  {
> +struct testInfo *info = (struct testInfo *) opaque;
> +
> +/* store vCPU bitmap so that the status XML can be created faithfully */
> +if (!info->activeVcpus)
> +info->activeVcpus = virDomainDefGetOnlineVcpumap(def);

This won't fly, @info is never cleared, in particular, its @activeVcpus is 
never set so it will contain some garbage that's on the stack when we get here:

Program received signal SIGSEGV, Segmentation fault.
0x71d76824 in virBitmapNextSetBit (bitmap=0x432bc0 <_start>, pos=0) at 
util/virbitmap.c:930
930 bits = bitmap->map[nl] & ~((1UL << nb) - 1);
(gdb) bt
#0  0x71d76824 in virBitmapNextSetBit (bitmap=0x432bc0 <_start>, pos=0) 
at util/virbitmap.c:930
#1  0x00432e1e in testGetStatuXMLPrefixVcpus (buf=0x7fffd560, 
data=0x7fffd680) at qemuxml2xmltest.c:115
#2  0x00432ecb in testGetStatusXMLPrefix (data=0x7fffd680) at 
qemuxml2xmltest.c:131
#3  0x00433003 in testCompareStatusXMLToXMLFiles 
(opaque=0x7fffd680) at qemuxml2xmltest.c:160
#4  0x00447a52 in virTestRun (title=0x55d07e "QEMU XML-2-XML-status 
minimal", body=0x432f14 , data=0x7fffd680) 
at testutils.c:179
#5  0x0043375f in mymain () at qemuxml2xmltest.c:360
#6  0x00449447 in virTestMain (argc=1, argv=0x7fffd8e8, 
func=0x43361c ) at testutils.c:969
#7  0x00446973 in main (argc=1, argv=0x7fffd8e8) at 
qemuxml2xmltest.c:891


ACK with this squashed in:

diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index a672fbb..eb392f4 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -311,6 +311,8 @@ mymain(void)
 struct testInfo info;
 virQEMUDriverConfigPtr cfg = NULL;
 
+memset(, 0, sizeof(info));
+
 if (qemuTestDriverInit() < 0)
 return EXIT_FAILURE;
 

Michal

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


Re: [libvirt] [PATCH 07/11] conf: Add private data for virDomainVcpuDef

2016-07-08 Thread Michal Privoznik
On 07.07.2016 15:41, Peter Krempa wrote:
> Allow to store driver specific data on a per-vcpu basis.
> 
> Move of the virDomainDef*Vcpus* functions was necessary as
> virDomainXMLOptionPtr was declared below this block and I didn't want to
> split the function headers.
> ---
>  src/conf/domain_conf.c| 28 +---
>  src/conf/domain_conf.h| 22 ++
>  src/hyperv/hyperv_driver.c|  3 ++-
>  src/libxl/libxl_driver.c  |  4 ++--
>  src/lxc/lxc_native.c  |  2 +-
>  src/openvz/openvz_conf.c  |  2 +-
>  src/openvz/openvz_driver.c| 16 ++--
>  src/phyp/phyp_driver.c|  2 +-
>  src/qemu/qemu_driver.c|  2 +-
>  src/qemu/qemu_parse_command.c |  9 +
>  src/test/test_driver.c|  4 +++-
>  src/vbox/vbox_common.c|  4 ++--
>  src/vmx/vmx.c |  2 +-
>  src/xen/xm_internal.c |  2 +-
>  src/xenapi/xenapi_driver.c|  2 +-
>  src/xenconfig/xen_common.c| 13 -
>  src/xenconfig/xen_common.h|  3 ++-
>  src/xenconfig/xen_sxpr.c  |  2 +-
>  src/xenconfig/xen_xl.c|  3 ++-
>  src/xenconfig/xen_xm.c|  3 ++-
>  20 files changed, 81 insertions(+), 47 deletions(-)

You forgot to update Virtuozzo (vz) driver.

> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index c2d7259..e660f8e 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -1307,12 +1307,23 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def)
> 
> 
>  static virDomainVcpuDefPtr
> -virDomainVcpuDefNew(void)
> +virDomainVcpuDefNew(virDomainXMLOptionPtr xmlopt)
>  {
> +virObjectPtr priv = NULL;
>  virDomainVcpuDefPtr ret;
> 
> -ignore_value(VIR_ALLOC(ret));
> +if (xmlopt && xmlopt->privateData.vcpuNew &&
> +!(priv = xmlopt->privateData.vcpuNew()))
> +goto cleanup;
> +
> +if (VIR_ALLOC(ret) < 0)
> +goto cleanup;
> +
> +ret->privateData = priv;
> +priv = NULL;
> 
> + cleanup:
> +virObjectUnref(priv);
>  return ret;

Funny, my compiler fails to see that @ret might be used uninitialized here.. 
All that's needed is just vcpuNew() function to fail. Initialize the @ret 
properly please.

>  }
> 

ACK if you squash this in:

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 9d0bc0d..7871230 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -1309,7 +1309,8 @@ prlsdkConvertDomainState(VIRTUAL_MACHINE_STATE 
domainState,
 
 static int
 prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
- virDomainDefPtr def)
+ virDomainDefPtr def,
+ virDomainXMLOptionPtr xmlopt)
 {
 char *buf;
 int hostcpus;
@@ -1327,7 +1328,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
 if (cpuCount > hostcpus)
 cpuCount = hostcpus;
 
-if (virDomainDefSetVcpusMax(def, cpuCount) < 0)
+if (virDomainDefSetVcpusMax(def, cpuCount, xmlopt) < 0)
 goto cleanup;
 
 if (virDomainDefSetVcpus(def, cpuCount) < 0)
@@ -1706,7 +1707,7 @@ prlsdkLoadDomain(vzDriverPtr driver, virDomainObjPtr dom)
  convert to Kbytes */
 def->mem.cur_balloon = ram << 10;
 
-if (prlsdkConvertCpuInfo(sdkdom, def) < 0)
+if (prlsdkConvertCpuInfo(sdkdom, def, driver->xmlopt) < 0)
 goto error;
 
 if (prlsdkConvertCpuMode(sdkdom, def) < 0)


Michal

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


Re: [libvirt] [PATCH 00/11] vCPU information storage improvements

2016-07-08 Thread Michal Privoznik
On 07.07.2016 15:40, Peter Krempa wrote:
> Cleanups and improvements that will make adding the new vCPU hotplug that was
> recently added to qemu easier.
> 
> Peter Krempa (11):
>   conf: Annotate that private data for objects are not copied
>   conf: Extract code formatting vCPU info
>   conf: Rename virDomainVcpuInfoPtr to virDomainVcpuDefPtr
>   conf: Don't report errors from virDomainDefGetVcpu
>   tests: qemuxml2xml: Format status XML header dynamically
>   conf: convert def->vcpus to a array of pointers
>   conf: Add private data for virDomainVcpuDef
>   qemu: domain: Add vcpu private data structure
>   qemu: domain: Extract formating and parsing of vCPU thread ids
>   qemu: Add cpu ID to the vCPU pid list in the status XML
>   qemu: Store vCPU thread ids in vcpu private data objects
> 
>  src/conf/domain_conf.c| 127 +-
>  src/conf/domain_conf.h|  32 ---
>  src/hyperv/hyperv_driver.c|   3 +-
>  src/libxl/libxl_domain.c  |   2 +-
>  src/libxl/libxl_driver.c  |   6 +-
>  src/lxc/lxc_native.c  |   2 +-
>  src/openvz/openvz_conf.c  |   2 +-
>  src/openvz/openvz_driver.c|  16 ++--
>  src/phyp/phyp_driver.c|   2 +-
>  src/qemu/qemu_cgroup.c|   2 +-
>  src/qemu/qemu_domain.c| 206 
> +++---
>  src/qemu/qemu_domain.h|  18 +++-
>  src/qemu/qemu_driver.c|  22 ++---
>  src/qemu/qemu_parse_command.c |   9 +-
>  src/qemu/qemu_process.c   |   6 +-
>  src/test/test_driver.c|   8 +-
>  src/vbox/vbox_common.c|   4 +-
>  src/vmx/vmx.c |   2 +-
>  src/vz/vz_sdk.c   |   2 +-
>  src/xen/xm_internal.c |   2 +-
>  src/xenapi/xenapi_driver.c|   2 +-
>  src/xenconfig/xen_common.c|  13 ++-
>  src/xenconfig/xen_common.h|   3 +-
>  src/xenconfig/xen_sxpr.c  |   2 +-
>  src/xenconfig/xen_xl.c|   3 +-
>  src/xenconfig/xen_xm.c|   3 +-
>  tests/qemuxml2xmltest.c   |  73 ---
>  27 files changed, 396 insertions(+), 176 deletions(-)
> 

ACK series, but see my comments to individual patches before pushing.

Michal

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


[libvirt] [PATCH RFC 3/5] libxl: implement virConnectCompareCPU

2016-07-08 Thread Joao Martins
Implement support for "virsh cpu-compare" so that we can calculate
common cpu element between a pool of hosts, which had a requirement
of providing host cpu description.

Signed-off-by: Joao Martins 
---
 src/libxl/libxl_driver.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 3189f1c..32bf150 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5740,6 +5740,43 @@ libxlConnectGetDomainCapabilities(virConnectPtr conn,
 }
 
 
+static int
+libxlConnectCompareCPU(virConnectPtr conn,
+   const char *xmlDesc,
+   unsigned int flags)
+{
+libxlDriverPrivatePtr driver = conn->privateData;
+libxlDriverConfigPtr cfg;
+int ret = VIR_CPU_COMPARE_ERROR;
+bool failIncompatible;
+
+virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+  VIR_CPU_COMPARE_ERROR);
+
+if (virConnectCompareCPUEnsureACL(conn) < 0)
+return ret;
+
+failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+
+cfg = libxlDriverConfigGet(driver);
+
+if (!cfg->caps->host.cpu ||
+!cfg->caps->host.cpu->model) {
+if (failIncompatible) {
+virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",
+   _("cannot get host CPU capabilities"));
+} else {
+VIR_WARN("cannot get host CPU capabilities");
+ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+}
+} else {
+ret = cpuCompareXML(cfg->caps->host.cpu, xmlDesc, failIncompatible);
+}
+
+virObjectUnref(cfg);
+return ret;
+}
+
 static virHypervisorDriver libxlHypervisorDriver = {
 .name = LIBXL_DRIVER_NAME,
 .connectOpen = libxlConnectOpen, /* 0.9.0 */
@@ -5842,6 +5879,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
 .nodeGetSecurityModel = libxlNodeGetSecurityModel, /* 1.2.16 */
 .domainInterfaceAddresses = libxlDomainInterfaceAddresses, /* 1.3.5 */
 .connectGetDomainCapabilities = libxlConnectGetDomainCapabilities, /* 
2.0.0 */
+.connectCompareCPU = libxlConnectCompareCPU, /* 2.1.0 */
 };
 
 static virConnectDriver libxlConnectDriver = {
-- 
2.1.4

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


[libvirt] [PATCH RFC 2/5] libxl: describe host cpu features based on hwcaps

2016-07-08 Thread Joao Martins
Parse libxl_hwcaps accounting for versions for Xen 4.4.
libxl_hwcaps is a set of cpuid leaves output that is described in [0] or
[1] in Xen 4.7. This is a collection of CPUID leaves that are we version
in libvirt whenever leaves are reordered or added. Thus we keep the
common ones in one struct and others for each version. Since
libxl_hwcaps doesn't appear to have a stable format across all supported
versions thus we need to keep track of changes as a compromise whenever
these extracting host featuresets are exported by libxl. Also we don't
fail in initializing the driver in case parsing of hwcaps failed.

xen/include/asm-x86/cpufeature.h
include/public/arch-x86/cpufeatureset.h

Signed-off-by: Joao Martins 
---
Probably to make it easier to extend hwcaps handling in the future may
be it's better to introduce an enum for the version and restructure this
in another way?
---
 src/libxl/libxl_capabilities.c | 106 +++--
 1 file changed, 103 insertions(+), 3 deletions(-)

diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index f71fd3b..c0857e5 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -36,6 +36,8 @@
 #include "domain_capabilities.h"
 #include "vircommand.h"
 #include "libxl_capabilities.h"
+#include "cpu/cpu_x86.h"
+#include "cpu/cpu_x86_data.h"
 
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
@@ -43,7 +45,8 @@
 VIR_LOG_INIT("libxl.libxl_capabilities");
 
 /* see xen-unstable.hg/xen/include/asm-x86/cpufeature.h */
-#define LIBXL_X86_FEATURE_PAE_MASK 0x40
+#define LIBXL_X86_FEATURE_PAE_MASK (1 << 6)
+#define LIBXL_X86_FEATURE_LM_MASK  (1 << 29)
 
 
 struct guest_arch {
@@ -57,17 +60,94 @@ struct guest_arch {
 
 #define XEN_CAP_REGEX 
"(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(aarch64|armv7l|x86_32|x86_64|ia64|powerpc64)(p|be)?"
 
+static int
+libxlCapsAddCPUID(virCPUx86Data *data, virCPUx86CPUID *cpuid, ssize_t ncaps)
+{
+size_t i;
+
+for (i = 0; i < ncaps; i++) {
+virCPUx86CPUID *c = [i];
+
+if (virCPUx86DataAddCPUID(data, c) < 0) {
+VIR_DEBUG("Failed to add CPUID(%x,%x)", c->eax_in, c->ecx_in);
+return -1;
+}
+}
+
+return 0;
+}
+
+/*
+ * The words represented in physinfo.hw_cap are host CPUID (sub) leafs.
+ * Position of these hasn't changed much up until Xen 4.7 with a rework
+ * on how CPUID is handled internally. As a side-effect it got normalized
+ * and also added more feature words. Although cannot be relied upon as
+ * stable interface, and hence we version changes in position of the features
+ * across all supported versions of the libxl driver until libxl exposes a
+ * stable representation of these capabilities. Fortunately not a lot of
+ * variation happened so it's still possible to keep track of these leafs
+ * to describe host CPU in libvirt capabilities. v0 is for Xen 4.4 up to 4.6,
+ * while v1 is meant for Xen 4.7, as depicted in the table below:
+ *
+ *  | v0 (Xen 4.4 - 4.6) |   v1 (Xen >= 4.7)|
+ *  -
+ *   word 0 | CPUID.0001.EDX | CPUID.0001.EDX   |
+ *   word 1 | CPUID.8001.EDX | CPUID.0001.ECX   |
+ *   word 2 | CPUID.80860001 | CPUID.8001.EDX   |
+ *   word 3 | - Linux-   | CPUID.8001.ECX   |
+ *   word 4 | CPUID.0001.ECX | CPUID.000D:1.EAX |
+ *   word 5 | CPUID.C001 | CPUID.0007:0.EBX |
+ *   word 6 | CPUID.8001.ECX | CPUID.0007:0.ECX |
+ *   word 7 | CPUID.0007.EBX | CPUID.8007.EDX   |
+ *   word 8 | - Non existent -   | CPUID.8008.EBX   |
+ *
+ */
+static virCPUDataPtr
+libxlCapsNodeData(virCPUDefPtr cpu, libxl_hwcap hwcap, unsigned version)
+{
+ssize_t ncaps;
+virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
+virCPUx86CPUID cpuid[] = {
+{ .eax_in = 0x0001, .edx = hwcap[0] },
+{ .eax_in = 0x0001, .ecx = (version > 0 ? hwcap[1] : hwcap[4]) },
+{ .eax_in = 0x8001, .edx = (version > 0 ? hwcap[2] : hwcap[1]) },
+{ .eax_in = 0x8001, .ecx = (version > 0 ? hwcap[3] : hwcap[6]) },
+{ .eax_in = 0x0007, .ebx = (version > 0 ? hwcap[5] : hwcap[7]) }
+};
+virCPUx86CPUID cpuid_ver1[] = {
+{ .eax_in = 0x000D, .ecx_in = 1U, .eax = hwcap[4] },
+{ .eax_in = 0x0007, .ecx_in = 0U, .ecx = hwcap[6] },
+{ .eax_in = 0x8007, .ecx_in = 0U, .edx = hwcap[7] },
+};
+
+ncaps = ARRAY_CARDINALITY(cpuid);
+if (libxlCapsAddCPUID(, cpuid, ncaps) < 0)
+return NULL;
+
+ncaps = ARRAY_CARDINALITY(cpuid_ver1);
+if (version > 0 && libxlCapsAddCPUID(, cpuid_ver1, ncaps) < 0)
+return NULL;
+
+return virCPUx86MakeData(cpu->arch, );
+}
+
 /* hw_caps is an array of 32-bit words whose meaning is listed in
  * xen-unstable.hg/xen/include/asm-x86/cpufeature.h.  Each feature
  * is defined in the form X*32+Y, 

[libvirt] [PATCH RFC 0/5] libxl: host cpu element in capabilities

2016-07-08 Thread Joao Martins
Hey!

This series is the RFC I mentioned in cpu map discussion for libxl[0].
That is to implement host.cpu element in caps,by getting topology and xen
hwcaps parsing done, followed by having cpu-{compare,baseline} and get cpu
models APIs implemented. Last thing missing I think it would be to
libxl_cpuid_set the features to enable/disable whichever format we choose plus
the appropriate XML convertion to/from XM and XL config formats.

Cheers,
Joao

[0] https://www.redhat.com/archives/libvir-list/2016-July/msg00237.html

Joao Martins (5):
  libxl: describe host topology in capabilities
  libxl: describe host cpu features based on hwcaps
  libxl: implement virConnectCompareCPU
  libxl: implement virConnectBaselineCPU
  libxl: implement virConnectGetCPUModelNames

 src/libxl/libxl_capabilities.c | 148 ++---
 src/libxl/libxl_driver.c   |  74 +
 2 files changed, 212 insertions(+), 10 deletions(-)

-- 
2.1.4

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


[libvirt] [PATCH RFC 5/5] libxl: implement virConnectGetCPUModelNames

2016-07-08 Thread Joao Martins
Useful for libvirt users (e.g. virt-manager) to extract CPU map
described model names. However setting of cpuid  is not
yet implemented.

Signed-off-by: Joao Martins 
---
 src/libxl/libxl_driver.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index a00dd55..c35a292 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5798,6 +5798,19 @@ libxlConnectBaselineCPU(virConnectPtr conn,
 return cpu;
 }
 
+static int
+libxlConnectGetCPUModelNames(virConnectPtr conn,
+ const char *arch,
+ char ***models,
+ unsigned int flags)
+{
+virCheckFlags(0, -1);
+if (virConnectGetCPUModelNamesEnsureACL(conn) < 0)
+return -1;
+
+return cpuGetModels(arch, models);
+}
+
 static virHypervisorDriver libxlHypervisorDriver = {
 .name = LIBXL_DRIVER_NAME,
 .connectOpen = libxlConnectOpen, /* 0.9.0 */
@@ -5902,6 +5915,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
 .connectGetDomainCapabilities = libxlConnectGetDomainCapabilities, /* 
2.0.0 */
 .connectCompareCPU = libxlConnectCompareCPU, /* 2.1.0 */
 .connectBaselineCPU = libxlConnectBaselineCPU, /* 2.1.0 */
+.connectGetCPUModelNames = libxlConnectGetCPUModelNames /* 2.1.0 */
 };
 
 static virConnectDriver libxlConnectDriver = {
-- 
2.1.4

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


[libvirt] [PATCH RFC 1/5] libxl: describe host topology in capabilities

2016-07-08 Thread Joao Martins
Refactor code from hwcaps to its own helper namely
libxlCapsInitCPU to handle all host cpu related operations.

Signed-off-by: Joao Martins 
---
 src/libxl/libxl_capabilities.c | 46 +-
 1 file changed, 37 insertions(+), 9 deletions(-)

diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index 0145116..f71fd3b 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -57,12 +57,47 @@ struct guest_arch {
 
 #define XEN_CAP_REGEX 
"(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(aarch64|armv7l|x86_32|x86_64|ia64|powerpc64)(p|be)?"
 
+/* hw_caps is an array of 32-bit words whose meaning is listed in
+ * xen-unstable.hg/xen/include/asm-x86/cpufeature.h.  Each feature
+ * is defined in the form X*32+Y, corresponding to the Y'th bit in
+ * the X'th 32-bit word of hw_cap.
+ */
+static int
+libxlCapsInitCPU(virCapsPtr caps, libxl_physinfo *phy_info)
+{
+virCPUDefPtr cpu = NULL;
+int ret = -1;
+int host_pae;
+
+if (VIR_ALLOC(cpu) < 0)
+goto error;
+
+host_pae = phy_info->hw_cap[0] & LIBXL_X86_FEATURE_PAE_MASK;
+if (host_pae &&
+virCapabilitiesAddHostFeature(caps, "pae") < 0)
+goto error;
+
+cpu->type = VIR_CPU_TYPE_HOST;
+cpu->cores = phy_info->cores_per_socket;
+cpu->threads = phy_info->threads_per_core;
+cpu->sockets = phy_info->nr_cpus / (cpu->cores * cpu->threads);
+caps->host.cpu = cpu;
+
+ret = 0;
+
+ cleanup:
+
+return ret;
+
+ error:
+virCPUDefFree(cpu);
+goto cleanup;
+}
 
 static int
 libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps)
 {
 libxl_physinfo phy_info;
-int host_pae;
 
 if (libxl_get_physinfo(ctx, _info) != 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -70,14 +105,7 @@ libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps)
 return -1;
 }
 
-/* hw_caps is an array of 32-bit words whose meaning is listed in
- * xen-unstable.hg/xen/include/asm-x86/cpufeature.h.  Each feature
- * is defined in the form X*32+Y, corresponding to the Y'th bit in
- * the X'th 32-bit word of hw_cap.
- */
-host_pae = phy_info.hw_cap[0] & LIBXL_X86_FEATURE_PAE_MASK;
-if (host_pae &&
-virCapabilitiesAddHostFeature(caps, "pae") < 0)
+if (libxlCapsInitCPU(caps, _info) < 0)
 return -1;
 
 if (virCapabilitiesSetNetPrefix(caps, LIBXL_GENERATED_PREFIX_XEN) < 0)
-- 
2.1.4

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


[libvirt] [PATCH RFC 4/5] libxl: implement virConnectBaselineCPU

2016-07-08 Thread Joao Martins
Akin to previous commit but for "virsh cpu-baseline" which
computes a baseline CPU for a set of host cpu elements.

Signed-off-by: Joao Martins 
---
 src/libxl/libxl_driver.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 32bf150..a00dd55 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -60,6 +60,7 @@
 #include "network/bridge_driver.h"
 #include "locking/domain_lock.h"
 #include "virstats.h"
+#include "cpu/cpu.h"
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -5777,6 +5778,26 @@ libxlConnectCompareCPU(virConnectPtr conn,
 return ret;
 }
 
+static char *
+libxlConnectBaselineCPU(virConnectPtr conn,
+const char **xmlCPUs,
+unsigned int ncpus,
+unsigned int flags)
+{
+char *cpu = NULL;
+
+virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
+  VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL);
+
+if (virConnectBaselineCPUEnsureACL(conn) < 0)
+goto cleanup;
+
+cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags);
+
+ cleanup:
+return cpu;
+}
+
 static virHypervisorDriver libxlHypervisorDriver = {
 .name = LIBXL_DRIVER_NAME,
 .connectOpen = libxlConnectOpen, /* 0.9.0 */
@@ -5880,6 +5901,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
 .domainInterfaceAddresses = libxlDomainInterfaceAddresses, /* 1.3.5 */
 .connectGetDomainCapabilities = libxlConnectGetDomainCapabilities, /* 
2.0.0 */
 .connectCompareCPU = libxlConnectCompareCPU, /* 2.1.0 */
+.connectBaselineCPU = libxlConnectBaselineCPU, /* 2.1.0 */
 };
 
 static virConnectDriver libxlConnectDriver = {
-- 
2.1.4

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


[libvirt] [PATCH REPOST 3/3] qemu: capabilities: Make virHostCPUGetKVMMaxVCPUs() errors fatal

2016-07-08 Thread Andrea Bolognani
An error in virHostCPUGetKVMMaxVCPUs() means we've been unable
to access /dev/kvm, or we're running on a platform that doesn't
support KVM in the first place.

If that's the case, we shouldn't ignore the error and report
domcapabilities even though we know the user won't be able to
start any KVM guest.
---
 src/qemu/qemu_capabilities.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c8d8a54..3ad71a2 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4347,9 +4347,12 @@ virQEMUCapsFillDomainCaps(virDomainCapsPtr domCaps,
 domCaps->maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps,
  domCaps->machine);
 if (domCaps->virttype == VIR_DOMAIN_VIRT_KVM) {
-int hostmaxvcpus = virHostCPUGetKVMMaxVCPUs();
-if (hostmaxvcpus >= 0)
-domCaps->maxvcpus = MIN(domCaps->maxvcpus, hostmaxvcpus);
+int hostmaxvcpus;
+
+if ((hostmaxvcpus = virHostCPUGetKVMMaxVCPUs()) < 0)
+return -1;
+
+domCaps->maxvcpus = MIN(domCaps->maxvcpus, hostmaxvcpus);
 }
 
 if (virQEMUCapsFillDomainOSCaps(os, firmwares, nfirmwares) < 0 ||
-- 
2.7.4

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


[libvirt] [PATCH REPOST 2/3] util: hostcpu: Drop obsolete compatibility code

2016-07-08 Thread Andrea Bolognani
All Linux releases we support (RHEL6 era) include these
definitions.
---
 src/util/virhostcpu.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index a33932f..8a8bda8 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -65,17 +65,6 @@ VIR_LOG_INIT("util.hostcpu");
 
 #define KVM_DEVICE "/dev/kvm"
 
-/* add definitions missing in older linux/kvm.h */
-#ifndef KVMIO
-# define KVMIO 0xAE
-#endif
-#ifndef KVM_CHECK_EXTENSION
-# define KVM_CHECK_EXTENSION   _IO(KVMIO,   0x03)
-#endif
-#ifndef KVM_CAP_NR_VCPUS
-# define KVM_CAP_NR_VCPUS 9   /* returns max vcpus per vm */
-#endif
-
 
 #if defined(__FreeBSD__) || defined(__APPLE__)
 static int
-- 
2.7.4

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


[libvirt] [PATCH REPOST 0/3] Small cleanups and improvements

2016-07-08 Thread Andrea Bolognani
Rebased on top of current master.

Previous attempt:

  https://www.redhat.com/archives/libvir-list/2016-June/msg02037.html


Andrea Bolognani (3):
  util: hostcpu: Add virHostCPUGetKVMMaxVCPUs() stub
  util: hostcpu: Drop obsolete compatibility code
  qemu: capabilities: Make virHostCPUGetKVMMaxVCPUs() errors fatal

 src/qemu/qemu_capabilities.c |  9 ++---
 src/util/virhostcpu.c| 25 -
 2 files changed, 18 insertions(+), 16 deletions(-)

-- 
2.7.4

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


[libvirt] [PATCH REPOST 1/3] util: hostcpu: Add virHostCPUGetKVMMaxVCPUs() stub

2016-07-08 Thread Andrea Bolognani
If we don't HAVE_LINUX_KVM_H, we can't query /dev/kvm to discover
the limits on the number of vCPUs, so we report an error and
return a negative value instead.
---
 src/util/virhostcpu.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 4ff4e72..a33932f 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -1299,6 +1299,7 @@ virHostCPUGetThreadsPerSubcore(virArch arch 
ATTRIBUTE_UNUSED)
 
 #endif /* HAVE_LINUX_KVM_H && defined(KVM_CAP_PPC_SMT) */
 
+#if HAVE_LINUX_KVM_H
 int
 virHostCPUGetKVMMaxVCPUs(void)
 {
@@ -1310,11 +1311,11 @@ virHostCPUGetKVMMaxVCPUs(void)
 return -1;
 }
 
-#ifdef KVM_CAP_MAX_VCPUS
+# ifdef KVM_CAP_MAX_VCPUS
 /* at first try KVM_CAP_MAX_VCPUS to determine the maximum count */
 if ((ret = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_MAX_VCPUS)) > 0)
 goto cleanup;
-#endif /* KVM_CAP_MAX_VCPUS */
+# endif /* KVM_CAP_MAX_VCPUS */
 
 /* as a fallback get KVM_CAP_NR_VCPUS (the recommended maximum number of
  * vcpus). Note that on most machines this is set to 160. */
@@ -1329,3 +1330,12 @@ virHostCPUGetKVMMaxVCPUs(void)
 VIR_FORCE_CLOSE(fd);
 return ret;
 }
+#else
+int
+virHostCPUGetKVMMaxVCPUs(void)
+{
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("KVM is not supported on this platform"));
+return -1;
+}
+#endif /* HAVE_LINUX_KVM_H */
-- 
2.7.4

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


[libvirt] [PATCH 1/2] qemu: Copy complete domain def in qemuDomainDefFormatBuf

2016-07-08 Thread Jiri Denemark
Playing directly with our live definition, updating it, and reverting it
back once we are done is very nice and it's quite dangerous too. Let's
just make a copy of the domain definition if needed and do all tricks on
the copy.

https://bugzilla.redhat.com/show_bug.cgi?id=1320470

Signed-off-by: Jiri Denemark 
---
 src/conf/domain_conf.c | 10 ++
 src/qemu/qemu_domain.c | 44 
 2 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cf5eb1d..72ff5c1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -21039,10 +21039,12 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
 break;
 
 case VIR_DOMAIN_CHR_TYPE_UNIX:
-virBufferAsprintf(buf, "data.nix.listen ? "bind" : "connect");
-virBufferEscapeString(buf, " path='%s'", def->data.nix.path);
-virDomainSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags);
+if (def->data.nix.path) {
+virBufferAsprintf(buf, "data.nix.listen ? "bind" : "connect");
+virBufferEscapeString(buf, " path='%s'", def->data.nix.path);
+virDomainSourceDefFormatSeclabel(buf, nseclabels, seclabels, 
flags);
+}
 break;
 
 case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 930e0b7..1b0279b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3071,19 +3071,25 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
virBuffer *buf)
 {
 int ret = -1;
-virCPUDefPtr cpu = NULL;
-virCPUDefPtr def_cpu = def->cpu;
-virDomainControllerDefPtr *controllers = NULL;
-int ncontrollers = 0;
+virDomainDefPtr copy = NULL;
 virCapsPtr caps = NULL;
 
 if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
 goto cleanup;
 
+if (!(flags & (VIR_DOMAIN_XML_UPDATE_CPU | VIR_DOMAIN_XML_MIGRATABLE)))
+goto format;
+
+if (!(copy = virDomainDefCopy(def, caps, driver->xmlopt,
+  flags & VIR_DOMAIN_XML_MIGRATABLE)))
+goto cleanup;
+
+def = copy;
+
 /* Update guest CPU requirements according to host CPU */
 if ((flags & VIR_DOMAIN_XML_UPDATE_CPU) &&
-def_cpu &&
-(def_cpu->mode != VIR_CPU_MODE_CUSTOM || def_cpu->model)) {
+def->cpu &&
+(def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
 if (!caps->host.cpu ||
 !caps->host.cpu->model) {
 virReportError(VIR_ERR_OPERATION_FAILED,
@@ -3091,10 +3097,8 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
 goto cleanup;
 }
 
-if (!(cpu = virCPUDefCopy(def_cpu)) ||
-cpuUpdate(cpu, caps->host.cpu) < 0)
+if (cpuUpdate(def->cpu, caps->host.cpu) < 0)
 goto cleanup;
-def->cpu = cpu;
 }
 
 if ((flags & VIR_DOMAIN_XML_MIGRATABLE)) {
@@ -3151,10 +3155,11 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
 }
 
 if (toremove) {
-controllers = def->controllers;
-ncontrollers = def->ncontrollers;
+virDomainControllerDefPtr *controllers = def->controllers;
+int ncontrollers = def->ncontrollers;
+
 if (VIR_ALLOC_N(def->controllers, ncontrollers - toremove) < 0) {
-controllers = NULL;
+def->controllers = controllers;
 goto cleanup;
 }
 
@@ -3163,23 +3168,22 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
 if (controllers[i] != usb && controllers[i] != pci)
 def->controllers[def->ncontrollers++] = controllers[i];
 }
+
+VIR_FREE(controllers);
+virDomainControllerDefFree(pci);
+virDomainControllerDefFree(usb);
 }
 
 
 }
 
-ret = virDomainDefFormatInternal(def, driver->caps,
+ format:
+ret = virDomainDefFormatInternal(def, caps,
  virDomainDefFormatConvertXMLFlags(flags),
  buf);
 
  cleanup:
-def->cpu = def_cpu;
-virCPUDefFree(cpu);
-if (controllers) {
-VIR_FREE(def->controllers);
-def->controllers = controllers;
-def->ncontrollers = ncontrollers;
-}
+virDomainDefFree(copy);
 virObjectUnref(caps);
 return ret;
 }
-- 
2.9.0

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


[libvirt] [PATCH 0/2] Fix migration with an auto generated channel path

2016-07-08 Thread Jiri Denemark
https://bugzilla.redhat.com/show_bug.cgi?id=1320470

Jiri Denemark (2):
  qemu: Copy complete domain def in qemuDomainDefFormatBuf
  qemu: Drop default channel path during migration

 src/conf/domain_conf.c | 10 +++---
 src/qemu/qemu_domain.c | 87 +-
 2 files changed, 57 insertions(+), 40 deletions(-)

-- 
2.9.0

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


[libvirt] [PATCH 2/2] qemu: Drop default channel path during migration

2016-07-08 Thread Jiri Denemark
Migration to an older libvirt (pre v1.3.0-175-g7140807) is broken
because older versions of libvirt generated different channel paths and
they didn't drop the default paths when parsing domain XMLs. We'd get
such a nice error message:

internal error: process exited while connecting to monitor:
2016-07-08T15:28:02.665706Z qemu-kvm: -chardev socket,
id=charchannel0,path=/var/lib/libvirt/qemu/channel/target/
domain-3-nest/org.qemu.guest_agent.0,server,nowait: Failed to bind
socket to /var/lib/libvirt/qemu/channel/target/domain-3-nest/
org.qemu.guest_agent.0: No such file or directory

That said, we should not even format the default paths when generating a
migratable XML.

https://bugzilla.redhat.com/show_bug.cgi?id=1320470

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c | 43 +++
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 1b0279b..0ef593c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2264,6 +2264,29 @@ qemuDomainDefaultNetModel(const virDomainDef *def,
 return "rtl8139";
 }
 
+
+/*
+ * Clear auto generated unix socket path, i.e., the one which starts with our
+ * channel directory.
+ */
+static void
+qemuDomainChrDefDropDefaultPath(virDomainChrDefPtr chr,
+virQEMUDriverPtr driver)
+{
+virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+
+if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
+chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO &&
+chr->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
+chr->source.data.nix.path &&
+STRPREFIX(chr->source.data.nix.path, cfg->channelTargetDir)) {
+VIR_FREE(chr->source.data.nix.path);
+}
+
+virObjectUnref(cfg);
+}
+
+
 static int
 qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
  const virDomainDef *def,
@@ -2345,21 +2368,8 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
 /* clear auto generated unix socket path for inactive definitions */
 if ((parseFlags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
-dev->type == VIR_DOMAIN_DEVICE_CHR &&
-dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
-dev->data.chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO 
&&
-dev->data.chr->source.type == VIR_DOMAIN_CHR_TYPE_UNIX &&
-dev->data.chr->source.data.nix.path &&
-STRPREFIX(dev->data.chr->source.data.nix.path, cfg->channelTargetDir)) 
{
-/*
- * If the address is generated by us (starts with our
- * channel dir), we should not keep it in the persistent
- * XML.  If libvirt is the one who generated it, users
- * shouldn't care about that.  If they do, they are
- * supposed to set it themselves.
- */
-VIR_FREE(dev->data.chr->source.data.nix.path);
-}
+dev->type == VIR_DOMAIN_DEVICE_CHR)
+qemuDomainChrDefDropDefaultPath(dev->data.chr, driver);
 
 /* forbid capabilities mode hostdev in this kind of hypervisor */
 if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
@@ -3174,7 +3184,8 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
 virDomainControllerDefFree(usb);
 }
 
-
+for (i = 0; i < def->nchannels; i++)
+qemuDomainChrDefDropDefaultPath(def->channels[i], driver);
 }
 
  format:
-- 
2.9.0

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


Re: [libvirt] cpu_map data access for libxl driver

2016-07-08 Thread Joao Martins
On 07/08/2016 09:08 AM, Cedric Bosdonnat wrote:
> Hello Joao!
> 
> On Thu, 2016-07-07 at 16:20 +0100, Joao Martins wrote:
>> FYI I too am working on guest  config work and have an RFC wrt to 
>> libvirt host
>> cpu detection. Perhaps we could joint work on this?
> 
> I started looking at the host cpu detection yesterday, but it seems the libxl
> hw_map bits aren't too easy to understand. But sure, if we can join efforts
> that would be good.
> 
Indeed, libxl hw_caps changes from Xen 4.4-4.6 to Xen 4.7 - and it wasn't 
somewhat
stabilized until the latter, although field is provided from even earlier xen
versions. So the quirk there is to handle that, other than that is plain cpuid 
leaves
output.

> I also couldn't find your RFC in the mailing list archives. Do you have code 
> available
> somewhere? Joining efforts without stepping on each other's toes isn't that 
> easy ;)
Ah, sure! I don't have a public tree available these days - let me post that 
shortly
on the list for discussion and we could continue from there (will CC you on the 
series).

>> As you know, there are two forms to represent this info in xen libxl cpuid: 
>> 1) is the
>> xend format which provides the input leaf and output registers values raw 
>> CPUID data,
>> and 2) the libxl format. Though while man page depicts what the feature 
>> names are -
>> the correspondent input, output registers, and feature names aren't really 
>> exported
>> by libxl headers and will have to be replicated in libvirt and adjusted to 
>> API
>> changes. So probably xend format would be better suited - which can possible
>> accomodate other leafs than those described by the libxl format? There is 
>> also a
>> special case for 'vmx' where we need to set libxl-side nestedhvm attribute 
>> to true
>> (on HVM guests).
> 
> Sure the xend format would be more flexible, however it's fairly easy to map 
> the
> libvirt names to the xen ones: those are mostly the same. This also helps 
> checking
> for the xen unsupported flags. Doing the mapping manually helped me see that 
> libxl
> has CPU features flags that libvirt doesn't have (maybe we'll have to add 
> them).
> And anyway, we will have to adjust the libvirt feature set if there are more 
> features
> supported in future libxl/xen versions as libvirt's  doesn't hold the 
> register bits
> but strings.
Hmm, mapping would be fairly easy indeed. I was more concerned about duplication
in libxl driver - specially as these feature names in libxl are private (as 
seen from
a library perspective and will have to piggy back what it is on libxl_cpuid.c, 
even
though mnemonics are similar). While having to keep up with changes between 
libxl and
cpu_map.xml in between. But perhaps may be that's less of a concern as 
cpu_map.xml is
made thinking for that sort of adjustments?

The register bits can be fetched as far as I could see from the APIs (see 
below). I
was more thinking along the lines of knowing the register bits from each 
feature name
somehow and just construct the string accordingly (potentially leading to a 
smaller
amounts of code?), and then support xl format whenever everything is exported. 
Or you
think it's a less preferable way to how it should be handled in libvirt? On the 
other
hand the xend syntax might be more cumbersome when setting things that we 
shouldn't,
even though is up to the libxl cpuid policy to validate.

Irrespective of the format we decide to use - we need somehow to convert a guest
 definition a complete list of CPUID/featurename data or pre-store id in 
cpu map
definitions in libxl cfg object. We can actually get the CPUID part through
cpuGuestData() (the input/ouput registers). Say for example on running on a 
Broadwell
processor and we use this cpu definition (the example doesn't make a lot of 
sense
here, it's just for the purpose of pointing out the issue):


   Nehalem
   


The CPUID registers part coming from cpuGuestData returns me this:

libxlMakeCPU:318 : CPUID[0] input=(EAX=1,ECX=0) :EAX=000306d0, EBX=
ECX=10982201 EDX=078bfbfd
libxlMakeCPU:318 : CPUID[1] input=(EAX=7,ECX=0) :EAX=, EBX=
ECX= EDX=
libxlMakeCPU:318 : CPUID[2] input=(EAX=d,ECX=1) :EAX=, EBX=
ECX= EDX=
libxlMakeCPU:318 : CPUID[3] input=(EAX=8001,ECX=0) :EAX=, 
EBX=
ECX=0001 EDX=20100800
libxlMakeCPU:318 : CPUID[4] input=(EAX=8007,ECX=0) :EAX=, 
EBX=
ECX= EDX=

So we would need to set too all features corresponding to Nehalem model as 
described
by cpu_map.xml, plus setting up AVX (in the context of this example). libxl 
keeps no
info of features associated with each model/family so there wouldn't be a 
shortcut
akin to QEMU where IIUC libvirt feeds qemu with the expected models and 
features that
it will use. Thoughts?

Joao

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


Re: [libvirt] [PATCH] qemu: report vcpu state in virDomainGetVcpus

2016-07-08 Thread Viktor Mihajlovski
On 08.07.2016 16:38, Peter Krempa wrote:
[snip]
>>>
>> Right, I can add another API to retrieve only the states, still using
>> the same monitor interface. I didn't want to break policy (in fact I
>> wasn't aware of that particular one), apologies.
> 
> Well, there isn't much of a policy at this point. Just that updating of
> the thread IDs when not necessary isn't a good approach.
> 
> Also please try to base the patch on the series I've posted so I don't
> have to rework it completely.
> 

Dang, mid-air collision. I'll post an update once I've sampled your
series. Thanks for the feedback.

-- 

Mit freundlichen Grüßen/Kind Regards
   Viktor Mihajlovski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martina Köderitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

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


Re: [libvirt] [PATCH] qemu: report vcpu state in virDomainGetVcpus

2016-07-08 Thread Peter Krempa
On Fri, Jul 08, 2016 at 16:33:59 +0200, Viktor Mihajlovski wrote:
> On 08.07.2016 15:54, Peter Krempa wrote:
> > On Fri, Jul 08, 2016 at 15:39:00 +0200, Boris Fiuczynski wrote:
> >> From: Viktor Mihajlovski 
> >>
> >> Currently, the virVcpuInfo returned by virDomainGetVcpus() will always
> >> report a state of VIR_VCPU_RUNNING for each defined domain vcpu even if
> >> the vcpu is currently in the halted state.
> >>
> >> As the monitor interface is in fact reporting the accurate state, it is
> >> rather easy to transport this information with the existing API.
> > 
> > Could you please elaborat how you expect to use this info?
> Dpending on the architecture, the halted state is an indication that the
> virtual CPU is not in use. On s390x for example the halted state is only
> reported if the CPU is stopped or in disabled wait, both indicating that
> the virtual CPUs are not enabled for the operating system.
> This information can be used by a libvirt client application for
> hotplugging decisions, and this is in fact the intention.

Okay that sounds reasonable.

> >> This is done by
> >> - adding a new state of VIR_VCPU_HALTED
> >> - extending the monitor to pass back the halted state for the vcpus
> >> - adding a new array to the private domain object reflecting the halted
> >>   state for the vcpus and update it along with the vcpu pids array
> >> - modifying the driver code to report the vcpu state based on the halted
> >>   indicator
> >> - extending virsh vcpuinfo to also display the halted state
> >> - modifying the monitor_json testcase
> >>
> >> The vcpu state is however not recorded in the internal XML format, since
> >> the state can change asynchronously (without notification).
> > 
> > virDomainGetVcpus does not call qemuDomainDetectVcpuPids nor does not
> > update the info in any way. qemuDomainDetectVcpuPids is called just at
> > startup of the qemu process. As of such this is reporting old data at
> > any time and thus doesn't really make much sense in the current state.
> Well, it's also called in the course of CPU hotplugging to update the
> CPU pids, but you are right in that the info is getting stale quickly.
> > 
> > Please note that calling qemuDomainDetectVcpuPids is not desired in
> > virDomainGetVcpus. You would need to update just the vcpu states.
> > 
> Right, I can add another API to retrieve only the states, still using
> the same monitor interface. I didn't want to break policy (in fact I
> wasn't aware of that particular one), apologies.

Well, there isn't much of a policy at this point. Just that updating of
the thread IDs when not necessary isn't a good approach.

Also please try to base the patch on the series I've posted so I don't
have to rework it completely.

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


Re: [libvirt] [PATCH] qemu: report vcpu state in virDomainGetVcpus

2016-07-08 Thread Viktor Mihajlovski
On 08.07.2016 15:54, Peter Krempa wrote:
> On Fri, Jul 08, 2016 at 15:39:00 +0200, Boris Fiuczynski wrote:
>> From: Viktor Mihajlovski 
>>
>> Currently, the virVcpuInfo returned by virDomainGetVcpus() will always
>> report a state of VIR_VCPU_RUNNING for each defined domain vcpu even if
>> the vcpu is currently in the halted state.
>>
>> As the monitor interface is in fact reporting the accurate state, it is
>> rather easy to transport this information with the existing API.
> 
> Could you please elaborat how you expect to use this info?
Dpending on the architecture, the halted state is an indication that the
virtual CPU is not in use. On s390x for example the halted state is only
reported if the CPU is stopped or in disabled wait, both indicating that
the virtual CPUs are not enabled for the operating system.
This information can be used by a libvirt client application for
hotplugging decisions, and this is in fact the intention.
> 
>> This is done by
>> - adding a new state of VIR_VCPU_HALTED
>> - extending the monitor to pass back the halted state for the vcpus
>> - adding a new array to the private domain object reflecting the halted
>>   state for the vcpus and update it along with the vcpu pids array
>> - modifying the driver code to report the vcpu state based on the halted
>>   indicator
>> - extending virsh vcpuinfo to also display the halted state
>> - modifying the monitor_json testcase
>>
>> The vcpu state is however not recorded in the internal XML format, since
>> the state can change asynchronously (without notification).
> 
> virDomainGetVcpus does not call qemuDomainDetectVcpuPids nor does not
> update the info in any way. qemuDomainDetectVcpuPids is called just at
> startup of the qemu process. As of such this is reporting old data at
> any time and thus doesn't really make much sense in the current state.
Well, it's also called in the course of CPU hotplugging to update the
CPU pids, but you are right in that the info is getting stale quickly.
> 
> Please note that calling qemuDomainDetectVcpuPids is not desired in
> virDomainGetVcpus. You would need to update just the vcpu states.
> 
Right, I can add another API to retrieve only the states, still using
the same monitor interface. I didn't want to break policy (in fact I
wasn't aware of that particular one), apologies.

-- 

Mit freundlichen Grüßen/Kind Regards
   Viktor Mihajlovski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martina Köderitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

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


Re: [libvirt] [PATCH 0/3] Clean up some duplicated code in qemuProcessSetup* functions

2016-07-08 Thread Michal Privoznik
On 07.07.2016 15:27, Martin Kletzander wrote:
> Initially posted in order to achieve something else, but that got
> rejected, so at least the cleanup part of it could make it in.
> 
> The previous versions (whose goal was something completely idfferent) are 
> here:
> 
>  - https://www.redhat.com/archives/libvir-list/2016-June/msg01537.html
> 
>  - https://www.redhat.com/archives/libvir-list/2016-July/msg00173.html
> 
> 
> Martin Kletzander (3):
>   qemu: Add qemuProcessSetupPid() and use it in
> qemuProcessSetupIOThread()
>   qemu: Use qemuProcessSetupPid() in qemuProcessSetupEmulator()
>   qemu: Use qemuProcessSetupPid() in qemuProcessSetupVcpu()
> 
>  src/qemu/qemu_process.c | 283 
> 
>  1 file changed, 92 insertions(+), 191 deletions(-)
> 

ACK series.

Nice cleanup!

Michal

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


Re: [libvirt] [PATCH 0/2] qemu: use -display none instead of -nographic

2016-07-08 Thread Paolo Bonzini


On 07/07/2016 11:59, Michal Privoznik wrote:
> BTW: there are lots of '-nographic' in our
> tests/qemuxml2argvdata/qemuxml2argv-*.args files, do we want to update
> those to have '-display none' instead?

Possibly, but to do that you'd have to add the capability to all the
tests.  It would be irrelevant for most tests, which test disk XML and
the like.

Paolo

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


Re: [libvirt] [PATCH] qemu: report vcpu state in virDomainGetVcpus

2016-07-08 Thread Peter Krempa
On Fri, Jul 08, 2016 at 15:39:00 +0200, Boris Fiuczynski wrote:
> From: Viktor Mihajlovski 
> 
> Currently, the virVcpuInfo returned by virDomainGetVcpus() will always
> report a state of VIR_VCPU_RUNNING for each defined domain vcpu even if
> the vcpu is currently in the halted state.
> 
> As the monitor interface is in fact reporting the accurate state, it is
> rather easy to transport this information with the existing API.

Could you please elaborat how you expect to use this info?

> This is done by
> - adding a new state of VIR_VCPU_HALTED
> - extending the monitor to pass back the halted state for the vcpus
> - adding a new array to the private domain object reflecting the halted
>   state for the vcpus and update it along with the vcpu pids array
> - modifying the driver code to report the vcpu state based on the halted
>   indicator
> - extending virsh vcpuinfo to also display the halted state
> - modifying the monitor_json testcase
> 
> The vcpu state is however not recorded in the internal XML format, since
> the state can change asynchronously (without notification).

virDomainGetVcpus does not call qemuDomainDetectVcpuPids nor does not
update the info in any way. qemuDomainDetectVcpuPids is called just at
startup of the qemu process. As of such this is reporting old data at
any time and thus doesn't really make much sense in the current state.

Please note that calling qemuDomainDetectVcpuPids is not desired in
virDomainGetVcpus. You would need to update just the vcpu states.

Still doing so doesn't seem to make much sense and thus I'd like an
elaboration why this is necessary.

> Signed-off-by: Viktor Mihajlovski 
> Signed-off-by: Boris Fiuczynski 
> Reviewed-by: Bjoern Walk 
> ---
>  include/libvirt/libvirt-domain.h |  1 +
>  src/qemu/qemu_domain.c   | 26 +-
>  src/qemu/qemu_domain.h   |  2 ++
>  src/qemu/qemu_driver.c   | 14 +-
>  src/qemu/qemu_monitor.c  |  7 ---
>  src/qemu/qemu_monitor.h  |  3 ++-
>  src/qemu/qemu_monitor_json.c | 22 +++---
>  src/qemu/qemu_monitor_json.h |  3 ++-
>  src/qemu/qemu_monitor_text.c | 17 +++--
>  src/qemu/qemu_monitor_text.h |  3 ++-
>  src/qemu/qemu_process.c  |  1 +
>  tests/qemumonitorjsontest.c  | 18 +++---
>  tools/virsh-domain.c |  3 ++-
>  13 files changed, 103 insertions(+), 17 deletions(-)
> 
> diff --git a/include/libvirt/libvirt-domain.h 
> b/include/libvirt/libvirt-domain.h
> index 7ea93aa..98b9420 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -1656,6 +1656,7 @@ typedef enum {
>  VIR_VCPU_OFFLINE= 0,/* the virtual CPU is offline */
>  VIR_VCPU_RUNNING= 1,/* the virtual CPU is running */
>  VIR_VCPU_BLOCKED= 2,/* the virtual CPU is blocked on resource */
> +VIR_VCPU_HALTED = 3,/* the virtual CPU is halted */
>  
>  # ifdef VIR_ENUM_SENTINELS
>  VIR_VCPU_LAST
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 42b5511..3428605 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -1256,6 +1256,7 @@ qemuDomainObjPrivateFree(void *data)
>  virDomainChrSourceDefFree(priv->monConfig);
>  qemuDomainObjFreeJob(priv);
>  VIR_FREE(priv->vcpupids);

I'm currently refactoring the code to get rid of this structure. (See
https://www.redhat.com/archives/libvir-list/2016-July/msg00182.html ) So
this is going against that direction.

> +VIR_FREE(priv->vcpuhalted);
>  VIR_FREE(priv->lockState);
>  VIR_FREE(priv->origname);

[...]

> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 098e654..0272fb4 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -1656,14 +1656,15 @@ qemuMonitorSystemReset(qemuMonitorPtr mon)
>   */
>  int
>  qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
> -  int **pids)
> +  int **pids,
> +  bool **haltpids)

The name of the variable doesn't make sense. The array refers to vcpus
rather than pids.

>  {
>  QEMU_CHECK_MONITOR(mon);
>  
>  if (mon->json)
> -return qemuMonitorJSONGetCPUInfo(mon, pids);
> +return qemuMonitorJSONGetCPUInfo(mon, pids, haltpids);
>  else
> -return qemuMonitorTextGetCPUInfo(mon, pids);
> +return qemuMonitorTextGetCPUInfo(mon, pids, haltpids);

Peter

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


[libvirt] [PATCH] qemu: report vcpu state in virDomainGetVcpus

2016-07-08 Thread Boris Fiuczynski
From: Viktor Mihajlovski 

Currently, the virVcpuInfo returned by virDomainGetVcpus() will always
report a state of VIR_VCPU_RUNNING for each defined domain vcpu even if
the vcpu is currently in the halted state.

As the monitor interface is in fact reporting the accurate state, it is
rather easy to transport this information with the existing API.

This is done by
- adding a new state of VIR_VCPU_HALTED
- extending the monitor to pass back the halted state for the vcpus
- adding a new array to the private domain object reflecting the halted
  state for the vcpus and update it along with the vcpu pids array
- modifying the driver code to report the vcpu state based on the halted
  indicator
- extending virsh vcpuinfo to also display the halted state
- modifying the monitor_json testcase

The vcpu state is however not recorded in the internal XML format, since
the state can change asynchronously (without notification).

Signed-off-by: Viktor Mihajlovski 
Signed-off-by: Boris Fiuczynski 
Reviewed-by: Bjoern Walk 
---
 include/libvirt/libvirt-domain.h |  1 +
 src/qemu/qemu_domain.c   | 26 +-
 src/qemu/qemu_domain.h   |  2 ++
 src/qemu/qemu_driver.c   | 14 +-
 src/qemu/qemu_monitor.c  |  7 ---
 src/qemu/qemu_monitor.h  |  3 ++-
 src/qemu/qemu_monitor_json.c | 22 +++---
 src/qemu/qemu_monitor_json.h |  3 ++-
 src/qemu/qemu_monitor_text.c | 17 +++--
 src/qemu/qemu_monitor_text.h |  3 ++-
 src/qemu/qemu_process.c  |  1 +
 tests/qemumonitorjsontest.c  | 18 +++---
 tools/virsh-domain.c |  3 ++-
 13 files changed, 103 insertions(+), 17 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 7ea93aa..98b9420 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1656,6 +1656,7 @@ typedef enum {
 VIR_VCPU_OFFLINE= 0,/* the virtual CPU is offline */
 VIR_VCPU_RUNNING= 1,/* the virtual CPU is running */
 VIR_VCPU_BLOCKED= 2,/* the virtual CPU is blocked on resource */
+VIR_VCPU_HALTED = 3,/* the virtual CPU is halted */
 
 # ifdef VIR_ENUM_SENTINELS
 VIR_VCPU_LAST
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 42b5511..3428605 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1256,6 +1256,7 @@ qemuDomainObjPrivateFree(void *data)
 virDomainChrSourceDefFree(priv->monConfig);
 qemuDomainObjFreeJob(priv);
 VIR_FREE(priv->vcpupids);
+VIR_FREE(priv->vcpuhalted);
 VIR_FREE(priv->lockState);
 VIR_FREE(priv->origname);
 
@@ -5470,6 +5471,7 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver,
  int asyncJob)
 {
 pid_t *cpupids = NULL;
+bool *cpuhalted = NULL;
 int ncpupids = 0;
 qemuDomainObjPrivatePtr priv = vm->privateData;
 
@@ -5506,7 +5508,7 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver,
 
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 return -1;
-ncpupids = qemuMonitorGetCPUInfo(priv->mon, );
+ncpupids = qemuMonitorGetCPUInfo(priv->mon, , );
 if (qemuDomainObjExitMonitor(driver, vm) < 0) {
 VIR_FREE(cpupids);
 return -2;
@@ -5526,16 +5528,38 @@ qemuDomainDetectVcpuPids(virQEMUDriverPtr driver,
  "got %d, wanted %d"),
ncpupids, virDomainDefGetVcpus(vm->def));
 VIR_FREE(cpupids);
+VIR_FREE(cpuhalted);
 return -1;
 }
 
  done:
 VIR_FREE(priv->vcpupids);
+VIR_FREE(priv->vcpuhalted);
 priv->nvcpupids = ncpupids;
 priv->vcpupids = cpupids;
+priv->vcpuhalted = cpuhalted;
 return ncpupids;
 }
 
+/**
+ * qemuDomainGetVcpuHalted:
+ * @vm: domain object
+ * @vcpu: cpu id
+ *
+ * Returns the vCPU halted state.
+  */
+bool
+qemuDomainGetVcpuHalted(virDomainObjPtr vm,
+unsigned int vcpu)
+{
+qemuDomainObjPrivatePtr priv = vm->privateData;
+
+if (vcpu >= priv->nvcpupids)
+return 0;
+
+return priv->vcpuhalted[vcpu];
+}
+
 
 bool
 qemuDomainSupportsNicdev(virDomainDefPtr def,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index c49f31c..8f7d421 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -186,6 +186,7 @@ struct _qemuDomainObjPrivate {
 
 int nvcpupids;
 int *vcpupids;
+bool *vcpuhalted;
 
 virDomainPCIAddressSetPtr pciaddrs;
 virDomainCCWAddressSetPtr ccwaddrs;
@@ -639,6 +640,7 @@ bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
 pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpu);
 int qemuDomainDetectVcpuPids(virQEMUDriverPtr driver, virDomainObjPtr vm,
  int asyncJob);
+bool qemuDomainGetVcpuHalted(virDomainObjPtr vm, unsigned int vcpu);
 
 

[libvirt] [libvirt-php][PATCH 05/14] examples: Fix 'if-else' formatting in libvirt.php

2016-07-08 Thread Michal Privoznik
In the file, there are couple of 'if-else' occurrences that just
hurt my eyes. For instance, multiline expression should be
wrapped in curly braces, if one side of 'else' has curly braces
the other one should have them too, and so on.

Signed-off-by: Michal Privoznik 
---
 examples/libvirt.php | 106 ---
 1 file changed, 49 insertions(+), 57 deletions(-)

diff --git a/examples/libvirt.php b/examples/libvirt.php
index 89aeb9f..9107885 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -94,8 +94,7 @@ class Libvirt {
 $img = imagecreatefrompng($imgFile);
 imagecopyresampled($new,$img,0,0,0,0, $w,$h,$width,$height);
 imagedestroy($img);
-}
-else {
+} else {
 $c = imagecolorallocate($new, 255, 255, 255);
 imagefill($new, 0, 0, $c);
 }
@@ -167,15 +166,17 @@ class Libvirt {
 if (!$seed)
 $seed = 1;
 
-if ($this->get_hypervisor_name() == 'qemu')
+if ($this->get_hypervisor_name() == 'qemu') {
 $prefix = '52:54:00';
-else
-if ($this->get_hypervisor_name() == 'xen')
+} else {
+if ($this->get_hypervisor_name() == 'xen') {
 $prefix = '00:16:3e';
-else
+} else {
 $prefix = $this->macbyte(($seed * rand()) % 256).':'.
-$this->macbyte(($seed * rand()) % 256).':'.
-$this->macbyte(($seed * rand()) % 256);
+$this->macbyte(($seed * rand()) % 256).':'.
+$this->macbyte(($seed * rand()) % 256);
+}
+}
 
 return $prefix.':'.
 $this->macbyte(($seed * rand()) % 256).':'.
@@ -247,9 +248,9 @@ class Libvirt {
 if ($tmp) {
 $tmp['bus'] = $buses[$i];
 $ret[] = $tmp;
-}
-else
+} else {
 $this->_set_last_error();
+}
 }
 
 if ($sort) {
@@ -283,9 +284,9 @@ class Libvirt {
 if ($tmp) {
 $tmp['bus'] = $buses[$i];
 $ret[] = $tmp;
-}
-else
+} else {
 $this->_set_last_error();
+}
 }
 
 if ($sort) {
@@ -393,17 +394,14 @@ class Libvirt {
 /* (1 << 40) is not working correctly on i386 systems */
 if ($value > 1099511627776)
 $unit = 'T';
+else if ($value > (1 << 30))
+$unit = 'G';
+else if ($value > (1 << 20))
+$unit = 'M';
+else if ($value > (1 << 10))
+$unit = 'K';
 else
-if ($value > (1 << 30))
-$unit = 'G';
-else
-if ($value > (1 << 20))
-$unit = 'M';
-else
-if ($value > (1 << 10))
-$unit = 'K';
-else
-$unit = 'B';
+$unit = 'B';
 }
 
 $unit = strtoupper($unit);
@@ -1012,41 +1010,35 @@ class Libvirt {
 return $type.' ('.$targetType.' on port '.$targetPort.')';
 else
 return array('type' => $type, 'targetType' => $targetType, 
'targetPort' => $targetPort);
-}
-else
-if ($type == 'input') {
-$type = $this->_get_single_xpath_result($domain, 
'//domain/devices/input/@type');
-$bus  = $this->_get_single_xpath_result($domain, 
'//domain/devices/input/@bus');
+} else if ($type == 'input') {
+$type = $this->_get_single_xpath_result($domain, 
'//domain/devices/input/@type');
+$bus  = $this->_get_single_xpath_result($domain, 
'//domain/devices/input/@bus');
 
-if ($display)
-return $type.' on '.$bus;
-else
-return array('type' => $type, 'bus' => $bus);
-}
+if ($display)
+return $type.' on '.$bus;
 else
-if ($type == 'graphics') {
-$type = $this->_get_single_xpath_result($domain, 
'//domain/devices/graphics/@type');
-$port = $this->_get_single_xpath_result($domain, 
'//domain/devices/graphics/@port');
-$autoport = $this->_get_single_xpath_result($domain, 
'//domain/devices/graphics/@autoport');
+return array('type' => $type, 'bus' => $bus);
+} else if ($type == 'graphics') {
+$type = $this->_get_single_xpath_result($domain, 
'//domain/devices/graphics/@type');
+$port = $this->_get_single_xpath_result($domain, 
'//domain/devices/graphics/@port');
+$autoport = $this->_get_single_xpath_result($domain, 

[libvirt] [libvirt-php][PATCH 11/14] examples: Show screenshot only for active domains

2016-07-08 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 examples/index.php   | 12 +++-
 examples/libvirt.php |  5 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/examples/index.php b/examples/index.php
index dbaa1bf..bdeb506 100644
--- a/examples/index.php
+++ b/examples/index.php
@@ -668,16 +668,16 @@
  "State" .
  "ID / VNC port";
 
-if (($tmp['active'] > 0) && ($lv->supports('screenshot')))
+if ($lv->supports('screenshot'))
 echo "Domain screenshot";
 
echo "Action" .
 "";
 
-$active = $tmp['active'];
 foreach ($doms as $name) {
 $dom = $lv->get_domain_object($name);
 $uuid = libvirt_domain_get_uuid_string($dom);
+$active = $lv->domain_is_active($dom);
 $info = $lv->domain_get_info($dom);
 $mem = number_format($info['memory'] / 1024, 2, '.', ' ').' MB';
 $cpu = $info['nrVirtCpu'];
@@ -716,8 +716,10 @@
  "$spaces$state$spaces" .
  "$spaces$id / $vnc$spaces";
 
-if (($active > 0) && ($lv->supports('screenshot')))
-echo "";
+if ($lv->supports('screenshot') && $active)
+echo "";
+else
+echo "$spaces";
 
 echo "$spaces";
 
@@ -735,7 +737,7 @@
 
 echo "$spaces" .
   "" .
-  "";
+  "\n";
 }
 echo "";
 
diff --git a/examples/libvirt.php b/examples/libvirt.php
index 2cab7a8..c30f06a 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -1162,5 +1162,10 @@ class Libvirt {
 $tmp = libvirt_node_get_info($this->conn);
 return ($tmp) ? $tmp : $this->_set_last_error();
 }
+
+function domain_is_active($domain) {
+$dom = $this->get_domain_object($domain);
+return libvirt_domain_is_active($dom);
+}
 }
 ?>
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 09/14] examples: Properly detect if we're connected

2016-07-08 Thread Michal Privoznik
So we have this special class Libvirt implemented in
examples/libvirt.php. It's aim is to wrap some low-level libvirt
APIs into slightly more advanced methods. Now, when instantiating
the class, connection URI can be passed in which case the class
will connect to it right in the constructor. However, later in
the code, the returned value (which is an object reference) is
compared against false, which will never ever be true.

Signed-off-by: Michal Privoznik 
---
 examples/index.php   | 4 ++--
 examples/libvirt.php | 5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/examples/index.php b/examples/index.php
index 687f408..dbaa1bf 100644
--- a/examples/index.php
+++ b/examples/index.php
@@ -1,7 +1,7 @@
 connect("qemu:///system") == false)
 die('Cannot open connection to hypervisor');
 $hn = $lv->get_hostname();
 if ($hn == false)
diff --git a/examples/libvirt.php b/examples/libvirt.php
index c60889a..14436d8 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -5,11 +5,9 @@ class Libvirt {
 private $allow_cached = true;
 private $dominfos = array();
 
-function Libvirt($uri = false, $debug=false) {
+function Libvirt($debug = false) {
 if ($debug)
 $this->set_logfile($debug);
-if ($uri != false)
-$this->connect($uri);
 }
 
 function _set_last_error() {
@@ -32,6 +30,7 @@ class Libvirt {
 $this->conn=libvirt_connect($uri, false);
 if ($this->conn==false)
 return $this->_set_last_error();
+return true;
 }
 
 function domain_disk_add($domain, $img, $dev, $type='scsi', $driver='raw') 
{
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 12/14] examples: Better translate volume perms

2016-07-08 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 examples/libvirt.php | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/examples/libvirt.php b/examples/libvirt.php
index c30f06a..96aac6e 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -502,12 +502,13 @@ class Libvirt {
 }
 
 function translate_perms($mode) {
-$mode = (string)((int)$mode);
+$mode = (int)$mode;
 
 $tmp = '-';
 
-for ($i = 0; $i < 3; $i++) {
-$bits = (int)$mode[$i];
+for ($i = 2; $i >=0 ; $i--) {
+$bits = $mode % 10;
+$mode /= 10;
 if ($bits & 4)
 $tmp[ ($i * 3) ] = 'r';
 if ($bits & 2)
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 04/14] examples: Reformat libvirt.php

2016-07-08 Thread Michal Privoznik
This file is just one class wrapping some libvirt APIs. However,
its formatting is just messy. Resolve this. Best viewed with:

  git show --ignore-space-change

Signed-off-by: Michal Privoznik 
---
 examples/libvirt.php | 2308 +-
 1 file changed, 1154 insertions(+), 1154 deletions(-)

diff --git a/examples/libvirt.php b/examples/libvirt.php
index cb1a0ad..89aeb9f 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -1,1177 +1,1177 @@
 set_logfile($debug);
-   if ($uri != false)
-   $this->connect($uri);
-   }
+function Libvirt($uri = false, $debug=false) {
+if ($debug)
+$this->set_logfile($debug);
+if ($uri != false)
+$this->connect($uri);
+}
 
-   function _set_last_error()
-   {
-   $this->last_error = libvirt_get_last_error();
-   return false;
-   }
+function _set_last_error()
+{
+$this->last_error = libvirt_get_last_error();
+return false;
+}
 
-   function set_logfile($filename)
-   {
-   if (!libvirt_logfile_set($filename))
-   return $this->_set_last_error();
+function set_logfile($filename)
+{
+if (!libvirt_logfile_set($filename))
+return $this->_set_last_error();
 
-   return true;
-   }
+return true;
+}
 
-   function print_resources() {
-   return libvirt_print_binding_resources();
-   }
+function print_resources() {
+return libvirt_print_binding_resources();
+}
 
-   function connect($uri = 'null') {
-   $this->conn=libvirt_connect($uri, false);
-   if ($this->conn==false)
-   return $this->_set_last_error();
-   }
+function connect($uri = 'null') {
+$this->conn=libvirt_connect($uri, false);
+if ($this->conn==false)
+return $this->_set_last_error();
+}
 
-function domain_disk_add($domain, $img, $dev, $type='scsi', 
$driver='raw') {
-$dom = $this->get_domain_object($domain);
+function domain_disk_add($domain, $img, $dev, $type='scsi', $driver='raw') 
{
+$dom = $this->get_domain_object($domain);
 
-$tmp = libvirt_domain_disk_add($dom, $img, $dev, 
$type, $driver);
-return ($tmp) ? $tmp : $this->_set_last_error();
+$tmp = libvirt_domain_disk_add($dom, $img, $dev, $type, $driver);
+return ($tmp) ? $tmp : $this->_set_last_error();
+}
+
+function domain_change_numVCpus($domain, $num) {
+$dom = $this->get_domain_object($domain);
+
+$tmp = libvirt_domain_change_vcpus($dom, $num);
+return ($tmp) ? $tmp : $this->_set_last_error();
+}
+
+function domain_change_memory_allocation($domain, $memory, $maxmem) {
+$dom = $this->get_domain_object($domain);
+
+$tmp = libvirt_domain_change_memory($dom, $memory, $maxmem);
+return ($tmp) ? $tmp : $this->_set_last_error();
+}
+
+function domain_change_boot_devices($domain, $first, $second) {
+$dom = $this->get_domain_object($domain);
+
+$tmp = libvirt_domain_change_boot_devices($dom, $first, $second);
+return ($tmp) ? $tmp : $this->_set_last_error();
+}
+
+function domain_get_screenshot($domain) {
+$dom = $this->get_domain_object($domain);
+
+$tmp = libvirt_domain_get_screenshot($dom, $this->get_hostname() );
+return ($tmp) ? $tmp : $this->_set_last_error();
+}
+
+function domain_get_screenshot_thumbnail($domain, $w=120) {
+$screen = $this->domain_get_screenshot($domain);
+$imgFile = tempnam("/tmp", "libvirt-php-tmp-resize-XX");;
+
+if ($screen) {
+$fp = fopen($imgFile, "wb");
+fwrite($fp, $screen);
+fclose($fp);
+}
+
+if (file_exists($imgFile) && $screen) {
+list($width, $height) = getimagesize($imgFile);
+$h = ($height / $width) * $w;
+} else {
+$w = $h = 1;
+//$h = $w * (3 / 4.5);
+}
+
+$new = imagecreatetruecolor($w, $h);
+if ($screen) {
+$img = imagecreatefrompng($imgFile);
+imagecopyresampled($new,$img,0,0,0,0, $w,$h,$width,$height);
+imagedestroy($img);
+}
+else {
+$c = imagecolorallocate($new, 255, 255, 255);
+imagefill($new, 0, 0, $c);
+}
+
+imagepng($new, $imgFile);
+imagedestroy($new);
+
+$fp = fopen($imgFile, "rb");
+$data = fread($fp, filesize($imgFile));
+fclose($fp);
+
+unlink($imgFile);
+return 

[libvirt] [libvirt-php][PATCH 01/14] gitignore: Ignore tags file

2016-07-08 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 927a4db..8c52e3f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,6 +33,7 @@ autom4te.cache/
 m4/*
 src/*.so
 stamp-h1
+tags
 tools/generate-api-docs
 libvirt-php-*.tar.gz
 *~
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 06/14] examples: Fix curly braces indent in libvirt.php

2016-07-08 Thread Michal Privoznik
The majority of the code has opening curly brace at the very same
line as the function declaration. Except for the two:
_set_last_error() and set_logfile(). Fix them.

Signed-off-by: Michal Privoznik 
---
 examples/libvirt.php | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/examples/libvirt.php b/examples/libvirt.php
index 9107885..c60889a 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -12,14 +12,12 @@ class Libvirt {
 $this->connect($uri);
 }
 
-function _set_last_error()
-{
+function _set_last_error() {
 $this->last_error = libvirt_get_last_error();
 return false;
 }
 
-function set_logfile($filename)
-{
+function set_logfile($filename) {
 if (!libvirt_logfile_set($filename))
 return $this->_set_last_error();
 
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 08/14] examples: Reformat index.php

2016-07-08 Thread Michal Privoznik
Le sigh. There's too much in this patch, I know. But hey, have
you seen the code? It was terrible. Now it's at least slightly
better readable.

Signed-off-by: Michal Privoznik 
---
 examples/index.php | 1333 ++--
 1 file changed, 657 insertions(+), 676 deletions(-)

diff --git a/examples/index.php b/examples/index.php
index b2f5b69..687f408 100644
--- a/examples/index.php
+++ b/examples/index.php
@@ -1,28 +1,28 @@
 Cannot open connection to 
hypervisor');
-   $hn = $lv->get_hostname();
-   if ($hn == false)
-   die('Cannot get hostname');
+require('libvirt.php');
+$lv = new Libvirt('qemu:///system');
+if ($lv == false)
+die('Cannot open connection to hypervisor');
+$hn = $lv->get_hostname();
+if ($hn == false)
+die('Cannot get hostname');
 
-   $action = array_key_exists('action', $_GET) ? $_GET['action'] : false;
-   $subaction = array_key_exists('subaction', $_GET) ? $_GET['subaction'] 
: false;
+$action = array_key_exists('action', $_GET) ? $_GET['action'] : false;
+$subaction = array_key_exists('subaction', $_GET) ? $_GET['subaction'] : 
false;
 
-   if (($action == 'get-screenshot') && (array_key_exists('uuid', $_GET))) 
{
-   if (array_key_exists('width', $_GET) && $_GET['width'])
-   $tmp = 
$lv->domain_get_screenshot_thumbnail($_GET['uuid'], $_GET['width']);
-   else
-   $tmp = $lv->domain_get_screenshot($_GET['uuid']);
+if (($action == 'get-screenshot') && (array_key_exists('uuid', $_GET))) {
+if (array_key_exists('width', $_GET) && $_GET['width'])
+$tmp = $lv->domain_get_screenshot_thumbnail($_GET['uuid'], 
$_GET['width']);
+else
+$tmp = $lv->domain_get_screenshot($_GET['uuid']);
 
-if (!$tmp)
-   echo $lv->get_last_error().'';
-   else {
-   Header('Content-Type: image/png');
-   die($tmp);
-   }
-   }
+if (!$tmp) {
+echo $lv->get_last_error().'';
+} else {
+Header('Content-Type: image/png');
+die($tmp);
+}
+}
 ?>
 

@@ -37,490 +37,487 @@
$uri = $lv->get_uri();
$tmp = $lv->get_domain_count();
 
-   if ($action == 'storage-pools') {
-   $msg = '';
-   if ($subaction == 'volume-delete') {
-   if ((array_key_exists('confirm', $_GET)) && 
($_GET['confirm'] == 'yes'))
-   $msg = $lv->storagevolume_delete( 
base64_decode($_GET['path']) ) ? 'Volume has been deleted successfully' : 
'Cannot delete volume';
-   else
-   $msg = '
-   
-   
-   Do you really want 
to delete volume '.base64_decode($_GET['path']).' ?
-   
-   
-   
-   
-   Yes, delete it
-   
-   
-   No, go back
-   
-   ';
-   }
-   else if ($subaction == 'volume-create') {
-   if (array_key_exists('sent', $_POST)) {
-   $msg = 
$lv->storagevolume_create($_GET['pool'], $_POST['name'], $_POST['capacity'], 
$_POST['allocation']) ?
-   'Volume has 
been created successfully' : 'Cannot create volume';
-   }
-   else
-   $msg = 'Create a new volume
-   
-   
-   Volume name: 
-   
-   
-   
-   Capacity (e.g. 10M 
or 1G): 
-   
-   
-   
-   Allocation (e.g. 
10M or 1G): 
-   
-   
-   
-   
-   
- 

[libvirt] [libvirt-php][PATCH 10/14] examples: Don't report errors when looking up a domain

2016-07-08 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 examples/libvirt.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/libvirt.php b/examples/libvirt.php
index 14436d8..2cab7a8 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -210,9 +210,9 @@ class Libvirt {
 if (is_resource($nameRes))
 return $nameRes;
 
-$dom=libvirt_domain_lookup_by_name($this->conn, $nameRes);
+$dom=@libvirt_domain_lookup_by_name($this->conn, $nameRes);
 if (!$dom) {
-$dom=libvirt_domain_lookup_by_uuid_string($this->conn, $nameRes);
+$dom=@libvirt_domain_lookup_by_uuid_string($this->conn, $nameRes);
 if (!$dom)
 return $this->_set_last_error();
 }
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 13/14] examples: Don't fetch volume count for inactive pools

2016-07-08 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 examples/libvirt.php | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/libvirt.php b/examples/libvirt.php
index 96aac6e..32d8314 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -456,12 +456,16 @@ class Libvirt {
 if (!is_string($otmp2))
 return $this->_set_last_error();
 $tmp = libvirt_storagepool_get_info($res);
-$tmp['volume_count'] = sizeof( libvirt_storagepool_list_volumes($res) 
);
 $tmp['active'] = libvirt_storagepool_is_active($res);
 $tmp['path'] = $path;
 $tmp['permissions'] = $perms;
 $tmp['id_user'] = $otmp1;
 $tmp['id_group'] = $otmp2;
+if ($tmp['active']) {
+$tmp['volume_count'] = sizeof( 
libvirt_storagepool_list_volumes($res) );
+} else {
+$tmp['volume_count'] = 0;
+}
 
 return $tmp;
 }
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 07/14] examples: Reformat header.php

2016-07-08 Thread Michal Privoznik
It's  not . Hawk.

Signed-off-by: Michal Privoznik 
---
 examples/header.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/header.php b/examples/header.php
index c944da0..14d45d9 100644
--- a/examples/header.php
+++ b/examples/header.php
@@ -4,4 +4,4 @@
 | Virtual networks
 | Node devices
 | Storage pools
-
+
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 00/14] Couple of fixes

2016-07-08 Thread Michal Privoznik
This is for examples/ reformat mostly. But there are some other fixes too.

BTW: This is pushed, so if you have any objections - patches are welcome :)

Michal Privoznik (14):
  gitignore: Ignore tags file
  configure: Provide default for php-confdir
  libvirt-php.spec.in: Honour php-{extensiondir,confdir}
  examples: Reformat libvirt.php
  examples: Fix 'if-else' formatting in libvirt.php
  examples: Fix curly braces indent in libvirt.php
  examples: Reformat header.php
  examples: Reformat index.php
  examples: Properly detect if we're connected
  examples: Don't report errors when looking up a domain
  examples: Show screenshot only for active domains
  examples: Better translate volume perms
  examples: Don't fetch volume count for inactive pools
  examples: Switch to ImageMagick for scaling pictures

 .gitignore   |1 +
 configure.ac |2 +
 examples/header.php  |2 +-
 examples/index.php   | 1335 +-
 examples/libvirt.php | 2317 +++---
 libvirt-php.spec.in  |7 +-
 m4/virt-php-confdir.m4   |4 +
 m4/virt-php-extension.m4 |   35 +
 8 files changed, 1865 insertions(+), 1838 deletions(-)
 create mode 100644 m4/virt-php-extension.m4

-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 14/14] examples: Switch to ImageMagick for scaling pictures

2016-07-08 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 configure.ac |  2 ++
 examples/index.php   |  6 ++---
 examples/libvirt.php | 68 
 libvirt-php.spec.in  |  1 +
 m4/virt-php-extension.m4 | 35 +
 5 files changed, 75 insertions(+), 37 deletions(-)
 create mode 100644 m4/virt-php-extension.m4

diff --git a/configure.ac b/configure.ac
index ed0d555..a82f7e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -164,6 +164,8 @@ AC_SUBST(PHP_LDFLAGS)
 LIBVIRT_CHECK_PHP_EXTENSIONDIR
 LIBVIRT_CHECK_PHP_CONFDIR
 
+LIBVIRT_CHECK_PHP_EXTENSION([imagick])
+
 OS=`uname`
 if test "$OS" = "Darwin"; then
 WL=-Wl,
diff --git a/examples/index.php b/examples/index.php
index bdeb506..1ba8193 100644
--- a/examples/index.php
+++ b/examples/index.php
@@ -14,13 +14,13 @@
 if (array_key_exists('width', $_GET) && $_GET['width'])
 $tmp = $lv->domain_get_screenshot_thumbnail($_GET['uuid'], 
$_GET['width']);
 else
-$tmp = $lv->domain_get_screenshot($_GET['uuid']);
+$tmp = $lv->domain_get_screenshot($_GET['uuid'], 0);
 
 if (!$tmp) {
 echo $lv->get_last_error().'';
 } else {
-Header('Content-Type: image/png');
-die($tmp);
+Header('Content-Type: ' . $tmp['mime']);
+die($tmp['data']);
 }
 }
 ?>
diff --git a/examples/libvirt.php b/examples/libvirt.php
index 32d8314..f65c50e 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -61,50 +61,50 @@ class Libvirt {
 return ($tmp) ? $tmp : $this->_set_last_error();
 }
 
-function domain_get_screenshot($domain) {
+function domain_get_screenshot($domain, $convert = 1) {
 $dom = $this->get_domain_object($domain);
 
-$tmp = libvirt_domain_get_screenshot($dom, $this->get_hostname() );
-return ($tmp) ? $tmp : $this->_set_last_error();
+$tmp = libvirt_domain_get_screenshot_api($dom);
+if ($tmp == false)
+return $this->_set_last_error();
+
+$mime = $tmp['mime'];
+
+if ($convert && $tmp['mime'] != "image/png") {
+$image = new Imagick();
+$image->readImage($tmp['file']);
+$image->setImageFormat("png");
+$data = $image->getImageBlob();
+$mime = "image/png";
+} else {
+$fp = fopen($tmp['file'], "rb");
+$data = fread($fp, filesize($tmp['file']));
+fclose($fp);
+}
+unlink($tmp['file']);
+unset($tmp['file']);
+$tmp['data'] = $data;
+$tmp['mime'] = $mime;
+
+return $tmp;
 }
 
 function domain_get_screenshot_thumbnail($domain, $w=120) {
 $screen = $this->domain_get_screenshot($domain);
-$imgFile = tempnam("/tmp", "libvirt-php-tmp-resize-XX");;
 
-if ($screen) {
-$fp = fopen($imgFile, "wb");
-fwrite($fp, $screen);
-fclose($fp);
-}
+if (!$screen)
+return false;
 
-if (file_exists($imgFile) && $screen) {
-list($width, $height) = getimagesize($imgFile);
-$h = ($height / $width) * $w;
-} else {
-$w = $h = 1;
-//$h = $w * (3 / 4.5);
-}
+$image = new Imagick();
+$image->readImageBlob($screen['data']);
+$origW = $image->getImageWidth();
+$origH = $image->getImageHeight();
+$h = ($w / $origW) * $origH;
+$image->resizeImage($w, $h, 0, 0);
 
-$new = imagecreatetruecolor($w, $h);
-if ($screen) {
-$img = imagecreatefrompng($imgFile);
-imagecopyresampled($new,$img,0,0,0,0, $w,$h,$width,$height);
-imagedestroy($img);
-} else {
-$c = imagecolorallocate($new, 255, 255, 255);
-imagefill($new, 0, 0, $c);
-}
+$screen['data'] = $image->getImageBlob();
 
-imagepng($new, $imgFile);
-imagedestroy($new);
-
-$fp = fopen($imgFile, "rb");
-$data = fread($fp, filesize($imgFile));
-fclose($fp);
-
-unlink($imgFile);
-return $data;
+return $screen;
 }
 
 function domain_get_screen_dimensions($domain) {
diff --git a/libvirt-php.spec.in b/libvirt-php.spec.in
index 2aae1d5..8cf6144 100644
--- a/libvirt-php.spec.in
+++ b/libvirt-php.spec.in
@@ -27,6 +27,7 @@ BuildRequires:php-devel
 BuildRequires: libvirt-devel >= %{req_libvirt_version}
 BuildRequires: libxml2-devel
 BuildRequires: libxslt
+BuildRequires:  php-pecl-imagick
 %if 0%{?suse_version}
 BuildRequires: xhtml-dtd
 %else
diff --git a/m4/virt-php-extension.m4 b/m4/virt-php-extension.m4
new file mode 100644
index 000..9040eb1
--- /dev/null
+++ b/m4/virt-php-extension.m4
@@ -0,0 +1,35 @@
+dnl The libvirt-php.so config
+dnl
+dnl Copyright (C) 2016 Red Hat, Inc.
+dnl
+dnl This library is free software; you can 

[libvirt] [libvirt-php][PATCH 02/14] configure: Provide default for php-confdir

2016-07-08 Thread Michal Privoznik
We use some really weird logic to get the directory where
libvirt-php.ini should go. We try to parse 'php-config
--configure' output. However, it may happen, that we learn
nothing from that. If that's the case, we should provide some
sensible default, /etc/php.d/ for instance.

Signed-off-by: Michal Privoznik 
---
 m4/virt-php-confdir.m4 | 4 
 1 file changed, 4 insertions(+)

diff --git a/m4/virt-php-confdir.m4 b/m4/virt-php-confdir.m4
index 4820de0..904d0c8 100644
--- a/m4/virt-php-confdir.m4
+++ b/m4/virt-php-confdir.m4
@@ -27,6 +27,10 @@ AC_DEFUN([LIBVIRT_CHECK_PHP_CONFDIR],[
   if test "x$with_php_confdir" != "xno" ; then
 if test "x$with_php_confdir" = "xcheck" ; then
   confdir="$($PHPCONFIG --configure-options | sed -n 
's/.*--with-config-file-scan-dir=\(\S*\).*/\1/p')"
+  if test "x$confdir" == "x" ; then
+dnl There's no usable result from phpconfig. Use some default.
+confdir="/etc/php.d/"
+  fi
 elif test "x$with_php_confdir" = "xno" || test "x$with_php_confdir" = 
"xyes"; then
   AC_MSG_ERROR([php-confdir must be used only with valid path])
 else
-- 
2.8.4

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


[libvirt] [libvirt-php][PATCH 03/14] libvirt-php.spec.in: Honour php-{extensiondir, confdir}

2016-07-08 Thread Michal Privoznik
So while we have the ability to specify where the module should
be installed, we are not doing so in the spec file. It's not very
wise.

Signed-off-by: Michal Privoznik 
---
 libvirt-php.spec.in | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libvirt-php.spec.in b/libvirt-php.spec.in
index 5a11581..2aae1d5 100644
--- a/libvirt-php.spec.in
+++ b/libvirt-php.spec.in
@@ -58,7 +58,10 @@ This package contain the document for libvirt-php.
 %setup -q -n libvirt-php-%{version}
 
 %build
-%configure --with-html-dir=%{_datadir}/doc 
--with-html-subdir=%{name}-%{version}/html --libdir=%{php_extdir}
+%configure --with-html-dir=%{_datadir}/doc \
+   --with-html-subdir=%{name}-%{version}/html \
+   --with-php-extensiondir=%{php_extdir} \
+   --with-php-confdir=%{php_confdir}
 make %{?_smp_mflags}
 
 %install
@@ -72,7 +75,6 @@ rm -rf %{buildroot}
 %files
 %defattr(-,root,root)
 %{php_extdir}/libvirt-php.so
-%{php_extdir}/libvirt-php.so.*
 %config(noreplace) %{php_confdir}/libvirt-php.ini
 
 %files -n libvirt-php-doc
-- 
2.8.4

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


[libvirt] [PATCH 3/4] virsh: Add option to suppress error in various functions

2016-07-08 Thread Nishith Shah
A bool 'report' has been introduced in various functions, which when set
to true will produce the error it is suppposed to produce, and when
false, will suppress the error. These functions are used in the next
patch for auto-completion.

Signed-off-by: Nishith Shah 
---
 tools/vsh.c | 33 -
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index c5d7578..fd93cca 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -434,7 +434,8 @@ static vshCmdOptDef helpopt = {
 };
 static const vshCmdOptDef *
 vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
-   uint64_t *opts_seen, int *opt_index, char **optstr)
+   uint64_t *opts_seen, int *opt_index, char **optstr,
+   bool report)
 {
 size_t i;
 const vshCmdOptDef *ret = NULL;
@@ -461,8 +462,9 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, 
const char *name,
 if ((value = strchr(name, '='))) {
 *value = '\0';
 if (*optstr) {
-vshError(ctl, _("invalid '=' after option --%s"),
- opt->name);
+if (report)
+vshError(ctl, _("invalid '=' after option --%s"),
+ opt->name);
 goto cleanup;
 }
 if (VIR_STRDUP(*optstr, value + 1) < 0)
@@ -471,7 +473,8 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, 
const char *name,
 continue;
 }
 if ((*opts_seen & (1ULL << i)) && opt->type != VSH_OT_ARGV) {
-vshError(ctl, _("option --%s already seen"), name);
+if (report)
+vshError(ctl, _("option --%s already seen"), name);
 goto cleanup;
 }
 *opts_seen |= 1ULL << i;
@@ -481,7 +484,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, 
const char *name,
 }
 }
 
-if (STRNEQ(cmd->name, "help")) {
+if (STRNEQ(cmd->name, "help") && report) {
 vshError(ctl, _("command '%s' doesn't support option --%s"),
  cmd->name, name);
 }
@@ -1352,7 +1355,7 @@ typedef enum {
 typedef struct _vshCommandParser vshCommandParser;
 struct _vshCommandParser {
 vshCommandToken(*getNextArg)(vshControl *, vshCommandParser *,
- char **);
+ char **, bool);
 /* vshCommandStringGetArg() */
 char *pos;
 /* vshCommandArgvGetArg() */
@@ -1387,7 +1390,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser)
 const vshCmdOptDef *opt = NULL;
 
 tkdata = NULL;
-tk = parser->getNextArg(ctl, parser, );
+tk = parser->getNextArg(ctl, parser, , true);
 
 if (tk == VSH_TK_ERROR)
 goto syntaxError;
@@ -1424,7 +1427,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser)
 /* Special case 'help' to ignore all spurious options */
 if (!(opt = vshCmddefGetOption(ctl, cmd, tkdata + 2,
_seen, _index,
-   ))) {
+   , true))) {
 VIR_FREE(optstr);
 if (STREQ(cmd->name, "help"))
 continue;
@@ -1437,7 +1440,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser)
 if (optstr)
 tkdata = optstr;
 else
-tk = parser->getNextArg(ctl, parser, );
+tk = parser->getNextArg(ctl, parser, , true);
 if (tk == VSH_TK_ERROR)
 goto syntaxError;
 if (tk != VSH_TK_ARG) {
@@ -1559,7 +1562,8 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser)
  */
 
 static vshCommandToken ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
-vshCommandArgvGetArg(vshControl *ctl, vshCommandParser *parser, char **res)
+vshCommandArgvGetArg(vshControl *ctl, vshCommandParser *parser, char **res,
+ bool report ATTRIBUTE_UNUSED)
 {
 if (parser->arg_pos == parser->arg_end) {
 *res = NULL;
@@ -1591,7 +1595,8 @@ vshCommandArgvParse(vshControl *ctl, int nargs, char 
**argv)
  */
 
 static vshCommandToken ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
-vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res)
+vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res,
+   bool report)
 {
 bool single_quote = false;
 bool double_quote = false;
@@ -1628,7 +1633,8 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandParser 
*parser, char **res)
  */
 p++;
 

[libvirt] [PATCH 1/4] virsh: Break vshCmddefOptParse into helper functions

2016-07-08 Thread Nishith Shah
Decompose vshCmddefOptParse into two helper functions, vshCmddefOptFill
and vshCmddefCheckInternals.

vshCmddefCheckInternals checks if the internal command definitions are
correct or not.

vshCmddefOptFill keeps track of the required options and mandatory
arguments through opts_required and opts_need_arg.

Signed-off-by: Nishith Shah 
---
 tools/vsh.c | 58 +++---
 1 file changed, 47 insertions(+), 11 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 2b78919..dcf99f2 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -318,16 +318,11 @@ vshCmddefGetInfo(const vshCmdDef * cmd, const char *name)
 return NULL;
 }
 
-/* Validate that the options associated with cmd can be parsed.  */
+/* Check if the internal command definitions are correct */
 static int
-vshCmddefOptParse(const vshCmdDef *cmd, uint64_t *opts_need_arg,
-  uint64_t *opts_required)
+vshCmddefCheckInternals(const vshCmdDef *cmd)
 {
 size_t i;
-bool optional = false;
-
-*opts_need_arg = 0;
-*opts_required = 0;
 
 if (!cmd->opts)
 return 0;
@@ -338,7 +333,6 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint64_t 
*opts_need_arg,
 if (i > 63)
 return -1; /* too many options */
 if (opt->type == VSH_OT_BOOL) {
-optional = true;
 if (opt->flags & VSH_OFLAG_REQ)
 return -1; /* bool options can't be mandatory */
 continue;
@@ -368,6 +362,34 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint64_t 
*opts_need_arg,
 return -1; /* alias option must map to a later option name */
 continue;
 }
+if (opt->type == VSH_OT_ARGV && cmd->opts[i + 1].name)
+return -1; /* argv option must be listed last */
+}
+return 0;
+}
+
+/* Keeps track of options that are required or need and argument */
+static int
+vshCmddefOptFill(const vshCmdDef *cmd, uint64_t *opts_need_arg,
+ uint64_t *opts_required)
+{
+size_t i;
+bool optional = false;
+
+*opts_need_arg = 0;
+*opts_required = 0;
+
+if (!cmd->opts)
+return 0;
+
+for (i = 0; cmd->opts[i].name; i++) {
+const vshCmdOptDef *opt = >opts[i];
+
+if (opt->type == VSH_OT_BOOL) {
+optional = true;
+continue;
+}
+
 if (opt->flags & VSH_OFLAG_REQ_OPT) {
 if (opt->flags & VSH_OFLAG_REQ)
 *opts_required |= 1ULL << i;
@@ -376,6 +398,9 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint64_t 
*opts_need_arg,
 continue;
 }
 
+if (opt->type == VSH_OT_ALIAS)
+continue; /* skip the alias option */
+
 *opts_need_arg |= 1ULL << i;
 if (opt->flags & VSH_OFLAG_REQ) {
 if (optional && opt->type != VSH_OT_ARGV)
@@ -384,13 +409,24 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint64_t 
*opts_need_arg,
 } else {
 optional = true;
 }
-
-if (opt->type == VSH_OT_ARGV && cmd->opts[i + 1].name)
-return -1; /* argv option must be listed last */
 }
 return 0;
 }
 
+/* Validate that the options associated with cmd can be parsed.  */
+static int
+vshCmddefOptParse(const vshCmdDef *cmd, uint64_t *opts_need_arg,
+  uint64_t *opts_required)
+{
+if (vshCmddefCheckInternals(cmd) < 0)
+return -1;
+
+if (vshCmddefOptFill(cmd, opts_need_arg, opts_required) < 0)
+return -1;
+
+return 0;
+}
+
 static vshCmdOptDef helpopt = {
 .name = "help",
 .type = VSH_OT_BOOL,
-- 
2.7.4

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


[libvirt] [PATCH 0/4] virsh: Provide better auto-completion

2016-07-08 Thread Nishith Shah
This series of patches are meant to improve existing auto-complete
functionality in virsh.

The first patch breaks vshCmddefOptParse into two smaller functions, for
use later in the third patch.

The second patch simply changes the types of variables used in existing
readline generators.

The third patch introduces quiet mode for the functions vshCmddefGetOption
and vshCommandStringGetArg.

The fourth patch introduces vshReadlineParse, which uses existing parsing
functions and borrows from vshCommandParse to quite some extent and provides
better auto-completion.

Nishith Shah (4):
  virsh: Break vshCmddefOptParse into helper functions
  virsh: Fix variable types in readline generators
  virsh: Add option to suppress error in various functions
  virsh: Introduce vshReadlineParse for improved auto-completion

 tools/vsh.c | 318 +++-
 1 file changed, 271 insertions(+), 47 deletions(-)

-- 
2.7.4

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


[libvirt] [PATCH 4/4] virsh: Introduce vshReadlineParse for improved auto-completion

2016-07-08 Thread Nishith Shah
The new function works as expected, and matches the current level of
autocomplete offered, along with several other improvements like quotes
handling, multiple command completion and space handling. Now, it is easy
to introduce options completer here.

Signed-off-by: Nishith Shah 
---
 tools/vsh.c | 221 ++--
 1 file changed, 200 insertions(+), 21 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index fd93cca..68f7785 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2582,7 +2582,7 @@ vshReadlineCommandGenerator(const char *text, int state)
 }
 
 static char *
-vshReadlineOptionsGenerator(const char *text, int state)
+vshReadlineOptionsGenerator(const char *text, int state, const vshCmdDef 
*cmd_parsed)
 {
 static unsigned int list_index;
 static size_t len;
@@ -2590,20 +2590,9 @@ vshReadlineOptionsGenerator(const char *text, int state)
 const char *name;
 
 if (!state) {
-/* determine command name */
-char *p;
-char *cmdname;
-
-if (!(p = strchr(rl_line_buffer, ' ')))
-return NULL;
-
-cmdname = vshCalloc(NULL, (p - rl_line_buffer) + 1, 1);
-memcpy(cmdname, rl_line_buffer, p - rl_line_buffer);
-
-cmd = vshCmddefSearch(cmdname);
+cmd = cmd_parsed;
 list_index = 0;
 len = strlen(text);
-VIR_FREE(cmdname);
 }
 
 if (!cmd)
@@ -2623,8 +2612,13 @@ vshReadlineOptionsGenerator(const char *text, int state)
 continue;
 
 if (len > 2) {
+/* provide auto-complete only when the text starts with -- */
+if (STRNEQLEN(text, "--", 2))
+return NULL;
 if (STRNEQLEN(name, text + 2, len - 2))
 continue;
+} else if (STRNEQLEN(text, "--", len)) {
+return NULL;
 }
 res = vshMalloc(NULL, strlen(name) + 3);
 snprintf(res, strlen(name) + 3,  "--%s", name);
@@ -2635,18 +2629,201 @@ vshReadlineOptionsGenerator(const char *text, int 
state)
 return NULL;
 }
 
+static char *
+vshReadlineParse(const char *text, int state)
+{
+static vshCommandParser parser, sanitizer;
+vshCommandToken tk;
+static const vshCmdDef *cmd;
+const vshCmdOptDef *opt;
+char *tkdata, *optstr, *const_tkdata, *res;
+static char *ctext, *sanitized_text;
+static uint64_t const_opts_need_arg, const_opts_required, const_opts_seen;
+uint64_t opts_need_arg, opts_required, opts_seen;
+unsigned int opt_index;
+static bool cmd_exists, opts_filled, opt_exists;
+static bool non_bool_opt_exists, data_acomplete;
+
+if (!state) {
+parser.pos = rl_line_buffer;
+parser.getNextArg = vshCommandStringGetArg;
+
+ctext = vshStrdup(NULL, text);
+sanitizer.pos = ctext;
+sanitizer.getNextArg = vshCommandStringGetArg;
+
+const_tkdata = NULL;
+tkdata = NULL;
+sanitized_text = NULL;
+optstr = NULL;
+res = NULL;
+
+/* Sanitize/de-quote the autocomplete text */
+tk = sanitizer.getNextArg(NULL, , _text, false);
+
+/* No autocomplete if sanitized text is a token error or token end */
+if (tk == VSH_TK_ERROR)
+goto error;
+
+tk = parser.getNextArg(NULL, , _tkdata, false);
+
+if (tk == VSH_TK_ERROR)
+goto error;
+
+/* Free-ing purposes */
+tkdata = const_tkdata;
+/* Skip leading space */
+virSkipSpaces((const char**));
+
+/* Handle ';'s */
+while (tk == VSH_TK_SUBCMD_END) {
+tk = parser.getNextArg(NULL, , _tkdata, false);
+tkdata = const_tkdata;
+}
+
+/* Skip trailing space after ;*/
+virSkipSpaces((const char**));
+
+cmd_exists = false;
+opts_filled = false;
+non_bool_opt_exists = false;
+data_acomplete = false;
+
+const_opts_need_arg = 0;
+const_opts_required = 0;
+const_opts_seen = 0;
+
+opt_index = 0;
+
+cmd = NULL;
+opt = NULL;
+
+/* Parse till text to be auto-completed is reached */
+while (STRNEQ(tkdata, sanitized_text)) {
+if (!cmd) {
+if (!(cmd = vshCmddefSearch(tkdata)))
+goto error;
+cmd_exists = true;
+
+if (vshCmddefOptFill(cmd, _opts_need_arg,
+ _opts_required) < 0)
+goto error;
+opts_filled = true;
+} else if (tkdata[0] == '-' && tkdata[1] == '-' &&
+   c_isalnum(tkdata[2])) {
+/* Command retrieved successfully, move to options */
+opts_need_arg = const_opts_need_arg;
+opts_required = const_opts_required;
+opts_seen = const_opts_seen;
+optstr = strchr(tkdata + 2, '=');
+opt_index = 0;

[libvirt] [PATCH 2/4] virsh: Fix variable types in readline generators

2016-07-08 Thread Nishith Shah
Use unsigned int for array indexes and size_t for length variables.

Signed-off-by: Nishith Shah 
---
 tools/vsh.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index dcf99f2..c5d7578 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2537,7 +2537,8 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void 
*opaque,
 static char *
 vshReadlineCommandGenerator(const char *text, int state)
 {
-static int grp_list_index, cmd_list_index, len;
+static unsigned int grp_list_index, cmd_list_index;
+static size_t len;
 const char *name;
 const vshCmdGrp *grp;
 const vshCmdDef *cmds;
@@ -2576,7 +2577,8 @@ vshReadlineCommandGenerator(const char *text, int state)
 static char *
 vshReadlineOptionsGenerator(const char *text, int state)
 {
-static int list_index, len;
+static unsigned int list_index;
+static size_t len;
 static const vshCmdDef *cmd;
 const char *name;
 
-- 
2.7.4

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


Re: [libvirt] [PATCH 0/2] qemu: Fix SPICE migration with incorrect URI

2016-07-08 Thread Jiri Denemark
On Wed, Jul 06, 2016 at 12:11:35 +0200, Pavel Hrdina wrote:
> On Tue, Jul 05, 2016 at 10:17:38AM +0200, Jiri Denemark wrote:
> > https://bugzilla.redhat.com/show_bug.cgi?id=1151723
> > 
> 
> ACK series

Pushed, thanks.

Jirka

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


[libvirt] [PATCH] qemu: hotplug: fix changeable media ejection

2016-07-08 Thread Bjoern Walk
Since return code is checked globally at the end of the function, let's
make sure that we set it correctly at any point.

This fixes a regression introduced in commit 0aa19f35 where the first
command to eject changeable media would fail unconditionally.

Signed-off-by: Bjoern Walk 
Reviewed-by: Boris Fiuczynski 
---
 src/qemu/qemu_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index c322543..789f18c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -240,7 +240,8 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 /* If the tray is present and tray change event is supported wait for it 
to open. */
 if (diskPriv->tray &&
 virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) {
-if (qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias, force) < 
0)
+rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias, force);
+if (rc < 0)
 goto error;
 } else  {
 /* otherwise report possible errors from the attempt to eject the 
media*/
-- 
2.6.6

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


Re: [libvirt] [PATCH v4 4/6] Add GVirConfigDomainHostdevPci

2016-07-08 Thread Christophe Fergeau
On Wed, Jul 06, 2016 at 10:11:18PM +0100, Zeeshan Ali (Khattak) wrote:
> On Thu, May 12, 2016 at 1:28 PM, Christophe Fergeau  
> wrote:
> > Looks I never answered this one.
> >
> > On Tue, Apr 26, 2016 at 05:04:30PM +0100, Zeeshan Ali (Khattak) wrote:
> >> >> +const gchar 
> >> >> *gvir_config_domain_hostdev_pci_get_rom_file(GVirConfigDomainHostdevPci 
> >> >> *hostdev)
> >> >> +{
> >> >> +return 
> >> >> gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(hostdev), "rom", 
> >> >> "file");
> >> >
> >> >> +}
> >> >> +
> >> >> +gboolean 
> >> >> gvir_config_domain_hostdev_pci_get_rom_bar(GVirConfigDomainHostdevPci 
> >> >> *hostdev)
> >> >> +{
> >> >> +return 
> >> >> gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(hostdev),
> >> >> +"rom", "bar", 
> >> >> FALSE);
> >> >
> >> > I'd prefer to handle on/off parsing here rather than moving it to
> >> > get_attribute_boolean().
> >>
> >> Why? Quick look through libvirt XML docs, shows that on/off is used in
> >> other places too.
> >
> > libvirt treats "on"/"off" and "yes"/"no" as different types,
> > virTristateSwitch and virTristateBool.
> 
> Giving them different names don't really make them different. on/off
> and yes/no, both have two states and are essentially booleans.

Yes, but treating them as boolean means it's complicated to do the right
thing when converting them to strings as you cannot guess whether to use
"on"/"off" or "yes"/"no"

> > This patch would treat the 2 as "boolean", and only in the parsing case
> > as it obviously cannot guess what is the right behaviour when converting
> > to string.
> > So I'd rather we don't start to treat both as booleans.
> 
> So you're suggesting that I inline the implementation and not make this 
> generic?

Either that, or introduce an enum type for "on"/"off" and use that ?

Christophe


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

Re: [libvirt] cpu_map data access for libxl driver

2016-07-08 Thread Cedric Bosdonnat
Hello Joao!

On Thu, 2016-07-07 at 16:20 +0100, Joao Martins wrote:
> FYI I too am working on guest  config work and have an RFC wrt to 
> libvirt host
> cpu detection. Perhaps we could joint work on this?

I started looking at the host cpu detection yesterday, but it seems the libxl
hw_map bits aren't too easy to understand. But sure, if we can join efforts
that would be good.

I also couldn't find your RFC in the mailing list archives. Do you have code 
available
somewhere? Joining efforts without stepping on each other's toes isn't that 
easy ;)

> As you know, there are two forms to represent this info in xen libxl cpuid: 
> 1) is the
> xend format which provides the input leaf and output registers values raw 
> CPUID data,
> and 2) the libxl format. Though while man page depicts what the feature names 
> are -
> the correspondent input, output registers, and feature names aren't really 
> exported
> by libxl headers and will have to be replicated in libvirt and adjusted to API
> changes. So probably xend format would be better suited - which can possible
> accomodate other leafs than those described by the libxl format? There is 
> also a
> special case for 'vmx' where we need to set libxl-side nestedhvm attribute to 
> true
> (on HVM guests).

Sure the xend format would be more flexible, however it's fairly easy to map the
libvirt names to the xen ones: those are mostly the same. This also helps 
checking
for the xen unsupported flags. Doing the mapping manually helped me see that 
libxl
has CPU features flags that libvirt doesn't have (maybe we'll have to add them).
And anyway, we will have to adjust the libvirt feature set if there are more 
features
supported in future libxl/xen versions as libvirt's  doesn't hold the 
register bits
but strings.

> There is one issue wrt to guest cpu features though: currently Xen and libxl 
> don't
> provide a way for libxl callers to fetch the cpuid policy that the guest will
> actually see at boot. So, when applying a cpuid policy the lower toolstack 
> layer
> (libxc) will validate may possibly disable or change some bits. Some features 
> are
> incompatible depending on guest type or feature dependencies whether it is a 
> PV or
> HVM guest or HAP enabled etc, alongside host supported levelling capabilities 
> (e.g.
> CPUID Faulting support on Intel boxes >= IvyBridge give PV guests CPUID being
> controlled like HVM guests, or otherwise warn libvirt user if not supported). 
> My
> point here is that even if we set the CPU features we would be blindly doing 
> so with
> no assurance that the domain will see those enabled. CPU topology too isn't
> specifiable under libxl or Xen. But I guess this could be solved as part 2 
> (which I
> intend to tackle on) and warn the user when it's not possible to double-check 
> cpu
> features info - which would be for all supported versions so far.

The warning thing sounds good to me since we don't have a tight control on what 
the
guest will see.

> Xen 4.7 had a great deal of improvement in this area, and future versions 
> will have
> more things coming in.
> (http://xenbits.xen.org/docs/4.7-testing/features/feature-levelling.html)

Good to see things will improve soon ;)

--
Cedric

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