[PATCH 06/16] LXC from native: convert phys network types to net hostdev devices

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

 



---
 src/lxc/lxc_native.c                               | 43 +++++++++++++++++++---
 .../lxcconf2xmldata/lxcconf2xml-physnetwork.config |  8 ++++
 tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml  | 35 ++++++++++++++++++
 tests/lxcconf2xmltest.c                            |  1 +
 4 files changed, 82 insertions(+), 5 deletions(-)
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index a9ef453..3667d04 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -558,6 +558,26 @@ error:
     return NULL;
 }
 
+static virDomainHostdevDefPtr
+lxcCreateHostdevDef(int mode, int type, const char *data)
+{
+    virDomainHostdevDefPtr hostdev = virDomainHostdevDefAlloc();
+
+    if (!hostdev)
+        return NULL;
+
+    hostdev->mode = mode;
+    hostdev->source.caps.type = type;
+
+    if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET &&
+        VIR_STRDUP(hostdev->source.caps.u.net.iface, data) < 0) {
+        virDomainHostdevDefFree(hostdev);
+        hostdev = NULL;
+    }
+
+    return hostdev;
+}
+
 static int
 lxcAddNetworkDefinition(virDomainDefPtr def,
                         const char *type,
@@ -566,21 +586,34 @@ lxcAddNetworkDefinition(virDomainDefPtr def,
                         const char *flag)
 {
     virDomainNetDefPtr net = NULL;
+    virDomainHostdevDefPtr hostdev = NULL;
 
     if ((type == NULL) || STREQ(type, "empty") || STREQ(type, ""))
         return 0;
 
-    if (!(net = lxcCreateNetDef(type, link, mac, flag)))
-        goto error;
+    if (type != NULL && STREQ(type, "phys")) {
+        if (!(hostdev = lxcCreateHostdevDef(VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES,
+                                            VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET,
+                                            link)))
+            goto error;
 
-    if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
-        goto error;
-    def->nets[def->nnets - 1] = net;
+        if (VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1) < 0)
+            goto error;
+        def->hostdevs[def->nhostdevs - 1] = hostdev;
+    } else {
+        if (!(net = lxcCreateNetDef(type, link, mac, flag)))
+            goto error;
+
+        if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
+            goto error;
+        def->nets[def->nnets - 1] = net;
+    }
 
     return 1;
 
 error:
     virDomainNetDefFree(net);
+    virDomainHostdevDefFree(hostdev);
     return -1;
 }
 
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config
new file mode 100644
index 0000000..5f113e4
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.config
@@ -0,0 +1,8 @@
+lxc.network.type = phys
+lxc.network.link = eth0
+
+lxc.mount.entry = /etc/resolv.conf etc/resolv.conf none bind,ro 0 0
+lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
+lxc.utsname = migrate_test
+lxc.autodev=1
+lxc.mount = /var/lib/lxc/migrate_test/fstab
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
new file mode 100644
index 0000000..98edfef
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
@@ -0,0 +1,35 @@
+<domain type='lxc'>
+  <name>migrate_test</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>4035770</memory>
+  <currentMemory unit='KiB'>0</currentMemory>
+  <vcpu placement='static' current='0'>1</vcpu>
+  <os>
+    <type>exe</type>
+    <init>/sbin/init</init>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/var/lib/lxc/migrate_test/rootfs'/>
+      <target dir='/'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/etc/resolv.conf'/>
+      <target dir='/etc/resolv.conf'/>
+      <readonly/>
+    </filesystem>
+    <filesystem type='ram' accessmode='passthrough'>
+      <source usage='2017885' units='KiB'/>
+      <target dir='/run'/>
+    </filesystem>
+    <hostdev mode='capabilities' type='net'>
+      <source>
+        <interface>eth0</interface>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c
index 34ddb67..fe2e3bc 100644
--- a/tests/lxcconf2xmltest.c
+++ b/tests/lxcconf2xmltest.c
@@ -108,6 +108,7 @@ mymain(void)
 
     DO_TEST("simple");
     DO_TEST("nonetwork");
+    DO_TEST("physnetwork");
 
     return ret;
 }
-- 
1.8.5.2

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