From eddfc123e517e658e9a38ce7105c18ac90fc78b0 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 17 Dec 2019 14:37:46 +0530 Subject: [PATCH] discard umount error if directory is not mounted if the directory is not mounted return nil during umount of mountPoint Discard error if error is os.IsNotExist Signed-off-by: Madhu Rajanna (cherry picked from commit dcafdb519ee17b60e769279f84fe44a78061d9f6) --- pkg/cephfs/nodeserver.go | 3 ++- pkg/cephfs/volumemounter.go | 4 ++++ pkg/util/nodecache.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/cephfs/nodeserver.go b/pkg/cephfs/nodeserver.go index dab49a335..530341323 100644 --- a/pkg/cephfs/nodeserver.go +++ b/pkg/cephfs/nodeserver.go @@ -267,7 +267,8 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu return nil, status.Error(codes.Internal, err.Error()) } - if err = os.Remove(targetPath); err != nil { + err = os.Remove(targetPath) + if err != nil && !os.IsNotExist(err) { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/pkg/cephfs/volumemounter.go b/pkg/cephfs/volumemounter.go index ff007013a..a78ae6282 100644 --- a/pkg/cephfs/volumemounter.go +++ b/pkg/cephfs/volumemounter.go @@ -321,6 +321,10 @@ func bindMount(ctx context.Context, from, to string, readOnly bool, mntOptions [ func unmountVolume(ctx context.Context, mountPoint string) error { if err := execCommandErr(ctx, "umount", mountPoint); err != nil { + if strings.Contains(err.Error(), fmt.Sprintf("exit status 32: umount: %s: not mounted", mountPoint)) || + strings.Contains(err.Error(), "No such file or directory") { + return nil + } return err } diff --git a/pkg/util/nodecache.go b/pkg/util/nodecache.go index 7b139d466..d41e1fa67 100644 --- a/pkg/util/nodecache.go +++ b/pkg/util/nodecache.go @@ -155,7 +155,7 @@ func (nc *NodeCache) Delete(identifier string) error { file := path.Join(nc.BasePath, nc.CacheDir, identifier+".json") err := os.Remove(file) if err != nil { - if err == os.ErrNotExist { + if os.IsNotExist(err) { klog.V(4).Infof("node-cache: cannot delete missing metadata storage file %s, assuming it's already deleted", file) return nil }