Skip to contentSkip to conversation

nvme: print out valid arguments when reading from /dev/nvme-fabrics

PATCH Superseded Hannes Reinecke 3 participants 6 messages Nov 19, 2021 – Nov 23, 2021 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: print out valid arguments when reading from /dev/nvme-fabrics

Currently applications have a hard time figuring out which nvme-over-fabrics arguments are supported for any given kernel; the ioctl will return an error code on failure, and the application has to guess whether this was due to an invalid argument or due to a connection or controller error.
With this patch applications can read a list of supported arguments by simply reading from /dev/nvme-fabrics, allowing them to validate the connection string.

---
 drivers/nvme/host/fabrics.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/nvme/host/fabrics.c +12 -1
index 0ac054f80a82..810bbc8c9b6b 100644
@@ -1144,7 +1144,18 @@ static int nvmf_dev_show(struct seq_file *seq_file, void *private)
 	mutex_lock(&nvmf_dev_mutex);
 	ctrl = seq_file->private;
 	if (!ctrl) {
-		ret = -EINVAL;
+		const struct match_token *tok;
+		int idx;
+
+		for (idx = 0; idx < ARRAY_SIZE(opt_tokens); idx++) {
+			tok = &opt_tokens[idx];
+			if (tok->token == NVMF_OPT_ERR)
+				continue;
+			if (idx)
+				seq_puts(seq_file, ",");
+			seq_puts(seq_file, tok->pattern);
+		}
+		seq_puts(seq_file, "\n");
 		goto out_unlock;
 	}
 
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Hannes Reinecke

Currently applications have a hard time figuring out which nvme-over-fabrics arguments are supported for any given kernel; the ioctl will return an error code on failure, and the application has to guess whether this was due to an invalid argument or due to a connection or controller error.
With this patch applications can read a list of supported arguments by simply reading from /dev/nvme-fabrics, allowing them to validate the connection string.

this seems useful and will avoid a trip to the source code.

Looks good.

#2 lore raw
In reply to Hannes Reinecke

The subject should use a nvme-fabrics prefix.

drivers/nvme/host/fabrics.c static int nvmf_dev_show(struct seq_file *seq_file, void *private) · line 1158

Quoted 12 lines
drivers/nvme/host/fabrics.c +12 -0
+		const struct match_token *tok;
+		int idx;
+
+		for (idx = 0; idx < ARRAY_SIZE(opt_tokens); idx++) {
+			tok = &opt_tokens[idx];
+			if (tok->token == NVMF_OPT_ERR)
+				continue;
+			if (idx)
+				seq_puts(seq_file, ",");
+			seq_puts(seq_file, tok->pattern);
+		}
+		seq_puts(seq_file, "\n");

A helper for this logic would be nice. Also shouldn't be there some kind of token to distinguish from the case where a controller has already been created?

#3 lore raw
Quoted 19 lines · Christoph Hellwig

The subject should use a nvme-fabrics prefix.

drivers/nvme/host/fabrics.c static int nvmf_dev_show(struct seq_file *seq_file, void *private) · line 1158

Quoted 12 lines
drivers/nvme/host/fabrics.c +12 -0
+		const struct match_token *tok;
+		int idx;
+
+		for (idx = 0; idx < ARRAY_SIZE(opt_tokens); idx++) {
+			tok = &opt_tokens[idx];
+			if (tok->token == NVMF_OPT_ERR)
+				continue;
+			if (idx)
+				seq_puts(seq_file, ",");
+			seq_puts(seq_file, tok->pattern);
+		}
+		seq_puts(seq_file, "\n");

A helper for this logic would be nice. Also shouldn't be there some kind of token to distinguish from the case where a controller has already been created?

Helper: sure.
But we don't need to distinguish the case where the controller has already been created as this is handled by the if condition further up.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
#4 lore raw
Quoted 3 lines · Hannes Reinecke

Helper: sure.
But we don't need to distinguish the case where the controller has already been created as this is handled by the if condition further up.

Well, a token that the reader clearly sees that there is no controller yet

#5 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Hannes Reinecke

Helper: sure.
But we don't need to distinguish the case where the controller has already been created as this is handled by the if condition further up.

Well, a token that the reader clearly sees that there is no controller yet

Ah. That. Sure, can do.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer