Skip to content

Commit

Permalink
refactor: add returned error to NvmeTransport
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun authored and glimchb committed Sep 25, 2023
1 parent ffc9fca commit 0a1f926
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// NvmeTransport interface is used to provide SPDK call params to create/delete
// Nvme controllers depending on used transport type.
type NvmeTransport interface {
Params(ctrlr *pb.NvmeController, nqn string) spdk.NvmfSubsystemAddListenerParams
Params(ctrlr *pb.NvmeController, nqn string) (spdk.NvmfSubsystemAddListenerParams, error)
}

// NvmeParameters contains all Nvme related structures
Expand Down
22 changes: 16 additions & 6 deletions pkg/frontend/nvme_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewNvmeTCPTransport(listenAddr string) NvmeTransport {
}
}

func (c *nvmeTCPTransport) Params(_ *pb.NvmeController, nqn string) spdk.NvmfSubsystemAddListenerParams {
func (c *nvmeTCPTransport) Params(_ *pb.NvmeController, nqn string) (spdk.NvmfSubsystemAddListenerParams, error) {
result := spdk.NvmfSubsystemAddListenerParams{}
result.Nqn = nqn
result.SecureChannel = false
Expand All @@ -84,7 +84,7 @@ func (c *nvmeTCPTransport) Params(_ *pb.NvmeController, nqn string) spdk.NvmfSub
result.ListenAddress.Trsvcid = c.listenPort
result.ListenAddress.Adrfam = c.protocol

return result
return result, nil
}

// CreateNvmeController creates an Nvme controller
Expand Down Expand Up @@ -116,9 +116,14 @@ func (s *Server) CreateNvmeController(_ context.Context, in *pb.CreateNvmeContro
return nil, err
}

params := s.Nvme.transport.Params(in.NvmeController, subsys.Spec.Nqn)
params, err := s.Nvme.transport.Params(in.NvmeController, subsys.Spec.Nqn)
if err != nil {
log.Printf("error: failed to create params for spdk call: %v", err)
return nil, status.Error(codes.InvalidArgument, err.Error())
}

var result spdk.NvmfSubsystemAddListenerResult
err := s.rpc.Call("nvmf_subsystem_add_listener", &params, &result)
err = s.rpc.Call("nvmf_subsystem_add_listener", &params, &result)
if err != nil {
log.Printf("error: %v", err)
return nil, err
Expand Down Expand Up @@ -163,9 +168,14 @@ func (s *Server) DeleteNvmeController(_ context.Context, in *pb.DeleteNvmeContro
return nil, err
}

params := s.Nvme.transport.Params(controller, subsys.Spec.Nqn)
params, err := s.Nvme.transport.Params(controller, subsys.Spec.Nqn)
if err != nil {
log.Printf("error: failed to create params for spdk call: %v", err)
return nil, status.Error(codes.InvalidArgument, err.Error())
}

var result spdk.NvmfSubsystemAddListenerResult
err := s.rpc.Call("nvmf_subsystem_remove_listener", &params, &result)
err = s.rpc.Call("nvmf_subsystem_remove_listener", &params, &result)
if err != nil {
log.Printf("error: %v", err)
return nil, err
Expand Down
16 changes: 14 additions & 2 deletions pkg/kvm/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package kvm

import (
"context"
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -41,14 +42,25 @@ func NewNvmeVfiouserTransport(ctrlrDir string) frontend.NvmeTransport {
}
}

func (c *nvmeVfiouserTransport) Params(ctrlr *pb.NvmeController, nqn string) spdk.NvmfSubsystemAddListenerParams {
func (c *nvmeVfiouserTransport) Params(ctrlr *pb.NvmeController, nqn string) (spdk.NvmfSubsystemAddListenerParams, error) {
pcieID := ctrlr.Spec.PcieId
if pcieID.PortId.Value != 0 {
return spdk.NvmfSubsystemAddListenerParams{},
errors.New("only port 0 is supported for vfiouser")
}

if pcieID.VirtualFunction.Value != 0 {
return spdk.NvmfSubsystemAddListenerParams{},
errors.New("virtual functions are not supported for vfiouser")
}

result := spdk.NvmfSubsystemAddListenerParams{}
ctrlrDirPath := controllerDirPath(c.ctrlrDir, frontend.GetSubsystemIDFromNvmeName(ctrlr.Name))
result.Nqn = nqn
result.ListenAddress.Trtype = "vfiouser"
result.ListenAddress.Traddr = ctrlrDirPath

return result
return result, nil
}

// CreateNvmeController creates an Nvme controller device and attaches it to QEMU instance
Expand Down

0 comments on commit 0a1f926

Please sign in to comment.