]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
strip trailing spaces from fabrics output
authorKeith Busch <kbusch@kernel.org>
Tue, 3 Aug 2021 16:45:22 +0000 (09:45 -0700)
committerDaniel Wagner <dwagner@suse.de>
Mon, 15 Nov 2021 11:06:29 +0000 (12:06 +0100)
Link: https://github.com/linux-nvme/nvme-cli/issues/1117
Signed-off-by: Keith Busch <kbusch@kernel.org>
fabrics.c
nvme.h

index 224c317f828e8f35872c880e724515609d4ea494..fd8eec01f568d608bfc0d4aec9d39e58de3bfec1 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -166,6 +166,10 @@ static void json_discovery_log(struct nvmf_discovery_log *log, int numrec)
                struct nvmf_disc_log_entry *e = &log->entries[i];
                struct json_object *entry = json_create_object();
 
+               nvme_strip_spaces(e->trsvcid, NVMF_TRSVCID_SIZE);
+               nvme_strip_spaces(e->subnqn, NVMF_NQN_SIZE);
+               nvme_strip_spaces(e->traddr, NVMF_TRADDR_SIZE);
+
                json_object_add_value_string(entry, "trtype",
                                             nvmf_trtype_str(e->trtype));
                json_object_add_value_string(entry, "adrfam",
@@ -175,8 +179,7 @@ static void json_discovery_log(struct nvmf_discovery_log *log, int numrec)
                json_object_add_value_string(entry,"treq",
                                             nvmf_treq_str(e->treq));
                json_object_add_value_uint(entry, "portid", e->portid);
-               json_object_add_value_string(entry, "trsvcid",
-                                            e->trsvcid);
+               json_object_add_value_string(entry, "trsvcid", e->trsvcid);
                json_object_add_value_string(entry, "subnqn", e->subnqn);
                json_object_add_value_string(entry, "traddr", e->traddr);
 
diff --git a/nvme.h b/nvme.h
index 41dd71f1d1815d6daddc64814bf3cbe9dd0523b2..eb7d63ff84bf1d10bb935e3ad1743d0e35f680e0 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -79,6 +79,12 @@ void nvme_free(void *p, bool huge);
 unsigned long long elapsed_utime(struct timeval start_time,
                                        struct timeval end_time);
 
+static inline void nvme_strip_spaces(char *s, int l)
+{
+        while (l && (s[l] == '\0' || s[l] == ' '))
+                s[l--] = '\0';
+}
+
 /* nvme-print.c */
 const char *nvme_select_to_string(int sel);