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 59d33f4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ require (
)

replace github.com/longhorn/types v0.0.0-20241123075624-48c550af4eab => github.com/derekbit/longhorn-types v0.0.0-20241126114320-36b8b01a8cb5

replace github.com/longhorn/go-spdk-helper v0.0.0-20241124090314-c396ae715a7f => github.com/derekbit/go-spdk-helper v0.0.0-20241126133109-a064d2aacb00
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/derekbit/go-spdk-helper v0.0.0-20241126133109-a064d2aacb00 h1:y4hBPdgnj0bZbkN1NnjHVpIwdJ437og3ZLT0SZ4IOm8=
github.com/derekbit/go-spdk-helper v0.0.0-20241126133109-a064d2aacb00/go.mod h1:F4KxpqJXmghH0E3GH0XRSr7M0v5DROFEwaecPbhnGY4=
github.com/derekbit/longhorn-types v0.0.0-20241126114320-36b8b01a8cb5 h1:r7oV/k86j2XNfNOXvGrkUwjoZNT4EpeL67kUf46JgGc=
github.com/derekbit/longhorn-types v0.0.0-20241126114320-36b8b01a8cb5/go.mod h1:dIPa2yMBPOa514bn3pohT7kbVAQcZbZSWItpgxunuPs=
github.com/gammazero/deque v0.2.0 h1:SkieyNB4bg2/uZZLxvya0Pq6diUlwx7m2TeT7GAIWaA=
Expand Down Expand Up @@ -50,8 +52,6 @@ github.com/longhorn/backupstore v0.0.0-20241124092526-138305866a87 h1:Alpq8lFYom
github.com/longhorn/backupstore v0.0.0-20241124092526-138305866a87/go.mod h1:43jaLhUmWSpP2TekZslfLcFBqFTe07Eucgv7hRst5Pw=
github.com/longhorn/go-common-libs v0.0.0-20241124035508-d6221574e626 h1:6RHxLM2DLwr7FrDn6yyryEXwa7yN01fcZfIyllxmBss=
github.com/longhorn/go-common-libs v0.0.0-20241124035508-d6221574e626/go.mod h1:gSa+qB058kcNlCaOOwIFPHb3tvqMTmKcxtL7HPTS4o4=
github.com/longhorn/go-spdk-helper v0.0.0-20241124090314-c396ae715a7f h1:P/XoCIN6+4q05tCTRAsSsVLMC8c0NV31HCkn+6xKrsc=
github.com/longhorn/go-spdk-helper v0.0.0-20241124090314-c396ae715a7f/go.mod h1:F4KxpqJXmghH0E3GH0XRSr7M0v5DROFEwaecPbhnGY4=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
Expand Down
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{},
},

Check warning on line 106 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L103-L106

Added lines #L103 - L106 were not covered by tests
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,
}
}

Check warning on line 632 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L621-L632

Added lines #L621 - L632 were not covered by tests

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,

Check warning on line 650 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L650

Added line #L650 was not covered by tests
}

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,
}

Check warning on line 964 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L958-L964

Added lines #L958 - L964 were not covered by tests
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.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ github.com/longhorn/go-common-libs/sync
github.com/longhorn/go-common-libs/sys
github.com/longhorn/go-common-libs/types
github.com/longhorn/go-common-libs/utils
# github.com/longhorn/go-spdk-helper v0.0.0-20241124090314-c396ae715a7f
# github.com/longhorn/go-spdk-helper v0.0.0-20241124090314-c396ae715a7f => github.com/derekbit/go-spdk-helper v0.0.0-20241126133109-a064d2aacb00
## explicit; go 1.22.7
github.com/longhorn/go-spdk-helper/pkg/jsonrpc
github.com/longhorn/go-spdk-helper/pkg/nvme
Expand Down

0 comments on commit 59d33f4

Please sign in to comment.