Skip to content

Commit

Permalink
feat(v2 upgrade): expose NVMe subsystem status
Browse files Browse the repository at this point in the history
Longhorn 9104

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Nov 27, 2024
1 parent 688c702 commit 5977643
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
29 changes: 29 additions & 0 deletions pkg/api/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ func RPCToInstanceList(obj *rpc.InstanceListResponse) map[string]*Instance {
return ret
}

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"`
}

type InstanceStatus struct {
State string `json:"state"`
ErrorMsg string `json:"errorMsg"`
Expand All @@ -73,9 +85,25 @@ type InstanceStatus struct {
TargetPortEnd int32 `json:"targetPortEnd"`
StandbyTargetPortStart int32 `json:"standbyTargetPortStart"`
StandbyTargetPortEnd int32 `json:"standbyTargetPortEnd"`
NvmeSubsystem NvmeSubsystem `json:"nvmeSubsystem"`
}

func RPCToInstanceStatus(obj *rpc.InstanceStatus) InstanceStatus {
nvmeSubsystem := NvmeSubsystem{
Paths: map[string]NvmeDevicePath{},
}
if obj.NvmeSubsystem != nil {
for pathName, path := range obj.NvmeSubsystem.Paths {
nvmeSubsystem.Paths[pathName] = NvmeDevicePath{
Trtype: path.Trtype,
Traddr: path.Traddr,
Trsvcid: path.Trsvcid,
SrcAddr: path.SrcAddr,
State: path.State,
}
}
}

return InstanceStatus{
State: obj.State,
ErrorMsg: obj.ErrorMsg,
Expand All @@ -86,6 +114,7 @@ func RPCToInstanceStatus(obj *rpc.InstanceStatus) InstanceStatus {
TargetPortEnd: obj.TargetPortEnd,
StandbyTargetPortStart: obj.StandbyTargetPortStart,
StandbyTargetPortEnd: obj.StandbyTargetPortEnd,
NvmeSubsystem: nvmeSubsystem,
}
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,19 @@ func replicaResponseToInstanceResponse(r *spdkapi.Replica) *rpc.InstanceResponse
}

func engineResponseToInstanceResponse(e *spdkapi.Engine) *rpc.InstanceResponse {
nvmeSubsystem := &rpc.NvmeSubsystem{
Paths: make(map[string]*rpc.NvmeDevicePath),
}
for pathName, path := range e.NvmeSubsystem.Paths {
nvmeSubsystem.Paths[pathName] = &rpc.NvmeDevicePath{
Trtype: path.Trtype,
Traddr: path.Traddr,
Trsvcid: path.Trsvcid,
SrcAddr: path.SrcAddr,
State: string(path.State),
}
}

return &rpc.InstanceResponse{
Spec: &rpc.InstanceSpec{
Name: e.Name,
Expand All @@ -729,6 +742,7 @@ func engineResponseToInstanceResponse(e *spdkapi.Engine) *rpc.InstanceResponse {
StandbyTargetPortStart: e.StandbyTargetPort,
StandbyTargetPortEnd: e.StandbyTargetPort,
Conditions: make(map[string]bool),
NvmeSubsystem: nvmeSubsystem,
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/sirupsen/logrus"
"k8s.io/mount-utils"

spdkhelpertypes "github.com/longhorn/go-spdk-helper/pkg/types"
helpertypes "github.com/longhorn/go-spdk-helper/pkg/types"
)

const (
Expand Down Expand Up @@ -128,7 +128,7 @@ func ParsePortRange(portRange string) (int32, int32, error) {
// IsSPDKTgtReady checks if SPDK target is ready
func IsSPDKTgtReady(timeout time.Duration) bool {
for i := 0; i < int(timeout.Seconds()); i++ {
conn, err := net.DialTimeout(spdkhelpertypes.DefaultJSONServerNetwork, spdkhelpertypes.DefaultUnixDomainSocketPath, 1*time.Second)
conn, err := net.DialTimeout(helpertypes.DefaultJSONServerNetwork, helpertypes.DefaultUnixDomainSocketPath, 1*time.Second)
if err == nil {
conn.Close()
return true
Expand Down

0 comments on commit 5977643

Please sign in to comment.