The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6736

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===

From 0b7c5b22b6c76b7e02a29b284c2f05ce263b977a Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 20 Jan 2020 11:56:26 +0000
Subject: [PATCH 1/2] lxd/device/device/utils/network: Adds host MTU support
 for VM tap devices

Also improves revert logic.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/device/device_utils_network.go | 38 ++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/lxd/device/device_utils_network.go 
b/lxd/device/device_utils_network.go
index 02016faa24..29982b6b0c 100644
--- a/lxd/device/device_utils_network.go
+++ b/lxd/device/device_utils_network.go
@@ -13,8 +13,11 @@ import (
        "strings"
        "sync"
 
+       "github.com/pkg/errors"
+
        deviceConfig "github.com/lxc/lxd/lxd/device/config"
        "github.com/lxc/lxd/lxd/instance"
+       "github.com/lxc/lxd/lxd/revert"
        "github.com/lxc/lxd/lxd/state"
        "github.com/lxc/lxd/lxd/util"
        "github.com/lxc/lxd/shared"
@@ -367,18 +370,45 @@ func networkCreateVethPair(hostName string, m 
deviceConfig.Device) (string, erro
 }
 
 // networkCreateTap creates and configures a TAP device.
-func networkCreateTap(hostName string) error {
+func networkCreateTap(hostName string, m deviceConfig.Device) error {
        _, err := shared.RunCommand("ip", "tuntap", "add", "name", hostName, 
"mode", "tap")
        if err != nil {
-               return fmt.Errorf("Failed to create the tap interfaces %s: %v", 
hostName, err)
+               return errors.Wrapf(err, "Failed to create the tap interfaces 
%s", hostName)
        }
 
+       revert := revert.New()
+       defer revert.Fail()
+
        _, err = shared.RunCommand("ip", "link", "set", "dev", hostName, "up")
        if err != nil {
-               NetworkRemoveInterface(hostName)
-               return fmt.Errorf("Failed to bring up the tap interface %s: 
%v", hostName, err)
+               return errors.Wrapf(err, "Failed to bring up the tap interface 
%s", hostName)
+       }
+       revert.Add(func() { NetworkRemoveInterface(hostName) })
+
+       // Set the MTU on peer. If not specified and has parent, will inherit 
MTU from parent.
+       if m["mtu"] != "" {
+               MTU, err := strconv.ParseUint(m["mtu"], 10, 32)
+               if err != nil {
+                       return errors.Wrapf(err, "Invalid MTU specified", err)
+               }
+
+               err = NetworkSetDevMTU(hostName, MTU)
+               if err != nil {
+                       return errors.Wrapf(err, "Failed to set the MTU")
+               }
+       } else if m["parent"] != "" {
+               parentMTU, err := NetworkGetDevMTU(m["parent"])
+               if err != nil {
+                       return errors.Wrapf(err, "Failed to get the parent MTU")
+               }
+
+               err = NetworkSetDevMTU(hostName, parentMTU)
+               if err != nil {
+                       return errors.Wrapf(err, "Failed to set the MTU")
+               }
        }
 
+       revert.Success()
        return nil
 }
 

From a65c53d2522f48146e159e7061610372f669416b Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 20 Jan 2020 11:57:15 +0000
Subject: [PATCH 2/2] lxd/device/nic/bridged: Makes VM host side TAP interface
 name prefixed with "tap"

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/device/nic_bridged.go | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lxd/device/nic_bridged.go b/lxd/device/nic_bridged.go
index d34d7d6aeb..0428adbbd4 100644
--- a/lxd/device/nic_bridged.go
+++ b/lxd/device/nic_bridged.go
@@ -119,18 +119,21 @@ func (d *nicBridged) Start() (*deviceConfig.RunConfig, 
error) {
 
        saveData := make(map[string]string)
        saveData["host_name"] = d.config["host_name"]
-       if saveData["host_name"] == "" {
-               saveData["host_name"] = NetworkRandomDevName("veth")
-       }
 
-       var peerName string // Only used with containers, empty for VMs.
+       var peerName string
 
        // Create veth pair and configure the peer end with custom hwaddr and 
mtu if supplied.
        if d.inst.Type() == instancetype.Container {
+               if saveData["host_name"] == "" {
+                       saveData["host_name"] = NetworkRandomDevName("veth")
+               }
                peerName, err = networkCreateVethPair(saveData["host_name"], 
d.config)
        } else if d.inst.Type() == instancetype.VM {
+               if saveData["host_name"] == "" {
+                       saveData["host_name"] = NetworkRandomDevName("tap")
+               }
                peerName = saveData["host_name"] // VMs use the host_name to 
link to the TAP FD.
-               err = networkCreateTap(saveData["host_name"])
+               err = networkCreateTap(saveData["host_name"], d.config)
        }
 
        if err != nil {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to