Skip to content

Commit

Permalink
changing the max limit for subsystem name for NVMe to 64chars
Browse files Browse the repository at this point in the history
changing the max limit for subsystem name for NVMe to 64 chars
  • Loading branch information
bhatnag authored Feb 22, 2024
1 parent 6eaacaf commit 4d87533
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
23 changes: 19 additions & 4 deletions storage_drivers/ontap/ontap_san_nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
// defaultNamespaceBlockSize represents the default block size used to create a namespace.
defaultNamespaceBlockSize = 4096
// maximumSubsystemNameLength represent the max length of subsystem name
maximumSubsystemNameLength = 96
maximumSubsystemNameLength = 64
)

// Namespace attributes stored in its comment field. These fields are useful for docker context.
Expand Down Expand Up @@ -729,7 +729,10 @@ func (d *NVMeStorageDriver) Destroy(ctx context.Context, volConfig *storage.Volu
func (d *NVMeStorageDriver) Publish(
ctx context.Context, volConfig *storage.VolumeConfig, publishInfo *utils.VolumePublishInfo,
) error {
// InternalName is of the format <storagePrefix><pvc_UUID>
name := volConfig.InternalName
// volConfig.Name is same as <pvc-UUID>
pvName := volConfig.Name

fields := LogFields{
"method": "Publish",
Expand Down Expand Up @@ -789,7 +792,7 @@ func (d *NVMeStorageDriver) Publish(
// else we use the subsystem created for that particular node
var ssName string
if volConfig.FileSystem == tridentconfig.FsRaw {
ssName = getNamespaceSpecificSubsystemName(name)
ssName = getNamespaceSpecificSubsystemName(name, pvName)
} else {
ssName = getNodeSpecificSubsystemName(publishInfo.HostName, publishInfo.TridentUUID)
}
Expand Down Expand Up @@ -1531,8 +1534,20 @@ func getNodeSpecificSubsystemName(nodeName, tridentUUID string) string {
}

// getNamespaceSpecificSubsystemName constructs the subsystem name using the name passed.
func getNamespaceSpecificSubsystemName(name string) string {
return fmt.Sprintf("s_%v", name)
func getNamespaceSpecificSubsystemName(name, pvName string) string {
subSystemPrefix := "s"
// Check if the subsystem name length is greater than 64 chars.
// 2 is added to the length to account for "s_" in the subsystem name
if (len(name) + 2) > maximumSubsystemNameLength {
// Truncate the storagePrefix so that the entire subsystem doesn't exceed 64 chars
// The -2 at the end is done to account for two additional "_" in the subsystem name
truncatedStoragePrefixIndex := maximumSubsystemNameLength - len(subSystemPrefix) - len(pvName) - 2

storagePrefix := name[:truncatedStoragePrefixIndex]

return (fmt.Sprintf("%s_%s_%s", subSystemPrefix, storagePrefix, pvName))
}
return (fmt.Sprintf("%s_%s", subSystemPrefix, name))
}

// extractNamespaceName extracts the namespace name from the given string if nsStr is set
Expand Down
33 changes: 26 additions & 7 deletions storage_drivers/ontap/ontap_san_nvme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,16 +930,35 @@ func TestNVMeParseNVMeNamespaceCommentString(t *testing.T) {
}

func TestGetNamespaceSpecificSubsystemName(t *testing.T) {
name := "fakeName"
expected_name := "s_fakeName"
// case 1: subsystem name is shorter than 64 char
name := "fakeName_pvc_b0d71710-8bb3-4334-8621-fe3c211c5f02"
volName := "pvc-b0d71710-8bb3-4334-8621-fe3c211c5f02"
expected_name := "s_fakeName_pvc_b0d71710-8bb3-4334-8621-fe3c211c5f02"

got_name := getNamespaceSpecificSubsystemName(name)
got_name := getNamespaceSpecificSubsystemName(name, volName)

assert.Equal(t, got_name, expected_name)

// case 2: subsystem name is longer than 64 char
name = "fakeNodeNamefakeNodeNamefakeNodeNamefakeNodeName_pvc_b0d71710-8bb3-4334-8621-fe3c211c5f02"
volName = "pvc-b0d71710-8bb3-4334-8621-fe3c211c5f02"
expected_name = "s_fakeNodeNamefakeNodeN_pvc-b0d71710-8bb3-4334-8621-fe3c211c5f02"
got_name = getNamespaceSpecificSubsystemName(name, volName)

assert.Equal(t, got_name, expected_name)

// case 3: subsystem name is exactly 64 char
name = "fakeNodeNamefakeNodeN_pvc_b0d71710-8bb3-4334-8621-fe3c211c5f02"
volName = "pvc-b0d71710-8bb3-4334-8621-fe3c211c5f02"
expected_name = "s_fakeNodeNamefakeNodeN_pvc_b0d71710-8bb3-4334-8621-fe3c211c5f02"

got_name = getNamespaceSpecificSubsystemName(name, volName)

assert.Equal(t, got_name, expected_name)
}

func TestGetNodeSpecificSubsystemName(t *testing.T) {
// case 1: subsystem, name is shorter than 96 char
// case 1: subsystem, name is shorter than 64 char
nodeName := "fakeNodeName"
tridentUUID := "fakeUUID"
expected := "fakeNodeName-fakeUUID"
Expand All @@ -948,12 +967,12 @@ func TestGetNodeSpecificSubsystemName(t *testing.T) {

assert.Equal(t, got, expected)

// case 2: subsystem name is longer than 96 char
// case 2: subsystem name is longer than 64 char
nodeName = "fakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNodeName"

expected = "fakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefak-fakeUUID"
expected = "fakeNodeNamefakeNodeNamefakeNodeNamefakeNodeNamefakeNod-fakeUUID"

got = getNodeSpecificSubsystemName(nodeName, tridentUUID)

assert.Equal(t, got, expected)
}

Expand Down

0 comments on commit 4d87533

Please sign in to comment.