@@ -1037,3 +1037,60 @@ func CheckReplicaComparisonPossible(volUuid string, volName string, volType comm
1037
1037
1038
1038
return err
1039
1039
}
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