提交 2a862092 编写于 作者: M Michal Privoznik

testNodeDeviceMockCreateVport: Don't call public APIs

This function is calling public APIs (virNodeDeviceLookupByName
etc.). That requires the driver lock to be unlocked and locked
again. If we, however, replace the public APIs calls with the
internal calls (that public APIs call anyway), we can drop the
lock/unlock exercise.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 ca1f3854
...@@ -5626,17 +5626,15 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) ...@@ -5626,17 +5626,15 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
} }
static virNodeDeviceDefPtr static virNodeDeviceObjPtr
testNodeDeviceMockCreateVport(virConnectPtr conn, testNodeDeviceMockCreateVport(testDriverPtr driver,
const char *wwnn, const char *wwnn,
const char *wwpn) const char *wwpn)
{ {
testDriverPtr driver = conn->privateData;
virNodeDevicePtr devcpy = NULL;
char *xml = NULL; char *xml = NULL;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
virNodeDevCapsDefPtr caps; virNodeDevCapsDefPtr caps;
virNodeDeviceObjPtr obj = NULL; virNodeDeviceObjPtr obj = NULL, objcopy = NULL;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
/* In the real code, we'd call virVHBAManageVport which would take the /* In the real code, we'd call virVHBAManageVport which would take the
...@@ -5648,9 +5646,15 @@ testNodeDeviceMockCreateVport(virConnectPtr conn, ...@@ -5648,9 +5646,15 @@ testNodeDeviceMockCreateVport(virConnectPtr conn,
* using the scsi_host11 definition, changing the name and the * using the scsi_host11 definition, changing the name and the
* scsi_host capability fields before calling virNodeDeviceAssignDef * scsi_host capability fields before calling virNodeDeviceAssignDef
* to add the def to the node device objects list. */ * to add the def to the node device objects list. */
if (!(devcpy = virNodeDeviceLookupByName(conn, "scsi_host11")) || if (!(objcopy = virNodeDeviceFindByName(&driver->devs, "scsi_host11")))
!(xml = virNodeDeviceGetXMLDesc(devcpy, 0)) || goto cleanup;
!(def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL)))
xml = virNodeDeviceDefFormat(objcopy->def);
virNodeDeviceObjUnlock(objcopy);
if (!xml)
goto cleanup;
if (!(def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL)))
goto cleanup; goto cleanup;
VIR_FREE(def->name); VIR_FREE(def->name);
...@@ -5684,23 +5688,17 @@ testNodeDeviceMockCreateVport(virConnectPtr conn, ...@@ -5684,23 +5688,17 @@ testNodeDeviceMockCreateVport(virConnectPtr conn,
if (!(obj = virNodeDeviceAssignDef(&driver->devs, def))) if (!(obj = virNodeDeviceAssignDef(&driver->devs, def)))
goto cleanup; goto cleanup;
virNodeDeviceObjUnlock(obj); def = NULL;
event = virNodeDeviceEventLifecycleNew(def->name, event = virNodeDeviceEventLifecycleNew(obj->def->name,
VIR_NODE_DEVICE_EVENT_CREATED, VIR_NODE_DEVICE_EVENT_CREATED,
0); 0);
testObjectEventQueue(driver, event); testObjectEventQueue(driver, event);
cleanup: cleanup:
VIR_FREE(xml); VIR_FREE(xml);
if (!obj) {
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
def = NULL; return obj;
}
if (devcpy)
virNodeDeviceFree(devcpy);
return def;
} }
...@@ -5712,8 +5710,8 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -5712,8 +5710,8 @@ testNodeDeviceCreateXML(virConnectPtr conn,
testDriverPtr driver = conn->privateData; testDriverPtr driver = conn->privateData;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
char *wwnn = NULL, *wwpn = NULL; char *wwnn = NULL, *wwpn = NULL;
virNodeDevicePtr dev = NULL; virNodeDevicePtr dev = NULL, ret = NULL;
virNodeDeviceDefPtr newdef = NULL; virNodeDeviceObjPtr obj = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
...@@ -5739,20 +5737,28 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -5739,20 +5737,28 @@ testNodeDeviceCreateXML(virConnectPtr conn,
* mocking udev. The mock routine will copy an existing vHBA and * mocking udev. The mock routine will copy an existing vHBA and
* rename a few fields to mock that. So in order to allow that to * rename a few fields to mock that. So in order to allow that to
* work properly, we need to drop our lock */ * work properly, we need to drop our lock */
testDriverUnlock(driver); if (!(obj = testNodeDeviceMockCreateVport(driver, wwnn, wwpn)))
if ((newdef = testNodeDeviceMockCreateVport(conn, wwnn, wwpn))) { goto cleanup;
if ((dev = virNodeDeviceLookupByName(conn, newdef->name)))
ignore_value(VIR_STRDUP(dev->parent, def->parent)); if (!(dev = virGetNodeDevice(conn, obj->def->name)))
} goto cleanup;
testDriverLock(driver);
newdef = NULL; VIR_FREE(dev->parent);
if (VIR_STRDUP(dev->parent, def->parent) < 0)
goto cleanup;
ret = dev;
dev = NULL;
cleanup: cleanup:
if (obj)
virNodeDeviceObjUnlock(obj);
testDriverUnlock(driver); testDriverUnlock(driver);
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
virObjectUnref(dev);
VIR_FREE(wwnn); VIR_FREE(wwnn);
VIR_FREE(wwpn); VIR_FREE(wwpn);
return dev; return ret;
} }
static int static int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册