Skip to content

Commit 2242d07

Browse files
committed
fabrics: Introduce connection connect error mapping
The kernel returns status information via error codes. Currently we map all error codes to ENVME_CONNECT_WRITE if the operation fails. Some of those error codes should be treated differently, such as EALREADY which means the connection attempt failed because the connection is already established. Many of the error codes are overloaded so we have to guess if they are actually from the nvme subsystem and not from the write command. Though in practice it's almost certainly the nvme subsystem. Still it's a guessing game due the very limited API between userland and kernel. Signed-off-by: Daniel Wagner <[email protected]>
1 parent aacaeea commit 2242d07

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/nvme/fabrics.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,26 @@ static int __nvmf_add_ctrl(nvme_root_t r, const char *argstr)
526526
if (ret != len) {
527527
nvme_msg(r, LOG_NOTICE, "Failed to write to %s: %s\n",
528528
nvmf_dev, strerror(errno));
529-
ret = -ENVME_CONNECT_WRITE;
529+
switch (errno) {
530+
case EALREADY:
531+
ret = -ENVME_CONNECT_ALREADY;
532+
break;
533+
case EINVAL:
534+
ret = -ENVME_CONNECT_INVAL;
535+
break;
536+
case EADDRINUSE:
537+
ret = -ENVME_CONNECT_ADDRINUSE;
538+
break;
539+
case ENODEV:
540+
ret = -ENVME_CONNECT_NODEV;
541+
break;
542+
case EOPNOTSUPP:
543+
ret = -ENVME_CONNECT_OPNOTSUPP;
544+
break;
545+
default:
546+
ret = -ENVME_CONNECT_WRITE;
547+
break;
548+
}
530549
goto out_close;
531550
}
532551

src/nvme/util.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ static const char * const libnvme_status[] = {
536536
[ENVME_CONNECT_INVAL_TR] = "invalid transport type",
537537
[ENVME_CONNECT_LOOKUP_SUBSYS_NAME] = "failed to lookup subsystem name",
538538
[ENVME_CONNECT_LOOKUP_SUBSYS] = "failed to lookup subsystem",
539+
[ENVME_CONNECT_ALREADY] = "already connnected",
540+
[ENVME_CONNECT_INVAL] = "invalid arguments/configuration",
541+
[ENVME_CONNECT_ADDRINUSE] = "hostnqn already in use",
542+
[ENVME_CONNECT_NODEV] = "invalid interface",
543+
[ENVME_CONNECT_OPNOTSUPP] ="not supported",
539544
};
540545

541546
const char *nvme_errno_to_string(int status)

src/nvme/util.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
* @ENVME_CONNECT_INVAL_TR: invalid transport type
3232
* @ENVME_CONNECT_LOOKUP_SUBSYS_NAME: failed to lookup subsystem name
3333
* @ENVME_CONNECT_LOOKUP_SUBSYS: failed to lookup subsystem
34+
* @ENVME_CONNECT_ALREADY: the connect attempt failed, already connected
35+
* @ENVME_CONNECT_INVAL: invalid arguments/configuration
36+
* @ENVME_CONNECT_ADDRINUSE: hostnqn already in use
37+
* @ENVME_CONNECT_NODEV: invalid interface
38+
* @ENVME_CONNECT_OPNOTSUPP: not supported
3439
*/
3540
enum nvme_connect_err {
3641
ENVME_CONNECT_RESOLVE = 1000,
@@ -45,6 +50,11 @@ enum nvme_connect_err {
4550
ENVME_CONNECT_INVAL_TR,
4651
ENVME_CONNECT_LOOKUP_SUBSYS_NAME,
4752
ENVME_CONNECT_LOOKUP_SUBSYS,
53+
ENVME_CONNECT_ALREADY,
54+
ENVME_CONNECT_INVAL,
55+
ENVME_CONNECT_ADDRINUSE,
56+
ENVME_CONNECT_NODEV,
57+
ENVME_CONNECT_OPNOTSUPP,
4858
};
4959

5060
/**

0 commit comments

Comments
 (0)