Skip to content

Commit 008c083

Browse files
authored
Luks device naming cleanup
Adjusts naming in the LUKS package
1 parent e78b15c commit 008c083

File tree

20 files changed

+137
-180
lines changed

20 files changed

+137
-180
lines changed

frontend/csi/controller_helpers/kubernetes/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (h *helper) ImportVolume(
116116
// LUKS annotation should be accepted as either "LUKSEncryption" or "luksEncryption" to match storage pools.
117117
if luksAnnotation := getCaseFoldedAnnotation(claim.GetObjectMeta().GetAnnotations(), AnnLUKSEncryption); luksAnnotation != "" {
118118
if convert.ToBool(luksAnnotation) {
119-
dataSize -= luks.LUKSMetadataSize
119+
dataSize -= luks.MetadataSize
120120
}
121121
}
122122

frontend/csi/node_server.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func (p *Plugin) nodeExpandVolume(
584584

585585
devicePath := publishInfo.DevicePath
586586
if convert.ToBool(publishInfo.LUKSEncryption) {
587-
if !luks.IsLegacyLUKSDevicePath(devicePath) {
587+
if !luks.IsLegacyDevicePath(devicePath) {
588588
devicePath, err = p.devices.GetLUKSDeviceForMultipathDevice(devicePath)
589589
if err != nil {
590590
Logc(ctx).WithFields(LogFields{
@@ -1330,7 +1330,7 @@ func (p *Plugin) nodeStageFCPVolume(
13301330
}
13311331

13321332
var luksDevice luks.Device
1333-
luksDevice = luks.NewLUKSDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
1333+
luksDevice = luks.NewDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
13341334

13351335
// Ensure we update the passphrase in case it has never been set before
13361336
err = ensureLUKSVolumePassphrase(ctx, p.restClient, luksDevice, volumeId, req.GetSecrets(), true)
@@ -1393,7 +1393,7 @@ func (p *Plugin) nodeUnstageFCPVolume(
13931393
var luksMapperPath string
13941394
fields := LogFields{"device": publishInfo.DevicePath}
13951395
// Set device path to dm device to correctly verify legacy volumes.
1396-
if luks.IsLegacyLUKSDevicePath(publishInfo.DevicePath) {
1396+
if luks.IsLegacyDevicePath(publishInfo.DevicePath) {
13971397
luksMapperPath = publishInfo.DevicePath
13981398
dmPath, err := luks.GetDmDevicePathFromLUKSLegacyPath(ctx, p.command,
13991399
publishInfo.DevicePath)
@@ -1482,7 +1482,7 @@ func (p *Plugin) nodeUnstageFCPVolume(
14821482
}
14831483

14841484
// Set device path to dm device to correctly verify legacy volumes.
1485-
if luks.IsLegacyLUKSDevicePath(publishInfo.DevicePath) {
1485+
if luks.IsLegacyDevicePath(publishInfo.DevicePath) {
14861486
publishInfo.DevicePath = deviceInfo.MultipathDevice
14871487
}
14881488
}
@@ -1615,16 +1615,16 @@ func (p *Plugin) nodePublishFCPVolume(
16151615
// Rotate the LUKS passphrase if needed, on failure, log and continue to publish
16161616

16171617
var luksDevice luks.Device
1618-
if luks.IsLegacyLUKSDevicePath(devicePath) {
1618+
if luks.IsLegacyDevicePath(devicePath) {
16191619
// Supports legacy volumes that store the LUKS device path
1620-
luksDevice, err = luks.NewLUKSDeviceFromMappingPath(
1620+
luksDevice, err = luks.NewDeviceFromMappingPath(
16211621
ctx, p.command, devicePath, req.VolumeContext["internalName"],
16221622
)
16231623
if err != nil {
16241624
return nil, status.Error(codes.Internal, err.Error())
16251625
}
16261626
} else {
1627-
luksDevice = luks.NewLUKSDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
1627+
luksDevice = luks.NewDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
16281628
}
16291629

16301630
err = ensureLUKSVolumePassphrase(ctx, p.restClient, luksDevice, req.GetVolumeId(), req.GetSecrets(), false)
@@ -1782,7 +1782,7 @@ func (p *Plugin) nodeStageISCSIVolume(
17821782
}
17831783

17841784
var luksDevice luks.Device
1785-
luksDevice = luks.NewLUKSDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
1785+
luksDevice = luks.NewDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
17861786

17871787
// Ensure we update the passphrase in case it has never been set before
17881788
err = ensureLUKSVolumePassphrase(ctx, p.restClient, luksDevice, volumeId, req.GetSecrets(), true)
@@ -1889,7 +1889,7 @@ func (p *Plugin) nodeUnstageISCSIVolume(
18891889
var luksMapperPath string
18901890
fields := LogFields{"device": publishInfo.DevicePath}
18911891
// Set device path to dm device to correctly verify legacy volumes.
1892-
if luks.IsLegacyLUKSDevicePath(publishInfo.DevicePath) {
1892+
if luks.IsLegacyDevicePath(publishInfo.DevicePath) {
18931893
luksMapperPath = publishInfo.DevicePath
18941894
dmPath, err := luks.GetDmDevicePathFromLUKSLegacyPath(ctx, p.command,
18951895
publishInfo.DevicePath)
@@ -1977,7 +1977,7 @@ func (p *Plugin) nodeUnstageISCSIVolume(
19771977
}
19781978

19791979
// Set device path to dm device to correctly verify legacy volumes.
1980-
if luks.IsLegacyLUKSDevicePath(publishInfo.DevicePath) {
1980+
if luks.IsLegacyDevicePath(publishInfo.DevicePath) {
19811981
publishInfo.DevicePath = deviceInfo.MultipathDevice
19821982
}
19831983
}
@@ -2152,12 +2152,12 @@ func (p *Plugin) nodePublishISCSIVolume(
21522152
// Rotate the LUKS passphrase if needed, on failure, log and continue to publish
21532153
var luksDevice luks.Device
21542154
var err error
2155-
if luks.IsLegacyLUKSDevicePath(devicePath) {
2155+
if luks.IsLegacyDevicePath(devicePath) {
21562156
// Supports legacy volumes that store the LUKS device path
2157-
luksDevice, err = luks.NewLUKSDeviceFromMappingPath(ctx, p.command, devicePath,
2157+
luksDevice, err = luks.NewDeviceFromMappingPath(ctx, p.command, devicePath,
21582158
req.VolumeContext["internalName"])
21592159
} else {
2160-
luksDevice = luks.NewLUKSDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
2160+
luksDevice = luks.NewDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
21612161
}
21622162

21632163
if err != nil {
@@ -2866,7 +2866,7 @@ func (p *Plugin) nodeStageNVMeVolume(
28662866
}
28672867

28682868
if isLUKS {
2869-
luksDevice := luks.NewLUKSDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
2869+
luksDevice := luks.NewDevice(publishInfo.DevicePath, req.VolumeContext["internalName"], p.command)
28702870

28712871
// Ensure we update the passphrase in case it has never been set before
28722872
err = ensureLUKSVolumePassphrase(ctx, p.restClient, luksDevice, volumeId, req.GetSecrets(), true)
@@ -3070,7 +3070,7 @@ func (p *Plugin) nodePublishNVMeVolume(
30703070
devicePath := publishInfo.DevicePath
30713071
if convert.ToBool(publishInfo.LUKSEncryption) {
30723072
// Rotate the LUKS passphrase if needed, on failure, log and continue to publish
3073-
luksDevice := luks.NewLUKSDevice(devicePath, req.VolumeContext["internalName"], p.command)
3073+
luksDevice := luks.NewDevice(devicePath, req.VolumeContext["internalName"], p.command)
30743074

30753075
err = ensureLUKSVolumePassphrase(ctx, p.restClient, luksDevice, req.GetVolumeId(), req.GetSecrets(), false)
30763076
if err != nil {

frontend/csi/node_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ func TestNodeUnstageISCSIVolume(t *testing.T) {
22672267
return mockNodeHelper
22682268
},
22692269
},
2270-
"SAN: iSCSI unstage: GetUnderlyingDevicePathForLUKSDevice error": {
2270+
"SAN: iSCSI unstage: GetUnderlyingDevicePathForDevice error": {
22712271
assertError: assert.NoError,
22722272
request: NewNodeUnstageVolumeRequestBuilder().Build(),
22732273
publishInfo: NewVolumePublishInfoBuilder(TypeiSCSIVolumePublishInfo).WithLUKSEncryption("true").Build(),

mocks/mock_utils/mock_devices/mock_luks/mock_luks.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

storage_drivers/ontap/ontap_common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4422,7 +4422,7 @@ func incrementWithLUKSMetadataIfLUKSEnabled(ctx context.Context, size uint64, lu
44224422
}
44234423

44244424
if isLUKS {
4425-
return size + luks.LUKSMetadataSize
4425+
return size + luks.MetadataSize
44264426
}
44274427

44284428
return size
@@ -4435,13 +4435,13 @@ func decrementWithLUKSMetadataIfLUKSEnabled(ctx context.Context, size uint64, lu
44354435
Logc(ctx).WithError(err).Debug("Could not parse luksEncryption string.")
44364436
}
44374437

4438-
if luks.LUKSMetadataSize > size {
4438+
if luks.MetadataSize > size {
44394439
Logc(ctx).WithError(err).WithField("size", size).Error("Size too small to subtract LUKS metadata.")
44404440
return 0
44414441
}
44424442

44434443
if isLUKS {
4444-
return size - luks.LUKSMetadataSize
4444+
return size - luks.MetadataSize
44454445
}
44464446

44474447
return size

storage_drivers/ontap/ontap_san.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ func (d *SANStorageDriver) Import(ctx context.Context, volConfig *storage.Volume
756756
volConfig.Size = lunInfo.Size
757757

758758
if convert.ToBool(volConfig.LUKSEncryption) {
759-
newSize, err := subtractUintFromSizeString(volConfig.Size, luks.LUKSMetadataSize)
759+
newSize, err := subtractUintFromSizeString(volConfig.Size, luks.MetadataSize)
760760
if err != nil {
761761
return err
762762
}

storage_drivers/ontap/ontap_san_economy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ func (d *SANEconomyStorageDriver) Import(
942942
volConfig.Size = extantLUN.Size
943943

944944
if convert.ToBool(volConfig.LUKSEncryption) {
945-
newSize, err := subtractUintFromSizeString(volConfig.Size, luks.LUKSMetadataSize)
945+
newSize, err := subtractUintFromSizeString(volConfig.Size, luks.MetadataSize)
946946
if err != nil {
947947
return err
948948
}

storage_drivers/ontap/ontap_san_nvme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ func (d *NVMeStorageDriver) Import(ctx context.Context, volConfig *storage.Volum
685685
// If the import is a LUKS encrypted volume, then remove the LUKS metadata overhead from the reported
686686
// size on the volConfig.
687687
if convert.ToBool(volConfig.LUKSEncryption) {
688-
newSize, err := subtractUintFromSizeString(volConfig.Size, luks.LUKSMetadataSize)
688+
newSize, err := subtractUintFromSizeString(volConfig.Size, luks.MetadataSize)
689689
if err != nil {
690690
return err
691691
}

utils/devices/luks/luks.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import (
1919
)
2020

2121
const (
22-
luksDevicePrefix = "luks-"
22+
devicePrefix = "luks-"
2323
// LUKS2 requires ~16MiB for overhead. Default to 18MiB just in case.
24-
LUKSMetadataSize = 18874368
24+
MetadataSize = 18874368
2525
)
2626

2727
type Device interface {
28-
EnsureLUKSDeviceMappedOnHost(ctx context.Context, name string, secrets map[string]string) (bool, error)
28+
EnsureDeviceMappedOnHost(ctx context.Context, name string, secrets map[string]string) (bool, error)
2929
MappedDevicePath() string
3030
MappedDeviceName() string
3131
RawDevicePath() string
@@ -42,8 +42,8 @@ type LUKSDevice struct {
4242
osFs afero.Fs
4343
}
4444

45-
func NewLUKSDevice(rawDevicePath, volumeId string, command execCmd.Command) *LUKSDevice {
46-
luksDeviceName := luksDevicePrefix + volumeId
45+
func NewDevice(rawDevicePath, volumeId string, command execCmd.Command) *LUKSDevice {
46+
luksDeviceName := devicePrefix + volumeId
4747
devices := devices.New()
4848
osFs := afero.NewOsFs()
4949
return NewDetailed(rawDevicePath, luksDeviceName, command, devices, osFs)
@@ -61,18 +61,18 @@ func NewDetailed(rawDevicePath, mappedDeviceName string, command execCmd.Command
6161
}
6262
}
6363

64-
func NewLUKSDeviceFromMappingPath(
64+
func NewDeviceFromMappingPath(
6565
ctx context.Context, command execCmd.Command, mappingPath, volumeId string,
6666
) (*LUKSDevice, error) {
67-
rawDevicePath, err := GetUnderlyingDevicePathForLUKSDevice(ctx, command, mappingPath)
67+
rawDevicePath, err := GetUnderlyingDevicePathForDevice(ctx, command, mappingPath)
6868
if err != nil {
6969
return nil, fmt.Errorf("could not determine underlying device for LUKS mapping; %v", err)
7070
}
71-
return NewLUKSDevice(rawDevicePath, volumeId, command), nil
71+
return NewDevice(rawDevicePath, volumeId, command), nil
7272
}
7373

7474
// EnsureLUKSDeviceMappedOnHost ensures the specified device is LUKS formatted, opened, and has the current passphrase.
75-
func (d *LUKSDevice) EnsureLUKSDeviceMappedOnHost(ctx context.Context, name string, secrets map[string]string) (bool, error) {
75+
func (d *LUKSDevice) EnsureDeviceMappedOnHost(ctx context.Context, name string, secrets map[string]string) (bool, error) {
7676
// Try to Open with current luks passphrase
7777
luksPassphraseName, luksPassphrase, previousLUKSPassphraseName, previousLUKSPassphrase := GetLUKSPassphrasesFromSecretMap(secrets)
7878
if luksPassphrase == "" {
@@ -149,7 +149,7 @@ func (d *LUKSDevice) ensureLUKSDevice(ctx context.Context, luksPassphrase string
149149
return true, nil
150150
}
151151

152-
if err := d.lUKSFormat(ctx, luksPassphrase); err != nil {
152+
if err := d.formatUnformattedDevice(ctx, luksPassphrase); err != nil {
153153
Logc(ctx).WithError(err).Error("Could not LUKS format device.")
154154
return false, fmt.Errorf("could not LUKS format device; %w", err)
155155
}
@@ -176,8 +176,8 @@ func GetLUKSPassphrasesFromSecretMap(secrets map[string]string) (string, string,
176176
return luksPassphraseName, luksPassphrase, previousLUKSPassphraseName, previousLUKSPassphrase
177177
}
178178

179-
// IsLegacyLUKSDevicePath returns true if the device path points to mapped LUKS device instead of mpath device.
180-
func IsLegacyLUKSDevicePath(devicePath string) bool {
179+
// IsLegacyDevicePath returns true if the device path points to mapped LUKS device instead of mpath device.
180+
func IsLegacyDevicePath(devicePath string) bool {
181181
return strings.Contains(devicePath, "luks")
182182
}
183183

@@ -186,7 +186,7 @@ func IsLegacyLUKSDevicePath(devicePath string) bool {
186186
func GetDmDevicePathFromLUKSLegacyPath(
187187
ctx context.Context, command execCmd.Command, devicePath string,
188188
) (string, error) {
189-
if !IsLegacyLUKSDevicePath(devicePath) {
189+
if !IsLegacyDevicePath(devicePath) {
190190
return "", fmt.Errorf("device path is not a legacy LUKS device path")
191191
}
192192
lsblk := lsblk.NewLsblkUtilDetailed(command)

utils/devices/luks/luks_darwin.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func (d *LUKSDevice) RotatePassphrase(ctx context.Context, volumeId, previousLUK
2222
return errors.UnsupportedError("RotatePassphrase is not supported for darwin")
2323
}
2424

25-
// IsLUKSFormatted returns whether LUKS headers have been placed on the device
26-
func (d *LUKSDevice) IsLUKSFormatted(ctx context.Context) (bool, error) {
27-
Logc(ctx).Debug(">>>> devices_darwin.IsLUKSFormatted")
28-
defer Logc(ctx).Debug("<<<< devices_darwin.IsLUKSFormatted")
29-
return false, errors.UnsupportedError("IsLUKSFormatted is not supported for darwin")
25+
// IsFormatted returns whether LUKS headers have been placed on the device
26+
func (d *LUKSDevice) IsFormatted(ctx context.Context) (bool, error) {
27+
Logc(ctx).Debug(">>>> devices_darwin.IsFormatted")
28+
defer Logc(ctx).Debug("<<<< devices_darwin.IsFormatted")
29+
return false, errors.UnsupportedError("IsFormatted is not supported for darwin")
3030
}
3131

3232
// IsOpen returns whether the device is an active luks device on the host
@@ -36,12 +36,12 @@ func (d *LUKSDevice) IsOpen(ctx context.Context) (bool, error) {
3636
return false, errors.UnsupportedError("IsOpen is not supported for darwin")
3737
}
3838

39-
// lUKSFormat attempts to set up LUKS headers on a device with the specified passphrase, but bails if the
39+
// formatUnformattedDevice attempts to set up LUKS headers on a device with the specified passphrase, but bails if the
4040
// underlying device already has a format present that is not LUKS.
41-
func (d *LUKSDevice) lUKSFormat(ctx context.Context, _ string) error {
42-
Logc(ctx).Debug(">>>> devices_darwin.LUKSFormat")
43-
defer Logc(ctx).Debug("<<<< devices_darwin.LUKSFormat")
44-
return errors.UnsupportedError("LUKSFormat is not supported for darwin")
41+
func (d *LUKSDevice) formatUnformattedDevice(ctx context.Context, _ string) error {
42+
Logc(ctx).Debug(">>>> devices_darwin.formatUnformattedDevice")
43+
defer Logc(ctx).Debug("<<<< devices_darwin.formatUnformattedDevice")
44+
return errors.UnsupportedError("formatUnformattedDevice is not supported for darwin")
4545
}
4646

4747
// Open makes the device accessible on the host
@@ -51,10 +51,10 @@ func (d *LUKSDevice) Open(ctx context.Context, luksPassphrase string) error {
5151
return errors.UnsupportedError("Open is not supported for darwin")
5252
}
5353

54-
func GetUnderlyingDevicePathForLUKSDevice(ctx context.Context, command exec.Command, luksDevicePath string) (string, error) {
55-
Logc(ctx).Debug(">>>> devices_darwin.GetUnderlyingDevicePathForLUKSDevice")
56-
defer Logc(ctx).Debug("<<<< devices_darwin.GetUnderlyingDevicePathForLUKSDevice")
57-
return "", errors.UnsupportedError("GetUnderlyingDevicePathForLUKSDevice is not supported for darwin")
54+
func GetUnderlyingDevicePathForDevice(ctx context.Context, command exec.Command, luksDevicePath string) (string, error) {
55+
Logc(ctx).Debug(">>>> devices_darwin.GetUnderlyingDevicePathForDevice")
56+
defer Logc(ctx).Debug("<<<< devices_darwin.GetUnderlyingDevicePathForDevice")
57+
return "", errors.UnsupportedError("GetUnderlyingDevicePathForDevice is not supported for darwin")
5858
}
5959

6060
// Resize performs a luksResize on the LUKS device

0 commit comments

Comments
 (0)