mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
util: move virInterface(State|Link)/virNetDevFeature from conf to util
These had been declared in conf/device_conf.h, but then used in util/virnetdev.c, meaning that we had to #include conf/device_conf.h in virnetdev.c (which we have for a long time said shouldn't be done. This caused a bigger problem when I tried to #include util/virnetdev.h in a file in src/conf (which is allowed) - for some reason the "device_conf.h: File not found" error. The solution is to move the data types and functions used in util sources from conf to util. Some names were adjusted during the move ("virInterface" --> "virNetDevIf", and "VIR_INTERFACE" --> "VIR_NETDEV_IF")
This commit is contained in:
parent
943a400c0d
commit
638c6e5ba5
@ -32,29 +32,6 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_DEVICE
|
||||
|
||||
VIR_ENUM_IMPL(virInterfaceState,
|
||||
VIR_INTERFACE_STATE_LAST,
|
||||
"" /* value of zero means no state */,
|
||||
"unknown", "notpresent",
|
||||
"down", "lowerlayerdown",
|
||||
"testing", "dormant", "up")
|
||||
|
||||
VIR_ENUM_IMPL(virNetDevFeature,
|
||||
VIR_NET_DEV_FEAT_LAST,
|
||||
"rx",
|
||||
"tx",
|
||||
"sg",
|
||||
"tso",
|
||||
"gso",
|
||||
"gro",
|
||||
"lro",
|
||||
"rxvlan",
|
||||
"txvlan",
|
||||
"ntuple",
|
||||
"rxhash",
|
||||
"rdma",
|
||||
"txudptnl")
|
||||
|
||||
int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
|
||||
bool report)
|
||||
{
|
||||
@ -196,7 +173,7 @@ virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
|
||||
|
||||
int
|
||||
virInterfaceLinkParseXML(xmlNodePtr node,
|
||||
virInterfaceLinkPtr lnk)
|
||||
virNetDevIfLinkPtr lnk)
|
||||
{
|
||||
int ret = -1;
|
||||
char *stateStr, *speedStr;
|
||||
@ -206,7 +183,7 @@ virInterfaceLinkParseXML(xmlNodePtr node,
|
||||
speedStr = virXMLPropString(node, "speed");
|
||||
|
||||
if (stateStr) {
|
||||
if ((state = virInterfaceStateTypeFromString(stateStr)) < 0) {
|
||||
if ((state = virNetDevIfStateTypeFromString(stateStr)) < 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("unknown link state: %s"),
|
||||
stateStr);
|
||||
@ -232,7 +209,7 @@ virInterfaceLinkParseXML(xmlNodePtr node,
|
||||
|
||||
int
|
||||
virInterfaceLinkFormat(virBufferPtr buf,
|
||||
const virInterfaceLink *lnk)
|
||||
const virNetDevIfLink *lnk)
|
||||
{
|
||||
if (!lnk->speed && !lnk->state) {
|
||||
/* If there's nothing to format, return early. */
|
||||
@ -244,7 +221,7 @@ virInterfaceLinkFormat(virBufferPtr buf,
|
||||
virBufferAsprintf(buf, " speed='%u'", lnk->speed);
|
||||
if (lnk->state)
|
||||
virBufferAsprintf(buf, " state='%s'",
|
||||
virInterfaceStateTypeToString(lnk->state));
|
||||
virNetDevIfStateTypeToString(lnk->state));
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,45 +32,7 @@
|
||||
# include "virthread.h"
|
||||
# include "virbuffer.h"
|
||||
# include "virpci.h"
|
||||
|
||||
typedef enum {
|
||||
VIR_INTERFACE_STATE_UNKNOWN = 1,
|
||||
VIR_INTERFACE_STATE_NOT_PRESENT,
|
||||
VIR_INTERFACE_STATE_DOWN,
|
||||
VIR_INTERFACE_STATE_LOWER_LAYER_DOWN,
|
||||
VIR_INTERFACE_STATE_TESTING,
|
||||
VIR_INTERFACE_STATE_DORMANT,
|
||||
VIR_INTERFACE_STATE_UP,
|
||||
VIR_INTERFACE_STATE_LAST
|
||||
} virInterfaceState;
|
||||
|
||||
VIR_ENUM_DECL(virInterfaceState)
|
||||
|
||||
typedef struct _virInterfaceLink virInterfaceLink;
|
||||
typedef virInterfaceLink *virInterfaceLinkPtr;
|
||||
struct _virInterfaceLink {
|
||||
virInterfaceState state; /* link state */
|
||||
unsigned int speed; /* link speed in Mbits per second */
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
VIR_NET_DEV_FEAT_GRXCSUM,
|
||||
VIR_NET_DEV_FEAT_GTXCSUM,
|
||||
VIR_NET_DEV_FEAT_GSG,
|
||||
VIR_NET_DEV_FEAT_GTSO,
|
||||
VIR_NET_DEV_FEAT_GGSO,
|
||||
VIR_NET_DEV_FEAT_GGRO,
|
||||
VIR_NET_DEV_FEAT_LRO,
|
||||
VIR_NET_DEV_FEAT_RXVLAN,
|
||||
VIR_NET_DEV_FEAT_TXVLAN,
|
||||
VIR_NET_DEV_FEAT_NTUPLE,
|
||||
VIR_NET_DEV_FEAT_RXHASH,
|
||||
VIR_NET_DEV_FEAT_RDMA,
|
||||
VIR_NET_DEV_FEAT_TXUDPTNL,
|
||||
VIR_NET_DEV_FEAT_LAST
|
||||
} virNetDevFeature;
|
||||
|
||||
VIR_ENUM_DECL(virNetDevFeature)
|
||||
# include "virnetdev.h"
|
||||
|
||||
typedef enum {
|
||||
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
|
||||
@ -218,9 +180,9 @@ bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
|
||||
virPCIDeviceAddress *addr2);
|
||||
|
||||
int virInterfaceLinkParseXML(xmlNodePtr node,
|
||||
virInterfaceLinkPtr lnk);
|
||||
virNetDevIfLinkPtr lnk);
|
||||
|
||||
int virInterfaceLinkFormat(virBufferPtr buf,
|
||||
const virInterfaceLink *lnk);
|
||||
const virNetDevIfLink *lnk);
|
||||
|
||||
#endif /* __DEVICE_CONF_H__ */
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "network_conf.h"
|
||||
#include "virtpm.h"
|
||||
#include "virstring.h"
|
||||
#include "virnetdev.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
||||
|
||||
|
@ -147,7 +147,7 @@ struct _virInterfaceDef {
|
||||
char *name; /* interface name */
|
||||
unsigned int mtu; /* maximum transmit size in byte */
|
||||
char *mac; /* MAC address */
|
||||
virInterfaceLink lnk; /* interface link info */
|
||||
virNetDevIfLink lnk; /* interface link info */
|
||||
|
||||
virInterfaceStartMode startmode; /* how it is started */
|
||||
|
||||
|
@ -140,7 +140,7 @@ typedef struct _virNodeDevCapData {
|
||||
char *address;
|
||||
unsigned int address_len;
|
||||
char *ifname;
|
||||
virInterfaceLink lnk;
|
||||
virNetDevIfLink lnk;
|
||||
virNodeDevNetCapType subtype; /* LAST -> no subtype */
|
||||
virBitmapPtr features; /* enum virNetDevFeature */
|
||||
} net;
|
||||
|
@ -78,8 +78,6 @@ virCPUModeTypeToString;
|
||||
# conf/device_conf.h
|
||||
virInterfaceLinkFormat;
|
||||
virInterfaceLinkParseXML;
|
||||
virInterfaceStateTypeFromString;
|
||||
virInterfaceStateTypeToString;
|
||||
virPCIDeviceAddressEqual;
|
||||
virPCIDeviceAddressFormat;
|
||||
virPCIDeviceAddressIsValid;
|
||||
@ -1861,6 +1859,8 @@ virNetDevAddRoute;
|
||||
virNetDevClearIPAddress;
|
||||
virNetDevDelMulti;
|
||||
virNetDevExists;
|
||||
virNetDevFeatureTypeFromString;
|
||||
virNetDevFeatureTypeToString;
|
||||
virNetDevGetFeatures;
|
||||
virNetDevGetIndex;
|
||||
virNetDevGetIPAddress;
|
||||
@ -1877,6 +1877,8 @@ virNetDevGetVirtualFunctionIndex;
|
||||
virNetDevGetVirtualFunctionInfo;
|
||||
virNetDevGetVirtualFunctions;
|
||||
virNetDevGetVLanID;
|
||||
virNetDevIfStateTypeFromString;
|
||||
virNetDevIfStateTypeToString;
|
||||
virNetDevIsVirtualFunction;
|
||||
virNetDevReplaceMacAddress;
|
||||
virNetDevReplaceNetConfig;
|
||||
|
@ -2547,10 +2547,33 @@ virNetDevRestoreNetConfig(const char *linkdev ATTRIBUTE_UNUSED,
|
||||
|
||||
#endif /* defined(__linux__) && defined(HAVE_LIBNL) */
|
||||
|
||||
VIR_ENUM_IMPL(virNetDevIfState,
|
||||
VIR_NETDEV_IF_STATE_LAST,
|
||||
"" /* value of zero means no state */,
|
||||
"unknown", "notpresent",
|
||||
"down", "lowerlayerdown",
|
||||
"testing", "dormant", "up")
|
||||
|
||||
VIR_ENUM_IMPL(virNetDevFeature,
|
||||
VIR_NET_DEV_FEAT_LAST,
|
||||
"rx",
|
||||
"tx",
|
||||
"sg",
|
||||
"tso",
|
||||
"gso",
|
||||
"gro",
|
||||
"lro",
|
||||
"rxvlan",
|
||||
"txvlan",
|
||||
"ntuple",
|
||||
"rxhash",
|
||||
"rdma",
|
||||
"txudptnl")
|
||||
|
||||
#ifdef __linux__
|
||||
int
|
||||
virNetDevGetLinkInfo(const char *ifname,
|
||||
virInterfaceLinkPtr lnk)
|
||||
virNetDevIfLinkPtr lnk)
|
||||
{
|
||||
int ret = -1;
|
||||
char *path = NULL;
|
||||
@ -2580,7 +2603,7 @@ virNetDevGetLinkInfo(const char *ifname,
|
||||
|
||||
/* We shouldn't allow 0 here, because
|
||||
* virInterfaceState enum starts from 1. */
|
||||
if ((tmp_state = virInterfaceStateTypeFromString(buf)) <= 0) {
|
||||
if ((tmp_state = virNetDevIfStateTypeFromString(buf)) <= 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to parse: %s"),
|
||||
buf);
|
||||
@ -2593,7 +2616,7 @@ virNetDevGetLinkInfo(const char *ifname,
|
||||
* report several misleading values. While igb reports 65535, realtek goes
|
||||
* with 10. To avoid muddying XML with insane values, don't report link
|
||||
* speed if that's the case. */
|
||||
if (lnk->state != VIR_INTERFACE_STATE_UP) {
|
||||
if (lnk->state != VIR_NETDEV_IF_STATE_UP) {
|
||||
lnk->speed = 0;
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
@ -2638,7 +2661,7 @@ virNetDevGetLinkInfo(const char *ifname,
|
||||
|
||||
int
|
||||
virNetDevGetLinkInfo(const char *ifname,
|
||||
virInterfaceLinkPtr lnk)
|
||||
virNetDevIfLinkPtr lnk)
|
||||
{
|
||||
/* Port me */
|
||||
VIR_DEBUG("Getting link info on %s is not implemented on this platform",
|
||||
|
@ -30,7 +30,6 @@
|
||||
# include "virmacaddr.h"
|
||||
# include "virpci.h"
|
||||
# include "virnetdevvlan.h"
|
||||
# include "device_conf.h"
|
||||
|
||||
# ifdef HAVE_STRUCT_IFREQ
|
||||
typedef struct ifreq virIfreq;
|
||||
@ -74,6 +73,43 @@ struct _virNetDevRxFilter {
|
||||
} vlan;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
VIR_NETDEV_IF_STATE_UNKNOWN = 1,
|
||||
VIR_NETDEV_IF_STATE_NOT_PRESENT,
|
||||
VIR_NETDEV_IF_STATE_DOWN,
|
||||
VIR_NETDEV_IF_STATE_LOWER_LAYER_DOWN,
|
||||
VIR_NETDEV_IF_STATE_TESTING,
|
||||
VIR_NETDEV_IF_STATE_DORMANT,
|
||||
VIR_NETDEV_IF_STATE_UP,
|
||||
VIR_NETDEV_IF_STATE_LAST
|
||||
} virNetDevIfState;
|
||||
|
||||
VIR_ENUM_DECL(virNetDevIfState)
|
||||
|
||||
typedef struct {
|
||||
virNetDevIfState state; /* link state */
|
||||
unsigned int speed; /* link speed in Mbits per second */
|
||||
} virNetDevIfLink, *virNetDevIfLinkPtr;
|
||||
|
||||
typedef enum {
|
||||
VIR_NET_DEV_FEAT_GRXCSUM,
|
||||
VIR_NET_DEV_FEAT_GTXCSUM,
|
||||
VIR_NET_DEV_FEAT_GSG,
|
||||
VIR_NET_DEV_FEAT_GTSO,
|
||||
VIR_NET_DEV_FEAT_GGSO,
|
||||
VIR_NET_DEV_FEAT_GGRO,
|
||||
VIR_NET_DEV_FEAT_LRO,
|
||||
VIR_NET_DEV_FEAT_RXVLAN,
|
||||
VIR_NET_DEV_FEAT_TXVLAN,
|
||||
VIR_NET_DEV_FEAT_NTUPLE,
|
||||
VIR_NET_DEV_FEAT_RXHASH,
|
||||
VIR_NET_DEV_FEAT_RDMA,
|
||||
VIR_NET_DEV_FEAT_TXUDPTNL,
|
||||
VIR_NET_DEV_FEAT_LAST
|
||||
} virNetDevFeature;
|
||||
|
||||
VIR_ENUM_DECL(virNetDevFeature)
|
||||
|
||||
int virNetDevSetupControl(const char *ifname,
|
||||
virIfreq *ifr)
|
||||
ATTRIBUTE_RETURN_CHECK;
|
||||
@ -187,7 +223,7 @@ int virNetDevGetFeatures(const char *ifname,
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
||||
|
||||
int virNetDevGetLinkInfo(const char *ifname,
|
||||
virInterfaceLinkPtr lnk)
|
||||
virNetDevIfLinkPtr lnk)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
virNetDevRxFilterPtr virNetDevRxFilterNew(void)
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
struct testVirNetDevGetLinkInfoData {
|
||||
const char *ifname; /* ifname to get info on */
|
||||
virInterfaceState state; /* expected state */
|
||||
virNetDevIfState state; /* expected state */
|
||||
unsigned int speed; /* expected speed */
|
||||
};
|
||||
|
||||
@ -39,7 +39,7 @@ testVirNetDevGetLinkInfo(const void *opaque)
|
||||
{
|
||||
int ret = -1;
|
||||
const struct testVirNetDevGetLinkInfoData *data = opaque;
|
||||
virInterfaceLink lnk;
|
||||
virNetDevIfLink lnk;
|
||||
|
||||
if (virNetDevGetLinkInfo(data->ifname, &lnk) < 0)
|
||||
goto cleanup;
|
||||
@ -47,8 +47,8 @@ testVirNetDevGetLinkInfo(const void *opaque)
|
||||
if (lnk.state != data->state) {
|
||||
fprintf(stderr,
|
||||
"Fetched link state (%s) doesn't match the expected one (%s)",
|
||||
virInterfaceStateTypeToString(lnk.state),
|
||||
virInterfaceStateTypeToString(data->state));
|
||||
virNetDevIfStateTypeToString(lnk.state),
|
||||
virNetDevIfStateTypeToString(data->state));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -77,9 +77,9 @@ mymain(void)
|
||||
ret = -1; \
|
||||
} while (0)
|
||||
|
||||
DO_TEST_LINK("eth0", VIR_INTERFACE_STATE_UP, 1000);
|
||||
DO_TEST_LINK("lo", VIR_INTERFACE_STATE_UNKNOWN, 0);
|
||||
DO_TEST_LINK("eth0-broken", VIR_INTERFACE_STATE_DOWN, 0);
|
||||
DO_TEST_LINK("eth0", VIR_NETDEV_IF_STATE_UP, 1000);
|
||||
DO_TEST_LINK("lo", VIR_NETDEV_IF_STATE_UNKNOWN, 0);
|
||||
DO_TEST_LINK("eth0-broken", VIR_NETDEV_IF_STATE_DOWN, 0);
|
||||
|
||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user