Skip to content
Draft
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
98 changes: 49 additions & 49 deletions fabrics.c

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void nvme_log_retry(int errnum)
if (log_level < LIBNVME_LOG_DEBUG)
return;

printf("passthru command returned '%s'\n", libnvme_strerror(errnum));
print_debug("passthru command returned '%s'\n", libnvme_strerror(errnum));
}

void *nvme_submit_entry(struct libnvme_transport_handle *hdl,
Expand Down Expand Up @@ -209,8 +209,8 @@ void *nvme_mi_submit_entry(struct libnvme_mi_ep *ep, __u8 type,
static void nvme_show_resp_admin(const struct nvme_mi_admin_resp_hdr *hdr, size_t hdr_len,
const void *data, size_t data_len)
{
printf("result : %08x\n", le32_to_cpu(hdr->cdw0));
printf("err : %d\n", hdr->status);
nvme_show_key_value("result ", "%08x", le32_to_cpu(hdr->cdw0));
nvme_show_key_value("err ", "%d", hdr->status);
}

static void nvme_show_resp(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len,
Expand Down
7 changes: 4 additions & 3 deletions nvme-models.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/types.h>
#include "nvme-models.h"
#include "nvme.h"
#include "nvme-print.h"

static char *_fmt1 = "/sys/class/nvme/nvme%d/device/subsystem_vendor";
static char *_fmt2 = "/sys/class/nvme/nvme%d/device/subsystem_device";
Expand Down Expand Up @@ -246,7 +247,7 @@ static int read_sys_node(char *where, char *save, size_t savesz)
fd = open(where, O_RDONLY);
if (fd < 0) {
if (errno != ENOENT) {
fprintf(stderr, "Failed to open %s with errno %s\n",
nvme_show_error("Failed to open %s with errno %s",
where, libnvme_strerror(errno));
}
return 1;
Expand Down Expand Up @@ -295,7 +296,7 @@ static FILE *open_pci_ids(void)
return fp;
}

fprintf(stderr, "Could not find pci.ids file\n");
nvme_show_error("Could not find pci.ids file");
return NULL;
}

Expand Down Expand Up @@ -350,7 +351,7 @@ static char *__nvme_product_name(int id)

result = malloc(LINE_BUF_SIZE);
if (!result) {
fprintf(stderr, "malloc: %s\n", libnvme_strerror(errno));
nvme_show_error("malloc: %s", libnvme_strerror(errno));
free_all();
return NULL;
}
Expand Down
19 changes: 18 additions & 1 deletion nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -5503,13 +5503,30 @@ void json_show_init(void)
json_r = json_create_object();
}

bool json_empty(struct json_object *obj)
{
if (!obj)
return true;

switch (json_object_get_type(obj)) {
case json_type_object:
return json_object_object_length(obj) == 0;
case json_type_array:
return json_object_array_length(obj) == 0;
default:
return false; /* scalars always have something to print */
}
}

void json_show_finish(void)
{
if (--json_init)
return;

if (json_r)
if (!json_empty(json_r))
json_output_object(json_r);
else
json_free_object(json_r);

json_r = NULL;
}
Expand Down
27 changes: 27 additions & 0 deletions nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,20 @@ void nvme_show_message(bool error, const char *msg, ...)
va_end(ap);
}

void nvme_show_verbose_message(const char *msg, ...)
{
va_list ap;

if (!nvme_args.verbose)
return;

va_start(ap, msg);

nvme_show_message(true, msg, ap);

va_end(ap);
}

void nvme_show_perror(const char *msg, ...)
{
struct print_ops *ops = nvme_print_ops(NORMAL);
Expand Down Expand Up @@ -1774,6 +1788,19 @@ void nvme_show_key_value(const char *key, const char *val, ...)

va_end(ap);
}
void nvme_show_verbose_key_value(const char *key, const char *val, ...)
{
va_list ap;

if (!nvme_args.verbose)
return;

va_start(ap, val);

nvme_show_key_value(key, val, ap);

va_end(ap);
}

void nvme_show_discovery_log(struct nvmf_discovery_log *log, uint64_t numrec,
nvme_print_flags_t flags)
Expand Down
4 changes: 4 additions & 0 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ typedef struct nvme_effects_log_node {

#define nvme_show_error(msg, ...) nvme_show_message(true, msg, ##__VA_ARGS__)
#define nvme_show_result(msg, ...) nvme_show_message(false, msg, ##__VA_ARGS__)
#define nvme_show_verbose_result(msg, ...) nvme_show_verbose_message(msg, ##__VA_ARGS__)
#define nvme_show_verbose_info(msg, ...) nvme_show_verbose_message(msg, ##__VA_ARGS__)

#define POWER_OF_TWO(exponent) (1 << (exponent))

Expand Down Expand Up @@ -373,11 +375,13 @@ const char *nvme_ipmsr_srs_to_string(__u8 srs);
void nvme_dev_full_path(libnvme_ns_t n, char *path, size_t len);
void nvme_generic_full_path(libnvme_ns_t n, char *path, size_t len);
void nvme_show_message(bool error, const char *msg, ...);
void nvme_show_verbose_message(const char *msg, ...);
void nvme_show_perror(const char *msg, ...);
void nvme_show_error_status(int status, const char *msg, ...);
void nvme_show_init(void);
void nvme_show_finish(void);
void nvme_show_key_value(const char *key, const char *value, ...);
void nvme_show_verbose_key_value(const char *key, const char *value, ...);
bool nvme_is_fabrics_reg(int offset);
bool nvme_is_fabrics_optional_reg(int offset);
bool nvme_registers_cmbloc_support(__u32 cmbsz);
Expand Down
Loading
Loading