From fd20c8b02075d557feaeda251428a5c5f9155e09 Mon Sep 17 00:00:00 2001 From: wenlxie Date: Sun, 4 Mar 2018 22:51:28 +0800 Subject: [PATCH] ignore the loopbackdevice error, or the rbd volume will not get detached --- pkg/volume/rbd/rbd.go | 20 ++++++++++++------- .../operationexecutor/operation_generator.go | 15 ++++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pkg/volume/rbd/rbd.go b/pkg/volume/rbd/rbd.go index ffc5c03c10..7051d2062b 100644 --- a/pkg/volume/rbd/rbd.go +++ b/pkg/volume/rbd/rbd.go @@ -940,14 +940,20 @@ func (rbd *rbdDiskUnmapper) TearDownDevice(mapPath, _ string) error { blkUtil := volumepathhandler.NewBlockVolumePathHandler() loop, err := volumepathhandler.BlockVolumePathHandler.GetLoopDevice(blkUtil, device) if err != nil { - return fmt.Errorf("rbd: failed to get loopback for device: %v, err: %v", device, err) + if err.Error() != volumepathhandler.ErrDeviceNotFound { + return fmt.Errorf("rbd: failed to get loopback for device: %v, err: %v", device, err) + } + glog.Warning("rbd: loopback for device: % not found", device) + } else { + if len(loop) != 0 { + // Remove loop device before detaching volume since volume detach operation gets busy if volume is opened by loopback. + err = volumepathhandler.BlockVolumePathHandler.RemoveLoopDevice(blkUtil, loop) + if err != nil { + return fmt.Errorf("rbd: failed to remove loopback :%v, err: %v", loop, err) + } + glog.V(4).Infof("rbd: successfully removed loop device: %s", loop) + } } - // Remove loop device before detaching volume since volume detach operation gets busy if volume is opened by loopback. - err = volumepathhandler.BlockVolumePathHandler.RemoveLoopDevice(blkUtil, loop) - if err != nil { - return fmt.Errorf("rbd: failed to remove loopback :%v, err: %v", loop, err) - } - glog.V(4).Infof("rbd: successfully removed loop device: %s", loop) err = rbd.manager.DetachBlockDisk(*rbd, mapPath) if err != nil { diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 21e4bbd04b..1b49ad342b 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -1058,11 +1058,18 @@ func (og *operationGenerator) GenerateUnmapDeviceFunc( glog.V(4).Infof("UnmapDevice: deviceToDetach.DevicePath: %v", deviceToDetach.DevicePath) loopPath, err := og.blkUtil.GetLoopDevice(deviceToDetach.DevicePath) if err != nil { - glog.Warningf(deviceToDetach.GenerateMsgDetailed("UnmapDevice: Couldn't find loopback device which takes file descriptor lock", fmt.Sprintf("device path: %q", deviceToDetach.DevicePath))) + if err.Error() == volumepathhandler.ErrDeviceNotFound { + glog.Warningf(deviceToDetach.GenerateMsgDetailed("UnmapDevice: Couldn't find loopback device which takes file descriptor lock", fmt.Sprintf("device path: %q", deviceToDetach.DevicePath))) + } else { + errInfo := "UnmapDevice.GetLoopDevice failed to get loopback device, " + fmt.Sprintf("device path: %q", deviceToDetach.DevicePath) + return deviceToDetach.GenerateError(errInfo, err) + } } else { - err = og.blkUtil.RemoveLoopDevice(loopPath) - if err != nil { - return deviceToDetach.GenerateError("UnmapDevice.AttachFileDevice failed", err) + if len(loopPath) != 0 { + err = og.blkUtil.RemoveLoopDevice(loopPath) + if err != nil { + return deviceToDetach.GenerateError("UnmapDevice.RemoveLoopDevice failed", err) + } } }