Skip to content

Commit bce596f

Browse files
committed
disk: create block mount file after attach
We should not leave it over if the attach failed
1 parent 85465f5 commit bce596f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pkg/disk/nodeserver.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,11 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
510510
targetPath := req.StagingTargetPath
511511
// targetPath format: /var/lib/kubelet/plugins/kubernetes.io/csi/pv/pv-disk-1e7001e0-c54a-11e9-8f89-00163e0e78a0/globalmount
512512

513+
if err := os.MkdirAll(targetPath, 0755); err != nil {
514+
klog.Errorf("NodeStageVolume: create volume %s path %s error: %v", req.VolumeId, targetPath, err)
515+
return nil, status.Error(codes.Internal, err.Error())
516+
}
517+
513518
isBlock := req.GetVolumeCapability().GetBlock() != nil
514519
if isBlock {
515520
targetPath = filepath.Join(targetPath, req.VolumeId)
@@ -527,17 +532,6 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
527532
return &csi.NodeStageVolumeResponse{}, nil
528533
}
529534

530-
if isBlock {
531-
if err := ns.mounter.EnsureBlock(targetPath); err != nil {
532-
klog.Errorf("NodeStageVolume: create block volume %s path %s error: %v", req.VolumeId, targetPath, err)
533-
return nil, status.Error(codes.Internal, err.Error())
534-
}
535-
} else {
536-
if err := os.MkdirAll(targetPath, 0755); err != nil {
537-
klog.Errorf("NodeStageVolume: create volume %s path %s error: %v", req.VolumeId, targetPath, err)
538-
return nil, status.Error(codes.Internal, err.Error())
539-
}
540-
}
541535
device := ""
542536
isSharedDisk := false
543537
if value, ok := req.VolumeContext[SharedEnable]; ok {
@@ -625,6 +619,10 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
625619

626620
// Block volume not need to format
627621
if isBlock {
622+
if err := ns.mounter.EnsureBlock(targetPath); err != nil {
623+
klog.Errorf("NodeStageVolume: create block volume %s path %s error: %v", req.VolumeId, targetPath, err)
624+
return nil, status.Error(codes.Internal, err.Error())
625+
}
628626
notmounted, err := ns.k8smounter.IsLikelyNotMountPoint(targetPath)
629627
if err != nil {
630628
return nil, status.Errorf(codes.Internal, "failed to check if %s is not a mount point: %v", targetPath, err)

0 commit comments

Comments
 (0)