From 42532c1c86090a33797eb4c67ce1a3e002b2090b Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 18 Apr 2021 17:58:35 +0530 Subject: [PATCH] Ignore not found error while deactivating snapshot While deleting a VM, if the associated device mapper device has been already deleted and cannot be found, the delete should continue without any error. --- pkg/dmlegacy/deactivate.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/dmlegacy/deactivate.go b/pkg/dmlegacy/deactivate.go index c3bcacfde..6e57d417d 100644 --- a/pkg/dmlegacy/deactivate.go +++ b/pkg/dmlegacy/deactivate.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/nightlyone/lockfile" @@ -11,6 +12,9 @@ import ( "github.com/weaveworks/ignite/pkg/util" ) +// dmsetupNotFound is the error message when dmsetup can't find a device. +const dmsetupNotFound = "No such device or address" + // DeactivateSnapshot deactivates the snapshot by removing it with dmsetup func DeactivateSnapshot(vm *api.VM) error { // Global lock path. @@ -42,6 +46,13 @@ func DeactivateSnapshot(vm *api.VM) error { dmArgs = append(dmArgs, baseDev) } - _, err = util.ExecuteCommand("dmsetup", dmArgs...) - return err + if _, err := util.ExecuteCommand("dmsetup", dmArgs...); err != nil { + // If the device is not found, it's been deleted already, return nil. + if strings.Contains(err.Error(), dmsetupNotFound) { + return nil + } + return err + } + + return nil }