}
static int __discover(nvme_ctrl_t c, const struct nvme_fabrics_config *defcfg,
- char *raw, bool connect, bool persistent, bool quiet,
+ char *raw, bool connect, bool persistent,
enum nvme_print_flags flags)
{
struct nvmf_discovery_log *log = NULL;
if (child) {
if (discover)
__discover(child, defcfg, raw,
- persistent, quiet,
+ persistent,
true, flags);
if (!persistent) {
nvme_ctrl_disconnect(child);
errno = 0;
ret = nvmf_add_ctrl(h, c, &cfg, false);
if (!ret) {
- __discover(c, defcfg, NULL, persistent, quiet,
+ __discover(c, defcfg, NULL, persistent,
connect, 0);
return 0;
if (!persistent)
enum nvme_print_flags flags;
nvme_root_t r;
nvme_host_t h;
+ unsigned int verbose = 0;
int ret;
char *format = "normal";
const char *tmp_device;
OPT_FLAG("persistent", 'p', &persistent, "persistent discovery connection"),
OPT_FLAG("quiet", 'S', &quiet, "suppress already connected errors"),
OPT_STRING("config", 'C', "FILE", &config_file, nvmf_config_file),
+ OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_END()
};
if (ret < 0)
return ret;
+ switch (verbose) {
+ case 0:
+ nvme_log_level = LOG_WARNING;
+ break;
+ case 1:
+ nvme_log_level = LOG_NOTICE;
+ break;
+ case 2:
+ nvme_log_level = LOG_INFO;
+ break;
+ default:
+ nvme_log_level = LOG_DEBUG;
+ break;
+ }
+ if (quiet)
+ nvme_log_level = LOG_ERR;
+
if (!strcmp(config_file, "none"))
config_file = NULL;
r = nvme_scan(config_file);
if (!ret) {
ret = __discover(c, &cfg, raw, connect,
- persistent, quiet, flags);
+ persistent, flags);
if (!device && !persistent)
nvme_ctrl_disconnect(c);
nvme_free_ctrl(c);
char *host_traddr = NULL, *host_iface = NULL;
char *trsvcid = NULL, *hostnqn = NULL, *hostid = NULL;
char *config_file = PATH_NVMF_CONFIG;
+ unsigned int verbose = 0;
nvme_root_t r;
nvme_host_t h;
nvme_ctrl_t c;
OPT_STRING("nqn", 'n', "NAME", &subsysnqn, nvmf_nqn),
NVMF_OPTS(cfg),
OPT_STRING("config", 'C', "FILE", &config_file, nvmf_config_file),
+ OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_END()
};
if (ret)
return ret;
+ switch (verbose) {
+ case 0:
+ nvme_log_level = LOG_WARNING;
+ break;
+ case 1:
+ nvme_log_level = LOG_NOTICE;
+ break;
+ case 2:
+ nvme_log_level = LOG_INFO;
+ break;
+ default:
+ nvme_log_level = LOG_DEBUG;
+ break;
+ }
+
if (!subsysnqn) {
nvme_msg(LOG_ERR,
"required argument [--nqn | -n] not specified\n");
struct config {
char *nqn;
char *device;
+ unsigned int verbose;
};
struct config cfg = { 0 };
OPT_ARGS(opts) = {
OPT_STRING("nqn", 'n', "NAME", &cfg.nqn, nvmf_nqn),
OPT_STRING("device", 'd', "DEV", &cfg.device, device),
+ OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"),
OPT_END()
};
if (ret)
return ret;
+ switch (cfg.verbose) {
+ case 0:
+ nvme_log_level = LOG_WARNING;
+ break;
+ case 1:
+ nvme_log_level = LOG_NOTICE;
+ break;
+ case 2:
+ nvme_log_level = LOG_INFO;
+ break;
+ default:
+ nvme_log_level = LOG_DEBUG;
+ break;
+ }
+
if (!cfg.nqn && !cfg.device) {
nvme_msg(LOG_ERR,
"Neither device name [--device | -d] nor NQN [--nqn | -n] provided\n");
struct config {
char *transport;
+ unsigned int verbose;
};
struct config cfg = { 0 };
OPT_ARGS(opts) = {
OPT_STRING("transport", 'r', "STR", (char *)&cfg.transport, nvmf_tport),
+ OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"),
OPT_END()
};
if (ret)
return ret;
+ switch (cfg.verbose) {
+ case 0:
+ nvme_log_level = LOG_WARNING;
+ break;
+ case 1:
+ nvme_log_level = LOG_NOTICE;
+ break;
+ case 2:
+ nvme_log_level = LOG_INFO;
+ break;
+ default:
+ nvme_log_level = LOG_DEBUG;
+ break;
+ }
+
r = nvme_scan(NULL);
if (!r) {
nvme_msg(LOG_ERR, "Failed to scan nvme subsystem: %s\n",
+++ /dev/null
-/*
- * Copyright (C) 2021 SUSE LLC
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *
- * This file implements basic logging functionality.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <syslog.h>
-#include <unistd.h>
-#include <time.h>
-#define LOG_FUNCNAME 1
-#include "log.h"
-#include "cleanup.h"
-
-#ifndef LOG_CLOCK
-#define LOG_CLOCK CLOCK_MONOTONIC
-#endif
-
-int log_level = DEFAULT_LOGLEVEL;
-bool log_timestamp;
-bool log_pid;
-
-void __attribute__((format(printf, 3, 4)))
-__msg(int lvl, const char *func, const char *format, ...)
-{
- va_list ap;
- char pidbuf[16];
- char timebuf[32];
- static const char *const formats[] = {
- "%s%s%s",
- "%s%s%s: ",
- "%s<%s>%s ",
- "%s<%s> %s: ",
- "[%s] %s%s ",
- "[%s]%s %s: ",
- "[%s] <%s>%s ",
- "[%s] <%s> %s: ",
- };
- char *header __cleanup__(cleanup_charp) = NULL;
- char *message __cleanup__(cleanup_charp) = NULL;
- int idx;
-
- if (lvl > log_level)
- return;
-
- if (log_timestamp) {
- struct timespec now;
-
- clock_gettime(LOG_CLOCK, &now);
- snprintf(timebuf, sizeof(timebuf), "%6ld.%06ld",
- (long)now.tv_sec, now.tv_nsec / 1000);
- } else
- *timebuf = '\0';
-
- if (log_pid)
- snprintf(pidbuf, sizeof(pidbuf), "%ld", (long)getpid());
- else
- *pidbuf = '\0';
-
- idx = ((log_timestamp ? 1 : 0) << 2) |
- ((log_pid ? 1 : 0) << 1) | (func ? 1 : 0);
-
- if (asprintf(&header, formats[idx], timebuf, pidbuf, func ? func : "")
- == -1)
- header = NULL;
-
- va_start(ap, format);
- if (vasprintf(&message, format, ap) == -1)
- message = NULL;
- va_end(ap);
-
- fprintf(stderr, "%s%s", header ? header : "<error>",
- message ? message : "<error>");
-
-}