From ff0be19d9b126639c049df96cd625cac292e73e0 Mon Sep 17 00:00:00 2001 From: Jack Lin Date: Mon, 13 Mar 2023 15:00:54 +0800 Subject: [PATCH] feat (manager): add delete data source tmp file at the end of the deletion Ref: longhorn 3682 Signed-off-by: Jack Lin (cherry picked from commit 455f018e5a80943c5d93a5f216ea973740f9fcee) --- pkg/manager/service.go | 9 +++++++-- pkg/types/types.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/manager/service.go b/pkg/manager/service.go index 6f51c87f..13fb7225 100644 --- a/pkg/manager/service.go +++ b/pkg/manager/service.go @@ -152,10 +152,15 @@ func (m *Manager) Delete(ctx context.Context, req *rpc.DeleteRequest) (resp *emp log.Info("Backing Image Manager: prepare to delete backing image") defer func() { if err != nil { - log.WithError(err).Error("Backing Image Manager: failed to delete backing image, will continue to do directory cleanup anyway") + log.WithError(err).Warn("Backing Image Manager: failed to delete backing image, will continue to do directory cleanup anyway") } if rmDirErr := os.RemoveAll(types.GetBackingImageDirectory(m.diskPath, req.Name, req.Uuid)); rmDirErr != nil { - log.WithError(rmDirErr).Errorf("Backing Image Manager: failed to remove the backing image work directory at the end of the deletion") + log.WithError(rmDirErr).Warn("Backing Image Manager: failed to remove the backing image work directory at the end of the deletion") + } + // Delete cmd is used to remove the tmp file left on the host as well when preparing backing image file failed. + tmpFilePath := fmt.Sprintf("%s%s", types.GetDataSourceFilePath(m.diskPath, req.Name, req.Uuid), types.TmpFileSuffix) + if rmTmpFileErr := os.RemoveAll(tmpFilePath); rmTmpFileErr != nil { + log.WithError(rmTmpFileErr).Warn("Backing Image Manager: failed to remove the data source tmp file at the end of the deletion") } }() diff --git a/pkg/types/types.go b/pkg/types/types.go index 65e87f9f..0b636a6b 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -38,6 +38,7 @@ const ( StateStarting = State("starting") StateInProgress = State("in-progress") StateFailed = State("failed") + StateFailedAndCleanUp = State("failed-and-cleanup") StateUnknown = State("unknown") StateReady = State("ready") StateReadyForTransfer = State("ready-for-transfer")