Skip to content

Commit

Permalink
fix: always ensure endpoint creation
Browse files Browse the repository at this point in the history
Longhorn 9919

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Dec 9, 2024
1 parent 9757dfd commit fa90a3a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/nvme/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,9 @@ func (i *Initiator) Start(transportAddress, transportServiceID string, dmDeviceA
return dmDeviceIsBusy, errors.Wrapf(err, "failed to load device info after connecting target for NVMe initiator %s", i.Name)
}

needMakeEndpoint := true
if dmDeviceAndEndpointCleanupRequired {
if dmDeviceIsBusy {
// Endpoint is already created, just replace the target device
needMakeEndpoint = false
i.logger.Info("Linear dm device is busy, trying the best to replace the target device for NVMe initiator")
if err := i.replaceDmDeviceTarget(); err != nil {
i.logger.WithError(err).Warnf("Failed to replace the target device for NVMe initiator")
Expand All @@ -325,8 +323,14 @@ func (i *Initiator) Start(transportAddress, transportServiceID string, dmDeviceA
i.dev.Export = i.dev.Nvme
}

if needMakeEndpoint {
i.logger.Infof("Creating endpoint %v", i.Endpoint)
i.logger.Infof("Creating endpoint %v", i.Endpoint)
exist, err := i.isEndpointExist()
if err != nil {
return dmDeviceIsBusy, errors.Wrapf(err, "failed to check if endpoint %v exists for NVMe initiator %s", i.Endpoint, i.Name)
}
if exist {
i.logger.Infof("Skipping endpoint %v creation for NVMe initiator", i.Endpoint)
} else {
if err := i.makeEndpoint(); err != nil {
return dmDeviceIsBusy, err
}
Expand Down Expand Up @@ -481,8 +485,8 @@ func (i *Initiator) loadNVMeDeviceInfoWithoutLock(transportAddress, transportSer
"transportServiceID": i.TransportServiceID,
})

devicePath := fmt.Sprintf("/dev/%s", i.NamespaceName)
dev, err := util.DetectDevice(devicePath, i.executor)
devPath := filepath.Join("/dev", i.NamespaceName)
dev, err := util.DetectDevice(devPath, i.executor)
if err != nil {
return errors.Wrapf(err, "cannot find the device for NVMe initiator %s with namespace name %s", i.Name, i.NamespaceName)
}
Expand Down

0 comments on commit fa90a3a

Please sign in to comment.