From 8d5c65b8cd6b02d18e665056a750e314d63b6143 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Tue, 21 Apr 2020 07:15:02 +0000 Subject: [PATCH] fix: comments(only create parent dir) --- pkg/volume/csi/csi_attacher.go | 14 +++++--------- pkg/volume/csi/csi_mounter.go | 12 ++++-------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 9733b6de11b..fe17e4b7ed6 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -276,16 +276,12 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo // Store volume metadata for UnmountDevice. Keep it around even if the // driver does not support NodeStage, UnmountDevice still needs it. - if err = os.MkdirAll(deviceMountPath, 0750); err != nil { - if isCorruptedDir(deviceMountPath) { - // leave to CSI driver to handle corrupted mount - klog.Warning(log("attacher.MountDevice detected corrupted mount for dir [%s]", deviceMountPath)) - } else { - return errors.New(log("attacher.MountDevice failed to create dir %#v: %v", deviceMountPath, err)) - } + parentDir := filepath.Dir(deviceMountPath) + if err = os.MkdirAll(parentDir, 0750); err != nil { + return errors.New(log("attacher.MountDevice failed to create dir %#v: %v", parentDir, err)) } - klog.V(4).Info(log("created target path successfully [%s]", deviceMountPath)) - dataDir := filepath.Dir(deviceMountPath) + klog.V(4).Info(log("created target path successfully [%s]", parentDir)) + dataDir := parentDir data := map[string]string{ volDataKey.volHandle: csiSource.VolumeHandle, volDataKey.driverName: csiSource.Driver, diff --git a/pkg/volume/csi/csi_mounter.go b/pkg/volume/csi/csi_mounter.go index fbcb16e75af..77560bf1a18 100644 --- a/pkg/volume/csi/csi_mounter.go +++ b/pkg/volume/csi/csi_mounter.go @@ -202,15 +202,11 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error } // create target_dir before call to NodePublish - if err := os.MkdirAll(dir, 0750); err != nil { - if isCorruptedDir(dir) { - // leave to CSI driver to handle corrupted mount - klog.Warning(log("mounter.SetUpAt detected corrupted mount for dir [%s]", dir)) - } else { - return errors.New(log("mounter.SetUpAt failed to create dir %#v: %v", dir, err)) - } + parentDir := filepath.Dir(dir) + if err := os.MkdirAll(parentDir, 0750); err != nil { + return errors.New(log("mounter.SetUpAt failed to create dir %#v: %v", parentDir, err)) } - klog.V(4).Info(log("created target path successfully [%s]", dir)) + klog.V(4).Info(log("created target path successfully [%s]", parentDir)) nodePublishSecrets = map[string]string{} if secretRef != nil {