From df80de8392d3cd2aaa0958900b43f614912f6d3d Mon Sep 17 00:00:00 2001 From: sys-liqian Date: Mon, 18 Dec 2023 07:42:03 -0500 Subject: [PATCH] fix: :bug: fix force umount fix force umount --- cmd/webdav/main.go | 2 +- deploy/csi-webdav-controller.yaml | 2 +- pkg/webdav/controller.go | 20 ++++++++------------ pkg/webdav/driver.go | 6 ------ pkg/webdav/node.go | 2 +- pkg/webdav/utils.go | 14 -------------- 6 files changed, 11 insertions(+), 35 deletions(-) diff --git a/cmd/webdav/main.go b/cmd/webdav/main.go index 4d919bb..0fc437e 100644 --- a/cmd/webdav/main.go +++ b/cmd/webdav/main.go @@ -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") ) diff --git a/deploy/csi-webdav-controller.yaml b/deploy/csi-webdav-controller.yaml index f88227a..a0ca556 100644 --- a/deploy/csi-webdav-controller.yaml +++ b/deploy/csi-webdav-controller.yaml @@ -79,7 +79,7 @@ spec: securityContext: privileged: true capabilities: - add: ["ALL"] + add: ["SYS_ADMIN"] allowPrivilegeEscalation: true args: - "-v=5" diff --git a/pkg/webdav/controller.go b/pkg/webdav/controller.go index 7897f11..e803601 100644 --- a/pkg/webdav/controller.go +++ b/pkg/webdav/controller.go @@ -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 } diff --git a/pkg/webdav/driver.go b/pkg/webdav/driver.go index 0bb7b9c..817c368 100644 --- a/pkg/webdav/driver.go +++ b/pkg/webdav/driver.go @@ -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), diff --git a/pkg/webdav/node.go b/pkg/webdav/node.go index 31b48da..46613b8 100644 --- a/pkg/webdav/node.go +++ b/pkg/webdav/node.go @@ -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) } diff --git a/pkg/webdav/utils.go b/pkg/webdav/utils.go index c3bbcdb..8ca5224 100644 --- a/pkg/webdav/utils.go +++ b/pkg/webdav/utils.go @@ -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 -}