Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NBFT parser SSNS flags #2215

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions nbft.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "nvme-print.h"

#include "util/types.h"
#include "util/logging.h"

#define NBFT_SYSFS_FILENAME "NBFT*"

Expand Down Expand Up @@ -80,7 +81,7 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
char *hostnqn_sys, char *hostid_sys,
const char *desc, bool connect,
const struct nvme_fabrics_config *cfg, char *nbft_path,
enum nvme_print_flags flags, bool verbose)
enum nvme_print_flags flags, unsigned int verbose)
{
char *hostnqn = NULL, *hostid = NULL, *host_traddr = NULL;
nvme_host_t h;
Expand All @@ -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)
Expand Down Expand Up @@ -159,9 +163,36 @@ 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.
*/
if (ret == -1 && (*ss)->unavailable) {
if (verbose >= 1)
fprintf(stderr,
"SSNS %d reported as unavailable, skipping\n",
(*ss)->index);
continue;
}

/*
* With TCP/DHCP, it can happen that the OS
* obtains a different local IP address than the
Expand All @@ -188,12 +219,14 @@ int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
ret = nvmf_add_ctrl(h, c, cfg);
if (ret == 0 && verbose >= 1)
fprintf(stderr,
"connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n",
"SSNS %d: connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n",
(*ss)->index,
host_traddr);
}

if (ret)
fprintf(stderr, "no controller found\n");
fprintf(stderr, "SSNS %d: no controller found\n",
(*ss)->index);
else {
if (flags == NORMAL)
print_connect_msg(c);
Expand Down
2 changes: 1 addition & 1 deletion nbft.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ extern int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg
char *hostnqn_sys, char *hostid_sys,
const char *desc, bool connect,
const struct nvme_fabrics_config *cfg, char *nbft_path,
enum nvme_print_flags flags, bool verbose);
enum nvme_print_flags flags, unsigned int verbose);
18 changes: 16 additions & 2 deletions plugins/nbft/nbft-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <stdio.h>
#include <fnmatch.h>

#include <libnvme.h>
#include "nvme-print.h"
#include "nvme.h"
#include "nbft.h"
#include "libnvme.h"
#include "fabrics.h"
#include "util/logging.h"

#define CREATE_CMD
#include "nbft-plugin.h"
Expand Down Expand Up @@ -168,7 +169,11 @@ static json_object *ssns_to_json(struct nbft_info_subsystem_ns *ss)
|| json_object_add_value_int(ss_json, "pdu_header_digest_required",
ss->pdu_header_digest_required)
|| json_object_add_value_int(ss_json, "data_digest_required",
ss->data_digest_required))
ss->data_digest_required)
|| json_object_add_value_int(ss_json, "discovered",
ss->discovered)
|| json_object_add_value_int(ss_json, "unavailable",
ss->unavailable))
goto fail;

return ss_json;
Expand Down Expand Up @@ -529,24 +534,32 @@ int show_nbft(int argc, char **argv, struct command *cmd, struct plugin *plugin)
enum nvme_print_flags flags;
int ret;
bool show_subsys = false, show_hfi = false, show_discovery = false;
unsigned int verbose = 0;
nvme_root_t r;

OPT_ARGS(opts) = {
OPT_FMT("output-format", 'o', &format, "Output format: normal|json"),
OPT_FLAG("subsystem", 's', &show_subsys, "show NBFT subsystems"),
OPT_FLAG("hfi", 'H', &show_hfi, "show NBFT HFIs"),
OPT_FLAG("discovery", 'd', &show_discovery, "show NBFT discovery controllers"),
OPT_STRING("nbft-path", 0, "STR", &nbft_path, "user-defined path for NBFT tables"),
OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_END()
};

ret = argconfig_parse(argc, argv, desc, opts);
if (ret)
return ret;

log_level = map_log_level(verbose, false /* quiet */);

ret = validate_output_format(format, &flags);
if (ret < 0)
return ret;

/* initialize libnvme logging */
r = nvme_create_root(stderr, log_level);

if (!(show_subsys || show_hfi || show_discovery))
show_subsys = show_hfi = show_discovery = true;

Expand All @@ -559,5 +572,6 @@ int show_nbft(int argc, char **argv, struct command *cmd, struct plugin *plugin)
ret = json_show_nbfts(&nbft_list, show_subsys, show_hfi, show_discovery);
free_nbfts(&nbft_list);
}
nvme_free_tree(r);
return ret;
}