Skip to content

Commit f93986b

Browse files
authored
Merge pull request #1329 from huww98/disk-block-touch-late
disk: create block mount file after attach
2 parents 01cf957 + bce596f commit f93986b

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
@@ -519,6 +519,11 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
519519
targetPath := req.StagingTargetPath
520520
// targetPath format: /var/lib/kubelet/plugins/kubernetes.io/csi/pv/pv-disk-1e7001e0-c54a-11e9-8f89-00163e0e78a0/globalmount
521521

522+
if err := os.MkdirAll(targetPath, 0755); err != nil {
523+
klog.Errorf("NodeStageVolume: create volume %s path %s error: %v", req.VolumeId, targetPath, err)
524+
return nil, status.Error(codes.Internal, err.Error())
525+
}
526+
522527
isBlock := req.GetVolumeCapability().GetBlock() != nil
523528
if isBlock {
524529
targetPath = filepath.Join(targetPath, req.VolumeId)
@@ -536,17 +541,6 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
536541
return &csi.NodeStageVolumeResponse{}, nil
537542
}
538543

539-
if isBlock {
540-
if err := ns.mounter.EnsureBlock(targetPath); err != nil {
541-
klog.Errorf("NodeStageVolume: create block volume %s path %s error: %v", req.VolumeId, targetPath, err)
542-
return nil, status.Error(codes.Internal, err.Error())
543-
}
544-
} else {
545-
if err := os.MkdirAll(targetPath, 0755); err != nil {
546-
klog.Errorf("NodeStageVolume: create volume %s path %s error: %v", req.VolumeId, targetPath, err)
547-
return nil, status.Error(codes.Internal, err.Error())
548-
}
549-
}
550544
device := ""
551545
isSharedDisk := false
552546
if value, ok := req.VolumeContext[SharedEnable]; ok {
@@ -637,6 +631,10 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
637631

638632
// Block volume not need to format
639633
if isBlock {
634+
if err := ns.mounter.EnsureBlock(targetPath); err != nil {
635+
klog.Errorf("NodeStageVolume: create block volume %s path %s error: %v", req.VolumeId, targetPath, err)
636+
return nil, status.Error(codes.Internal, err.Error())
637+
}
640638
notmounted, err := ns.k8smounter.IsLikelyNotMountPoint(targetPath)
641639
if err != nil {
642640
return nil, status.Errorf(codes.Internal, "failed to check if %s is not a mount point: %v", targetPath, err)

0 commit comments

Comments
 (0)