Skip to content

Commit

Permalink
pr feedback: make fixed number of retries and remove timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim An <maksiman@microsoft.com>
  • Loading branch information
anmaxvl committed Oct 22, 2021
1 parent fe14a75 commit c3b802a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions internal/guest/storage/devicemapper/devicemapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func CreateDevice(name string, flags CreateFlags, targets []Target) (_ string, e
}

// RemoveDevice removes a device-mapper device and its associated device node.
func RemoveDevice(name string) error {
func RemoveDevice(name string) (err error) {
rm := func() error {
f, err := openMapper()
if err != nil {
Expand All @@ -283,18 +283,14 @@ func RemoveDevice(name string) error {

// This is workaround for "device or resource busy" error, which occasionally happens after the device mapper
// target has been unmounted.
for {
if err := rm(); err != nil {
select {
case <-time.After(time.Second):
return fmt.Errorf("timeout removing device %s", name)
default:
time.Sleep(10 * time.Millisecond)
continue
}
for i := 0; i < 10; i++ {
if err = rm(); err != nil {
time.Sleep(10 * time.Millisecond)
continue
}
return nil
break
}
return
}

func removeDevice(f *os.File, name string) error {
Expand Down

0 comments on commit c3b802a

Please sign in to comment.