mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
interface: list all interfaces with flags == 0
virConnectListAllInterfaces should support to list all of interfaces when the value of flags is 0. The behaviour is consistent with other virConnectListAll* APIs
This commit is contained in:
parent
83e4c77547
commit
7ac2c4fe62
@ -211,4 +211,8 @@ char *virInterfaceDefFormat(const virInterfaceDefPtr def);
|
|||||||
void virInterfaceObjLock(virInterfaceObjPtr obj);
|
void virInterfaceObjLock(virInterfaceObjPtr obj);
|
||||||
void virInterfaceObjUnlock(virInterfaceObjPtr obj);
|
void virInterfaceObjUnlock(virInterfaceObjPtr obj);
|
||||||
|
|
||||||
|
#define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE \
|
||||||
|
(VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
|
||||||
|
VIR_CONNECT_LIST_INTERFACES_INACTIVE)
|
||||||
|
|
||||||
#endif /* __INTERFACE_CONF_H__ */
|
#endif /* __INTERFACE_CONF_H__ */
|
||||||
|
@ -260,6 +260,7 @@ static int netcfConnectListDefinedInterfaces(virConnectPtr conn, char **const na
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MATCH(FLAG) (flags & (FLAG))
|
||||||
static int
|
static int
|
||||||
netcfConnectListAllInterfaces(virConnectPtr conn,
|
netcfConnectListAllInterfaces(virConnectPtr conn,
|
||||||
virInterfacePtr **ifaces,
|
virInterfacePtr **ifaces,
|
||||||
@ -276,8 +277,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
|
|
||||||
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
|
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
|
||||||
VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
|
|
||||||
|
|
||||||
interfaceDriverLock(driver);
|
interfaceDriverLock(driver);
|
||||||
|
|
||||||
@ -293,7 +293,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
_("failed to get number of host interfaces: %s%s%s"),
|
_("failed to get number of host interfaces: %s%s%s"),
|
||||||
errmsg, details ? " - " : "",
|
errmsg, details ? " - " : "",
|
||||||
details ? details : "");
|
details ? details : "");
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +303,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
|
|
||||||
if (VIR_ALLOC_N(names, count) < 0) {
|
if (VIR_ALLOC_N(names, count) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,16 +359,19 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
/* XXX: Filter the result, need to be splitted once new filter flags
|
/* XXX: Filter the result, need to be splitted once new filter flags
|
||||||
* except active|inactive are supported.
|
* except active|inactive are supported.
|
||||||
*/
|
*/
|
||||||
if (((status & NETCF_IFACE_ACTIVE) &&
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
|
||||||
(flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
|
!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
|
||||||
((status & NETCF_IFACE_INACTIVE) &&
|
(status & NETCF_IFACE_ACTIVE)) ||
|
||||||
(flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
|
(MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
|
||||||
if (ifaces) {
|
(status & NETCF_IFACE_INACTIVE)))) {
|
||||||
iface_obj = virGetInterface(conn, ncf_if_name(iface),
|
ncf_if_free(iface);
|
||||||
ncf_if_mac_string(iface));
|
continue;
|
||||||
tmp_iface_objs[niface_objs] = iface_obj;
|
}
|
||||||
}
|
|
||||||
niface_objs++;
|
if (ifaces) {
|
||||||
|
iface_obj = virGetInterface(conn, ncf_if_name(iface),
|
||||||
|
ncf_if_mac_string(iface));
|
||||||
|
tmp_iface_objs[niface_objs++] = iface_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
ncf_if_free(iface);
|
ncf_if_free(iface);
|
||||||
|
@ -282,6 +282,7 @@ udevConnectListDefinedInterfaces(virConnectPtr conn,
|
|||||||
VIR_UDEV_IFACE_INACTIVE);
|
VIR_UDEV_IFACE_INACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MATCH(FLAG) (flags & (FLAG))
|
||||||
static int
|
static int
|
||||||
udevConnectListAllInterfaces(virConnectPtr conn,
|
udevConnectListAllInterfaces(virConnectPtr conn,
|
||||||
virInterfacePtr **ifaces,
|
virInterfacePtr **ifaces,
|
||||||
@ -299,8 +300,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
int status = 0;
|
int status = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
|
virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
|
||||||
VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
|
|
||||||
|
|
||||||
/* Grab a udev reference */
|
/* Grab a udev reference */
|
||||||
udev = udev_ref(driverState->udev);
|
udev = udev_ref(driverState->udev);
|
||||||
@ -354,7 +354,6 @@ udevConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
const char *path;
|
const char *path;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *macaddr;
|
const char *macaddr;
|
||||||
int add_to_list = 0;
|
|
||||||
|
|
||||||
path = udev_list_entry_get_name(dev_entry);
|
path = udev_list_entry_get_name(dev_entry);
|
||||||
dev = udev_device_new_from_syspath(udev, path);
|
dev = udev_device_new_from_syspath(udev, path);
|
||||||
@ -363,18 +362,17 @@ udevConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
|
status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
|
||||||
|
|
||||||
/* Filter the results */
|
/* Filter the results */
|
||||||
if (status && (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE))
|
if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
|
||||||
add_to_list = 1;
|
!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && status) ||
|
||||||
else if (!status && (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))
|
(MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !status))) {
|
||||||
add_to_list = 1;
|
udev_device_unref(dev);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* If we matched a filter, then add it */
|
/* If we matched a filter, then add it */
|
||||||
if (add_to_list) {
|
if (ifaces) {
|
||||||
if (ifaces) {
|
iface_obj = virGetInterface(conn, name, macaddr);
|
||||||
iface_obj = virGetInterface(conn, name, macaddr);
|
ifaces_list[count++] = iface_obj;
|
||||||
ifaces_list[count] = iface_obj;
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
udev_device_unref(dev);
|
udev_device_unref(dev);
|
||||||
}
|
}
|
||||||
@ -387,6 +385,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
|
|||||||
if (ifaces) {
|
if (ifaces) {
|
||||||
ignore_value(VIR_REALLOC_N(ifaces_list, count + 1));
|
ignore_value(VIR_REALLOC_N(ifaces_list, count + 1));
|
||||||
*ifaces = ifaces_list;
|
*ifaces = ifaces_list;
|
||||||
|
ifaces_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
Loading…
Reference in New Issue
Block a user