Re: [PATCH v3 2/5] link-state: conf: Add element to XML for controling link state

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

 



On Mon, Sep 05, 2011 at 05:26:51PM +0200, Peter Krempa wrote:
> A new element is introduced to XML that allows to control
> state of virtual network interfaces in hypervisors.
> 
> Live modification of the link state allows networking tools
> propagate topology changes to guest OS or testing of
> scenarios in complex (virtual) networks.
> 
> This patch adds elements to XML grammars and parsing and generating
> code.
> 
>  docs/formatdomain.html.in  - Documentation of new element
>  docs/schemas/network.rng   - Grammar for the new element
>  src/conf/domain_conf.c     - Parsing and generating code
>  src/conf/domain_conf.h     - Enum of available link states
> ---
>  docs/formatdomain.html.in |   21 +++++++++++++++++++++
>  docs/schemas/network.rng  |   11 +++++++++++
>  src/conf/domain_conf.c    |   24 ++++++++++++++++++++++++
>  src/conf/domain_conf.h    |   11 +++++++++++
>  4 files changed, 67 insertions(+), 0 deletions(-)
> 
> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> index b960381..53de6c8 100644
> --- a/docs/formatdomain.html.in
> +++ b/docs/formatdomain.html.in
> @@ -2092,6 +2092,27 @@ qemu-kvm -net nic,model=? /dev/null
>        <span class="since">Since 0.9.4</span>
>      </p>
> 
> +    <h5><a name="elementLink">Modyfing virtual link state</a></h5>
> +<pre>
> +  ...
> +  &lt;devices&gt;
> +    &lt;interface type='network'&gt;
> +      &lt;source network='default'/&gt;
> +      &lt;target dev='vnet0'/&gt;
> +      <b>&lt;link state='down'/&gt;</b>
> +    &lt;/interface&gt;
> +  &lt;devices&gt;
> +  ...</pre>
> +
> +    <p>
> +      This element provides means of setting state of the virtual network link.
> +      Possible values for attribute <code>state</code> are <code>up</code> and
> +      <code>down</code>. If <code>down</code> is specified as the value, the interface
> +      behaves as if it had the network cable disconnected. Default behavior if this
> +      element is unspecified is to have the link state <code>up</code>.
> +      <span class="since">Since 0.9.5</span>
> +    </p>
> +
>      <h4><a name="elementsInput">Input devices</a></h4>
> 
>      <p>
> diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng
> index 1c44471..937e180 100644
> --- a/docs/schemas/network.rng
> +++ b/docs/schemas/network.rng
> @@ -150,6 +150,17 @@
>         <optional>
>           <ref name="bandwidth"/>
>         </optional>
> +       <optional>
> +         <element name="link">
> +           <attribute name="state">
> +             <choice>
> +               <value>up</value>
> +               <value>down</value>
> +             </choice>
> +           </attribute>
> +           <empty/>
> +         </element>
> +        </optional>
> 
>          <!-- <ip> element -->
>          <zeroOrMore>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index cce9955..75431fb 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -251,6 +251,11 @@ VIR_ENUM_IMPL(virDomainNetVirtioTxMode, VIR_DOMAIN_NET_VIRTIO_TX_MODE_LAST,
>                "iothread",
>                "timer")
> 
> +VIR_ENUM_IMPL(virDomainNetInterfaceLinkState, VIR_DOMAIN_NET_INTERFACE_LINK_STATE_LAST,
> +              "default",
> +              "up",
> +              "down")
> +
>  VIR_ENUM_IMPL(virDomainChrChannelTarget,
>                VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST,
>                "guestfwd",
> @@ -2945,6 +2950,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
>      char *internal = NULL;
>      char *devaddr = NULL;
>      char *mode = NULL;
> +    char *linkstate = NULL;
>      virNWFilterHashTablePtr filterparams = NULL;
>      virVirtualPortProfileParamsPtr virtPort = NULL;
>      virDomainActualNetDefPtr actual = NULL;
> @@ -3021,6 +3027,9 @@ virDomainNetDefParseXML(virCapsPtr caps,
>                      /* An auto-generated target name, blank it out */
>                      VIR_FREE(ifname);
>                  }
> +            } else if ((linkstate == NULL) &&
> +                       xmlStrEqual(cur->name, BAD_CAST "link")) {
> +                linkstate = virXMLPropString(cur, "state");
>              } else if ((script == NULL) &&
>                         (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
>                          def->type == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
> @@ -3285,6 +3294,16 @@ virDomainNetDefParseXML(virCapsPtr caps,
>          }
>      }
> 
> +    def->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT;
> +    if (linkstate != NULL) {
> +        if ((def->linkstate = virDomainNetInterfaceLinkStateTypeFromString(linkstate)) <= 0) {
> +            virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                                 _("unknown interface link state '%s'"),
> +                                 linkstate);
> +            goto error;

   right it catches state='default' as unknown :-)

> +        }
> +    }
> +
>      if (filter != NULL) {
>          switch (def->type) {
>          case VIR_DOMAIN_NET_TYPE_ETHERNET:
> @@ -3332,6 +3351,7 @@ cleanup:
>      VIR_FREE(internal);
>      VIR_FREE(devaddr);
>      VIR_FREE(mode);
> +    VIR_FREE(linkstate);
>      virNWFilterHashTableFree(filterparams);
> 
>      return def;
> @@ -9429,6 +9449,10 @@ virDomainNetDefFormat(virBufferPtr buf,
>          virBufferAddLit(buf,   "      </tune>\n");
>      }
> 
> +    if (def->linkstate)
> +        virBufferAsprintf(buf, "      <link state='%s'/>\n",
> +                          virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
> +
>      if (virBandwidthDefFormat(buf, def->bandwidth, "      ") < 0)
>          return -1;
> 
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index e218a30..dc094f7 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -394,6 +394,15 @@ enum virDomainNetVirtioTxModeType {
>      VIR_DOMAIN_NET_VIRTIO_TX_MODE_LAST,
>  };
> 
> +/* link interface states */
> +enum virDomainNetInterfaceLinkState {
> +        VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT = 0, /* Default link state (up) */
> +        VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP,          /* Link is up. ("cable" connected) */
> +        VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN ,       /* Link is down. ("cable" disconnected) */
> +
> +        VIR_DOMAIN_NET_INTERFACE_LINK_STATE_LAST
> +};
> +
>  /* Config that was actually used to bring up interface, after
>   * resolving network reference. This is private data, only used within
>   * libvirt, but still must maintain backward compatibility, because
> @@ -479,6 +488,7 @@ struct _virDomainNetDef {
>      char *filter;
>      virNWFilterHashTablePtr filterparams;
>      virBandwidthPtr bandwidth;
> +    int linkstate;
>  };
> 
>  /* Used for prefix of ifname of any network name generated dynamically
> @@ -1789,6 +1799,7 @@ VIR_ENUM_DECL(virDomainFSAccessMode)
>  VIR_ENUM_DECL(virDomainNet)
>  VIR_ENUM_DECL(virDomainNetBackend)
>  VIR_ENUM_DECL(virDomainNetVirtioTxMode)
> +VIR_ENUM_DECL(virDomainNetInterfaceLinkState)
>  VIR_ENUM_DECL(virDomainChrDevice)
>  VIR_ENUM_DECL(virDomainChrChannelTarget)
>  VIR_ENUM_DECL(virDomainChrConsoleTarget)

  ACK, looks fine,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
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]