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 3aea492 commit 9db0036
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
27 changes: 27 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,23 @@ 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 {
nvmeSubstem := NvmeSubsystem{
Paths: map[string]NvmeDevicePath{},
}
for pathName, path := range obj.NvmeSubsystem.Paths {
nvmeSubstem.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 +112,7 @@ func RPCToInstanceStatus(obj *rpc.InstanceStatus) InstanceStatus {
TargetPortEnd: obj.TargetPortEnd,
StandbyTargetPortStart: obj.StandbyTargetPortStart,
StandbyTargetPortEnd: obj.StandbyTargetPortEnd,
NvmeSubsystem: nvmeSubstem,
}
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,21 @@ 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: path.State,
}

logrus.Infof("Debug =====> pathName: %v, path: %v", pathName, path)
}

return &rpc.InstanceResponse{
Spec: &rpc.InstanceSpec{
Name: e.Name,
Expand All @@ -729,6 +744,7 @@ func engineResponseToInstanceResponse(e *spdkapi.Engine) *rpc.InstanceResponse {
StandbyTargetPortStart: e.StandbyTargetPort,
StandbyTargetPortEnd: e.StandbyTargetPort,
Conditions: make(map[string]bool),
NvmeSubsystem: nvmeSubsystem,
},
}
}
Expand Down

0 comments on commit 9db0036

Please sign in to comment.