Skip to content

Commit

Permalink
fix(sbs): fallback to b_ssd volume id convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Nox-404 committed Mar 5, 2024
1 parent e9dd4c0 commit e736821
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/driver/diskutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
)

const (
diskByIDPath = "/dev/disk/by-id"
diskByIDPath = "/dev/disk/by-id"
// TODO(nox): DEPRECATION B_SSD - remove legacy format when legacy volumes are fully phased out.
legacyDiskSCWPrefix = "scsi-0SCW_b_ssd_volume-"
diskSCWPrefix = "scsi-0SCW_sbs_"
diskLuksMapperPrefix = "scw-luks-"
diskLuksMapperPath = "/dev/mapper/"
Expand Down Expand Up @@ -80,6 +82,13 @@ func devicePath(volumeID string) string {
return path.Join(diskByIDPath, diskSCWPrefix+volumeID)
}

// legacyDevicePath returns the legacy b_ssd volume path
//
// TODO(nox): DEPRECATION B_SSD - remove legacy mode when legacy volumes are fully phased out.
func legacyDevicePath(volumeID string) string {
return path.Join(diskByIDPath, legacyDiskSCWPrefix+volumeID)
}

// EncryptAndOpenDevice encrypts the volume with the given ID with the given passphrase and opens it
// If the device is already encrypted (LUKS header present), it will only open the device.
func (d *diskUtils) EncryptAndOpenDevice(volumeID string, passphrase string) (string, error) {
Expand Down Expand Up @@ -211,6 +220,11 @@ func (d *diskUtils) MountToTarget(sourcePath, targetPath, fsType string, mountOp
func (d *diskUtils) GetDevicePath(volumeID string) (string, error) {
devicePath := devicePath(volumeID)
realDevicePath, err := filepath.EvalSymlinks(devicePath)
// TODO(nox): DEPRECATION B_SSD - remove legacy fallback when legacy volumes are fully phased out.
if err != nil && errors.Is(os.ErrNotExist, err) {
devicePath = legacyDevicePath(volumeID)
realDevicePath, err = filepath.EvalSymlinks(devicePath)
}
if err != nil {
return "", fmt.Errorf("failed to get real device path: %w", err)
}
Expand Down

0 comments on commit e736821

Please sign in to comment.