mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
virGetinterface matching of MAC and interface name
MAC address of a particular interface may change over time, and the reduced virInterface object (which contains just name and mac) needs to reflect these changes. Since we can't modify the mac address of an existing virInterface (some other thread may currently be using it) we just create a new virInterface, and let the old one die a dignified death when its refct goes to 0. * src/datatypes.c: fix the matching and lifetime of virInterface object accordingly
This commit is contained in:
parent
6eeca586d4
commit
9734c81f3a
@ -516,9 +516,10 @@ virUnrefNetwork(virNetworkPtr network) {
|
|||||||
* @mac: pointer to the mac
|
* @mac: pointer to the mac
|
||||||
*
|
*
|
||||||
* Lookup if the interface is already registered for that connection,
|
* Lookup if the interface is already registered for that connection,
|
||||||
* if yes return a new pointer to it, if no allocate a new structure,
|
* if yes return a new pointer to it (possibly updating the MAC
|
||||||
* and register it in the table. In any case a corresponding call to
|
* address), if no allocate a new structure, and register it in the
|
||||||
* virUnrefInterface() is needed to not leak data.
|
* 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
|
* Returns a pointer to the interface, or NULL in case of failure
|
||||||
*/
|
*/
|
||||||
@ -532,11 +533,9 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
|
|||||||
}
|
}
|
||||||
virMutexLock(&conn->lock);
|
virMutexLock(&conn->lock);
|
||||||
|
|
||||||
/* TODO search by MAC first as they are better differentiators */
|
|
||||||
|
|
||||||
ret = (virInterfacePtr) virHashLookup(conn->interfaces, name);
|
ret = (virInterfacePtr) virHashLookup(conn->interfaces, name);
|
||||||
/* TODO check the MAC */
|
|
||||||
if (ret == NULL) {
|
if ((ret == NULL) || STRCASENEQ(ret->mac, mac)) {
|
||||||
if (VIR_ALLOC(ret) < 0) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
virReportOOMError(conn);
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
@ -593,7 +592,6 @@ virReleaseInterface(virInterfacePtr iface) {
|
|||||||
virConnectPtr conn = iface->conn;
|
virConnectPtr conn = iface->conn;
|
||||||
DEBUG("release interface %p %s", iface, iface->name);
|
DEBUG("release interface %p %s", iface, iface->name);
|
||||||
|
|
||||||
/* TODO search by MAC first as they are better differenciators */
|
|
||||||
if (virHashRemoveEntry(conn->interfaces, iface->name, NULL) < 0)
|
if (virHashRemoveEntry(conn->interfaces, iface->name, NULL) < 0)
|
||||||
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("interface missing from connection hash table"));
|
_("interface missing from connection hash table"));
|
||||||
|
Loading…
Reference in New Issue
Block a user