]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nbft: Pause logging for expected connection failures
authorTomas Bzatek <tbzatek@redhat.com>
Tue, 13 Feb 2024 14:54:15 +0000 (09:54 -0500)
committerDaniel Wagner <wagi@monom.org>
Tue, 19 Mar 2024 16:44:03 +0000 (17:44 +0100)
For unavailable SSNSs, pause logging to make connection
attempts truly silent.

Kernel errors are still being logged, e.g.
  nvme nvme8: failed to connect socket: -110

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
nbft.c

diff --git a/nbft.c b/nbft.c
index 9b39c9aa506a850bb7a9829b6a507994d53b1456..50f4e6e5bc50cbe948be56517458b85445d48aba 100644 (file)
--- a/nbft.c
+++ b/nbft.c
@@ -13,6 +13,7 @@
 #include "nvme-print.h"
 
 #include "util/types.h"
+#include "util/logging.h"
 
 #define NBFT_SYSFS_FILENAME    "NBFT*"
 
@@ -107,6 +108,9 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
                for (ss = entry->nbft->subsystem_ns_list; ss && *ss; ss++)
                        for (i = 0; i < (*ss)->num_hfis; i++) {
                                nvme_ctrl_t cl;
+                               int saved_log_level = log_level;
+                               bool saved_log_pid = false;
+                               bool saved_log_tstamp = false;
 
                                hfi = (*ss)->hfis[i];
                                if (hostnqn_arg)
@@ -159,9 +163,24 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
                                        goto out_free;
                                }
 
+                               /* Pause logging for unavailable SSNSs */
+                               if ((*ss)->unavailable && verbose < 1) {
+                                       saved_log_level = nvme_get_logging_level(r,
+                                                                                &saved_log_pid,
+                                                                                &saved_log_tstamp);
+                                       nvme_init_logging(r, -1, false, false);
+                               }
+
                                errno = 0;
                                ret = nvmf_add_ctrl(h, c, cfg);
 
+                               /* Resume logging */
+                               if ((*ss)->unavailable && verbose < 1)
+                                       nvme_init_logging(r,
+                                                         saved_log_level,
+                                                         saved_log_pid,
+                                                         saved_log_tstamp);
+
                                /*
                                 * In case this SSNS was marked as 'unavailable' and
                                 * the connection attempt failed again, ignore it.