Skip to content

Commit 0c9443b

Browse files
calebsanderigaw
authored andcommitted
fabrics: handle /dev/nvme-fabrics read failure
The ability to read from /dev/nvme-fabrics to find supported options is a newer Linux kernel feature added in f18ee3d988157 (5.17-rc1). On earlier kernels, this read returns EINVAL, preventing the controller from being added: $ nvme discover --transport tcp --traddr 192.168.1.62 Failed to read from /dev/nvme-fabrics: Invalid argument failed to add controller, error Invalid argument So don't treat EINVAL as a fatal error, and instead fall back to a default set of supported options. With this change, controllers can be created successfully: $ nvme discover --transport tcp --traddr 192.168.1.62 Discovery Log Number of Records 4, Generation counter 125 ... Fixes: d123131 ("fabrics: Do not pass unsupported options to kernel") Signed-off-by: Caleb Sander <[email protected]>
1 parent f7ba8bf commit 0c9443b

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/nvme/fabrics.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,37 @@ const char *nvmf_cms_str(__u8 cm)
196196
return arg_str(cms, ARRAY_SIZE(cms), cm);
197197
}
198198

199+
/*
200+
* Derived from Linux's supported options (the opt_tokens table)
201+
* when the mechanism to report supported options was added (f18ee3d988157).
202+
* Not all of these options may actually be supported,
203+
* but we retain the old behavior of passing all that might be.
204+
*/
205+
static const struct nvme_fabric_options default_supported_options = {
206+
.ctrl_loss_tmo = true,
207+
.data_digest = true,
208+
.disable_sqflow = true,
209+
.discovery = true,
210+
.duplicate_connect = true,
211+
.fast_io_fail_tmo = true,
212+
.hdr_digest = true,
213+
.host_iface = true,
214+
.host_traddr = true,
215+
.hostid = true,
216+
.hostnqn = true,
217+
.keep_alive_tmo = true,
218+
.nqn = true,
219+
.nr_io_queues = true,
220+
.nr_poll_queues = true,
221+
.nr_write_queues = true,
222+
.queue_size = true,
223+
.reconnect_delay = true,
224+
.tos = true,
225+
.traddr = true,
226+
.transport = true,
227+
.trsvcid = true,
228+
};
229+
199230
void nvmf_default_config(struct nvme_fabrics_config *cfg)
200231
{
201232
memset(cfg, 0, sizeof(*cfg));
@@ -644,6 +675,19 @@ static int __nvmf_supported_options(nvme_root_t r)
644675
memset(buf, 0x0, sizeof(buf));
645676
len = read(fd, buf, sizeof(buf) - 1);
646677
if (len < 0) {
678+
if (errno == EINVAL) {
679+
/*
680+
* Older Linux kernels don't allow reading from nvmf_dev
681+
* to get supported options, so use a default set
682+
*/
683+
nvme_msg(r, LOG_DEBUG,
684+
"Cannot read %s, using default options\n",
685+
nvmf_dev);
686+
*r->options = default_supported_options;
687+
ret = 0;
688+
goto out_close;
689+
}
690+
647691
nvme_msg(r, LOG_ERR, "Failed to read from %s: %s\n",
648692
nvmf_dev, strerror(errno));
649693
ret = -ENVME_CONNECT_READ;

0 commit comments

Comments
 (0)