mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	Cleaning up loopback removal process
This commit is contained in:
		@@ -361,9 +361,10 @@ func (util *FCUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri
 | 
			
		||||
	}
 | 
			
		||||
	loop, err := volumeutil.BlockVolumePathHandler.GetLoopDevice(blkUtil, dstPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		glog.Warningf("fc: failed to get loopback for device: %v, err: %v", dstPath, err)
 | 
			
		||||
	} else {
 | 
			
		||||
		glog.V(4).Infof("fc: found loopback: %v", loop)
 | 
			
		||||
		if err.Error() != volumeutil.ErrDeviceNotFound {
 | 
			
		||||
			return fmt.Errorf("fc: failed to get loopback for destination path: %v, err: %v", dstPath, err)
 | 
			
		||||
		}
 | 
			
		||||
		glog.Warning("fc: loopback for destination path: %s not found", dstPath)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Detach volume from kubelet node
 | 
			
		||||
@@ -386,12 +387,13 @@ func (util *FCUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri
 | 
			
		||||
		glog.Errorf("fc: last error occurred during detach disk:\n%v", lastErr)
 | 
			
		||||
		return lastErr
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(loop) != 0 {
 | 
			
		||||
		// The volume was successfully detached from node. We can safely remove the loopback.
 | 
			
		||||
		err = volumeutil.BlockVolumePathHandler.RemoveLoopDevice(blkUtil, loop)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("fc: failed to remove loopback :%v, err: %v", loop, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -521,18 +521,23 @@ func (util *ISCSIUtil) DetachBlockISCSIDisk(c iscsiDiskUnmapper, mapPath string)
 | 
			
		||||
	blkUtil := volumeutil.NewBlockVolumePathHandler()
 | 
			
		||||
	loop, err := volumeutil.BlockVolumePathHandler.GetLoopDevice(blkUtil, devicePath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if err.Error() != volumeutil.ErrDeviceNotFound {
 | 
			
		||||
			return fmt.Errorf("failed to get loopback for device: %v, err: %v", devicePath, err)
 | 
			
		||||
		}
 | 
			
		||||
		glog.Warning("iscsi: loopback for device: %s not found", device)
 | 
			
		||||
	}
 | 
			
		||||
	// Detach a volume from kubelet node
 | 
			
		||||
	err = util.detachISCSIDisk(c.exec, portals, iqn, iface, volName, initiatorName, found)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("failed to finish detachISCSIDisk, err: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	if len(loop) != 0 {
 | 
			
		||||
		// The volume was successfully detached from node. We can safely remove the loopback.
 | 
			
		||||
		err = volumeutil.BlockVolumePathHandler.RemoveLoopDevice(blkUtil, loop)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("failed to remove loopback :%v, err: %v", loop, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,6 @@ const (
 | 
			
		||||
 | 
			
		||||
	ErrDeviceNotFound     = "device not found"
 | 
			
		||||
	ErrDeviceNotSupported = "device not supported"
 | 
			
		||||
	ErrNotAvailable       = "not available"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// IsReady checks for the existence of a regular file
 | 
			
		||||
 
 | 
			
		||||
@@ -51,7 +51,7 @@ func (v VolumePathHandler) AttachFileDevice(path string) (string, error) {
 | 
			
		||||
func (v VolumePathHandler) GetLoopDevice(path string) (string, error) {
 | 
			
		||||
	_, err := os.Stat(path)
 | 
			
		||||
	if os.IsNotExist(err) {
 | 
			
		||||
		return "", errors.New(ErrNotAvailable)
 | 
			
		||||
		return "", errors.New(ErrDeviceNotFound)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", fmt.Errorf("not attachable: %v", err)
 | 
			
		||||
@@ -84,9 +84,11 @@ func (v VolumePathHandler) RemoveLoopDevice(device string) error {
 | 
			
		||||
	cmd := exec.Command(losetupPath, args...)
 | 
			
		||||
	out, err := cmd.CombinedOutput()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if !strings.Contains(string(out), "No such device or address") {
 | 
			
		||||
			return err
 | 
			
		||||
		if _, err := os.Stat(device); os.IsNotExist(err) {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		glog.V(2).Infof("Failed to remove loopback device: %s: %v %s", device, err, out)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user