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.wu@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, &devices, 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(&obj);
+ goto cleanup;
+ }
+
+ virNodeDeviceObjEndAPI(&obj);
+ }
+
+ 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
On Wed, Jan 10, 2018 at 08:14:51PM +0800, Wu Zongyong wrote: > 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.wu@huawei.com> > --- Thank you for posting the patch, since I hadn't noticed the problem with other APIs until I read it. It was a sad realization that a driver change is not reflected by a udev/kernel CHANGE event, that would make things much much simpler. I have an idea to either make this patch shorter or not needed at all though, we'll see when I finish my patch (it's a long-needed refactor). Despite I haven't found any major flaws in this patch, let's just put it on hold for a while until I finish my investigation/work on my patch and see we can really do better here. Thanks, Erik -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
It is a bit inefficient about my patch, and it is imperfect. I wish to see a better idea to fix this problem. And again, thank you for your correction to my patches. Thanks, Zongyong Wu > -----Original Message----- > From: Erik Skultety [mailto:eskultet@redhat.com] > Sent: Thursday, January 11, 2018 6:16 PM > To: Wuzongyong (Euler Dept) <cordius.wu@huawei.com> > Cc: libvir-list@redhat.com; weijinfen <weijinfen@huawei.com>; Wanzongshun > (Vincent) <wanzongshun@huawei.com> > Subject: Re: [PATCH 3/3] nodedev: update caps before invoking nodedev > driver interfaces > > On Wed, Jan 10, 2018 at 08:14:51PM +0800, Wu Zongyong wrote: > > 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.wu@huawei.com> > > --- > > Thank you for posting the patch, since I hadn't noticed the problem with > other APIs until I read it. > It was a sad realization that a driver change is not reflected by a > udev/kernel CHANGE event, that would make things much much simpler. I have > an idea to either make this patch shorter or not needed at all though, > we'll see when I finish my patch (it's a long-needed refactor). Despite I > haven't found any major flaws in this patch, let's just put it on hold for > a while until I finish my investigation/work on my patch and see we can > really do better here. > > Thanks, > Erik -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.