Skip to content

Commit

Permalink
fix: engine without frontend should not be failed due to missing NVMf…
Browse files Browse the repository at this point in the history
… subsystem

An engine without a frontend is not exposed and without a NVMf
subsystem, so no need to fail the engine in the
validateAndUpdateFrontend().

Longhorn 9965

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit authored and innobead committed Dec 12, 2024
1 parent efa03bf commit 776b2e0
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions pkg/spdk/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (e *Engine) handleFrontend(spdkClient *spdkclient.Client, superiorPortAlloc
}

if e.Frontend == types.FrontendEmpty {
e.log.Infof("No frontend specified, will not expose the volume %s", e.VolumeName)
e.log.Info("No frontend specified, will not expose bdev for engine")
return nil
}

Expand Down Expand Up @@ -926,22 +926,19 @@ func (e *Engine) checkAndUpdateInfoFromReplicaNoLock() {
}

func (e *Engine) validateAndUpdateFrontend(subsystemMap map[string]*spdktypes.NvmfSubsystem) (err error) {
if e.Frontend != types.FrontendEmpty &&
e.Frontend != types.FrontendSPDKTCPNvmf &&
e.Frontend != types.FrontendSPDKTCPBlockdev {
if !types.IsFrontendSupported(e.Frontend) {
return fmt.Errorf("unknown frontend type %s", e.Frontend)
}

nqn := helpertypes.GetNQN(e.Name)

subsystem, ok := subsystemMap[nqn]
if !ok {
return fmt.Errorf("cannot find the NVMf subsystem for engine %s", e.Name)
if e.Nqn == "" {
return fmt.Errorf("NQN is empty for engine %s", e.Name)
}

subsystem := subsystemMap[e.Nqn]

if e.Frontend == types.FrontendEmpty {
if subsystem != nil {
return fmt.Errorf("found NVMf subsystem %s for engine %s with empty frontend", nqn, e.Name)
return fmt.Errorf("found NVMf subsystem %s for engine %s with empty frontend", e.Nqn, e.Name)
}
if e.Endpoint != "" {
return fmt.Errorf("found non-empty endpoint %s for engine %s with empty frontend", e.Endpoint, e.Name)
Expand All @@ -952,10 +949,14 @@ func (e *Engine) validateAndUpdateFrontend(subsystemMap map[string]*spdktypes.Nv
return nil
}

if subsystem == nil || len(subsystem.ListenAddresses) == 0 {
if subsystem == nil {
return fmt.Errorf("cannot find the NVMf subsystem for engine %s", e.Name)
}

if len(subsystem.ListenAddresses) == 0 {
return fmt.Errorf("cannot find any listener for NVMf subsystem %s for engine %s", e.Nqn, e.Name)
}

port := 0
for _, listenAddr := range subsystem.ListenAddresses {
if !strings.EqualFold(string(listenAddr.Adrfam), string(spdktypes.NvmeAddressFamilyIPv4)) ||
Expand All @@ -976,7 +977,7 @@ func (e *Engine) validateAndUpdateFrontend(subsystemMap map[string]*spdktypes.Nv
switch e.Frontend {
case types.FrontendSPDKTCPBlockdev:
if e.initiator == nil {
initiator, err := nvme.NewInitiator(e.VolumeName, nqn, nvme.HostProc)
initiator, err := nvme.NewInitiator(e.VolumeName, e.Nqn, nvme.HostProc)
if err != nil {
return errors.Wrapf(err, "failed to create initiator for engine %v during frontend validation and update", e.Name)
}
Expand All @@ -985,7 +986,7 @@ func (e *Engine) validateAndUpdateFrontend(subsystemMap map[string]*spdktypes.Nv
if err := e.initiator.LoadNVMeDeviceInfo(e.initiator.TransportAddress, e.initiator.TransportServiceID, e.initiator.SubsystemNQN); err != nil {
if strings.Contains(err.Error(), "connecting state") ||
strings.Contains(err.Error(), "resetting state") {
e.log.WithError(err).Warnf("Ignored to validate and update engine %v, because the device is still in a transient state", e.Name)
e.log.WithError(err).Warn("Ignored to validate and update engine, because the device is still in a transient state")
return nil
}
return err
Expand All @@ -1001,7 +1002,7 @@ func (e *Engine) validateAndUpdateFrontend(subsystemMap map[string]*spdktypes.Nv
return fmt.Errorf("found mismatching between engine endpoint %s and actual block device endpoint %s for engine %s", e.Endpoint, blockDevEndpoint, e.Name)
}
case types.FrontendSPDKTCPNvmf:
nvmfEndpoint := GetNvmfEndpoint(nqn, e.IP, e.Port)
nvmfEndpoint := GetNvmfEndpoint(e.Nqn, e.IP, e.Port)
if e.Endpoint == "" {
e.Endpoint = nvmfEndpoint
}
Expand Down

0 comments on commit 776b2e0

Please sign in to comment.