Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Zimin <alexandr.zimin@flant.com>
  • Loading branch information
AleksZimin committed Apr 23, 2024
1 parent adbc80c commit bac90a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
27 changes: 23 additions & 4 deletions images/sds-local-volume-csi/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,25 @@ func (d *Driver) NodePublishVolume(ctx context.Context, request *csi.NodePublish
switch volCap.GetAccessType().(type) {
case *csi.VolumeCapability_Block:
d.log.Trace("[NodePublishVolume] Block volume detected.")
vgName, ok := request.GetVolumeContext()[internal.VGNameKey]
if !ok {
return nil, status.Error(codes.InvalidArgument, "[NodeStageVolume] Volume group name cannot be empty")
}

devPath := fmt.Sprintf("/dev/%s/%s", vgName, request.VolumeId)
d.log.Debug(fmt.Sprintf("[NodePublishVolume] Checking if device exists: %s", devPath))
exists, err := d.storeManager.PathExists(devPath)
if err != nil {
return nil, status.Errorf(codes.Internal, "[NodePublishVolume] Error checking if device exists: %v", err)
}
if !exists {
return nil, status.Errorf(codes.NotFound, "[NodePublishVolume] Device %s not found", devPath)
}
err = d.storeManager.FormatAndMount(devPath, target, true, fsType, false, mountOptions, "", "")
if err != nil {
return nil, status.Errorf(codes.Internal, "[NodePublishVolume] Error mounting volume %q at %q: %v", devPath, target, err)
}

case *csi.VolumeCapability_Mount:
d.log.Trace("[NodePublishVolume] Mount volume detected.")
mountVolume := volCap.GetMount()
Expand All @@ -241,11 +260,11 @@ func (d *Driver) NodePublishVolume(ctx context.Context, request *csi.NodePublish
}

mountOptions = collectMountOptions(fsType, mountVolume.GetMountFlags(), mountOptions)
}

err := d.storeManager.BindMount(source, target, fsType, mountOptions)
if err != nil {
return nil, status.Errorf(codes.Internal, "[NodePublishVolume] Error bind mounting volume %q. Source: %q. Target: %q. Mount options:%v. Err: %v", volumeID, source, target, mountOptions, err)
err := d.storeManager.BindMount(source, target, fsType, mountOptions)
if err != nil {
return nil, status.Errorf(codes.Internal, "[NodePublishVolume] Error bind mounting volume %q. Source: %q. Target: %q. Mount options:%v. Err: %v", volumeID, source, target, mountOptions, err)
}
}

return &csi.NodePublishVolumeResponse{}, nil
Expand Down
12 changes: 6 additions & 6 deletions images/sds-local-volume-csi/pkg/utils/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (s *Store) FormatAndMount(devSourcePath, target string, isBlock bool, fsTyp
if isBlock {
s.Log.Trace("≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈ BLOCK MOUNT ≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈")
s.Log.Trace("-----------------== start Create File ==---------------")
f, err := os.OpenFile(target, os.O_CREATE, os.FileMode(0666))
f, err := os.OpenFile(target, os.O_CREATE, os.FileMode(0644))
if err != nil {
if !os.IsExist(err) {
return fmt.Errorf("could not create bind target for block volume %s, %w", target, err)
Expand Down Expand Up @@ -224,19 +224,19 @@ func (s *Store) BindMount(source, target, fsType string, mountOpts []string) err
isMountPoint := false
exists, err := s.PathExists(target)
if err != nil {
return fmt.Errorf("[BindMount] could not check if target directory %s exists: %w", target, err)
return fmt.Errorf("[BindMount] could not check if target file %s exists: %w", target, err)
}

if exists {
s.Log.Trace(fmt.Sprintf("[BindMount] target directory %s already exists", target))
s.Log.Trace(fmt.Sprintf("[BindMount] target file %s already exists", target))
isMountPoint, err = s.NodeStorage.IsMountPoint(target)
if err != nil {
return fmt.Errorf("[BindMount] could not check if target directory %s is a mount point: %w", target, err)
return fmt.Errorf("[BindMount] could not check if target file %s is a mount point: %w", target, err)
}
} else {
s.Log.Trace(fmt.Sprintf("[BindMount] creating target directory %q", target))
s.Log.Trace(fmt.Sprintf("[BindMount] creating target file %q", target))
if err := os.MkdirAll(target, os.FileMode(0755)); err != nil {
return fmt.Errorf("[BindMount] could not create target directory %q: %w", target, err)
return fmt.Errorf("[BindMount] could not create target file %q: %w", target, err)
}
}

Expand Down

0 comments on commit bac90a6

Please sign in to comment.