[libvirt] [PATCH v7 13/14] docs: Add 'uid' and 'fid' information

2018-10-18 Thread Yi Min Zhao
Update 'Device address' section to describe 'zpci' element and
its two attributes 'uid' and 'fid'.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 docs/formatdomain.html.in | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8189959773..9ca4975d10 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3925,7 +3925,15 @@
 (since 0.9.7, requires QEMU
 0.13). multifunction defaults to 'off',
 but should be set to 'on' for function 0 of a slot that will
-have multiple functions used.
+have multiple functions used.
+(Since 4.9.0), PCI address extensions
+depending on the architecture are supported. For example, PCI
+addresses for S390 guests will have a zpci child
+element, with two attributes: uid (a hex value
+between 0x0001 and 0x, inclusive), and fid (a
+hex value between 0x and 0x, inclusive) used by
+PCI devices on S390 for User-defined Identifiers and Function
+Identifiers.
 Since 1.3.5, some hypervisor
 drivers may accept an address type='pci'/
 element with no other attributes as an explicit request to
-- 
Yi Min

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

[libvirt] [PATCH v7 14/14] news: Update news for PCI address extension attributes

2018-10-18 Thread Yi Min Zhao
Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 docs/news.xml | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index dc08c96352..6c2e0f27f1 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -35,6 +35,17 @@
 
   
 
+  
+
+  qemu: Added support for PCI device on S390
+
+
+  PCI addresses can now include the new zpci element which contains
+  uid (user-defined identifier) and fid (PCI function identifier)
+  attributes and makes the corresponding devices usable by S390
+  guests.
+
+  
 
 
 
-- 
Yi Min

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

[libvirt] [PATCH v7 08/14] conf: Introduce parser, formatter for uid and fid

2018-10-18 Thread Yi Min Zhao
This patch introduces new XML parser/formatter functions. Uid is
16-bit and non-zero. Fid is 32-bit. They are the two attributes of zpci
which is introduced as PCI address element. Zpci element is parsed and
formatted along with PCI address. And add the related test cases.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
---
 docs/schemas/basictypes.rng   | 27 ++
 docs/schemas/domaincommon.rng |  1 +
 src/conf/device_conf.c| 53 +++
 src/conf/domain_addr.c|  3 ++
 src/conf/domain_conf.c| 12 -
 src/libvirt_private.syms  |  2 +
 src/util/virpci.c | 26 +
 src/util/virpci.h |  6 +++
 .../disk-virtio-s390-zpci.args| 25 +
 .../disk-virtio-s390-zpci.xml | 19 +++
 tests/qemuxml2argvdata/hostdev-vfio-zpci.args | 23 
 tests/qemuxml2argvdata/hostdev-vfio-zpci.xml  | 21 
 tests/qemuxml2argvtest.c  |  7 +++
 .../disk-virtio-s390-zpci.xml | 31 +++
 .../qemuxml2xmloutdata/hostdev-vfio-zpci.xml  | 32 +++
 tests/qemuxml2xmltest.c   |  6 +++
 16 files changed, 293 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/disk-virtio-s390-zpci.args
 create mode 100644 tests/qemuxml2argvdata/disk-virtio-s390-zpci.xml
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci.args
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci.xml
 create mode 100644 tests/qemuxml2xmloutdata/disk-virtio-s390-zpci.xml
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-vfio-zpci.xml

diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index 14a3670e5c..71a6db3bb4 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -65,6 +65,17 @@
   
 
   
+  
+
+  
+(0x)?[0-9a-fA-F]{1,8}
+  
+  
+0
+4294967295
+  
+
+  
 
   
 
@@ -111,6 +122,22 @@
   
 
   
+  
+
+  
+
+  
+
+  
+
+
+  
+
+  
+
+  
+
+  
 
   
   
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 099a949cf8..9eeae80452 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -5220,6 +5220,7 @@
 pci
   
   
+  
 
 
   
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 98a419f40f..f9f6b6e38f 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -47,6 +47,45 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, 
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST,
   "dimm",
 );
 
+static int
+virZPCIDeviceAddressParseXML(xmlNodePtr node,
+ virPCIDeviceAddressPtr addr)
+{
+virZPCIDeviceAddress def = { 0 };
+char *uid;
+char *fid;
+int ret = -1;
+
+uid = virXMLPropString(node, "uid");
+fid = virXMLPropString(node, "fid");
+
+if (uid &&
+virStrToLong_uip(uid, NULL, 0, ) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("Cannot parse  'uid' attribute"));
+goto cleanup;
+}
+
+if (fid &&
+virStrToLong_uip(fid, NULL, 0, ) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("Cannot parse  'fid' attribute"));
+goto cleanup;
+}
+
+if (!virZPCIDeviceAddressIsEmpty() &&
+!virZPCIDeviceAddressIsValid())
+goto cleanup;
+
+addr->zpci = def;
+ret = 0;
+
+ cleanup:
+VIR_FREE(uid);
+VIR_FREE(fid);
+return ret;
+}
+
 int
 virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
 virDomainDeviceInfoPtr src)
@@ -181,6 +220,8 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
 virPCIDeviceAddressPtr addr)
 {
 char *domain, *slot, *bus, *function, *multi;
+xmlNodePtr cur;
+xmlNodePtr zpci = NULL;
 int ret = -1;
 
 memset(addr, 0, sizeof(*addr));
@@ -230,6 +271,18 @@ virPCIDeviceAddressParseXML(xmlNodePtr node,
 if (!virPCIDeviceAddressIsEmpty(addr) && !virPCIDeviceAddressIsValid(addr, 
true))
 goto cleanup;
 
+cur = node->children;
+while (cur) {
+if (cur->type == XML_ELEMENT_NODE &&
+virXMLNodeNameEqual(cur, "zpci")) {
+zpci = cur;
+}
+cur = cur->next;
+}
+
+if (zpci && virZPCIDeviceAddressParseXML(zpci, addr) < 0)
+goto cleanup;
+
 ret = 0;
 
  cleanup:
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 902837d4ee..c307d85ee1 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1040,6 +1040,9 @@ 

[libvirt] [PATCH v7 07/14] conf: use virXMLFormatElement() in virDomainDeviceInfoFormat()

2018-10-18 Thread Yi Min Zhao
In order to add zPCI child element for PCI address, we update
virDomainDeviceInfoFormat() to format device info by helper function
virXMLFormatElement(). Then we could simply format zPCI address into
child buffer later.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
---
 src/conf/domain_conf.c | 40 ++--
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e8e0adc819..88964f10c6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6400,6 +6400,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
   virDomainDeviceInfoPtr info,
   unsigned int flags)
 {
+virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
+
 if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) {
 virBufferAsprintf(buf, "bootIndex);
 
@@ -6444,13 +6446,13 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)
 return;
 
-virBufferAsprintf(buf, "type));
 
 switch ((virDomainDeviceAddressType) info->type) {
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
 if (!virPCIDeviceAddressIsEmpty(>addr.pci)) {
-virBufferAsprintf(buf, " domain='0x%.4x' bus='0x%.2x' "
+virBufferAsprintf(, " domain='0x%.4x' bus='0x%.2x' "
   "slot='0x%.2x' function='0x%.1x'",
   info->addr.pci.domain,
   info->addr.pci.bus,
@@ -6458,13 +6460,13 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
   info->addr.pci.function);
 }
 if (info->addr.pci.multi) {
-   virBufferAsprintf(buf, " multifunction='%s'",
- 
virTristateSwitchTypeToString(info->addr.pci.multi));
+virBufferAsprintf(, " multifunction='%s'",
+  
virTristateSwitchTypeToString(info->addr.pci.multi));
 }
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
-virBufferAsprintf(buf, " controller='%d' bus='%d' target='%d' 
unit='%d'",
+virBufferAsprintf(, " controller='%d' bus='%d' target='%d' 
unit='%d'",
   info->addr.drive.controller,
   info->addr.drive.bus,
   info->addr.drive.target,
@@ -6472,34 +6474,34 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
-virBufferAsprintf(buf, " controller='%d' bus='%d' port='%d'",
+virBufferAsprintf(, " controller='%d' bus='%d' port='%d'",
   info->addr.vioserial.controller,
   info->addr.vioserial.bus,
   info->addr.vioserial.port);
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
-virBufferAsprintf(buf, " controller='%d' slot='%d'",
+virBufferAsprintf(, " controller='%d' slot='%d'",
   info->addr.ccid.controller,
   info->addr.ccid.slot);
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
-virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus);
+virBufferAsprintf(, " bus='%d'", info->addr.usb.bus);
 if (virDomainUSBAddressPortIsValid(info->addr.usb.port)) {
-virBufferAddLit(buf, " port='");
-virDomainUSBAddressPortFormatBuf(buf, info->addr.usb.port);
-virBufferAddLit(buf, "'");
+virBufferAddLit(, " port='");
+virDomainUSBAddressPortFormatBuf(, info->addr.usb.port);
+virBufferAddLit(, "'");
 }
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
 if (info->addr.spaprvio.has_reg)
-virBufferAsprintf(buf, " reg='0x%llx'", info->addr.spaprvio.reg);
+virBufferAsprintf(, " reg='0x%llx'", 
info->addr.spaprvio.reg);
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
-virBufferAsprintf(buf, " cssid='0x%x' ssid='0x%x' devno='0x%04x'",
+virBufferAsprintf(, " cssid='0x%x' ssid='0x%x' devno='0x%04x'",
   info->addr.ccw.cssid,
   info->addr.ccw.ssid,
   info->addr.ccw.devno);
@@ -6510,15 +6512,15 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
 if (info->addr.isa.iobase > 0)
-virBufferAsprintf(buf, " iobase='0x%x'", info->addr.isa.iobase);
+virBufferAsprintf(, " iobase='0x%x'", 
info->addr.isa.iobase);
 if (info->addr.isa.irq > 0)
-virBufferAsprintf(buf, " irq='0x%x'", info->addr.isa.irq);
+virBufferAsprintf(, " irq='0x%x'", info->addr.isa.irq);
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
-virBufferAsprintf(buf, " slot='%u'", info->addr.dimm.slot);
+

[libvirt] [PATCH v7 03/14] conf: Introduce a new PCI address extension flag

2018-10-18 Thread Yi Min Zhao
This patch introduces PCI address extension flag for virDomainDeviceInfo
and virPCIDeviceAddress. The extension flag in virDomainDeviceInfo is
used internally during calculating PCI extension flag. The one in
virPCIDeviceAddress is the duplicate to indicate extension address is
being used. Currently only zPCI extension address is introduced to deal
with 'uid' and 'fid' on the S390 platform.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 src/conf/device_conf.h |   4 +
 src/conf/domain_addr.h |   5 ++
 src/qemu/qemu_domain_address.c | 140 -
 src/util/virpci.h  |   1 +
 4 files changed, 148 insertions(+), 2 deletions(-)

diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 407956bd02..2366e03607 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -166,6 +166,10 @@ struct _virDomainDeviceInfo {
  * assignment, never saved and never reported.
  */
 int pciConnectFlags; /* enum virDomainPCIConnectFlags */
+/* pciAddrExtFlags is only used internally to calculate PCI
+ * address extension flags during address assignment.
+ */
+int pciAddrExtFlags; /* enum virDomainPCIAddressExtensionFlags */
 char *loadparm;
 
 /* PCI devices will only be automatically placed on a PCI bus
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
index 2a9af9c00b..435b3c5d7f 100644
--- a/src/conf/domain_addr.h
+++ b/src/conf/domain_addr.h
@@ -29,6 +29,11 @@
 # define VIR_PCI_ADDRESS_SLOT_LAST 31
 # define VIR_PCI_ADDRESS_FUNCTION_LAST 7
 
+typedef enum {
+VIR_PCI_ADDRESS_EXTENSION_NONE = 0, /* no extension */
+VIR_PCI_ADDRESS_EXTENSION_ZPCI = 1 << 0, /* zPCI support */
+} virPCIDeviceAddressExtensionFlags;
+
 typedef enum {
VIR_PCI_CONNECT_HOTPLUGGABLE = 1 << 0, /* is hotplug needed/supported */
 
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 8a8764cff5..c0374ccaf3 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -509,6 +509,64 @@ qemuDomainAssignVirtioMMIOAddresses(virDomainDefPtr def,
 }
 
 
+static bool
+qemuDomainDeviceSupportZPCI(virDomainDeviceDefPtr device)
+{
+switch ((virDomainDeviceType)device->type) {
+case VIR_DOMAIN_DEVICE_CHR:
+return false;
+
+case VIR_DOMAIN_DEVICE_CONTROLLER:
+case VIR_DOMAIN_DEVICE_DISK:
+case VIR_DOMAIN_DEVICE_LEASE:
+case VIR_DOMAIN_DEVICE_FS:
+case VIR_DOMAIN_DEVICE_NET:
+case VIR_DOMAIN_DEVICE_INPUT:
+case VIR_DOMAIN_DEVICE_SOUND:
+case VIR_DOMAIN_DEVICE_VIDEO:
+case VIR_DOMAIN_DEVICE_HOSTDEV:
+case VIR_DOMAIN_DEVICE_WATCHDOG:
+case VIR_DOMAIN_DEVICE_GRAPHICS:
+case VIR_DOMAIN_DEVICE_HUB:
+case VIR_DOMAIN_DEVICE_REDIRDEV:
+case VIR_DOMAIN_DEVICE_SMARTCARD:
+case VIR_DOMAIN_DEVICE_MEMBALLOON:
+case VIR_DOMAIN_DEVICE_NVRAM:
+case VIR_DOMAIN_DEVICE_RNG:
+case VIR_DOMAIN_DEVICE_SHMEM:
+case VIR_DOMAIN_DEVICE_TPM:
+case VIR_DOMAIN_DEVICE_PANIC:
+case VIR_DOMAIN_DEVICE_MEMORY:
+case VIR_DOMAIN_DEVICE_IOMMU:
+case VIR_DOMAIN_DEVICE_VSOCK:
+break;
+
+case VIR_DOMAIN_DEVICE_NONE:
+case VIR_DOMAIN_DEVICE_LAST:
+default:
+virReportEnumRangeError(virDomainDeviceType, device->type);
+return false;
+}
+
+return true;
+}
+
+
+static virPCIDeviceAddressExtensionFlags
+qemuDomainDeviceCalculatePCIAddressExtensionFlags(virQEMUCapsPtr qemuCaps,
+  virDomainDeviceDefPtr dev)
+{
+virPCIDeviceAddressExtensionFlags extFlags = 0;
+
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI) &&
+qemuDomainDeviceSupportZPCI(dev)) {
+extFlags |= VIR_PCI_ADDRESS_EXTENSION_ZPCI;
+}
+
+return extFlags;
+}
+
+
 /**
  * qemuDomainDeviceCalculatePCIConnectFlags:
  *
@@ -990,6 +1048,56 @@ qemuDomainFillAllPCIConnectFlags(virDomainDefPtr def,
 }
 
 
+/**
+ * qemuDomainFillDevicePCIExtensionFlagsIter:
+ *
+ * @def: the entire DomainDef
+ * @dev: The device to be checked
+ * @info: virDomainDeviceInfo within the device
+ * @opaque: qemu capabilities
+ *
+ * Sets the pciAddressExtFlags for a single device's info. Has properly
+ * formatted arguments to be called by virDomainDeviceInfoIterate().
+ *
+ * Always returns 0 - there is no failure.
+ */
+static int
+qemuDomainFillDevicePCIExtensionFlagsIter(virDomainDefPtr def ATTRIBUTE_UNUSED,
+  virDomainDeviceDefPtr dev,
+  virDomainDeviceInfoPtr info,
+  void *opaque)
+{
+virQEMUCapsPtr qemuCaps = opaque;
+
+info->pciAddrExtFlags =
+qemuDomainDeviceCalculatePCIAddressExtensionFlags(qemuCaps, dev);
+
+return 0;
+}
+
+
+/**
+ * qemuDomainFillAllPCIExtensionFlags:
+ *
+ * @def: the entire DomainDef
+ * @qemuCaps: as you'd expect
+ *
+ * Set the 

[libvirt] [PATCH v7 11/14] qemu: Generate and use zPCI device in QEMU command line

2018-10-18 Thread Yi Min Zhao
Add new functions to generate zPCI command string and append it to
QEMU command line. And the related tests are added.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 src/qemu/qemu_command.c   | 104 ++
 src/qemu/qemu_command.h   |   2 +
 .../disk-virtio-s390-zpci.args|   1 +
 .../hostdev-vfio-zpci-autogenerate.args   |  25 +
 .../hostdev-vfio-zpci-autogenerate.xml|  18 +++
 .../hostdev-vfio-zpci-boundaries.args |  29 +
 .../hostdev-vfio-zpci-boundaries.xml  |  30 +
 .../hostdev-vfio-zpci-multidomain-many.args   |  39 +++
 .../hostdev-vfio-zpci-multidomain-many.xml|  79 +
 tests/qemuxml2argvdata/hostdev-vfio-zpci.args |   2 +
 tests/qemuxml2argvtest.c  |  13 +++
 .../hostdev-vfio-zpci-autogenerate.xml|  34 ++
 .../hostdev-vfio-zpci-boundaries.xml  |  48 
 .../hostdev-vfio-zpci-multidomain-many.xml|  97 
 tests/qemuxml2xmltest.c   |  11 ++
 15 files changed, 532 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.args
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.xml
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.args
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.xml
 create mode 100644 
tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.args
 create mode 100644 
tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.xml
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-vfio-zpci-autogenerate.xml
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-vfio-zpci-boundaries.xml
 create mode 100644 
tests/qemuxml2xmloutdata/hostdev-vfio-zpci-multidomain-many.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 269276f2f9..817cb6fddb 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2195,6 +2195,57 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
 return NULL;
 }
 
+char *
+qemuBuildZPCIDevStr(virDomainDeviceInfoPtr dev)
+{
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+virBufferAsprintf(,
+  "zpci,uid=%u,fid=%u,target=%s,id=zpci%u",
+  dev->addr.pci.zpci.uid,
+  dev->addr.pci.zpci.fid,
+  dev->alias,
+  dev->addr.pci.zpci.uid);
+
+if (virBufferCheckError() < 0) {
+virBufferFreeAndReset();
+return NULL;
+}
+
+return virBufferContentAndReset();
+}
+
+static int
+qemuCommandAddZPCIDevice(virCommandPtr cmd,
+ virDomainDeviceInfoPtr dev)
+{
+char *devstr = NULL;
+
+virCommandAddArg(cmd, "-device");
+
+if (!(devstr = qemuBuildZPCIDevStr(dev)))
+return -1;
+
+virCommandAddArg(cmd, devstr);
+
+VIR_FREE(devstr);
+return 0;
+}
+
+static int
+qemuCommandAddExtDevice(virCommandPtr cmd,
+virDomainDeviceInfoPtr dev)
+{
+if (dev->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI ||
+dev->addr.pci.extFlags == VIR_PCI_ADDRESS_EXTENSION_NONE) {
+return 0;
+}
+
+if (dev->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI)
+return qemuCommandAddZPCIDevice(cmd, dev);
+
+return 0;
+}
 
 static int
 qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
@@ -2431,6 +2482,9 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
 if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
 if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC ||
 virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (qemuCommandAddExtDevice(cmd, >info) < 0)
+return -1;
+
 virCommandAddArg(cmd, "-device");
 
 if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex,
@@ -2629,6 +2683,9 @@ qemuBuildFSDevCommandLine(virCommandPtr cmd,
 virCommandAddArg(cmd, optstr);
 VIR_FREE(optstr);
 
+if (qemuCommandAddExtDevice(cmd, >info) < 0)
+return -1;
+
 virCommandAddArg(cmd, "-device");
 if (!(optstr = qemuBuildFSDevStr(def, fs, qemuCaps)))
 return -1;
@@ -3089,6 +3146,11 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
 goto cleanup;
 
 if (devstr) {
+if (qemuCommandAddExtDevice(cmd, >info) < 0) {
+VIR_FREE(devstr);
+goto cleanup;
+}
+
 virCommandAddArg(cmd, "-device");
 virCommandAddArg(cmd, devstr);
 VIR_FREE(devstr);
@@ -3887,6 +3949,9 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd,
 if (!def->watchdog)
 return 0;
 
+if (qemuCommandAddExtDevice(cmd, >watchdog->info) < 0)
+return -1;
+
 virCommandAddArg(cmd, 

Re: [libvirt] [PATCH v6 09/13] conf: Allocate/release 'uid' and 'fid' in PCI address

2018-10-18 Thread Yi Min Zhao



在 2018/10/18 下午11:44, Andrea Bolognani 写道:

On Thu, 2018-10-18 at 15:13 +0800, Yi Min Zhao wrote:

在 2018/10/17 下午10:30, Andrea Bolognani 写道:

On Tue, 2018-10-16 at 11:28 +0800, Yi Min Zhao wrote:

I think this would make things complex. If either PCI address or
zPCI address exists, we have to do more checks for calling
virDomainPCIAddressReserveAddr(). And there are amounts of
code calling ***IsWanted() to call ***ReserveNext***(). I think
keeping them separately is better.

Again, I might be missing something because I haven't actually tried
implementing any of this, but at least from the theoretical point of
view I don't see how keeping them separate would make things simpler:
if anything, it seems to me like it would make them more complicated
for the calling code because now you have to worry about the PCI
address extensions *in addition* to the PCI address itself.

For example, during collection stage, checking both PCI address and
extension address
is requried, and still need to separately do some additional checks for
PCI address if it
is present, at last in reserving addr function we still check if PCI
normal address or
extension address exists to separately reserve present one. So that we
have to do the
check on the same condition repetively. If you don't have strong
opposition, I want to
send the new version ASAP.

So I gave an half-hearted stab at implementing my own suggestion
today, and quite unsurprisingly I have gained more sympathy for your
argument in the process :)

The main problem I see is that, as you noticed, we have a lot of
calls to IsWanted(), IsPresent(), ReserveAddr() and ReserveNextAddr()
where really we should be using EnsureAddr() pretty much all of the
time and hide most of the details from the drivers, which in turn
would make it easier to change them in a transparent manner.

Another big problem, which I highlighted in the past, is that the
current API was not designed with the idea that PCI addresses could
have "parts" in mind, and so it's not nuanced enough: if I call
IsEmpty() on and address where the PCI part itself has been filled
in but the zPCI part hasn't, or vice versa, what should I get back?
The answer is probably that, after we've made sure those functions
are used as little as possible thanks to the changes outlined above,
we should replace them with better named alternatives.

Of course it would be entirely unfair to ask you to perform such
a massive refactoring before your series can be considered for
inclusion, so at this point I'm okay with merging it and cleaning
up the pre-existing mess afterwards.

There's still the question of whether Dan is now okay with the XML
structure as currently implemented; assuming that's the case, it
would be great if Laine could also take a quick look at the series
before it's pushed.


Do you mean expect Laine to take a quick look at this series, or the 
next one?


--
Yi Min

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

[libvirt] [PATCH v7 06/14] conf: Introduce address caching for PCI extensions

2018-10-18 Thread Yi Min Zhao
This patch provides a caching mechanism for the device address
extensions uid and fid on S390. For efficient sparse address allocation,
we introduce two hash tables for uid/fid which hold the address set
information per domain. Also in order to improve performance of
searching available value, we introduce our own callbacks for the two
hashtables. In this way, uid/fid is saved in hash key and hash value
could be any non-NULL pointer due to no operation on hash value. That is
also the reason why we don't introduce hash value free callback.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 src/bhyve/bhyve_device.c   |  3 +-
 src/conf/domain_addr.c | 93 +-
 src/conf/domain_addr.h | 10 +++-
 src/qemu/qemu_domain_address.c |  6 ++-
 4 files changed, 108 insertions(+), 4 deletions(-)

diff --git a/src/bhyve/bhyve_device.c b/src/bhyve/bhyve_device.c
index 207ac6a2dd..a59dfe4519 100644
--- a/src/bhyve/bhyve_device.c
+++ b/src/bhyve/bhyve_device.c
@@ -71,7 +71,8 @@ bhyveDomainPCIAddressSetCreate(virDomainDefPtr def, unsigned 
int nbuses)
 {
 virDomainPCIAddressSetPtr addrs;
 
-if ((addrs = virDomainPCIAddressSetAlloc(nbuses)) == NULL)
+if ((addrs = virDomainPCIAddressSetAlloc(nbuses,
+ VIR_PCI_ADDRESS_EXTENSION_NONE)) 
== NULL)
 return NULL;
 
 if (virDomainPCIAddressBusSetModel(>buses[0],
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 442e6aab94..902837d4ee 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -27,6 +27,7 @@
 #include "virlog.h"
 #include "virstring.h"
 #include "domain_addr.h"
+#include "virhashcode.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -727,8 +728,93 @@ virDomainPCIAddressReleaseAddr(virDomainPCIAddressSetPtr 
addrs,
 addrs->buses[addr->bus].slot[addr->slot].functions &= ~(1 << 
addr->function);
 }
 
+
+static uint32_t
+virZPCIAddrKeyCode(const void *name,
+   uint32_t seed)
+{
+unsigned int value = *((unsigned int *)name);
+return virHashCodeGen(, sizeof(value), seed);
+}
+
+
+static bool
+virZPCIAddrKeyEqual(const void *namea,
+const void *nameb)
+{
+return *((unsigned int *)namea) == *((unsigned int *)nameb);
+}
+
+
+static void *
+virZPCIAddrKeyCopy(const void *name)
+{
+unsigned int *copy;
+
+if (VIR_ALLOC(copy) < 0)
+return NULL;
+
+*copy = *((unsigned int *)name);
+return (void *)copy;
+}
+
+
+static void
+virZPCIAddrKeyFree(void *name)
+{
+VIR_FREE(name);
+}
+
+
+static void
+virDomainPCIAddressSetExtensionFree(virDomainPCIAddressSetPtr addrs)
+{
+if (!addrs || !addrs->zpciIds)
+return;
+
+virHashFree(addrs->zpciIds->uids);
+virHashFree(addrs->zpciIds->fids);
+VIR_FREE(addrs->zpciIds);
+}
+
+
+static int
+virDomainPCIAddressSetExtensionAlloc(virDomainPCIAddressSetPtr addrs,
+ virPCIDeviceAddressExtensionFlags 
extFlags)
+{
+if (extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) {
+if (addrs->zpciIds)
+return 0;
+
+if (VIR_ALLOC(addrs->zpciIds) < 0)
+return -1;
+
+if (!(addrs->zpciIds->uids = virHashCreateFull(10, NULL,
+   virZPCIAddrKeyCode,
+   virZPCIAddrKeyEqual,
+   virZPCIAddrKeyCopy,
+   virZPCIAddrKeyFree)))
+goto error;
+
+if (!(addrs->zpciIds->fids = virHashCreateFull(10, NULL,
+   virZPCIAddrKeyCode,
+   virZPCIAddrKeyEqual,
+   virZPCIAddrKeyCopy,
+   virZPCIAddrKeyFree)))
+goto error;
+}
+
+return 0;
+
+ error:
+virDomainPCIAddressSetExtensionFree(addrs);
+return -1;
+}
+
+
 virDomainPCIAddressSetPtr
-virDomainPCIAddressSetAlloc(unsigned int nbuses)
+virDomainPCIAddressSetAlloc(unsigned int nbuses,
+virPCIDeviceAddressExtensionFlags extFlags)
 {
 virDomainPCIAddressSetPtr addrs;
 
@@ -739,6 +825,10 @@ virDomainPCIAddressSetAlloc(unsigned int nbuses)
 goto error;
 
 addrs->nbuses = nbuses;
+
+if (virDomainPCIAddressSetExtensionAlloc(addrs, extFlags) < 0)
+goto error;
+
 return addrs;
 
  error:
@@ -753,6 +843,7 @@ virDomainPCIAddressSetFree(virDomainPCIAddressSetPtr addrs)
 if (!addrs)
 return;
 
+virDomainPCIAddressSetExtensionFree(addrs);
 VIR_FREE(addrs->buses);
 VIR_FREE(addrs);
 }
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
index 435b3c5d7f..8d64d6b795 100644
--- 

[libvirt] [PATCH v7 05/14] qemu: Auto add pci-root for s390/s390x guests

2018-10-18 Thread Yi Min Zhao
The pci-root depends on zpci capability. So autogenerate pci-root if
zpci exists.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 src/qemu/qemu_domain.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f00f1b3fdb..961755ef84 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3287,6 +3287,7 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def,
 case VIR_ARCH_S390X:
 addDefaultUSB = false;
 addPanicDevice = true;
+addPCIRoot = virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI);
 break;
 
 case VIR_ARCH_SPARC:
-- 
Yi Min

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

[libvirt] [PATCH v7 04/14] qemu: Enable PCI multi bus for S390 guests

2018-10-18 Thread Yi Min Zhao
QEMU on s390 supports PCI multibus since forever.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 src/qemu/qemu_capabilities.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ee6a7462f6..bf1b90875b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1700,6 +1700,10 @@ bool virQEMUCapsHasPCIMultiBus(virQEMUCapsPtr qemuCaps,
 return false;
 }
 
+/* S390 supports PCI-multibus. */
+if (ARCH_IS_S390(def->os.arch))
+return true;
+
 /* If ARM 'virt' supports PCI, it supports multibus.
  * No extra conditions here for simplicity.
  */
-- 
Yi Min

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

[libvirt] [PATCH v7 12/14] qemu: Add hotpluging support for PCI devices on S390 guests

2018-10-18 Thread Yi Min Zhao
This commit adds hotplug support for PCI devices on S390 guests.
There's no need to implement hot unplug for zPCI as QEMU implements
an unplug callback which will unplug both PCI and zPCI device in a
cascaded way.
Currently, the following PCI devices are supported:
  virtio-blk-pci
  virtio-net-pci
  virtio-rng-pci
  virtio-input-host-pci
  virtio-keyboard-pci
  virtio-mouse-pci
  virtio-tablet-pci
  vfio-pci
  SCSIVhost device

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 src/qemu/qemu_hotplug.c | 160 +---
 1 file changed, 151 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0a63741b9e..5f756b7267 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -154,6 +154,80 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver,
 }
 
 
+static int
+qemuDomainAttachZPCIDevice(qemuMonitorPtr mon,
+   virDomainDeviceInfoPtr info)
+{
+char *devstr_zpci = NULL;
+int ret = -1;
+
+if (!(devstr_zpci = qemuBuildZPCIDevStr(info)))
+goto cleanup;
+
+if (qemuMonitorAddDevice(mon, devstr_zpci) < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+VIR_FREE(devstr_zpci);
+return ret;
+}
+
+
+static int
+qemuDomainDetachZPCIDevice(qemuMonitorPtr mon,
+   virDomainDeviceInfoPtr info)
+{
+char *zpciAlias = NULL;
+int ret = -1;
+
+if (virAsprintf(, "zpci%d", info->addr.pci.zpci.uid) < 0)
+goto cleanup;
+
+if (qemuMonitorDelDevice(mon, zpciAlias) < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+VIR_FREE(zpciAlias);
+return ret;
+}
+
+
+static int
+qemuDomainAttachExtensionDevice(qemuMonitorPtr mon,
+virDomainDeviceInfoPtr info)
+{
+if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI ||
+info->addr.pci.extFlags == VIR_PCI_ADDRESS_EXTENSION_NONE) {
+return 0;
+}
+
+if (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI)
+return qemuDomainAttachZPCIDevice(mon, info);
+
+return 0;
+}
+
+
+static int
+qemuDomainDetachExtensionDevice(qemuMonitorPtr mon,
+virDomainDeviceInfoPtr info)
+{
+if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI ||
+info->addr.pci.extFlags == VIR_PCI_ADDRESS_EXTENSION_NONE) {
+return 0;
+}
+
+if (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI)
+return qemuDomainDetachZPCIDevice(mon, info);
+
+return 0;
+}
+
+
 static int
 qemuHotplugWaitForTrayEject(virDomainObjPtr vm,
 virDomainDiskDefPtr disk)
@@ -845,8 +919,13 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
 if (qemuHotplugDiskSourceAttach(priv->mon, diskdata) < 0)
 goto exit_monitor;
 
-if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+if (qemuDomainAttachExtensionDevice(priv->mon, >info) < 0)
+goto exit_monitor;
+
+if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
+ignore_value(qemuDomainDetachExtensionDevice(priv->mon, >info));
 goto exit_monitor;
+}
 
 if (qemuDomainObjExitMonitor(driver, vm) < 0) {
 ret = -2;
@@ -954,7 +1033,16 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr 
driver,
 goto cleanup;
 
 qemuDomainObjEnterMonitor(driver, vm);
-ret = qemuMonitorAddDevice(priv->mon, devstr);
+
+if ((ret = qemuDomainAttachExtensionDevice(priv->mon,
+   >info)) < 0) {
+goto exit_monitor;
+}
+
+if ((ret = qemuMonitorAddDevice(priv->mon, devstr)) < 0)
+ignore_value(qemuDomainDetachExtensionDevice(priv->mon, 
>info));
+
+ exit_monitor:
 if (qemuDomainObjExitMonitor(driver, vm) < 0) {
 releaseaddr = false;
 ret = -1;
@@ -1417,6 +1505,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
 }
 
 if (qemuDomainIsS390CCW(vm->def) &&
+net->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
 virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CCW)) {
 net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW;
 if (!(ccwaddrs = virDomainCCWAddressSetCreateFromDomain(vm->def)))
@@ -1486,7 +1575,15 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
 goto try_remove;
 
 qemuDomainObjEnterMonitor(driver, vm);
+
+if (qemuDomainAttachExtensionDevice(priv->mon, >info) < 0) {
+ignore_value(qemuDomainObjExitMonitor(driver, vm));
+virDomainAuditNet(vm, NULL, net, "attach", false);
+goto try_remove;
+}
+
 if (qemuMonitorAddDevice(priv->mon, nicstr) < 0) {
+ignore_value(qemuDomainDetachExtensionDevice(priv->mon, >info));
 ignore_value(qemuDomainObjExitMonitor(driver, vm));
 virDomainAuditNet(vm, NULL, net, "attach", false);
 goto try_remove;
@@ -1703,8 

[libvirt] [PATCH v7 09/14] qemu: Add zPCI address definition check

2018-10-18 Thread Yi Min Zhao
We should ensure that QEMU supports zPCI when a zPCI address is defined
in XML and otherwise report an error. This patch introduces a generic
validation function qemuDomainDeviceDefValidateAddress() which calls
qemuDomainDeviceDefValidateZPCIAddress() if address type is PCI address.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Andrea Bolognani 
---
 src/qemu/qemu_domain.c| 36 +++
 .../hostdev-vfio-zpci-wrong-arch.xml  | 34 ++
 tests/qemuxml2argvtest.c  |  2 ++
 3 files changed, 72 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 961755ef84..8bdc3f58e8 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5797,6 +5797,38 @@ qemuDomainDeviceDefValidateInput(const virDomainInputDef 
*input,
 }
 
 
+static int
+qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info,
+   virQEMUCapsPtr qemuCaps)
+{
+if (!virZPCIDeviceAddressIsEmpty(>addr.pci.zpci) &&
+!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   "%s",
+   _("This QEMU binary doesn't support zPCI"));
+return -1;
+}
+
+return 0;
+}
+
+
+static int
+qemuDomainDeviceDefValidateAddress(const virDomainDeviceDef *dev,
+   virQEMUCapsPtr qemuCaps)
+{
+virDomainDeviceInfoPtr info;
+
+if (!(info = virDomainDeviceGetInfo((virDomainDeviceDef *)dev)))
+return 0;
+
+if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)
+return qemuDomainDeviceDefValidateZPCIAddress(info, qemuCaps);
+
+return 0;
+}
+
+
 static int
 qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
 const virDomainDef *def,
@@ -5810,6 +5842,9 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
 def->emulator)))
 return -1;
 
+if ((ret = qemuDomainDeviceDefValidateAddress(dev, qemuCaps)) < 0)
+goto cleanup;
+
 switch ((virDomainDeviceType)dev->type) {
 case VIR_DOMAIN_DEVICE_NET:
 ret = qemuDomainDeviceDefValidateNetwork(dev->data.net);
@@ -5885,6 +5920,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
 break;
 }
 
+ cleanup:
 virObjectUnref(qemuCaps);
 return ret;
 }
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml 
b/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml
new file mode 100644
index 00..bfb2f83a3b
--- /dev/null
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml
@@ -0,0 +1,34 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9466-926a-d65c16db1809
+  219100
+  219100
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-i686
+
+  
+  
+  
+
+
+
+  
+  
+
+  
+  
+
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 7b9e6bf2be..09c52f5f38 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1683,6 +1683,8 @@ mymain(void)
 DO_TEST_PARSE_ERROR("hostdev-mdev-display-missing-graphics",
 QEMU_CAPS_DEVICE_VFIO_PCI,
 QEMU_CAPS_VFIO_PCI_DISPLAY);
+DO_TEST_PARSE_ERROR("hostdev-vfio-zpci-wrong-arch",
+QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST("hostdev-vfio-zpci",
 QEMU_CAPS_DEVICE_VFIO_PCI,
 QEMU_CAPS_DEVICE_ZPCI);
-- 
Yi Min

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


[libvirt] [PATCH v7 00/14] PCI passthrough support on s390

2018-10-18 Thread Yi Min Zhao
Abstract

The PCI representation in QEMU has been extended for S390
allowing configuration of zPCI attributes like uid (user-defined
identifier) and fid (PCI function identifier).
The details can be found here:
https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg07262.html

To support the new zPCI feature of the S390 platform, a new element of
PCI address is introduced. It has two optional attributes, @uid and
@fid. For example:
  


  


  

  

If they are defined by the user, unique values within the guest domain
must be used. If they are not specified and the architecture requires
them, they are automatically generated with non-conflicting values.

zPCI address as an extension of the PCI address are stored in a new
structure 'virZPCIDeviceAddress' which is a member of common PCI
Address structure. Additionally, two hashtables are used for assignment
and reservation of zPCI uid/fid.

In support of extending the PCI address, a new PCI address extension flag is
introduced. This extension flag allows is not only dedicated for the S390
platform but also other architectures needing certain extensions to PCI
address space.

Code Base
=
commit in master:
3a1cdb06fd conf: Fix bug in finding alloc through matching vcpus

Change Log
==
v6->v7:
1. Optimize some functions' names and code logic.
2. Fixup build error.
3. Add negative test case for patch 9.
4. Use virXMLFormatElement() in virDomainDeviceInfoFormat().

v5->v6:
1. Modify zPCI XML definition.
2. Optimize the logic of zPCI address assignment and reservation.
3. Add extension flag into PCI address structure.
4. Update commit messages.

v4->v5:
1. Update the version number.
2. Fixup code style error.
3. Separate qemu code into single patch.
4. Rebase the patches to the new code of master branch.

v3->v4:
1. Update docs.
2. Format code style.
3. Optimize zPCI support check.
4. Move the check of zPCI defined in xml but unsupported by Qemu to
   qemuDomainDeviceDefValidate().
5. Change zpci address member of PCI address struct from pointer to
   instance.
6. Modify zpci address definition principle. Currently the user must
   either define both of uid and fid or not.

v2->v3:
1. Revise code style.
2. Update test cases.
3. Introduce qemuDomainCollectPCIAddressExtension() to collect PCI
   extension addresses.
4. Introduce virDeviceInfoPCIAddressExtensionPresent() to check if zPCI
   address exists.
5. Optimize zPCI address check logic.
6. Optimize passed parameters of zPCI addr alloc/release/reserve functions.
7. Report enum range error in qemuDomainDeviceSupportZPCI().
8. Update commit messages.

v1->v2:
1. Separate test commit and merge testcases into corresponding commits that
   introduce the functionalities firstly.
2. Spare some checks for zpci device.
3. Add vsock and controller support.
4. Add uin32 type schema.
5. Rename zpciuid and zpcifid to zpci_uid and zpci_fid.
6. Always return multibus support on S390.

Yi Min Zhao (14):
  conf: Add definitions for 'uid' and 'fid' PCI address attributes
  qemu: Introduce zPCI capability
  conf: Introduce a new PCI address extension flag
  qemu: Enable PCI multi bus for S390 guests
  qemu: Auto add pci-root for s390/s390x guests
  conf: Introduce address caching for PCI extensions
  conf: use virXMLFormatElement() in virDomainDeviceInfoFormat()
  conf: Introduce parser, formatter for uid and fid
  qemu: Add zPCI address definition check
  conf: Allocate/release 'uid' and 'fid' in PCI address
  qemu: Generate and use zPCI device in QEMU command line
  qemu: Add hotpluging support for PCI devices on S390 guests
  docs: Add 'uid' and 'fid' information
  news: Update news for PCI address extension attributes

 cfg.mk|   1 +
 docs/formatdomain.html.in |  10 +-
 docs/news.xml |  11 +
 docs/schemas/basictypes.rng   |  27 ++
 docs/schemas/domaincommon.rng |   1 +
 src/bhyve/bhyve_device.c  |   3 +-
 src/conf/device_conf.c|  69 
 src/conf/device_conf.h|   7 +
 src/conf/domain_addr.c| 340 +-
 src/conf/domain_addr.h|  27 +-
 src/conf/domain_conf.c|  50 ++-
 src/libvirt_private.syms  |   7 +
 src/qemu/qemu_capabilities.c  |   6 +
 src/qemu/qemu_capabilities.h  |   1 +
 src/qemu/qemu_command.c   | 104 ++
 src/qemu/qemu_command.h   |   2 +
 src/qemu/qemu_domain.c|  37 ++
 src/qemu/qemu_domain_address.c| 205 ++-
 src/qemu/qemu_hotplug.c   | 160 -
 src/util/virpci.c |  26 ++
 src/util/virpci.h |  15 +
 .../caps_2.10.0.s390x.xml |   1 +
 

[libvirt] [PATCH v7 10/14] conf: Allocate/release 'uid' and 'fid' in PCI address

2018-10-18 Thread Yi Min Zhao
This patch adds new functions for reservation, assignment and release
to handle the uid/fid. If the uid/fid is defined in the domain XML,
they will be reserved directly in the collecting phase. If any of them
is not defined, we will find out an available value for them from the
zPCI address hashtable, and reserve them. For the hotplug case there
might not be a zPCI definition. So allocate and reserve uid/fid the
case. Assign if needed and reserve uid/fid for the defined case.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Bjoern Walk 
Reviewed-by: Boris Fiuczynski 
---
 src/conf/device_conf.c |  16 +++
 src/conf/device_conf.h |   3 +
 src/conf/domain_addr.c | 244 +
 src/conf/domain_addr.h |  12 ++
 src/libvirt_private.syms   |   5 +
 src/qemu/qemu_domain_address.c |  59 +++-
 6 files changed, 338 insertions(+), 1 deletion(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index f9f6b6e38f..44b210d5ec 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -28,6 +28,7 @@
 #include "viruuid.h"
 #include "virbuffer.h"
 #include "device_conf.h"
+#include "domain_addr.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_DEVICE
@@ -215,6 +216,21 @@ virDeviceInfoPCIAddressIsPresent(const virDomainDeviceInfo 
*info)
 }
 
 
+bool
+virDeviceInfoPCIAddressExtensionIsWanted(const virDomainDeviceInfo *info)
+{
+return (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) &&
+   virZPCIDeviceAddressIsEmpty(>addr.pci.zpci);
+}
+
+bool
+virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo *info)
+{
+return (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI) &&
+   !virZPCIDeviceAddressIsEmpty(>addr.pci.zpci);
+}
+
+
 int
 virPCIDeviceAddressParseXML(xmlNodePtr node,
 virPCIDeviceAddressPtr addr)
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 2366e03607..867b633903 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -198,6 +198,9 @@ bool virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr 
info,
 bool virDeviceInfoPCIAddressIsWanted(const virDomainDeviceInfo *info);
 bool virDeviceInfoPCIAddressIsPresent(const virDomainDeviceInfo *info);
 
+bool virDeviceInfoPCIAddressExtensionIsWanted(const virDomainDeviceInfo *info);
+bool virDeviceInfoPCIAddressExtensionIsPresent(const virDomainDeviceInfo 
*info);
+
 int virPCIDeviceAddressParseXML(xmlNodePtr node,
 virPCIDeviceAddressPtr addr);
 
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index c307d85ee1..d174558282 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -33,6 +33,238 @@
 
 VIR_LOG_INIT("conf.domain_addr");
 
+static int
+virDomainZPCIAddressReserveId(virHashTablePtr set,
+  unsigned int id,
+  const char *name)
+{
+if (virHashLookup(set, )) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("zPCI %s %o is already reserved"),
+   name, id);
+return -1;
+}
+
+if (virHashAddEntry(set, , (void*)1) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Failed to reserve %s %o"),
+   name, id);
+return -1;
+}
+
+return 0;
+}
+
+
+static int
+virDomainZPCIAddressReserveUid(virHashTablePtr set,
+   virZPCIDeviceAddressPtr addr)
+{
+return virDomainZPCIAddressReserveId(set, addr->uid, "uid");
+}
+
+
+static int
+virDomainZPCIAddressReserveFid(virHashTablePtr set,
+   virZPCIDeviceAddressPtr addr)
+{
+return virDomainZPCIAddressReserveId(set, addr->fid, "fid");
+}
+
+
+static int
+virDomainZPCIAddressAssignId(virHashTablePtr set,
+ unsigned int *id,
+ unsigned int min,
+ unsigned int max,
+ const char *name)
+{
+while (virHashLookup(set, )) {
+if (min == max) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("There is no more free %s."),
+   name);
+return -1;
+}
+++min;
+}
+*id = min;
+
+return 0;
+}
+
+
+static int
+virDomainZPCIAddressAssignUid(virHashTablePtr set,
+  virZPCIDeviceAddressPtr addr)
+{
+return virDomainZPCIAddressAssignId(set, >uid, 1,
+VIR_DOMAIN_DEVICE_ZPCI_MAX_UID, "uid");
+}
+
+
+static int
+virDomainZPCIAddressAssignFid(virHashTablePtr set,
+  virZPCIDeviceAddressPtr addr)
+{
+return virDomainZPCIAddressAssignId(set, >fid, 0,
+VIR_DOMAIN_DEVICE_ZPCI_MAX_FID, "fid");
+}
+
+
+static void
+virDomainZPCIAddressReleaseId(virHashTablePtr set,
+  unsigned 

[libvirt] [PATCH v7 02/14] qemu: Introduce zPCI capability

2018-10-18 Thread Yi Min Zhao
Let's introduce zPCI capability.

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 src/qemu/qemu_capabilities.c | 2 ++
 src/qemu/qemu_capabilities.h | 1 +
 tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml  | 1 +
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml  | 1 +
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml  | 1 +
 9 files changed, 10 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e228f52ec0..ee6a7462f6 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -508,6 +508,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   /* 315 */
   "vfio-pci.display",
   "blockdev",
+  "zpci",
 );
 
 
@@ -1092,6 +1093,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
 { "vhost-vsock-device", QEMU_CAPS_DEVICE_VHOST_VSOCK },
 { "mch", QEMU_CAPS_DEVICE_MCH },
 { "sev-guest", QEMU_CAPS_SEV_GUEST },
+{ "zpci", QEMU_CAPS_DEVICE_ZPCI },
 };
 
 static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioBalloon[] = {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 934620ed31..cd417c9062 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -492,6 +492,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */
 /* 315 */
 QEMU_CAPS_VFIO_PCI_DISPLAY, /* -device vfio-pci.display */
 QEMU_CAPS_BLOCKDEV, /* -blockdev and blockdev-add are supported */
+QEMU_CAPS_DEVICE_ZPCI, /* -device zpci */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
index e000aac384..3c311042f3 100644
--- a/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml
@@ -113,6 +113,7 @@
   
   
   
+  
   201
   0
   306247
diff --git a/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml
index 4eb8a39d94..48db1dbf2d 100644
--- a/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml
@@ -120,6 +120,7 @@
   
   
   
+  
   2011000
   0
   345099
diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml
index 79320d5229..4c561f6214 100644
--- a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml
@@ -128,6 +128,7 @@
   
   
   
+  
   2012000
   0
   374287
diff --git a/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml
index b30c31cafc..de87692857 100644
--- a/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml
@@ -100,6 +100,7 @@
   
   
   
+  
   2007000
   0
   219140
diff --git a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
index b010f731a5..f3a32ad376 100644
--- a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
@@ -103,6 +103,7 @@
   
   
   
+  
   2007093
   0
   244554
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml
index 5a4371ab83..f1e05ab1c4 100644
--- a/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml
@@ -107,6 +107,7 @@
   
   
   
+  
   2009000
   0
   267973
diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml
index 3b5f9818a5..c841030b2b 100644
--- a/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml
@@ -130,6 +130,7 @@
   
   
   
+  
   300
   0
   387601
-- 
Yi Min

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

[libvirt] [PATCH v7 01/14] conf: Add definitions for 'uid' and 'fid' PCI address attributes

2018-10-18 Thread Yi Min Zhao
Add zPCI definitions in preparation of extending the PCI address
with parameters uid (user-defined identifier) and fid (PCI function
identifier).

Signed-off-by: Yi Min Zhao 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Stefan Zimmermann 
Reviewed-by: Bjoern Walk 
Reviewed-by: Ján Tomko 
Reviewed-by: Andrea Bolognani 
---
 cfg.mk| 1 +
 src/util/virpci.h | 8 
 2 files changed, 9 insertions(+)

diff --git a/cfg.mk b/cfg.mk
index 4790d0b7e7..1fc6a2dabb 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -472,6 +472,7 @@ sc_prohibit_canonicalize_file_name:
 # Insist on correct types for [pug]id.
 sc_correct_id_types:
@prohibit='\<(int|long) *[pug]id\>' \
+   exclude='exempt from syntax-check' \
halt='use pid_t for pid, uid_t for uid, gid_t for gid' \
  $(_sc_search_regexp)
 
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 16c2eded5e..4cc9298d85 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -37,12 +37,20 @@ typedef virPCIDeviceAddress *virPCIDeviceAddressPtr;
 typedef struct _virPCIDeviceList virPCIDeviceList;
 typedef virPCIDeviceList *virPCIDeviceListPtr;
 
+typedef struct _virZPCIDeviceAddress virZPCIDeviceAddress;
+typedef virZPCIDeviceAddress *virZPCIDeviceAddressPtr;
+struct _virZPCIDeviceAddress {
+unsigned int uid; /* exempt from syntax-check */
+unsigned int fid;
+};
+
 struct _virPCIDeviceAddress {
 unsigned int domain;
 unsigned int bus;
 unsigned int slot;
 unsigned int function;
 int multi; /* virTristateSwitch */
+virZPCIDeviceAddress zpci;
 };
 
 typedef enum {
-- 
Yi Min

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

Re: [libvirt] [PATCH] libvirtd: fix potential deadlock when starting vm

2018-10-18 Thread owen...@ucloud.cn
Thanks for your detailed explanation, Maybe i can set udev_monitor to 
nonblocking on centos6.



owen...@ucloud.cn
 
From: Erik Skultety
Date: 2018-10-18 20:23
To: John Ferlan
CC: Bingsong Si; libvir-list
Subject: Re: [libvirt] [PATCH] libvirtd: fix potential deadlock when starting vm
On Tue, Oct 16, 2018 at 05:57:17PM -0400, John Ferlan wrote:
>
>
> On 10/11/18 4:13 AM, Bingsong Si wrote:
> > On CentOS 6, udev_monitor_receive_device will block until the socket becomes
>
> Is this really CentOS6 only or just where you've seen it?
>
> > readable, udevEventHandleThread will hold the lock all the time and
> > udevEventHandleCallback hard to get the lock, will block the event poll.
> > To fix this, set dataReady to false after receive an udev event.
> >
> > Signed-off-by: Bingsong Si 
> > ---
> >  src/node_device/node_device_udev.c | 5 +
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> >
>
> I've CC'd Erik since he wrote and perhaps remembers all the "gotchas" he
> discovered in the udev callback code.
>
> I wonder if this has to do with the EAGAIN and EWOULDBLOCK @errno checks
> done in the !device loop that are different in "older" (much older) code.
>
> Although I have this very vague recollection that there was some problem
> with centos6 that was fixed by some OS patch.  Hopefully Erik remembers
> (and maybe we should log it in the code at this point ;-)) - I did do
> some searching, but came up empty.
 
Remembering a year old issue, let me tell you, my head hurts :) (and we probably
should put a note somewhere, so that we don't have to dig out dinosaurs
again)...the only thing I remember is that there was a reason why I did things
this way and not the way this patch is proposing, and indeed I then found this:
 
https://www.redhat.com/archives/libvir-list/2017-September/msg00683.html
 
TL;DR:
The scheduler comes into play here. The problem I had was that the event loop
could be scheduled (and it in fact was) earlier than the handler thread here.
What that essentially means is that by the time the thread actually handled the
event and read the data from the monitor, the event loop fired the very same
event, simply because the data hadn't been retrieved from the socket at that
point yet.
This was mainly connected to the design flaw of that specific version of patch
series. With the current design, setting dataReady immediately after reading the
data or after encoutering the first EAGAIN doesn't matter and the scheduler
wouldn't have an impact either way, that's true. However, with CentOS 6 the
scheduler would still come into play even with your patch (it was much more
noticeable the more devices you had in/added into the system), you'd still
remain blocking on the recv call. The correct fix would be more
complex and IIRC it would involve pulling the monitor object out of the private
data lockable object and would need to be guarded by a separate lock (I haven't
thought about it much though, so I might be wrong).
 
That said, we already dropped upstream support for CentOS 6, so I'm
not really keen on "fixing" anything, unless the currently supported platforms
suffer from a related issue which would require code changes in which case we
could merge a patch like this upstream. You should upgrade your platform to a
newer CentOS if you want to rely on features provided by new(ish) libvirt.
 
Erik
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] qemu: Avoid memleak on failure to format blockjobs

2018-10-18 Thread Eric Blake

On 10/18/18 3:08 PM, Eric Blake wrote:

virXMLFormatElement() frees attrBuf on success, but not necessarily
on failure. Most other callers of this function take the time to
reset attrBuf afterwords, but qemuDomainObjPrivateXMLFOrmatBlockjobs()
was relying on it succeeding, and could thus result in a memory leak.

Signed-off-by: Eric Blake 
---
  src/qemu/qemu_domain.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index dd67be5e2a..ad7a6fe136 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2232,11 +2232,15 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf,
  {
  virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
  bool bj = qemuDomainHasBlockjob(vm, false);
+ret = -1;


I need to quit editing patches in my mailer. As written, this obviously 
doesn't compile; s/ret/int ret/




  virBufferAsprintf(, " active='%s'",

virTristateBoolTypeToString(virTristateBoolFromBool(bj)));

-return virXMLFormatElement(buf, "blockjobs", , NULL);
+ret = virXMLFormatElement(buf, "blockjobs", , NULL);
+ cleanup:


and this label is unused.


+virBufferFreeAndReset();
+return ret;
  }




--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

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


Re: [libvirt] [PATCH v4 2/5] libxl: add support for PVH

2018-10-18 Thread Jim Fehlig

On 10/18/18 11:35 AM, Marek Marczykowski-Górecki wrote:

On Thu, Oct 18, 2018 at 11:08:34AM -0600, Jim Fehlig wrote:

On 10/17/18 12:59 PM, Marek Marczykowski-Górecki wrote:

On Sat, Oct 13, 2018 at 08:46:19AM -0600, Jim Fehlig wrote:

I had some couch time at the start of the weekend and was finally able to
try using this series with virt-install. As it turns out, reporting
duplicate  blocks for  'xen' is not quite right. Instead we
will want to report the additional  under the existing 'xen'
 blocks.


Is that virt-install limitation? In that case, IMO virt-install should
be fixed, instead of changing capabilities xml to match its limitations.


Perhaps it is a virt-install limitation, but my suggestion was based more on
how the qemu driver reports the different machines


   hvm
   
 64
 /usr/bin/qemu-system-x86_64
 pc-i440fx-3.0
 pc-q35-3.0
 ...
   


Compare that with reporting PV and PVH in different  blocks, where
the  and  are the same. It seems confusing from a consumers
POV


   xen
   
 64
 /usr/bin/qemu-system-x86_64
 xenpv
   



   xen
   
 64
 /usr/bin/qemu-system-x86_64
 xenpvh
   


How should a consumer interpret that? Is the machine for os_type=xen,
arch=x86_64 a xenpv or a xenpvh?


I don't see a problem - each guest block represent set of possible
configurations. Given the current structure, you could also ask "is
the os_type for arch=x86_64 a xen or a hvm?". Both are valid, with
possibly different set of features available. And the same goes for
xenpv and xenpvh machines.


Right, it is not a problem. I've not been super confident in our modeling choice 
and keep coming up with lame reasons while VIR_DOMAIN_OSTYPE_XENPVH might be a 
better approach. But it is time for me to stop talking in circles and commit 
this series. VIR_DOMAIN_OSTYPE_XENPV and machine xenpvh still feels like the 
best approach and no one has flat out objected to that. We can always adjust the 
capabilities reporting later if we feel there is a better way to do it.



Actually, I see qemu had similar problem as we have now with some features
being specific to some machine value - maxCpus. And as solution, it was
put in machine's attributes. But I think this approach is short-sighted.


Agreed, we can't just keep adding attributes. Seems a better approach would be 
 for each , but that is beyond the scope of this series.


Regards,
Jim

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

[libvirt] [PULL 42/45] net: stellaris_enet: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Peter Maydell 
Cc: qemu-...@nongnu.org
Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181001063803.22330-10-...@kaod.org>
Signed-off-by: Eduardo Habkost 
---
 hw/net/stellaris_enet.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c
index 165562d788..3ee1e0f8a4 100644
--- a/hw/net/stellaris_enet.c
+++ b/hw/net/stellaris_enet.c
@@ -473,9 +473,9 @@ static NetClientInfo net_stellaris_enet_info = {
 .receive = stellaris_enet_receive,
 };
 
-static int stellaris_enet_init(SysBusDevice *sbd)
+static void stellaris_enet_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 stellaris_enet_state *s = STELLARIS_ENET(dev);
 
 memory_region_init_io(>mmio, OBJECT(s), _enet_ops, s,
@@ -489,7 +489,6 @@ static int stellaris_enet_init(SysBusDevice *sbd)
 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
 
 stellaris_enet_reset(s);
-return 0;
 }
 
 static Property stellaris_enet_properties[] = {
@@ -500,9 +499,8 @@ static Property stellaris_enet_properties[] = {
 static void stellaris_enet_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = stellaris_enet_init;
+dc->realize = stellaris_enet_realize;
 dc->props = stellaris_enet_properties;
 dc->vmsd = _stellaris_enet;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 41/45] net: smc91c111: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Signed-off-by: Cédric Le Goater 
Message-Id: <20181001063803.22330-9-...@kaod.org>
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Eduardo Habkost 
---
 hw/net/smc91c111.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c
index d2fd2040e8..99da2d9297 100644
--- a/hw/net/smc91c111.c
+++ b/hw/net/smc91c111.c
@@ -766,9 +766,9 @@ static NetClientInfo net_smc91c111_info = {
 .receive = smc91c111_receive,
 };
 
-static int smc91c111_init1(SysBusDevice *sbd)
+static void smc91c111_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 smc91c111_state *s = SMC91C111(dev);
 
 memory_region_init_io(>mmio, OBJECT(s), _mem_ops, s,
@@ -780,7 +780,6 @@ static int smc91c111_init1(SysBusDevice *sbd)
   object_get_typename(OBJECT(dev)), dev->id, s);
 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
 /* ??? Save/restore.  */
-return 0;
 }
 
 static Property smc91c111_properties[] = {
@@ -791,9 +790,8 @@ static Property smc91c111_properties[] = {
 static void smc91c111_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = smc91c111_init1;
+dc->realize = smc91c111_realize;
 dc->reset = smc91c111_reset;
 dc->vmsd = _smc91c111;
 dc->props = smc91c111_properties;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 39/45] net: mipsnet: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Aleksandar Markovic 
Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181001063803.22330-7-...@kaod.org>
Signed-off-by: Eduardo Habkost 
---
 hw/net/mipsnet.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c
index 5a63df7ccb..03b3104278 100644
--- a/hw/net/mipsnet.c
+++ b/hw/net/mipsnet.c
@@ -236,9 +236,9 @@ static const MemoryRegionOps mipsnet_ioport_ops = {
 .impl.max_access_size = 4,
 };
 
-static int mipsnet_sysbus_init(SysBusDevice *sbd)
+static void mipsnet_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 MIPSnetState *s = MIPS_NET(dev);
 
 memory_region_init_io(>io, OBJECT(dev), _ioport_ops, s,
@@ -249,8 +249,6 @@ static int mipsnet_sysbus_init(SysBusDevice *sbd)
 s->nic = qemu_new_nic(_mipsnet_info, >conf,
   object_get_typename(OBJECT(dev)), dev->id, s);
 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
-
-return 0;
 }
 
 static void mipsnet_sysbus_reset(DeviceState *dev)
@@ -267,9 +265,8 @@ static Property mipsnet_properties[] = {
 static void mipsnet_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = mipsnet_sysbus_init;
+dc->realize = mipsnet_realize;
 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
 dc->desc = "MIPS Simulator network device";
 dc->reset = mipsnet_sysbus_reset;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 30/45] memory-device: complete factoring out pre_plug handling

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

With all required memory device class functions in place, we can factor
out pre_plug handling of memory devices. Take proper care of errors. We
still have to carry along legacy_align required for pc compatibility
handling.

We will factor out tracing of the address separately in a follow-up
patch.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-14-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h |  5 ++---
 hw/mem/memory-device.c | 32 +---
 hw/mem/pc-dimm.c   | 15 +++
 3 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index ed7cf5bf4b..d92acd2425 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -99,9 +99,8 @@ typedef struct MemoryDeviceClass {
 
 MemoryDeviceInfoList *qmp_memory_device_list(void);
 uint64_t get_plugged_memory_size(void);
-uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
- uint64_t align, uint64_t size,
- Error **errp);
+void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
+const uint64_t *legacy_align, Error **errp);
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
uint64_t addr);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 07749bab69..aa4ddd5918 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -93,9 +93,10 @@ static void memory_device_check_addable(MachineState *ms, 
uint64_t size,
 
 }
 
-uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint,
- uint64_t align, uint64_t size,
- Error **errp)
+static uint64_t memory_device_get_free_addr(MachineState *ms,
+const uint64_t *hint,
+uint64_t align, uint64_t size,
+Error **errp)
 {
 uint64_t address_space_start, address_space_end;
 GSList *list = NULL, *item;
@@ -247,6 +248,31 @@ uint64_t get_plugged_memory_size(void)
 return size;
 }
 
+void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
+const uint64_t *legacy_align, Error **errp)
+{
+const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+Error *local_err = NULL;
+uint64_t addr, align;
+MemoryRegion *mr;
+
+mr = mdc->get_memory_region(md, _err);
+if (local_err) {
+goto out;
+}
+
+align = legacy_align ? *legacy_align : memory_region_get_alignment(mr);
+addr = mdc->get_addr(md);
+addr = memory_device_get_free_addr(ms, !addr ? NULL : , align,
+   memory_region_size(mr), _err);
+if (local_err) {
+goto out;
+}
+mdc->set_addr(md, addr, _err);
+out:
+error_propagate(errp, local_err);
+}
+
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
uint64_t addr)
 {
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 4a15091734..b2959bcf0e 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -32,10 +32,8 @@ static int pc_dimm_get_free_slot(const int *hint, int 
max_slots, Error **errp);
 void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
   const uint64_t *legacy_align, Error **errp)
 {
-MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
 Error *local_err = NULL;
-MemoryRegion *mr;
-uint64_t addr, align;
+uint64_t addr;
 int slot;
 
 slot = object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP,
@@ -49,22 +47,15 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState 
*machine,
 _abort);
 trace_mhp_pc_dimm_assigned_slot(slot);
 
-mr = mdc->get_memory_region(MEMORY_DEVICE(dimm), _err);
+memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
+   _err);
 if (local_err) {
 goto out;
 }
 
-align = legacy_align ? *legacy_align : memory_region_get_alignment(mr);
 addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
 _abort);
-addr = memory_device_get_free_addr(machine, !addr ? NULL : , align,
-   memory_region_size(mr), _err);
-if (local_err) {
-goto out;
-}
 trace_mhp_pc_dimm_assigned_address(addr);
-object_property_set_uint(OBJECT(dimm), addr, PC_DIMM_ADDR_PROP,
- _abort);
 out:
 error_propagate(errp, local_err);
 }
-- 
2.18.0.rc1.1.g3f1ff2140

--

[libvirt] [PULL 25/45] memory-device: document MemoryDeviceClass

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

Document the functions. Don't document get_region_size(), as we will be
dropping/replacing that one soon.

Use same documentation style as in include/exec/memory.h, but don't
document the parameters, as they are self-explanatory.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-9-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index f02b229837..0474a3dd11 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -29,12 +29,48 @@ typedef struct MemoryDeviceState {
 Object parent_obj;
 } MemoryDeviceState;
 
+/**
+ * MemoryDeviceClass:
+ *
+ * All memory devices need to implement TYPE_MEMORY_DEVICE as an interface.
+ *
+ * A memory device is a device that owns a memory region which is
+ * mapped into guest physical address space at a certain address. The
+ * address in guest physical memory can either be specified explicitly
+ * or get assigned automatically.
+ */
 typedef struct MemoryDeviceClass {
+/* private */
 InterfaceClass parent_class;
 
+/*
+ * Return the address of the memory device in guest physical memory.
+ *
+ * Called when (un)plugging a memory device or when iterating over
+ * all memory devices mapped into guest physical address space.
+ *
+ * If "0" is returned, no address has been specified by the user and
+ * no address has been assigned to this memory device yet.
+ */
 uint64_t (*get_addr)(const MemoryDeviceState *md);
+
+/*
+ * Return the amount of memory provided by the memory device currently
+ * usable ("plugged") by the VM.
+ *
+ * Called when calculating the total amount of ram available to the
+ * VM (e.g. to report memory stats to the user).
+ *
+ * This is helpful for devices that dynamically manage the amount of
+ * memory accessible by the guest via the reserved memory region. For
+ * most devices, this corresponds to the size of the memory region.
+ */
 uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
 uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
+
+/*
+ * Translate the memory device into #MemoryDeviceInfo.
+ */
 void (*fill_device_info)(const MemoryDeviceState *md,
  MemoryDeviceInfo *info);
 } MemoryDeviceClass;
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 28/45] memory-device: drop get_region_size()

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

There are no remaining users of get_region_size() except
memory_device_get_region_size() itself. We can make
memory_device_get_region_size() work directly on get_memory_region()
instead and drop get_region_size().

In addition, we can now use memory_device_get_region_size() in pc-dimm
code to implement get_plugged_size()"

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-12-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h |  1 -
 hw/mem/memory-device.c | 11 +--
 hw/mem/pc-dimm.c   | 18 +-
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 659f38385c..9c3398bc4a 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -71,7 +71,6 @@ typedef struct MemoryDeviceClass {
  * most devices, this corresponds to the size of the memory region.
  */
 uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
-uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
 
 /*
  * Return the memory region of the memory device.
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 425830c65c..07749bab69 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -268,9 +268,16 @@ void memory_device_unplug_region(MachineState *ms, 
MemoryRegion *mr)
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
Error **errp)
 {
-MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+MemoryRegion *mr;
 
-return mdc->get_region_size(md, errp);
+/* dropping const here is fine as we don't touch the memory region */
+mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
+if (!mr) {
+return 0;
+}
+
+return memory_region_size(mr);
 }
 
 static const TypeInfo memory_device_info = {
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index c9f6ad589e..47b2e83389 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -236,21 +236,6 @@ static uint64_t pc_dimm_md_get_addr(const 
MemoryDeviceState *md)
 return dimm->addr;
 }
 
-static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
-   Error **errp)
-{
-MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
-MemoryRegion *mr;
-
-/* dropping const here is fine as we don't touch the memory region */
-mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
-if (!mr) {
-return 0;
-}
-
-return memory_region_size(mr);
-}
-
 static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
   Error **errp)
 {
@@ -302,8 +287,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
 
 mdc->get_addr = pc_dimm_md_get_addr;
 /* for a dimm plugged_size == region_size */
-mdc->get_plugged_size = pc_dimm_md_get_region_size;
-mdc->get_region_size = pc_dimm_md_get_region_size;
+mdc->get_plugged_size = memory_device_get_region_size;
 mdc->get_memory_region = pc_dimm_md_get_memory_region;
 mdc->fill_device_info = pc_dimm_md_fill_device_info;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 18/45] memory-device: fix alignment error message

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

We're missing "x" after the leading 0.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-2-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 hw/mem/memory-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 6de4f70bb4..0b52fe2c5e 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -120,7 +120,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, 
const uint64_t *hint,
 
 /* address_space_start indicates the maximum alignment we expect */
 if (QEMU_ALIGN_UP(address_space_start, align) != address_space_start) {
-error_setg(errp, "the alignment (0%" PRIx64 ") is not supported",
+error_setg(errp, "the alignment (0x%" PRIx64 ") is not supported",
align);
 return 0;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 45/45] numa: Clean up error reporting in parse_numa()

2018-10-18 Thread Eduardo Habkost
From: Markus Armbruster 

Calling error_report() in a function that takes an Error ** argument
is suspicious.  parse_numa() does that, and then fails without setting
an error.  Its caller main(), via qemu_opts_foreach(), is fine with
it, but clean it up anyway.

While there, give parse_numa() internal linkage.

Cc: Eduardo Habkost 
Signed-off-by: Markus Armbruster 
Message-Id: <20181008173125.19678-26-arm...@redhat.com>
Reviewed-by: Eduardo Habkost 
Signed-off-by: Eduardo Habkost 
---
 include/sysemu/numa.h | 1 -
 numa.c| 8 +++-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h
index 7a0ae751aa..21713b7e2f 100644
--- a/include/sysemu/numa.h
+++ b/include/sysemu/numa.h
@@ -22,7 +22,6 @@ struct NumaNodeMem {
 };
 
 extern NodeInfo numa_info[MAX_NODES];
-int parse_numa(void *opaque, QemuOpts *opts, Error **errp);
 void parse_numa_opts(MachineState *ms);
 void numa_complete_configuration(MachineState *ms);
 void query_numa_node_mem(NumaNodeMem node_mem[]);
diff --git a/numa.c b/numa.c
index 1d7c49ad43..50ec016013 100644
--- a/numa.c
+++ b/numa.c
@@ -215,7 +215,7 @@ end:
 error_propagate(errp, err);
 }
 
-int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
+static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
 {
 NumaOptions *object = NULL;
 MachineState *ms = MACHINE(opaque);
@@ -239,7 +239,7 @@ int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
 end:
 qapi_free_NumaOptions(object);
 if (err) {
-error_report_err(err);
+error_propagate(errp, err);
 return -1;
 }
 
@@ -444,9 +444,7 @@ void numa_complete_configuration(MachineState *ms)
 
 void parse_numa_opts(MachineState *ms)
 {
-if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, NULL)) {
-exit(1);
-}
+qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, _fatal);
 }
 
 void qmp_set_numa_node(NumaOptions *cmd, Error **errp)
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 44/45] net: xgmac: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Peter Maydell 
Cc: qemu-...@nongnu.org
Cc: Rob Herring 
Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181001063803.22330-12-...@kaod.org>
Signed-off-by: Eduardo Habkost 
---
 hw/net/xgmac.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/net/xgmac.c b/hw/net/xgmac.c
index fa001563d3..63f5a62ebf 100644
--- a/hw/net/xgmac.c
+++ b/hw/net/xgmac.c
@@ -374,9 +374,9 @@ static NetClientInfo net_xgmac_enet_info = {
 .receive = eth_rx,
 };
 
-static int xgmac_enet_init(SysBusDevice *sbd)
+static void xgmac_enet_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 XgmacState *s = XGMAC(dev);
 
 memory_region_init_io(>iomem, OBJECT(s), _mem_ops, s,
@@ -397,8 +397,6 @@ static int xgmac_enet_init(SysBusDevice *sbd)
  (s->conf.macaddr.a[2] << 16) |
  (s->conf.macaddr.a[1] << 8) |
   s->conf.macaddr.a[0];
-
-return 0;
 }
 
 static Property xgmac_properties[] = {
@@ -408,10 +406,9 @@ static Property xgmac_properties[] = {
 
 static void xgmac_enet_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-sbc->init = xgmac_enet_init;
+dc->realize = xgmac_enet_realize;
 dc->vmsd = _xgmac;
 dc->props = xgmac_properties;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 10/45] hw/pci-host/bonito: Use DeviceState::realize rather than SysBusDevice::init

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Move from the legacy SysBusDevice::init method to using DeviceState::realize.

Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <20181002212522.23303-7-f4...@amsat.org>
Reviewed-by: Peter Maydell 
Signed-off-by: Eduardo Habkost 
---
 hw/pci-host/bonito.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index 9868e2eccc..9f33582706 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -595,7 +595,7 @@ static const VMStateDescription vmstate_bonito = {
 }
 };
 
-static int bonito_pcihost_initfn(SysBusDevice *dev)
+static void bonito_pcihost_realize(DeviceState *dev, Error **errp)
 {
 PCIHostState *phb = PCI_HOST_BRIDGE(dev);
 
@@ -603,8 +603,6 @@ static int bonito_pcihost_initfn(SysBusDevice *dev)
  pci_bonito_set_irq, pci_bonito_map_irq,
  dev, get_system_memory(), get_system_io(),
  0x28, 32, TYPE_PCI_BUS);
-
-return 0;
 }
 
 static void bonito_realize(PCIDevice *dev, Error **errp)
@@ -684,7 +682,6 @@ PCIBus *bonito_init(qemu_irq *pic)
 pcihost->pic = pic;
 qdev_init_nofail(dev);
 
-/* set the pcihost pointer before bonito_initfn is called */
 d = pci_create(phb->bus, PCI_DEVFN(0, 0), TYPE_PCI_BONITO);
 s = PCI_BONITO(d);
 s->pcihost = pcihost;
@@ -726,9 +723,9 @@ static const TypeInfo bonito_info = {
 
 static void bonito_pcihost_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-k->init = bonito_pcihost_initfn;
+dc->realize = bonito_pcihost_realize;
 }
 
 static const TypeInfo bonito_pcihost_info = {
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 36/45] net: lan9118: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Signed-off-by: Cédric Le Goater 
Message-Id: <20181001063803.22330-4-...@kaod.org>
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Eduardo Habkost 
---
 hw/net/lan9118.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c
index b9032dac59..a6269d9463 100644
--- a/hw/net/lan9118.c
+++ b/hw/net/lan9118.c
@@ -1320,9 +1320,9 @@ static NetClientInfo net_lan9118_info = {
 .link_status_changed = lan9118_set_link,
 };
 
-static int lan9118_init1(SysBusDevice *sbd)
+static void lan9118_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 lan9118_state *s = LAN9118(dev);
 QEMUBH *bh;
 int i;
@@ -1349,8 +1349,6 @@ static int lan9118_init1(SysBusDevice *sbd)
 s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
 ptimer_set_freq(s->timer, 1);
 ptimer_set_limit(s->timer, 0x, 1);
-
-return 0;
 }
 
 static Property lan9118_properties[] = {
@@ -1362,12 +1360,11 @@ static Property lan9118_properties[] = {
 static void lan9118_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = lan9118_init1;
 dc->reset = lan9118_reset;
 dc->props = lan9118_properties;
 dc->vmsd = _lan9118;
+dc->realize = lan9118_realize;
 }
 
 static const TypeInfo lan9118_info = {
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 13/45] hw/sparc64/niagara: Model the I/O Bridge with the 'unimplemented_device'

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Since the I/O Bridge device is not implemented,  Use the
TYPE_UNIMPLEMENTED_DEVICE which suits better: if the user
asks for 'unimp' warnings via the -d option then all accesses
will generate logging.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Artyom Tarasenko 
Message-Id: <20181002212522.23303-10-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 default-configs/sparc64-softmmu.mak | 1 -
 hw/sparc64/niagara.c| 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/default-configs/sparc64-softmmu.mak 
b/default-configs/sparc64-softmmu.mak
index 52edafe547..ce63d47046 100644
--- a/default-configs/sparc64-softmmu.mak
+++ b/default-configs/sparc64-softmmu.mak
@@ -16,5 +16,4 @@ CONFIG_SIMBA=y
 CONFIG_SUNHME=y
 CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
-CONFIG_EMPTY_SLOT=y
 CONFIG_SUN4V_RTC=y
diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c
index 4fa8cb2904..f8a856f611 100644
--- a/hw/sparc64/niagara.c
+++ b/hw/sparc64/niagara.c
@@ -29,7 +29,7 @@
 #include "hw/hw.h"
 #include "hw/boards.h"
 #include "hw/char/serial.h"
-#include "hw/empty_slot.h"
+#include "hw/misc/unimp.h"
 #include "hw/loader.h"
 #include "hw/sparc/sparc64.h"
 #include "hw/timer/sun4v-rtc.h"
@@ -161,7 +161,7 @@ static void niagara_init(MachineState *machine)
 serial_mm_init(sysmem, NIAGARA_UART_BASE, 0, NULL, 115200,
serial_hd(0), DEVICE_BIG_ENDIAN);
 }
-empty_slot_init(NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
+create_unimplemented_device("sun4v-iob", NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
 sun4v_rtc_init(NIAGARA_RTC_BASE);
 }
 
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 03/45] vl:c: make sure that sockets are calculated correctly in '-smp X' case

2018-10-18 Thread Eduardo Habkost
From: Igor Mammedov 

commit
  (5cdc9b76e3 vl.c: Remove dead assignment)
removed sockets calculation when 'sockets' weren't provided on CLI
since there wasn't any users for it back then. Exiting checks
are neither reachable
   } else if (sockets * cores * threads < cpus) {
or nor triggerable
   if (sockets * cores * threads > max_cpus)
so we weren't noticing wrong topology since then, since users
recalculate sockets adhoc on their own.

However with deprecation check it becomes noticable, for example
  -smp 2
will start printing warning:
  "warning: Invalid CPU topology deprecated: sockets (1) * cores (1) * threads 
(1) != maxcpus (2)"
calculating sockets if they weren't specified.

Fix it by returning back sockets calculation if it's omitted on CLI.

Signed-off-by: Igor Mammedov 
Reviewed-by: Andrew Jones 
Message-Id: <1536836762-273036-3-git-send-email-imamm...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 vl.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/vl.c b/vl.c
index 027d04c7ca..2324321d91 100644
--- a/vl.c
+++ b/vl.c
@@ -1199,11 +1199,14 @@ static void smp_parse(QemuOpts *opts)
 
 /* compute missing values, prefer sockets over cores over threads */
 if (cpus == 0 || sockets == 0) {
-sockets = sockets > 0 ? sockets : 1;
 cores = cores > 0 ? cores : 1;
 threads = threads > 0 ? threads : 1;
 if (cpus == 0) {
+sockets = sockets > 0 ? sockets : 1;
 cpus = cores * threads * sockets;
+} else {
+max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+sockets = max_cpus / (cores * threads);
 }
 } else if (cores == 0) {
 threads = threads > 0 ? threads : 1;
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 27/45] memory-device: factor out get_memory_region() from pc-dimm

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

The memory region is necessary for plugging/unplugging a memory device.
The region size (via get_region_size()) is no longer sufficient, as
besides the alignment, also the region itself is required in order to
add it to the device memory region of the machine via
- memory_region_add_subregion
- memory_region_del_subregion

So, to factor out plugging/unplugging of memory devices from pc-dimm
code, we have to factor out access to the memory region first.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-11-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h | 15 +++
 include/hw/mem/pc-dimm.h   |  4 
 hw/mem/nvdimm.c|  9 ++---
 hw/mem/pc-dimm.c   | 27 ++-
 4 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 898df3057d..659f38385c 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -38,6 +38,11 @@ typedef struct MemoryDeviceState {
  * mapped into guest physical address space at a certain address. The
  * address in guest physical memory can either be specified explicitly
  * or get assigned automatically.
+ *
+ * Conceptually, memory devices only span one memory region. If multiple
+ * successive memory regions are used, a covering memory region has to
+ * be provided. Scattered memory regions are not supported for single
+ * devices.
  */
 typedef struct MemoryDeviceClass {
 /* private */
@@ -68,6 +73,16 @@ typedef struct MemoryDeviceClass {
 uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
 uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
 
+/*
+ * Return the memory region of the memory device.
+ *
+ * Called when (un)plugging the memory device, to (un)map the
+ * memory region in guest physical memory, but also to detect the
+ * required alignment during address assignment or when the size of the
+ * memory region is required.
+ */
+MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp);
+
 /*
  * Translate the memory device into #MemoryDeviceInfo.
  */
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 99cbd54de7..01436b9f50 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -61,9 +61,6 @@ typedef struct PCDIMMDevice {
  * PCDIMMDeviceClass:
  * @realize: called after common dimm is realized so that the dimm based
  * devices get the chance to do specified operations.
- * @get_memory_region: returns #MemoryRegion associated with @dimm which
- * is directly mapped into the physical address space of guest. Will not
- * fail after the device was realized.
  * @get_vmstate_memory_region: returns #MemoryRegion which indicates the
  * memory of @dimm should be kept during live migration. Will not fail
  * after the device was realized.
@@ -74,7 +71,6 @@ typedef struct PCDIMMDeviceClass {
 
 /* public */
 void (*realize)(PCDIMMDevice *dimm, Error **errp);
-MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp);
 MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
Error **errp);
 } PCDIMMDeviceClass;
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index 1c6674c4ed..49324f3fae 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -27,6 +27,7 @@
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "hw/mem/nvdimm.h"
+#include "hw/mem/memory-device.h"
 
 static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *name,
   void *opaque, Error **errp)
@@ -118,9 +119,10 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice 
*nvdimm, Error **errp)
 nvdimm->nvdimm_mr->align = align;
 }
 
-static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)
+static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md,
+ Error **errp)
 {
-NVDIMMDevice *nvdimm = NVDIMM(dimm);
+NVDIMMDevice *nvdimm = NVDIMM(md);
 Error *local_err = NULL;
 
 if (!nvdimm->nvdimm_mr) {
@@ -190,11 +192,12 @@ static Property nvdimm_properties[] = {
 static void nvdimm_class_init(ObjectClass *oc, void *data)
 {
 PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
+MemoryDeviceClass *mdc = MEMORY_DEVICE_CLASS(oc);
 NVDIMMClass *nvc = NVDIMM_CLASS(oc);
 DeviceClass *dc = DEVICE_CLASS(oc);
 
 ddc->realize = nvdimm_realize;
-ddc->get_memory_region = nvdimm_get_memory_region;
+mdc->get_memory_region = nvdimm_md_get_memory_region;
 dc->props = nvdimm_properties;
 
 nvc->read_label_data = nvdimm_read_label_data;
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 3e43ec8742..c9f6ad589e 100644
--- a/hw/mem/pc-dimm.c

[libvirt] [PULL 07/45] hw/timer/sun4v-rtc: Use DeviceState::realize rather than SysBusDevice::init

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Move from the legacy SysBusDevice::init method to using DeviceState::realize.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Reviewed-by: Cédric Le Goater 
Message-Id: <20181002212522.23303-4-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/timer/sun4v-rtc.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/timer/sun4v-rtc.c b/hw/timer/sun4v-rtc.c
index 13be94f8da..4e7f6a1eff 100644
--- a/hw/timer/sun4v-rtc.c
+++ b/hw/timer/sun4v-rtc.c
@@ -63,21 +63,21 @@ void sun4v_rtc_init(hwaddr addr)
 sysbus_mmio_map(s, 0, addr);
 }
 
-static int sun4v_rtc_init1(SysBusDevice *dev)
+static void sun4v_rtc_realize(DeviceState *dev, Error **errp)
 {
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 Sun4vRtc *s = SUN4V_RTC(dev);
 
 memory_region_init_io(>iomem, OBJECT(s), _rtc_ops, s,
   "sun4v-rtc", 0x08ULL);
-sysbus_init_mmio(dev, >iomem);
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static void sun4v_rtc_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-k->init = sun4v_rtc_init1;
+dc->realize = sun4v_rtc_realize;
 }
 
 static const TypeInfo sun4v_rtc_info = {
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 04/45] numa: Fix QMP command set-numa-node error handling

2018-10-18 Thread Eduardo Habkost
From: Markus Armbruster 

Calling error_report() in a function that takes an Error ** argument
is suspicious.  parse_numa_node() does that, and then exit()s.  It
also passes _fatal to machine_set_cpu_numa_node().  Both wrong.
Attempting to configure numa when the machine doesn't support it kills
the VM:

$ qemu-system-x86_64 -nodefaults -S -display none -M none -preconfig -qmp 
stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, 
"package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}}
{"execute": "qmp_capabilities"}
{"return": {}}
{"execute": "set-numa-node", "arguments": {"type": "node"}}
NUMA is not supported by this machine-type
$ echo $?
1

Messed up when commit 64c2a8f6d3f and 7c88e65d9e9 (v2.10.0) added
incorrect error handling right next to correct examples.  Latent bug
until commit f3be67812c2 (v3.0.0) made it accessible via QMP.  Fairly
harmless in practice, because it's limited to RUN_STATE_PRECONFIG.
The fix is obvious: replace error_report(); exit() by error_setg();
return.

This affects parse_numa_node()'s other caller
numa_complete_configuration(): since it ignores errors, the "NUMA is
not supported by this machine-type" is now ignored, too.  But that
error is as unexpected there as any other.  Change it to abort on
error instead.

Fixes: f3be67812c226162f86ce92634bd913714445420
Cc: Igor Mammedov 
Signed-off-by: Markus Armbruster 
Message-Id: <20181008173125.19678-15-arm...@redhat.com>
Reviewed-by: Eduardo Habkost 
Reviewed-by: Igor Mammedov 
Signed-off-by: Eduardo Habkost 
---
 numa.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/numa.c b/numa.c
index 81542d4ebb..1d7c49ad43 100644
--- a/numa.c
+++ b/numa.c
@@ -60,6 +60,7 @@ NodeInfo numa_info[MAX_NODES];
 static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
 Error **errp)
 {
+Error *err = NULL;
 uint16_t nodenr;
 uint16List *cpus = NULL;
 MachineClass *mc = MACHINE_GET_CLASS(ms);
@@ -82,8 +83,8 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions 
*node,
 }
 
 if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) {
-error_report("NUMA is not supported by this machine-type");
-exit(1);
+error_setg(errp, "NUMA is not supported by this machine-type");
+return;
 }
 for (cpus = node->cpus; cpus; cpus = cpus->next) {
 CpuInstanceProperties props;
@@ -97,7 +98,11 @@ static void parse_numa_node(MachineState *ms, 
NumaNodeOptions *node,
 props = mc->cpu_index_to_instance_props(ms, cpus->value);
 props.node_id = nodenr;
 props.has_node_id = true;
-machine_set_cpu_numa_node(ms, , _fatal);
+machine_set_cpu_numa_node(ms, , );
+if (err) {
+error_propagate(errp, err);
+return;
+}
 }
 
 if (node->has_mem && node->has_memdev) {
@@ -367,7 +372,7 @@ void numa_complete_configuration(MachineState *ms)
 if (ms->ram_slots > 0 && nb_numa_nodes == 0 &&
 mc->auto_enable_numa_with_memhp) {
 NumaNodeOptions node = { };
-parse_numa_node(ms, , NULL);
+parse_numa_node(ms, , _abort);
 }
 
 assert(max_numa_nodeid <= MAX_NODES);
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PATCH] qemu: Avoid memleak on failure to format blockjobs

2018-10-18 Thread Eric Blake
virXMLFormatElement() frees attrBuf on success, but not necessarily
on failure. Most other callers of this function take the time to
reset attrBuf afterwords, but qemuDomainObjPrivateXMLFOrmatBlockjobs()
was relying on it succeeding, and could thus result in a memory leak.

Signed-off-by: Eric Blake 
---
 src/qemu/qemu_domain.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index dd67be5e2a..ad7a6fe136 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2232,11 +2232,15 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf,
 {
 virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
 bool bj = qemuDomainHasBlockjob(vm, false);
+ret = -1;

 virBufferAsprintf(, " active='%s'",
   
virTristateBoolTypeToString(virTristateBoolFromBool(bj)));

-return virXMLFormatElement(buf, "blockjobs", , NULL);
+ret = virXMLFormatElement(buf, "blockjobs", , NULL);
+ cleanup:
+virBufferFreeAndReset();
+return ret;
 }


-- 
2.17.2

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


[libvirt] [PULL 06/45] hw/timer/sun4v-rtc: Convert from DPRINTF() macro to trace events

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Artyom Tarasenko 
Reviewed-by: Cédric Le Goater 
Message-Id: <20181002212522.23303-3-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/timer/sun4v-rtc.c  | 13 +++--
 hw/timer/trace-events |  4 
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/hw/timer/sun4v-rtc.c b/hw/timer/sun4v-rtc.c
index 310523225f..13be94f8da 100644
--- a/hw/timer/sun4v-rtc.c
+++ b/hw/timer/sun4v-rtc.c
@@ -14,15 +14,8 @@
 #include "hw/sysbus.h"
 #include "qemu/timer.h"
 #include "hw/timer/sun4v-rtc.h"
+#include "trace.h"
 
-//#define DEBUG_SUN4V_RTC
-
-#ifdef DEBUG_SUN4V_RTC
-#define DPRINTF(fmt, ...)   \
-do { printf("sun4v_rtc: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while (0)
-#endif
 
 #define TYPE_SUN4V_RTC "sun4v_rtc"
 #define SUN4V_RTC(obj) OBJECT_CHECK(Sun4vRtc, (obj), TYPE_SUN4V_RTC)
@@ -41,14 +34,14 @@ static uint64_t sun4v_rtc_read(void *opaque, hwaddr addr,
 /* accessing the high 32 bits */
 val >>= 32;
 }
-DPRINTF("read from " TARGET_FMT_plx " val %lx\n", addr, val);
+trace_sun4v_rtc_read(addr, val);
 return val;
 }
 
 static void sun4v_rtc_write(void *opaque, hwaddr addr,
  uint64_t val, unsigned size)
 {
-DPRINTF("write 0x%x to " TARGET_FMT_plx "\n", (unsigned)val, addr);
+trace_sun4v_rtc_read(addr, val);
 }
 
 static const MemoryRegionOps sun4v_rtc_ops = {
diff --git a/hw/timer/trace-events b/hw/timer/trace-events
index ca9ad6321a..75bd3b1042 100644
--- a/hw/timer/trace-events
+++ b/hw/timer/trace-events
@@ -66,5 +66,9 @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data, 
unsigned size) "CMSDK A
 cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) 
"CMSDK APB dualtimer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
 cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
 
+# hw/timer/sun4v-rtc.c
+sun4v_rtc_read(uint64_t addr, uint64_t value) "read: addr 0x%" PRIx64 " value 
0x%" PRIx64
+sun4v_rtc_write(uint64_t addr, uint64_t value) "write: addr 0x%" PRIx64 " 
value 0x%" PRIx64
+
 # hw/timer/xlnx-zynqmp-rtc.c
 xlnx_zynqmp_rtc_gettime(int year, int month, int day, int hour, int min, int 
sec) "Get time from host: %d-%d-%d %2d:%02d:%02d"
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 35/45] net: etraxfs_eth: add a reset method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Edgar E. Iglesias 
Signed-off-by: Cédric Le Goater 
Message-Id: <20181001063803.22330-3-...@kaod.org>
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Eduardo Habkost 
---
 hw/net/etraxfs_eth.c | 31 +--
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c
index 64ab3df1ae..36855804db 100644
--- a/hw/net/etraxfs_eth.c
+++ b/hw/net/etraxfs_eth.c
@@ -127,7 +127,7 @@ tdk_write(struct qemu_phy *phy, unsigned int req, unsigned 
int data)
 }
 
 static void
-tdk_init(struct qemu_phy *phy)
+tdk_reset(struct qemu_phy *phy)
 {
 phy->regs[0] = 0x3100;
 /* PHY Id.  */
@@ -136,9 +136,6 @@ tdk_init(struct qemu_phy *phy)
 /* Autonegotiation advertisement reg.  */
 phy->regs[4] = 0x01E1;
 phy->link = 1;
-
-phy->read = tdk_read;
-phy->write = tdk_write;
 }
 
 struct qemu_mdio
@@ -585,6 +582,27 @@ static NetClientInfo net_etraxfs_info = {
 .link_status_changed = eth_set_link,
 };
 
+static void etraxfs_eth_reset(DeviceState *dev)
+{
+ETRAXFSEthState *s = ETRAX_FS_ETH(dev);
+
+memset(s->regs, 0, sizeof(s->regs));
+memset(s->macaddr, 0, sizeof(s->macaddr));
+s->duplex_mismatch = 0;
+
+s->mdio_bus.mdc = 0;
+s->mdio_bus.mdio = 0;
+s->mdio_bus.state = 0;
+s->mdio_bus.drive = 0;
+s->mdio_bus.cnt = 0;
+s->mdio_bus.addr = 0;
+s->mdio_bus.opc = 0;
+s->mdio_bus.req = 0;
+s->mdio_bus.data = 0;
+
+tdk_reset(>phy);
+}
+
 static void etraxfs_eth_realize(DeviceState *dev, Error **errp)
 {
 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
@@ -609,8 +627,8 @@ static void etraxfs_eth_realize(DeviceState *dev, Error 
**errp)
   object_get_typename(OBJECT(s)), dev->id, s);
 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
 
-
-tdk_init(>phy);
+s->phy.read = tdk_read;
+s->phy.write = tdk_write;
 mdio_attach(>mdio_bus, >phy, s->phyaddr);
 }
 
@@ -627,6 +645,7 @@ static void etraxfs_eth_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc->realize = etraxfs_eth_realize;
+dc->reset = etraxfs_eth_reset;
 dc->props = etraxfs_eth_properties;
 /* Reason: pointer properties "dma_out", "dma_in" */
 dc->user_creatable = false;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 40/45] net: opencores_eth: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Max Filippov 
Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181001063803.22330-8-...@kaod.org>
Acked-by: Max Filippov 
Signed-off-by: Eduardo Habkost 
---
 hw/net/opencores_eth.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c
index d42b79c08c..d6f54f8d82 100644
--- a/hw/net/opencores_eth.c
+++ b/hw/net/opencores_eth.c
@@ -715,9 +715,9 @@ static const MemoryRegionOps open_eth_desc_ops = {
 .write = open_eth_desc_write,
 };
 
-static int sysbus_open_eth_init(SysBusDevice *sbd)
+static void sysbus_open_eth_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 OpenEthState *s = OPEN_ETH(dev);
 
 memory_region_init_io(>reg_io, OBJECT(dev), _eth_reg_ops, s,
@@ -732,7 +732,6 @@ static int sysbus_open_eth_init(SysBusDevice *sbd)
 
 s->nic = qemu_new_nic(_open_eth_info, >conf,
   object_get_typename(OBJECT(s)), dev->id, s);
-return 0;
 }
 
 static void qdev_open_eth_reset(DeviceState *dev)
@@ -750,9 +749,8 @@ static Property open_eth_properties[] = {
 static void open_eth_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = sysbus_open_eth_init;
+dc->realize = sysbus_open_eth_realize;
 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
 dc->desc = "Opencores 10/100 Mbit Ethernet";
 dc->reset = qdev_open_eth_reset;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 38/45] net: milkymist_minimac2: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Michael Walle 
Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181001063803.22330-6-...@kaod.org>
Acked-by: Michael Walle 
Signed-off-by: Eduardo Habkost 
---
 hw/net/milkymist-minimac2.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/net/milkymist-minimac2.c b/hw/net/milkymist-minimac2.c
index 3eaa19dfde..7ef1daee41 100644
--- a/hw/net/milkymist-minimac2.c
+++ b/hw/net/milkymist-minimac2.c
@@ -452,9 +452,9 @@ static NetClientInfo net_milkymist_minimac2_info = {
 .receive = minimac2_rx,
 };
 
-static int milkymist_minimac2_init(SysBusDevice *sbd)
+static void milkymist_minimac2_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 MilkymistMinimac2State *s = MILKYMIST_MINIMAC2(dev);
 size_t buffers_size = TARGET_PAGE_ALIGN(3 * MINIMAC2_BUFFER_SIZE);
 
@@ -479,8 +479,6 @@ static int milkymist_minimac2_init(SysBusDevice *sbd)
 s->nic = qemu_new_nic(_milkymist_minimac2_info, >conf,
   object_get_typename(OBJECT(dev)), dev->id, s);
 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
-
-return 0;
 }
 
 static const VMStateDescription vmstate_milkymist_minimac2_mdio = {
@@ -521,9 +519,8 @@ static Property milkymist_minimac2_properties[] = {
 static void milkymist_minimac2_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = milkymist_minimac2_init;
+dc->realize = milkymist_minimac2_realize;
 dc->reset = milkymist_minimac2_reset;
 dc->vmsd = _milkymist_minimac2;
 dc->props = milkymist_minimac2_properties;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 00/45] Machine queue, 2018-10-18

2018-10-18 Thread Eduardo Habkost
The following changes since commit 09558375a634e17cea6cfbfec883ac2376d2dc7f:

  Merge remote-tracking branch 
'remotes/pmaydell/tags/pull-target-arm-20181016-1' into staging (2018-10-16 
17:42:56 +0100)

are available in the Git repository at:

  git://github.com/ehabkost/qemu.git tags/machine-next-pull-request

for you to fetch changes up to 6d8e1bcc7dd5e819ce81e6a87fffe23e39c700cc:

  numa: Clean up error reporting in parse_numa() (2018-10-17 16:33:40 -0300)


Machine queue, 2018-10-18

* sysbus init/realize cleanups
  (Cédric Le Goater, Philippe Mathieu-Daudé)
* memory-device refactoring (David Hildenbrand)
* -smp: deprecate incorrect CPUs topology (Igor Mammedov)
* -numa parsing cleanups (Markus Armbruster)
* Fix hostmem-file memory leak (Zhang Yi)
* Typo fix (Li Qiang)



Queue for Machine Core patches


Cédric Le Goater (11):
  net: etraxfs_eth: convert SysBus init method to a realize method
  net: etraxfs_eth: add a reset method
  net: lan9118: convert SysBus init method to a realize method
  net: lance: convert SysBus init method to a realize method
  net: milkymist_minimac2: convert SysBus init method to a realize
method
  net: mipsnet: convert SysBus init method to a realize method
  net: opencores_eth: convert SysBus init method to a realize method
  net: smc91c111: convert SysBus init method to a realize method
  net: stellaris_enet: convert SysBus init method to a realize method
  net: stellaris_enet: add a reset method
  net: xgmac: convert SysBus init method to a realize method

David Hildenbrand (16):
  memory-device: fix alignment error message
  memory-device: fix error message when hinted address is too small
  memory-device: improve "range conflicts" error message
  pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug
  memory-device: use memory device terminology in error messages
  memory-device: introduce separate config option
  memory-device: forward errors in get_region_size()/get_plugged_size()
  memory-device: document MemoryDeviceClass
  memory-device: add and use memory_device_get_region_size()
  memory-device: factor out get_memory_region() from pc-dimm
  memory-device: drop get_region_size()
  memory-device: add device class function set_addr()
  memory-device: complete factoring out pre_plug handling
  memory-device: complete factoring out plug handling
  memory-device: complete factoring out unplug handling
  memory-device: trace when pre_plugging/plugging/unplugging

Igor Mammedov (2):
  vl.c deprecate incorrect CPUs topology
  vl:c: make sure that sockets are calculated correctly in '-smp X' case

Li Qiang (1):
  machine: fix a typo

Markus Armbruster (2):
  numa: Fix QMP command set-numa-node error handling
  numa: Clean up error reporting in parse_numa()

Philippe Mathieu-Daudé (12):
  trace-events: Fix copy/paste typo
  hw/timer/sun4v-rtc: Convert from DPRINTF() macro to trace events
  hw/timer/sun4v-rtc: Use DeviceState::realize rather than
SysBusDevice::init
  hw/ssi/xilinx_spi: Use DeviceState::realize rather than
SysBusDevice::init
  hw/sh4/sh_pci: Use DeviceState::realize rather than SysBusDevice::init
  hw/pci-host/bonito: Use DeviceState::realize rather than
SysBusDevice::init
  hw/mips/gt64xxx_pci: Convert gt64120_reset() function into Device
reset method
  hw/mips/gt64xxx_pci: Mark as bridge device
  hw/sparc64/niagara: Model the I/O Bridge with the
'unimplemented_device'
  hw/alpha/typhoon: Remove unuseful code
  hw/hppa/dino: Remove unuseful code
  hw/mips/malta: Remove unuseful code

Zhang Yi (1):
  hostmem-file: fixed the memory leak while get pmem path.

 default-configs/i386-softmmu.mak|   3 +-
 default-configs/ppc64-softmmu.mak   |   3 +-
 default-configs/sparc64-softmmu.mak |   1 -
 qapi/misc.json  |   2 +-
 include/hw/mem/memory-device.h  |  74 +---
 include/hw/mem/pc-dimm.h|  10 +--
 include/sysemu/numa.h   |   1 -
 backends/hostmem-file.c |  10 ++-
 hw/alpha/typhoon.c  |  13 
 hw/core/machine.c   |   2 +-
 hw/hppa/dino.c  |   7 --
 hw/i386/pc.c|   6 +-
 hw/mem/memory-device.c  | 103 ++--
 hw/mem/nvdimm.c |   9 ++-
 hw/mem/pc-dimm.c|  84 ---
 hw/mips/gt64xxx_pci.c   |  18 ++---
 hw/mips/mips_malta.c|  13 
 hw/net/etraxfs_eth.c|  44 
 hw/net/lan9118.c|   9 +--
 hw/net/lance.c  |   8 +--
 hw/net/milkymist-minimac2.c |   9 +--
 hw/net/mipsnet.c|   9 +--
 hw/net/opencores_eth.c  |   8 +--
 hw/net/smc91c111.c  |   8 +--
 hw/net/stellaris_enet.c |  15 ++--
 hw/net/xgmac.c  |   

[libvirt] [PULL 37/45] net: lance: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181001063803.22330-5-...@kaod.org>
Signed-off-by: Eduardo Habkost 
---
 hw/net/lance.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/net/lance.c b/hw/net/lance.c
index a08d5ac6a8..f987b2fd18 100644
--- a/hw/net/lance.c
+++ b/hw/net/lance.c
@@ -97,9 +97,9 @@ static const VMStateDescription vmstate_lance = {
 }
 };
 
-static int lance_init(SysBusDevice *sbd)
+static void lance_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 SysBusPCNetState *d = SYSBUS_PCNET(dev);
 PCNetState *s = >state;
 
@@ -115,7 +115,6 @@ static int lance_init(SysBusDevice *sbd)
 s->phys_mem_read = ledma_memory_read;
 s->phys_mem_write = ledma_memory_write;
 pcnet_common_init(dev, s, _lance_info);
-return 0;
 }
 
 static void lance_reset(DeviceState *dev)
@@ -144,9 +143,8 @@ static Property lance_properties[] = {
 static void lance_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = lance_init;
+dc->realize = lance_realize;
 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
 dc->fw_name = "ethernet";
 dc->reset = lance_reset;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 15/45] hw/hppa/dino: Remove unuseful code

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Message-Id: <20181002212522.23303-12-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/hppa/dino.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/hw/hppa/dino.c b/hw/hppa/dino.c
index 564b938e3a..31e09942b5 100644
--- a/hw/hppa/dino.c
+++ b/hw/hppa/dino.c
@@ -488,17 +488,10 @@ PCIBus *dino_init(MemoryRegion *addr_space,
 return b;
 }
 
-static int dino_pcihost_init(SysBusDevice *dev)
-{
-return 0;
-}
-
 static void dino_pcihost_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-k->init = dino_pcihost_init;
 dc->vmsd = _dino;
 }
 
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 20/45] memory-device: improve "range conflicts" error message

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

Handle id==NULL better and indicate that we are dealing with memory
devices.

Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-4-da...@redhat.com>
Reviewed-by: David Gibson 
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Eduardo Habkost 
---
 hw/mem/memory-device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 7c706fadfc..0624184c40 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -175,7 +175,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, 
const uint64_t *hint,
 if (ranges_overlap(md_addr, md_size, new_addr, size)) {
 if (hint) {
 const DeviceState *d = DEVICE(md);
-error_setg(errp, "address range conflicts with '%s'", d->id);
+error_setg(errp, "address range conflicts with memory device"
+   " id='%s'", d->id ? d->id : "(unnamed)");
 goto out;
 }
 new_addr = QEMU_ALIGN_UP(md_addr + md_size, align);
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 16/45] hw/mips/malta: Remove unuseful code

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Message-Id: <20181002212522.23303-13-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/mips/mips_malta.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 29b90bacf3..c1cf0fe12e 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -1422,23 +1422,10 @@ void mips_malta_init(MachineState *machine)
 pci_vga_init(pci_bus);
 }
 
-static int mips_malta_sysbus_device_init(SysBusDevice *sysbusdev)
-{
-return 0;
-}
-
-static void mips_malta_class_init(ObjectClass *klass, void *data)
-{
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
-
-k->init = mips_malta_sysbus_device_init;
-}
-
 static const TypeInfo mips_malta_device = {
 .name  = TYPE_MIPS_MALTA,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(MaltaState),
-.class_init= mips_malta_class_init,
 };
 
 static void mips_malta_machine_init(MachineClass *mc)
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 26/45] memory-device: add and use memory_device_get_region_size()

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

We will factor out get_memory_region() from pc-dimm to memory device code
soon. Once that is done, get_region_size() can be implemented
generically and essentially be replaced by
memory_device_get_region_size (and work only on get_memory_region()).

We have some users of get_memory_region() (spapr and pc-dimm code) that are
only interested in the size. So let's rework them to use
memory_device_get_region_size() first, then we can factor out
get_memory_region() and eventually remove get_region_size() without
touching the same code multiple times.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-10-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h |  2 ++
 hw/mem/memory-device.c | 13 ++---
 hw/mem/pc-dimm.c   | 10 --
 hw/ppc/spapr.c | 21 +++--
 4 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 0474a3dd11..898df3057d 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -83,5 +83,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const 
uint64_t *hint,
 void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
uint64_t addr);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
+uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
+   Error **errp);
 
 #endif
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index c1e1b81cf2..425830c65c 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -57,10 +57,9 @@ static int memory_device_used_region_size(Object *obj, void 
*opaque)
 if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) {
 const DeviceState *dev = DEVICE(obj);
 const MemoryDeviceState *md = MEMORY_DEVICE(obj);
-const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj);
 
 if (dev->realized) {
-*size += mdc->get_region_size(md, _abort);
+*size += memory_device_get_region_size(md, _abort);
 }
 }
 
@@ -167,7 +166,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, 
const uint64_t *hint,
 uint64_t md_size, md_addr;
 
 md_addr = mdc->get_addr(md);
-md_size = mdc->get_region_size(md, _abort);
+md_size = memory_device_get_region_size(md, _abort);
 
 if (ranges_overlap(md_addr, md_size, new_addr, size)) {
 if (hint) {
@@ -266,6 +265,14 @@ void memory_device_unplug_region(MachineState *ms, 
MemoryRegion *mr)
 memory_region_del_subregion(>device_memory->mr, mr);
 }
 
+uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
+   Error **errp)
+{
+MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+
+return mdc->get_region_size(md, errp);
+}
+
 static const TypeInfo memory_device_info = {
 .name  = TYPE_MEMORY_DEVICE,
 .parent= TYPE_INTERFACE,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 130f78d0de..3e43ec8742 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -161,16 +161,14 @@ static Property pc_dimm_properties[] = {
 static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name,
  void *opaque, Error **errp)
 {
+Error *local_err = NULL;
 uint64_t value;
-MemoryRegion *mr;
-PCDIMMDevice *dimm = PC_DIMM(obj);
-PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(obj);
 
-mr = ddc->get_memory_region(dimm, errp);
-if (!mr) {
+value = memory_device_get_region_size(MEMORY_DEVICE(obj), _err);
+if (local_err) {
+error_propagate(errp, local_err);
 return;
 }
-value = memory_region_size(mr);
 
 visit_type_uint64(v, name, , errp);
 }
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index c078347b66..c08130facb 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3128,12 +3128,10 @@ static void spapr_memory_plug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 Error *local_err = NULL;
 sPAPRMachineState *ms = SPAPR_MACHINE(hotplug_dev);
 PCDIMMDevice *dimm = PC_DIMM(dev);
-PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-MemoryRegion *mr = ddc->get_memory_region(dimm, _abort);
 uint64_t size, addr;
 uint32_t node;
 
-size = memory_region_size(mr);
+size = memory_device_get_region_size(MEMORY_DEVICE(dev), _abort);
 
 pc_dimm_plug(dimm, MACHINE(ms), _err);
 if (local_err) {
@@ -3169,9 +3167,7 @@ static void spapr_memory_pre_plug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 const sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(hotplug_dev);
 sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_dev);
 PCDIMMDevice *dimm = PC_DIMM(dev);
-PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
 Error 

[libvirt] [PULL 43/45] net: stellaris_enet: add a reset method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Peter Maydell 
Cc: qemu-...@nongnu.org
Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181001063803.22330-11-...@kaod.org>
Signed-off-by: Eduardo Habkost 
---
 hw/net/stellaris_enet.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c
index 3ee1e0f8a4..b3375ebb45 100644
--- a/hw/net/stellaris_enet.c
+++ b/hw/net/stellaris_enet.c
@@ -457,8 +457,10 @@ static const MemoryRegionOps stellaris_enet_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void stellaris_enet_reset(stellaris_enet_state *s)
+static void stellaris_enet_reset(DeviceState *dev)
 {
+stellaris_enet_state *s =  STELLARIS_ENET(dev);
+
 s->mdv = 0x80;
 s->rctl = SE_RCTL_BADCRC;
 s->im = SE_INT_PHY | SE_INT_MD | SE_INT_RXER | SE_INT_FOV | SE_INT_TXEMP
@@ -487,8 +489,6 @@ static void stellaris_enet_realize(DeviceState *dev, Error 
**errp)
 s->nic = qemu_new_nic(_stellaris_enet_info, >conf,
   object_get_typename(OBJECT(dev)), dev->id, s);
 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
-
-stellaris_enet_reset(s);
 }
 
 static Property stellaris_enet_properties[] = {
@@ -501,6 +501,7 @@ static void stellaris_enet_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc->realize = stellaris_enet_realize;
+dc->reset = stellaris_enet_reset;
 dc->props = stellaris_enet_properties;
 dc->vmsd = _stellaris_enet;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 12/45] hw/mips/gt64xxx_pci: Mark as bridge device

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

The gt64120 is currently listed as uncategorized device.
Mark it as bridge device.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Peter Maydell 
Reviewed-by: Cédric Le Goater 
Message-Id: <20181002212522.23303-9-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/mips/gt64xxx_pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index dcd1a66329..1cd8aac658 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -1232,6 +1232,7 @@ static void gt64120_class_init(ObjectClass *klass, void 
*data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 dc->reset = gt64120_reset;
 dc->vmsd = _gt64120;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 34/45] net: etraxfs_eth: convert SysBus init method to a realize method

2018-10-18 Thread Eduardo Habkost
From: Cédric Le Goater 

Cc: Edgar E. Iglesias 
Signed-off-by: Cédric Le Goater 
Reviewed-by: Peter Maydell 
Message-Id: <20181001063803.22330-2-...@kaod.org>
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Eduardo Habkost 
---
 hw/net/etraxfs_eth.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c
index a6932432b1..64ab3df1ae 100644
--- a/hw/net/etraxfs_eth.c
+++ b/hw/net/etraxfs_eth.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "net/net.h"
 #include "hw/cris/etraxfs.h"
@@ -584,14 +585,14 @@ static NetClientInfo net_etraxfs_info = {
 .link_status_changed = eth_set_link,
 };
 
-static int fs_eth_init(SysBusDevice *sbd)
+static void etraxfs_eth_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 ETRAXFSEthState *s = ETRAX_FS_ETH(dev);
 
 if (!s->dma_out || !s->dma_in) {
-error_report("Unconnected ETRAX-FS Ethernet MAC");
-return -1;
+error_setg(errp, "Unconnected ETRAX-FS Ethernet MAC");
+return;
 }
 
 s->dma_out->client.push = eth_tx_push;
@@ -611,7 +612,6 @@ static int fs_eth_init(SysBusDevice *sbd)
 
 tdk_init(>phy);
 mdio_attach(>mdio_bus, >phy, s->phyaddr);
-return 0;
 }
 
 static Property etraxfs_eth_properties[] = {
@@ -625,9 +625,8 @@ static Property etraxfs_eth_properties[] = {
 static void etraxfs_eth_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = fs_eth_init;
+dc->realize = etraxfs_eth_realize;
 dc->props = etraxfs_eth_properties;
 /* Reason: pointer properties "dma_out", "dma_in" */
 dc->user_creatable = false;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 33/45] memory-device: trace when pre_plugging/plugging/unplugging

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

Let's trace the address and the id of a memory device when
pre_plugging/plugging/unplugging succeeded.

Trace it when pre_plugging as well as when plugging, so we really know
when a specific address is actually used.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-17-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 hw/mem/memory-device.c | 8 
 hw/mem/pc-dimm.c   | 8 
 hw/mem/trace-events| 5 -
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 30585d6148..7de1ccd497 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -17,6 +17,7 @@
 #include "qemu/range.h"
 #include "hw/virtio/vhost.h"
 #include "sysemu/kvm.h"
+#include "trace.h"
 
 static gint memory_device_addr_sort(gconstpointer a, gconstpointer b)
 {
@@ -269,6 +270,10 @@ void memory_device_pre_plug(MemoryDeviceState *md, 
MachineState *ms,
 goto out;
 }
 mdc->set_addr(md, addr, _err);
+if (!local_err) {
+trace_memory_device_pre_plug(DEVICE(md)->id ? DEVICE(md)->id : "",
+ addr);
+}
 out:
 error_propagate(errp, local_err);
 }
@@ -288,6 +293,7 @@ void memory_device_plug(MemoryDeviceState *md, MachineState 
*ms)
 
 memory_region_add_subregion(>device_memory->mr,
 addr - ms->device_memory->base, mr);
+trace_memory_device_plug(DEVICE(md)->id ? DEVICE(md)->id : "", addr);
 }
 
 void memory_device_unplug(MemoryDeviceState *md, MachineState *ms)
@@ -303,6 +309,8 @@ void memory_device_unplug(MemoryDeviceState *md, 
MachineState *ms)
 g_assert(ms->device_memory);
 
 memory_region_del_subregion(>device_memory->mr, mr);
+trace_memory_device_unplug(DEVICE(md)->id ? DEVICE(md)->id : "",
+   mdc->get_addr(md));
 }
 
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 6c854139a7..0c9b9e8292 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -33,7 +33,6 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState 
*machine,
   const uint64_t *legacy_align, Error **errp)
 {
 Error *local_err = NULL;
-uint64_t addr;
 int slot;
 
 slot = object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP,
@@ -49,13 +48,6 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState 
*machine,
 
 memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
_err);
-if (local_err) {
-goto out;
-}
-
-addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
-_abort);
-trace_mhp_pc_dimm_assigned_address(addr);
 out:
 error_propagate(errp, local_err);
 }
diff --git a/hw/mem/trace-events b/hw/mem/trace-events
index e150dcc497..0f2f278ff2 100644
--- a/hw/mem/trace-events
+++ b/hw/mem/trace-events
@@ -2,4 +2,7 @@
 
 # hw/mem/pc-dimm.c
 mhp_pc_dimm_assigned_slot(int slot) "%d"
-mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
+# hw/mem/memory-device.c
+memory_device_pre_plug(const char *id, uint64_t addr) "id=%s addr=0x%"PRIx64
+memory_device_plug(const char *id, uint64_t addr) "id=%s addr=0x%"PRIx64
+memory_device_unplug(const char *id, uint64_t addr) "id=%s addr=0x%"PRIx64
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 05/45] trace-events: Fix copy/paste typo

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Missed while reviewing 5dd85b4b486.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Peter Maydell 
Reviewed-by: Cédric Le Goater 
Message-Id: <20181002212522.23303-2-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/timer/trace-events | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/timer/trace-events b/hw/timer/trace-events
index fa4213df5b..ca9ad6321a 100644
--- a/hw/timer/trace-events
+++ b/hw/timer/trace-events
@@ -56,7 +56,7 @@ systick_timer_tick(void) "systick reload"
 systick_read(uint64_t addr, uint32_t value, unsigned size) "systick read addr 
0x%" PRIx64 " data 0x%" PRIx32 " size %u"
 systick_write(uint64_t addr, uint32_t value, unsigned size) "systick write 
addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
 
-# hw/char/cmsdk_apb_timer.c
+# hw/timer/cmsdk_apb_timer.c
 cmsdk_apb_timer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB 
timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
 cmsdk_apb_timer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK 
APB timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
 cmsdk_apb_timer_reset(void) "CMSDK APB timer: reset"
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 02/45] vl.c deprecate incorrect CPUs topology

2018-10-18 Thread Eduardo Habkost
From: Igor Mammedov 

-smp [cpus],sockets/cores/threads[,maxcpus] should describe topology
so that total number of logical CPUs [sockets * cores * threads]
would be equal to [maxcpus], however historically we didn't have
such check in QEMU and it is possible to start VM with an invalid
topology.
Deprecate invalid options combination so we can make sure that
the topology VM started with is always correct in the future.
Users with an invalid sockets/cores/threads/maxcpus values should
fix their CLI to make sure that
   [sockets * cores * threads] == [maxcpus]

Signed-off-by: Igor Mammedov 
Reviewed-by: Andrew Jones 
Reviewed-by: Eduardo Habkost 
Message-Id: <1536836762-273036-2-git-send-email-imamm...@redhat.com>
Reviewed-by: Eric Blake 
Signed-off-by: Eduardo Habkost 
---
 vl.c |  7 +++
 qemu-deprecated.texi | 12 
 2 files changed, 19 insertions(+)

diff --git a/vl.c b/vl.c
index 4e25c78bff..027d04c7ca 100644
--- a/vl.c
+++ b/vl.c
@@ -1235,6 +1235,13 @@ static void smp_parse(QemuOpts *opts)
 exit(1);
 }
 
+if (sockets * cores * threads != max_cpus) {
+warn_report("Invalid CPU topology deprecated: "
+"sockets (%u) * cores (%u) * threads (%u) "
+"!= maxcpus (%u)",
+sockets, cores, threads, max_cpus);
+}
+
 smp_cpus = cpus;
 smp_cores = cores;
 smp_threads = threads;
diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
index 11b870c5c1..5d2d7a3588 100644
--- a/qemu-deprecated.texi
+++ b/qemu-deprecated.texi
@@ -86,6 +86,18 @@ for these file types is 'host_cdrom' or 'host_device' as 
appropriate.
 The @option{name} parameter of the @option{-net} option is a synonym
 for the @option{id} parameter, which should now be used instead.
 
+@subsection -smp (invalid topologies) (since 3.1)
+
+CPU topology properties should describe whole machine topology including
+possible CPUs.
+
+However, historically it was possible to start QEMU with an incorrect topology
+where @math{@var{n} <= @var{sockets} * @var{cores} * @var{threads} < 
@var{maxcpus}},
+which could lead to an incorrect topology enumeration by the guest.
+Support for invalid topologies will be removed, the user must ensure
+topologies described with -smp include all possible cpus, i.e.
+  @math{@var{sockets} * @var{cores} * @var{threads} = @var{maxcpus}}.
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 32/45] memory-device: complete factoring out unplug handling

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

With the new memory device functions in place, we can factor out
unplugging of memory devices completely.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Reviewed-by: Eric Auger 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-16-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h |  2 +-
 hw/mem/memory-device.c | 11 +--
 hw/mem/pc-dimm.c   |  5 +
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 53d89dac89..e904e194d5 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -102,7 +102,7 @@ uint64_t get_plugged_memory_size(void);
 void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
 const uint64_t *legacy_align, Error **errp);
 void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
-void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
+void memory_device_unplug(MemoryDeviceState *md, MachineState *ms);
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
Error **errp);
 
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 6569896b7e..30585d6148 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -290,9 +290,16 @@ void memory_device_plug(MemoryDeviceState *md, 
MachineState *ms)
 addr - ms->device_memory->base, mr);
 }
 
-void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr)
+void memory_device_unplug(MemoryDeviceState *md, MachineState *ms)
 {
-/* we expect a previous call to memory_device_get_free_addr() */
+const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+MemoryRegion *mr;
+
+/*
+ * We expect that a previous call to memory_device_pre_plug() succeeded, so
+ * it can't fail at this point.
+ */
+mr = mdc->get_memory_region(md, _abort);
 g_assert(ms->device_memory);
 
 memory_region_del_subregion(>device_memory->mr, mr);
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 647841bcd4..6c854139a7 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -73,13 +73,10 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState 
*machine, Error **errp)
 void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine)
 {
 PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
 MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
   _abort);
-MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
-  _abort);
 
-memory_device_unplug_region(machine, mr);
+memory_device_unplug(MEMORY_DEVICE(dimm), machine);
 vmstate_unregister_ram(vmstate_mr, DEVICE(dimm));
 }
 
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 09/45] hw/sh4/sh_pci: Use DeviceState::realize rather than SysBusDevice::init

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Move from the legacy SysBusDevice::init method to using DeviceState::realize.

Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <20181002212522.23303-6-f4...@amsat.org>
Reviewed-by: Peter Maydell 
Signed-off-by: Eduardo Habkost 
---
 hw/sh4/sh_pci.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/hw/sh4/sh_pci.c b/hw/sh4/sh_pci.c
index 4ec2e35500..379d0685ed 100644
--- a/hw/sh4/sh_pci.c
+++ b/hw/sh4/sh_pci.c
@@ -120,16 +120,15 @@ static void sh_pci_set_irq(void *opaque, int irq_num, int 
level)
 qemu_set_irq(pic[irq_num], level);
 }
 
-static int sh_pci_device_init(SysBusDevice *dev)
+static void sh_pci_device_realize(DeviceState *dev, Error **errp)
 {
-PCIHostState *phb;
-SHPCIState *s;
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+SHPCIState *s = SH_PCI_HOST_BRIDGE(dev);
+PCIHostState *phb = PCI_HOST_BRIDGE(s);
 int i;
 
-s = SH_PCI_HOST_BRIDGE(dev);
-phb = PCI_HOST_BRIDGE(s);
 for (i = 0; i < 4; i++) {
-sysbus_init_irq(dev, >irq[i]);
+sysbus_init_irq(sbd, >irq[i]);
 }
 phb->bus = pci_register_root_bus(DEVICE(dev), "pci",
  sh_pci_set_irq, sh_pci_map_irq,
@@ -143,13 +142,12 @@ static int sh_pci_device_init(SysBusDevice *dev)
  >memconfig_p4, 0, 0x224);
 memory_region_init_alias(>isa, OBJECT(s), "sh_pci.isa",
  get_system_io(), 0, 0x4);
-sysbus_init_mmio(dev, >memconfig_p4);
-sysbus_init_mmio(dev, >memconfig_a7);
+sysbus_init_mmio(sbd, >memconfig_p4);
+sysbus_init_mmio(sbd, >memconfig_a7);
 s->iobr = 0xfe24;
 memory_region_add_subregion(get_system_memory(), s->iobr, >isa);
 
 s->dev = pci_create_simple(phb->bus, PCI_DEVFN(0, 0), "sh_pci_host");
-return 0;
 }
 
 static void sh_pci_host_realize(PCIDevice *d, Error **errp)
@@ -187,9 +185,9 @@ static const TypeInfo sh_pci_host_info = {
 
 static void sh_pci_device_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = sh_pci_device_init;
+dc->realize = sh_pci_device_realize;
 }
 
 static const TypeInfo sh_pci_device_info = {
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 31/45] memory-device: complete factoring out plug handling

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

With the new memory device functions in place, we can factor out
plugging of memory devices completely.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Reviewed-by: Eric Auger 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-15-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h |  3 +--
 hw/mem/memory-device.c | 13 ++---
 hw/mem/pc-dimm.c   |  9 +
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index d92acd2425..53d89dac89 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -101,8 +101,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void);
 uint64_t get_plugged_memory_size(void);
 void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
 const uint64_t *legacy_align, Error **errp);
-void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
-   uint64_t addr);
+void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
Error **errp);
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index aa4ddd5918..6569896b7e 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -273,10 +273,17 @@ out:
 error_propagate(errp, local_err);
 }
 
-void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
-   uint64_t addr)
+void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
 {
-/* we expect a previous call to memory_device_get_free_addr() */
+const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+const uint64_t addr = mdc->get_addr(md);
+MemoryRegion *mr;
+
+/*
+ * We expect that a previous call to memory_device_pre_plug() succeeded, so
+ * it can't fail at this point.
+ */
+mr = mdc->get_memory_region(md, _abort);
 g_assert(ms->device_memory);
 
 memory_region_add_subregion(>device_memory->mr,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index b2959bcf0e..647841bcd4 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -63,17 +63,10 @@ out:
 void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
 {
 PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dimm);
 MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
   _abort);
-MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dimm),
-  _abort);
-uint64_t addr;
-
-addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
-_abort);
 
-memory_device_plug_region(machine, mr, addr);
+memory_device_plug(MEMORY_DEVICE(dimm), machine);
 vmstate_register_ram(vmstate_mr, DEVICE(dimm));
 }
 
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 29/45] memory-device: add device class function set_addr()

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

To be able to factor out address assignment of memory devices, we will
have to read (get_addr()) and write (set_addr()) the address.

We can't use properties for this purpose, as properties are device
specific. E.g. while the address property for a DIMM is called "addr", it
might be called differently (e.g. "memaddr") for other devices.

Especially virtio based memory devices cannot use "addr" as that is already
reserved and used for the address on the bus (for the proxy device).

Also, it might be possible to have memory devices without address
properties (e.g. internal DIMM-like thingies).

In contrast to get_addr(), we expect that set_addr() can fail.

Keep it simple for now for pc-dimm and simply set the static property, that
will fail once realized.

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Reviewed-by: Eric Auger 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-13-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h | 8 
 hw/mem/pc-dimm.c   | 7 +++
 2 files changed, 15 insertions(+)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 9c3398bc4a..ed7cf5bf4b 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -59,6 +59,14 @@ typedef struct MemoryDeviceClass {
  */
 uint64_t (*get_addr)(const MemoryDeviceState *md);
 
+/*
+ * Set the address of the memory device in guest physical memory.
+ *
+ * Called when plugging the memory device to configure the determined
+ * address in guest physical memory.
+ */
+void (*set_addr)(MemoryDeviceState *md, uint64_t addr, Error **errp);
+
 /*
  * Return the amount of memory provided by the memory device currently
  * usable ("plugged") by the VM.
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 47b2e83389..4a15091734 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -236,6 +236,12 @@ static uint64_t pc_dimm_md_get_addr(const 
MemoryDeviceState *md)
 return dimm->addr;
 }
 
+static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
+Error **errp)
+{
+object_property_set_uint(OBJECT(md), addr, PC_DIMM_ADDR_PROP, errp);
+}
+
 static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
   Error **errp)
 {
@@ -286,6 +292,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
 ddc->get_vmstate_memory_region = pc_dimm_get_memory_region;
 
 mdc->get_addr = pc_dimm_md_get_addr;
+mdc->set_addr = pc_dimm_md_set_addr;
 /* for a dimm plugged_size == region_size */
 mdc->get_plugged_size = memory_device_get_region_size;
 mdc->get_memory_region = pc_dimm_md_get_memory_region;
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 01/45] hostmem-file: fixed the memory leak while get pmem path.

2018-10-18 Thread Eduardo Habkost
From: Zhang Yi 

object_get_canonical_path_component() returns a string which
must be freed using g_free().

Reported-by: Peter Maydell 
Signed-off-by: Michael S. Tsirkin 
Signed-off-by: Zhang Yi 
Message-Id: 
<7328fb16c394eaf5d65437d11c2a9343647b6d3d.1535471899.git.yi.z.zh...@linux.intel.com>
Reviewed-by: Eduardo Habkost 
Signed-off-by: Eduardo Habkost 
---
 backends/hostmem-file.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index e64074954f..639c8d4307 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -145,20 +145,26 @@ static void file_memory_backend_set_pmem(Object *o, bool 
value, Error **errp)
 HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
 
 if (host_memory_backend_mr_inited(backend)) {
+char *path = object_get_canonical_path_component(o);
+
 error_setg(errp, "cannot change property 'pmem' of %s '%s'",
object_get_typename(o),
-   object_get_canonical_path_component(o));
+   path);
+g_free(path);
 return;
 }
 
 #ifndef CONFIG_LIBPMEM
 if (value) {
 Error *local_err = NULL;
+char *path = object_get_canonical_path_component(o);
+
 error_setg(_err,
"Lack of libpmem support while setting the 'pmem=on'"
" of %s '%s'. We can't ensure data persistence.",
object_get_typename(o),
-   object_get_canonical_path_component(o));
+   path);
+g_free(path);
 error_propagate(errp, local_err);
 return;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 24/45] memory-device: forward errors in get_region_size()/get_plugged_size()

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

Let's properly forward the errors, so errors from get_region_size() /
get_plugged_size() can be handled.

Users right now call both functions after the device has been realized,
which is will never fail, so it is fine to continue using error_abort.

While at it, remove a leftover error check (suggested by Igor).

Reviewed-by: David Gibson 
Reviewed-by: Igor Mammedov 
Reviewed-by: Eric Auger 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-8-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/memory-device.h | 4 ++--
 hw/mem/memory-device.c | 9 +++--
 hw/mem/pc-dimm.c   | 5 +++--
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 2853b084b5..f02b229837 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -33,8 +33,8 @@ typedef struct MemoryDeviceClass {
 InterfaceClass parent_class;
 
 uint64_t (*get_addr)(const MemoryDeviceState *md);
-uint64_t (*get_plugged_size)(const MemoryDeviceState *md);
-uint64_t (*get_region_size)(const MemoryDeviceState *md);
+uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
+uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
 void (*fill_device_info)(const MemoryDeviceState *md,
  MemoryDeviceInfo *info);
 } MemoryDeviceClass;
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 87369ef2e1..c1e1b81cf2 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -60,7 +60,7 @@ static int memory_device_used_region_size(Object *obj, void 
*opaque)
 const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj);
 
 if (dev->realized) {
-*size += mdc->get_region_size(md);
+*size += mdc->get_region_size(md, _abort);
 }
 }
 
@@ -167,10 +167,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, 
const uint64_t *hint,
 uint64_t md_size, md_addr;
 
 md_addr = mdc->get_addr(md);
-md_size = mdc->get_region_size(md);
-if (*errp) {
-goto out;
-}
+md_size = mdc->get_region_size(md, _abort);
 
 if (ranges_overlap(md_addr, md_size, new_addr, size)) {
 if (hint) {
@@ -234,7 +231,7 @@ static int memory_device_plugged_size(Object *obj, void 
*opaque)
 const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj);
 
 if (dev->realized) {
-*size += mdc->get_plugged_size(md);
+*size += mdc->get_plugged_size(md, _abort);
 }
 }
 
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index f46fb7ada2..130f78d0de 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -234,14 +234,15 @@ static uint64_t pc_dimm_md_get_addr(const 
MemoryDeviceState *md)
 return dimm->addr;
 }
 
-static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md)
+static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
+   Error **errp)
 {
 /* dropping const here is fine as we don't touch the memory region */
 PCDIMMDevice *dimm = PC_DIMM(md);
 const PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(md);
 MemoryRegion *mr;
 
-mr = ddc->get_memory_region(dimm, _abort);
+mr = ddc->get_memory_region(dimm, errp);
 if (!mr) {
 return 0;
 }
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 23/45] memory-device: introduce separate config option

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

Some architectures might support memory devices, while they don't
support DIMM/NVDIMM. So let's
- Rename CONFIG_MEM_HOTPLUG to CONFIG_MEM_DEVICE
- Introduce CONFIG_DIMM and use it similarly to CONFIG NVDIMM

CONFIG_DIMM and CONFIG_NVDIMM require CONFIG_MEM_DEVICE.

Reviewed-by: Igor Mammedov 
Reviewed-by: David Gibson 
Acked-by: David Gibson 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-7-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 default-configs/i386-softmmu.mak  | 3 ++-
 default-configs/ppc64-softmmu.mak | 3 ++-
 qapi/misc.json| 2 +-
 hw/Makefile.objs  | 2 +-
 hw/mem/Makefile.objs  | 4 ++--
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 8c7d4a0fa0..4c1637338b 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -50,7 +50,8 @@ CONFIG_PCI_Q35=y
 CONFIG_APIC=y
 CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
-CONFIG_MEM_HOTPLUG=y
+CONFIG_MEM_DEVICE=y
+CONFIG_DIMM=y
 CONFIG_NVDIMM=y
 CONFIG_ACPI_NVDIMM=y
 CONFIG_PCIE_PORT=y
diff --git a/default-configs/ppc64-softmmu.mak 
b/default-configs/ppc64-softmmu.mak
index b94af6c7c6..f550573782 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -16,4 +16,5 @@ CONFIG_VIRTIO_VGA=y
 CONFIG_XICS=$(CONFIG_PSERIES)
 CONFIG_XICS_SPAPR=$(CONFIG_PSERIES)
 CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM))
-CONFIG_MEM_HOTPLUG=y
+CONFIG_MEM_DEVICE=y
+CONFIG_DIMM=y
diff --git a/qapi/misc.json b/qapi/misc.json
index 3a68af9ca3..9b964644aa 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -2066,7 +2066,7 @@
 #
 # @plugged-memory: size of memory that can be hot-unplugged. This field
 #  is omitted if target doesn't support memory hotplug
-#  (i.e. CONFIG_MEM_HOTPLUG not defined on build time).
+#  (i.e. CONFIG_MEM_DEVICE not defined at build time).
 #
 # Since: 2.11.0
 ##
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index a19c1417ed..58872e27e0 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -33,7 +33,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += vfio/
 devices-dirs-$(CONFIG_SOFTMMU) += virtio/
 devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
 devices-dirs-$(CONFIG_SOFTMMU) += xen/
-devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/
+devices-dirs-$(CONFIG_MEM_DEVICE) += mem/
 devices-dirs-$(CONFIG_SOFTMMU) += smbios/
 devices-dirs-y += core/
 common-obj-y += $(devices-dirs-y)
diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs
index 10be4df2a2..3e2f7c5ca2 100644
--- a/hw/mem/Makefile.objs
+++ b/hw/mem/Makefile.objs
@@ -1,3 +1,3 @@
-common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o
-common-obj-$(CONFIG_MEM_HOTPLUG) += memory-device.o
+common-obj-$(CONFIG_DIMM) += pc-dimm.o
+common-obj-$(CONFIG_MEM_DEVICE) += memory-device.o
 common-obj-$(CONFIG_NVDIMM) += nvdimm.o
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 22/45] memory-device: use memory device terminology in error messages

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

While we rephrased most error messages, we missed these.

Reviewed-by: Dr. David Alan Gilbert 
Reviewed-by: Igor Mammedov 
Reviewed-by: David Gibson 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-6-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 hw/mem/memory-device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 0624184c40..87369ef2e1 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -87,7 +87,7 @@ static void memory_device_check_addable(MachineState *ms, 
uint64_t size,
 memory_device_used_region_size(OBJECT(ms), _region_size);
 if (used_region_size + size > ms->maxram_size - ms->ram_size) {
 error_setg(errp, "not enough space, currently 0x%" PRIx64
-   " in use of total hot pluggable 0x" RAM_ADDR_FMT,
+   " in use of total space for memory devices 0x" RAM_ADDR_FMT,
used_region_size, ms->maxram_size - ms->ram_size);
 return;
 }
@@ -145,12 +145,12 @@ uint64_t memory_device_get_free_addr(MachineState *ms, 
const uint64_t *hint,
 if (hint) {
 new_addr = *hint;
 if (new_addr < address_space_start) {
-error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
+error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" 
PRIx64
"] before 0x%" PRIx64, new_addr, size,
address_space_start);
 return 0;
 } else if ((new_addr + size) > address_space_end) {
-error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
+error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" 
PRIx64
"] beyond 0x%" PRIx64, new_addr, size,
address_space_end);
 return 0;
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 21/45] pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

We're plugging/unplugging a PCDIMMDevice, so directly pass this type
instead of a more generic DeviceState.

Reviewed-by: David Gibson 
Acked-by: David Gibson 
Reviewed-by: Igor Mammedov 
Reviewed-by: Eric Auger 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-5-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 include/hw/mem/pc-dimm.h |  6 +++---
 hw/i386/pc.c |  6 +++---
 hw/mem/pc-dimm.c | 24 +++-
 hw/ppc/spapr.c   |  8 
 4 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index b382eb4303..99cbd54de7 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -79,8 +79,8 @@ typedef struct PCDIMMDeviceClass {
Error **errp);
 } PCDIMMDeviceClass;
 
-void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
+void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
   const uint64_t *legacy_align, Error **errp);
-void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp);
-void pc_dimm_unplug(DeviceState *dev, MachineState *machine);
+void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp);
+void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine);
 #endif
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index cd5029c149..19ace9dadd 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1704,7 +1704,7 @@ static void pc_memory_pre_plug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 return;
 }
 
-pc_dimm_pre_plug(dev, MACHINE(hotplug_dev),
+pc_dimm_pre_plug(PC_DIMM(dev), MACHINE(hotplug_dev),
  pcmc->enforce_aligned_dimm ? NULL : _align, errp);
 }
 
@@ -1716,7 +1716,7 @@ static void pc_memory_plug(HotplugHandler *hotplug_dev,
 PCMachineState *pcms = PC_MACHINE(hotplug_dev);
 bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
 
-pc_dimm_plug(dev, MACHINE(pcms), _err);
+pc_dimm_plug(PC_DIMM(dev), MACHINE(pcms), _err);
 if (local_err) {
 goto out;
 }
@@ -1776,7 +1776,7 @@ static void pc_memory_unplug(HotplugHandler *hotplug_dev,
 goto out;
 }
 
-pc_dimm_unplug(dev, MACHINE(pcms));
+pc_dimm_unplug(PC_DIMM(dev), MACHINE(pcms));
 object_unparent(OBJECT(dev));
 
  out:
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index fb6bcaedc4..f46fb7ada2 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -29,24 +29,24 @@
 
 static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
 
-void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
+void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
   const uint64_t *legacy_align, Error **errp)
 {
-PCDIMMDevice *dimm = PC_DIMM(dev);
 PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
 Error *local_err = NULL;
 MemoryRegion *mr;
 uint64_t addr, align;
 int slot;
 
-slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+slot = object_property_get_int(OBJECT(dimm), PC_DIMM_SLOT_PROP,
_abort);
 slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : 
,
  machine->ram_slots, _err);
 if (local_err) {
 goto out;
 }
-object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, 
_abort);
+object_property_set_int(OBJECT(dimm), slot, PC_DIMM_SLOT_PROP,
+_abort);
 trace_mhp_pc_dimm_assigned_slot(slot);
 
 mr = ddc->get_memory_region(dimm, _err);
@@ -55,7 +55,7 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
 }
 
 align = legacy_align ? *legacy_align : memory_region_get_alignment(mr);
-addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
+addr = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
 _abort);
 addr = memory_device_get_free_addr(machine, !addr ? NULL : , align,
memory_region_size(mr), _err);
@@ -63,38 +63,36 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState 
*machine,
 goto out;
 }
 trace_mhp_pc_dimm_assigned_address(addr);
-object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP,
+object_property_set_uint(OBJECT(dimm), addr, PC_DIMM_ADDR_PROP,
  _abort);
 out:
 error_propagate(errp, local_err);
 }
 
-void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp)
+void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
 {
-PCDIMMDevice *dimm = PC_DIMM(dev);
 PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
 MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
   _abort);
 MemoryRegion *mr = ddc->get_memory_region(dimm, _abort);
 

[libvirt] [PULL 19/45] memory-device: fix error message when hinted address is too small

2018-10-18 Thread Eduardo Habkost
From: David Hildenbrand 

The "at" should actually be a "before".
if (new_addr < address_space_start)
 -> "can't add memory ... before... $address_space_start"

So it looks similar to the other check
} else if ((new_addr + size) > address_space_end)
 -> "can't add memory ... beyond..."

Reviewed-by: Dr. David Alan Gilbert 
Reviewed-by: Igor Mammedov 
Reviewed-by: David Gibson 
Signed-off-by: David Hildenbrand 
Message-Id: <20181005092024.14344-3-da...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 hw/mem/memory-device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 0b52fe2c5e..7c706fadfc 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -146,7 +146,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, 
const uint64_t *hint,
 new_addr = *hint;
 if (new_addr < address_space_start) {
 error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
-   "] at 0x%" PRIx64, new_addr, size, address_space_start);
+   "] before 0x%" PRIx64, new_addr, size,
+   address_space_start);
 return 0;
 } else if ((new_addr + size) > address_space_end) {
 error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 14/45] hw/alpha/typhoon: Remove unuseful code

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Message-Id: <20181002212522.23303-11-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/alpha/typhoon.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index d74b5b55e1..8004afe45b 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -932,23 +932,10 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus 
**isa_bus,
 return b;
 }
 
-static int typhoon_pcihost_init(SysBusDevice *dev)
-{
-return 0;
-}
-
-static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
-{
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
-
-k->init = typhoon_pcihost_init;
-}
-
 static const TypeInfo typhoon_pcihost_info = {
 .name  = TYPE_TYPHOON_PCI_HOST_BRIDGE,
 .parent= TYPE_PCI_HOST_BRIDGE,
 .instance_size = sizeof(TyphoonState),
-.class_init= typhoon_pcihost_class_init,
 };
 
 static void typhoon_iommu_memory_region_class_init(ObjectClass *klass,
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 17/45] machine: fix a typo

2018-10-18 Thread Eduardo Habkost
From: Li Qiang 

Cc: qemu-triv...@nongnu.org
Signed-off-by: Li Qiang 
Message-Id: <20181010161025.34796-1-liq...@163.com>
Reviewed-by: Stefano Garzarella 
Signed-off-by: Eduardo Habkost 
---
 hw/core/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 1987557833..da50ad6de7 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -636,7 +636,7 @@ static void machine_class_init(ObjectClass *oc, void *data)
 machine_get_memory_encryption, machine_set_memory_encryption,
 _abort);
 object_class_property_set_description(oc, "memory-encryption",
-"Set memory encyption object to use", _abort);
+"Set memory encryption object to use", _abort);
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data)
-- 
2.18.0.rc1.1.g3f1ff2140

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


[libvirt] [PULL 11/45] hw/mips/gt64xxx_pci: Convert gt64120_reset() function into Device reset method

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Convert the gt64120_reset() function into a proper Device reset method.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Peter Maydell 
Reviewed-by: Cédric Le Goater 
Message-Id: <20181002212522.23303-8-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/mips/gt64xxx_pci.c | 17 +++--
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 24ad0ad024..dcd1a66329 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -992,9 +992,9 @@ static void gt64120_pci_set_irq(void *opaque, int irq_num, 
int level)
 }
 
 
-static void gt64120_reset(void *opaque)
+static void gt64120_reset(DeviceState *dev)
 {
-GT64120State *s = opaque;
+GT64120State *s = GT64120_PCI_HOST_BRIDGE(dev);
 
 /* FIXME: Malta specific hw assumptions ahead */
 
@@ -1184,16 +1184,6 @@ PCIBus *gt64120_register(qemu_irq *pic)
 return phb->bus;
 }
 
-static int gt64120_init(SysBusDevice *dev)
-{
-GT64120State *s;
-
-s = GT64120_PCI_HOST_BRIDGE(dev);
-
-qemu_register_reset(gt64120_reset, s);
-return 0;
-}
-
 static void gt64120_pci_realize(PCIDevice *d, Error **errp)
 {
 /* FIXME: Malta specific hw assumptions ahead */
@@ -1241,9 +1231,8 @@ static const TypeInfo gt64120_pci_info = {
 static void gt64120_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
 
-sdc->init = gt64120_init;
+dc->reset = gt64120_reset;
 dc->vmsd = _gt64120;
 }
 
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [PULL 08/45] hw/ssi/xilinx_spi: Use DeviceState::realize rather than SysBusDevice::init

2018-10-18 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Move from the legacy SysBusDevice::init method to using DeviceState::realize.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Reviewed-by: Cédric Le Goater 
Message-Id: <20181002212522.23303-5-f4...@amsat.org>
Signed-off-by: Eduardo Habkost 
---
 hw/ssi/xilinx_spi.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/ssi/xilinx_spi.c b/hw/ssi/xilinx_spi.c
index 83585bc8b2..3dae303d5b 100644
--- a/hw/ssi/xilinx_spi.c
+++ b/hw/ssi/xilinx_spi.c
@@ -319,9 +319,9 @@ static const MemoryRegionOps spi_ops = {
 }
 };
 
-static int xilinx_spi_init(SysBusDevice *sbd)
+static void xilinx_spi_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 XilinxSPI *s = XILINX_SPI(dev);
 int i;
 
@@ -344,8 +344,6 @@ static int xilinx_spi_init(SysBusDevice *sbd)
 
 fifo8_create(>tx_fifo, FIFO_CAPACITY);
 fifo8_create(>rx_fifo, FIFO_CAPACITY);
-
-return 0;
 }
 
 static const VMStateDescription vmstate_xilinx_spi = {
@@ -368,9 +366,8 @@ static Property xilinx_spi_properties[] = {
 static void xilinx_spi_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = xilinx_spi_init;
+dc->realize = xilinx_spi_realize;
 dc->reset = xlx_spi_reset;
 dc->props = xilinx_spi_properties;
 dc->vmsd = _xilinx_spi;
-- 
2.18.0.rc1.1.g3f1ff2140

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

[libvirt] [tck PATCH 3/3] double timeout on nwfilter 060-concurrency test

2018-10-18 Thread Laine Stump
The previous timeout of 5 minutes works out okay on 4 core 8 thread
AMD hardware, but isn't enough on, for example, a 2 core virtual
machine running on the same hardware - it takes about 4 minutes on the
former, and 8.5 minutes on the latter. So let's double the timeout to
10 minutes and see if anybody is still complaining.

Signed-off-by: Laine Stump 
---
 scripts/nwfilter/nwfilter_concurrent.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/nwfilter/nwfilter_concurrent.sh 
b/scripts/nwfilter/nwfilter_concurrent.sh
index c42dd78..88ac876 100644
--- a/scripts/nwfilter/nwfilter_concurrent.sh
+++ b/scripts/nwfilter/nwfilter_concurrent.sh
@@ -244,7 +244,7 @@ runTest()
 
   # Test runs for a maximum of 5 minutes
   now=`date +%s`
-  test_end=$(($now + 5 * 60))
+  test_end=$(($now + 10 * 60))
 
   while :;
   do
-- 
2.14.5

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


[libvirt] [tck PATCH 2/3] fix selinux/100-static-relabel-no test

2018-10-18 Thread Laine Stump
This test disables auto-relabeling so that it can test if setting a
user-defined label in the config will work. The problem is that the
disk image used to boot is then not labelled correctly, and qemu can't
open it.

To circumvent this failure (which is *not* of the functionality we're
testing), this patch just temporarily sets SELinux to permissive mode
during the test, then sets it back during cleanup.

Signed-off-by: Laine Stump 
---
 scripts/selinux/100-static-relabel-no.t | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/scripts/selinux/100-static-relabel-no.t 
b/scripts/selinux/100-static-relabel-no.t
index ab52534..733dbf3 100644
--- a/scripts/selinux/100-static-relabel-no.t
+++ b/scripts/selinux/100-static-relabel-no.t
@@ -32,10 +32,14 @@ use Test::More tests => 6;
 use Sys::Virt::TCK;
 use Sys::Virt::TCK::SELinux;
 
+my $selinux_status = "";
 my $tck = Sys::Virt::TCK->new();
 my $conn = eval { $tck->setup(); };
 BAIL_OUT "failed to setup test harness: $@" if $@;
-END { $tck->cleanup if $tck; }
+END {
+system("setenforce", "1") if ($selinux_status eq "Enforcing");
+$tck->cleanup if $tck;
+}
 
 my $info;
 eval {
@@ -58,6 +62,13 @@ SKIP: {
->disk(src => $disk, dst => "vdb", type => "file")
->as_xml;
 
+chomp($selinux_status = `getenforce`);
+diag "selinux is $selinux_status";
+if ($selinux_status eq "Enforcing") {
+diag "Temporarily setting SELinux to Permissive mode";
+system("setenforce", "0");
+}
+
 diag "Creating a new transient domain";
 my $dom;
 ok_domain(sub { $dom = $conn->create_domain($xml) }, "created transient 
domain object");
-- 
2.14.5

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


[libvirt] [tck PATCH 1/3] reduce required libvirt version in rpm spec

2018-10-18 Thread Laine Stump
Some distros where we want to run libvirt-tck have stock libvirt
versions lower than 4.4.0 (e.g. Fedora 28 has libvirt-4.1.0, and RHEL7
has libvirt-3.9.0). Reduce the version in the specfile Requires: so
that we can get the tck installed without needing to upgrade to some
newer unofficial libvirt build.

Signed-off-by: Laine Stump 
---
 perl-Sys-Virt-TCK.spec.PL | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/perl-Sys-Virt-TCK.spec.PL b/perl-Sys-Virt-TCK.spec.PL
index b91a7e7..6756f0d 100644
--- a/perl-Sys-Virt-TCK.spec.PL
+++ b/perl-Sys-Virt-TCK.spec.PL
@@ -34,7 +34,7 @@ License: GPLv2
 Source: http://libvirt.org/sources/tck/%{appname}-v%{version}.tar.gz
 Url: http://libvirt.org/
 Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
-Requires: libvirt >= 4.4.0
+Requires: libvirt >= 3.9.0
 %if 0%{?fedora} || 0%{?rhel} > 7
 BuildRequires: perl-interpreter
 BuildRequires: perl-generators
-- 
2.14.5

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


[libvirt] [tck PATCH 0/3] a few minor TCK bugfixes

2018-10-18 Thread Laine Stump
Laine Stump (3):
  reduce required libvirt version in rpm spec
  fix selinux/100-static-relabel-no test
  double timeout on nwfilter 060-concurrency test

 perl-Sys-Virt-TCK.spec.PL   |  2 +-
 scripts/nwfilter/nwfilter_concurrent.sh |  2 +-
 scripts/selinux/100-static-relabel-no.t | 13 -
 3 files changed, 14 insertions(+), 3 deletions(-)

-- 
2.14.5

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


Re: [libvirt] [PATCH v4 2/5] libxl: add support for PVH

2018-10-18 Thread Marek Marczykowski-Górecki
On Thu, Oct 18, 2018 at 11:08:34AM -0600, Jim Fehlig wrote:
> On 10/17/18 12:59 PM, Marek Marczykowski-Górecki wrote:
> > On Sat, Oct 13, 2018 at 08:46:19AM -0600, Jim Fehlig wrote:
> > > I had some couch time at the start of the weekend and was finally able to
> > > try using this series with virt-install. As it turns out, reporting
> > > duplicate  blocks for  'xen' is not quite right. Instead 
> > > we
> > > will want to report the additional  under the existing 'xen'
> > >  blocks.
> > 
> > Is that virt-install limitation? In that case, IMO virt-install should
> > be fixed, instead of changing capabilities xml to match its limitations.
> 
> Perhaps it is a virt-install limitation, but my suggestion was based more on
> how the qemu driver reports the different machines
> 
> 
>   hvm
>   
> 64
> /usr/bin/qemu-system-x86_64
> pc-i440fx-3.0
> pc-q35-3.0
> ...
>   
> 
> 
> Compare that with reporting PV and PVH in different  blocks, where
> the  and  are the same. It seems confusing from a consumers
> POV
> 
> 
>   xen
>   
> 64
> /usr/bin/qemu-system-x86_64
> xenpv
>   
> 
> 
> 
>   xen
>   
> 64
> /usr/bin/qemu-system-x86_64
> xenpvh
>   
> 
> 
> How should a consumer interpret that? Is the machine for os_type=xen,
> arch=x86_64 a xenpv or a xenpvh?

I don't see a problem - each guest block represent set of possible
configurations. Given the current structure, you could also ask "is
the os_type for arch=x86_64 a xen or a hvm?". Both are valid, with
possibly different set of features available. And the same goes for
xenpv and xenpvh machines.
Actually, I see qemu had similar problem as we have now with some features
being specific to some machine value - maxCpus. And as solution, it was
put in machine's attributes. But I think this approach is short-sighted.

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?


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

Re: [libvirt] [PATCH v4 2/5] libxl: add support for PVH

2018-10-18 Thread Jim Fehlig

On 10/17/18 12:59 PM, Marek Marczykowski-Górecki wrote:

On Sat, Oct 13, 2018 at 08:46:19AM -0600, Jim Fehlig wrote:

I had some couch time at the start of the weekend and was finally able to
try using this series with virt-install. As it turns out, reporting
duplicate  blocks for  'xen' is not quite right. Instead we
will want to report the additional  under the existing 'xen'
 blocks.


Is that virt-install limitation? In that case, IMO virt-install should
be fixed, instead of changing capabilities xml to match its limitations.


Perhaps it is a virt-install limitation, but my suggestion was based more on how 
the qemu driver reports the different machines



  hvm
  
64
/usr/bin/qemu-system-x86_64
pc-i440fx-3.0
pc-q35-3.0
...
  


Compare that with reporting PV and PVH in different  blocks, where the 
 and  are the same. It seems confusing from a consumers POV



  xen
  
64
/usr/bin/qemu-system-x86_64
xenpv
  



  xen
  
64
/usr/bin/qemu-system-x86_64
xenpvh
  


How should a consumer interpret that? Is the machine for os_type=xen, 
arch=x86_64 a xenpv or a xenpvh?


Regards,
Jim

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

Re: [libvirt] [PATCH v6 09/13] conf: Allocate/release 'uid' and 'fid' in PCI address

2018-10-18 Thread Christian Borntraeger


On 10/18/2018 05:44 PM, Andrea Bolognani wrote:
> On Thu, 2018-10-18 at 15:13 +0800, Yi Min Zhao wrote:
>> 在 2018/10/17 下午10:30, Andrea Bolognani 写道:
>>> On Tue, 2018-10-16 at 11:28 +0800, Yi Min Zhao wrote:
 I think this would make things complex. If either PCI address or
 zPCI address exists, we have to do more checks for calling
 virDomainPCIAddressReserveAddr(). And there are amounts of
 code calling ***IsWanted() to call ***ReserveNext***(). I think
 keeping them separately is better.
>>>
>>> Again, I might be missing something because I haven't actually tried
>>> implementing any of this, but at least from the theoretical point of
>>> view I don't see how keeping them separate would make things simpler:
>>> if anything, it seems to me like it would make them more complicated
>>> for the calling code because now you have to worry about the PCI
>>> address extensions *in addition* to the PCI address itself.
>>
>> For example, during collection stage, checking both PCI address and 
>> extension address
>> is requried, and still need to separately do some additional checks for 
>> PCI address if it
>> is present, at last in reserving addr function we still check if PCI 
>> normal address or
>> extension address exists to separately reserve present one. So that we 
>> have to do the
>> check on the same condition repetively. If you don't have strong 
>> opposition, I want to
>> send the new version ASAP.
> 
> So I gave an half-hearted stab at implementing my own suggestion
> today, and quite unsurprisingly I have gained more sympathy for your
> argument in the process :)
> 
> The main problem I see is that, as you noticed, we have a lot of
> calls to IsWanted(), IsPresent(), ReserveAddr() and ReserveNextAddr()
> where really we should be using EnsureAddr() pretty much all of the
> time and hide most of the details from the drivers, which in turn
> would make it easier to change them in a transparent manner.
> 
> Another big problem, which I highlighted in the past, is that the
> current API was not designed with the idea that PCI addresses could
> have "parts" in mind, and so it's not nuanced enough: if I call
> IsEmpty() on and address where the PCI part itself has been filled
> in but the zPCI part hasn't, or vice versa, what should I get back?
> The answer is probably that, after we've made sure those functions
> are used as little as possible thanks to the changes outlined above,
> we should replace them with better named alternatives.
> 
> Of course it would be entirely unfair to ask you to perform such
> a massive refactoring before your series can be considered for
> inclusion, so at this point I'm okay with merging it and cleaning
> up the pre-existing mess afterwards.
> 
> There's still the question of whether Dan is now okay with the XML
> structure as currently implemented; assuming that's the case, it
> would be great if Laine could also take a quick look at the series
> before it's pushed.


As I said before, I think the current XML is the right variant. This is
exactly how QEMU implements it (have a real classic pci bus naming scheme
augmented with some additional data named uid/fid).
So having an zcpi name space (instead of a pci one) would be wrong.

Daniel, having said this, are you ok with the current variant?

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

Re: [libvirt] [PATCH] libvirtd: fix potential deadlock when starting vm

2018-10-18 Thread John Ferlan
[...]

>>
>> The one thing I have forgotten or perhaps I should say struck me -
>> should this code use virCondWaitUntil or would it just not matter?
>>
>> Let's say 10 devices were added and on the 10th one we had this issue,
>> set dataReady to false, but then didn't get another udev device ready
>> event for "a while" leaving that 10th one in limbo until such time a new
>> device was available (e.g. udevEventHandleCallback is called by udev).
> 
> Can you be more specific on how we could utilize virCondWaitUntil? Because the
> way I see it, it wouldn't help us in either of the cases because the problem
> isn't the thread waiting to be woken up to process an event rather it's the
> recvmsg syscall in libudev which would cause the issue on old CentOS.
> Looking at your example, if you put virCondWaitUntil in the !device 
> conditional
> path, how would that prevent us to hang after processing the last device if we
> never got a chance to even hit the !device code path, since we kept getting
> legitimate events until the last device where we got several events for a
> single piece of data? It very well might be the jetlag speaking for me, but I
> just don't see it in your example.
> 
> Erik
> 

I guess it was the "getting of legitimate events" that I couldn't recall
the exact workings. My "theory" was we got a group of 10 devices, failed
on the last one, and didn't get another call for let's say hours. Then
we have this device in limbo just because udev told us too soon an we
acted, but the scheduler had other ideas vis-a-vis filling in the
@device.  I'm fine with things as they are still.

More details if you care to read... First, I think the theory of
thinking about using Until processing works better than the actual
practice of coding it - Until would requiring using virTimeMillisNow
which can fail so we need to account for that...

My general thought was without writing a lick of code was:

bool timedWait = false;
int rc;

...

while (!priv->dataReady && !priv->threadQuit) {

errno = 0;
if (!timedWait)
rc = virCondWait(...)
else
rc = virCondWaitUntil(...);

if (rc < 0 && errno != ETIMEDOUT) {
virReportSystemError ...
}

timedWait = false;

...

if (!device) {
...
virObjectLock(priv);
priv->dataReady = false;
virObjectUnlock(priv);
timedWait = true;
...


IOW: Only use the timedWait when/if !device caused the "continue;". I
also note now that the virCondWait error check doesn't check < 0, just
that the return is not 0... Maybe that was copied from virFDStreamThread
since other callers check < 0.

Once I started writing code I realized the virTimeMillisNow issue, so
then things would become:

errno = 0;
if (timedWait) {
/* If we fail this, then just use virCondWait */
if (virTimeMillisNow() < 0) {
timedWait = false;
} else {
when = now + 1000ull;
rc = virCondWait(>threadCond,
 >parent.lock,
 when);
}
}

if (!timedWait)
rc = virCondWait(>threadCond, >parent.lock);

if (rc < 0 && errno != ETIMEDOUT) {

Much uglier and scarier than I first thought.

John

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


Re: [libvirt] [PATCH v6 09/13] conf: Allocate/release 'uid' and 'fid' in PCI address

2018-10-18 Thread Andrea Bolognani
On Thu, 2018-10-18 at 15:13 +0800, Yi Min Zhao wrote:
> 在 2018/10/17 下午10:30, Andrea Bolognani 写道:
> > On Tue, 2018-10-16 at 11:28 +0800, Yi Min Zhao wrote:
> > > I think this would make things complex. If either PCI address or
> > > zPCI address exists, we have to do more checks for calling
> > > virDomainPCIAddressReserveAddr(). And there are amounts of
> > > code calling ***IsWanted() to call ***ReserveNext***(). I think
> > > keeping them separately is better.
> > 
> > Again, I might be missing something because I haven't actually tried
> > implementing any of this, but at least from the theoretical point of
> > view I don't see how keeping them separate would make things simpler:
> > if anything, it seems to me like it would make them more complicated
> > for the calling code because now you have to worry about the PCI
> > address extensions *in addition* to the PCI address itself.
> 
> For example, during collection stage, checking both PCI address and 
> extension address
> is requried, and still need to separately do some additional checks for 
> PCI address if it
> is present, at last in reserving addr function we still check if PCI 
> normal address or
> extension address exists to separately reserve present one. So that we 
> have to do the
> check on the same condition repetively. If you don't have strong 
> opposition, I want to
> send the new version ASAP.

So I gave an half-hearted stab at implementing my own suggestion
today, and quite unsurprisingly I have gained more sympathy for your
argument in the process :)

The main problem I see is that, as you noticed, we have a lot of
calls to IsWanted(), IsPresent(), ReserveAddr() and ReserveNextAddr()
where really we should be using EnsureAddr() pretty much all of the
time and hide most of the details from the drivers, which in turn
would make it easier to change them in a transparent manner.

Another big problem, which I highlighted in the past, is that the
current API was not designed with the idea that PCI addresses could
have "parts" in mind, and so it's not nuanced enough: if I call
IsEmpty() on and address where the PCI part itself has been filled
in but the zPCI part hasn't, or vice versa, what should I get back?
The answer is probably that, after we've made sure those functions
are used as little as possible thanks to the changes outlined above,
we should replace them with better named alternatives.

Of course it would be entirely unfair to ask you to perform such
a massive refactoring before your series can be considered for
inclusion, so at this point I'm okay with merging it and cleaning
up the pre-existing mess afterwards.

There's still the question of whether Dan is now okay with the XML
structure as currently implemented; assuming that's the case, it
would be great if Laine could also take a quick look at the series
before it's pushed.

-- 
Andrea Bolognani / Red Hat / Virtualization

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

Re: [libvirt] [PATCH] libvirt: add daemon itself as shutdown reason

2018-10-18 Thread John Ferlan



On 10/17/18 4:16 AM, Nikolay Shirokovskiy wrote:
> 
> 
> On 16.10.2018 15:48, John Ferlan wrote:
>>
>>
>> On 10/8/18 7:21 AM, Nikolay Shirokovskiy wrote:
>>> Let's introduce shutdown reason "daemon" which means we have to
>>> kill running domain ourselves as the best action we can take at
>>> that moment. Failure to pick up domain on daemon restart is
>>> one example of such case. Using reason "crashed" is a bit misleading
>>> as it is used when qemu is actually crashed or qemu destroyed on
>>> guest panic as result of user choice that is the problem was
>>> in qemu/guest itself. So I propose to use "crashed" only for
>>> qemu side issues and introduce "daemon" when we have to kill the qemu
>>> for good.
>>
>> How about (although reading below may shed some more context):
>>
>> This patch introduces a new shutdown reason "daemon" in order
>> to indicate that the daemon needed to force shutdown the domain
>> as the best course of action to take at the moment.
>>
>> This action would occur during Reconnect processing when it's
>> determined that either the QEMU monitor no longer exists for
>> some unknown reason or creation of a thread to reconnect the
>> domain failed.
> 
> Mostly I'm fine with this one except "monitor no longer exists"
> is condition for reason "crashed" or "unknown" (Martin's contribution)
> 
>>
>>>
>>> There is another example where "daemon" will be useful. If we can
>>> not reboot domain we kill it and got "crashed" reason now. Looks
>>> like good candidate for "daemon" reason.
>>
>> If you feel this way, then a followup patch could/should be posted;
>> otherwise, this'll be lost to commit message heaven where all good ideas
>> go to die ;-).
> 
> Sure!
> 
>>
>>>
>>> Signed-off-by: Nikolay Shirokovskiy 
>>> ---
>>>  include/libvirt/libvirt-domain.h |  1 +
>>>  src/conf/domain_conf.c   |  3 ++-
>>>  src/qemu/qemu_process.c  | 11 ---
>>>  tools/virsh-domain-monitor.c |  3 ++-
>>>  4 files changed, 9 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/include/libvirt/libvirt-domain.h 
>>> b/include/libvirt/libvirt-domain.h
>>> index fdd2d6b..11fdab5 100644
>>> --- a/include/libvirt/libvirt-domain.h
>>> +++ b/include/libvirt/libvirt-domain.h
>>> @@ -145,6 +145,7 @@ typedef enum {
>>>  VIR_DOMAIN_SHUTOFF_FAILED = 6,  /* domain failed to start */
>>>  VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT = 7, /* restored from a snapshot 
>>> which was
>>> * taken while domain was 
>>> shutoff */
>>> +VIR_DOMAIN_SHUTOFF_DAEMON = 8,  /* daemon have to kill domain */
>>
>> s/have to/decides to/
>>
>>>  # ifdef VIR_ENUM_SENTINELS
>>>  VIR_DOMAIN_SHUTOFF_LAST
>>>  # endif
>>> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>>> index 9911d56..e441723 100644
>>> --- a/src/conf/domain_conf.c
>>> +++ b/src/conf/domain_conf.c
>>> @@ -779,7 +779,8 @@ VIR_ENUM_IMPL(virDomainShutoffReason, 
>>> VIR_DOMAIN_SHUTOFF_LAST,
>>>"migrated",
>>>"saved",
>>>"failed",
>>> -  "from snapshot")
>>> +  "from snapshot",
>>> +  "daemon")
>>>  
>>>  VIR_ENUM_IMPL(virDomainCrashedReason, VIR_DOMAIN_CRASHED_LAST,
>>>"unknown",
>>> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
>>> index e9c7618..c4bc9ca 100644
>>> --- a/src/qemu/qemu_process.c
>>> +++ b/src/qemu/qemu_process.c
>>> @@ -7988,15 +7988,12 @@ qemuProcessReconnect(void *opaque)
>>>  /* We can't get the monitor back, so must kill the VM
>>>   * to remove danger of it ending up running twice if
>>>   * user tries to start it again later
>>
>> Since we're changing anyway, let's put the stop there, e.g.
>> "s/later/later./"
>>
>>> - * If we couldn't get the monitor since QEMU supports
>>> - * no-shutdown, we can safely say that the domain
>>> - * crashed ... */
>>> -state = VIR_DOMAIN_SHUTOFF_CRASHED;
>>> -/* If BeginJob failed, we jumped here without a job, let's hope 
>>> another
>>> + * If BeginJob failed, we jumped here without a job, let's hope 
>>> another
>>>   * thread didn't have a chance to start playing with the domain yet
>>>   * (it's all we can do anyway).
>>>   */
>>> -qemuProcessStop(driver, obj, state, QEMU_ASYNC_JOB_NONE, 
>>> stopFlags);
>>> +qemuProcessStop(driver, obj, VIR_DOMAIN_SHUTOFF_DAEMON,
>>> +QEMU_ASYNC_JOB_NONE, stopFlags);
>>>  }
>>>  goto cleanup;
>>>  }
>>> @@ -8035,7 +8032,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
>>>   * is no thread that could be doing anything else with the same 
>>> domain
>>>   * object.
>>>   */
>>> -qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED,
>>> +qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_DAEMON,
>>>  QEMU_ASYNC_JOB_NONE, 0);
>>>  

[libvirt] [PATCH] qemu: Restore lost shutdown reason

2018-10-18 Thread John Ferlan
When qemuProcessReconnectHelper was introduced (commit d38897a5d)
reconnection failure used VIR_DOMAIN_SHUTOFF_FAILED; however, that
was changed in commit bda2f17d to either VIR_DOMAIN_SHUTOFF_CRASHED
or VIR_DOMAIN_SHUTOFF_UNKNOWN.

When QEMU_CAPS_NO_SHUTDOWN checking was removed in commit fe35b1ad6
the conditional state was just left at VIR_DOMAIN_SHUTOFF_CRASHED.

Restore the logic adjustment using the same conditions as command
line building and alter the comment to describe the reasoning.

Signed-off-by: John Ferlan 
---

 This was "discovered" while reviewing Nikolay's patch related
 to adding "DAEMON" as the shutdown reason:

https://www.redhat.com/archives/libvir-list/2018-October/msg00493.html

 While working through the iterations of that - figured I'd at
 least post this.


 src/qemu/qemu_process.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3955eda17c..4a39111d51 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7985,11 +7985,16 @@ qemuProcessReconnect(void *opaque)
 if (virDomainObjIsActive(obj)) {
 /* We can't get the monitor back, so must kill the VM
  * to remove danger of it ending up running twice if
- * user tries to start it again later
- * If we couldn't get the monitor since QEMU supports
- * no-shutdown, we can safely say that the domain
- * crashed ... */
-state = VIR_DOMAIN_SHUTOFF_CRASHED;
+ * user tries to start it again later.
+ *
+ * If we cannot get to the monitor when the QEMU command
+ * line used -no-shutdown, then we can safely say that the
+ * domain crashed; otherwise we don't really know. */
+if (priv->monJSON && priv->allowReboot == VIR_TRISTATE_BOOL_YES)
+state = VIR_DOMAIN_SHUTOFF_CRASHED;
+else
+state = VIR_DOMAIN_SHUTOFF_UNKNOWN;
+
 /* If BeginJob failed, we jumped here without a job, let's hope another
  * thread didn't have a chance to start playing with the domain yet
  * (it's all we can do anyway).
-- 
2.17.2

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


[libvirt] [PATCH] virFileInData: Preserve errno on error

2018-10-18 Thread Michal Privoznik
The virFileInData() function should return to the caller if the
current position the passed file is in is a data section or a
hole (and also how long the current section is). At any rate,
upon return from this function (be it successful or not) the
original position in the file is restored. This may mess up with
errno which might have been set earlier. Save the errno into a
local variable so it can be restored for the caller's sake.

Signed-off-by: Michal Privoznik 
---
 src/util/virfile.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index e09992e41a..f6f01ec1e1 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -4072,11 +4072,18 @@ virFileInData(int fd,
 ret = 0;
  cleanup:
 /* At any rate, reposition back to where we started. */
-if (cur != (off_t) -1 &&
-lseek(fd, cur, SEEK_SET) == (off_t) -1) {
-virReportSystemError(errno, "%s",
- _("unable to restore position in file"));
-ret = -1;
+if (cur != (off_t) -1) {
+int theerrno = errno;
+
+if (lseek(fd, cur, SEEK_SET) == (off_t) -1) {
+virReportSystemError(errno, "%s",
+ _("unable to restore position in file"));
+ret = -1;
+if (theerrno == 0)
+theerrno = errno;
+}
+
+errno = theerrno;
 }
 return ret;
 }
-- 
2.18.1

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


[libvirt] [PATCH] virfile: Take symlink into account in virFileIsSharedFixFUSE

2018-10-18 Thread Michal Privoznik
https://bugzilla.redhat.com/show_bug.cgi?id=1640465

Weirdly enough, there can be symlinks in the path we are trying
to fix. If it is the case our clever algorithm that finds matches
against mount table won't work. Canonicalize path at the
beginning then.

Signed-off-by: Michal Privoznik 
---
 cfg.mk  |  2 +-
 src/util/virfile.c  | 17 ++---
 tests/virfilemock.c | 33 -
 tests/virfiletest.c |  1 +
 4 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 4790d0b7e7..d0183c02ff 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1229,7 +1229,7 @@ exclude_file_name_regexp--sc_prohibit_select = \
^cfg\.mk$$
 
 exclude_file_name_regexp--sc_prohibit_canonicalize_file_name = \
-  ^cfg\.mk$$
+  ^(cfg\.mk|tests/virfilemock\.c)$$
 
 exclude_file_name_regexp--sc_prohibit_raw_allocation = \
   
^(docs/hacking\.html\.in|src/util/viralloc\.[ch]|examples/.*|tests/(securityselinuxhelper|(vircgroup|nss)mock|commandhelper)\.c|tools/wireshark/src/packet-libvirt\.c)$$
diff --git a/src/util/virfile.c b/src/util/virfile.c
index e09992e41a..4747a26ad3 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3473,9 +3473,19 @@ virFileIsSharedFixFUSE(const char *path,
 char mntbuf[1024];
 char *mntDir = NULL;
 char *mntType = NULL;
+char *canonPath = NULL;
 size_t maxMatching = 0;
 int ret = -1;
 
+if (!(canonPath = virFileCanonicalizePath(path))) {
+virReportSystemError(errno,
+ _("unable to canonicalize %s"),
+ path);
+return -1;
+}
+
+VIR_DEBUG("Path %s after canonicalization %s", path, canonPath);
+
 if (!(f = setmntent(PROC_MOUNTS, "r"))) {
 virReportSystemError(errno,
  _("Unable to open %s"),
@@ -3487,7 +3497,7 @@ virFileIsSharedFixFUSE(const char *path,
 const char *p;
 size_t len = strlen(mb.mnt_dir);
 
-if (!(p = STRSKIP(path, mb.mnt_dir)))
+if (!(p = STRSKIP(canonPath, mb.mnt_dir)))
 continue;
 
 if (*(p - 1) != '/' && *p != '/' && *p != '\0')
@@ -3504,13 +3514,14 @@ virFileIsSharedFixFUSE(const char *path,
 }
 
 if (STREQ_NULLABLE(mntType, "fuse.glusterfs")) {
-VIR_DEBUG("Found gluster FUSE mountpoint=%s for path=%s. "
-  "Fixing shared FS type", mntDir, path);
+VIR_DEBUG("Found gluster FUSE mountpoint=%s for canonPath=%s. "
+  "Fixing shared FS type", mntDir, canonPath);
 *f_type = GFS2_MAGIC;
 }
 
 ret = 0;
  cleanup:
+VIR_FREE(canonPath);
 VIR_FREE(mntType);
 VIR_FREE(mntDir);
 endmntent(f);
diff --git a/tests/virfilemock.c b/tests/virfilemock.c
index 822c757380..ae5c8d025a 100644
--- a/tests/virfilemock.c
+++ b/tests/virfilemock.c
@@ -28,11 +28,14 @@
 #endif
 
 #include "virmock.h"
+#include "virstring.h"
+#include "viralloc.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
 static FILE *(*real_setmntent)(const char *filename, const char *type);
 static int (*real_statfs)(const char *path, struct statfs *buf);
+static char *(*real_canonicalize_file_name)(const char *path);
 
 
 static void
@@ -43,6 +46,7 @@ init_syms(void)
 
 VIR_MOCK_REAL_INIT(setmntent);
 VIR_MOCK_REAL_INIT(statfs);
+VIR_MOCK_REAL_INIT(canonicalize_file_name);
 }
 
 
@@ -94,6 +98,7 @@ statfs_mock(const char *mtab,
 FILE *f;
 struct mntent mb;
 char mntbuf[1024];
+char *canonPath = NULL;
 int ret = -1;
 
 if (!(f = real_setmntent(mtab, "r"))) {
@@ -101,10 +106,16 @@ statfs_mock(const char *mtab,
 return -1;
 }
 
+/* We don't need to do this in callers because real statfs(2)
+ * does that for us. However, in mocked implementation we
+ * need to do this. */
+if (!(canonPath = canonicalize_file_name(path)))
+return -1;
+
 while (getmntent_r(f, , mntbuf, sizeof(mntbuf))) {
 int ftype;
 
-if (STRNEQ(mb.mnt_dir, path))
+if (STRNEQ(mb.mnt_dir, canonPath))
 continue;
 
 if (STREQ(mb.mnt_type, "nfs") ||
@@ -136,6 +147,7 @@ statfs_mock(const char *mtab,
 }
 
 endmntent(f);
+VIR_FREE(canonPath);
 return ret;
 }
 
@@ -152,3 +164,22 @@ statfs(const char *path, struct statfs *buf)
 
 return real_statfs(path, buf);
 }
+
+
+char *
+canonicalize_file_name(const char *path)
+{
+if (getenv("LIBVIRT_MTAB")) {
+const char *p;
+char *ret;
+
+if ((p = STRSKIP(path, "/some/symlink")))
+ignore_value(virAsprintfQuiet(, "/gluster%s", p));
+else
+ignore_value(VIR_STRDUP_QUIET(ret, path));
+
+return ret;
+}
+
+return real_canonicalize_file_name(path);
+}
diff --git a/tests/virfiletest.c b/tests/virfiletest.c
index 1f2be74c8d..f7b263f2e9 100644
--- a/tests/virfiletest.c
+++ b/tests/virfiletest.c
@@ -456,6 +456,7 @@ mymain(void)
 DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", false);
 

Re: [libvirt] [PATCH] libvirtd: fix potential deadlock when starting vm

2018-10-18 Thread Erik Skultety
On Thu, Oct 18, 2018 at 10:16:19AM -0400, John Ferlan wrote:
>
>
> On 10/18/18 8:23 AM, Erik Skultety wrote:
> > On Tue, Oct 16, 2018 at 05:57:17PM -0400, John Ferlan wrote:
> >>
> >>
> >> On 10/11/18 4:13 AM, Bingsong Si wrote:
> >>> On CentOS 6, udev_monitor_receive_device will block until the socket 
> >>> becomes
> >>
> >> Is this really CentOS6 only or just where you've seen it?
> >>
> >>> readable, udevEventHandleThread will hold the lock all the time and
> >>> udevEventHandleCallback hard to get the lock, will block the event poll.
> >>> To fix this, set dataReady to false after receive an udev event.
> >>>
> >>> Signed-off-by: Bingsong Si 
> >>> ---
> >>>  src/node_device/node_device_udev.c | 5 +
> >>>  1 file changed, 1 insertion(+), 4 deletions(-)
> >>>
> >>
> >> I've CC'd Erik since he wrote and perhaps remembers all the "gotchas" he
> >> discovered in the udev callback code.
> >>
> >> I wonder if this has to do with the EAGAIN and EWOULDBLOCK @errno checks
> >> done in the !device loop that are different in "older" (much older) code.
> >>
> >> Although I have this very vague recollection that there was some problem
> >> with centos6 that was fixed by some OS patch.  Hopefully Erik remembers
> >> (and maybe we should log it in the code at this point ;-)) - I did do
> >> some searching, but came up empty.
> >
> > Remembering a year old issue, let me tell you, my head hurts :) (and we 
> > probably
> > should put a note somewhere, so that we don't have to dig out dinosaurs
> > again)...the only thing I remember is that there was a reason why I did 
> > things
> > this way and not the way this patch is proposing, and indeed I then found 
> > this:
> >
> > https://www.redhat.com/archives/libvir-list/2017-September/msg00683.html
> >
> > TL;DR:
> > The scheduler comes into play here. The problem I had was that the event 
> > loop
> > could be scheduled (and it in fact was) earlier than the handler thread 
> > here.
> > What that essentially means is that by the time the thread actually handled 
> > the
> > event and read the data from the monitor, the event loop fired the very same
> > event, simply because the data hadn't been retrieved from the socket at that
> > point yet.
> > This was mainly connected to the design flaw of that specific version of 
> > patch
> > series. With the current design, setting dataReady immediately after 
> > reading the
> > data or after encoutering the first EAGAIN doesn't matter and the scheduler
> > wouldn't have an impact either way, that's true. However, with CentOS 6 the
> > scheduler would still come into play even with your patch (it was much more
> > noticeable the more devices you had in/added into the system), you'd still
> > remain blocking on the recv call. The correct fix would be more
> > complex and IIRC it would involve pulling the monitor object out of the 
> > private
> > data lockable object and would need to be guarded by a separate lock (I 
> > haven't
> > thought about it much though, so I might be wrong).
> >
> > That said, we already dropped upstream support for CentOS 6, so I'm
> > not really keen on "fixing" anything, unless the currently supported 
> > platforms
> > suffer from a related issue which would require code changes in which case 
> > we
> > could merge a patch like this upstream. You should upgrade your platform to 
> > a
> > newer CentOS if you want to rely on features provided by new(ish) libvirt.
> >
> > Erik
> >
>
> Thanks for the details - I could support such a patch (or write it using
> the above description).
>
> The one thing I have forgotten or perhaps I should say struck me -
> should this code use virCondWaitUntil or would it just not matter?
>
> Let's say 10 devices were added and on the 10th one we had this issue,
> set dataReady to false, but then didn't get another udev device ready
> event for "a while" leaving that 10th one in limbo until such time a new
> device was available (e.g. udevEventHandleCallback is called by udev).

Can you be more specific on how we could utilize virCondWaitUntil? Because the
way I see it, it wouldn't help us in either of the cases because the problem
isn't the thread waiting to be woken up to process an event rather it's the
recvmsg syscall in libudev which would cause the issue on old CentOS.
Looking at your example, if you put virCondWaitUntil in the !device conditional
path, how would that prevent us to hang after processing the last device if we
never got a chance to even hit the !device code path, since we kept getting
legitimate events until the last device where we got several events for a
single piece of data? It very well might be the jetlag speaking for me, but I
just don't see it in your example.

Erik

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


[libvirt] [PATCH v2 1/3] qemu: add vfio-ap capability

2018-10-18 Thread Boris Fiuczynski
Introduce vfio-ap capability.

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

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e228f52ec0..2ca5af3297 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -508,6 +508,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   /* 315 */
   "vfio-pci.display",
   "blockdev",
+  "vfio-ap",
 );
 
 
@@ -1092,6 +1093,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
 { "vhost-vsock-device", QEMU_CAPS_DEVICE_VHOST_VSOCK },
 { "mch", QEMU_CAPS_DEVICE_MCH },
 { "sev-guest", QEMU_CAPS_SEV_GUEST },
+{ "vfio-ap", QEMU_CAPS_DEVICE_VFIO_AP },
 };
 
 static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsVirtioBalloon[] = {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 934620ed31..6bb9a2c8f0 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -492,6 +492,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */
 /* 315 */
 QEMU_CAPS_VFIO_PCI_DISPLAY, /* -device vfio-pci.display */
 QEMU_CAPS_BLOCKDEV, /* -blockdev and blockdev-add are supported */
+QEMU_CAPS_DEVICE_VFIO_AP, /* -device vfio-ap */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
-- 
2.17.0

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


[libvirt] [PATCH v2 0/3] qemu: guest dedicated crypto adapters

2018-10-18 Thread Boris Fiuczynski
v2:
+ added singleton check for vfio-ap mediated device

This patch series introduces initial libvirt support for guest
dedicated crypto adapters on S390.
It allows to specify a vfio-ap mediated device in a domain.
Extensive documentation about AP is available in patch 6 of
the QEMU patch series.

KVM/kernel: guest dedicated crypto adapters
https://lkml.org/lkml/2018/9/26/25

QEMU: s390x: vfio-ap: guest dedicated crypto adapters
https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg01993.html

The qemu patch series has been included into master.
https://git.qemu.org/?p=qemu.git;a=commit;h=69ac8c4cb93f2685839ff7b857cef306b388ff3c

Boris Fiuczynski (3):
  qemu: add vfio-ap capability
  qemu: vfio-ap device support
  news: Update news for vfio-ap support

 docs/formatdomain.html.in  |  3 ++-
 docs/news.xml  |  9 +
 docs/schemas/domaincommon.rng  |  1 +
 src/conf/domain_conf.c | 28 
 src/qemu/qemu_capabilities.c   |  2 ++
 src/qemu/qemu_capabilities.h   |  1 +
 src/qemu/qemu_command.c|  8 
 src/qemu/qemu_domain_address.c |  4 
 src/util/virmdev.c |  3 ++-
 src/util/virmdev.h |  1 +
 10 files changed, 58 insertions(+), 2 deletions(-)

-- 
2.17.0

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


[libvirt] [PATCH v2 3/3] news: Update news for vfio-ap support

2018-10-18 Thread Boris Fiuczynski
Signed-off-by: Boris Fiuczynski 
---
 docs/news.xml | 9 +
 1 file changed, 9 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index dc08c96352..e5476a3332 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -35,6 +35,15 @@
 
   
 
+  
+
+  qemu: Add vfio AP support
+
+
+  The QEMU driver now has support to passthrough adjunct processors
+  into QEMU guests on S390.
+
+  
 
 
 
-- 
2.17.0

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


[libvirt] [PATCH v2 2/3] qemu: vfio-ap device support

2018-10-18 Thread Boris Fiuczynski
Adjusting domain format documentation, adding device address
support and adding command line generation for vfio-ap.
Since only one mediated hostdev with model vfio-ap is supported a check
disallows to define domains with more than one such hostdev device.

Signed-off-by: Boris Fiuczynski 
Reviewed-by: Bjoern Walk 
---
 docs/formatdomain.html.in  |  3 ++-
 docs/schemas/domaincommon.rng  |  1 +
 src/conf/domain_conf.c | 28 
 src/qemu/qemu_command.c|  8 
 src/qemu/qemu_domain_address.c |  4 
 src/util/virmdev.c |  3 ++-
 src/util/virmdev.h |  1 +
 7 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8189959773..269741a690 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4616,8 +4616,9 @@
   For mediated devices (Since 3.2.0)
   the model attribute specifies the device API which
   determines how the host's vfio driver will expose the device to the
-  guest. Currently, model='vfio-pci' and
+  guest. Currently, model='vfio-pci',
   model='vfio-ccw' (Since 
4.4.0)
+  and model='vfio-ap' (Since 
4.9.0)
   is supported. MDEV section
   provides more information about mediated devices as well as how to
   create mediated devices on the host.
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 099a949cf8..b9ac5df479 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4618,6 +4618,7 @@
   
 vfio-pci
 vfio-ccw
+vfio-ap
   
 
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e8e0adc819..1f8797f997 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4275,6 +4275,31 @@ virDomainDefPostParseGraphics(virDomainDef *def)
 }
 
 
+static int
+virDomainDefPostParseHostdev(virDomainDefPtr def)
+{
+size_t i;
+bool vfioap_found = false;
+
+/* verify settings of hostdevs vfio-ap */
+for (i = 0; i < def->nhostdevs; i++) {
+virDomainHostdevDefPtr hostdev = def->hostdevs[i];
+
+if (virHostdevIsMdevDevice(hostdev) &&
+hostdev->source.subsys.u.mdev.model == 
VIR_MDEV_MODEL_TYPE_VFIO_AP) {
+if (vfioap_found) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Only one hostdev of model vfio-ap is "
+ "support"));
+return -1;
+}
+vfioap_found = true;
+}
+}
+return 0;
+}
+
+
 /**
  * virDomainDriveAddressIsUsedByDisk:
  * @def: domain definition containing the disks to check
@@ -5185,6 +5210,9 @@ virDomainDefPostParseCommon(virDomainDefPtr def,
 
 virDomainDefPostParseGraphics(def);
 
+if (virDomainDefPostParseHostdev(def) < 0)
+return -1;
+
 if (virDomainDefPostParseCPU(def) < 0)
 return -1;
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1ff593c657..6e3ff67660 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5476,6 +5476,14 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
 return -1;
 }
 break;
+case VIR_MDEV_MODEL_TYPE_VFIO_AP:
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_AP)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("VFIO AP device assignment is not "
+ "supported by this version of QEMU"));
+return -1;
+}
+break;
 case VIR_MDEV_MODEL_TYPE_LAST:
 default:
 virReportEnumRangeError(virMediatedDeviceModelType,
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 8a8764cff5..24dd7c1a58 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -294,6 +294,10 @@ qemuDomainPrimeVfioDeviceAddresses(virDomainDefPtr def,
 subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_CCW &&
 def->hostdevs[i]->info->type == 
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
 def->hostdevs[i]->info->type = type;
+
+if (virHostdevIsMdevDevice(def->hostdevs[i]) &&
+subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_AP)
+def->hostdevs[i]->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
 }
 }
 
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 10a2b08337..3e11e38802 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -48,7 +48,8 @@ struct _virMediatedDeviceList {
 
 VIR_ENUM_IMPL(virMediatedDeviceModel, VIR_MDEV_MODEL_TYPE_LAST,
   "vfio-pci",
-  "vfio-ccw")
+  "vfio-ccw",
+  "vfio-ap")
 
 static virClassPtr virMediatedDeviceListClass;
 
diff --git 

Re: [libvirt] [PATCH] libvirtd: fix potential deadlock when starting vm

2018-10-18 Thread John Ferlan



On 10/18/18 8:23 AM, Erik Skultety wrote:
> On Tue, Oct 16, 2018 at 05:57:17PM -0400, John Ferlan wrote:
>>
>>
>> On 10/11/18 4:13 AM, Bingsong Si wrote:
>>> On CentOS 6, udev_monitor_receive_device will block until the socket becomes
>>
>> Is this really CentOS6 only or just where you've seen it?
>>
>>> readable, udevEventHandleThread will hold the lock all the time and
>>> udevEventHandleCallback hard to get the lock, will block the event poll.
>>> To fix this, set dataReady to false after receive an udev event.
>>>
>>> Signed-off-by: Bingsong Si 
>>> ---
>>>  src/node_device/node_device_udev.c | 5 +
>>>  1 file changed, 1 insertion(+), 4 deletions(-)
>>>
>>
>> I've CC'd Erik since he wrote and perhaps remembers all the "gotchas" he
>> discovered in the udev callback code.
>>
>> I wonder if this has to do with the EAGAIN and EWOULDBLOCK @errno checks
>> done in the !device loop that are different in "older" (much older) code.
>>
>> Although I have this very vague recollection that there was some problem
>> with centos6 that was fixed by some OS patch.  Hopefully Erik remembers
>> (and maybe we should log it in the code at this point ;-)) - I did do
>> some searching, but came up empty.
> 
> Remembering a year old issue, let me tell you, my head hurts :) (and we 
> probably
> should put a note somewhere, so that we don't have to dig out dinosaurs
> again)...the only thing I remember is that there was a reason why I did things
> this way and not the way this patch is proposing, and indeed I then found 
> this:
> 
> https://www.redhat.com/archives/libvir-list/2017-September/msg00683.html
> 
> TL;DR:
> The scheduler comes into play here. The problem I had was that the event loop
> could be scheduled (and it in fact was) earlier than the handler thread here.
> What that essentially means is that by the time the thread actually handled 
> the
> event and read the data from the monitor, the event loop fired the very same
> event, simply because the data hadn't been retrieved from the socket at that
> point yet.
> This was mainly connected to the design flaw of that specific version of patch
> series. With the current design, setting dataReady immediately after reading 
> the
> data or after encoutering the first EAGAIN doesn't matter and the scheduler
> wouldn't have an impact either way, that's true. However, with CentOS 6 the
> scheduler would still come into play even with your patch (it was much more
> noticeable the more devices you had in/added into the system), you'd still
> remain blocking on the recv call. The correct fix would be more
> complex and IIRC it would involve pulling the monitor object out of the 
> private
> data lockable object and would need to be guarded by a separate lock (I 
> haven't
> thought about it much though, so I might be wrong).
> 
> That said, we already dropped upstream support for CentOS 6, so I'm
> not really keen on "fixing" anything, unless the currently supported platforms
> suffer from a related issue which would require code changes in which case we
> could merge a patch like this upstream. You should upgrade your platform to a
> newer CentOS if you want to rely on features provided by new(ish) libvirt.
> 
> Erik
> 

Thanks for the details - I could support such a patch (or write it using
the above description).

The one thing I have forgotten or perhaps I should say struck me -
should this code use virCondWaitUntil or would it just not matter?

Let's say 10 devices were added and on the 10th one we had this issue,
set dataReady to false, but then didn't get another udev device ready
event for "a while" leaving that 10th one in limbo until such time a new
device was available (e.g. udevEventHandleCallback is called by udev).

Usage of the *Until would only occur if we've fallen into the !device
and continue code path and would be cleared prior before getting @device
again. Too much over thinking ;->?

John

John

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


[libvirt] [snmp PATCH 18/20] libvirtSnmp: Report libvirt errors if no domain is found

2018-10-18 Thread Michal Privoznik
Instead of plain printf(), report proper libvirt error.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 2f2f406..c334967 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -322,7 +322,7 @@ libvirtSnmpCreate(unsigned char *uuid, int state)
 }
 
 if (!(dom = virDomainLookupByUUID(conn, uuid))) {
-printf("Cannot find domain to create\n");
+printLibvirtError("No such domain");
 return -1;
 }
 
@@ -344,7 +344,7 @@ libvirtSnmpDestroy(unsigned char *uuid)
 int ret = -1;
 
 if (!(dom = virDomainLookupByUUID(conn, uuid))) {
-printf("Cannot find domain to destroy\n");
+printLibvirtError("No such domain");
 return -1;
 }
 
@@ -366,7 +366,7 @@ libvirtSnmpChangeState(unsigned char *uuid, int newstate, 
int oldstate)
 int ret = -1;
 
 if (!(dom = virDomainLookupByUUID(conn, uuid))) {
-printf("Cannot find domain to change\n");
+printLibvirtError("No such domain");
 return 1;
 }
 
-- 
2.18.1

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


[libvirt] [snmp PATCH 15/20] libvirtSnmp: s/showError/printLibvirtError/

2018-10-18 Thread Michal Privoznik
We have two function that do merely the same. Merge them into
one.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c  | 65 --
 src/libvirtSnmpError.c | 38 
 src/libvirtSnmpError.h | 13 -
 3 files changed, 57 insertions(+), 59 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 7aa83a1..97bb927 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -30,6 +30,7 @@
 #include 
 
 #include "libvirtSnmp.h"
+#include "libvirtSnmpError.h"
 #include "libvirtGuestTable.h"  /* include our MIB structures*/
 #include "libvirtNotifications.h"
 
@@ -43,17 +44,6 @@
 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
 #endif
 
-# ifndef ATTRIBUTE_FMT_PRINTF
-#  ifndef __clang__
-#   define ATTRIBUTE_FMT_PRINTF(fmtpos, argpos) \
-   __attribute__((__format__ (__gnu_printf__, fmtpos, argpos)))
-#  else
-#   define ATTRIBUTE_FMT_PRINTF(fmtpos, argpos) \
-   __attribute__((__format__ (__printf__, fmtpos, argpos)))
-#  endif
-# endif
-
-
 int verbose = 0;
 virConnectPtr conn;
 int callbackRet = -1;
@@ -86,37 +76,6 @@ stop(int sig)
 run = 0;
 }
 
-static void
-ATTRIBUTE_FMT_PRINTF(1,2)
-showError(const char *fmt, ...)
-{
-const char *libvirtErr = virGetLastErrorMessage();
-char ebuf[1024];
-int rc;
-int size = 0;
-va_list ap;
-
-va_start(ap, fmt);
-rc = vsnprintf(ebuf, sizeof(ebuf), fmt, ap);
-size += rc;
-va_end(ap);
-
-if (rc < 0 || size >= sizeof(ebuf))
-return;
-
-rc = snprintf(ebuf + size, sizeof(ebuf) - size, ": %s\n", libvirtErr);
-size += rc;
-
-if (rc < 0 || size >= sizeof(ebuf))
-return;
-
-fputs(ebuf, stderr);
-snmp_log(LOG_ERR, "%s", ebuf);
-
-virResetLastError();
-}
-
-
 static int
 insertGuest(netsnmp_container *container, virDomainPtr domain)
 {
@@ -126,7 +85,7 @@ insertGuest(netsnmp_container *container, virDomainPtr 
domain)
 unsigned char uuid[VIR_UUID_BUFLEN];
 
 if (virDomainGetInfo(domain, ) < 0) {
-showError("Failed to get domain info");
+printLibvirtError("Failed to get domain info");
 goto error;
 }
 
@@ -138,7 +97,7 @@ insertGuest(netsnmp_container *container, virDomainPtr 
domain)
 
 /* set the index of the row */
 if (virDomainGetUUID(domain, uuid) < 0) {
-showError("Failed to get domain UUID");
+printLibvirtError("Failed to get domain UUID");
 goto error;
 }
 
@@ -151,7 +110,7 @@ insertGuest(netsnmp_container *container, virDomainPtr 
domain)
 
 /* set the data */
 if (!(name = virDomainGetName(domain))) {
-showError("Failed to get domain name");
+printLibvirtError("Failed to get domain name");
 goto error;
 }
 
@@ -195,7 +154,7 @@ libvirtSnmpLoadGuests(netsnmp_container *container)
 virDomainPtr *domains = NULL;
 
 if ((ndomains = virConnectListAllDomains(conn, , 0)) < 0) {
-showError("Failed to list all domains");
+printLibvirtError("Failed to list all domains");
 goto cleanup;
 }
 
@@ -221,7 +180,7 @@ pollingThreadFunc(void *foo)
 {
 while (run) {
 if (virEventRunDefaultImpl() < 0) {
-showError("Failed to run event loop");
+printLibvirtError("Failed to run event loop");
 pthread_exit(NULL);
 }
 }
@@ -250,7 +209,7 @@ libvirtRegisterEvents(virConnectPtr conn) {
NULL, myFreeFunc);
 
 if (callbackRet == -1) {
-showError("Failed to register libvirt event handler");
+printLibvirtError("Failed to register libvirt event handler");
 goto cleanup;
 }
 
@@ -287,7 +246,7 @@ int libvirtSnmpInit(void)
 /* TODO: configure the URI */
 /* Use libvirt env variable LIBVIRT_DEFAULT_URI by default*/
 if (!(conn = virConnectOpenAuth(NULL, virConnectAuthPtrDefault, 0))) {
-showError("No connection to hypervisor");
+printLibvirtError("No connection to hypervisor");
 return -1;
 }
 
@@ -326,7 +285,7 @@ void libvirtSnmpShutdown(void)
 }
 
 if ((rc = virConnectClose(conn))) {
-showError("Failed to disconnect from hypervisor. "
+printLibvirtError("Failed to disconnect from hypervisor. "
   "Leaked references: %d\n", rc);
 }
 }
@@ -366,7 +325,7 @@ libvirtSnmpCreate(unsigned char *uuid, int state)
 }
 
 if (virDomainCreateWithFlags(dom, flags) < 0) {
-showError("Failed to create domain: %s", virDomainGetName(dom));
+printLibvirtError("Failed to create domain: %s", 
virDomainGetName(dom));
 goto cleanup;
 }
 
@@ -388,7 +347,7 @@ libvirtSnmpDestroy(unsigned char *uuid)
 }
 
 if (virDomainDestroy(dom) < 0) {
-showError("Failed to destroy domain %s", virDomainGetName(dom));
+printLibvirtError("Failed to destroy domain %s", 
virDomainGetName(dom));
 goto cleanup;
 }
 
@@ -421,7 +380,7 @@ 

[libvirt] [snmp PATCH 14/20] libvirtSnmp: Drop 'extern' from function headers

2018-10-18 Thread Michal Privoznik
These functions are not extern. Drop the keyword.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/libvirtSnmp.h b/src/libvirtSnmp.h
index 24707bd..f109bb4 100644
--- a/src/libvirtSnmp.h
+++ b/src/libvirtSnmp.h
@@ -31,29 +31,29 @@
 /*
  * Populate libvirtGuestTable into given container.
  */
-extern int
+int
 libvirtSnmpLoadGuests(netsnmp_container *container);
 
-extern int
+int
 libvirtSnmpInit(void);
 
-extern void
+void
 libvirtSnmpShutdown(void);
 
 /**
  * Check that domain with given UUID exists.
  * Return 0 if so, -1 if not.
  */
-extern int
+int
 libvirtSnmpCheckDomainExists(unsigned char *uuid);
 
-extern int
+int
 libvirtSnmpCreate(unsigned char *uuid, int state);
 
-extern int
+int
 libvirtSnmpDestroy(unsigned char *uuid);
 
-extern int
+int
 libvirtSnmpChangeState(unsigned char *uuid, int newstate, int oldstate);
 
 #endif /* __LIBVIRT_SNMP_H__ */
-- 
2.18.1

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


[libvirt] [snmp PATCH 10/20] src: Fix includes in header files

2018-10-18 Thread Michal Privoznik
A header file should include another header file if and only if
an there exists a symbol that requires the inclusion. For
instance, if a header file declares the following function:

  int function(virDomainPtr dom);

then it is okay to have the header file include libvirt.h.
Unfortunately, some of our header files have needless includes.

Signed-off-by: Michal Privoznik 
---
 src/libvirtNotifications.h |  2 +-
 src/libvirtSnmp.c  |  2 ++
 src/libvirtSnmp.h  | 10 +++---
 src/libvirtSnmpError.c |  7 ++-
 src/libvirtSnmpError.h |  3 ---
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/libvirtNotifications.h b/src/libvirtNotifications.h
index ee7a2e3..6c532b0 100644
--- a/src/libvirtNotifications.h
+++ b/src/libvirtNotifications.h
@@ -23,7 +23,7 @@
 #ifndef __LIBVIRT_NOTIFICATIONS_H__
 # define __LIBVIRT_NOTIFICATIONS_H__
 
-#include "libvirtSnmp.h"
+# include 
 
 /*
  * function declarations
diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 4ad6fab..3b5c17f 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -26,6 +26,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "libvirtSnmp.h"
 #include "libvirtGuestTable.h"  /* include our MIB structures*/
diff --git a/src/libvirtSnmp.h b/src/libvirtSnmp.h
index 2c5b0e5..24707bd 100644
--- a/src/libvirtSnmp.h
+++ b/src/libvirtSnmp.h
@@ -23,14 +23,10 @@
 #ifndef __LIBVIRT_SNMP_H__
 # define __LIBVIRT_SNMP_H__
 
-/* standard libvirt includes */
-#include 
-#include 
-
 /* standard Net-SNMP includes */
-#include 
-#include 
-#include 
+# include 
+# include 
+# include 
 
 /*
  * Populate libvirtGuestTable into given container.
diff --git a/src/libvirtSnmpError.c b/src/libvirtSnmpError.c
index f5d546d..1678bcb 100644
--- a/src/libvirtSnmpError.c
+++ b/src/libvirtSnmpError.c
@@ -20,8 +20,13 @@
  * Author: Michal Privoznik 
  */
 
-#include "libvirtSnmpError.h"
+#include 
+
 #include 
+#include 
+#include 
+
+#include "libvirtSnmpError.h"
 
 /**
  * Print libvirt error
diff --git a/src/libvirtSnmpError.h b/src/libvirtSnmpError.h
index 6d59478..e28ad7c 100644
--- a/src/libvirtSnmpError.h
+++ b/src/libvirtSnmpError.h
@@ -23,9 +23,6 @@
 #ifndef __LIBVIRT_SNMP_ERROR_H__
 # define __LIBVIRT_SNMP_ERROR_H__
 
-#include 
-#include 
-
 extern void printLibvirtError(const char *msg);
 
 #endif /* __LIBVIRT_SNMP_ERROR_H__ */
-- 
2.18.1

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


[libvirt] [snmp PATCH 08/20] libvirtSnmp: Rewrite some functions

2018-10-18 Thread Michal Privoznik
Some function initialize retval to 0 and then for every error
path they reset it to -1.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c | 50 +++
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 1e7e345..4ad6fab 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -258,9 +258,7 @@ int libvirtSnmpInit(void)
 
 /* TODO: configure the URI */
 /* Use libvirt env variable LIBVIRT_DEFAULT_URI by default*/
-conn = virConnectOpenAuth(NULL, virConnectAuthPtrDefault, 0);
-
-if (NULL == conn) {
+if (!(conn = virConnectOpenAuth(NULL, virConnectAuthPtrDefault, 0))) {
 printf("No connection to hypervisor\n");
 showError(conn);
 return -1;
@@ -283,6 +281,7 @@ libvirtDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque 
ATTRIBUTE_UNUSED)
 void libvirtSnmpShutdown(void)
 {
 int timer;
+int rc;
 
 /* in case server is being stopped, run is still 1, so let's
  * shutdown the thread in a clean way */
@@ -299,8 +298,9 @@ void libvirtSnmpShutdown(void)
 printf("Failed to unregister domain events\n");
 }
 
-if (0 != virConnectClose(conn)) {
-printf("Failed to disconnect from hypervisor\n");
+if ((rc = virConnectClose(conn))) {
+printf("Failed to disconnect from hypervisor. "
+   "Leaked references: %d\n", rc);
 showError(conn);
 }
 }
@@ -320,18 +320,11 @@ int
 libvirtSnmpCreate(unsigned char *uuid, int state)
 {
 virDomainPtr dom;
-int ret;
+int ret = -1;
 unsigned int flags = 0;
 
-dom = virDomainLookupByUUID(conn, uuid);
-if (dom == NULL) {
-printf("Cannot find domain to create\n");
-return -1;
-}
-
 switch(state) {
 case VIR_DOMAIN_RUNNING:
-flags = 0;
 break;
 case VIR_DOMAIN_PAUSED:
 flags = VIR_DOMAIN_START_PAUSED;
@@ -341,10 +334,18 @@ libvirtSnmpCreate(unsigned char *uuid, int state)
 return -1;
 }
 
-ret = virDomainCreateWithFlags(dom, flags);
-if (ret) {
-showError(conn);
+if (!(dom = virDomainLookupByUUID(conn, uuid))) {
+printf("Cannot find domain to create\n");
+return -1;
 }
+
+if (virDomainCreateWithFlags(dom, flags) < 0) {
+showError(conn);
+goto cleanup;
+}
+
+ret = 0;
+ cleanup:
 virDomainFree(dom);
 return ret;
 }
@@ -353,27 +354,26 @@ int
 libvirtSnmpDestroy(unsigned char *uuid)
 {
 virDomainPtr dom;
-int ret;
 
-dom = virDomainLookupByUUID(conn, uuid);
-if (dom == NULL) {
+if (!(dom = virDomainLookupByUUID(conn, uuid))) {
 printf("Cannot find domain to destroy\n");
 return -1;
 }
 
-ret = virDomainDestroy(dom);
-if (ret) {
+if (virDomainDestroy(dom) < 0) {
 showError(conn);
+return -1;
 }
+
 virDomainFree(dom);
-return ret;
+return 0;
 }
 
 int
 libvirtSnmpChangeState(unsigned char *uuid, int newstate, int oldstate)
 {
 virDomainPtr dom;
-int ret = 0;
+int ret = -1;
 
 dom = virDomainLookupByUUID(conn, uuid);
 if (dom == NULL) {
@@ -389,13 +389,11 @@ libvirtSnmpChangeState(unsigned char *uuid, int newstate, 
int oldstate)
 ret = virDomainShutdown(dom);
 else {
 printf("Wrong state transition from %d to %d\n", oldstate, newstate);
-ret = -1;
 goto out;
 }
 
-if (ret != 0) {
+if (ret < 0)
 showError(conn);
-}
  out:
 virDomainFree(dom);
 return ret;
-- 
2.18.1

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


[libvirt] [snmp PATCH 06/20] libvirtSnmp: Modernize libvirtSnmpLoadGuests

2018-10-18 Thread Michal Privoznik
Since libvirt-0.9.13 we have this atomic API for listing domains.
Use that instead of the old ones.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c | 107 +++---
 1 file changed, 16 insertions(+), 91 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 22cf8f0..589fd03 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -165,105 +165,30 @@ insertGuest(netsnmp_container *container, virDomainPtr 
domain)
 int
 libvirtSnmpLoadGuests(netsnmp_container *container)
 {
-int ret = 0, i, numIds, numActiveDomains;
-int numNames, numDefinedDomains;
-int *idList = NULL;
-char **nameList = NULL;
-virDomainPtr domain = NULL;
+int ret = -1;
+int i;
+int ndomains;
+virDomainPtr *domains = NULL;
 
-numActiveDomains = virConnectNumOfDomains(conn);
-if (-1 == numActiveDomains) {
-ret = -1;
-printf("Failed to get number of active domains\n");
+if ((ndomains = virConnectListAllDomains(conn, , 0)) < 0) {
+printf("Failed to list all domains\n");
 showError(conn);
-goto out;
+goto cleanup;
 }
 
-idList = malloc(sizeof(*idList) * numActiveDomains);
 
-if (NULL == idList) {
-ret = -1;
-printf("Could not allocate memory for list of active domains\n");
-goto out;
+for (i = 0; i < ndomains; i++) {
+if (insertGuest(container, domains[i]) < 0)
+goto cleanup;
 }
 
-numIds = virConnectListDomains(conn,
-   idList,
-   numActiveDomains);
-
-if (-1 == numIds) {
-ret = -1;
-printf("Could not get list of defined domains from hypervisor\n");
-showError(conn);
-goto out;
+ret = 0;
+ cleanup:
+if (domains) {
+for (i = 0; i < ndomains; i++)
+virDomainFree(domains[i]);
+free(domains);
 }
-
-for (i = 0 ; i < numIds ; i++) {
-domain = virDomainLookupByID(conn, *(idList + i));
-if (NULL == domain) {
-printf("Failed to lookup domain\n");
-showError(conn);
-ret = -1;
-goto out;
-}
-
-ret = insertGuest(container, domain);
-
-virDomainFree(domain);
-
-if (-1 == ret)
-goto out;
-}
-
-/* Inactive domains */
-numDefinedDomains = virConnectNumOfDefinedDomains(conn);
-if (-1 == numDefinedDomains) {
-ret = -1;
-printf("Failed to get number of defined domains\n");
-showError(conn);
-goto out;
-}
-
-nameList = malloc(sizeof(*nameList) * numDefinedDomains);
-
-if (NULL == nameList) {
-ret = -1;
-printf("Could not allocate memory for list of defined domains\n");
-goto out_inact;
-}
-
-numNames = virConnectListDefinedDomains(conn,
-nameList,
-numDefinedDomains);
-
-if (-1 == numNames) {
-ret = -1;
-printf("Could not get list of defined domains from hypervisor\n");
-showError(conn);
-goto out_inact;
-}
-
-for (i = 0 ; i < numNames ; i++) {
-domain = virDomainLookupByName(conn, *(nameList + i));
-if (NULL == domain) {
-printf("Failed to lookup domain\n");
-showError(conn);
-ret = -1;
-goto out_inact;
-}
-
-ret = insertGuest(container, domain);
-
-virDomainFree(domain);
-
-if (-1 == ret)
-goto out_inact;
-}
-
- out_inact:
-free(nameList);
- out:
-free(idList);
 return ret;
 }
 
-- 
2.18.1

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


[libvirt] [snmp PATCH 05/20] showError: Switch to less ancient error reporting

2018-10-18 Thread Michal Privoznik
So far, the function calls virConnCopyLastError() which is
suboptimal since we have virGetLastErrorMessage(). Switch to
that.

Signed-off-by: Michal Privoznik 
---
 configure.ac  |  2 +-
 src/libvirtSnmp.c | 31 +++
 2 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1b4112e..baac0e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@ dnl
 
 
 dnl do we have libvirt installed?
-LIBVIRT_REQUIRED=0.9.0
+LIBVIRT_REQUIRED=1.0.6
 
 PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
 AC_SUBST(LIBVIRT_LIBS)
diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 111c97b..22cf8f0 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -76,36 +76,11 @@ stop(int sig)
 static void
 showError(virConnectPtr conn)
 {
-int ret;
-virErrorPtr err;
+const char *err = virGetLastErrorMessage();
 
-err = malloc(sizeof(*err));
-if (NULL == err) {
-printf("Could not allocate memory for error data\n");
-goto out;
-}
+snmp_log(LOG_ERR, "libvirt reported: \"%s\"\n", err);
 
-ret = virConnCopyLastError(conn, err);
-
-switch (ret) {
-case 0:
-snmp_log(LOG_ERR, "No error found\n");
-break;
-
-case -1:
-snmp_log(LOG_ERR, "Parameter error when attempting to get last 
error\n");
-break;
-
-default:
-snmp_log(LOG_ERR, "libvirt reported: \"%s\"\n", err->message);
-break;
-}
-
-virResetError(err);
-free(err);
-
- out:
-return;
+virResetLastError();
 }
 
 
-- 
2.18.1

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


[libvirt] [snmp PATCH 04/20] configure.ac: Drop useless "-lvirt" in LIBVIRT_LIBS

2018-10-18 Thread Michal Privoznik
We are using PKG_CHECK_MODULES() which sets LIBVIRT_LIBS and
LIBVIRT_CFLAGS. There is no need to modify the former and put
"-lvirt" into it.

Signed-off-by: Michal Privoznik 
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 7834c34..1b4112e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,8 +26,8 @@ dnl do we have libvirt installed?
 LIBVIRT_REQUIRED=0.9.0
 
 PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
-LIBVIRT_LIBS="$LIBVIRT_LIBS -lvirt"
 AC_SUBST(LIBVIRT_LIBS)
+AC_SUBST(LIBVIRT_CFLAGS)
 
 SNMP_CONFIG="net-snmp-config"
 SNMP_CFLAGS=""
-- 
2.18.1

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


[libvirt] [snmp PATCH 00/20] Misc cleanups and improvements

2018-10-18 Thread Michal Privoznik
These are not pushed. I'll wait couple of moments if there is somebody
who has opinion. If not I will push them.

Michal Privoznik (20):
  libvirtGuestTable.c: Free duplicated domain name
  libvirtSnmp.c: Retab and realign
  configure: Drop support for libvirt older than 0.9.0
  configure.ac: Drop useless "-lvirt" in LIBVIRT_LIBS
  showError: Switch to less ancient error reporting
  libvirtSnmp: Modernize libvirtSnmpLoadGuests
  libvirtSnmp: Modernize insertGuest
  libvirtSnmp: Rewrite some functions
  src: Fix header file defines
  src: Fix includes in header files
  libvirtRegisterEvents: Drop pthread_attr_init
  libvirtSnmp: turn showError() into printf-like function
  libvirtSnmpError: Drop 'extern' for printLibvirtError()
  libvirtSnmp: Drop 'extern' from function headers
  libvirtSnmp: s/showError/printLibvirtError/
  libvirtSnmpError: Introduce and use printSystemError
  libvirtSnmp: Fix type of libvirtUnregisterEvents()
  libvirtSnmp: Report libvirt errors if no domain is found
  libvirtSnmpInit: Don't report errors from libvirtRegisterEvents()
  .gitignore: Ignore tags file

 .gitignore |   1 +
 configure.ac   |  31 +-
 src/Makefile.am|  18 -
 src/event_poll.c   | 724 -
 src/event_poll.h   | 132 ---
 src/ignore-value.h |  64 
 src/internal.h | 138 ---
 src/libvirtGuestTable.c|   4 +-
 src/libvirtNotifications.h |   8 +-
 src/libvirtSnmp.c  | 436 --
 src/libvirtSnmp.h  |  30 +-
 src/libvirtSnmpError.c |  83 -
 src/libvirtSnmpError.h |  23 +-
 src/memory.c   | 313 
 src/memory.h   | 212 ---
 src/threads.c  | 251 -
 src/threads.h  | 101 --
 src/util.c | 105 --
 src/util.h |  38 --
 19 files changed, 261 insertions(+), 2451 deletions(-)
 delete mode 100644 src/event_poll.c
 delete mode 100644 src/event_poll.h
 delete mode 100644 src/ignore-value.h
 delete mode 100644 src/internal.h
 delete mode 100644 src/memory.c
 delete mode 100644 src/memory.h
 delete mode 100644 src/threads.c
 delete mode 100644 src/threads.h
 delete mode 100644 src/util.c
 delete mode 100644 src/util.h

-- 
2.18.1

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


[libvirt] [snmp PATCH 17/20] libvirtSnmp: Fix type of libvirtUnregisterEvents()

2018-10-18 Thread Michal Privoznik
This function returns only a single value. It makes no sense to
have it return that. Make it return void.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 3a93bc6..2f2f406 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -227,14 +227,14 @@ libvirtRegisterEvents(virConnectPtr conn)
 }
 
 /* Unregister domain events collection */
-int
+static void
 libvirtUnregisterEvents(virConnectPtr conn)
 {
-void *status;
+if (callbackRet < 0)
+return;
 
 virConnectDomainEventDeregisterAny(conn, callbackRet);
 callbackRet = -1;
-return 0;
 }
 
 int libvirtSnmpInit(void)
@@ -284,13 +284,11 @@ void libvirtSnmpShutdown(void)
 if (timer != -1)
 virEventRemoveTimeout(timer);
 
-if (libvirtUnregisterEvents(conn)) {
-printf("Failed to unregister domain events\n");
-}
+libvirtUnregisterEvents(conn);
 
 if ((rc = virConnectClose(conn))) {
 printLibvirtError("Failed to disconnect from hypervisor. "
-  "Leaked references: %d\n", rc);
+  "Leaked references: %d\n", rc);
 }
 }
 
-- 
2.18.1

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


[libvirt] [snmp PATCH 19/20] libvirtSnmpInit: Don't report errors from libvirtRegisterEvents()

2018-10-18 Thread Michal Privoznik
The libvirtRegisterEvents() function now reports errors on its
own. No need to duplicate the effort.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index c334967..e63942b 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -254,10 +254,8 @@ int libvirtSnmpInit(void)
 return -1;
 }
 
-if ((callbackRet == -1) && libvirtRegisterEvents(conn)) {
-printf("Unable to register domain events\n");
+if ((callbackRet == -1) && libvirtRegisterEvents(conn))
 return -1;
-}
 
 return 0;
 }
-- 
2.18.1

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


[libvirt] [snmp PATCH 20/20] .gitignore: Ignore tags file

2018-10-18 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index ce79f12..dd930b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@ ChangeLog
 /INSTALL
 Makefile
 Makefile.in
+tags
 /aclocal.m4
 /autom4te.cache/
 /build-aux/compile
-- 
2.18.1

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


[libvirt] [snmp PATCH 16/20] libvirtSnmpError: Introduce and use printSystemError

2018-10-18 Thread Michal Privoznik
This function formats passed string and prints stringified system
error.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c  |  8 ++--
 src/libvirtSnmpError.c | 38 ++
 src/libvirtSnmpError.h |  3 +++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 97bb927..3a93bc6 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -189,8 +189,10 @@ pollingThreadFunc(void *foo)
 
 /* Function to register domain lifecycle events collection */
 int
-libvirtRegisterEvents(virConnectPtr conn) {
+libvirtRegisterEvents(virConnectPtr conn)
+{
 struct sigaction action_stop;
+int rc;
 int ret = -1;
 
 memset(_stop, 0, sizeof action_stop);
@@ -214,8 +216,10 @@ libvirtRegisterEvents(virConnectPtr conn) {
 }
 
 /* we need a thread to poll for events */
-if (pthread_create(_thread, NULL, pollingThreadFunc, NULL))
+if ((rc = pthread_create(_thread, NULL, pollingThreadFunc, NULL))) {
+printSystemError(rc, "Unable to create polling thread");
 goto cleanup;
+}
 
 ret = 0;
  cleanup:
diff --git a/src/libvirtSnmpError.c b/src/libvirtSnmpError.c
index c356aae..33a65c2 100644
--- a/src/libvirtSnmpError.c
+++ b/src/libvirtSnmpError.c
@@ -65,3 +65,41 @@ printLibvirtError(const char *fmt, ...)
 
 virResetLastError();
 }
+
+
+/**
+ * printSystemError:
+ * @theerrno: the errno value
+ * @fmt: Error message format string
+ *
+ * Print system error with @theerrno translated into human readable form.
+ */
+void
+printSystemError(int theerrno, const char *fmt, ...)
+{
+char ebuf[1024];
+char sysebuf[1024];
+int rc;
+int size = 0;
+va_list ap;
+
+if (!strerror_r(theerrno, sysebuf, sizeof(sysebuf)))
+return;
+
+va_start(ap, fmt);
+rc = vsnprintf(ebuf, sizeof(ebuf), fmt, ap);
+size += rc;
+va_end(ap);
+
+if (rc < 0 || size >= sizeof(ebuf))
+return;
+
+rc = snprintf(ebuf + size, sizeof(ebuf) - size, ": %s\n", sysebuf);
+size += rc;
+
+if (rc < 0 || size >= sizeof(ebuf))
+return;
+
+fputs(ebuf, stderr);
+snmp_log(LOG_ERR, "%s", ebuf);
+}
diff --git a/src/libvirtSnmpError.h b/src/libvirtSnmpError.h
index 46c98f0..e8822d1 100644
--- a/src/libvirtSnmpError.h
+++ b/src/libvirtSnmpError.h
@@ -36,4 +36,7 @@
 void printLibvirtError(const char *fmt, ...)
 ATTRIBUTE_FMT_PRINTF(1, 2);
 
+void printSystemError(int theerrno, const char *fmt, ...)
+ATTRIBUTE_FMT_PRINTF(2, 3);
+
 #endif /* __LIBVIRT_SNMP_ERROR_H__ */
-- 
2.18.1

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


[libvirt] [snmp PATCH 09/20] src: Fix header file defines

2018-10-18 Thread Michal Privoznik
To avoid multiple includes, header files start with:

  #ifndef __SOMETHING__
  # define __SOMETHING__

Well, SOMETHING should be the file name, and there should be a
space after hash and before 'define'.

Signed-off-by: Michal Privoznik 
---
 src/libvirtNotifications.h | 6 +++---
 src/libvirtSnmp.h  | 6 +++---
 src/libvirtSnmpError.h | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/libvirtNotifications.h b/src/libvirtNotifications.h
index 0be8fdc..ee7a2e3 100644
--- a/src/libvirtNotifications.h
+++ b/src/libvirtNotifications.h
@@ -20,8 +20,8 @@
  * Author: Michal Privoznik 
  */
 
-#ifndef LIBVIRTNOTIFICATIONS_H
-#define LIBVIRTNOTIFICATIONS_H
+#ifndef __LIBVIRT_NOTIFICATIONS_H__
+# define __LIBVIRT_NOTIFICATIONS_H__
 
 #include "libvirtSnmp.h"
 
@@ -30,4 +30,4 @@
  */
 int send_libvirtGuestNotif_trap(virDomainPtr dom);
 
-#endif /* LIBVIRTNOTIFICATIONS_H */
+#endif /* __LIBVIRT_NOTIFICATIONS_H__ */
diff --git a/src/libvirtSnmp.h b/src/libvirtSnmp.h
index bac9988..2c5b0e5 100644
--- a/src/libvirtSnmp.h
+++ b/src/libvirtSnmp.h
@@ -20,8 +20,8 @@
  * Author: Michal Privoznik 
  */
 
-#ifndef __VIR_SNMP_H__
-#define __VIR_SNMP_H__
+#ifndef __LIBVIRT_SNMP_H__
+# define __LIBVIRT_SNMP_H__
 
 /* standard libvirt includes */
 #include 
@@ -60,5 +60,5 @@ libvirtSnmpDestroy(unsigned char *uuid);
 extern int
 libvirtSnmpChangeState(unsigned char *uuid, int newstate, int oldstate);
 
-#endif /* __VIR_SNMP_H__ */
+#endif /* __LIBVIRT_SNMP_H__ */
 
diff --git a/src/libvirtSnmpError.h b/src/libvirtSnmpError.h
index 518cc03..6d59478 100644
--- a/src/libvirtSnmpError.h
+++ b/src/libvirtSnmpError.h
@@ -20,12 +20,12 @@
  * Author: Michal Privoznik 
  */
 
-#ifndef __VIR_SNMP_ERROR_H__
-#define __VIR_SNMP_ERROR_H__
+#ifndef __LIBVIRT_SNMP_ERROR_H__
+# define __LIBVIRT_SNMP_ERROR_H__
 
 #include 
 #include 
 
 extern void printLibvirtError(const char *msg);
 
-#endif
+#endif /* __LIBVIRT_SNMP_ERROR_H__ */
-- 
2.18.1

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


[libvirt] [snmp PATCH 11/20] libvirtRegisterEvents: Drop pthread_attr_init

2018-10-18 Thread Michal Privoznik
The threads are JOINABLE by default. No need to go through
pthread_attr_* circus to set what is default anyway.

Signed-off-by: Michal Privoznik 
---
 src/libvirtSnmp.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c
index 3b5c17f..88f2ec6 100644
--- a/src/libvirtSnmp.c
+++ b/src/libvirtSnmp.c
@@ -205,7 +205,7 @@ pollingThreadFunc(void *foo)
 int
 libvirtRegisterEvents(virConnectPtr conn) {
 struct sigaction action_stop;
-pthread_attr_t thread_attr;
+int ret = -1;
 
 memset(_stop, 0, sizeof action_stop);
 
@@ -226,15 +226,12 @@ libvirtRegisterEvents(virConnectPtr conn) {
 return -1;
 
 /* we need a thread to poll for events */
-pthread_attr_init(_attr);
-pthread_attr_setdetachstate(_attr, PTHREAD_CREATE_JOINABLE);
+if (pthread_create(_thread, NULL, pollingThreadFunc, NULL))
+goto cleanup;
 
-if (pthread_create(_thread, _attr, pollingThreadFunc, NULL))
-return -1;
-
-pthread_attr_destroy(_attr);
-
-return 0;
+ret = 0;
+ cleanup:
+return ret;
 }
 
 /* Unregister domain events collection */
-- 
2.18.1

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


  1   2   >