[libvirt] [PATCH 1/1] Initial POC of port profile id support

Stefan Berger stefanb at us.ibm.com
Mon Apr 26 12:17:05 UTC 2010


libvir-list-bounces at redhat.com wrote on 04/02/2010 11:42:03 AM:


> 
> On 03/31/2010 06:28 AM, Daniel P. Berrange wrote:
> > On Tue, Mar 30, 2010 at 05:30:56PM -0400, David Allan wrote:
> >> ---
[...]


> >
> > Wouldn't this also be valid for the type=bridge networking mode, since
> > that is connecting VMs to the LAN too.
> 
> Agreed with both; an updated patch is attached.  I also added a test for 

> the new element.
> 
> Dave


>
>From a945107f047c7cd71f9c1b74fd74c47d8cdc3670 Mon Sep 17 00:00:00 2001
From: David Allan <dallan at redhat.com>
Date: Fri, 12 Mar 2010 13:25:04 -0500
Subject: [PATCH 1/1] POC of port profile id support

* Modified schema per DanPB's feedback
* Added test for modified schema
---
 docs/schemas/domain.rng                |   13 +++++++++++++
 src/conf/domain_conf.c                 |   12 ++++++++++++
 src/conf/domain_conf.h                 |    1 +
 src/libvirt_private.syms               |    3 +++
 src/qemu/qemu_conf.c                   |   12 ++++++++++++
 src/util/macvtap.c                     |   13 +++++++++++++
 src/util/macvtap.h                     |    4 ++++
 tests/domainschemadata/portprofile.xml |   15 +++++++++++++++
 8 files changed, 73 insertions(+), 0 deletions(-)
 create mode 100644 tests/domainschemadata/portprofile.xml

diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 228665c..53280ce 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -816,6 +816,9 @@
               </optional>
               <empty/>
             </element>
+            <optional>
+              <ref name="switchPort"/>
+            </optional>
             <ref name="interface-options"/>
           </interleave>
         </group>
@@ -896,6 +899,16 @@
       </optional>
     </interleave>
   </define>
+  <define name="switchPort">
+    <element name="switchport">
+      <optional>
+        <attribute name="profile">
+          <text/>
+        </attribute>
+      </optional>
+      <empty/>
+    </element>
+  </define>
   <!--
       An emulator description is just a path to the binary used for the 
task
     -->
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 067f053..d2b791f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -481,6 +481,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def)

     case VIR_DOMAIN_NET_TYPE_DIRECT:
         VIR_FREE(def->data.direct.linkdev);
+        VIR_FREE(def->data.direct.profileid);
         break;

     case VIR_DOMAIN_NET_TYPE_USER:
@@ -1823,6 +1824,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
     char *internal = NULL;
     char *devaddr = NULL;
     char *mode = NULL;
+    char *profileid = NULL;
     virNWFilterHashTablePtr filterparams = NULL;

     if (VIR_ALLOC(def) < 0) {
@@ -1865,6 +1867,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
                        xmlStrEqual(cur->name, BAD_CAST "source")) {
                 dev  = virXMLPropString(cur, "dev");
                 mode = virXMLPropString(cur, "mode");
+                profileid = virXMLPropString(cur, "profileid");




COMMENT:

For the above code to be able to parse this 

+      <source dev='eth0' mode='vepa'/>
+      <switchport profile='foo'/>


I think you'll first need to find a switchport element.


             } else if ((network == NULL) &&
                        ((def->type == VIR_DOMAIN_NET_TYPE_SERVER) ||
                         (def->type == VIR_DOMAIN_NET_TYPE_CLIENT) ||
@@ -2040,6 +2043,10 @@ virDomainNetDefParseXML(virCapsPtr caps,
         } else
             def->data.direct.mode = VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA;

+        if (profileid != NULL) {
+            def->data.direct.profileid = profileid;
+        }
+
         def->data.direct.linkdev = dev;
         dev = NULL;

@@ -2105,6 +2112,7 @@ cleanup:
     VIR_FREE(internal);
     VIR_FREE(devaddr);
     VIR_FREE(mode);
+    VIR_FREE(profileid);
     virNWFilterHashTableFree(filterparams);

     return def;
@@ -5131,6 +5139,10 @@ virDomainNetDefFormat(virBufferPtr buf,
                               def->data.direct.linkdev);
         virBufferVSprintf(buf, " mode='%s'",
 virDomainNetdevMacvtapTypeToString(def->data.direct.mode));
+        if (def->data.direct.profileid) {
+            virBufferEscapeString(buf, " profileid='%s'",
+                                  def->data.direct.profileid);
+        }



COMMENT:

You'd need to print a switchport element first.




         virBufferAddLit(buf, "/>\n");
         break;

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b789289..37a58a9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -289,6 +289,7 @@ struct _virDomainNetDef {
         struct {
             char *linkdev;
             int mode;
+            char *profileid;
         } direct;
     } data;
     char *ifname;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 878eda3..253f935 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -703,3 +703,6 @@ virXPathLongLong;
 virXPathULongLong;
 virXPathLongHex;
 virXPathULongHex;
+
+# macvtap.h
+sendPortProfileId;


COMMENT:

There's a separate libvirt_macvtap.syms file.

Also, please prefix this function with macvtap -> macvtapSendPortProfileId 





diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 55397cd..3cb3ce9 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1469,6 +1469,18 @@ qemudPhysIfaceConnect(virConnectPtr conn,
         net->model && STREQ(net->model, "virtio"))
         vnet_hdr = 1;

+    /* Failure here is equivalent to the failure to plug in a physical
+     * network port.
+     *
+     * If this operation is non-blocking we will have a race between
+     * the VM starting and the interface coming up.
+     *
+     * If any of the subsequent operations fail, will we need to
+     * unwind the sending of the port profile id? */
+    sendPortProfileId(net->data.direct.linkdev,
+                      net->data.direct.mode,
+                      net->data.direct.profileid);
+

COMMENT:

I'd push this call into the openMacvtapTap function since it will be part 
of the setup of the Tap device, no?

   Stefan



     rc = openMacvtapTap(conn, net->ifname, net->mac, linkdev, brmode,
                         &res_ifname, vnet_hdr);
     if (rc >= 0) {
diff --git a/src/util/macvtap.c b/src/util/macvtap.c
index 999e670..585e56b 100644
--- a/src/util/macvtap.c
+++ b/src/util/macvtap.c
@@ -43,6 +43,7 @@

 # include "util.h"
 # include "memory.h"
+# include "logging.h"
 # include "macvtap.h"
 # include "conf/domain_conf.h"
 # include "virterror_internal.h"
@@ -673,6 +674,18 @@ configMacvtapTap(int tapfd, int vnet_hdr)
 }


+int
+sendPortProfileId(const char *linkdev,
+                  int mode,
+                  const char *profileid)
+{
+    VIR_DEBUG("Sending port profile id '%s' on physical device '%s' mode 
%d",
+              profileid, linkdev, mode);
+
+    return 0;
+}
+
+
 /**
  * openMacvtapTap:
  * Create an instance of a macvtap device and open its tap character
diff --git a/src/util/macvtap.h b/src/util/macvtap.h
index bd5f4d6..6cd7621 100644
--- a/src/util/macvtap.h
+++ b/src/util/macvtap.h
@@ -38,6 +38,10 @@ int openMacvtapTap(virConnectPtr conn,

 void delMacvtap(const char *ifname);

+int sendPortProfileId(const char *linkdev,
+                      int mode,
+                      const char *profileid);
+
 # endif /* WITH_MACVTAP */

 # define MACVTAP_MODE_PRIVATE_STR  "private"
diff --git a/tests/domainschemadata/portprofile.xml 
b/tests/domainschemadata/portprofile.xml
new file mode 100644
index 0000000..7152ffd
--- /dev/null
+++ b/tests/domainschemadata/portprofile.xml
@@ -0,0 +1,15 @@
+<domain type='lxc'>
+  <name>portprofile</name>
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
+  <memory>1048576</memory>
+    <os>
+        <type>exe</type>
+        <init>/sh</init>
+    </os>
+  <devices>
+    <interface type='direct'>
+      <source dev='eth0' mode='vepa'/>
+      <switchport profile='foo'/>
+    </interface>
+  </devices>
+</domain>
-- 
1.7.0.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100426/737c83a4/attachment-0001.htm>


More information about the libvir-list mailing list