fix: 🐛 fix umount webdav server

fix umount webdav server

Signed-off-by: sys-liqian <lq1083301982@163.com>
This commit is contained in:
sys-liqian
2023-12-22 22:28:14 -05:00
parent 7051bb12b2
commit ff95639565
4 changed files with 43 additions and 11 deletions

View File

@@ -101,6 +101,12 @@ func (c *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu
return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err.Error())
}
defer func() {
if err = c.mounter.Unmount(targetPath); err != nil {
klog.Warningf("failed to unmount targetpath %s: %v", targetPath, err.Error())
}
}()
if mountPermissions > 0 {
// Reset directory permissions because of umask problems
if err = os.Chmod(internalVolumePath, os.FileMode(mountPermissions)); err != nil {
@@ -108,10 +114,6 @@ 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),
@@ -142,16 +144,18 @@ 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 = c.mounter.Unmount(targetPath); err != nil {
klog.Warningf("failed to unmount targetpath %s: %v", targetPath, err.Error())
}
}()
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
}

View File

@@ -110,9 +110,20 @@ func (n *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpub
if len(targetPath) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
}
klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath)
err := n.mounter.Unmount(targetPath)
notMnt, err := n.mounter.IsLikelyNotMountPoint(targetPath)
if err != nil {
if os.IsNotExist(err) {
return nil, status.Error(codes.NotFound, "Targetpath not found")
}
return nil, status.Error(codes.Internal, err.Error())
}
if notMnt {
return &csi.NodeUnpublishVolumeResponse{}, nil
}
klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath)
err = n.mounter.Unmount(targetPath)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to unmount target %q: %v", targetPath, err)
}