Skip to content

Commit

Permalink
[CSI] remove nodePublishDiskAsFilesystemDeprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmyagkov committed Jan 6, 2025
1 parent b5c6c77 commit eb16ac3
Showing 1 changed file with 2 additions and 78 deletions.
80 changes: 2 additions & 78 deletions cloud/blockstore/tools/csi_driver/internal/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,81 +588,14 @@ func (s *nodeService) nodeStageDiskAsVhostSocket(
return s.createDummyImgFile(endpointDir)
}

func (s *nodeService) nodePublishDiskAsFilesystemDeprecated(
ctx context.Context,
req *csi.NodePublishVolumeRequest) error {

diskId := req.VolumeId
resp, err := s.startNbsEndpointForNBD(ctx, s.getPodId(req), diskId, req.VolumeContext)
if err != nil {
return fmt.Errorf("failed to start NBS endpoint: %w", err)
}

if resp.NbdDeviceFile == "" {
return fmt.Errorf("NbdDeviceFile shouldn't be empty")
}

logVolume(req.VolumeId, "endpoint started with device: %q", resp.NbdDeviceFile)

mnt := req.VolumeCapability.GetMount()

fsType := req.VolumeContext["fsType"]
if mnt != nil && mnt.FsType != "" {
fsType = mnt.FsType
}
if fsType == "" {
fsType = "ext4"
}

err = s.makeFilesystemIfNeeded(diskId, resp.NbdDeviceFile, fsType)
if err != nil {
return err
}

mounted, _ := s.mounter.IsMountPoint(req.TargetPath)
if !mounted {
targetPerm := os.FileMode(0775)
if err := os.MkdirAll(req.TargetPath, targetPerm); err != nil {
return fmt.Errorf("failed to create target directory: %w", err)
}

if err := os.Chmod(req.TargetPath, targetPerm); err != nil {
return fmt.Errorf("failed to chmod target path: %w", err)
}
}

mountOptions := []string{}
if mnt != nil {
for _, flag := range mnt.MountFlags {
mountOptions = append(mountOptions, flag)
}
}
if req.Readonly {
mountOptions = append(mountOptions, "ro")
}

err = s.mountIfNeeded(
diskId,
resp.NbdDeviceFile,
req.TargetPath,
fsType,
mountOptions)
if err != nil {
return err
}

return nil
}

func (s *nodeService) nodePublishDiskAsFilesystem(
ctx context.Context,
req *csi.NodePublishVolumeRequest) error {

// Fallback to previous implementation for already mounted volumes
// Must be removed after migration of all endpoints to the new format
mounted, _ := s.mounter.IsMountPoint(req.StagingTargetPath)
if !mounted {
return s.nodePublishDiskAsFilesystemDeprecated(ctx, req)
return s.statusErrorf(codes.FailedPrecondition,
"Staging target path is not mounted: %w", req.VolumeId)
}

mounted, _ = s.mounter.IsMountPoint(req.TargetPath)
Expand Down Expand Up @@ -748,15 +681,6 @@ func (s *nodeService) nodeStageDiskAsFilesystem(
diskId := req.VolumeId
resp, err := s.startNbsEndpointForNBD(ctx, "", diskId, req.VolumeContext)
if err != nil {
if s.IsMountConflictError(err) {
localEndpoint, err := s.hasLocalEndpoint(ctx, diskId)
if err != nil {
return err
}
if localEndpoint {
return nil
}
}
return fmt.Errorf("failed to start NBS endpoint: %w", err)
}

Expand Down

0 comments on commit eb16ac3

Please sign in to comment.