From 0d16d045dfd0d800a00dc362736b815f6cc96de8 Mon Sep 17 00:00:00 2001 From: Swagat Bora Date: Thu, 9 Feb 2023 23:40:09 +0000 Subject: [PATCH] Fix retry logic within devmapper device deactivation Signed-off-by: Swagat Bora (cherry picked from commit 6ae3e5df6a9dda573e57f06610474848431ba2cb) Signed-off-by: Swagat Bora --- snapshots/devmapper/pool_device.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/snapshots/devmapper/pool_device.go b/snapshots/devmapper/pool_device.go index 4a1e971fccd2..88ed8f74419a 100644 --- a/snapshots/devmapper/pool_device.go +++ b/snapshots/devmapper/pool_device.go @@ -76,6 +76,15 @@ func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) { return poolDevice, nil } +func skipRetry(err error) bool { + if err == nil { + return true // skip retry if no error + } else if !errors.Is(err, unix.EBUSY) { + return true // skip retry if error is not due to device or resource busy + } + return false +} + func retry(ctx context.Context, f func() error) error { var ( maxRetries = 100 @@ -85,9 +94,8 @@ func retry(ctx context.Context, f func() error) error { for attempt := 1; attempt <= maxRetries; attempt++ { retryErr = f() - if retryErr == nil { - return nil - } else if retryErr != unix.EBUSY { + + if skipRetry(retryErr) { return retryErr }