Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries when removing device mapper target #1200

Merged
merged 7 commits into from
Nov 3, 2021
Prev Previous commit
Next Next commit
pr feedback: make fixed number of retries and remove timeout
Signed-off-by: Maksim An <maksiman@microsoft.com>
  • Loading branch information
anmaxvl committed Nov 1, 2021
commit ebd6fb36304d7172779f19c168158d72a845f308
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 {
anmaxvl marked this conversation as resolved.
Show resolved Hide resolved
time.Sleep(10 * time.Millisecond)
continue
}
return nil
break
}
return
}

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