mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00:00
interface: re-use name and mac address rather than re-retrieving
Getting the MAC address of an interface is actually fairly expensive, and we've already gotten it and stored it into def, so just keep def around a bit longer and retrieve it from there. This reduces the time for "virsh iface-list --all" from 28 to 23 seconds when there are 400 interfaces.
This commit is contained in:
parent
6fda6699e5
commit
070732735f
@ -583,6 +583,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
virInterfaceDefPtr def;
|
virInterfaceDefPtr def;
|
||||||
|
|
||||||
iface = ncf_lookup_by_name(driver->netcf, names[i]);
|
iface = ncf_lookup_by_name(driver->netcf, names[i]);
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
const char *errmsg, *details;
|
const char *errmsg, *details;
|
||||||
@ -615,27 +616,26 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
virInterfaceDefFree(def);
|
virInterfaceDefFree(def);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
virInterfaceDefFree(def);
|
|
||||||
|
|
||||||
/* XXX: Filter the result, need to be split once new filter flags
|
/* XXX: Filter the result, need to be split once new filter flags
|
||||||
* except active|inactive are supported.
|
* except active|inactive are supported.
|
||||||
*/
|
*/
|
||||||
if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
|
||||||
!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && active) ||
|
!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && active) ||
|
||||||
(MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !active))) {
|
(MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !active))) {
|
||||||
|
virInterfaceDefFree(def);
|
||||||
ncf_if_free(iface);
|
ncf_if_free(iface);
|
||||||
iface = NULL;
|
iface = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifaces) {
|
if (ifaces) {
|
||||||
if (!(iface_obj = virGetInterface(conn, ncf_if_name(iface),
|
if (!(iface_obj = virGetInterface(conn, def->name, def->mac)))
|
||||||
ncf_if_mac_string(iface))))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
tmp_iface_objs[niface_objs] = iface_obj;
|
tmp_iface_objs[niface_objs] = iface_obj;
|
||||||
}
|
}
|
||||||
niface_objs++;
|
niface_objs++;
|
||||||
|
|
||||||
|
virInterfaceDefFree(def);
|
||||||
ncf_if_free(iface);
|
ncf_if_free(iface);
|
||||||
iface = NULL;
|
iface = NULL;
|
||||||
}
|
}
|
||||||
@ -698,7 +698,7 @@ static virInterfacePtr netcfInterfaceLookupByName(virConnectPtr conn,
|
|||||||
if (virInterfaceLookupByNameEnsureACL(conn, def) < 0)
|
if (virInterfaceLookupByNameEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virGetInterface(conn, ncf_if_name(iface), ncf_if_mac_string(iface));
|
ret = virGetInterface(conn, def->name, def->mac);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
ncf_if_free(iface);
|
ncf_if_free(iface);
|
||||||
@ -746,7 +746,7 @@ static virInterfacePtr netcfInterfaceLookupByMACString(virConnectPtr conn,
|
|||||||
if (virInterfaceLookupByMACStringEnsureACL(conn, def) < 0)
|
if (virInterfaceLookupByMACStringEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virGetInterface(conn, ncf_if_name(iface), ncf_if_mac_string(iface));
|
ret = virGetInterface(conn, def->name, def->mac);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
ncf_if_free(iface);
|
ncf_if_free(iface);
|
||||||
|
Loading…
Reference in New Issue
Block a user