[lxc-devel] [lxd/master] lxd/storage: Check base image is available locally

stgraber on Github lxc-bot at linuxcontainers.org
Fri Oct 9 20:55:26 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 471 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201009/b6e19ec4/attachment.bin>
-------------- next part --------------
From e035cf76c534740d806556dbb7df0b6532a14274 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 9 Oct 2020 16:51:10 -0400
Subject: [PATCH] lxd/storage: Check base image is available locally
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This uses a bit of a shortcut by checking the filesystem for it instead
of hitting the database.

Closes #8015

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage/backend_lxd.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 379c644874..20ddfc145c 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1125,12 +1125,17 @@ func (b *lxdBackend) CreateInstanceFromMigration(inst instance.Instance, conn io
 		// transfer the base image files too.
 		if args.MigrationType.FSType == migration.MigrationFSType_RSYNC {
 			fingerprint := inst.ExpandedConfig()["volatile.base_image"]
+
+			// Confirm that the image is present in the project.
 			_, _, err = b.state.Cluster.GetImage(inst.Project(), fingerprint, false)
 			if err != db.ErrNoSuchObject && err != nil {
 				return err
 			}
 
-			if err == nil {
+			// Then make sure that the image is available locally too (not guaranteed in clusters).
+			local := shared.PathExists(shared.VarPath("images", fingerprint))
+
+			if err == nil && local {
 				logger.Debug("Using optimised migration from existing image", log.Ctx{"fingerprint": fingerprint})
 
 				// Populate the volume filler with the fingerprint and image filler


More information about the lxc-devel mailing list