linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: hare@suse.de (Hannes Reinecke)
Subject: [PATCH 1/6] nvme-discover: Retry discovery log if the generation counter changes
Date: Thu, 20 Sep 2018 11:09:34 +0200	[thread overview]
Message-ID: <20180920090939.6348-2-hare@suse.de> (raw)
In-Reply-To: <20180920090939.6348-1-hare@suse.de>

If the generation counter changes we need to validate if the number
of records has changed, too.
If so we need to retry retrieving the discovery log to the most recent
values. The retry will be terminated after MAX_DISC_RETRIES (currently
set to 10) to avoid infinite recursion.

Signed-off-by: Hannes Reinecke <hare at suse.com>
---
 fabrics.c | 67 ++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 36 insertions(+), 31 deletions(-)

diff --git a/fabrics.c b/fabrics.c
index 029105b..83eeb00 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -71,6 +71,7 @@ static struct config {
 #define PATH_NVMF_HOSTID	"/etc/nvme/hostid"
 #define SYS_NVME		"/sys/class/nvme"
 #define MAX_DISC_ARGS		10
+#define MAX_DISC_RETRIES	10
 
 enum {
 	OPT_INSTANCE,
@@ -283,7 +284,7 @@ static int nvmf_get_log_page_discovery(const char *dev_path,
 	struct nvmf_disc_rsp_page_hdr *log;
 	unsigned int log_size = 0;
 	unsigned long genctr;
-	int error, fd;
+	int error, fd, max_retries = MAX_DISC_RETRIES, retries = 0;
 
 	fd = open(dev_path, O_RDWR);
 	if (fd < 0) {
@@ -315,42 +316,46 @@ static int nvmf_get_log_page_discovery(const char *dev_path,
 		goto out_free_log;
 	}
 
-	/* check numrec limits */
-	*numrec = le64_to_cpu(log->numrec);
-	genctr = le64_to_cpu(log->genctr);
-	free(log);
+	do {
+		/* check numrec limits */
+		*numrec = le64_to_cpu(log->numrec);
+		genctr = le64_to_cpu(log->genctr);
+		free(log);
 
-	if (*numrec == 0) {
-		error = DISC_NO_LOG;
-		goto out_close;
-	}
+		if (*numrec == 0) {
+			error = DISC_NO_LOG;
+			goto out_close;
+		}
 
-	/* we are actually retrieving the entire discovery tables
-	 * for the second get_log_page(), per
-	 * NVMe spec so no need to round_up(), or there is something
-	 * seriously wrong with the standard
-	 */
-	log_size = sizeof(struct nvmf_disc_rsp_page_hdr) +
+		/* we are actually retrieving the entire discovery tables
+		 * for the second get_log_page(), per
+		 * NVMe spec so no need to round_up(), or there is something
+		 * seriously wrong with the standard
+		 */
+		log_size = sizeof(struct nvmf_disc_rsp_page_hdr) +
 			sizeof(struct nvmf_disc_rsp_page_entry) * *numrec;
 
-	/* allocate discovery log pages based on page_hdr->numrec */
-	log = calloc(1, log_size);
-	if (!log) {
-		error = -ENOMEM;
-		goto out_close;
-	}
+		/* allocate discovery log pages based on page_hdr->numrec */
+		log = calloc(1, log_size);
+		if (!log) {
+			error = -ENOMEM;
+			goto out_close;
+		}
 
-	/*
-	 * issue new get_log_page w/numdl+numdh set to get all records,
-	 * up to MAX_DISC_LOGS.
-	 */
-	error = nvme_discovery_log(fd, log, log_size);
-	if (error) {
-		error = DISC_GET_LOG;
-		goto out_free_log;
-	}
+		/*
+		 * issue new get_log_page w/numdl+numdh set to get all records,
+		 * up to MAX_DISC_LOGS.
+		 */
+		error = nvme_discovery_log(fd, log, log_size);
+		if (error) {
+			error = DISC_GET_LOG;
+			goto out_free_log;
+		}
+
+	} while (genctr != le64_to_cpu(log->genctr) &&
+		 ++retries < max_retries);
 
-	if (*numrec != le32_to_cpu(log->numrec) || genctr != le64_to_cpu(log->genctr)) {
+	if (*numrec != le32_to_cpu(log->numrec)) {
 		error = DISC_NOT_EQUAL;
 		goto out_free_log;
 	}
-- 
2.13.7

  reply	other threads:[~2018-09-20  9:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20  9:09 [PATCH 0/6] nvme-cli: fixup large log page transfer Hannes Reinecke
2018-09-20  9:09 ` Hannes Reinecke [this message]
2018-09-20  9:09 ` [PATCH 2/6] nvme-ioctl: retrieve log pages in 4k chunks Hannes Reinecke
2018-09-20  9:09 ` [PATCH 3/6] nvme-discover: Re-check generation counter after log page transfer Hannes Reinecke
2018-09-20  9:09 ` [PATCH 4/6] seagate-nvme: fixup coding style Hannes Reinecke
2018-09-20  9:09 ` [PATCH 5/6] nvme-cli: Add 'rae' argument to nvme_get_log() Hannes Reinecke
2018-09-20  9:09 ` [PATCH 6/6] nvme-cli: kill nvme_passthru_admin() Hannes Reinecke
2018-09-20 15:22 ` [PATCH 0/6] nvme-cli: fixup large log page transfer Keith Busch

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=20180920090939.6348-2-hare@suse.de \
    --to=hare@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).