Skip to content

Commit

Permalink
fix: func connectNVMfBdev detaches the nvme controller before and aft…
Browse files Browse the repository at this point in the history
…er attachment (failure)

Longhorn 10293

Signed-off-by: Shuo Wu <[email protected]>
  • Loading branch information
shuo-wu authored and derekbit committed Jan 31, 2025
1 parent 44753b5 commit 6e966aa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/spdk/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,24 @@ func connectNVMfBdev(spdkClient *spdkclient.Client, controllerName, address stri
return "", fmt.Errorf("controllerName or address is empty")
}

defer func() {
if err != nil {
if _, detachErr := spdkClient.BdevNvmeDetachController(controllerName); detachErr != nil && !jsonrpc.IsJSONRPCRespErrorNoSuchDevice(detachErr) {
logrus.WithError(detachErr).Errorf("Failed to detach NVMe controller %s after failing at attaching it", controllerName)
}
}
}()

ip, port, err := net.SplitHostPort(address)
if err != nil {
return "", err
}

// Blindly detach the controller in case of the previous replica connection is not cleaned up correctly
if _, err := spdkClient.BdevNvmeDetachController(controllerName); err != nil && !jsonrpc.IsJSONRPCRespErrorNoSuchDevice(err) {
return "", err
}

nvmeBdevNameList, err := spdkClient.BdevNvmeAttachController(controllerName, helpertypes.GetNQN(controllerName),
ip, port, spdktypes.NvmeTransportTypeTCP, spdktypes.NvmeAddressFamilyIPv4,
int32(ctrlrLossTimeout), replicaReconnectDelaySec, int32(fastIOFailTimeoutSec), replicaMultipath)
Expand Down

0 comments on commit 6e966aa

Please sign in to comment.