mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-23 11:52:20 +00:00
Release conn lock before reporting errors (end)
* src/datatypes.c: more cleanup, where lock must be released before calling error handling which tries to get it.
This commit is contained in:
parent
335f6bc251
commit
647247740f
@ -270,11 +270,13 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
/* TODO check the UUID */
|
/* TODO check the UUID */
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
if (VIR_ALLOC(ret) < 0) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ret->name = strdup(name);
|
ret->name = strdup(name);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -285,6 +287,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
||||||
|
|
||||||
if (virHashAddEntry(conn->domains, name, ret) < 0) {
|
if (virHashAddEntry(conn->domains, name, ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("failed to add domain to connection hash table"));
|
_("failed to add domain to connection hash table"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -299,7 +302,6 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
return(ret);
|
return(ret);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virMutexUnlock(&conn->lock);
|
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
VIR_FREE(ret->name);
|
VIR_FREE(ret->name);
|
||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
@ -325,15 +327,19 @@ virReleaseDomain(virDomainPtr domain) {
|
|||||||
DEBUG("release domain %p %s", domain, domain->name);
|
DEBUG("release domain %p %s", domain, domain->name);
|
||||||
|
|
||||||
/* TODO search by UUID first as they are better differenciators */
|
/* TODO search by UUID first as they are better differenciators */
|
||||||
if (virHashRemoveEntry(conn->domains, domain->name, NULL) < 0)
|
if (virHashRemoveEntry(conn->domains, domain->name, NULL) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("domain missing from connection hash table"));
|
_("domain missing from connection hash table"));
|
||||||
|
conn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
domain->magic = -1;
|
domain->magic = -1;
|
||||||
domain->id = -1;
|
domain->id = -1;
|
||||||
VIR_FREE(domain->name);
|
VIR_FREE(domain->name);
|
||||||
VIR_FREE(domain);
|
VIR_FREE(domain);
|
||||||
|
|
||||||
|
if (conn) {
|
||||||
DEBUG("unref connection %p %d", conn, conn->refs);
|
DEBUG("unref connection %p %d", conn, conn->refs);
|
||||||
conn->refs--;
|
conn->refs--;
|
||||||
if (conn->refs == 0) {
|
if (conn->refs == 0) {
|
||||||
@ -341,9 +347,9 @@ virReleaseDomain(virDomainPtr domain) {
|
|||||||
/* Already unlocked mutex */
|
/* Already unlocked mutex */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&conn->lock);
|
virMutexUnlock(&conn->lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -406,11 +412,13 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
/* TODO check the UUID */
|
/* TODO check the UUID */
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
if (VIR_ALLOC(ret) < 0) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ret->name = strdup(name);
|
ret->name = strdup(name);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -420,6 +428,7 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
||||||
|
|
||||||
if (virHashAddEntry(conn->networks, name, ret) < 0) {
|
if (virHashAddEntry(conn->networks, name, ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("failed to add network to connection hash table"));
|
_("failed to add network to connection hash table"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -431,7 +440,6 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
return(ret);
|
return(ret);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virMutexUnlock(&conn->lock);
|
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
VIR_FREE(ret->name);
|
VIR_FREE(ret->name);
|
||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
@ -457,14 +465,18 @@ virReleaseNetwork(virNetworkPtr network) {
|
|||||||
DEBUG("release network %p %s", network, network->name);
|
DEBUG("release network %p %s", network, network->name);
|
||||||
|
|
||||||
/* TODO search by UUID first as they are better differenciators */
|
/* TODO search by UUID first as they are better differenciators */
|
||||||
if (virHashRemoveEntry(conn->networks, network->name, NULL) < 0)
|
if (virHashRemoveEntry(conn->networks, network->name, NULL) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("network missing from connection hash table"));
|
_("network missing from connection hash table"));
|
||||||
|
conn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
network->magic = -1;
|
network->magic = -1;
|
||||||
VIR_FREE(network->name);
|
VIR_FREE(network->name);
|
||||||
VIR_FREE(network);
|
VIR_FREE(network);
|
||||||
|
|
||||||
|
if (conn) {
|
||||||
DEBUG("unref connection %p %d", conn, conn->refs);
|
DEBUG("unref connection %p %d", conn, conn->refs);
|
||||||
conn->refs--;
|
conn->refs--;
|
||||||
if (conn->refs == 0) {
|
if (conn->refs == 0) {
|
||||||
@ -472,9 +484,9 @@ virReleaseNetwork(virNetworkPtr network) {
|
|||||||
/* Already unlocked mutex */
|
/* Already unlocked mutex */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&conn->lock);
|
virMutexUnlock(&conn->lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -714,11 +726,13 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui
|
|||||||
/* TODO check the UUID */
|
/* TODO check the UUID */
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
if (VIR_ALLOC(ret) < 0) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ret->name = strdup(name);
|
ret->name = strdup(name);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -728,6 +742,7 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui
|
|||||||
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
||||||
|
|
||||||
if (virHashAddEntry(conn->storagePools, name, ret) < 0) {
|
if (virHashAddEntry(conn->storagePools, name, ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("failed to add storage pool to connection hash table"));
|
_("failed to add storage pool to connection hash table"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -739,7 +754,6 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui
|
|||||||
return(ret);
|
return(ret);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virMutexUnlock(&conn->lock);
|
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
VIR_FREE(ret->name);
|
VIR_FREE(ret->name);
|
||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
@ -766,14 +780,18 @@ virReleaseStoragePool(virStoragePoolPtr pool) {
|
|||||||
DEBUG("release pool %p %s", pool, pool->name);
|
DEBUG("release pool %p %s", pool, pool->name);
|
||||||
|
|
||||||
/* TODO search by UUID first as they are better differenciators */
|
/* TODO search by UUID first as they are better differenciators */
|
||||||
if (virHashRemoveEntry(conn->storagePools, pool->name, NULL) < 0)
|
if (virHashRemoveEntry(conn->storagePools, pool->name, NULL) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("pool missing from connection hash table"));
|
_("pool missing from connection hash table"));
|
||||||
|
conn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pool->magic = -1;
|
pool->magic = -1;
|
||||||
VIR_FREE(pool->name);
|
VIR_FREE(pool->name);
|
||||||
VIR_FREE(pool);
|
VIR_FREE(pool);
|
||||||
|
|
||||||
|
if (conn) {
|
||||||
DEBUG("unref connection %p %d", conn, conn->refs);
|
DEBUG("unref connection %p %d", conn, conn->refs);
|
||||||
conn->refs--;
|
conn->refs--;
|
||||||
if (conn->refs == 0) {
|
if (conn->refs == 0) {
|
||||||
@ -781,9 +799,9 @@ virReleaseStoragePool(virStoragePoolPtr pool) {
|
|||||||
/* Already unlocked mutex */
|
/* Already unlocked mutex */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&conn->lock);
|
virMutexUnlock(&conn->lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -845,16 +863,19 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const c
|
|||||||
ret = (virStorageVolPtr) virHashLookup(conn->storageVols, key);
|
ret = (virStorageVolPtr) virHashLookup(conn->storageVols, key);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
if (VIR_ALLOC(ret) < 0) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ret->pool = strdup(pool);
|
ret->pool = strdup(pool);
|
||||||
if (ret->pool == NULL) {
|
if (ret->pool == NULL) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ret->name = strdup(name);
|
ret->name = strdup(name);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -864,6 +885,7 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const c
|
|||||||
ret->conn = conn;
|
ret->conn = conn;
|
||||||
|
|
||||||
if (virHashAddEntry(conn->storageVols, key, ret) < 0) {
|
if (virHashAddEntry(conn->storageVols, key, ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("failed to add storage vol to connection hash table"));
|
_("failed to add storage vol to connection hash table"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -875,7 +897,6 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const c
|
|||||||
return(ret);
|
return(ret);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virMutexUnlock(&conn->lock);
|
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
VIR_FREE(ret->name);
|
VIR_FREE(ret->name);
|
||||||
VIR_FREE(ret->pool);
|
VIR_FREE(ret->pool);
|
||||||
@ -903,15 +924,19 @@ virReleaseStorageVol(virStorageVolPtr vol) {
|
|||||||
DEBUG("release vol %p %s", vol, vol->name);
|
DEBUG("release vol %p %s", vol, vol->name);
|
||||||
|
|
||||||
/* TODO search by UUID first as they are better differenciators */
|
/* TODO search by UUID first as they are better differenciators */
|
||||||
if (virHashRemoveEntry(conn->storageVols, vol->key, NULL) < 0)
|
if (virHashRemoveEntry(conn->storageVols, vol->key, NULL) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("vol missing from connection hash table"));
|
_("vol missing from connection hash table"));
|
||||||
|
conn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
vol->magic = -1;
|
vol->magic = -1;
|
||||||
VIR_FREE(vol->name);
|
VIR_FREE(vol->name);
|
||||||
VIR_FREE(vol->pool);
|
VIR_FREE(vol->pool);
|
||||||
VIR_FREE(vol);
|
VIR_FREE(vol);
|
||||||
|
|
||||||
|
if (conn) {
|
||||||
DEBUG("unref connection %p %d", conn, conn->refs);
|
DEBUG("unref connection %p %d", conn, conn->refs);
|
||||||
conn->refs--;
|
conn->refs--;
|
||||||
if (conn->refs == 0) {
|
if (conn->refs == 0) {
|
||||||
@ -919,9 +944,9 @@ virReleaseStorageVol(virStorageVolPtr vol) {
|
|||||||
/* Already unlocked mutex */
|
/* Already unlocked mutex */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&conn->lock);
|
virMutexUnlock(&conn->lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -982,6 +1007,7 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
|
|||||||
ret = (virNodeDevicePtr) virHashLookup(conn->nodeDevices, name);
|
ret = (virNodeDevicePtr) virHashLookup(conn->nodeDevices, name);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
if (VIR_ALLOC(ret) < 0) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -989,11 +1015,13 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
|
|||||||
ret->conn = conn;
|
ret->conn = conn;
|
||||||
ret->name = strdup(name);
|
ret->name = strdup(name);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virHashAddEntry(conn->nodeDevices, name, ret) < 0) {
|
if (virHashAddEntry(conn->nodeDevices, name, ret) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("failed to add node dev to conn hash table"));
|
_("failed to add node dev to conn hash table"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -1005,7 +1033,6 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
|
|||||||
return(ret);
|
return(ret);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virMutexUnlock(&conn->lock);
|
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
VIR_FREE(ret->name);
|
VIR_FREE(ret->name);
|
||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
@ -1031,15 +1058,19 @@ virReleaseNodeDevice(virNodeDevicePtr dev) {
|
|||||||
virConnectPtr conn = dev->conn;
|
virConnectPtr conn = dev->conn;
|
||||||
DEBUG("release dev %p %s", dev, dev->name);
|
DEBUG("release dev %p %s", dev, dev->name);
|
||||||
|
|
||||||
if (virHashRemoveEntry(conn->nodeDevices, dev->name, NULL) < 0)
|
if (virHashRemoveEntry(conn->nodeDevices, dev->name, NULL) < 0) {
|
||||||
|
virMutexUnlock(&conn->lock);
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("dev missing from connection hash table"));
|
_("dev missing from connection hash table"));
|
||||||
|
conn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
dev->magic = -1;
|
dev->magic = -1;
|
||||||
VIR_FREE(dev->name);
|
VIR_FREE(dev->name);
|
||||||
VIR_FREE(dev->parent);
|
VIR_FREE(dev->parent);
|
||||||
VIR_FREE(dev);
|
VIR_FREE(dev);
|
||||||
|
|
||||||
|
if (conn) {
|
||||||
DEBUG("unref connection %p %d", conn, conn->refs);
|
DEBUG("unref connection %p %d", conn, conn->refs);
|
||||||
conn->refs--;
|
conn->refs--;
|
||||||
if (conn->refs == 0) {
|
if (conn->refs == 0) {
|
||||||
@ -1047,9 +1078,9 @@ virReleaseNodeDevice(virNodeDevicePtr dev) {
|
|||||||
/* Already unlocked mutex */
|
/* Already unlocked mutex */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&conn->lock);
|
virMutexUnlock(&conn->lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user