From 46f1ab9e992da0c965fd2b4ab2ddb25accdeb11d Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 7 Jun 2021 11:00:03 +0530 Subject: [PATCH] cephfs: use IsMountPoint to check mountpoint Currently we are relaying on the error output from the umount command we run on the nodes when mounting the volume but we are not checking for all the error message to verify the volume is mounted or not. This commits uses IsMountPoint function in util to check the mountpoint. Signed-off-by: Madhu Rajanna --- internal/cephfs/nodeserver.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/cephfs/nodeserver.go b/internal/cephfs/nodeserver.go index 5013bc7cf..ec125e833 100644 --- a/internal/cephfs/nodeserver.go +++ b/internal/cephfs/nodeserver.go @@ -264,6 +264,22 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu } defer ns.VolumeLocks.Release(volID) + isMnt, err := util.IsMountPoint(targetPath) + if err != nil { + if os.IsNotExist(err) { + // targetPath has already been deleted + util.DebugLog(ctx, "targetPath: %s has already been deleted", targetPath) + return &csi.NodeUnpublishVolumeResponse{}, nil + } + return nil, status.Error(codes.NotFound, err.Error()) + } + if !isMnt { + if err = os.RemoveAll(targetPath); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &csi.NodeUnpublishVolumeResponse{}, nil + } + // Unmount the bind-mount if err = unmountVolume(ctx, targetPath); err != nil { return nil, status.Error(codes.Internal, err.Error()) @@ -294,6 +310,19 @@ func (ns *NodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag defer ns.VolumeLocks.Release(volID) stagingTargetPath := req.GetStagingTargetPath() + + isMnt, err := util.IsMountPoint(stagingTargetPath) + if err != nil { + if os.IsNotExist(err) { + // targetPath has already been deleted + util.DebugLog(ctx, "targetPath: %s has already been deleted", stagingTargetPath) + return &csi.NodeUnstageVolumeResponse{}, nil + } + return nil, status.Error(codes.NotFound, err.Error()) + } + if !isMnt { + return &csi.NodeUnstageVolumeResponse{}, nil + } // Unmount the volume if err = unmountVolume(ctx, stagingTargetPath); err != nil { return nil, status.Error(codes.Internal, err.Error())