virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
-/************************************************************************
- * *
- * Domain and Connections allocations *
- * *
- ************************************************************************/
+virClassPtr virConnectClass;
+virClassPtr virDomainClass;
+virClassPtr virDomainSnapshotClass;
+virClassPtr virInterfaceClass;
+virClassPtr virNetworkClass;
+virClassPtr virNodeDeviceClass;
+virClassPtr virNWFilterClass;
+virClassPtr virSecretClass;
+virClassPtr virStreamClass;
+virClassPtr virStorageVolClass;
+virClassPtr virStoragePoolClass;
+
+static void virConnectDispose(void *obj);
+static void virDomainDispose(void *obj);
+static void virDomainSnapshotDispose(void *obj);
+static void virInterfaceDispose(void *obj);
+static void virNetworkDispose(void *obj);
+static void virNodeDeviceDispose(void *obj);
+static void virNWFilterDispose(void *obj);
+static void virSecretDispose(void *obj);
+static void virStreamDispose(void *obj);
+static void virStorageVolDispose(void *obj);
+static void virStoragePoolDispose(void *obj);
+
+static int
+virDataTypesOnceInit(void)
+{
+#define DECLARE_CLASS(basename) \
+ if (!(basename ## Class = virClassNew(#basename, \
+ sizeof(basename), \
+ basename ## Dispose))) \
+ return -1;
+
+ DECLARE_CLASS(virConnect);
+ DECLARE_CLASS(virDomain);
+ DECLARE_CLASS(virDomainSnapshot);
+ DECLARE_CLASS(virInterface);
+ DECLARE_CLASS(virNetwork);
+ DECLARE_CLASS(virNodeDevice);
+ DECLARE_CLASS(virNWFilter);
+ DECLARE_CLASS(virSecret);
+ DECLARE_CLASS(virStream);
+ DECLARE_CLASS(virStorageVol);
+ DECLARE_CLASS(virStoragePool);
+
+#undef DECLARE_CLASS
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virDataTypes)
/**
* virGetConnect:
* Returns a new pointer or NULL in case of error.
*/
virConnectPtr
-virGetConnect(void) {
+virGetConnect(void)
+{
virConnectPtr ret;
- if (VIR_ALLOC(ret) < 0) {
- virReportOOMError();
- goto failed;
- }
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
+ if (!(ret = virObjectNew(virConnectClass)))
+ return NULL;
+
if (virMutexInit(&ret->lock) < 0) {
VIR_FREE(ret);
- goto failed;
+ return NULL;
}
- ret->magic = VIR_CONNECT_MAGIC;
- ret->driver = NULL;
- ret->networkDriver = NULL;
- ret->privateData = NULL;
- ret->networkPrivateData = NULL;
- ret->interfacePrivateData = NULL;
-
- ret->refs = 1;
return ret;
-
-failed:
- if (ret != NULL) {
- virMutexDestroy(&ret->lock);
- VIR_FREE(ret);
- }
- return NULL;
}
/**
- * virReleaseConnect:
+ * virConnectDispose:
* @conn: the hypervisor connection to release
*
* Unconditionally release all memory associated with a connection.
* be used once this method returns.
*/
static void
-virReleaseConnect(virConnectPtr conn) {
- VIR_DEBUG("release connection %p", conn);
-
- /* make sure to release the connection lock before we call the
- * close callbacks, otherwise we will deadlock if an error
- * is raised by any of the callbacks */
- virMutexUnlock(&conn->lock);
+virConnectDispose(void *obj)
+{
+ virConnectPtr conn = obj;
if (conn->networkDriver)
conn->networkDriver->close(conn);
virMutexUnlock(&conn->lock);
virMutexDestroy(&conn->lock);
- VIR_FREE(conn);
}
-/**
- * virUnrefConnect:
- * @conn: the hypervisor connection to unreference
- *
- * Unreference the connection. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefConnect(virConnectPtr conn) {
- int refs;
-
- if ((!VIR_IS_CONNECT(conn))) {
- virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
- return -1;
- }
- virMutexLock(&conn->lock);
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- refs = conn->refs;
- if (refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return 0;
- }
- virMutexUnlock(&conn->lock);
- return refs;
-}
/**
* virGetDomain:
* Lookup if the domain is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
- * virUnrefDomain() is needed to not leak data.
+ * virObjectUnref() is needed to not leak data.
*
* Returns a pointer to the domain, or NULL in case of failure
*/
virDomainPtr
-virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
+virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid)
+{
virDomainPtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
virCheckNonNullArgReturn(name, NULL);
virCheckNonNullArgReturn(uuid, NULL);
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virDomainClass)))
+ return NULL;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_DOMAIN_MAGIC;
- ret->conn = conn;
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
+
+ ret->conn = virObjectRef(conn);
ret->id = -1;
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
return ret;
- error:
- if (ret != NULL) {
- VIR_FREE(ret->name);
- VIR_FREE(ret);
- }
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseDomain:
+ * virDomainDispose:
* @domain: the domain to release
*
* Unconditionally release all memory associated with a domain.
* which may also be released if its ref count hits zero.
*/
static void
-virReleaseDomain(virDomainPtr domain) {
- virConnectPtr conn = domain->conn;
+virDomainDispose(void *obj)
+{
+ virDomainPtr domain = obj;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(domain->uuid, uuidstr);
VIR_DEBUG("release domain %p %s %s", domain, domain->name, uuidstr);
- domain->magic = -1;
- domain->id = -1;
VIR_FREE(domain->name);
- VIR_FREE(domain);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
+ virObjectUnref(domain->conn);
}
-/**
- * virUnrefDomain:
- * @domain: the domain to unreference
- *
- * Unreference the domain. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefDomain(virDomainPtr domain) {
- int refs;
-
- if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
- virLibConnError(VIR_ERR_INVALID_DOMAIN, "%s",
- _("bad domain or no connection"));
- return -1;
- }
- virMutexLock(&domain->conn->lock);
- VIR_DEBUG("unref domain %p %s %d", domain, domain->name, domain->refs);
- domain->refs--;
- refs = domain->refs;
- if (refs == 0) {
- virReleaseDomain(domain);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&domain->conn->lock);
- return refs;
-}
-
/**
* virGetNetwork:
* @conn: the hypervisor connection
* Lookup if the network is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
- * virUnrefNetwork() is needed to not leak data.
+ * virObjectUnref() is needed to not leak data.
*
* Returns a pointer to the network, or NULL in case of failure
*/
virNetworkPtr
-virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
+virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid)
+{
virNetworkPtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
virCheckNonNullArgReturn(name, NULL);
virCheckNonNullArgReturn(uuid, NULL);
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virNetworkClass)))
+ return NULL;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_NETWORK_MAGIC;
- ret->conn = conn;
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
+
+ ret->conn = virObjectRef(conn);
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
return ret;
- error:
- if (ret != NULL) {
- VIR_FREE(ret->name);
- VIR_FREE(ret);
- }
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseNetwork:
+ * virNetworkDispose:
* @network: the network to release
*
* Unconditionally release all memory associated with a network.
* which may also be released if its ref count hits zero.
*/
static void
-virReleaseNetwork(virNetworkPtr network) {
- virConnectPtr conn = network->conn;
+virNetworkDispose(void *obj)
+{
+ virNetworkPtr network = obj;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(network->uuid, uuidstr);
VIR_DEBUG("release network %p %s %s", network, network->name, uuidstr);
- network->magic = -1;
VIR_FREE(network->name);
- VIR_FREE(network);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
-}
-
-
-/**
- * virUnrefNetwork:
- * @network: the network to unreference
- *
- * Unreference the network. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefNetwork(virNetworkPtr network) {
- int refs;
-
- if (!VIR_IS_CONNECTED_NETWORK(network)) {
- virLibConnError(VIR_ERR_INVALID_NETWORK, "%s",
- _("bad network or no connection"));
- return -1;
- }
- virMutexLock(&network->conn->lock);
- VIR_DEBUG("unref network %p %s %d", network, network->name, network->refs);
- network->refs--;
- refs = network->refs;
- if (refs == 0) {
- virReleaseNetwork(network);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&network->conn->lock);
- return refs;
+ virObjectUnref(network->conn);
}
* Lookup if the interface is already registered for that connection,
* if yes return a new pointer to it (possibly updating the MAC
* address), if no allocate a new structure, and register it in the
- * table. In any case a corresponding call to virUnrefInterface() is
+ * table. In any case a corresponding call to virObjectUnref() is
* needed to not leak data.
*
* Returns a pointer to the interface, or NULL in case of failure
*/
virInterfacePtr
-virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
+virGetInterface(virConnectPtr conn, const char *name, const char *mac)
+{
virInterfacePtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
if (mac == NULL)
mac = "";
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virInterfaceClass)))
+ return NULL;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->mac = strdup(mac);
- if (ret->mac == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
+ if (!(ret->mac = strdup(mac)))
+ goto no_memory;
- ret->magic = VIR_INTERFACE_MAGIC;
- ret->conn = conn;
+ ret->conn = virObjectRef(conn);
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
return ret;
- error:
- if (ret != NULL) {
- VIR_FREE(ret->name);
- VIR_FREE(ret->mac);
- VIR_FREE(ret);
- }
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseInterface:
+ * virInterfaceDispose:
* @interface: the interface to release
*
* Unconditionally release all memory associated with an interface.
* which may also be released if its ref count hits zero.
*/
static void
-virReleaseInterface(virInterfacePtr iface) {
- virConnectPtr conn = iface->conn;
+virInterfaceDispose(void *obj)
+{
+ virInterfacePtr iface = obj;
VIR_DEBUG("release interface %p %s", iface, iface->name);
- iface->magic = -1;
VIR_FREE(iface->name);
VIR_FREE(iface->mac);
- VIR_FREE(iface);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
-}
-
-
-/**
- * virUnrefInterface:
- * @interface: the interface to unreference
- *
- * Unreference the interface. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefInterface(virInterfacePtr iface) {
- int refs;
-
- if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
- virLibConnError(VIR_ERR_INVALID_INTERFACE, "%s",
- _("bad interface or no connection"));
- return -1;
- }
- virMutexLock(&iface->conn->lock);
- VIR_DEBUG("unref interface %p %s %d", iface, iface->name, iface->refs);
- iface->refs--;
- refs = iface->refs;
- if (refs == 0) {
- virReleaseInterface(iface);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&iface->conn->lock);
- return refs;
+ virObjectUnref(iface->conn);
}
* Lookup if the storage pool is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
- * virUnrefStoragePool() is needed to not leak data.
+ * virObjectUnref() is needed to not leak data.
*
* Returns a pointer to the network, or NULL in case of failure
*/
virStoragePoolPtr
virGetStoragePool(virConnectPtr conn, const char *name,
- const unsigned char *uuid) {
+ const unsigned char *uuid)
+{
virStoragePoolPtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
virCheckNonNullArgReturn(name, NULL);
virCheckNonNullArgReturn(uuid, NULL);
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virStoragePoolClass)))
+ return NULL;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_STORAGE_POOL_MAGIC;
- ret->conn = conn;
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
+
+ ret->conn = virObjectRef(conn);
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
return ret;
-error:
- if (ret != NULL) {
- VIR_FREE(ret->name);
- VIR_FREE(ret);
- }
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseStoragePool:
+ * virStoragePoolDispose:
* @pool: the pool to release
*
* Unconditionally release all memory associated with a pool.
* which may also be released if its ref count hits zero.
*/
static void
-virReleaseStoragePool(virStoragePoolPtr pool) {
- virConnectPtr conn = pool->conn;
+virStoragePoolDispose(void *obj)
+{
+ virStoragePoolPtr pool = obj;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(pool->uuid, uuidstr);
VIR_DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);
- pool->magic = -1;
VIR_FREE(pool->name);
- VIR_FREE(pool);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
-}
-
-
-/**
- * virUnrefStoragePool:
- * @pool: the pool to unreference
- *
- * Unreference the pool. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefStoragePool(virStoragePoolPtr pool) {
- int refs;
-
- if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
- virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, "%s",
- _("bad storage pool or no connection"));
- return -1;
- }
- virMutexLock(&pool->conn->lock);
- VIR_DEBUG("unref pool %p %s %d", pool, pool->name, pool->refs);
- pool->refs--;
- refs = pool->refs;
- if (refs == 0) {
- virReleaseStoragePool(pool);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&pool->conn->lock);
- return refs;
+ virObjectUnref(pool->conn);
}
* Lookup if the storage vol is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
- * virUnrefStorageVol() is needed to not leak data.
+ * virObjectUnref() is needed to not leak data.
*
* Returns a pointer to the storage vol, or NULL in case of failure
*/
virStorageVolPtr
virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
- const char *key) {
+ const char *key)
+{
virStorageVolPtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
virCheckNonNullArgReturn(name, NULL);
virCheckNonNullArgReturn(key, NULL);
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virStorageVolClass)))
+ return NULL;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->pool = strdup(pool);
- if (ret->pool == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->key = strdup(key);
- if (ret->key == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_STORAGE_VOL_MAGIC;
- ret->conn = conn;
+ if (!(ret->pool = strdup(pool)))
+ goto no_memory;
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
+ if (!(ret->key = strdup(key)))
+ goto no_memory;
+
+ ret->conn = virObjectRef(conn);
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
return ret;
-error:
- if (ret != NULL) {
- VIR_FREE(ret->key);
- VIR_FREE(ret->name);
- VIR_FREE(ret->pool);
- VIR_FREE(ret);
- }
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseStorageVol:
+ * virStorageVolDispose:
* @vol: the vol to release
*
* Unconditionally release all memory associated with a vol.
* which may also be released if its ref count hits zero.
*/
static void
-virReleaseStorageVol(virStorageVolPtr vol) {
- virConnectPtr conn = vol->conn;
+virStorageVolDispose(void *obj)
+{
+ virStorageVolPtr vol = obj;
VIR_DEBUG("release vol %p %s", vol, vol->name);
- vol->magic = -1;
VIR_FREE(vol->key);
VIR_FREE(vol->name);
VIR_FREE(vol->pool);
- VIR_FREE(vol);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
-}
-
-
-/**
- * virUnrefStorageVol:
- * @vol: the vol to unreference
- *
- * Unreference the vol. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefStorageVol(virStorageVolPtr vol) {
- int refs;
-
- if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
- virLibConnError(VIR_ERR_INVALID_STORAGE_VOL, "%s",
- _("bad storage volume or no connection"));
- return -1;
- }
- virMutexLock(&vol->conn->lock);
- VIR_DEBUG("unref vol %p %s %d", vol, vol->name, vol->refs);
- vol->refs--;
- refs = vol->refs;
- if (refs == 0) {
- virReleaseStorageVol(vol);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&vol->conn->lock);
- return refs;
+ virObjectUnref(vol->conn);
}
* Lookup if the device is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
- * virUnrefNodeDevice() is needed to not leak data.
+ * virObjectUnref() is needed to not leak data.
*
* Returns a pointer to the node device, or NULL in case of failure
*/
{
virNodeDevicePtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
}
virCheckNonNullArgReturn(name, NULL);
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virNodeDeviceClass)))
+ return NULL;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_NODE_DEVICE_MAGIC;
- ret->conn = conn;
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
+ ret->conn = virObjectRef(conn);
return ret;
-
-error:
- if (ret != NULL) {
- VIR_FREE(ret->name);
- VIR_FREE(ret);
- }
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseNodeDevice:
+ * virNodeDeviceDispose:
* @dev: the dev to release
*
* Unconditionally release all memory associated with a dev.
* which may also be released if its ref count hits zero.
*/
static void
-virReleaseNodeDevice(virNodeDevicePtr dev) {
- virConnectPtr conn = dev->conn;
+virNodeDeviceDispose(void *obj)
+{
+ virNodeDevicePtr dev = obj;
VIR_DEBUG("release dev %p %s", dev, dev->name);
- dev->magic = -1;
VIR_FREE(dev->name);
VIR_FREE(dev->parent);
- VIR_FREE(dev);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
-}
-
-/**
- * virUnrefNodeDevice:
- * @dev: the dev to unreference
- *
- * Unreference the dev. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefNodeDevice(virNodeDevicePtr dev) {
- int refs;
-
- virMutexLock(&dev->conn->lock);
- VIR_DEBUG("unref dev %p %s %d", dev, dev->name, dev->refs);
- dev->refs--;
- refs = dev->refs;
- if (refs == 0) {
- virReleaseNodeDevice(dev);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&dev->conn->lock);
- return refs;
+ virObjectUnref(dev->conn);
}
*
* Lookup if the secret is already registered for that connection, if so return
* a pointer to it, otherwise allocate a new structure, and register it in the
- * table. In any case a corresponding call to virUnrefSecret() is needed to not
+ * table. In any case a corresponding call to virObjectUnref() is needed to not
* leak data.
*
* Returns a pointer to the secret, or NULL in case of failure
{
virSecretPtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
virCheckNonNullArgReturn(uuid, NULL);
virCheckNonNullArgReturn(usageID, NULL);
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virSecretClass)))
+ return NULL;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_SECRET_MAGIC;
- ret->conn = conn;
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
ret->usageType = usageType;
- if (!(ret->usageID = strdup(usageID))) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
- return ret;
+ if (!(ret->usageID = strdup(usageID)))
+ goto no_memory;
-error:
- if (ret != NULL) {
- VIR_FREE(ret->usageID);
- VIR_FREE(ret);
- }
+ ret->conn = virObjectRef(conn);
+
+ return ret;
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseSecret:
+ * virSecretDispose:
* @secret: the secret to release
*
* Unconditionally release all memory associated with a secret. The conn.lock
* released if its ref count hits zero.
*/
static void
-virReleaseSecret(virSecretPtr secret) {
- virConnectPtr conn = secret->conn;
+virSecretDispose(void *obj)
+{
+ virSecretPtr secret = obj;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(secret->uuid, uuidstr);
VIR_DEBUG("release secret %p %s", secret, uuidstr);
VIR_FREE(secret->usageID);
- secret->magic = -1;
- VIR_FREE(secret);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
+ virObjectUnref(secret->conn);
}
-/**
- * virUnrefSecret:
- * @secret: the secret to unreference
- *
- * Unreference the secret. If the use count drops to zero, the structure is
- * actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefSecret(virSecretPtr secret) {
- int refs;
- if (!VIR_IS_CONNECTED_SECRET(secret)) {
- virLibConnError(VIR_ERR_INVALID_SECRET, "%s",
- _("bad secret or no connection"));
- return -1;
- }
- virMutexLock(&secret->conn->lock);
- VIR_DEBUG("unref secret %p %p %d", secret, secret->uuid, secret->refs);
- secret->refs--;
- refs = secret->refs;
- if (refs == 0) {
- virReleaseSecret(secret);
- /* Already unlocked mutex */
- return 0;
- }
+virStreamPtr
+virGetStream(virConnectPtr conn)
+{
+ virStreamPtr ret = NULL;
- virMutexUnlock(&secret->conn->lock);
- return refs;
-}
+ if (virDataTypesInitialize() < 0)
+ return NULL;
-virStreamPtr virGetStream(virConnectPtr conn) {
- virStreamPtr ret = NULL;
+ if (!(ret = virObjectNew(virStreamClass)))
+ return NULL;
- virMutexLock(&conn->lock);
+ ret->conn = virObjectRef(conn);
- if (VIR_ALLOC(ret) < 0) {
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_STREAM_MAGIC;
- ret->conn = conn;
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
return ret;
-
-error:
- virMutexUnlock(&conn->lock);
- VIR_FREE(ret);
- return NULL;
}
static void
-virReleaseStream(virStreamPtr st) {
- virConnectPtr conn = st->conn;
+virStreamDispose(void *obj)
+{
+ virStreamPtr st = obj;
VIR_DEBUG("release dev %p", st);
- st->magic = -1;
- VIR_FREE(st);
-
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
-
- virMutexUnlock(&conn->lock);
-}
-
-int virUnrefStream(virStreamPtr st) {
- int refs;
-
- virMutexLock(&st->conn->lock);
- VIR_DEBUG("unref stream %p %d", st, st->refs);
- st->refs--;
- refs = st->refs;
- if (refs == 0) {
- virReleaseStream(st);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&st->conn->lock);
- return refs;
+ virObjectUnref(st->conn);
}
* Lookup if the network filter is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
- * virUnrefNWFilter() is needed to not leak data.
+ * virObjectUnref() is needed to not leak data.
*
* Returns a pointer to the network, or NULL in case of failure
*/
virNWFilterPtr
-virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid) {
+virGetNWFilter(virConnectPtr conn, const char *name,
+ const unsigned char *uuid)
+{
virNWFilterPtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection"));
return NULL;
virCheckNonNullArgReturn(name, NULL);
virCheckNonNullArgReturn(uuid, NULL);
- virMutexLock(&conn->lock);
+ if (!(ret = virObjectNew(virNWFilterClass)))
+ return NULL;
+
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_NWFILTER_MAGIC;
- ret->conn = conn;
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
- conn->refs++;
- ret->refs++;
- virMutexUnlock(&conn->lock);
- return ret;
+ ret->conn = virObjectRef(conn);
-error:
- if (ret != NULL) {
- VIR_FREE(ret->name);
- VIR_FREE(ret);
- }
+ return ret;
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
/**
- * virReleaseNWFilter:
+ * virNWFilterDispose:
* @nwfilter: the nwfilter to release
*
* Unconditionally release all memory associated with a nwfilter.
* which may also be released if its ref count hits zero.
*/
static void
-virReleaseNWFilter(virNWFilterPtr nwfilter)
+virNWFilterDispose(void *obj)
{
- virConnectPtr conn = nwfilter->conn;
+ virNWFilterPtr nwfilter = obj;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(nwfilter->uuid, uuidstr);
VIR_DEBUG("release nwfilter %p %s %s", nwfilter, nwfilter->name, uuidstr);
- nwfilter->magic = -1;
VIR_FREE(nwfilter->name);
- VIR_FREE(nwfilter);
-
- if (conn) {
- VIR_DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&conn->lock);
- }
-}
-
-
-/**
- * virUnrefNWFilter:
- * @nwfilter: the nwfilter to unreference
- *
- * Unreference the networkf itler. If the use count drops to zero, the
- * structure is actually freed.
- *
- * Returns the reference count or -1 in case of failure.
- */
-int
-virUnrefNWFilter(virNWFilterPtr nwfilter)
-{
- int refs;
-
- if (!VIR_IS_CONNECTED_NWFILTER(nwfilter)) {
- virLibConnError(VIR_ERR_INVALID_NWFILTER, "%s",
- _("bad nwfilter or no connection"));
- return -1;
- }
- virMutexLock(&nwfilter->conn->lock);
- VIR_DEBUG("unref nwfilter %p %s %d", nwfilter, nwfilter->name,
- nwfilter->refs);
- nwfilter->refs--;
- refs = nwfilter->refs;
- if (refs == 0) {
- virReleaseNWFilter(nwfilter);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&nwfilter->conn->lock);
- return refs;
+ virObjectUnref(nwfilter->conn);
}
{
virDomainSnapshotPtr ret = NULL;
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
if (!VIR_IS_DOMAIN(domain)) {
virLibConnError(VIR_ERR_INVALID_DOMAIN, "%s", _("bad domain"));
return NULL;
}
virCheckNonNullArgReturn(name, NULL);
- virMutexLock(&domain->conn->lock);
-
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&domain->conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&domain->conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_SNAPSHOT_MAGIC;
- ret->domain = domain;
+ if (!(ret = virObjectNew(virDomainSnapshotClass)))
+ return NULL;
+ if (!(ret->name = strdup(name)))
+ goto no_memory;
+ ret->domain = virObjectRef(domain);
- domain->refs++;
- ret->refs++;
- virMutexUnlock(&domain->conn->lock);
return ret;
-
- error:
- if (ret != NULL) {
- VIR_FREE(ret->name);
- VIR_FREE(ret);
- }
+no_memory:
+ virReportOOMError();
+ virObjectUnref(ret);
return NULL;
}
static void
-virReleaseDomainSnapshot(virDomainSnapshotPtr snapshot)
+virDomainSnapshotDispose(void *obj)
{
- virDomainPtr domain = snapshot->domain;
+ virDomainSnapshotPtr snapshot = obj;
VIR_DEBUG("release snapshot %p %s", snapshot, snapshot->name);
- snapshot->magic = -1;
VIR_FREE(snapshot->name);
- VIR_FREE(snapshot);
-
- if (domain) {
- VIR_DEBUG("unref domain %p %d", domain, domain->refs);
- domain->refs--;
- if (domain->refs == 0) {
- virReleaseDomain(domain);
- /* Already unlocked mutex */
- return;
- }
- virMutexUnlock(&domain->conn->lock);
- }
-}
-
-int
-virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot)
-{
- int refs;
-
- if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot)) {
- virLibConnError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, "%s",
- _("not a snapshot"));
- return -1;
- }
-
- virMutexLock(&snapshot->domain->conn->lock);
- VIR_DEBUG("unref snapshot %p %s %d", snapshot, snapshot->name, snapshot->refs);
- snapshot->refs--;
- refs = snapshot->refs;
- if (refs == 0) {
- virReleaseDomainSnapshot(snapshot);
- /* Already unlocked mutex */
- return 0;
- }
-
- virMutexUnlock(&snapshot->domain->conn->lock);
- return refs;
+ virObjectUnref(snapshot->domain);
}
*
*/
-#ifndef __VIRT_DATATYPES_H_
-# define __VIRT_DATATYPES_H_
+#ifndef __VIR_DATATYPES_H_
+# define __VIR_DATATYPES_H_
# include "internal.h"
# include "driver.h"
# include "threads.h"
-
-/**
- * VIR_CONNECT_MAGIC:
- *
- * magic value used to protect the API when pointers to connection structures
- * are passed down by the users.
- */
-# define VIR_CONNECT_MAGIC 0x4F23DEAD
-# define VIR_IS_CONNECT(obj) ((obj) && (obj)->magic==VIR_CONNECT_MAGIC)
-
-
-/**
- * VIR_DOMAIN_MAGIC:
- *
- * magic value used to protect the API when pointers to domain structures
- * are passed down by the users.
- */
-# define VIR_DOMAIN_MAGIC 0xDEAD4321
-# define VIR_IS_DOMAIN(obj) ((obj) && (obj)->magic==VIR_DOMAIN_MAGIC)
-# define VIR_IS_CONNECTED_DOMAIN(obj) (VIR_IS_DOMAIN(obj) && VIR_IS_CONNECT((obj)->conn))
-
-/**
- * VIR_NETWORK_MAGIC:
- *
- * magic value used to protect the API when pointers to network structures
- * are passed down by the users.
- */
-# define VIR_NETWORK_MAGIC 0xDEAD1234
-# define VIR_IS_NETWORK(obj) ((obj) && (obj)->magic==VIR_NETWORK_MAGIC)
-# define VIR_IS_CONNECTED_NETWORK(obj) (VIR_IS_NETWORK(obj) && VIR_IS_CONNECT((obj)->conn))
-
-/**
- * VIR_INTERFACE_MAGIC:
- *
- * magic value used to protect the API when pointers to interface structures
- * are passed down by the users.
- */
-# define VIR_INTERFACE_MAGIC 0xDEAD5309
-# define VIR_IS_INTERFACE(obj) ((obj) && (obj)->magic==VIR_INTERFACE_MAGIC)
-# define VIR_IS_CONNECTED_INTERFACE(obj) (VIR_IS_INTERFACE(obj) && VIR_IS_CONNECT((obj)->conn))
-
-/**
- * VIR_STORAGE_POOL_MAGIC:
- *
- * magic value used to protect the API when pointers to storage pool structures
- * are passed down by the users.
- */
-# define VIR_STORAGE_POOL_MAGIC 0xDEAD5678
-# define VIR_IS_STORAGE_POOL(obj) ((obj) && (obj)->magic==VIR_STORAGE_POOL_MAGIC)
-# define VIR_IS_CONNECTED_STORAGE_POOL(obj) (VIR_IS_STORAGE_POOL(obj) && VIR_IS_CONNECT((obj)->conn))
-
-/**
- * VIR_STORAGE_VOL_MAGIC:
- *
- * magic value used to protect the API when pointers to storage vol structures
- * are passed down by the users.
- */
-# define VIR_STORAGE_VOL_MAGIC 0xDEAD8765
-# define VIR_IS_STORAGE_VOL(obj) ((obj) && (obj)->magic==VIR_STORAGE_VOL_MAGIC)
-# define VIR_IS_CONNECTED_STORAGE_VOL(obj) (VIR_IS_STORAGE_VOL(obj) && VIR_IS_CONNECT((obj)->conn))
-
-/**
- * VIR_NODE_DEVICE_MAGIC:
- *
- * magic value used to protect the API when pointers to storage vol structures
- * are passed down by the users.
- */
-# define VIR_NODE_DEVICE_MAGIC 0xDEAD5679
-# define VIR_IS_NODE_DEVICE(obj) ((obj) && (obj)->magic==VIR_NODE_DEVICE_MAGIC)
-# define VIR_IS_CONNECTED_NODE_DEVICE(obj) (VIR_IS_NODE_DEVICE(obj) && VIR_IS_CONNECT((obj)->conn))
-
-/**
- * VIR_SECRET_MAGIC:
- *
- * magic value used to protect the API when pointers to secret structures are
- * passed down by the users.
- */
-# define VIR_SECRET_MAGIC 0x5678DEAD
-# define VIR_IS_SECRET(obj) ((obj) && (obj)->magic==VIR_SECRET_MAGIC)
-# define VIR_IS_CONNECTED_SECRET(obj) (VIR_IS_SECRET(obj) && VIR_IS_CONNECT((obj)->conn))
-
-
-/**
- * VIR_STREAM_MAGIC:
- *
- * magic value used to protect the API when pointers to stream structures
- * are passed down by the users.
- */
-# define VIR_STREAM_MAGIC 0x1DEAD666
-# define VIR_IS_STREAM(obj) ((obj) && (obj)->magic==VIR_STREAM_MAGIC)
-# define VIR_IS_CONNECTED_STREAM(obj) (VIR_IS_STREAM(obj) && VIR_IS_CONNECT((obj)->conn))
-
-
-/**
- * VIR_NWFILTER_MAGIC:
- *
- * magic value used to protect the API when pointers to network filter
- * pool structures are passed down by the users.
- */
-# define VIR_NWFILTER_MAGIC 0xDEAD7777
-# define VIR_IS_NWFILTER(obj) ((obj) && (obj)->magic==VIR_NWFILTER_MAGIC)
-# define VIR_IS_CONNECTED_NWFILTER(obj) (VIR_IS_NWFILTER(obj) && VIR_IS_CONNECT((obj)->conn))
-
-/**
- * VIR_SNAPSHOT_MAGIC:
- *
- * magic value used to protect the API when pointers to snapshot structures
- * are passed down by the users.
- */
-# define VIR_SNAPSHOT_MAGIC 0x6666DEAD
-# define VIR_IS_SNAPSHOT(obj) ((obj) && (obj)->magic==VIR_SNAPSHOT_MAGIC)
-# define VIR_IS_DOMAIN_SNAPSHOT(obj) (VIR_IS_SNAPSHOT(obj) && VIR_IS_DOMAIN((obj)->domain))
+# include "virobject.h"
+
+extern virClassPtr virConnectClass;
+extern virClassPtr virDomainClass;
+extern virClassPtr virDomainSnapshotClass;
+extern virClassPtr virInterfaceClass;
+extern virClassPtr virNetworkClass;
+extern virClassPtr virNodeDeviceClass;
+extern virClassPtr virNWFilterClass;
+extern virClassPtr virSecretClass;
+extern virClassPtr virStreamClass;
+extern virClassPtr virStorageVolClass;
+extern virClassPtr virStoragePoolClass;
+
+# define VIR_IS_CONNECT(obj) \
+ (virObjectIsClass((obj), virConnectClass))
+
+# define VIR_IS_DOMAIN(obj) \
+ (virObjectIsClass((obj), virDomainClass))
+# define VIR_IS_CONNECTED_DOMAIN(obj) \
+ (VIR_IS_DOMAIN(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_NETWORK(obj) \
+ (virObjectIsClass((obj), virNetworkClass))
+# define VIR_IS_CONNECTED_NETWORK(obj) \
+ (VIR_IS_NETWORK(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_INTERFACE(obj) \
+ (virObjectIsClass((obj), virInterfaceClass))
+# define VIR_IS_CONNECTED_INTERFACE(obj) \
+ (VIR_IS_INTERFACE(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_STORAGE_POOL(obj) \
+ (virObjectIsClass((obj), virStoragePoolClass))
+# define VIR_IS_CONNECTED_STORAGE_POOL(obj) \
+ (VIR_IS_STORAGE_POOL(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_STORAGE_VOL(obj) \
+ (virObjectIsClass((obj), virStorageVolClass))
+# define VIR_IS_CONNECTED_STORAGE_VOL(obj) \
+ (VIR_IS_STORAGE_VOL(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_NODE_DEVICE(obj) \
+ (virObjectIsClass((obj), virNodeDeviceClass))
+# define VIR_IS_CONNECTED_NODE_DEVICE(obj) \
+ (VIR_IS_NODE_DEVICE(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_SECRET(obj) \
+ (virObjectIsClass((obj), virSecretClass))
+# define VIR_IS_CONNECTED_SECRET(obj) \
+ (VIR_IS_SECRET(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_STREAM(obj) \
+ (virObjectIsClass((obj), virStreamClass))
+# define VIR_IS_CONNECTED_STREAM(obj) \
+ (VIR_IS_STREAM(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_NWFILTER(obj) \
+ (virObjectIsClass((obj), virNWFilterClass))
+# define VIR_IS_CONNECTED_NWFILTER(obj) \
+ (VIR_IS_NWFILTER(obj) && VIR_IS_CONNECT((obj)->conn))
+
+# define VIR_IS_SNAPSHOT(obj) \
+ (virObjectIsClass((obj), virDomainSnapshotClass))
+# define VIR_IS_DOMAIN_SNAPSHOT(obj) \
+ (VIR_IS_SNAPSHOT(obj) && VIR_IS_DOMAIN((obj)->domain))
/**
* _virConnect:
* Internal structure associated to a connection
*/
struct _virConnect {
+ virObject object;
/* All the variables from here, until the 'lock' declaration
* are setup at time of connection open, and never changed
* since. Thus no need to lock when accessing them
*/
- unsigned int magic; /* specific value to check */
unsigned int flags; /* a set of connection flags */
virURIPtr uri; /* connection URI */
virFreeCallback closeFreeCallback;
bool closeDispatch;
unsigned closeUnregisterCount;
-
- int refs; /* reference count */
};
/**
* Internal structure associated to a domain
*/
struct _virDomain {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
+ virObject object;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the domain external name */
int id; /* the domain ID */
* Internal structure associated to a domain
*/
struct _virNetwork {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
+ virObject object;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the network external name */
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier */
* Internal structure associated to a physical host interface
*/
struct _virInterface {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
+ virObject object;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the network external name */
char *mac; /* the interface MAC address */
* Internal structure associated to a storage pool
*/
struct _virStoragePool {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
+ virObject object;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the storage pool external name */
unsigned char uuid[VIR_UUID_BUFLEN]; /* the storage pool unique identifier */
* Internal structure associated to a storage volume
*/
struct _virStorageVol {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
+ virObject object;
virConnectPtr conn; /* pointer back to the connection */
char *pool; /* Pool name of owner */
char *name; /* the storage vol external name */
* Internal structure associated with a node device
*/
struct _virNodeDevice {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
+ virObject object;
virConnectPtr conn; /* pointer back to the connection */
char *name; /* device name (unique on node) */
char *parent; /* parent device name */
* Internal structure associated with a secret
*/
struct _virSecret {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
+ virObject object;
virConnectPtr conn; /* pointer back to the connection */
unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */
int usageType; /* the type of usage */
* Internal structure associated with an input stream
*/
struct _virStream {
- unsigned int magic;
+ virObject object;
virConnectPtr conn;
- int refs;
unsigned int flags;
virStreamDriverPtr driver;
* Internal structure associated with a domain snapshot
*/
struct _virDomainSnapshot {
- unsigned int magic;
- int refs;
+ virObject object;
char *name;
virDomainPtr domain;
};
-/************************************************************************
- * *
- * API for domain/connections (de)allocations and lookups *
- * *
- ************************************************************************/
+/**
+* _virNWFilter:
+*
+* Internal structure associated to a network filter
+*/
+struct _virNWFilter {
+ virObject object;
+ virConnectPtr conn; /* pointer back to the connection */
+ char *name; /* the network filter external name */
+ unsigned char uuid[VIR_UUID_BUFLEN]; /* the network filter unique identifier */
+};
+
+
+/*
+ * Helper APIs for allocating new object instances
+ */
virConnectPtr virGetConnect(void);
-int virUnrefConnect(virConnectPtr conn);
virDomainPtr virGetDomain(virConnectPtr conn,
const char *name,
const unsigned char *uuid);
-int virUnrefDomain(virDomainPtr domain);
virNetworkPtr virGetNetwork(virConnectPtr conn,
const char *name,
const unsigned char *uuid);
-int virUnrefNetwork(virNetworkPtr network);
-
virInterfacePtr virGetInterface(virConnectPtr conn,
const char *name,
const char *mac);
-int virUnrefInterface(virInterfacePtr iface);
-
virStoragePoolPtr virGetStoragePool(virConnectPtr conn,
- const char *name,
- const unsigned char *uuid);
-int virUnrefStoragePool(virStoragePoolPtr pool);
+ const char *name,
+ const unsigned char *uuid);
virStorageVolPtr virGetStorageVol(virConnectPtr conn,
- const char *pool,
- const char *name,
- const char *key);
-int virUnrefStorageVol(virStorageVolPtr vol);
-
+ const char *pool,
+ const char *name,
+ const char *key);
virNodeDevicePtr virGetNodeDevice(virConnectPtr conn,
const char *name);
-int virUnrefNodeDevice(virNodeDevicePtr dev);
-
virSecretPtr virGetSecret(virConnectPtr conn,
const unsigned char *uuid,
int usageType,
const char *usageID);
-int virUnrefSecret(virSecretPtr secret);
-
virStreamPtr virGetStream(virConnectPtr conn);
-int virUnrefStream(virStreamPtr st);
-
-/**
-* _virNWFilter:
-*
-* Internal structure associated to a network filter
-*/
-struct _virNWFilter {
- unsigned int magic; /* specific value to check */
- int refs; /* reference count */
- virConnectPtr conn; /* pointer back to the connection */
- char *name; /* the network filter external name */
- unsigned char uuid[VIR_UUID_BUFLEN]; /* the network filter unique identifier */
-};
-
virNWFilterPtr virGetNWFilter(virConnectPtr conn,
const char *name,
const unsigned char *uuid);
-int virUnrefNWFilter(virNWFilterPtr nwfilter);
-
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
const char *name);
-int virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot);
-#endif
+#endif /* __VIR_DATATYPES_H__ */