Skip to content

Commit 7491e8e

Browse files
committed
fix(sbs): fallback to b_ssd volume id convention
1 parent 9a14499 commit 7491e8e

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

pkg/driver/diskutils.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import (
1616
)
1717

1818
const (
19-
diskByIDPath = "/dev/disk/by-id"
19+
diskByIDPath = "/dev/disk/by-id"
20+
// TODO(nox): DEPRECATION B_SSD - remove legacy format when legacy volumes are fully phased out.
21+
legacyDiskSCWPrefix = "scsi-0SCW_b_ssd_volume-"
2022
diskSCWPrefix = "scsi-0SCW_sbs_volume-"
2123
diskLuksMapperPrefix = "scw-luks-"
2224
diskLuksMapperPath = "/dev/mapper/"
@@ -80,6 +82,13 @@ func devicePath(volumeID string) string {
8082
return path.Join(diskByIDPath, diskSCWPrefix+volumeID)
8183
}
8284

85+
// legacyDevicePath returns the legacy b_ssd volume path
86+
//
87+
// TODO(nox): DEPRECATION B_SSD - remove legacy mode when legacy volumes are fully phased out.
88+
func legacyDevicePath(volumeID string) string {
89+
return path.Join(diskByIDPath, legacyDiskSCWPrefix+volumeID)
90+
}
91+
8392
// EncryptAndOpenDevice encrypts the volume with the given ID with the given passphrase and opens it
8493
// If the device is already encrypted (LUKS header present), it will only open the device.
8594
func (d *diskUtils) EncryptAndOpenDevice(volumeID string, passphrase string) (string, error) {
@@ -211,6 +220,11 @@ func (d *diskUtils) MountToTarget(sourcePath, targetPath, fsType string, mountOp
211220
func (d *diskUtils) GetDevicePath(volumeID string) (string, error) {
212221
devicePath := devicePath(volumeID)
213222
realDevicePath, err := filepath.EvalSymlinks(devicePath)
223+
// TODO(nox): DEPRECATION B_SSD - remove legacy fallback when legacy volumes are fully phased out.
224+
if err != nil && errors.Is(err, fs.ErrNotExist) {
225+
devicePath = legacyDevicePath(volumeID)
226+
realDevicePath, err = filepath.EvalSymlinks(devicePath)
227+
}
214228
if err != nil {
215229
return "", fmt.Errorf("failed to get real device path: %w", err)
216230
}

0 commit comments

Comments
 (0)