Skip to content

Commit 6ae3e5d

Browse files
committed
Fix retry logic within devmapper device deactivation
Signed-off-by: Swagat Bora <[email protected]>
1 parent 3d32da8 commit 6ae3e5d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

snapshots/devmapper/pool_device.go

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

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

98107
for attempt := 1; attempt <= maxRetries; attempt++ {
99108
retryErr = f()
100-
if retryErr == nil {
101-
return nil
102-
} else if retryErr != unix.EBUSY {
109+
110+
if skipRetry(retryErr) {
103111
return retryErr
104112
}
105113

0 commit comments

Comments
 (0)