提交 69db5f92 编写于 作者: L Laine Stump

interface: report link state for bonds and vlans too

The interface state for bonds and vlans does seem to reflect the state
of the underlying physical devices, at least in some cases, so it
makes sense to allow reporting it (netcf now does).

The link state/speed for bridge devices is meaningless though, so we
don't even look for it.
上级 c8e42205
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
of the form DEVICE.VLAN of the form DEVICE.VLAN
--> -->
<optional><ref name="name-attr"/></optional> <optional><ref name="name-attr"/></optional>
<ref name="link-speed-state"/>
</define> </define>
<define name="vlan-device"> <define name="vlan-device">
...@@ -156,6 +157,7 @@ ...@@ -156,6 +157,7 @@
<value>bond</value> <value>bond</value>
</attribute> </attribute>
<ref name="name-attr"/> <ref name="name-attr"/>
<ref name="link-speed-state"/>
</define> </define>
<define name="bond-element"> <define name="bond-element">
......
...@@ -669,6 +669,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) ...@@ -669,6 +669,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
int type; int type;
char *tmp; char *tmp;
xmlNodePtr cur = ctxt->node; xmlNodePtr cur = ctxt->node;
xmlNodePtr lnk;
/* check @type */ /* check @type */
tmp = virXPathString("string(./@type)", ctxt); tmp = virXPathString("string(./@type)", ctxt);
...@@ -704,20 +706,22 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) ...@@ -704,20 +706,22 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
goto error; goto error;
} }
def->type = type; def->type = type;
if (type != VIR_INTERFACE_TYPE_BRIDGE) {
/* link status makes no sense for a bridge */
lnk = virXPathNode("./link", ctxt);
if (lnk && virInterfaceLinkParseXML(lnk, &def->lnk) < 0)
goto error;
}
switch (type) { switch (type) {
case VIR_INTERFACE_TYPE_ETHERNET: { case VIR_INTERFACE_TYPE_ETHERNET: {
xmlNodePtr lnk;
if (virInterfaceDefParseName(def, ctxt) < 0) if (virInterfaceDefParseName(def, ctxt) < 0)
goto error; goto error;
tmp = virXPathString("string(./mac/@address)", ctxt); tmp = virXPathString("string(./mac/@address)", ctxt);
if (tmp != NULL) if (tmp != NULL)
def->mac = tmp; def->mac = tmp;
lnk = virXPathNode("./link", ctxt);
if (lnk && virInterfaceLinkParseXML(lnk, &def->lnk) < 0)
goto error;
if (parentIfType == VIR_INTERFACE_TYPE_LAST) { if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
/* only recognize these in toplevel bond interfaces */ /* only recognize these in toplevel bond interfaces */
if (virInterfaceDefParseStartMode(def, ctxt) < 0) if (virInterfaceDefParseStartMode(def, ctxt) < 0)
...@@ -1110,6 +1114,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def) ...@@ -1110,6 +1114,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def)
break; break;
case VIR_INTERFACE_TYPE_BOND: case VIR_INTERFACE_TYPE_BOND:
virInterfaceStartmodeDefFormat(buf, def->startmode); virInterfaceStartmodeDefFormat(buf, def->startmode);
virInterfaceLinkFormat(buf, &def->lnk);
if (def->mtu != 0) if (def->mtu != 0)
virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu); virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu);
virInterfaceProtocolDefFormat(buf, def); virInterfaceProtocolDefFormat(buf, def);
...@@ -1119,6 +1124,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def) ...@@ -1119,6 +1124,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def)
virInterfaceStartmodeDefFormat(buf, def->startmode); virInterfaceStartmodeDefFormat(buf, def->startmode);
if (def->mac != NULL) if (def->mac != NULL)
virBufferAsprintf(buf, "<mac address='%s'/>\n", def->mac); virBufferAsprintf(buf, "<mac address='%s'/>\n", def->mac);
virInterfaceLinkFormat(buf, &def->lnk);
if (def->mtu != 0) if (def->mtu != 0)
virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu); virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu);
virInterfaceProtocolDefFormat(buf, def); virInterfaceProtocolDefFormat(buf, def);
......
<interface type='bond' name='bond0'> <interface type='bond' name='bond0'>
<start mode='none'/> <start mode='none'/>
<link speed='1000' state='up'/>
<protocol family='ipv4'> <protocol family='ipv4'>
<ip address='192.168.50.7' prefix='24'/> <ip address='192.168.50.7' prefix='24'/>
<route gateway='192.168.50.1'/> <route gateway='192.168.50.1'/>
......
<interface type='vlan' name='eth0.42'> <interface type='vlan' name='eth0.42'>
<start mode='onboot'/> <start mode='onboot'/>
<link state='lowerlayerdown'/>
<protocol family='ipv4'> <protocol family='ipv4'>
<dhcp peerdns='no'/> <dhcp peerdns='no'/>
</protocol> </protocol>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册