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 committed Dec 12, 2024
1 parent efa03bf commit 58953d6
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")

Check warning on line 426 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L426

Added line #L426 was not covered by tests
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) {

Check warning on line 929 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L929

Added line #L929 was not covered by tests
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)

Check warning on line 934 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L933-L934

Added lines #L933 - L934 were not covered by tests
}

subsystem := subsystemMap[e.Nqn]

Check warning on line 938 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L937-L938

Added lines #L937 - L938 were not covered by tests
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)

Check warning on line 941 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L941

Added line #L941 was not covered by tests
}
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 {

Check warning on line 952 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L952

Added line #L952 was not covered by tests
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)
}

Check warning on line 958 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L956-L958

Added lines #L956 - L958 were not covered by tests

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)

Check warning on line 980 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L980

Added line #L980 was not covered by tests
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")

Check warning on line 989 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L989

Added line #L989 was not covered by tests
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)

Check warning on line 1005 in pkg/spdk/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/engine.go#L1005

Added line #L1005 was not covered by tests
if e.Endpoint == "" {
e.Endpoint = nvmfEndpoint
}
Expand Down

0 comments on commit 58953d6

Please sign in to comment.