Skip to content

Commit 0d16d04

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 9e9f4c8 commit 0d16d04

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
@@ -76,6 +76,15 @@ func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) {
7676
return poolDevice, nil
7777
}
7878

79+
func skipRetry(err error) bool {
80+
if err == nil {
81+
return true // skip retry if no error
82+
} else if !errors.Is(err, unix.EBUSY) {
83+
return true // skip retry if error is not due to device or resource busy
84+
}
85+
return false
86+
}
87+
7988
func retry(ctx context.Context, f func() error) error {
8089
var (
8190
maxRetries = 100
@@ -85,9 +94,8 @@ func retry(ctx context.Context, f func() error) error {
8594

8695
for attempt := 1; attempt <= maxRetries; attempt++ {
8796
retryErr = f()
88-
if retryErr == nil {
89-
return nil
90-
} else if retryErr != unix.EBUSY {
97+
98+
if skipRetry(retryErr) {
9199
return retryErr
92100
}
93101

0 commit comments

Comments
 (0)