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

Re: [libvirt] [PATCH 2/5] macvtap support for libvirt -- parse new interface XML



On Mon, Feb 08, 2010 at 02:36:51PM -0500, Stefan Berger wrote:
> This part adds support to domain_conf.{c|h} for parsing the new
> interface XML of type 'direct'. The parsed mode is now stored as 
> an int.
> 
> Signed-off-by: Stefan Berger <stefanb us ibm com>
> 
> 
> 
> 
> 

> Index: libvirt-macvtap/src/conf/domain_conf.c
> ===================================================================
> --- libvirt-macvtap.orig/src/conf/domain_conf.c
> +++ libvirt-macvtap/src/conf/domain_conf.c
> @@ -41,6 +41,7 @@
>  #include "c-ctype.h"
>  #include "logging.h"
>  #include "network.h"
> +#include "macvtap.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_DOMAIN
>  
> @@ -140,7 +141,8 @@ VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_N
>                "mcast",
>                "network",
>                "bridge",
> -              "internal")
> +              "internal",
> +              "direct")
>  
>  VIR_ENUM_IMPL(virDomainChrTarget, VIR_DOMAIN_CHR_TARGET_TYPE_LAST,
>                "null",
> @@ -222,6 +224,12 @@ VIR_ENUM_IMPL(virDomainSeclabel, VIR_DOM
>                "dynamic",
>                "static")
>  
> +VIR_ENUM_IMPL(virDomainNetdevMacvtap, VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
> +              "vepa",
> +              "private",
> +              "bridge")
> +
> +
>  #define virDomainReportError(conn, code, fmt...)                           \
>          virReportErrorHelper(conn, VIR_FROM_DOMAIN, code, __FILE__,        \
>                                 __FUNCTION__, __LINE__, fmt)
> @@ -430,6 +438,10 @@ void virDomainNetDefFree(virDomainNetDef
>      case VIR_DOMAIN_NET_TYPE_INTERNAL:
>          VIR_FREE(def->data.internal.name);
>          break;
> +
> +    case VIR_DOMAIN_NET_TYPE_DIRECT:
> +        VIR_FREE(def->data.direct.linkdev);
> +        break;
>      }
>  
>      VIR_FREE(def->ifname);
> @@ -1631,6 +1643,7 @@ virDomainNetDefParseXML(virConnectPtr co
>      char *model = NULL;
>      char *internal = NULL;
>      char *devaddr = NULL;
> +    char *mode = NULL;
>  
>      if (VIR_ALLOC(def) < 0) {
>          virReportOOMError(conn);
> @@ -1667,9 +1680,11 @@ virDomainNetDefParseXML(virConnectPtr co
>                         (xmlStrEqual(cur->name, BAD_CAST "source"))) {
>                  bridge = virXMLPropString(cur, "bridge");
>              } else if ((dev == NULL) &&
> -                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET) &&
> +                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
> +                        def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
>                         xmlStrEqual(cur->name, BAD_CAST "source")) {
> -                dev = virXMLPropString(cur, "dev");
> +                dev  = virXMLPropString(cur, "dev");
> +                mode = virXMLPropString(cur, "mode");
>              } else if ((network == NULL) &&
>                         ((def->type == VIR_DOMAIN_NET_TYPE_SERVER) ||
>                          (def->type == VIR_DOMAIN_NET_TYPE_CLIENT) ||
> @@ -1823,6 +1838,29 @@ virDomainNetDefParseXML(virConnectPtr co
>          def->data.internal.name = internal;
>          internal = NULL;
>          break;
> +
> +    case VIR_DOMAIN_NET_TYPE_DIRECT:
> +        if (dev == NULL) {
> +            virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
> +        _("No <source> 'dev' attribute specified with <interface type='direct'/>"));
> +            goto error;
> +        }
> +
> +        if (mode != NULL) {
> +            int m;
> +            if ((m = virDomainNetdevMacvtapTypeFromString(mode)) < 0) {
> +                virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
> +                                     _("Unkown mode has been specified"));
> +                goto error;
> +            }
> +            def->data.direct.mode = m;
> +        } else
> +            def->data.direct.mode = VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA;
> +
> +        def->data.direct.linkdev = dev;
> +        dev = NULL;
> +
> +        break;
>      }
>  
>      if (ifname != NULL) {
> @@ -4796,6 +4834,13 @@ virDomainNetDefFormat(virConnectPtr conn
>                                def->data.internal.name);
>          break;
>  
> +    case VIR_DOMAIN_NET_TYPE_DIRECT:
> +        virBufferEscapeString(buf, "      <source dev='%s'",
> +                              def->data.direct.linkdev);
> +        virBufferEscapeString(buf, " mode='%s'",
> +                   virDomainNetdevMacvtapTypeToString(def->data.direct.mode));
> +        virBufferAddLit(buf, "/>\n");
> +        break;
>      }
>  
>      if (def->ifname)
> Index: libvirt-macvtap/src/conf/domain_conf.h
> ===================================================================
> --- libvirt-macvtap.orig/src/conf/domain_conf.h
> +++ libvirt-macvtap/src/conf/domain_conf.h
> @@ -211,11 +211,22 @@ enum virDomainNetType {
>      VIR_DOMAIN_NET_TYPE_NETWORK,
>      VIR_DOMAIN_NET_TYPE_BRIDGE,
>      VIR_DOMAIN_NET_TYPE_INTERNAL,
> +    VIR_DOMAIN_NET_TYPE_DIRECT,
>  
>      VIR_DOMAIN_NET_TYPE_LAST,
>  };
>  
>  
> +/* the mode type for macvtap devices */
> +enum virDomainNetdevMacvtapType {
> +    VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA,
> +    VIR_DOMAIN_NETDEV_MACVTAP_MODE_PRIVATE,
> +    VIR_DOMAIN_NETDEV_MACVTAP_MODE_BRIDGE,
> +
> +    VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
> +};
> +
> +
>  /* Stores the virtual network interface configuration */
>  typedef struct _virDomainNetDef virDomainNetDef;
>  typedef virDomainNetDef *virDomainNetDefPtr;
> @@ -244,6 +255,10 @@ struct _virDomainNetDef {
>          struct {
>              char *name;
>          } internal;
> +        struct {
> +            char *linkdev;
> +            int mode;
> +        } direct;
>      } data;
>      char *ifname;
>      virDomainDeviceInfo info;
> @@ -594,6 +609,8 @@ struct _virSecurityLabelDef {
>      int type;
>  };
>  
> +
> +
>  #define VIR_DOMAIN_CPUMASK_LEN 1024
>  
>  /* Guest VM main configuration */
> @@ -915,4 +932,6 @@ VIR_ENUM_DECL(virDomainGraphics)
>  VIR_ENUM_DECL(virDomainState)
>  VIR_ENUM_DECL(virDomainSeclabel)
>  
> +VIR_ENUM_DECL(virDomainNetdevMacvtap)
> +
>  #endif /* __DOMAIN_CONF_H */

ACK, looks good now

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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