fix: 🐛 fix force umount
fix force umount
This commit is contained in:
		
							parent
							
								
									f8aa58a3be
								
							
						
					
					
						commit
						df80de8392
					
				| @ -29,7 +29,7 @@ var ( | ||||
| 	nodeID                = flag.String("nodeid", "", "node id") | ||||
| 	mountPermissions      = flag.Uint64("mount-permissions", 0, "mounted folder permissions") | ||||
| 	driverName            = flag.String("drivername", "", "name of the driver") | ||||
| 	workingMountDir       = flag.String("working-mount-dir", "/tmp", "working directory for provisioner to mount davfs shares temporarily") | ||||
| 	workingMountDir       = flag.String("working-mount-dir", "/tmp/csi-storage", "working directory for provisioner to mount davfs shares temporarily") | ||||
| 	defaultOnDeletePolicy = flag.String("default-ondelete-policy", "", "default policy for deleting subdirectory when deleting a volume") | ||||
| ) | ||||
| 
 | ||||
|  | ||||
| @ -79,7 +79,7 @@ spec: | ||||
|           securityContext: | ||||
|             privileged: true | ||||
|             capabilities: | ||||
|               add: ["ALL"] | ||||
|               add: ["SYS_ADMIN"] | ||||
|             allowPrivilegeEscalation: true | ||||
|           args: | ||||
|             - "-v=5" | ||||
|  | ||||
| @ -96,12 +96,6 @@ func (c *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu | ||||
| 		return nil, status.Errorf(codes.Internal, fmt.Sprintf("mount failed: %v", err.Error())) | ||||
| 	} | ||||
| 
 | ||||
| 	defer func() { | ||||
| 		if err = umount(c.mounter, targetPath); err != nil { | ||||
| 			klog.Warningf("failed to unmount src webdav server after snapshot volume copy: %v", err) | ||||
| 		} | ||||
| 	}() | ||||
| 
 | ||||
| 	internalVolumePath := filepath.Join(targetPath, req.Name) | ||||
| 	if err = os.Mkdir(internalVolumePath, 0777); err != nil && !os.IsExist(err) { | ||||
| 		return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err.Error()) | ||||
| @ -114,6 +108,10 @@ func (c *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if err = c.mounter.Unmount(targetPath); err != nil { | ||||
| 		return nil, status.Errorf(codes.Internal, "failed to unmount targetpath %s %v", targetPath, err) | ||||
| 	} | ||||
| 
 | ||||
| 	return &csi.CreateVolumeResponse{ | ||||
| 		Volume: &csi.Volume{ | ||||
| 			VolumeId:      MakeVolumeId(sourcePath, req.Name), | ||||
| @ -144,18 +142,16 @@ func (c *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolu | ||||
| 		return nil, status.Errorf(codes.Internal, fmt.Sprintf("mount failed: %v", err.Error())) | ||||
| 	} | ||||
| 
 | ||||
| 	defer func() { | ||||
| 		if err = umount(c.mounter, targetPath); err != nil { | ||||
| 			klog.Warningf("failed to unmount src webdav server after snapshot volume copy: %v", err) | ||||
| 		} | ||||
| 	}() | ||||
| 
 | ||||
| 	internalVolumePath := filepath.Join(targetPath, subDir) | ||||
| 	klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath) | ||||
| 	if err = os.RemoveAll(internalVolumePath); err != nil { | ||||
| 		return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error()) | ||||
| 	} | ||||
| 
 | ||||
| 	if err = c.mounter.Unmount(targetPath); err != nil { | ||||
| 		return nil, status.Errorf(codes.Internal, "failed to unmount targetpath %s %v", targetPath, err) | ||||
| 	} | ||||
| 
 | ||||
| 	return &csi.DeleteVolumeResponse{}, nil | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -17,8 +17,6 @@ limitations under the License. | ||||
| package webdav | ||||
| 
 | ||||
| import ( | ||||
| 	"runtime" | ||||
| 
 | ||||
| 	"github.com/container-storage-interface/spec/lib/go/csi" | ||||
| 	"github.com/sys-liqian/csi-driver-webdav/pkg/webdav/mount" | ||||
| 
 | ||||
| @ -98,10 +96,6 @@ func (d *Driver) Run() { | ||||
| 	klog.V(2).Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta) | ||||
| 
 | ||||
| 	mounter := mount.New("") | ||||
| 	if runtime.GOOS == "linux" { | ||||
| 		// MounterForceUnmounter is only implemented on Linux now | ||||
| 		mounter = mounter.(mount.MounterForceUnmounter) | ||||
| 	} | ||||
| 	server := NewNonBlockingGRPCServer() | ||||
| 	server.Start(d.endpoint, | ||||
| 		NewIdentityServer(d), | ||||
|  | ||||
| @ -113,7 +113,7 @@ func (n *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpub | ||||
| 	} | ||||
| 	klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath) | ||||
| 
 | ||||
| 	err := umount(n.mounter, targetPath) | ||||
| 	err := n.mounter.Unmount(targetPath) | ||||
| 	if err != nil { | ||||
| 		return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err) | ||||
| 	} | ||||
|  | ||||
| @ -21,10 +21,8 @@ import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/container-storage-interface/spec/lib/go/csi" | ||||
| 	"github.com/sys-liqian/csi-driver-webdav/pkg/webdav/mount" | ||||
| 	"google.golang.org/grpc" | ||||
| 	"k8s.io/klog/v2" | ||||
| ) | ||||
| @ -93,15 +91,3 @@ func ParseVolumeId(volumeId string) (webdavSharePath, subDir string, err error) | ||||
| 	} | ||||
| 	return arr[0], arr[1], nil | ||||
| } | ||||
| 
 | ||||
| func umount(mounter mount.Interface, path string) (err error) { | ||||
| 	extensiveMountPointCheck := true | ||||
| 	forceUnmounter, ok := mounter.(mount.MounterForceUnmounter) | ||||
| 	if ok { | ||||
| 		klog.V(2).Infof("force unmount %s", path) | ||||
| 		err = mount.CleanupMountWithForce(path, forceUnmounter, extensiveMountPointCheck, 30*time.Second) | ||||
| 	} else { | ||||
| 		err = mount.CleanupMountPoint(path, mounter, extensiveMountPointCheck) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user