mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Wagner <wagi@kernel.org>
To: Keith Busch <kbusch@kernel.org>, Christoph Hellwig <hch@lst.de>,
	 Sagi Grimberg <sagi@grimberg.me>,
	James Smart <james.smart@broadcom.com>
Cc: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
	 Hannes Reinecke <hare@suse.de>,
	linux-nvme@lists.infradead.org,  linux-kernel@vger.kernel.org,
	Daniel Wagner <wagi@kernel.org>
Subject: [PATCH v3 3/4] nvme-fc: refactore nvme_fc_reconnect_or_delete
Date: Fri, 29 Aug 2025 17:37:27 +0200	[thread overview]
Message-ID: <20250829-nvme-fc-sync-v3-3-d69c87e63aee@kernel.org> (raw)
In-Reply-To: <20250829-nvme-fc-sync-v3-0-d69c87e63aee@kernel.org>

Instead using if else blocks, apply the 'early return' and 'goto out'
pattern. This reduces the overall complexity of this function as the
conditions can be read in a linear order.

The only function change is that always the next reconnect attempt
message will be printed.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
---
 drivers/nvme/host/fc.c | 64 +++++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 3e6c79bf0bfd3884867c9ebeb24771323a619934..5d9e193bd2525ae1a2f08e2a0a16ca41e08a7304 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -3249,7 +3249,6 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
 	struct nvme_fc_rport *rport = ctrl->rport;
 	struct nvme_fc_remote_port *portptr = &rport->remoteport;
 	unsigned long recon_delay = ctrl->ctrl.opts->reconnect_delay * HZ;
-	bool recon = true;
 
 	if (nvme_ctrl_state(&ctrl->ctrl) != NVME_CTRL_CONNECTING)
 		return;
@@ -3259,38 +3258,43 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
 			"NVME-FC{%d}: reset: Reconnect attempt failed (%d)\n",
 			ctrl->cnum, status);
 	} else if (time_after_eq(jiffies, rport->dev_loss_end))
-		recon = false;
+		goto delete_log;
 
-	if (recon && nvmf_should_reconnect(&ctrl->ctrl, status)) {
-		if (portptr->port_state == FC_OBJSTATE_ONLINE)
-			dev_info(ctrl->ctrl.device,
-				"NVME-FC{%d}: Reconnect attempt in %ld "
-				"seconds\n",
-				ctrl->cnum, recon_delay / HZ);
-		else if (time_after(jiffies + recon_delay, rport->dev_loss_end))
-			recon_delay = rport->dev_loss_end - jiffies;
+	if (!nvmf_should_reconnect(&ctrl->ctrl, status))
+		goto delete_log;
 
-		queue_delayed_work(nvme_wq, &ctrl->connect_work, recon_delay);
-	} else {
-		if (portptr->port_state == FC_OBJSTATE_ONLINE) {
-			if (status > 0 && (status & NVME_STATUS_DNR))
-				dev_warn(ctrl->ctrl.device,
-					 "NVME-FC{%d}: reconnect failure\n",
-					 ctrl->cnum);
-			else
-				dev_warn(ctrl->ctrl.device,
-					 "NVME-FC{%d}: Max reconnect attempts "
-					 "(%d) reached.\n",
-					 ctrl->cnum, ctrl->ctrl.nr_reconnects);
-		} else
+	if (portptr->port_state != FC_OBJSTATE_ONLINE &&
+	    time_after(jiffies + recon_delay, rport->dev_loss_end))
+		recon_delay = rport->dev_loss_end - jiffies;
+
+	dev_info(ctrl->ctrl.device,
+		 "NVME-FC{%d}: Reconnect attempt in %ld seconds\n",
+		 ctrl->cnum, recon_delay / HZ);
+
+	queue_delayed_work(nvme_wq, &ctrl->connect_work, recon_delay);
+
+	return;
+
+delete_log:
+	if (portptr->port_state == FC_OBJSTATE_ONLINE) {
+		if (status > 0 && (status & NVME_STATUS_DNR))
 			dev_warn(ctrl->ctrl.device,
-				"NVME-FC{%d}: dev_loss_tmo (%d) expired "
-				"while waiting for remoteport connectivity.\n",
-				ctrl->cnum, min_t(int, portptr->dev_loss_tmo,
-					(ctrl->ctrl.opts->max_reconnects *
-					 ctrl->ctrl.opts->reconnect_delay)));
-		nvme_fc_ctrl_put(ctrl);
-	}
+				 "NVME-FC{%d}: reconnect failure\n",
+				 ctrl->cnum);
+		else
+			dev_warn(ctrl->ctrl.device,
+				 "NVME-FC{%d}: Max reconnect attempts "
+				 "(%d) reached.\n",
+				 ctrl->cnum, ctrl->ctrl.nr_reconnects);
+	} else
+		dev_warn(ctrl->ctrl.device,
+			 "NVME-FC{%d}: dev_loss_tmo (%d) expired "
+			 "while waiting for remoteport connectivity.\n",
+			 ctrl->cnum, min_t(int, portptr->dev_loss_tmo,
+					   (ctrl->ctrl.opts->max_reconnects *
+					    ctrl->ctrl.opts->reconnect_delay)));
+
+	nvme_fc_ctrl_put(ctrl);
 }
 
 static void

-- 
2.51.0


  parent reply	other threads:[~2025-08-29 15:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29 15:37 [PATCH v3 0/4] nvme-fc: fix blktests nvme/041 Daniel Wagner
2025-08-29 15:37 ` [PATCH v3 1/4] nvme-fabrics: introduce ref-counting for nvmf_ctrl_options Daniel Wagner
2025-08-29 15:37 ` [PATCH v3 2/4] nvme-fc: reorganize ctrl ref-counting and cleanup code Daniel Wagner
2025-09-01 11:46   ` Dan Carpenter
2025-09-03  7:34     ` Daniel Wagner
2025-09-02  6:45   ` Hannes Reinecke
2025-08-29 15:37 ` Daniel Wagner [this message]
2025-09-02  6:47   ` [PATCH v3 3/4] nvme-fc: refactore nvme_fc_reconnect_or_delete Hannes Reinecke
2025-08-29 15:37 ` [PATCH v3 4/4] nvme-fc: wait for initial connect attempt to finish Daniel Wagner
2025-09-02  9:13   ` Hannes Reinecke
2025-09-03  7:45     ` Daniel Wagner
2025-10-27 21:43 ` [PATCH v3 0/4] nvme-fc: fix blktests nvme/041 Justin Tee
2025-11-06 18:41   ` Justin Tee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250829-nvme-fc-sync-v3-3-d69c87e63aee@kernel.org \
    --to=wagi@kernel.org \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    --cc=shinichiro.kawasaki@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®