[lxc-devel] [lxd/master] VM: Adds VM support to P2P NIC device

tomponline on Github lxc-bot at linuxcontainers.org
Tue Jan 21 13:52:50 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 361 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200121/54e94726/attachment.bin>
-------------- next part --------------
From d45e3707d3d550b34e772a4e00af2c0f585d94a8 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 21 Jan 2020 13:51:31 +0000
Subject: [PATCH] lxd/device/nic/p2p: Adds VM support

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/device/nic_p2p.go | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/lxd/device/nic_p2p.go b/lxd/device/nic_p2p.go
index 6b2770218e..038cb420a2 100644
--- a/lxd/device/nic_p2p.go
+++ b/lxd/device/nic_p2p.go
@@ -14,7 +14,7 @@ type nicP2P struct {
 
 // validateConfig checks the supplied config for correctness.
 func (d *nicP2P) validateConfig() error {
-	if d.inst.Type() != instancetype.Container {
+	if d.inst.Type() != instancetype.Container && d.inst.Type() != instancetype.VM {
 		return ErrUnsupportedDevType
 	}
 
@@ -28,6 +28,7 @@ func (d *nicP2P) validateConfig() error {
 		"limits.max",
 		"ipv4.routes",
 		"ipv6.routes",
+		"boot.priority",
 	}
 	err := d.config.Validate(nicValidationRules([]string{}, optionalFields))
 	if err != nil {
@@ -61,12 +62,23 @@ func (d *nicP2P) 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
 
 	// Create veth pair and configure the peer end with custom hwaddr and mtu if supplied.
-	peerName, err := networkCreateVethPair(saveData["host_name"], d.config)
+	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"], d.config)
+	}
+
 	if err != nil {
 		return nil, err
 	}
@@ -92,6 +104,12 @@ func (d *nicP2P) Start() (*deviceConfig.RunConfig, error) {
 		{Key: "link", Value: peerName},
 	}
 
+	if d.inst.Type() == instancetype.VM {
+		runConf.NetworkInterface = append(runConf.NetworkInterface,
+			deviceConfig.RunConfigItem{Key: "hwaddr", Value: d.config["hwaddr"]},
+		)
+	}
+
 	return &runConf, nil
 }
 


More information about the lxc-devel mailing list