mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00:00
interface: let netcf pre-filter for active vs. inactive
If a system has a large number of active or active interfaces, it can be a big waste of time to retrieve and qualify all interfaces if the caller only wanted one subset. Since netcf has a simple flag for this, translate the libvirt flag into a netcf flag and let netcf pre-filter.
This commit is contained in:
parent
070732735f
commit
ce692d5ea6
@ -528,10 +528,10 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
unsigned int ncf_flags = 0;
|
||||||
struct netcf_if *iface = NULL;
|
struct netcf_if *iface = NULL;
|
||||||
virInterfacePtr *tmp_iface_objs = NULL;
|
virInterfacePtr *tmp_iface_objs = NULL;
|
||||||
virInterfacePtr iface_obj = NULL;
|
virInterfacePtr iface_obj = NULL;
|
||||||
bool active;
|
|
||||||
int niface_objs = 0;
|
int niface_objs = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
@ -543,14 +543,20 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
|
|
||||||
virObjectLock(driver);
|
virObjectLock(driver);
|
||||||
|
|
||||||
/* List all interfaces, in case of we might support new filter flags
|
/* let netcf pre-filter for this flag to save time */
|
||||||
* except active|inactive in future.
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE)) {
|
||||||
*/
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE))
|
||||||
count = ncf_num_of_interfaces(driver->netcf, NETCF_IFACE_ACTIVE |
|
ncf_flags |= NETCF_IFACE_ACTIVE;
|
||||||
NETCF_IFACE_INACTIVE);
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE))
|
||||||
if (count < 0) {
|
ncf_flags |= NETCF_IFACE_INACTIVE;
|
||||||
|
} else {
|
||||||
|
ncf_flags = NETCF_IFACE_ACTIVE | NETCF_IFACE_INACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((count = ncf_num_of_interfaces(driver->netcf, ncf_flags)) < 0) {
|
||||||
const char *errmsg, *details;
|
const char *errmsg, *details;
|
||||||
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
||||||
|
|
||||||
virReportError(netcf_to_vir_err(errcode),
|
virReportError(netcf_to_vir_err(errcode),
|
||||||
_("failed to get number of host interfaces: %s%s%s"),
|
_("failed to get number of host interfaces: %s%s%s"),
|
||||||
errmsg, details ? " - " : "",
|
errmsg, details ? " - " : "",
|
||||||
@ -566,11 +572,11 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
if (VIR_ALLOC_N(names, count) < 0)
|
if (VIR_ALLOC_N(names, count) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((count = ncf_list_interfaces(driver->netcf, count, names,
|
if ((count = ncf_list_interfaces(driver->netcf, count,
|
||||||
NETCF_IFACE_ACTIVE |
|
names, ncf_flags)) < 0) {
|
||||||
NETCF_IFACE_INACTIVE)) < 0) {
|
|
||||||
const char *errmsg, *details;
|
const char *errmsg, *details;
|
||||||
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
int errcode = ncf_error(driver->netcf, &errmsg, &details);
|
||||||
|
|
||||||
virReportError(netcf_to_vir_err(errcode),
|
virReportError(netcf_to_vir_err(errcode),
|
||||||
_("failed to list host interfaces: %s%s%s"),
|
_("failed to list host interfaces: %s%s%s"),
|
||||||
errmsg, details ? " - " : "",
|
errmsg, details ? " - " : "",
|
||||||
@ -604,9 +610,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netcfInterfaceObjIsActive(iface, &active) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
if (!(def = netcfGetMinimalDefForDevice(iface)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -616,17 +619,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
virInterfaceDefFree(def);
|
virInterfaceDefFree(def);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* XXX: Filter the result, need to be split once new filter flags
|
|
||||||
* except active|inactive are supported.
|
|
||||||
*/
|
|
||||||
if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
|
|
||||||
!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && active) ||
|
|
||||||
(MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !active))) {
|
|
||||||
virInterfaceDefFree(def);
|
|
||||||
ncf_if_free(iface);
|
|
||||||
iface = NULL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ifaces) {
|
if (ifaces) {
|
||||||
if (!(iface_obj = virGetInterface(conn, def->name, def->mac)))
|
if (!(iface_obj = virGetInterface(conn, def->name, def->mac)))
|
||||||
|
Loading…
Reference in New Issue
Block a user