提交 95ea171b 编写于 作者: J John Ferlan

nodedev: Create helper for finding by name in driver

Create nodeDeviceObjFindByName which will perform the corresponding
virNodeDeviceObjFindByName call for various node_device_driver callers
rather than having the same repetitive code.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 7c40ed4a
...@@ -235,12 +235,10 @@ nodeConnectListAllNodeDevices(virConnectPtr conn, ...@@ -235,12 +235,10 @@ nodeConnectListAllNodeDevices(virConnectPtr conn,
} }
virNodeDevicePtr static virNodeDeviceObjPtr
nodeDeviceLookupByName(virConnectPtr conn, nodeDeviceObjFindByName(const char *name)
const char *name)
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDevicePtr ret = NULL;
nodeDeviceLock(); nodeDeviceLock();
obj = virNodeDeviceObjFindByName(&driver->devs, name); obj = virNodeDeviceObjFindByName(&driver->devs, name);
...@@ -250,9 +248,22 @@ nodeDeviceLookupByName(virConnectPtr conn, ...@@ -250,9 +248,22 @@ nodeDeviceLookupByName(virConnectPtr conn,
virReportError(VIR_ERR_NO_NODE_DEVICE, virReportError(VIR_ERR_NO_NODE_DEVICE,
_("no node device with matching name '%s'"), _("no node device with matching name '%s'"),
name); name);
goto cleanup;
} }
return obj;
}
virNodeDevicePtr
nodeDeviceLookupByName(virConnectPtr conn,
const char *name)
{
virNodeDeviceObjPtr obj;
virNodeDevicePtr ret = NULL;
if (!(obj = nodeDeviceObjFindByName(name)))
return NULL;
if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0) if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0)
goto cleanup; goto cleanup;
...@@ -264,8 +275,7 @@ nodeDeviceLookupByName(virConnectPtr conn, ...@@ -264,8 +275,7 @@ nodeDeviceLookupByName(virConnectPtr conn,
} }
cleanup: cleanup:
if (obj) virNodeDeviceObjUnlock(obj);
virNodeDeviceObjUnlock(obj);
return ret; return ret;
} }
...@@ -338,16 +348,8 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, ...@@ -338,16 +348,8 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
nodeDeviceLock(); if (!(obj = nodeDeviceObjFindByName(dev->name)))
obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); return NULL;
nodeDeviceUnlock();
if (!obj) {
virReportError(VIR_ERR_NO_NODE_DEVICE,
_("no node device with matching name '%s'"),
dev->name);
goto cleanup;
}
if (virNodeDeviceGetXMLDescEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceGetXMLDescEnsureACL(dev->conn, obj->def) < 0)
goto cleanup; goto cleanup;
...@@ -361,8 +363,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, ...@@ -361,8 +363,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
ret = virNodeDeviceDefFormat(obj->def); ret = virNodeDeviceDefFormat(obj->def);
cleanup: cleanup:
if (obj) virNodeDeviceObjUnlock(obj);
virNodeDeviceObjUnlock(obj);
return ret; return ret;
} }
...@@ -373,16 +374,8 @@ nodeDeviceGetParent(virNodeDevicePtr dev) ...@@ -373,16 +374,8 @@ nodeDeviceGetParent(virNodeDevicePtr dev)
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
char *ret = NULL; char *ret = NULL;
nodeDeviceLock(); if (!(obj = nodeDeviceObjFindByName(dev->name)))
obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); return NULL;
nodeDeviceUnlock();
if (!obj) {
virReportError(VIR_ERR_NO_NODE_DEVICE,
_("no node device with matching name '%s'"),
dev->name);
goto cleanup;
}
if (virNodeDeviceGetParentEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceGetParentEnsureACL(dev->conn, obj->def) < 0)
goto cleanup; goto cleanup;
...@@ -396,8 +389,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev) ...@@ -396,8 +389,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev)
} }
cleanup: cleanup:
if (obj) virNodeDeviceObjUnlock(obj);
virNodeDeviceObjUnlock(obj);
return ret; return ret;
} }
...@@ -410,16 +402,8 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) ...@@ -410,16 +402,8 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev)
int ncaps = 0; int ncaps = 0;
int ret = -1; int ret = -1;
nodeDeviceLock(); if (!(obj = nodeDeviceObjFindByName(dev->name)))
obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); return -1;
nodeDeviceUnlock();
if (!obj) {
virReportError(VIR_ERR_NO_NODE_DEVICE,
_("no node device with matching name '%s'"),
dev->name);
goto cleanup;
}
if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, obj->def) < 0)
goto cleanup; goto cleanup;
...@@ -441,8 +425,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) ...@@ -441,8 +425,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev)
ret = ncaps; ret = ncaps;
cleanup: cleanup:
if (obj) virNodeDeviceObjUnlock(obj);
virNodeDeviceObjUnlock(obj);
return ret; return ret;
} }
...@@ -458,16 +441,8 @@ nodeDeviceListCaps(virNodeDevicePtr dev, ...@@ -458,16 +441,8 @@ nodeDeviceListCaps(virNodeDevicePtr dev,
int ncaps = 0; int ncaps = 0;
int ret = -1; int ret = -1;
nodeDeviceLock(); if (!(obj = nodeDeviceObjFindByName(dev->name)))
obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); return -1;
nodeDeviceUnlock();
if (!obj) {
virReportError(VIR_ERR_NO_NODE_DEVICE,
_("no node device with matching name '%s'"),
dev->name);
goto cleanup;
}
if (virNodeDeviceListCapsEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceListCapsEnsureACL(dev->conn, obj->def) < 0)
goto cleanup; goto cleanup;
...@@ -497,8 +472,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, ...@@ -497,8 +472,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev,
ret = ncaps; ret = ncaps;
cleanup: cleanup:
if (obj) virNodeDeviceObjUnlock(obj);
virNodeDeviceObjUnlock(obj);
if (ret == -1) { if (ret == -1) {
--ncaps; --ncaps;
while (--ncaps >= 0) while (--ncaps >= 0)
...@@ -635,13 +609,10 @@ nodeDeviceDestroy(virNodeDevicePtr dev) ...@@ -635,13 +609,10 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
char *wwnn = NULL, *wwpn = NULL; char *wwnn = NULL, *wwpn = NULL;
int parent_host = -1; int parent_host = -1;
if (!(obj = nodeDeviceObjFindByName(dev->name)))
return -1;
nodeDeviceLock(); nodeDeviceLock();
if (!(obj = virNodeDeviceObjFindByName(&driver->devs, dev->name))) {
virReportError(VIR_ERR_NO_NODE_DEVICE,
_("no node device with matching name '%s'"),
dev->name);
goto cleanup;
}
if (virNodeDeviceDestroyEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceDestroyEnsureACL(dev->conn, obj->def) < 0)
goto cleanup; goto cleanup;
...@@ -667,8 +638,7 @@ nodeDeviceDestroy(virNodeDevicePtr dev) ...@@ -667,8 +638,7 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
cleanup: cleanup:
nodeDeviceUnlock(); nodeDeviceUnlock();
if (obj) virNodeDeviceObjUnlock(obj);
virNodeDeviceObjUnlock(obj);
VIR_FREE(wwnn); VIR_FREE(wwnn);
VIR_FREE(wwpn); VIR_FREE(wwpn);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册