[libvirt] [PATCH] qemuProcess: update hostdevs before connectting qemu monitor

2018-09-20 Thread Wu Zongyong
In a following case:

virsh start $domain
service libvirtd stop
 the guest from within the $domain
service libvirtd start

Notice that PCI devices which have been assigned to the $domain will
still be bound to stub drivers instead rebound to host drivers.
In that case the call stack is like below:

libvirtd start
qemuProcessReconnect
qemuProcessStop
qemuHostdevReAttachDomainDevices
qemuHostdevReAttachPCIDevices
virHostdevReAttachPCIDevices

qemuHostdevUpdateActiveDomainDevices won't be called because the monitor
channel is closed. So host devices in $domain will not be added to either
activePCIHostdevs list or inactivePCIHostdev list. And therefore,
virHostdevReAttachPCIDevices just neglects these host PCI devices which
are bound to stub drivers and don't rebind them to host drivers.

This patch fixs that by moving qemuHostdevUpdateActiveDomainDevices before
qemuConnectMonitor.

Signed-off-by: Wu Zongyong 
---
 src/qemu/qemu_process.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f9a01da..d187271 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7783,6 +7783,9 @@ qemuProcessReconnect(void *opaque)
  * allowReboot in status XML and we need to initialize it. */
 qemuProcessPrepareAllowReboot(obj);
 
+if (qemuHostdevUpdateActiveDomainDevices(driver, obj->def) < 0)
+goto error;
+
 if (priv->qemuCaps &&
 virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS))
 retry = false;
@@ -7794,9 +7797,6 @@ qemuProcessReconnect(void *opaque)
 if (qemuConnectMonitor(driver, obj, QEMU_ASYNC_JOB_NONE, retry, NULL) < 0)
 goto error;
 
-if (qemuHostdevUpdateActiveDomainDevices(driver, obj->def) < 0)
-goto error;
-
 priv->machineName = qemuDomainGetMachineName(obj);
 if (!priv->machineName)
 goto error;
-- 
1.9.1

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


[libvirt] [PATCH] virhostdev: Fix PCI devices are still attatched to stub driver bug

2018-08-31 Thread Wu Zongyong
Currently, PCI devices will not be rebound to host drivers but
attached to the stub driver when:

1) use libvirt to start a virtual machine with PCI devices assigned,
then stop libvirtd process and shutdown the virtual machine. Finally,
PCI devices are still bound to the stub driver instead of host drivers
after libvirt start again.
2) use libvirt to shutdown a virtual machine wtih PCI devices assigned,
then stop libvirtd process before libvirt try to rebind PCI devices to
host drivers. Finally, PCI devices are still bound to the stub driver
after libvirt start again.

Notice that the comment on the top of virPCIDeviceDetach as follows:

activeDevs should be a list of all PCI devices currently in use by a
domain.inactiveDevs is a list of all PCI devices that libvirt has
detached from the host driver + attached to the stub driver, but
hasn't yet assigned to a domain.

It's not reasonable that libvirt filter out devices that are either not
active or not used by the current domain and driver. For devices belong
to domains that has been shutdown before libvirt start, we should put
them into inactiveDevs if then meet the condition that PCI devices have
been detached from the host driver + attached to the stub driver.

Moreover, we set orignal states of PCI devices when build PCI devices
list in virHostdevGetPCIHostDeviceList if states has been set in struct
virDomainHostdevDefPtr.

Signed-off-by: Wu Zongyong 
---
 src/util/virhostdev.c | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index ca79c37..ecf95e3 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -235,6 +235,7 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr 
*hostdevs, int nhostdevs)
 for (i = 0; i < nhostdevs; i++) {
 virDomainHostdevDefPtr hostdev = hostdevs[i];
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
+virDomainHostdevOrigStatesPtr origstates = >origstates;
 virPCIDevicePtr pci;
 
 if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
@@ -262,6 +263,10 @@ virHostdevGetPCIHostDeviceList(virDomainHostdevDefPtr 
*hostdevs, int nhostdevs)
 virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN);
 else
 virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM);
+
+virPCIDeviceSetUnbindFromStub(pci, 
origstates->states.pci.unbind_from_stub);
+virPCIDeviceSetRemoveSlot(pci, origstates->states.pci.remove_slot);
+virPCIDeviceSetReprobe(pci, origstates->states.pci.reprobe);
 }
 
 return pcidevs;
@@ -1008,8 +1013,19 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
 continue;
 }
 } else {
-virPCIDeviceListDel(pcidevs, pci);
-continue;
+int stub = virPCIDeviceGetStubDriver(pci);
+if (stub > VIR_PCI_STUB_DRIVER_NONE &&
+stub < VIR_PCI_STUB_DRIVER_LAST) {
+/* The device is bound to a known stub driver: add a copy
+ * to the inactive list */
+VIR_DEBUG("Adding PCI device %s to inactive list",
+  virPCIDeviceGetName(pci));
+if (virPCIDeviceListAddCopy(mgr->inactivePCIHostdevs, pci) < 
0) {
+VIR_ERROR(_("Failed to add PCI device %s to the inactive 
list"),
+  virGetLastErrorMessage());
+virResetLastError();
+}
+}
 }
 
 i++;
-- 
1.9.1

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


[libvirt] Why does vnc show blackscreen after using mstsc to connect to a windows vm with a nvidia gpu passtrough

2018-06-01 Thread Wu Zongyong
Hi,

As the title says, VNC inside a windows virtual machine doesn’t work after I 
try to use mstsc to access the vm with a gpu passthrough.
It seems that the scenario is normal, but could someone tell me something 
deeply about the reason why vnc shows blackscreen? 

Thanks.

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

[libvirt] [PATCH v3 0/3] nodedev: update caps before quering nodedev infos

2018-01-10 Thread Wu Zongyong
Some capabilities of node devices rely on what driver they bound to, 
and therefore, these capabilities may change when the driver change.
In current implemention, it is not consistent between real status and
the status we get by invoking nodedev interfaces.
So, this series of patches try to manually update devices' capabilities
each time before nodedev driver interfaces invoked.

Wu Zongyong (3):

  v2->v3:
1. split a single patch to three part
2. fix memory leak and lock problems
3. update caps before invoking nodedev driver interfaces (refer to patch 
3/3)


  nodedev: add macro guard to node_device_udev header file
  nodedev: update mdev_types caps before dumpxml
  nodedev: update caps before invoking nodedev driver interfaces

 src/node_device/node_device_driver.c  | 55 +++
 src/node_device/node_device_linux_sysfs.c | 22 +
 src/node_device/node_device_udev.c| 37 +
 src/node_device/node_device_udev.h| 18 +++---
 4 files changed, 121 insertions(+), 11 deletions(-)

-- 
1.9.1

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


[libvirt] [PATCH 3/3] nodedev: update caps before invoking nodedev driver interfaces

2018-01-10 Thread Wu Zongyong
Some capabilities of node devices rely on what driver they bound to,
and therefore, these capabilities may change when the driver change.
So, it is necessary to manually update devices' capabilities each time
before nodedev driver interfaces invoked.

Signed-off-by: Wu Zongyong <cordius...@huawei.com>
---
 src/node_device/node_device_driver.c | 55 
 1 file changed, 55 insertions(+)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index facfeb6..d854516 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -155,6 +155,42 @@ nodeDeviceUpdateDriverName(virNodeDeviceDefPtr def 
ATTRIBUTE_UNUSED)
 #endif
 
 
+static int
+nodeConnectUpdateAllNodeDevicesCaps(virConnectPtr conn,
+virNodeDeviceObjListFilter filter)
+{
+int ret = -1;
+size_t i;
+virNodeDevicePtr *devices;
+
+if (virNodeDeviceObjListExport(conn, driver->devs, , filter, 0) < 
0)
+return -1;
+
+for (i = 0; devices[i]; i++) {
+virNodeDeviceObjPtr obj;
+virNodeDeviceDefPtr def;
+
+if (!(obj = virNodeDeviceObjListFindByName(driver->devs, 
devices[i]->name)))
+goto cleanup;
+def = virNodeDeviceObjGetDef(obj);
+
+if (nodeDeviceUpdateCaps(def) < 0) {
+virNodeDeviceObjEndAPI();
+goto cleanup;
+}
+
+virNodeDeviceObjEndAPI();
+}
+
+ret = 0;
+ cleanup:
+for (i = 0; devices[i]; i++)
+virObjectUnref(devices[i]);
+VIR_FREE(devices);
+return ret;
+}
+
+
 void
 nodeDeviceLock(void)
 {
@@ -179,6 +215,9 @@ nodeNumOfDevices(virConnectPtr conn,
 
 virCheckFlags(0, -1);
 
+if (nodeConnectUpdateAllNodeDevicesCaps(conn, virNodeNumOfDevicesCheckACL) 
< 0)
+return -1;
+
 return virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap,
 virNodeNumOfDevicesCheckACL);
 }
@@ -196,6 +235,9 @@ nodeListDevices(virConnectPtr conn,
 
 virCheckFlags(0, -1);
 
+if (nodeConnectUpdateAllNodeDevicesCaps(conn, virNodeListDevicesCheckACL) 
< 0)
+return -1;
+
 return virNodeDeviceObjListGetNames(driver->devs, conn,
 virNodeListDevicesCheckACL,
 cap, names, maxnames);
@@ -212,6 +254,10 @@ nodeConnectListAllNodeDevices(virConnectPtr conn,
 if (virConnectListAllNodeDevicesEnsureACL(conn) < 0)
 return -1;
 
+if (nodeConnectUpdateAllNodeDevicesCaps(conn,
+
virConnectListAllNodeDevicesCheckACL) < 0)
+return -1;
+
 return virNodeDeviceObjListExport(conn, driver->devs, devices,
   virConnectListAllNodeDevicesCheckACL,
   flags);
@@ -248,6 +294,9 @@ nodeDeviceLookupByName(virConnectPtr conn,
 if (virNodeDeviceLookupByNameEnsureACL(conn, def) < 0)
 goto cleanup;
 
+if (nodeDeviceUpdateCaps(def) < 0)
+goto cleanup;
+
 if ((device = virGetNodeDevice(conn, name))) {
 if (VIR_STRDUP(device->parent, def->parent) < 0) {
 virObjectUnref(device);
@@ -370,6 +419,9 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device)
 if (virNodeDeviceNumOfCapsEnsureACL(device->conn, def) < 0)
 goto cleanup;
 
+if (nodeDeviceUpdateCaps(def) < 0)
+goto cleanup;
+
 for (caps = def->caps; caps; caps = caps->next) {
 ++ncaps;
 
@@ -411,6 +463,9 @@ nodeDeviceListCaps(virNodeDevicePtr device,
 if (virNodeDeviceListCapsEnsureACL(device->conn, def) < 0)
 goto cleanup;
 
+if (nodeDeviceUpdateCaps(def) < 0)
+goto cleanup;
+
 for (caps = def->caps; caps && ncaps < maxnames; caps = caps->next) {
 if (VIR_STRDUP(names[ncaps++], 
virNodeDevCapTypeToString(caps->data.type)) < 0)
 goto cleanup;
-- 
1.9.1

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


[libvirt] [PATCH 1/3] nodedev: add macro guard to node_device_udev header file

2018-01-10 Thread Wu Zongyong
Signed-off-by: Wu Zongyong <cordius...@huawei.com>
---
 src/node_device/node_device_udev.h | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/node_device/node_device_udev.h 
b/src/node_device/node_device_udev.h
index f15e520..300f57e 100644
--- a/src/node_device/node_device_udev.h
+++ b/src/node_device/node_device_udev.h
@@ -19,10 +19,15 @@
  *
  * Author: Dave Allan <dal...@redhat.com>
  */
+#ifndef __VIR_NODE_DEVICE_UDEV_H__
+# define __VIR_NODE_DEVICE_UDEV_H__
 
-#include 
-#include 
+# include 
+# include 
 
-#define SYSFS_DATA_SIZE 4096
-#define DMI_DEVPATH "/sys/devices/virtual/dmi/id"
-#define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id"
+# define SYSFS_DATA_SIZE 4096
+# define DMI_DEVPATH "/sys/devices/virtual/dmi/id"
+# define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id"
+
+
+#endif /* __VIR_NODE_DEVICE_UDEV_H__ */
-- 
1.9.1

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


[libvirt] [PATCH 2/3] nodedev: update mdev_types caps before dumpxml

2018-01-10 Thread Wu Zongyong
In current implemention, mdev_types caps keep constant all
the time. But, it is possible that a device capable of
mdev_types sometime(for example:bind to proper driver) and
incapable of mdev_types at other times(for example: unbind
from its driver).
We should keep the info of xml dumped out consistent with
real status of the device.

Signed-off-by: Wu Zongyong <cordius...@huawei.com>
---
 src/node_device/node_device_linux_sysfs.c | 22 ++
 src/node_device/node_device_udev.c| 37 ++-
 src/node_device/node_device_udev.h|  3 +++
 3 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/src/node_device/node_device_linux_sysfs.c 
b/src/node_device/node_device_linux_sysfs.c
index 6f438e5..388ffb4 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -29,6 +29,7 @@
 #include "dirname.h"
 #include "node_device_driver.h"
 #include "node_device_hal.h"
+#include "node_device_udev.h"
 #include "node_device_linux_sysfs.h"
 #include "virerror.h"
 #include "viralloc.h"
@@ -175,6 +176,25 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr 
pci_dev)
 return ret;
 }
 
+static int
+nodeDeviceSysfsGetPCIMdevTypesCaps(const char *sysfsPath,
+   virNodeDevCapPCIDevPtr pci_dev)
+{
+size_t i;
+
+/* this could be a refresh, so clear out the old data */
+for (i = 0; i < pci_dev->nmdev_types; i++)
+virNodeDevCapMdevTypeFree(pci_dev->mdev_types[i]);
+VIR_FREE(pci_dev->mdev_types);
+pci_dev->nmdev_types = 0;
+pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
+
+if (udevPCISysfsGetMdevTypesCap(sysfsPath, pci_dev) < 0)
+return -1;
+
+return 0;
+}
+
 
 /* nodeDeviceSysfsGetPCIRelatedCaps() get info that is stored in sysfs
  * about devices related to this device, i.e. things that can change
@@ -190,6 +210,8 @@ nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath,
 return -1;
 if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(pci_dev) < 0)
 return -1;
+if (nodeDeviceSysfsGetPCIMdevTypesCaps(sysfsPath, pci_dev) < 0)
+return -1;
 return 0;
 }
 
diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index e0fca61..7b0014e 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -506,6 +506,37 @@ udevPCIGetMdevTypesCap(struct udev_device *device,
 }
 
 
+int
+udevPCISysfsGetMdevTypesCap(const char *sysfsPath,
+virNodeDevCapPCIDevPtr pci_dev)
+{
+int ret = -1;
+struct udev *udev = NULL;
+struct udev_device *device = NULL;
+udevEventDataPtr priv = driver->privateData;
+
+virObjectLock(priv);
+udev = udev_monitor_get_udev(priv->udev_monitor);
+device = udev_device_new_from_syspath(udev, sysfsPath);
+virObjectUnlock(priv);
+
+if (!device) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("failed to create udev device from path %s"),
+   sysfsPath);
+goto cleanup;
+}
+
+if (udevPCIGetMdevTypesCap(device, pci_dev) < 0)
+goto cleanup;
+
+ret = 0;
+ cleanup:
+udev_device_unref(device);
+return ret;
+}
+
+
 static int
 udevProcessPCI(struct udev_device *device,
virNodeDeviceDefPtr def)
@@ -597,12 +628,6 @@ udevProcessPCI(struct udev_device *device,
 }
 }
 
-/* check whether the device is mediated devices framework capable, if so,
- * process it
- */
-if (udevPCIGetMdevTypesCap(device, pci_dev) < 0)
-goto cleanup;
-
 ret = 0;
 
  cleanup:
diff --git a/src/node_device/node_device_udev.h 
b/src/node_device/node_device_udev.h
index 300f57e..bbdc70f 100644
--- a/src/node_device/node_device_udev.h
+++ b/src/node_device/node_device_udev.h
@@ -29,5 +29,8 @@
 # define DMI_DEVPATH "/sys/devices/virtual/dmi/id"
 # define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id"
 
+int
+udevPCISysfsGetMdevTypesCap(const char *sysfsPath, virNodeDevCapPCIDevPtr 
pci_dev);
+
 
 #endif /* __VIR_NODE_DEVICE_UDEV_H__ */
-- 
1.9.1

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


[libvirt] [PATCH v2] nodedev: update mdev_types caps before dumpxml

2018-01-08 Thread Wu Zongyong
In current implemention, mdev_types caps keep constant all
the time. But, it is possible that a device capable of
mdev_types sometime(for example:bind to proper driver) and
incapable of mdev_types at other times(for example: unbind
from its driver).
We should keep the info of xml dumped out consistent with
real status of the device.

Signed-off-by: Wu Zongyong <cordius...@huawei.com>
---

v2:
- fix mistakes pointed out by Erik

 src/node_device/node_device_linux_sysfs.c | 21 +
 src/node_device/node_device_udev.c| 29 +
 src/node_device/node_device_udev.h| 18 +-
 3 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/src/node_device/node_device_linux_sysfs.c 
b/src/node_device/node_device_linux_sysfs.c
index 6f438e5..8b00aff 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -29,6 +29,7 @@
 #include "dirname.h"
 #include "node_device_driver.h"
 #include "node_device_hal.h"
+#include "node_device_udev.h"
 #include "node_device_linux_sysfs.h"
 #include "virerror.h"
 #include "viralloc.h"
@@ -175,6 +176,24 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr 
pci_dev)
 return ret;
 }
 
+static int
+nodeDeviceSysfsGetPCIMdevTypesCaps(const char *sysfsPath,
+   virNodeDevCapPCIDevPtr pci_dev)
+{
+size_t i;
+
+/* this could be a refresh, so clear out the old data */
+for (i = 0; i < pci_dev->nmdev_types; i++)
+virNodeDevCapMdevTypeFree(pci_dev->mdev_types[i]);
+VIR_FREE(pci_dev->mdev_types);
+pci_dev->nmdev_types = 0;
+
+if (udevPCISysfsGetMdevTypesCap(sysfsPath, pci_dev) < 0)
+return -1;
+
+return 0;
+}
+
 
 /* nodeDeviceSysfsGetPCIRelatedCaps() get info that is stored in sysfs
  * about devices related to this device, i.e. things that can change
@@ -190,6 +209,8 @@ nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath,
 return -1;
 if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(pci_dev) < 0)
 return -1;
+if (nodeDeviceSysfsGetPCIMdevTypesCaps(sysfsPath, pci_dev) < 0)
+return -1;
 return 0;
 }
 
diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index e0fca61..781facf 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -506,6 +506,35 @@ udevPCIGetMdevTypesCap(struct udev_device *device,
 }
 
 
+int
+udevPCISysfsGetMdevTypesCap(const char *sysfsPath,
+virNodeDevCapPCIDevPtr pci_dev)
+{
+int ret = -1;
+udevEventDataPtr priv = NULL;
+struct udev *udev = NULL;
+struct udev_device *device = NULL;
+
+priv = driver->privateData;
+udev = udev_monitor_get_udev(priv->udev_monitor);
+device = udev_device_new_from_syspath(udev, sysfsPath);
+if (!device) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("failed to create udev device from path %s"),
+   sysfsPath);
+goto cleanup;
+}
+
+if (udevPCIGetMdevTypesCap(device, pci_dev) < 0)
+goto cleanup;
+
+ret = 0;
+ cleanup:
+udev_device_unref(device);
+return ret;
+}
+
+
 static int
 udevProcessPCI(struct udev_device *device,
virNodeDeviceDefPtr def)
diff --git a/src/node_device/node_device_udev.h 
b/src/node_device/node_device_udev.h
index f15e520..bbdc70f 100644
--- a/src/node_device/node_device_udev.h
+++ b/src/node_device/node_device_udev.h
@@ -19,10 +19,18 @@
  *
  * Author: Dave Allan <dal...@redhat.com>
  */
+#ifndef __VIR_NODE_DEVICE_UDEV_H__
+# define __VIR_NODE_DEVICE_UDEV_H__
 
-#include 
-#include 
+# include 
+# include 
 
-#define SYSFS_DATA_SIZE 4096
-#define DMI_DEVPATH "/sys/devices/virtual/dmi/id"
-#define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id"
+# define SYSFS_DATA_SIZE 4096
+# define DMI_DEVPATH "/sys/devices/virtual/dmi/id"
+# define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id"
+
+int
+udevPCISysfsGetMdevTypesCap(const char *sysfsPath, virNodeDevCapPCIDevPtr 
pci_dev);
+
+
+#endif /* __VIR_NODE_DEVICE_UDEV_H__ */
-- 
1.8.3.1

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


[libvirt] [PATCH] nodedev: update mdev_types caps before dumpxml

2017-12-26 Thread Wu Zongyong
In current implemention, mdev_types caps keep constant all
the time. But, it is possible that a device capable of
mdev_types sometime(for example:bind to proper driver) and
incapable of mdev_types at other times(for example: unbind
from its driver).
We should keep the info of xml dumped out consistent with
real status of the device.
---
 src/node_device/node_device_linux_sysfs.c | 42 +++
 src/node_device/node_device_udev.c| 11 ++--
 src/node_device/node_device_udev.h|  8 ++
 3 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/src/node_device/node_device_linux_sysfs.c 
b/src/node_device/node_device_linux_sysfs.c
index 6f438e5..2dc01bf 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -29,6 +29,7 @@
 #include "dirname.h"
 #include "node_device_driver.h"
 #include "node_device_hal.h"
+#include "node_device_udev.h"
 #include "node_device_linux_sysfs.h"
 #include "virerror.h"
 #include "viralloc.h"
@@ -175,6 +176,45 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr 
pci_dev)
 return ret;
 }
 
+static int
+nodeDeviceSysfsGetPCIMdevTypesCaps(const char *sysfsPath,
+   virNodeDevCapPCIDevPtr pci_dev)
+{
+size_t i;
+int ret = -1;
+struct udev *udev = NULL;
+struct udev_device *device = NULL;
+
+/* this could be a refresh, so clear out the old data */
+for (i = 0; i < pci_dev->nmdev_types; i++)
+   VIR_FREE(pci_dev->mdev_types[i]);
+VIR_FREE(pci_dev->mdev_types);
+pci_dev->nmdev_types = 0;
+
+udev = udev_new();
+if (!udev) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("failed to create udev context"));
+goto cleanup;
+}
+device = udev_device_new_from_syspath(udev, sysfsPath);
+if (!device) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("failed to create udev device from path %s"),
+   sysfsPath);
+goto cleanup;
+}
+
+if (udevPCIGetMdevTypesCap(device, pci_dev) < 0)
+goto cleanup;
+
+ret = 0;
+ cleanup:
+udev_device_unref(device);
+udev_unref(udev);
+return ret;
+}
+
 
 /* nodeDeviceSysfsGetPCIRelatedCaps() get info that is stored in sysfs
  * about devices related to this device, i.e. things that can change
@@ -190,6 +230,8 @@ nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath,
 return -1;
 if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(pci_dev) < 0)
 return -1;
+if (nodeDeviceSysfsGetPCIMdevTypesCaps(sysfsPath, pci_dev) < 0)
+return -1;
 return 0;
 }
 
diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index 1e1b717..256bb66 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -432,7 +432,7 @@ udevFillMdevType(struct udev_device *device,
 }
 
 
-static int
+int
 udevPCIGetMdevTypesCap(struct udev_device *device,
virNodeDevCapPCIDevPtr pcidata)
 {
@@ -599,8 +599,15 @@ udevProcessPCI(struct udev_device *device,
 
 /* check whether the device is mediated devices framework capable, if so,
  * process it
+ *
+ * UDEV doesn't report attributes under subdirectories by default but is
+ * able to query them if the path to the attribute is relative to the
+ * device's base path, e.g. /sys/devices/../:00:01.0/ is the device's
+ * base path as udev reports it, but we're interested in attributes under
+ * /sys/devices/../:00:01.0/mdev_supported_types//. So, we need 
to
+ * scan the subdirectories ourselves.
  */
-if (udevPCIGetMdevTypesCap(device, pci_dev) < 0)
+if (udevPCIGetMdevTypesCap(udev_device_get_syspath(device), pci_dev) < 0)
 goto cleanup;
 
 ret = 0;
diff --git a/src/node_device/node_device_udev.h 
b/src/node_device/node_device_udev.h
index f15e520..9f78289 100644
--- a/src/node_device/node_device_udev.h
+++ b/src/node_device/node_device_udev.h
@@ -19,6 +19,8 @@
  *
  * Author: Dave Allan 
  */
+#ifndef __VIR_NODE_DEVICE_UDEV_H__
+#define __VIR_NODE_DEVICE_UDEV_H__
 
 #include 
 #include 
@@ -26,3 +28,9 @@
 #define SYSFS_DATA_SIZE 4096
 #define DMI_DEVPATH "/sys/devices/virtual/dmi/id"
 #define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id"
+
+int
+udevPCIGetMdevTypesCap(struct udev_device *device, virNodeDevCapPCIDevPtr 
pcidata);
+
+
+#endif /* __VIR_NODE_DEVICE_UDEV_H__ */
-- 
1.9.1

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


[libvirt] [PATCH] nodedev: update mdev_types caps before dumpxml

2017-12-26 Thread Wu Zongyong
Wu Zongyong (1):
  nodedev: update mdev_types caps before dumpxml

 src/node_device/node_device_linux_sysfs.c | 42 +++
 src/node_device/node_device_udev.c| 11 ++--
 src/node_device/node_device_udev.h|  8 ++
 3 files changed, 59 insertions(+), 2 deletions(-)

-- 
1.9.1

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


[libvirt] [PATCH] Fix the incorrect memory freeing which will result in crash

2017-01-06 Thread Wu Zongyong
The number of elements in new_params is equal to the length of info,
instead of nparams, so it's wrong to free new_params using nparams.

Signed-off-by: Wu Zongyong <wuzon...@mail.ustc.edu.cn>
---
 libvirt-override.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libvirt-override.c b/libvirt-override.c
index db14244..dac4250 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -632,7 +632,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self 
ATTRIBUTE_UNUSED,
 int nparams = 0;
 Py_ssize_t size = 0;
 unsigned int flags;
-virTypedParameterPtr params, new_params = NULL;
+virTypedParameterPtr params = NULL, new_params = NULL;
 
 if (!PyArg_ParseTuple(args,
   (char *)"OOI:virDomainSetScedulerParametersFlags",
@@ -694,7 +694,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self 
ATTRIBUTE_UNUSED,
 
  cleanup:
 virTypedParamsFree(params, nparams);
-virTypedParamsFree(new_params, nparams);
+virTypedParamsFree(new_params, size);
 return ret;
 }
 
@@ -7682,7 +7682,7 @@ libvirt_virNodeSetMemoryParameters(PyObject *self 
ATTRIBUTE_UNUSED,
 int nparams = 0;
 Py_ssize_t size = 0;
 unsigned int flags;
-virTypedParameterPtr params, new_params = NULL;
+virTypedParameterPtr params = NULL, new_params = NULL;
 
 if (!PyArg_ParseTuple(args,
   (char *)"OOI:virNodeSetMemoryParameters",
@@ -7741,7 +7741,7 @@ libvirt_virNodeSetMemoryParameters(PyObject *self 
ATTRIBUTE_UNUSED,
 
  cleanup:
 virTypedParamsFree(params, nparams);
-virTypedParamsFree(new_params, nparams);
+virTypedParamsFree(new_params, size);
 return ret;
 }
 
-- 
2.10.0.windows.1


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