From 60c7419d9fc45e428046fb35966f3489c2f5ea0f Mon Sep 17 00:00:00 2001 From: Derek Su Date: Tue, 26 Nov 2024 20:55:56 +0800 Subject: [PATCH] WIP Signed-off-by: Derek Su --- pkg/api/types.go | 27 +++++++++++++++++++ pkg/spdk/engine.go | 27 +++++++++++++++++++ .../go-spdk-helper/pkg/nvme/initiator.go | 15 ++++++----- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index 1f600307..3021c72e 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -40,6 +40,18 @@ type Lvol struct { SnapshotTimestamp string `json:"snapshot_timestamp"` } +type NvmeDevicePath struct { + Trtype string `json:"trtype"` + Traddr string `json:"traddr"` + Trsvcid string `json:"trsvcid"` + SrcAddr string `json:"src_addr"` + State string `json:"state"` +} + +type NvmeSubsystem struct { + Paths map[string]*NvmeDevicePath `json:"paths"` +} + func ProtoLvolToLvol(l *spdkrpc.Lvol) *Lvol { if l == nil { return nil @@ -138,9 +150,23 @@ type Engine struct { Endpoint string `json:"endpoint"` State string `json:"state"` ErrorMsg string `json:"error_msg"` + NvmeSubsystem NvmeSubsystem `json:"nvme_subsystem"` } func ProtoEngineToEngine(e *spdkrpc.Engine) *Engine { + nvme := NvmeSubsystem{ + Paths: map[string]*NvmeDevicePath{}, + } + for pathName, path := range e.NvmeSubsystem.Paths { + nvme.Paths[pathName] = &NvmeDevicePath{ + Trtype: path.Trtype, + Traddr: path.Traddr, + Trsvcid: path.Trsvcid, + SrcAddr: path.SrcAddr, + State: path.State, + } + } + res := &Engine{ Name: e.Name, VolumeName: e.VolumeName, @@ -159,6 +185,7 @@ func ProtoEngineToEngine(e *spdkrpc.Engine) *Engine { Endpoint: e.Endpoint, State: e.State, ErrorMsg: e.ErrorMsg, + NvmeSubsystem: nvme, } for rName, mode := range e.ReplicaModeMap { res.ReplicaModeMap[rName] = types.GRPCReplicaModeToReplicaMode(mode) diff --git a/pkg/spdk/engine.go b/pkg/spdk/engine.go index 5815273c..e614b793 100644 --- a/pkg/spdk/engine.go +++ b/pkg/spdk/engine.go @@ -47,6 +47,7 @@ type Engine struct { Endpoint string Nqn string Nguid string + NvmeSubsystem api.NvmeSubsystem ReplicaStatusMap map[string]*EngineReplicaStatus @@ -99,6 +100,10 @@ func NewEngine(engineName, volumeName, frontend string, specSize uint64, engineU SnapshotMap: map[string]*api.Lvol{}, + NvmeSubsystem: api.NvmeSubsystem{ + Paths: map[string]*api.NvmeDevicePath{}, + }, + UpdateCh: engineUpdateCh, log: log, @@ -613,6 +618,19 @@ func (e *Engine) Get() (res *spdkrpc.Engine) { } func (e *Engine) getWithoutLock() (res *spdkrpc.Engine) { + nvmeSubsystem := &spdkrpc.NvmeSubsystem{ + Paths: map[string]*spdkrpc.NvmeDevicePath{}, + } + for pathName, path := range e.NvmeSubsystem.Paths { + nvmeSubsystem.Paths[pathName] = &spdkrpc.NvmeDevicePath{ + Trtype: path.Trtype, + Traddr: path.Traddr, + Trsvcid: path.Trsvcid, + SrcAddr: path.SrcAddr, + State: path.State, + } + } + res = &spdkrpc.Engine{ Name: e.Name, SpecSize: e.SpecSize, @@ -629,6 +647,7 @@ func (e *Engine) getWithoutLock() (res *spdkrpc.Engine) { Endpoint: e.Endpoint, State: string(e.State), ErrorMsg: e.ErrorMsg, + NvmeSubsystem: nvmeSubsystem, } for replicaName, replicaStatus := range e.ReplicaStatusMap { @@ -935,6 +954,14 @@ func (e *Engine) validateAndUpdateFrontend(subsystemMap map[string]*spdktypes.Nv } return err } + + e.NvmeSubsystem.Paths[e.initiator.ControllerName] = &api.NvmeDevicePath{ + Trtype: string(spdktypes.NvmeTransportTypeTCP), + Traddr: e.initiator.TransportAddress, + Trsvcid: e.initiator.TransportServiceID, + State: e.initiator.ControllerState, + } + if err := e.initiator.LoadEndpoint(e.dmDeviceBusy); err != nil { return err } diff --git a/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go b/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go index e9fdac98..a899a4ac 100644 --- a/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go +++ b/vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go @@ -39,11 +39,12 @@ type Initiator struct { TransportAddress string TransportServiceID string - Endpoint string - ControllerName string - NamespaceName string - dev *util.LonghornBlockDevice - isUp bool + Endpoint string + ControllerName string + ControllerState string + NamespaceName string + dev *util.LonghornBlockDevice + isUp bool hostProc string executor *commonns.Executor @@ -467,11 +468,13 @@ func (i *Initiator) loadNVMeDeviceInfoWithoutLock(transportAddress, transportSer if i.ControllerName != "" && i.ControllerName != nvmeDevices[0].Controllers[0].Controller { return fmt.Errorf("found mismatching between the detected controller name %s and the recorded value %s for NVMe initiator %s", nvmeDevices[0].Controllers[0].Controller, i.ControllerName, i.Name) } - i.ControllerName = nvmeDevices[0].Controllers[0].Controller i.NamespaceName = nvmeDevices[0].Namespaces[0].NameSpace + i.ControllerName = nvmeDevices[0].Controllers[0].Controller + i.ControllerState = nvmeDevices[0].Controllers[0].State i.TransportAddress, i.TransportServiceID = GetIPAndPortFromControllerAddress(nvmeDevices[0].Controllers[0].Address) i.logger.WithFields(logrus.Fields{ "controllerName": i.ControllerName, + "controllerState": i.ControllerState, "namespaceName": i.NamespaceName, "transportAddress": i.TransportAddress, "transportServiceID": i.TransportServiceID,