[lxc-devel] [lxd/master] lxd: Cleanup storage volumes properly for VMs

monstermunchkin on Github lxc-bot at linuxcontainers.org
Fri Nov 15 14:45:15 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 503 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191115/7ac85bf1/attachment.bin>
-------------- next part --------------
From 0007725a279c22dcadc7dcbd6698999ddf3e7d77 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 15 Nov 2019 15:44:19 +0100
Subject: [PATCH] lxd: Cleanup storage volumes properly for VMs

If the storage pool cannot be initialized using the new storage backend,
try removing the storage pool volume the old way.

This fixes #6461.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/vm_qemu.go | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lxd/vm_qemu.go b/lxd/vm_qemu.go
index 05601479ad..7215175cda 100644
--- a/lxd/vm_qemu.go
+++ b/lxd/vm_qemu.go
@@ -1834,7 +1834,23 @@ func (vm *vmQemu) Delete() error {
 	// Attempt to initialize storage interface for the instance.
 	pool, err := storagePools.GetPoolByInstance(vm.state, vm)
 	if err != nil {
-		logger.Error("Failed to init storage pool", log.Ctx{"project": vm.Project(), "instance": vm.Name(), "err": err})
+		logger.Warn("Failed to init storage pool", log.Ctx{"project": vm.Project(), "instance": vm.Name(), "err": err})
+
+		// Remove the volume record from the database.
+		poolName, err := vm.StoragePool()
+		if err != nil {
+			return err
+		}
+
+		poolID, err := vm.state.Cluster.StoragePoolGetID(poolName)
+		if err != nil {
+			return err
+		}
+
+		err = vm.state.Cluster.StoragePoolVolumeDelete(vm.Project(), vm.Name(), db.StoragePoolVolumeTypeVM, poolID)
+		if err != nil {
+			return err
+		}
 	}
 
 	if pool != nil {


More information about the lxc-devel mailing list