/** * virGetNWFilter: * @conn: the hypervisor connection * @name: pointer to the network filter pool name * @uuid: pointer to the uuid * * 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 * 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) { 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); if (!(ret = virObjectNew(virNWFilterClass))) return NULL; if (VIR_STRDUP(ret->name, name) < 0) goto error; memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); ret->conn = virObjectRef(conn); return ret; error: virObjectUnref(ret); return NULL; }
/** * virGetSecret: * @conn: the hypervisor connection * @uuid: secret UUID * * 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 virObjectUnref() is needed to not * leak data. * * Returns a pointer to the secret, or NULL in case of failure */ virSecretPtr virGetSecret(virConnectPtr conn, const unsigned char *uuid, int usageType, const char *usageID) { 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); if (!(ret = virObjectNew(virSecretClass))) return NULL; memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); ret->usageType = usageType; if (VIR_STRDUP(ret->usageID, usageID) < 0) goto error; ret->conn = virObjectRef(conn); return ret; error: virObjectUnref(ret); return NULL; }
/** * virGetStorageVol: * @conn: the hypervisor connection * @pool: pool owning the volume * @name: pointer to the storage vol name * @key: pointer to unique key of the volume * * 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. * * 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) { virStorageVolPtr ret = NULL; if (!VIR_IS_CONNECT(conn)) { virLibConnError(VIR_ERR_INVALID_CONN, _("no connection")); return NULL; } virCheckNonNullArgReturn(name, NULL); virCheckNonNullArgReturn(key, NULL); virMutexLock(&conn->lock); 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; 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); } return NULL; }
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain, const char *name) { 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); if (!(ret = virObjectNew(virDomainSnapshotClass))) return NULL; if (VIR_STRDUP(ret->name, name) < 0) goto cleanup; ret->domain = virObjectRef(domain); return ret; cleanup: virObjectUnref(ret); return NULL; }
/** * virGetNodeDevice: * @conn: the hypervisor connection * @name: device name (unique on node) * * 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 * virObjectUnref() is needed to not leak data. * * Returns a pointer to the node device, or NULL in case of failure */ virNodeDevicePtr virGetNodeDevice(virConnectPtr conn, const char *name) { 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); if (!(ret = virObjectNew(virNodeDeviceClass))) return NULL; if (VIR_STRDUP(ret->name, name) < 0) goto error; ret->conn = virObjectRef(conn); return ret; error: virObjectUnref(ret); return NULL; }
/** * virGetInterface: * @conn: the hypervisor connection * @name: pointer to the interface name * @mac: pointer to the mac * * 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 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) { virInterfacePtr 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); /* a NULL mac from caller is okay. Treat it as blank */ if (mac == NULL) mac = ""; if (!(ret = virObjectNew(virInterfaceClass))) return NULL; if (VIR_STRDUP(ret->name, name) < 0 || VIR_STRDUP(ret->mac, mac) < 0) goto error; ret->conn = virObjectRef(conn); return ret; error: virObjectUnref(ret); return NULL; }
/** * virGetSecret: * @conn: the hypervisor connection * @uuid: secret UUID * * 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 * leak data. * * Returns a pointer to the secret, or NULL in case of failure */ virSecretPtr virGetSecret(virConnectPtr conn, const unsigned char *uuid, int usageType, const char *usageID) { virSecretPtr ret = NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; if (!VIR_IS_CONNECT(conn)) { virLibConnError(VIR_ERR_INVALID_CONN, _("no connection")); return NULL; } virCheckNonNullArgReturn(uuid, NULL); virCheckNonNullArgReturn(usageID, NULL); virMutexLock(&conn->lock); virUUIDFormat(uuid, uuidstr); 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; error: if (ret != NULL) { VIR_FREE(ret->usageID); VIR_FREE(ret); } return NULL; }
/** * virGetStoragePool: * @conn: the hypervisor connection * @name: pointer to the storage pool name * @uuid: pointer to the uuid * * 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. * * Returns a pointer to the network, or NULL in case of failure */ virStoragePoolPtr virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uuid) { virStoragePoolPtr ret = NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; if (!VIR_IS_CONNECT(conn)) { virLibConnError(VIR_ERR_INVALID_CONN, _("no connection")); return NULL; } virCheckNonNullArgReturn(name, NULL); virCheckNonNullArgReturn(uuid, NULL); virMutexLock(&conn->lock); virUUIDFormat(uuid, uuidstr); 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; 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); } return NULL; }
/** * virGetInterface: * @conn: the hypervisor connection * @name: pointer to the interface name * @mac: pointer to the mac * * 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 * 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) { virInterfacePtr ret = NULL; if (!VIR_IS_CONNECT(conn)) { virLibConnError(VIR_ERR_INVALID_CONN, _("no connection")); return NULL; } virCheckNonNullArgReturn(name, NULL); /* a NULL mac from caller is okay. Treat it as blank */ if (mac == NULL) mac = ""; virMutexLock(&conn->lock); 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; } ret->magic = VIR_INTERFACE_MAGIC; ret->conn = 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); } return NULL; }
/** * virGetStorageVol: * @conn: the hypervisor connection * @pool: pool owning the volume * @name: pointer to the storage vol name * @key: pointer to unique key of the volume * @privateData: pointer to driver specific private data * @freeFunc: private data cleanup function pointer specfic to driver * * 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 * 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, void *privateData, virFreeCallback freeFunc) { virStorageVolPtr ret = NULL; if (virDataTypesInitialize() < 0) return NULL; if (!VIR_IS_CONNECT(conn)) { virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); return NULL; } virCheckNonNullArgReturn(pool, NULL); virCheckNonNullArgReturn(name, NULL); virCheckNonNullArgReturn(key, NULL); if (!(ret = virObjectNew(virStorageVolClass))) return NULL; if (VIR_STRDUP(ret->pool, pool) < 0 || VIR_STRDUP(ret->name, name) < 0 || VIR_STRDUP(ret->key, key) < 0) goto error; ret->conn = virObjectRef(conn); /* set driver specific data */ ret->privateData = privateData; ret->privateDataFreeFunc = freeFunc; return ret; error: virObjectUnref(ret); return NULL; }
/** * virGetStoragePool: * @conn: the hypervisor connection * @name: pointer to the storage pool name * @uuid: pointer to the uuid * @privateData: pointer to driver specific private data * @freeFunc: private data cleanup function pointer specfic to driver * * 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 * virObjectUnref() is needed to not leak data. * * Returns a pointer to the storage pool, or NULL in case of failure */ virStoragePoolPtr virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uuid, void *privateData, virFreeCallback freeFunc) { 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); if (!(ret = virObjectNew(virStoragePoolClass))) return NULL; if (VIR_STRDUP(ret->name, name) < 0) goto error; ret->conn = virObjectRef(conn); memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN); /* set the driver specific data */ ret->privateData = privateData; ret->privateDataFreeFunc = freeFunc; return ret; error: virObjectUnref(ret); return NULL; }
/** * virAdmConnectGetLibVersion: * @conn: pointer to an active admin connection * @libVer: stores the current remote libvirt version number * * Retrieves the remote side libvirt version used by the daemon. Format * returned in @libVer is of a following pattern: * major * 1,000,000 + minor * 1,000 + release. * * Returns 0 on success, -1 on failure and @libVer follows this format: */ int virAdmConnectGetLibVersion(virAdmConnectPtr conn, unsigned long long *libVer) { VIR_DEBUG("conn=%p, libVir=%p", conn, libVer); virResetLastError(); virCheckAdmConnectReturn(conn, -1); virCheckNonNullArgReturn(libVer, -1); if (remoteAdminConnectGetLibVersion(conn, libVer) < 0) goto error; return 0; error: virDispatchError(NULL); return -1; }
/** * virGetNodeDevice: * @conn: the hypervisor connection * @name: device name (unique on node) * * 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. * * Returns a pointer to the node device, or NULL in case of failure */ virNodeDevicePtr virGetNodeDevice(virConnectPtr conn, const char *name) { virNodeDevicePtr ret = NULL; if (!VIR_IS_CONNECT(conn)) { virLibConnError(VIR_ERR_INVALID_CONN, _("no connection")); return NULL; } virCheckNonNullArgReturn(name, NULL); virMutexLock(&conn->lock); 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; } conn->refs++; ret->refs++; virMutexUnlock(&conn->lock); return ret; error: if (ret != NULL) { VIR_FREE(ret->name); VIR_FREE(ret); } return NULL; }
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain, const char *name) { virDomainSnapshotPtr ret = NULL; if (!VIR_IS_DOMAIN(domain)) { virLibConnError(VIR_ERR_INVALID_DOMAIN, _("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; domain->refs++; ret->refs++; virMutexUnlock(&domain->conn->lock); return ret; error: if (ret != NULL) { VIR_FREE(ret->name); VIR_FREE(ret); } return NULL; }