diff --git a/pkg/nvme/initiator.go b/pkg/nvme/initiator.go index e969adc..5d7c9ef 100644 --- a/pkg/nvme/initiator.go +++ b/pkg/nvme/initiator.go @@ -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") @@ -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 %s", i.Endpoint, i.Name) + } else { if err := i.makeEndpoint(); err != nil { return dmDeviceIsBusy, err }