nvme

package
v0.0.0-...-58f6e79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NVME_PATH = "/sys/class/nvme-subsystem"
	SUBSYSNQN = "/subsysnqn"
)
View Source
const MaxSessionsPerSubsystem = 2

MaxSessionsPerSubsystem represents the total number of paths from host to ONTAP subsystem. NVMe subsystem can have maximum 2 dataLIFs, so it is capped to 2.

View Source
const NVMeAttachTimeout = 20 * time.Second
View Source
const NVMeListCmdTimeoutInSeconds = 10

NVMeListCmdTimeoutInSeconds is the default timeout supplied to NVMe cli command.

View Source
const TransportAddressEqualTo = "traddr="

TransportAddressEqualTo is a part of Path.Address string. It is used to extract IP address.

Variables

This section is empty.

Functions

func SortSubsystemsUsingSessions

func SortSubsystemsUsingSessions(subs []NVMeSubsystem, pubSessions *NVMeSessions)

SortSubsystemsUsingSessions sorts the subsystems in accordance to the LastAccessTime present in the NVMeSessionData.

Types

type NVMeDevice

type NVMeDevice struct {
	Device        string `json:"Device"`
	NamespacePath string `json:"Namespace_Path"`
	NSID          int    `json:"NSID"`
	UUID          string `json:"UUID"`
	Size          string `json:"Size"`
	NamespaceSize int64  `json:"Namespace_Size"`
	// contains filtered or unexported fields
}

NVMeDevice represents the NVMe device structure present in the cli json output of `nvme netapp ontapdevices`

 "ONTAPdevices":[
  {
    "Device":"/dev/nvme0n1",
    "Vserver":"nvme_svm0",
    "Namespace_Path":"/vol/trident_pvc_402e841e_d6ca_424e_be0b_07d412bf7fdf/namespace0",
    "NSID":1,
    "UUID":"1055d699-7f4f-4195-a573-5a433b8eb4bc",
    "Size":"31.46MB",
    "LBA_Data_Size":4096,
    "Namespace_Size":7680
  }
]

func (*NVMeDevice) FlushDevice

func (d *NVMeDevice) FlushDevice(ctx context.Context, ignoreErrors, force bool) error

FlushDevice flushes any ongoing IOs on the device.

func (*NVMeDevice) FlushNVMeDevice

func (d *NVMeDevice) FlushNVMeDevice(ctx context.Context) error

FlushNVMeDevice flushes any ongoing IOs present on the NVMe device.

func (*NVMeDevice) GetPath

func (d *NVMeDevice) GetPath() string

GetPath returns the device path where we mount the filesystem in NodePublish.

func (*NVMeDevice) IsNil

func (d *NVMeDevice) IsNil() bool

IsNil returns true if Device and NamespacePath are not set.

type NVMeDeviceInterface

type NVMeDeviceInterface interface {
	GetPath() string
	FlushDevice(ctx context.Context, ignoreErrors, force bool) error
	IsNil() bool
	FlushNVMeDevice(ctx context.Context) error
}

type NVMeDevices

type NVMeDevices struct {
	Devices []NVMeDevice `json:"ONTAPdevices"`
}

type NVMeHandler

type NVMeHandler struct {
	// contains filtered or unexported fields
}

NVMeHandler implements the NVMeInterface. It acts as a layer to invoke all the NVMe related operations on the k8s node. This struct is currently empty as we don't need to store any node or NVMe related information yet.

func NewNVMeHandlerDetailed

func NewNVMeHandlerDetailed(command exec.Command, devicesClient devices.Devices,
	mountClient mount.Mount, fsClient filesystem.Filesystem, osFs afero.Fs,
) *NVMeHandler

func (*NVMeHandler) AddPublishedNVMeSession

func (nh *NVMeHandler) AddPublishedNVMeSession(pubSessions *NVMeSessions, publishInfo *models.VolumePublishInfo)

AddPublishedNVMeSession adds the published NVMeSession to the given session map.

func (*NVMeHandler) AttachNVMeVolume

func (nh *NVMeHandler) AttachNVMeVolume(
	ctx context.Context, name, mountpoint string, publishInfo *models.VolumePublishInfo, secrets map[string]string,
) error

func (*NVMeHandler) AttachNVMeVolumeRetry

func (nh *NVMeHandler) AttachNVMeVolumeRetry(
	ctx context.Context, name, mountpoint string, publishInfo *models.VolumePublishInfo, secrets map[string]string,
	timeout time.Duration,
) error

func (*NVMeHandler) GetHostNqn

func (nh *NVMeHandler) GetHostNqn(ctx context.Context) (string, error)

GetHostNqn returns the Nqn string of the k8s node.

func (*NVMeHandler) GetNVMeDeviceList

func (nh *NVMeHandler) GetNVMeDeviceList(ctx context.Context) (NVMeDevices, error)

GetNVMeDeviceList returns the list of NVMe devices present on the k8s node.

func (*NVMeHandler) GetNVMeSubsystem

func (nh *NVMeHandler) GetNVMeSubsystem(ctx context.Context, nqn string) (*NVMeSubsystem, error)

func (*NVMeHandler) InspectNVMeSessions

func (nh *NVMeHandler) InspectNVMeSessions(
	ctx context.Context, pubSessions, currSessions *NVMeSessions,
) []NVMeSubsystem

InspectNVMeSessions compares and checks if the current sessions are in-line with the published sessions. If any subsystem is missing any path in the current session (as compared with the published session), then it is added in the subsToFix array for healing.

func (*NVMeHandler) NVMeActiveOnHost

func (nh *NVMeHandler) NVMeActiveOnHost(ctx context.Context) (bool, error)

func (*NVMeHandler) NVMeMountVolume

func (nh *NVMeHandler) NVMeMountVolume(
	ctx context.Context, name, mountpoint string, publishInfo *models.VolumePublishInfo, secrets map[string]string,
) error

func (*NVMeHandler) NewNVMeSubsystem

func (nh *NVMeHandler) NewNVMeSubsystem(ctx context.Context, subsNqn string) NVMeSubsystemInterface

NewNVMeSubsystem returns NVMe subsystem object. Even if a subsystem is not connected to the k8s node, this function returns a minimal NVMe subsystem object.

func (*NVMeHandler) PopulateCurrentNVMeSessions

func (nh *NVMeHandler) PopulateCurrentNVMeSessions(ctx context.Context, currSessions *NVMeSessions) error

PopulateCurrentNVMeSessions populates the given session map with the current session present on the k8s node. This is done by listing the existing NVMe namespaces using the nvme cli command.

func (*NVMeHandler) RectifyNVMeSession

func (nh *NVMeHandler) RectifyNVMeSession(
	ctx context.Context, subsystemToFix NVMeSubsystem, pubSessions *NVMeSessions,
)

RectifyNVMeSession applies the required remediation on the subsystemToFix to make it working again.

func (*NVMeHandler) RemovePublishedNVMeSession

func (nh *NVMeHandler) RemovePublishedNVMeSession(pubSessions *NVMeSessions, subNQN, nsUUID string) bool

RemovePublishedNVMeSession deletes the namespace from the published NVMeSession. If the number of namespaces associated with a session comes down to 0, we delete that session and send a disconnect signal for that subsystem.

type NVMeInterface

type NVMeInterface interface {
	NVMeActiveOnHost(ctx context.Context) (bool, error)
	GetHostNqn(ctx context.Context) (string, error)
	NewNVMeSubsystem(ctx context.Context, subsNqn string) NVMeSubsystemInterface
	AddPublishedNVMeSession(pubSessions *NVMeSessions, publishInfo *models.VolumePublishInfo)
	RemovePublishedNVMeSession(pubSessions *NVMeSessions, subNQN, nsUUID string) bool
	PopulateCurrentNVMeSessions(ctx context.Context, currSessions *NVMeSessions) error
	InspectNVMeSessions(ctx context.Context, pubSessions, currSessions *NVMeSessions) []NVMeSubsystem
	RectifyNVMeSession(ctx context.Context, subsystemToFix NVMeSubsystem, pubSessions *NVMeSessions)
	NVMeMountVolume(
		ctx context.Context, name, mountpoint string, publishInfo *models.VolumePublishInfo, secrets map[string]string,
	) error
	AttachNVMeVolume(
		ctx context.Context, name, mountpoint string, publishInfo *models.VolumePublishInfo, secrets map[string]string,
	) error
	AttachNVMeVolumeRetry(
		ctx context.Context, name, mountpoint string, publishInfo *models.VolumePublishInfo, secrets map[string]string,
		timeout time.Duration,
	) error
	GetNVMeDeviceList(ctx context.Context) (NVMeDevices, error)
	GetNVMeSubsystem(ctx context.Context, nqn string) (*NVMeSubsystem, error)
}

func NewNVMeHandler

func NewNVMeHandler() NVMeInterface

NewNVMeHandler returns the interface to handle NVMe related utils operations.

type NVMeOperation

type NVMeOperation int8

NVMeOperation is a data structure for NVMe self-healing operations.

const (
	NoOp NVMeOperation = iota
	ConnectOp
)

type NVMeSessionData

type NVMeSessionData struct {
	Subsystem      NVMeSubsystem
	Namespaces     map[string]bool
	NVMeTargetIPs  []string
	LastAccessTime time.Time
	Remediation    NVMeOperation
}

NVMeSessionData contains all the information related to any NVMe session. It has the subsystem information, the corresponding backend target IPs (dataLIFs for ONTAP), last access time and remediation. Last access time is used in self-healing so that newer sessions will get prioritised. In the future, we can add DH-HMAC-CHAP to this structure once we start supporting CHAP for NVMe. Also, if we realise at any point that we have a namespace missing use case to handle, we need to store that too in this structure.

func NewNVMeSessionData

func NewNVMeSessionData(subsystem NVMeSubsystem, targetIPs []string) *NVMeSessionData

NewNVMeSessionData returns NVMeSessionData object with the specified subsystem, targetIPs and default values.

func (*NVMeSessionData) AddTargetIP

func (sd *NVMeSessionData) AddTargetIP(ip string)

func (*NVMeSessionData) IsTargetIPPresent

func (sd *NVMeSessionData) IsTargetIPPresent(ip string) bool

func (*NVMeSessionData) SetRemediation

func (sd *NVMeSessionData) SetRemediation(op NVMeOperation)

SetRemediation updates the remediation value.

type NVMeSessions

type NVMeSessions struct {
	Info map[string]*NVMeSessionData
}

NVMeSessions is a map of subsystem NQN and NVMeSessionData used for tracking self-healing information.

func NewNVMeSessions

func NewNVMeSessions() *NVMeSessions

NewNVMeSessions initializes and returns empty NVMeSession object pointer.

func (*NVMeSessions) AddNVMeSession

func (s *NVMeSessions) AddNVMeSession(subsystem NVMeSubsystem, targetIPs []string)

AddNVMeSession adds a new NVMeSession to the session map.

func (*NVMeSessions) AddNamespaceToSession

func (s *NVMeSessions) AddNamespaceToSession(subNQN, nsUUID string) bool

AddNamespaceToSession adds the Namespace UUID to the list of Namespaces for session.

func (*NVMeSessions) CheckNVMeSessionExists

func (s *NVMeSessions) CheckNVMeSessionExists(subNQN string) bool

CheckNVMeSessionExists queries if a particular NVMeSession is present using the subsystem NQN.

func (*NVMeSessions) GetNamespaceCountForSession

func (s *NVMeSessions) GetNamespaceCountForSession(subNQN string) int

GetNamespaceCountForSession Gets the number of Namespaces associated with the given session.

func (*NVMeSessions) IsEmpty

func (s *NVMeSessions) IsEmpty() bool

IsEmpty checks if the subsystem map is empty.

func (*NVMeSessions) RemoveNVMeSession

func (s *NVMeSessions) RemoveNVMeSession(subNQN string)

RemoveNVMeSession deletes NVMeSession corresponding to a given subsystem NQN.

func (*NVMeSessions) RemoveNamespaceFromSession

func (s *NVMeSessions) RemoveNamespaceFromSession(subNQN, nsUUID string)

RemoveNamespaceFromSession Removes the Namespace UUID from the list of Namespaces for session.

func (*NVMeSessions) ResetRemediationForAll

func (s *NVMeSessions) ResetRemediationForAll()

ResetRemediationForAll updates the remediation for all the NVMeSessions to NoOp.

type NVMeSubsystem

type NVMeSubsystem struct {
	Name  string `json:"Name"`
	NQN   string `json:"NQN"`
	Paths []Path `json:"Paths"`
	// contains filtered or unexported fields
}

NVMeSubsystem represents the NVMe subsystem structure present in the cli json output of `nvme list-subsys`. Paths represent all the sessions present for that subsystem. "Subsystems":[

  {
    "Name":"nvme-subsys0",
    "NQN":"nqn.1992-08.com.netapp:sn.d65e8c1addb211ed9257005056b32ae5:subsystem.scspa2826047001-02d067a5-a376-4cc1-bcd7-093ed58afe70",
    "Paths":[
      {
        "Name":"nvme0",
        "Transport":"tcp",
        "Address":"traddr=10.193.96.225,trsvcid=4420",
        "State":"live"
      },
      {
        "Name":"nvme1",
        "Transport":"tcp",
        "Address":"traddr=10.193.96.226,trsvcid=4420",
        "State":"live"
      }
    ]
  }
]

func NewNVMeSubsystem

func NewNVMeSubsystem(nqn string, command exec.Command, fs afero.Fs) *NVMeSubsystem

func NewNVMeSubsystemDetailed

func NewNVMeSubsystemDetailed(nqn, name string, paths []Path, command exec.Command,
	osFs afero.Fs,
) *NVMeSubsystem

func (*NVMeSubsystem) Connect

func (s *NVMeSubsystem) Connect(ctx context.Context, nvmeTargetIps []string, connectOnly bool) error

Connect creates paths corresponding to all the targetIPs for the subsystem and updates the in-memory subsystem path details.

func (*NVMeSubsystem) ConnectSubsystemToHost

func (s *NVMeSubsystem) ConnectSubsystemToHost(ctx context.Context, IP string) error

ConnectSubsystemToHost creates a path (or session) from the subsystem to the k8s node for the provided IP.

func (*NVMeSubsystem) Disconnect

func (s *NVMeSubsystem) Disconnect(ctx context.Context) error

Disconnect removes the subsystem and its corresponding paths/sessions from the k8s node.

func (*NVMeSubsystem) DisconnectSubsystemFromHost

func (s *NVMeSubsystem) DisconnectSubsystemFromHost(ctx context.Context) error

DisconnectSubsystemFromHost removes the subsystem from the k8s node.

func (*NVMeSubsystem) GetConnectionStatus

func (s *NVMeSubsystem) GetConnectionStatus() NVMeSubsystemConnectionStatus

GetConnectionStatus checks if subsystem is connected to the k8s node.

func (*NVMeSubsystem) GetNVMeDevice

func (s *NVMeSubsystem) GetNVMeDevice(ctx context.Context, nsUUID string) (NVMeDeviceInterface, error)

func (*NVMeSubsystem) GetNVMeDeviceAt

func (s *NVMeSubsystem) GetNVMeDeviceAt(ctx context.Context, nsUUID string) (NVMeDeviceInterface, error)

func (*NVMeSubsystem) GetNVMeDeviceCountAt

func (s *NVMeSubsystem) GetNVMeDeviceCountAt(ctx context.Context, path string) (int, error)

func (*NVMeSubsystem) GetNamespaceCount

func (s *NVMeSubsystem) GetNamespaceCount(ctx context.Context) (int, error)

GetNamespaceCount returns the number of namespaces mapped to the subsystem.

func (*NVMeSubsystem) GetNamespaceCountForSubsDevice

func (s *NVMeSubsystem) GetNamespaceCountForSubsDevice(ctx context.Context) (int, error)

GetNamespaceCountForSubsDevice returns the number of namespaces present in a given subsystem device.

func (*NVMeSubsystem) IsNetworkPathPresent

func (s *NVMeSubsystem) IsNetworkPathPresent(ip string) bool

IsNetworkPathPresent checks if there is a path present in the subsystem corresponding to the LIF.

type NVMeSubsystemConnectionStatus

type NVMeSubsystemConnectionStatus int8

NVMeSubsystemConnectionStatus is a data structure which reflects NVMe subsystem connection status.

const (
	NVMeSubsystemConnected NVMeSubsystemConnectionStatus = iota
	NVMeSubsystemDisconnected
	NVMeSubsystemPartiallyConnected
)

NVMe subsystem connection states

type NVMeSubsystemInterface

type NVMeSubsystemInterface interface {
	GetConnectionStatus() NVMeSubsystemConnectionStatus
	Connect(ctx context.Context, nvmeTargetIps []string, connectOnly bool) error
	Disconnect(ctx context.Context) error
	GetNamespaceCount(ctx context.Context) (int, error)
	IsNetworkPathPresent(ip string) bool
	ConnectSubsystemToHost(ctx context.Context, IP string) error
	DisconnectSubsystemFromHost(ctx context.Context) error
	GetNamespaceCountForSubsDevice(ctx context.Context) (int, error)
	GetNVMeDevice(ctx context.Context, nsUUID string) (NVMeDeviceInterface, error)
	GetNVMeDeviceAt(ctx context.Context, nsUUID string) (NVMeDeviceInterface, error)
	GetNVMeDeviceCountAt(ctx context.Context, path string) (int, error)
}

type Path

type Path struct {
	Name      string `json:"Name"`
	Transport string `json:"Transport"`
	Address   string `json:"Address"`
	State     string `json:"State"`
}

func GetNVMeSubsystemPaths

func GetNVMeSubsystemPaths(ctx context.Context, fs afero.Fs, subsystemDirPath string) ([]Path, error)

type Subsystems

type Subsystems struct {
	Subsystems []NVMeSubsystem `json:"Subsystems"`
}

func GetNVMeSubsystemList

func GetNVMeSubsystemList(ctx context.Context, command exec.Command) (Subsystems, error)

GetNVMeSubsystemList returns the list of subsystems connected to the k8s node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL