From b3a27c44bf25104787eea4026b7a07ea9dbb7de9 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Wed, 4 Mar 2020 11:33:06 +0000 Subject: [PATCH] fix comments --- pkg/volume/csi/csi_attacher.go | 15 ++++++++++----- pkg/volume/csi/csi_mounter.go | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index c9e3b4b780e..9733b6de11b 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -276,11 +276,16 @@ 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. - dataDir := filepath.Dir(deviceMountPath) - if err = os.MkdirAll(dataDir, 0750); err != nil { - return errors.New(log("attacher.MountDevice failed to create dir %#v: %v", dataDir, err)) + 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)) + } } - klog.V(4).Info(log("created target parent path successfully [%s]", dataDir)) + klog.V(4).Info(log("created target path successfully [%s]", deviceMountPath)) + dataDir := filepath.Dir(deviceMountPath) data := map[string]string{ volDataKey.volHandle: csiSource.VolumeHandle, volDataKey.driverName: csiSource.Driver, @@ -298,7 +303,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo if err != nil && volumetypes.IsOperationFinishedError(err) { // clean up metadata klog.Errorf(log("attacher.MountDevice failed: %v", err)) - if err := removeMountDir(c.plugin, dataDir); err != nil { + if err := removeMountDir(c.plugin, deviceMountPath); err != nil { klog.Error(log("attacher.MountDevice failed to remove mount dir after error [%s]: %v", deviceMountPath, err)) } } diff --git a/pkg/volume/csi/csi_mounter.go b/pkg/volume/csi/csi_mounter.go index 7626234ac83..fbcb16e75af 100644 --- a/pkg/volume/csi/csi_mounter.go +++ b/pkg/volume/csi/csi_mounter.go @@ -201,6 +201,17 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error return fmt.Errorf("volume source not found in volume.Spec") } + // 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)) + } + } + klog.V(4).Info(log("created target path successfully [%s]", dir)) + nodePublishSecrets = map[string]string{} if secretRef != nil { nodePublishSecrets, err = getCredentialsFromSecret(c.k8s, secretRef)