[lxc-devel] [lxd/master] Disable USB on s390x

stgraber on Github lxc-bot at linuxcontainers.org
Tue Oct 20 19:05:07 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201020/46737b62/attachment.bin>
-------------- next part --------------
From 524c519eefe8a87b6152e152f04e1755fc0d1fcf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 20 Oct 2020 14:35:03 -0400
Subject: [PATCH 1/3] lxd/seccomp: Fix go vet
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/seccomp/seccomp.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/seccomp/seccomp.go b/lxd/seccomp/seccomp.go
index 3959fab4b4..90be41223e 100644
--- a/lxd/seccomp/seccomp.go
+++ b/lxd/seccomp/seccomp.go
@@ -2026,7 +2026,7 @@ func (s *Server) MountSyscallShift(c Instance) bool {
 	return false
 }
 
-var pageSize int = 4096
+var pageSize = 4096
 
 func init() {
 	tmp := unix.Getpagesize()

From a4f287312fb03f3b3d58201fa9e7ec568d5e7176 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 20 Oct 2020 14:57:22 -0400
Subject: [PATCH 2/3] lxd/instance: Add Architecture to common
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/instance/drivers/driver_common.go |  6 ++++++
 lxd/instance/drivers/driver_lxc.go    | 10 ++--------
 lxd/instance/drivers/driver_qemu.go   | 10 ++--------
 lxd/instance/instance_interface.go    |  2 +-
 4 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/lxd/instance/drivers/driver_common.go b/lxd/instance/drivers/driver_common.go
index 7f3e9da6dd..05cc85be09 100644
--- a/lxd/instance/drivers/driver_common.go
+++ b/lxd/instance/drivers/driver_common.go
@@ -11,6 +11,7 @@ import (
 // common provides structure common to all instance types.
 type common struct {
 	dbType          instancetype.Type
+	architecture    int
 	devPaths        []string
 	expandedConfig  map[string]string
 	expandedDevices deviceConfig.Devices
@@ -31,6 +32,11 @@ func (c *common) Type() instancetype.Type {
 	return c.dbType
 }
 
+// Architecture returns the instance's architecture.
+func (c *common) Architecture() int {
+	return c.architecture
+}
+
 // ExpandedConfig returns instance's expanded config.
 func (c *common) ExpandedConfig() map[string]string {
 	return c.expandedConfig
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 81d814e3df..c5b694e0ee 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -145,6 +145,7 @@ func lxcCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
 	c := &lxc{
 		common: common{
 			dbType:       args.Type,
+			architecture: args.Architecture,
 			localConfig:  args.Config,
 			localDevices: args.Devices,
 			project:      args.Project,
@@ -156,7 +157,6 @@ func lxcCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
 		node:         args.Node,
 		description:  args.Description,
 		ephemeral:    args.Ephemeral,
-		architecture: args.Architecture,
 		snapshot:     args.Snapshot,
 		stateful:     args.Stateful,
 		creationDate: args.CreationDate,
@@ -403,6 +403,7 @@ func lxcInstantiate(s *state.State, args db.InstanceArgs, expandedDevices device
 	c := &lxc{
 		common: common{
 			dbType:       args.Type,
+			architecture: args.Architecture,
 			localConfig:  args.Config,
 			localDevices: args.Devices,
 			project:      args.Project,
@@ -413,7 +414,6 @@ func lxcInstantiate(s *state.State, args db.InstanceArgs, expandedDevices device
 		name:         args.Name,
 		description:  args.Description,
 		ephemeral:    args.Ephemeral,
-		architecture: args.Architecture,
 		snapshot:     args.Snapshot,
 		creationDate: args.CreationDate,
 		lastUsedDate: args.LastUsedDate,
@@ -448,7 +448,6 @@ type lxc struct {
 	common
 
 	// Properties
-	architecture int
 	snapshot     bool
 	creationDate time.Time
 	lastUsedDate time.Time
@@ -6638,11 +6637,6 @@ func (c *lxc) IsSnapshot() bool {
 	return c.snapshot
 }
 
-// Architecture returns architecture of instance.
-func (c *lxc) Architecture() int {
-	return c.architecture
-}
-
 // CreationDate returns creation date of instance.
 func (c *lxc) CreationDate() time.Time {
 	return c.creationDate
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 733a868605..9f433b2112 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -103,6 +103,7 @@ func qemuInstantiate(s *state.State, args db.InstanceArgs, expandedDevices devic
 	vm := &qemu{
 		common: common{
 			dbType:       args.Type,
+			architecture: args.Architecture,
 			localConfig:  args.Config,
 			localDevices: args.Devices,
 			project:      args.Project,
@@ -113,7 +114,6 @@ func qemuInstantiate(s *state.State, args db.InstanceArgs, expandedDevices devic
 		name:         args.Name,
 		description:  args.Description,
 		ephemeral:    args.Ephemeral,
-		architecture: args.Architecture,
 		snapshot:     args.Snapshot,
 		creationDate: args.CreationDate,
 		lastUsedDate: args.LastUsedDate,
@@ -155,6 +155,7 @@ func qemuCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
 	vm := &qemu{
 		common: common{
 			dbType:       args.Type,
+			architecture: args.Architecture,
 			localConfig:  args.Config,
 			localDevices: args.Devices,
 			state:        s,
@@ -166,7 +167,6 @@ func qemuCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
 		node:         args.Node,
 		description:  args.Description,
 		ephemeral:    args.Ephemeral,
-		architecture: args.Architecture,
 		snapshot:     args.Snapshot,
 		stateful:     args.Stateful,
 		creationDate: args.CreationDate,
@@ -312,7 +312,6 @@ type qemu struct {
 	common
 
 	// Properties.
-	architecture int
 	snapshot     bool
 	creationDate time.Time
 	lastUsedDate time.Time
@@ -4367,11 +4366,6 @@ func (vm *qemu) Description() string {
 	return vm.description
 }
 
-// Architecture returns the instance's architecture.
-func (vm *qemu) Architecture() int {
-	return vm.architecture
-}
-
 // CreationDate returns the instance's creation date.
 func (vm *qemu) CreationDate() time.Time {
 	return vm.creationDate
diff --git a/lxd/instance/instance_interface.go b/lxd/instance/instance_interface.go
index e49458bd86..a19cdccba8 100644
--- a/lxd/instance/instance_interface.go
+++ b/lxd/instance/instance_interface.go
@@ -35,6 +35,7 @@ const (
 type ConfigReader interface {
 	Project() string
 	Type() instancetype.Type
+	Architecture() int
 	ExpandedConfig() map[string]string
 	ExpandedDevices() deviceConfig.Devices
 	LocalConfig() map[string]string
@@ -105,7 +106,6 @@ type Instance interface {
 	Location() string
 	Name() string
 	Description() string
-	Architecture() int
 	CreationDate() time.Time
 	LastUsedDate() time.Time
 

From fce5ee2821b109a013c91fe8b2a64c6b89c92d72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 20 Oct 2020 14:57:50 -0400
Subject: [PATCH 3/3] lxd/devices: Disable USB on s390x
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/device/usb.go                   |  5 +++++
 lxd/instance/drivers/driver_qemu.go | 21 ++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/lxd/device/usb.go b/lxd/device/usb.go
index 4c6efea101..e668acf278 100644
--- a/lxd/device/usb.go
+++ b/lxd/device/usb.go
@@ -11,6 +11,7 @@ import (
 	"github.com/lxc/lxd/lxd/instance"
 	"github.com/lxc/lxd/lxd/instance/instancetype"
 	"github.com/lxc/lxd/shared"
+	"github.com/lxc/lxd/shared/osarch"
 	"github.com/lxc/lxd/shared/validate"
 )
 
@@ -49,6 +50,10 @@ func (d *usb) validateConfig(instConf instance.ConfigReader) error {
 		return ErrUnsupportedDevType
 	}
 
+	if instConf.Architecture() == osarch.ARCH_64BIT_S390_BIG_ENDIAN {
+		return fmt.Errorf("USB devices aren't supported on s390x")
+	}
+
 	rules := map[string]func(string) error{
 		"vendorid":  validate.Optional(validate.IsDeviceID),
 		"productid": validate.Optional(validate.IsDeviceID),
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 9f433b2112..b1932e5fad 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -1755,15 +1755,18 @@ func (vm *qemu) generateQemuConfigFile(busName string, devConfs []*deviceConfig.
 		return "", err
 	}
 
-	devBus, devAddr, multi = bus.allocate(busFunctionGroupGeneric)
-	err = qemuUSB.Execute(sb, map[string]interface{}{
-		"bus":           bus.name,
-		"devBus":        devBus,
-		"devAddr":       devAddr,
-		"multifunction": multi,
-	})
-	if err != nil {
-		return "", err
+	// s390x doesn't really have USB.
+	if vm.architecture != osarch.ARCH_64BIT_S390_BIG_ENDIAN {
+		devBus, devAddr, multi = bus.allocate(busFunctionGroupGeneric)
+		err = qemuUSB.Execute(sb, map[string]interface{}{
+			"bus":           bus.name,
+			"devBus":        devBus,
+			"devAddr":       devAddr,
+			"multifunction": multi,
+		})
+		if err != nil {
+			return "", err
+		}
 	}
 
 	devBus, devAddr, multi = bus.allocate(busFunctionGroupNone)


More information about the lxc-devel mailing list