From a6020c58ab8564b69d88b96b62232f760e2fee73 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Sun, 8 Dec 2024 14:50:07 +0800 Subject: [PATCH] fix: always ensure endpoint creation Longhorn 9919 Signed-off-by: Derek Su --- pkg/nvme/initiator.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/nvme/initiator.go b/pkg/nvme/initiator.go index e969adc..033b1ac 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", i.Endpoint) + } else { if err := i.makeEndpoint(); err != nil { return dmDeviceIsBusy, err }