Skip to content

Commit

Permalink
refactor: move opiAdressFamilyToSpdk to utils
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 Oct 2, 2023
1 parent 970a567 commit c7cd781
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/backend/nvme_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *Server) CreateNvmePath(_ context.Context, in *pb.CreateNvmePathRequest)
Name: path.Base(controller.Name),
Trtype: s.opiTransportToSpdk(in.NvmePath.GetTrtype()),
Traddr: in.NvmePath.GetTraddr(),
Adrfam: s.opiAdressFamilyToSpdk(in.NvmePath.GetFabrics().GetAdrfam()),
Adrfam: utils.OpiAdressFamilyToSpdk(in.NvmePath.GetFabrics().GetAdrfam()),
Trsvcid: fmt.Sprint(in.NvmePath.GetFabrics().GetTrsvcid()),
Subnqn: in.NvmePath.GetFabrics().GetSubnqn(),
Hostnqn: in.NvmePath.GetFabrics().GetHostnqn(),
Expand Down Expand Up @@ -133,7 +133,7 @@ func (s *Server) DeleteNvmePath(_ context.Context, in *pb.DeleteNvmePathRequest)
Name: path.Base(controller.Name),
Trtype: s.opiTransportToSpdk(nvmePath.GetTrtype()),
Traddr: nvmePath.GetTraddr(),
Adrfam: s.opiAdressFamilyToSpdk(nvmePath.GetFabrics().GetAdrfam()),
Adrfam: utils.OpiAdressFamilyToSpdk(nvmePath.GetFabrics().GetAdrfam()),
Trsvcid: fmt.Sprint(nvmePath.GetFabrics().GetTrsvcid()),
Subnqn: nvmePath.GetFabrics().GetSubnqn(),
}
Expand Down Expand Up @@ -270,14 +270,6 @@ func (s *Server) opiTransportToSpdk(transport pb.NvmeTransportType) string {
return strings.ReplaceAll(transport.String(), "NVME_TRANSPORT_", "")
}

func (s *Server) opiAdressFamilyToSpdk(adrfam pb.NvmeAddressFamily) string {
if adrfam == pb.NvmeAddressFamily_NVME_ADDRESS_FAMILY_UNSPECIFIED {
return ""
}

return strings.ReplaceAll(adrfam.String(), "NVME_ADRFAM_", "")
}

func (s *Server) opiMultipathToSpdk(multipath pb.NvmeMultipath) string {
return strings.ToLower(
strings.ReplaceAll(multipath.String(), "NVME_MULTIPATH_", ""),
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"google.golang.org/grpc/status"

"github.com/opiproject/gospdk/spdk"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
)

// ExtractPagination is a helper function for List pagination to fetch PageSize and PageToken
Expand Down Expand Up @@ -145,3 +146,12 @@ func spdkMockServerCommunicate(rpc spdk.JSONRPC, l net.Listener, toSend []string
func ResourceIDToVolumeName(resourceID string) string {
return fmt.Sprintf("//storage.opiproject.org/volumes/%s", resourceID)
}

// OpiAdressFamilyToSpdk converts opi address family to the one used in spdk
func OpiAdressFamilyToSpdk(adrfam pb.NvmeAddressFamily) string {
if adrfam == pb.NvmeAddressFamily_NVME_ADDRESS_FAMILY_UNSPECIFIED {
return ""
}

return strings.ReplaceAll(adrfam.String(), "NVME_ADRFAM_", "")
}

0 comments on commit c7cd781

Please sign in to comment.