Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions internal/nvmeof/nodeserver/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ type NodeServer struct {

// ConnectionInfo holds NVMe-oF connection details.
type NvmeConnectionInfo struct {
SubsystemNQN string `json:"subsystemNQN"`
NamespaceID uint32 `json:"namespaceID"`
NamespaceUUID string `json:"namespaceUUID"`
Listeners []nvmeof.GatewayAddress `json:"listeners"`
HostNQN string `json:"hostNQN,omitempty"`
Transport string `json:"transport"`
SubsystemNQN string `json:"subsystemNQN"`
NamespaceID uint32 `json:"namespaceID"`
NamespaceUUID string `json:"namespaceUUID"`
Listeners []nvmeof.ListenerDetails `json:"listeners"`
HostNQN string `json:"hostNQN,omitempty"`
Transport string `json:"transport"`
}

// stageTransaction struct represents the state a transaction was when it either completed
Expand Down Expand Up @@ -566,7 +566,7 @@ func (ns *NodeServer) getNvmeConnection(volumeContext, publishContext map[string
return nil, errors.New("missing listeners in volume context")
}

var listeners []nvmeof.GatewayAddress
var listeners []nvmeof.ListenerDetails
if err := json.Unmarshal([]byte(listenersJSON), &listeners); err != nil {
return nil, fmt.Errorf("failed to parse listeners JSON: %w", err)
}
Expand Down
26 changes: 21 additions & 5 deletions internal/nvmeof/nvmeof_initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -58,7 +59,7 @@ type NVMeInitiator interface {
// ConnectRequest represents a subsystem connection request.
type ConnectRequest struct {
SubsystemNQN string
Listeners []GatewayAddress
Listeners []ListenerDetails
Transport string // "tcp"
HostNQN string // Optional - empty means use system default
}
Expand Down Expand Up @@ -154,29 +155,44 @@ func (ni *nvmeInitiator) ConnectSubsystem(ctx context.Context, req *ConnectReque
// Try connecting to each address until one succeeds
var success bool
for _, listener := range req.Listeners {
// resolve the IP-address of the listener, .Address can be set to 0.0.0.0
addrs, err := net.LookupHost(listener.Hostname)
if err != nil {
log.WarningLog(ctx, "Failed to resolve %q: %v", listener.Hostname, err)

continue
}
if len(addrs) == 0 {
log.WarningLog(ctx, "Resolving %q returned 0 IP-addresses", listener.Hostname)

continue
}

ip := addrs[0]

portStr := strconv.FormatUint(uint64(listener.Port), 10)

// Check if already connected to this specific gateway
if req.HostNQN != "" && existingConnections != nil {
if existingConnections.hasPathToGateway(
req.SubsystemNQN, req.HostNQN, listener.Address, portStr) {
req.SubsystemNQN, req.HostNQN, ip, portStr) {
log.DebugLog(ctx, "Already connected to subsystem %s via %s:%s with HostNQN %s",
req.SubsystemNQN, listener.Address, portStr, req.HostNQN)
req.SubsystemNQN, ip, portStr, req.HostNQN)
success = true

continue
}
}

log.DebugLog(ctx, "Connecting to NVMe-oF subsystem %s at %v:%s",
req.SubsystemNQN, listener.Address, portStr)
req.SubsystemNQN, ip, portStr)

// Build nvme connect command for this address
args := []string{
"connect",
"-t", req.Transport,
"-n", req.SubsystemNQN,
"-a", listener.Address,
"-a", ip,
"-s", portStr,
"-l", nvmeCtrlLossTmo,
}
Expand Down