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

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) ===
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 6b4533a92cfe6eacabe6a1393270b7d7949d2b2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Tue, 27 Oct 2020 18:23:03 -0400
Subject: [PATCH] lxd/storage: Lock during the whole image replace
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index b2c1272991..f3d8f83273 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1039,6 +1039,11 @@ func (b *lxdBackend) CreateInstanceFromImage(inst 
instance.Instance, fingerprint
                // by creating a new cached image volume using the pool's 
current settings (including volume.size).
                if errors.Cause(err) == drivers.ErrCannotBeShrunk {
                        logger.Debug("Cached image volume is larger than new 
volume and cannot be shrunk, regenerating image volume")
+
+                       // Lock during the entire process to avoid attempts at 
creating while the image is gone.
+                       unlock := 
locking.Lock(drivers.OperationLockName(b.name, string(drivers.VolumeTypeImage), 
fmt.Sprintf("ReplaceImage_%v", fingerprint)))
+                       defer unlock()
+
                        err = b.DeleteImage(fingerprint, op)
                        if err != nil {
                                return err
@@ -1055,7 +1060,6 @@ func (b *lxdBackend) CreateInstanceFromImage(inst 
instance.Instance, fingerprint
                        }
                } else if err != nil {
                        return err
-
                }
        }
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to