Skip to content

Commit

Permalink
Merge pull request #65 from Nox-404/sbs-volume-id
Browse files Browse the repository at this point in the history
fix(sbs): use new SBS volume id convention
  • Loading branch information
Nox-404 authored Mar 6, 2024
2 parents b14d6df + 7491e8e commit 67efc67
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/driver/diskutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
)

const (
diskByIDPath = "/dev/disk/by-id"
diskSCWPrefix = "scsi-0SCW_b_ssd_volume-"
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_volume-"
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(err, fs.ErrNotExist) {
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 67efc67

Please sign in to comment.