Skip to content

Commit d528415

Browse files
committed
Fix retry logic within devmapper device deactivation
Signed-off-by: Swagat Bora <[email protected]> (cherry picked from commit 6ae3e5d) Signed-off-by: Swagat Bora <[email protected]>
1 parent c553746 commit d528415

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

snapshots/devmapper/pool_device.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) {
8989
return poolDevice, nil
9090
}
9191

92+
func skipRetry(err error) bool {
93+
if err == nil {
94+
return true // skip retry if no error
95+
} else if !errors.Is(err, unix.EBUSY) {
96+
return true // skip retry if error is not due to device or resource busy
97+
}
98+
return false
99+
}
100+
92101
func retry(ctx context.Context, f func() error) error {
93102
var (
94103
maxRetries = 100
@@ -98,9 +107,8 @@ func retry(ctx context.Context, f func() error) error {
98107

99108
for attempt := 1; attempt <= maxRetries; attempt++ {
100109
retryErr = f()
101-
if retryErr == nil {
102-
return nil
103-
} else if retryErr != unix.EBUSY {
110+
111+
if skipRetry(retryErr) {
104112
return retryErr
105113
}
106114

0 commit comments

Comments
 (0)