mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 11:01:19 +00:00
Merge all return paths from node device driver APIs
This commit is contained in:
parent
04a31e99fc
commit
e8a4ea75a3
@ -1,3 +1,11 @@
|
|||||||
|
Thu Dec 4 21:46:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/libvirt.c, src/datatypes.h, src/datatypes.c: Cache
|
||||||
|
device parent string to workaround need to keep public
|
||||||
|
virNodeDeviceGetParent API returning a const string
|
||||||
|
* src/node_device.c: Merge all return paths from node
|
||||||
|
device driver APIs
|
||||||
|
|
||||||
Thu Dec 4 21:43:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
Thu Dec 4 21:43:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/openvz_conf.h: Add driver lock
|
* src/openvz_conf.h: Add driver lock
|
||||||
|
@ -861,6 +861,7 @@ virReleaseNodeDevice(virNodeDevicePtr dev) {
|
|||||||
|
|
||||||
dev->magic = -1;
|
dev->magic = -1;
|
||||||
VIR_FREE(dev->name);
|
VIR_FREE(dev->name);
|
||||||
|
VIR_FREE(dev->parent);
|
||||||
VIR_FREE(dev);
|
VIR_FREE(dev);
|
||||||
|
|
||||||
DEBUG("unref connection %p %d", conn, conn->refs);
|
DEBUG("unref connection %p %d", conn, conn->refs);
|
||||||
|
@ -199,6 +199,7 @@ struct _virNodeDevice {
|
|||||||
int refs; /* reference count */
|
int refs; /* reference count */
|
||||||
virConnectPtr conn; /* pointer back to the connection */
|
virConnectPtr conn; /* pointer back to the connection */
|
||||||
char *name; /* device name (unique on node) */
|
char *name; /* device name (unique on node) */
|
||||||
|
char *parent; /* parent device name */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -5689,11 +5689,15 @@ const char *virNodeDeviceGetParent(virNodeDevicePtr dev)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev->conn->deviceMonitor && dev->conn->deviceMonitor->deviceGetParent)
|
if (!dev->parent) {
|
||||||
return dev->conn->deviceMonitor->deviceGetParent (dev);
|
if (dev->conn->deviceMonitor && dev->conn->deviceMonitor->deviceGetParent) {
|
||||||
|
dev->parent = dev->conn->deviceMonitor->deviceGetParent (dev);
|
||||||
|
} else {
|
||||||
virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dev->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,66 +91,86 @@ static virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn,
|
|||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
|
virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
|
||||||
virNodeDeviceObjPtr obj = virNodeDeviceFindByName(&driver->devs, name);
|
virNodeDeviceObjPtr obj;
|
||||||
|
virNodeDevicePtr ret = NULL;
|
||||||
|
|
||||||
|
obj = virNodeDeviceFindByName(&driver->devs, name);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
virNodeDeviceReportError(conn, VIR_ERR_INVALID_NODE_DEVICE,
|
virNodeDeviceReportError(conn, VIR_ERR_INVALID_NODE_DEVICE,
|
||||||
"%s", _("no node device with matching name"));
|
"%s", _("no node device with matching name"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virGetNodeDevice(conn, name);
|
ret = virGetNodeDevice(conn, name);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *nodeDeviceDumpXML(virNodeDevicePtr dev,
|
static char *nodeDeviceDumpXML(virNodeDevicePtr dev,
|
||||||
unsigned int flags ATTRIBUTE_UNUSED)
|
unsigned int flags ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
||||||
virNodeDeviceObjPtr obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
virNodeDeviceObjPtr obj;
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
||||||
"%s", _("no node device with matching name"));
|
"%s", _("no node device with matching name"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virNodeDeviceDefFormat(dev->conn, obj->def);
|
ret = virNodeDeviceDefFormat(dev->conn, obj->def);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *nodeDeviceGetParent(virNodeDevicePtr dev)
|
static char *nodeDeviceGetParent(virNodeDevicePtr dev)
|
||||||
{
|
{
|
||||||
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
||||||
virNodeDeviceObjPtr obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
virNodeDeviceObjPtr obj;
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
||||||
"%s", _("no node device with matching name"));
|
"%s", _("no node device with matching name"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj->def->parent;
|
ret = strdup(obj->def->parent);
|
||||||
|
if (!ret)
|
||||||
|
virNodeDeviceReportError(dev->conn, VIR_ERR_NO_MEMORY, NULL);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int nodeDeviceNumOfCaps(virNodeDevicePtr dev)
|
static int nodeDeviceNumOfCaps(virNodeDevicePtr dev)
|
||||||
{
|
{
|
||||||
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
||||||
virNodeDeviceObjPtr obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
virNodeDeviceObjPtr obj;
|
||||||
virNodeDevCapsDefPtr caps;
|
virNodeDevCapsDefPtr caps;
|
||||||
int ncaps = 0;
|
int ncaps = 0;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
||||||
"%s", _("no node device with matching name"));
|
"%s", _("no node device with matching name"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (caps = obj->def->caps; caps; caps = caps->next)
|
for (caps = obj->def->caps; caps; caps = caps->next)
|
||||||
++ncaps;
|
++ncaps;
|
||||||
|
ret = ncaps;
|
||||||
|
|
||||||
return ncaps;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -158,29 +178,32 @@ static int
|
|||||||
nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
|
nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
|
||||||
{
|
{
|
||||||
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData;
|
||||||
virNodeDeviceObjPtr obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
virNodeDeviceObjPtr obj;
|
||||||
virNodeDevCapsDefPtr caps;
|
virNodeDevCapsDefPtr caps;
|
||||||
int ncaps = 0;
|
int ncaps = 0;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
virNodeDeviceReportError(dev->conn, VIR_ERR_INVALID_NODE_DEVICE,
|
||||||
"%s", _("no node device with matching name"));
|
"%s", _("no node device with matching name"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
|
for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
|
||||||
names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type));
|
names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type));
|
||||||
if (names[ncaps++] == NULL)
|
if (names[ncaps++] == NULL)
|
||||||
goto failure;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ret = ncaps;
|
||||||
|
|
||||||
return ncaps;
|
cleanup:
|
||||||
|
if (ret == -1) {
|
||||||
failure:
|
|
||||||
--ncaps;
|
--ncaps;
|
||||||
while (--ncaps >= 0)
|
while (--ncaps >= 0)
|
||||||
VIR_FREE(names[ncaps]);
|
VIR_FREE(names[ncaps]);
|
||||||
return -1;
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user