[lxc-devel] [lxd/master] Storage pool loader instance type checks

tomponline on Github lxc-bot at linuxcontainers.org
Thu Dec 19 12:09:37 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 617 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191219/ad054f23/attachment.bin>
-------------- next part --------------
From f41d62f98599b757f2896e4588c2d49090b9f163 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 19 Dec 2019 12:06:33 +0000
Subject: [PATCH 1/4] lxd/backup: Adds check for supported instance type when
 loading storage pool

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/backup.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/backup.go b/lxd/backup.go
index b784e9129e..64c5e5b022 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -121,7 +121,7 @@ func backupCreateTarball(s *state.State, path string, b backup.Backup, c instanc
 	}
 
 	pool, err := storagePools.GetPoolByInstance(s, c)
-	if err != storageDrivers.ErrUnknownDriver && err != db.ErrNoSuchObject {
+	if err != storageDrivers.ErrUnknownDriver && err != storageDrivers.ErrNotImplemented && err != db.ErrNoSuchObject {
 		if err != nil {
 			return err
 		}

From 3ab1ab5c7acedcf3dbb9f96b5661b51db33b0c73 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 19 Dec 2019 12:07:06 +0000
Subject: [PATCH 2/4] lxd/container: Adds check for supported instance type
 when restoring backup

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/container.go | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lxd/container.go b/lxd/container.go
index cd3789c63f..8aed96c556 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -216,7 +216,25 @@ func instanceCreateFromBackup(s *state.State, info backup.Info, srcData io.ReadS
 
 	// Check if we can load new storage layer for pool driver type.
 	pool, err := storagePools.GetPoolByName(s, info.Pool)
-	if err != storageDrivers.ErrUnknownDriver {
+
+	supportedInstanceType := false
+	if pool != nil {
+		// No concept of instance type in backups yet, so default to container type.
+		volType, err := storagePools.InstanceTypeToVolumeType(instancetype.Container)
+		if err != nil {
+			return nil, nil, err
+		}
+
+		// We don't have an instance yet so cannot use GetPoolByInstance, so interrogate the driver
+		// directly for instance type support.
+		for _, supportedType := range pool.Driver().Info().VolumeTypes {
+			if supportedType == volType {
+				supportedInstanceType = true
+			}
+		}
+	}
+
+	if err != storageDrivers.ErrUnknownDriver && supportedInstanceType {
 		if err != nil {
 			return nil, nil, err
 		}

From 61a5f411466a8b3240feb70a90a9bfdbed572bb6 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 19 Dec 2019 12:07:32 +0000
Subject: [PATCH 3/4] lxd/container/lxc: Adds check for supported instance type
 when loading storage pool

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/container_lxc.go | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 854e504f2d..231501ddb6 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -240,8 +240,8 @@ func containerLXCCreate(s *state.State, args db.InstanceArgs) (instance.Instance
 
 	// Initialize the container storage
 	// Check if we can load new storage layer for pool driver type.
-	pool, err := storagePools.GetPoolByName(c.state, storagePool)
-	if err != storageDrivers.ErrUnknownDriver {
+	pool, err := storagePools.GetPoolByInstance(c.state, c)
+	if err != storageDrivers.ErrUnknownDriver && err != storageDrivers.ErrNotImplemented {
 		if err != nil {
 			return nil, err
 		}
@@ -3426,7 +3426,7 @@ func (c *containerLXC) Delete() error {
 
 	// Check if we can load new storage layer for pool driver type.
 	pool, err := storagePools.GetPoolByInstance(c.state, c)
-	if err != storageDrivers.ErrUnknownDriver && err != db.ErrNoSuchObject {
+	if err != storageDrivers.ErrUnknownDriver && err != storageDrivers.ErrNotImplemented && err != db.ErrNoSuchObject {
 		if err != nil {
 			return err
 		}
@@ -3474,7 +3474,7 @@ func (c *containerLXC) Delete() error {
 				}
 			}
 		}
-	} else if err == storageDrivers.ErrUnknownDriver {
+	} else if err != db.ErrNoSuchObject {
 		// Attempt to initialize storage interface for the container.
 		err := c.initStorage()
 		if err != nil {
@@ -5802,8 +5802,8 @@ func (c *containerLXC) diskState() map[string]api.InstanceStateDisk {
 		var usage int64
 
 		// Check if we can load new storage layer for pool driver type.
-		pool, err := storagePools.GetPoolByName(c.state, dev.Config["pool"])
-		if err != storageDrivers.ErrUnknownDriver {
+		pool, err := storagePools.GetPoolByInstance(c.state, c)
+		if err != storageDrivers.ErrUnknownDriver && err != storageDrivers.ErrNotImplemented {
 			if err != nil {
 				logger.Error("Error loading storage pool", log.Ctx{"project": c.Project(), "instance": c.Name(), "err": err})
 				continue

From a86d7e0e283c73d83bbfb7aedcb5a62349672b8f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 19 Dec 2019 12:07:52 +0000
Subject: [PATCH 4/4] lxd/migrate/container: Adds check for supported instance
 type when loading storage pool

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/migrate_container.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/migrate_container.go b/lxd/migrate_container.go
index 208041a654..3dfd73f50f 100644
--- a/lxd/migrate_container.go
+++ b/lxd/migrate_container.go
@@ -345,7 +345,7 @@ func (s *migrationSourceWs) Do(state *state.State, migrateOp *operations.Operati
 
 	// Check if we can load new storage layer for pool driver type.
 	pool, err := storagePools.GetPoolByInstance(state, s.instance)
-	if err != storageDrivers.ErrUnknownDriver && err != db.ErrNoSuchObject {
+	if err != storageDrivers.ErrUnknownDriver && err != storageDrivers.ErrNotImplemented && err != db.ErrNoSuchObject {
 		if err != nil {
 			return err
 		}


More information about the lxc-devel mailing list