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@xxxxxxxxxx> --- 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@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list