From 492c89ff07a2331a0e25dd1ba561f702e247bc17 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 20 Nov 2024 10:15:40 +0100 Subject: [PATCH] rbd: use os.Remove to remove directory using os.RemoveAll will remove everything in the director after the Umount we should be using os.Remove only to remove the empty directory Signed-off-by: Madhu Rajanna (cherry picked from commit 39cc628adf1da1ab78f3aacfb7fe8f53e9a1fd29) --- internal/cephfs/nodeserver.go | 21 +-------------------- internal/rbd/nodeserver.go | 4 ++-- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/internal/cephfs/nodeserver.go b/internal/cephfs/nodeserver.go index f55fc7466..08eaad16c 100644 --- a/internal/cephfs/nodeserver.go +++ b/internal/cephfs/nodeserver.go @@ -462,16 +462,7 @@ func (ns *NodeServer) NodePublishVolume( volOptions := &store.VolumeOptions{} defer volOptions.Destroy() - if err := volOptions.DetectMounter(req.GetVolumeContext()); err != nil { - return nil, status.Errorf(codes.Internal, "failed to detect mounter for volume %s: %v", volID, err.Error()) - } - - volMounter, err := mounter.New(volOptions) - if err != nil { - return nil, status.Errorf(codes.Internal, "failed to create mounter for volume %s: %v", volID, err.Error()) - } - - if err = util.CreateMountPoint(targetPath); err != nil { + if err := util.CreateMountPoint(targetPath); err != nil { log.ErrorLog(ctx, "failed to create mount point at %s: %v", targetPath, err) return nil, status.Error(codes.Internal, err.Error()) @@ -559,16 +550,6 @@ func (ns *NodeServer) NodeUnpublishVolume( } targetPath := req.GetTargetPath() - volID := req.GetVolumeId() - if acquired := ns.VolumeLocks.TryAcquire(targetPath); !acquired { - log.ErrorLog(ctx, util.TargetPathOperationAlreadyExistsFmt, targetPath) - - return nil, status.Errorf(codes.Aborted, util.TargetPathOperationAlreadyExistsFmt, targetPath) - } - defer ns.VolumeLocks.Release(targetPath) - - // stop the health-checker that may have been started in NodeGetVolumeStats() - ns.healthChecker.StopChecker(volID, targetPath) isMnt, err := util.IsMountPoint(ns.Mounter, targetPath) if err != nil { diff --git a/internal/rbd/nodeserver.go b/internal/rbd/nodeserver.go index e635f27eb..41703356b 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -940,7 +940,7 @@ func (ns *NodeServer) NodeUnpublishVolume( return nil, status.Error(codes.NotFound, err.Error()) } if !isMnt { - if err = os.RemoveAll(targetPath); err != nil { + if err = os.Remove(targetPath); err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -951,7 +951,7 @@ func (ns *NodeServer) NodeUnpublishVolume( return nil, status.Error(codes.Internal, err.Error()) } - if err = os.RemoveAll(targetPath); err != nil { + if err = os.Remove(targetPath); err != nil { return nil, status.Error(codes.Internal, err.Error()) }