fix: 🐛 fix force umount

fix force umount
dev
sys-liqian 1 year ago
parent f8aa58a3be
commit df80de8392

@ -29,7 +29,7 @@ var (
nodeID = flag.String("nodeid", "", "node id") nodeID = flag.String("nodeid", "", "node id")
mountPermissions = flag.Uint64("mount-permissions", 0, "mounted folder permissions") mountPermissions = flag.Uint64("mount-permissions", 0, "mounted folder permissions")
driverName = flag.String("drivername", "", "name of the driver") 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") defaultOnDeletePolicy = flag.String("default-ondelete-policy", "", "default policy for deleting subdirectory when deleting a volume")
) )

@ -79,7 +79,7 @@ spec:
securityContext: securityContext:
privileged: true privileged: true
capabilities: capabilities:
add: ["ALL"] add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true allowPrivilegeEscalation: true
args: args:
- "-v=5" - "-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())) 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) internalVolumePath := filepath.Join(targetPath, req.Name)
if err = os.Mkdir(internalVolumePath, 0777); err != nil && !os.IsExist(err) { if err = os.Mkdir(internalVolumePath, 0777); err != nil && !os.IsExist(err) {
return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err.Error()) 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{ return &csi.CreateVolumeResponse{
Volume: &csi.Volume{ Volume: &csi.Volume{
VolumeId: MakeVolumeId(sourcePath, req.Name), 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())) 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) internalVolumePath := filepath.Join(targetPath, subDir)
klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath) klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath)
if err = os.RemoveAll(internalVolumePath); err != nil { if err = os.RemoveAll(internalVolumePath); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error()) 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 return &csi.DeleteVolumeResponse{}, nil
} }

@ -17,8 +17,6 @@ limitations under the License.
package webdav package webdav
import ( import (
"runtime"
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/sys-liqian/csi-driver-webdav/pkg/webdav/mount" "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) klog.V(2).Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta)
mounter := mount.New("") mounter := mount.New("")
if runtime.GOOS == "linux" {
// MounterForceUnmounter is only implemented on Linux now
mounter = mounter.(mount.MounterForceUnmounter)
}
server := NewNonBlockingGRPCServer() server := NewNonBlockingGRPCServer()
server.Start(d.endpoint, server.Start(d.endpoint,
NewIdentityServer(d), 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) 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 { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err) return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err)
} }

@ -21,10 +21,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"time"
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/sys-liqian/csi-driver-webdav/pkg/webdav/mount"
"google.golang.org/grpc" "google.golang.org/grpc"
"k8s.io/klog/v2" "k8s.io/klog/v2"
) )
@ -93,15 +91,3 @@ func ParseVolumeId(volumeId string) (webdavSharePath, subDir string, err error)
} }
return arr[0], arr[1], nil 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…
Cancel
Save