[PATCH 2/5] interface: report link state for bonds and vlans too

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---
 docs/schemas/interface.rng         |  2 ++
 src/conf/interface_conf.c          | 18 ++++++++++++------
 tests/interfaceschemadata/bond.xml |  1 +
 tests/interfaceschemadata/vlan.xml |  1 +
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/docs/schemas/interface.rng b/docs/schemas/interface.rng
index 27610a5..80962d4 100644
--- a/docs/schemas/interface.rng
+++ b/docs/schemas/interface.rng
@@ -78,6 +78,7 @@
          of the form DEVICE.VLAN
     -->
     <optional><ref name="name-attr"/></optional>
+    <ref name="link-speed-state"/>
   </define>
 
   <define name="vlan-device">
@@ -156,6 +157,7 @@
       <value>bond</value>
     </attribute>
     <ref name="name-attr"/>
+    <ref name="link-speed-state"/>
   </define>
 
   <define name="bond-element">
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 2b3f699..397920b 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -669,6 +669,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
     int type;
     char *tmp;
     xmlNodePtr cur = ctxt->node;
+    xmlNodePtr lnk;
+
 
     /* check @type */
     tmp = virXPathString("string(./@type)", ctxt);
@@ -704,20 +706,22 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType)
         goto error;
     }
     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) {
         case VIR_INTERFACE_TYPE_ETHERNET: {
-            xmlNodePtr lnk;
-
             if (virInterfaceDefParseName(def, ctxt) < 0)
                 goto error;
             tmp = virXPathString("string(./mac/@address)", ctxt);
             if (tmp != NULL)
                 def->mac = tmp;
 
-            lnk = virXPathNode("./link", ctxt);
-            if (lnk && virInterfaceLinkParseXML(lnk, &def->lnk) < 0)
-                goto error;
-
             if (parentIfType == VIR_INTERFACE_TYPE_LAST) {
                 /* only recognize these in toplevel bond interfaces */
                 if (virInterfaceDefParseStartMode(def, ctxt) < 0)
@@ -1110,6 +1114,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def)
             break;
         case VIR_INTERFACE_TYPE_BOND:
             virInterfaceStartmodeDefFormat(buf, def->startmode);
+            virInterfaceLinkFormat(buf, &def->lnk);
             if (def->mtu != 0)
                 virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu);
             virInterfaceProtocolDefFormat(buf, def);
@@ -1119,6 +1124,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def)
             virInterfaceStartmodeDefFormat(buf, def->startmode);
             if (def->mac != NULL)
                 virBufferAsprintf(buf, "<mac address='%s'/>\n", def->mac);
+            virInterfaceLinkFormat(buf, &def->lnk);
             if (def->mtu != 0)
                 virBufferAsprintf(buf, "<mtu size='%d'/>\n", def->mtu);
             virInterfaceProtocolDefFormat(buf, def);
diff --git a/tests/interfaceschemadata/bond.xml b/tests/interfaceschemadata/bond.xml
index c4e6d40..cbc1dfa 100644
--- a/tests/interfaceschemadata/bond.xml
+++ b/tests/interfaceschemadata/bond.xml
@@ -1,5 +1,6 @@
 <interface type='bond' name='bond0'>
   <start mode='none'/>
+  <link speed='1000' state='up'/>
   <protocol family='ipv4'>
     <ip address='192.168.50.7' prefix='24'/>
     <route gateway='192.168.50.1'/>
diff --git a/tests/interfaceschemadata/vlan.xml b/tests/interfaceschemadata/vlan.xml
index a9570e3..6432b96 100644
--- a/tests/interfaceschemadata/vlan.xml
+++ b/tests/interfaceschemadata/vlan.xml
@@ -1,5 +1,6 @@
 <interface type='vlan' name='eth0.42'>
   <start mode='onboot'/>
+  <link state='lowerlayerdown'/>
   <protocol family='ipv4'>
     <dhcp peerdns='no'/>
   </protocol>
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]