Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Nov 26, 2024
1 parent 6e07df9 commit 60c7419
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
27 changes: 27 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions pkg/spdk/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Engine struct {
Endpoint string
Nqn string
Nguid string
NvmeSubsystem api.NvmeSubsystem

ReplicaStatusMap map[string]*EngineReplicaStatus

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 9 additions & 6 deletions vendor/github.com/longhorn/go-spdk-helper/pkg/nvme/initiator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 60c7419

Please sign in to comment.