[libvirt] [PATCH v2 2/2] Implement support for <hostdev caps=net>

Daniel P. Berrange berrange at redhat.com
Mon Apr 8 16:42:49 UTC 2013


On Fri, Apr 05, 2013 at 08:26:40AM -0400, Bogdan Purcareata wrote:
> This allows a container-type domain to have exclusive access to one of
> the host's NICs.
> 
> Wire <hostdev caps=net> with the lxc_controller - when moving the newly
> created veth devices into a new namespace, also look for any hostdev
> devices that should be moved. Note: once the container domain has been
> destroyed, there is no code that moves the interfaces back to the
> original namespace. This does happen, though, probably due to default
> cleanup on namespace destruction.
> 
> Signed-off-by: Bogdan Purcareata <bogdan.purcareata at freescale.com>
> ---
>  src/lxc/lxc_container.c  |  4 +++-
>  src/lxc/lxc_controller.c | 16 ++++++++++++++++
>  src/lxc/lxc_hostdev.c    |  1 +
>  3 files changed, 20 insertions(+), 1 deletion(-)

ACK, but I added this in before pushing to GIT so that we force
private net namespace on startup of container & also validate
the parser

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 002ba9e..a494363 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -2286,6 +2286,22 @@ virArch lxcContainerGetAlt32bitArch(virArch arch)
 }
 
 
+static bool
+lxcNeedNetworkNamespace(virDomainDefPtr def)
+{
+    size_t i;
+    if (def->nets != NULL)
+        return true;
+    if (def->features & (1 << VIR_DOMAIN_FEATURE_PRIVNET))
+        return true;
+    for (i = 0 ; i < def->nhostdevs ; i++) {
+        if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES &&
+            def->hostdevs[i]->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
+            return true;
+    }
+    return false;
+}
+
 /**
  * lxcContainerStart:
  * @def: pointer to virtual machine structure
@@ -2329,8 +2345,7 @@ int lxcContainerStart(virDomainDefPtr def,
         cflags |= CLONE_NEWUSER;
     }
 
-    if (def->nets != NULL ||
-        (def->features & (1 << VIR_DOMAIN_FEATURE_PRIVNET))) {
+    if (lxcNeedNetworkNamespace(def)) {
         VIR_DEBUG("Enable network namespaces");
         cflags |= CLONE_NEWNET;
     }
diff --git a/tests/lxcxml2xmldata/lxc-hostdev.xml b/tests/lxcxml2xmldata/lxc-hostdev.xml
index b022cc7..befe0db 100644
--- a/tests/lxcxml2xmldata/lxc-hostdev.xml
+++ b/tests/lxcxml2xmldata/lxc-hostdev.xml
@@ -31,5 +31,10 @@
         <char>/dev/tty0</char>
       </source>
     </hostdev>
+    <hostdev mode='capabilities' type='net'>
+      <source>
+        <interface>eth0</interface>
+      </source>
+    </hostdev>
   </devices>
 </domain>



Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list