Skip to content

Commit 8946ab2

Browse files
committed
feat(rdma): verify volume connection protocol by checking volume live path in nvme sub system connection
Signed-off-by: rohan2794 <[email protected]>
1 parent 0be6af6 commit 8946ab2

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

common/k8stest/util_rdma.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import (
1212
logf "sigs.k8s.io/controller-runtime/pkg/log"
1313
)
1414

15-
const RdmaDeviceName = "rxe0"
15+
const (
16+
RdmaDeviceName = "rxe0"
17+
TcpProtocol = "tcp"
18+
RdmaProtocol = "rdma"
19+
)
1620

1721
type RdmaDeviceNetworkInterface struct {
1822
IfIndex int `json:"ifindex"`
@@ -369,3 +373,27 @@ func RestoreConfiguredDisabledRdmaDevicesOnAllMayastorNodes() error {
369373
}
370374
return nil
371375
}
376+
377+
// IsVolumeConnectedOverSpecifiedProtocol return true if volume is connected over specified protocol
378+
// by checking nvme list subsystem live path protocol for specified volume
379+
func IsVolumeConnectedOverSpecifiedProtocol(volUuid, initiatorNode, protocol string) (bool, error) {
380+
// get node IP
381+
nodeIp, err := GetNodeIPAddress(initiatorNode)
382+
if err != nil {
383+
return false, fmt.Errorf("failed to get node IP for node %s, error: %v", initiatorNode, err)
384+
} else if *nodeIp == "" {
385+
return false, fmt.Errorf("node IP for node %s not found", initiatorNode)
386+
}
387+
logf.Log.Info("Node IP", "node", initiatorNode, "IP", *nodeIp)
388+
389+
//volume should get connected over tcp
390+
logf.Log.Info("verify volume connection", "expected protocol", protocol)
391+
nvmeListSubsysProtocol, err := GetNvmeListSubsystemVolumeEntryLivePathProtocol(*nodeIp, volUuid)
392+
if err != nil {
393+
return false, fmt.Errorf("failed to get nvme list subsystem live path protocol for volume %s on node %s, error: %v", volUuid, initiatorNode, err)
394+
} else if nvmeListSubsysProtocol == "" {
395+
return false, fmt.Errorf("nvme list subsystem live path protocol for volume %s on node %s not found", volUuid, initiatorNode)
396+
}
397+
logf.Log.Info("Volume connection protocol", "volume", volUuid, "protocol", nvmeListSubsysProtocol)
398+
return true, nil
399+
}

common/k8stest/util_replica.go

+57
Original file line numberDiff line numberDiff line change
@@ -1037,3 +1037,60 @@ func CheckReplicaComparisonPossible(volUuid string, volName string, volType comm
10371037

10381038
return err
10391039
}
1040+
1041+
// GetNvmeListSubSys returns the list of nvme subsystems on the initiator node
1042+
func GetNvmeListSubSys(initiatorNodeIP string) (map[string][]nvmeListSubsystemEntry, error) {
1043+
subSysList := make(map[string][]nvmeListSubsystemEntry)
1044+
output, err := agent.NvmeListSubSys(initiatorNodeIP)
1045+
if output == "" || err != nil {
1046+
logf.Log.Info("nvme list-subsys failed", "output", output, "err", err)
1047+
return nil, err
1048+
} else {
1049+
output = trimForJson(output)
1050+
if err = json.Unmarshal([]byte(output), &subSysList); err != nil {
1051+
logf.Log.Info("Failed to unmarshal target", "error", err)
1052+
return nil, err
1053+
}
1054+
}
1055+
return subSysList, nil
1056+
}
1057+
1058+
// GetNvmeListSubsystemVolumeEntryLivePath returns the live path of the volume entry in the subsystem
1059+
func GetNvmeListSubsystemVolumeEntryLivePath(initiatorNodeIP string, volumeUuid string) (map[string]string, error) {
1060+
subSysPath := make(map[string]string)
1061+
subSysList, err := GetNvmeListSubSys(initiatorNodeIP)
1062+
if err != nil {
1063+
logf.Log.Info("nvme list-subsys failed", "err", err)
1064+
return subSysPath, err
1065+
}
1066+
for _, subSys := range subSysList["Subsystems"] {
1067+
if strings.Contains(subSys.NQN, volumeUuid) {
1068+
for _, path := range subSys.Paths {
1069+
if path["State"] == "live" {
1070+
subSysPath = path
1071+
break
1072+
}
1073+
}
1074+
}
1075+
}
1076+
return subSysPath, nil
1077+
}
1078+
1079+
// GetNvmeListSubsystemVolumeEntryLivePathProtocol returns the transport protocol of the volume entry in the subsystem
1080+
func GetNvmeListSubsystemVolumeEntryLivePathProtocol(initiatorNodeIP string, volumeUuid string) (string, error) {
1081+
subSysLivePath, err := GetNvmeListSubsystemVolumeEntryLivePath(initiatorNodeIP, volumeUuid)
1082+
if err != nil {
1083+
logf.Log.Info("failed to get live nvme sub sys path",
1084+
"initiatorNodeIP", initiatorNodeIP,
1085+
"volumeUuid", volumeUuid,
1086+
"err", err)
1087+
return "", err
1088+
}
1089+
logf.Log.Info("Volume sub system live path",
1090+
"volumeUuid", volumeUuid,
1091+
"subSysLivePath", subSysLivePath)
1092+
if subSysLivePath["Transport"] == "" {
1093+
return "", fmt.Errorf("failed to get live nvme sub sys path transport for volume %s with initiatorNodeIP %s", volumeUuid, initiatorNodeIP)
1094+
}
1095+
return subSysLivePath["Transport"], nil
1096+
}

0 commit comments

Comments
 (0)