]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: update return values for dim
authorMartin George <marting@netapp.com>
Fri, 15 Nov 2024 11:04:05 +0000 (16:34 +0530)
committerDaniel Wagner <wagi@monom.org>
Fri, 22 Nov 2024 06:58:10 +0000 (07:58 +0100)
The nvme dim command returns a zero even for failure scenarios
as shown below:

nvme0 DIM register command error. Status:0xffffffff -
Operation not supported

echo $?
0

Fix this by ensuring appropriate values are returned for success
and failure scenarios. And while at it, remove a couple of
superfluous braces too here.

Signed-off-by: Martin George <marting@netapp.com>
fabrics.c

index eb90d98cf06903f975f5e305380e542bc034a8e7..4d250e99c57caf93a392a8ba2947519ac1d98d1e 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -1430,7 +1430,7 @@ int nvmf_config(const char *desc, int argc, char **argv)
        return 0;
 }
 
-static void dim_operation(nvme_ctrl_t c, enum nvmf_dim_tas tas, const char *name)
+static int dim_operation(nvme_ctrl_t c, enum nvmf_dim_tas tas, const char *name)
 {
        static const char * const task[] = {
                [NVMF_DIM_TAS_REGISTER]   = "register",
@@ -1451,6 +1451,8 @@ static void dim_operation(nvme_ctrl_t c, enum nvmf_dim_tas tas, const char *name
                fprintf(stderr, "%s DIM %s command error. Result:0x%04x, Status:0x%04x - %s\n",
                        name, t, result, status, nvme_status_to_string(status, false));
        }
+
+       return nvme_status_to_errno(status, true);
 }
 
 int nvmf_dim(const char *desc, int argc, char **argv)
@@ -1530,9 +1532,8 @@ int nvmf_dim(const char *desc, int argc, char **argv)
                                nvme_for_each_subsystem(h, s) {
                                        if (strcmp(nvme_subsystem_get_nqn(s), p))
                                                continue;
-                                       nvme_subsystem_for_each_ctrl(s, c) {
-                                               dim_operation(c, tas, p);
-                                       }
+                                       nvme_subsystem_for_each_ctrl(s, c)
+                                               ret = dim_operation(c, tas, p);
                                }
                        }
                }
@@ -1551,9 +1552,9 @@ int nvmf_dim(const char *desc, int argc, char **argv)
                                        p, nvme_strerror(errno));
                                return -errno;
                        }
-                       dim_operation(c, tas, p);
+                       ret = dim_operation(c, tas, p);
                }
        }
 
-       return 0;
+       return ret;
 }