[PATCH] OpenVZ: add ethernet interface type support

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

 



Hi all,

This patch adds support for ethernet interface type to OpenVZ domains
as stated in this previous message: http://www.redhat.com/archives/libvir-
list/2010-July/msg00658.html

Regards,

Jean-Baptiste
From 140ecba1ee0ed19df8eba5538c0cd7f1fd167ac2 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Rouault <jean-baptiste.rouault@xxxxxxxxxxx>
Date: Wed, 18 Aug 2010 16:59:59 +0200
Subject: [PATCH] OpenVZ: add ethernet interface type support

---
 src/openvz/openvz_driver.c |   47 +++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index d2f91c6..a8dacec 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -741,53 +741,56 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
     virCapabilitiesGenerateMac(driver->caps, host_mac);
     virFormatMacAddr(host_mac, host_macaddr);
 
-    if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
+    if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+        (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
+         net->data.ethernet.ipaddr == NULL)) {
         virBuffer buf = VIR_BUFFER_INITIALIZER;
-        char *dev_name_ve;
         int veid = openvzGetVEID(vpsid);
 
         //--netif_add ifname[,mac,host_ifname,host_mac]
         ADD_ARG_LIT("--netif_add") ;
 
-        /* generate interface name in ve and copy it to options */
-        dev_name_ve = openvzGenerateContainerVethName(veid);
-        if (dev_name_ve == NULL) {
-           openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Could not generate eth name for container"));
-           rc = -1;
-           goto exit;
+        /* if user doesn't specify guest interface name,
+         * then we need to generate it */
+        if (net->data.ethernet.dev == NULL) {
+            net->data.ethernet.dev = openvzGenerateContainerVethName(veid);
+            if (net->data.ethernet.dev == NULL) {
+               openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Could not generate eth name for container"));
+               rc = -1;
+               goto exit;
+            }
         }
 
         /* if user doesn't specified host interface name,
          * than we need to generate it */
         if (net->ifname == NULL) {
-            net->ifname = openvzGenerateVethName(veid, dev_name_ve);
+            net->ifname = openvzGenerateVethName(veid, net->data.ethernet.dev);
             if (net->ifname == NULL) {
                openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Could not generate veth name"));
                rc = -1;
-               VIR_FREE(dev_name_ve);
                goto exit;
             }
         }
 
-        virBufferAdd(&buf, dev_name_ve, -1); /* Guest dev */
+        virBufferAdd(&buf, net->data.ethernet.dev, -1); /* Guest dev */
         virBufferVSprintf(&buf, ",%s", macaddr); /* Guest dev mac */
         virBufferVSprintf(&buf, ",%s", net->ifname); /* Host dev */
         virBufferVSprintf(&buf, ",%s", host_macaddr); /* Host dev mac */
 
-        if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {
-            virBufferVSprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */
-        } else {
-            virBufferVSprintf(configBuf, "ifname=%s", dev_name_ve);
-            virBufferVSprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */
-            virBufferVSprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */
-            virBufferVSprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */
-            virBufferVSprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */
+        if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
+            if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {
+                virBufferVSprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */
+            } else {
+                virBufferVSprintf(configBuf, "ifname=%s", net->data.ethernet.dev);
+                virBufferVSprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */
+                virBufferVSprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */
+                virBufferVSprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */
+                virBufferVSprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */
+            }
         }
 
-        VIR_FREE(dev_name_ve);
-
         if (!(opt = virBufferContentAndReset(&buf)))
             goto no_memory;
 
-- 
1.7.0.4

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