-Subproject commit a2e424322385bedfefbcf6620711083c7ff4f6c3
+Subproject commit 5fca2499aa7342ab7b57067982e54822409c8561
}
}
-void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags flags)
+static void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags flags)
{
nvme_print_object(nvme_props_to_json(bar, flags));
}
-void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
+static void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
enum nvme_print_flags flags)
{
nvme_print_object(nvme_id_ns_to_json(ns, flags));
}
-void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flags)
+static void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flags)
{
nvme_print_object(nvme_id_ns_desc_list_to_json(data, flags));
}
-void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, enum nvme_print_flags flags)
+static void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, enum nvme_print_flags flags)
{
nvme_print_object(nvme_id_ctrl_to_json(ctrl, flags));
}
-void nvme_show_id_nvmset(struct nvme_id_nvmset_list *nvmset, unsigned nvmset_id,
+static void nvme_show_id_nvmset(struct nvme_id_nvmset_list *nvmset, unsigned nvmset_id,
enum nvme_print_flags flags)
{
nvme_print_object(nvme_id_nvm_set_list_to_json(nvmset, flags));
}
-void nvme_show_list_secondary_ctrl(
+static void nvme_show_list_secondary_ctrl(
struct nvme_secondary_ctrl_list *sc_list,
__u32 count, enum nvme_print_flags flags)
{
nvme_print_object(nvme_id_secondary_ctrl_list_to_json(sc_list, flags));
}
-void nvme_show_id_ns_granularity_list(struct nvme_id_ns_granularity_list *glist,
+static void nvme_show_id_ns_granularity_list(struct nvme_id_ns_granularity_list *glist,
enum nvme_print_flags flags)
{
nvme_print_object(nvme_id_ns_granularity_list_to_json(glist, flags));
}
-void nvme_show_id_uuid_list(struct nvme_id_uuid_list *uuid_list,
+static void nvme_show_id_uuid_list(struct nvme_id_uuid_list *uuid_list,
enum nvme_print_flags flags)
{
nvme_print_object(nvme_id_uuid_list_to_json(uuid_list, flags));
}
-void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries,
+static void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries,
const char *devname, enum nvme_print_flags flags)
{
nvme_print_object(nvme_error_log_to_json(err_log, entries, flags));
}
-void nvme_show_resv_report(struct nvme_resv_status *status, int bytes,
+static void nvme_show_resv_report(struct nvme_resv_status *status, int bytes,
__u32 cdw11, enum nvme_print_flags flags)
{
nvme_print_object(nvme_resv_report_to_json(status, cdw11 & 1, flags));
}
-void nvme_show_fw_log(struct nvme_firmware_slot *fw_log,
+static void nvme_show_fw_log(struct nvme_firmware_slot *fw_log,
const char *devname, enum nvme_print_flags flags)
{
nvme_print_object(nvme_fw_slot_log_to_json(fw_log, flags));
}
-void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
+static void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
const char *devname,
enum nvme_print_flags flags)
{
nvme_print_object(nvme_ns_list_to_json(log, flags));
}
-void nvme_show_effects_log(struct nvme_cmd_effects_log *effects,
+static void nvme_show_effects_log(struct nvme_cmd_effects_log *effects,
unsigned int flags)
{
nvme_print_object(nvme_cmd_effects_log_to_json(effects, flags));
}
-void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
+static void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
__u16 group_id, const char *devname,
enum nvme_print_flags flags)
{
nvme_print_object(nvme_endurance_group_log_to_json(endurance_log, flags));
}
-void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
+static void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
const char *devname, enum nvme_print_flags flags)
{
nvme_print_object(nvme_smart_log_to_json(smart, flags));
}
-void nvme_show_ana_log(struct nvme_ana_log *ana_log, const char *devname,
+static void nvme_show_ana_log(struct nvme_ana_log *ana_log, const char *devname,
enum nvme_print_flags flags, size_t len)
{
nvme_print_object(nvme_ana_log_to_json(ana_log, flags));
}
-void nvme_show_self_test_log(struct nvme_self_test_log *self_test, const char *devname,
+static void nvme_show_self_test_log(struct nvme_self_test_log *self_test, const char *devname,
enum nvme_print_flags flags)
{
nvme_print_object(nvme_dev_self_test_log_to_json(self_test, flags));
}
-void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,
+static void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,
const char *devname, enum nvme_print_flags flags)
{
nvme_print_object(nvme_sanitize_log_to_json(sanitize, flags));
}
-void nvme_directive_show(__u8 dtype, __u8 doper, __u16 spec, __u32 nsid, __u32 result,
+static void nvme_directive_show(__u8 dtype, __u8 doper, __u16 spec, __u32 nsid, __u32 result,
void *buf, __u32 len, enum nvme_print_flags flags)
{
struct json_object *j = NULL;
fprintf(stderr, "Unrecognized dtype:%d doper:%d\n", dtype, doper);
}
-void nvme_feature_show_fields(__u32 fid, unsigned int result, void **buf,
+static void nvme_feature_show_fields(__u32 fid, unsigned int result, void **buf,
unsigned long flags)
{
nvme_print_object(nvme_feature_to_json(fid, result, 0, buf, flags));
}
-void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
+static void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
enum nvme_print_flags flags)
{
- nvme_lba_status_desc_list_to_json(list, flags);
+ nvme_print_object(nvme_lba_status_desc_list_to_json(list, flags));
}
+
static int get_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
struct nvme_smart_log log;
};
OPT_ARGS(opts) = {
- OPT_LIST("nqn", 'n', &cfg.nqn, nvmf_nqn),
+ OPT_STRING("nqn", 'n', "NAME", &cfg.nqn, nvmf_nqn),
NVMF_OPTS(cfg),
OPT_END()
};
struct config cfg = { 0 };
OPT_ARGS(opts) = {
- OPT_LIST("nqn", 'n', &cfg.nqn, nqn),
- OPT_LIST("device", 'd', &cfg.device, device),
+ OPT_STRING("nqn", 'n', "NAME", &cfg.nqn, nqn),
+ OPT_STRING("device", 'd', "DEV", &cfg.device, device),
OPT_END()
};
static int wdc_get_pci_ids(uint32_t *device_id, uint32_t *vendor_id)
{
- int fd, ret = -1;
- char *block, path[512], *id;
-
- id = calloc(1, 32);
- if (!id) {
- fprintf(stderr, "ERROR : WDC : %s : calloc failed\n", __func__);
- return -1;
- }
-
- block = (char *)devicename;
+ char vid[256], did[256], id[32];
+ nvme_ctrl_t c = NULL;
+ nvme_ns_t n = NULL;
+ int fd, ret;
- /* read the vendor ID from sys fs */
- sprintf(path, "/sys/class/nvme/%s/device/vendor", block);
+ c = nvme_scan_ctrl(devicename);
+ if (c) {
+ snprintf(vid, sizeof(vid), "%s/device/vendor",
+ nvme_ctrl_get_sysfs_dir(c));
+ snprintf(did, sizeof(did), "%s/device/device",
+ nvme_ctrl_get_sysfs_dir(c));
+ nvme_free_ctrl(c);
+ } else {
+ n = nvme_scan_namespace(devicename);
+ if (!n) {
+ fprintf(stderr, "Unable to find %s\n", devicename);
+ return -1;
+ }
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- sprintf(path, "/sys/class/misc/%s/device/vendor", block);
- fd = open(path, O_RDONLY);
+ snprintf(vid, sizeof(vid), "%s/device/device/vendor",
+ nvme_ns_get_sysfs_dir(n));
+ snprintf(did, sizeof(did), "%s/device/device/device",
+ nvme_ns_get_sysfs_dir(n));
+ nvme_free_ns(n);
}
+
+ fd = open(vid, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "ERROR : WDC : %s : Open vendor file failed\n", __func__);
- ret = -1;
- goto free_id;
+ return -1;
}
ret = read(fd, id, 32);
+ close(fd);
+
if (ret < 0) {
fprintf(stderr, "%s: Read of pci vendor id failed\n", __func__);
- ret = -1;
- goto close_fd;
- } else {
- if (id[strlen(id) - 1] == '\n')
- id[strlen(id) - 1] = '\0';
-
- /* convert the device id string to an int */
- *vendor_id = (int)strtol(&id[2], NULL, 16);
- ret = 0;
+ return -1;
}
- /* read the device ID from sys fs */
- sprintf(path, "/sys/class/nvme/%s/device/device", block);
+ if (id[strlen(id) - 1] == '\n')
+ id[strlen(id) - 1] = '\0';
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- sprintf(path, "/sys/class/misc/%s/device/device", block);
- fd = open(path, O_RDONLY);
- }
+ *vendor_id = strtol(id, NULL, 0);
+ ret = 0;
+
+ fd = open(did, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "ERROR : WDC : %s : Open device file failed\n", __func__);
- ret = -1;
- goto close_fd;
+ return -1;
}
ret = read(fd, id, 32);
+ close(fd);
+
if (ret < 0) {
fprintf(stderr, "%s: Read of pci device id failed\n", __func__);
- ret = -1;
- } else {
- if (id[strlen(id) - 1] == '\n')
- id[strlen(id) - 1] = '\0';
-
- /* convert the device id string to an int */
- *device_id = strtol(&id[2], NULL, 16);
- ret = 0;
+ return -1;
}
-close_fd:
- close(fd);
-free_id:
- free(block);
- free(id);
- return ret;
+ if (id[strlen(id) - 1] == '\n')
+ id[strlen(id) - 1] = '\0';
+
+ *device_id = strtol(id, NULL, 0);
+ return 0;
}
static bool wdc_check_device(int fd)
+++ /dev/null
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-
-#include <uuid/uuid.h>
-
-#include "print.h"
-#include "models.h"
-#include "util/json.h"
-#include "util/suffix.h"
-#include "common.h"
-
-
-static const uint8_t zero_uuid[16] = { 0 };
-static const uint8_t invalid_uuid[16] = {[0 ... 15] = 0xff };
-
-static void nvme_print_object(struct json_object *j)
-{
- const unsigned long jflags =
- JSON_C_TO_STRING_SPACED|JSON_C_TO_STRING_PRETTY;
-
- if (j) {
- nvme_json_object_print(stdout, j, jflags);
- json_object_put(j);
- }
-}
-
-void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_props_to_json(bar, flags));
-}
-
-void nvme_show_single_property(int offset, uint64_t value64, int human)
-{
-}
-
-void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
- enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_id_ns_to_json(ns, mode));
-}
-
-void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_id_ns_desc_list_to_json(data, flags));
-}
-
-void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)
-{
- nvme_print_object(nvme_id_ctrl_to_json(ctrl, mode));
-}
-
-void nvme_show_id_nvmset(struct nvme_id_nvmset_list *nvmset, unsigned nvmset_id,
- enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_id_nvm_set_list_to_json(nvmset, flags));
-}
-
-void nvme_show_list_secondary_ctrl(
- struct nvme_secondary_ctrl_list *sc_list,
- __u32 count, enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_id_secondary_ctrl_list_to_json(sc_list, flags));
-}
-
-void nvme_show_id_ns_granularity_list(struct nvme_id_ns_granularity_list *glist,
- enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_id_ns_granularity_list_to_json(glist, flags));
-}
-
-void nvme_show_id_uuid_list(const struct nvme_id_uuid_list *uuid_list,
- enum nvme_print_flags flags)
-{
- nnvme_print_object(vme_id_uuid_list_to_json(uuid_list, flags));
-}
-
-void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries,
- const char *devname, enum nvme_print_flags flags)
-{
- nnvme_print_object(vme_error_log_to_json(err_log, entries, flags));
-}
-
-void nvme_show_resv_report(struct nvme_reservation_status *status, int bytes,
- __u32 cdw11, enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_resv_report_to_json(status, cdw11 & 1, flags));
-}
-
-void nvme_show_fw_log(struct nvme_firmware_slot *fw_log,
- const char *devname, enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_fw_slot_log_to_json(fw_log, flags));
-}
-
-void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
- const char *devname,
- enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_ns_list_to_json(log, flags));
-}
-
-void nvme_show_effects_log(struct nvme_cmd_effects_log *effects,
- unsigned int flags)
-{
- nvme_print_object(nvme_cmd_effects_log_to_json(effects, flags));
-}
-
-void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
- __u16 group_id, const char *devname,
- enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_endurance_group_log_to_json(endurance_log, flags));
-}
-
-void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
- const char *devname, enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_smart_log_to_json(smart, flags));
-}
-
-void nvme_show_ana_log(struct nvme_ana_log *ana_log, const char *devname,
- enum nvme_print_flags flags, size_t len)
-{
- nvme_print_object(nvme_ana_log_to_json(ana_log, flags));
-}
-
-void nvme_show_self_test_log(struct nvme_self_test_log *self_test, const char *devname,
- enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_dev_self_test_log_to_json(self_test, flags));
-}
-
-void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,
- const char *devname, enum nvme_print_flags flags)
-{
- nvme_print_object(nvme_sanitize_log_to_json(sanitize, flags));
-}
-
-void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result,
- void *buf, __u32 len, enum nvme_print_flags flags)
-{
- struct json_object *j;
-
- switch (dtype) {
- case NVME_DIRECTIVE_DTYPE_IDENTIFY:
- switch (doper) {
- case NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM:
- j = nvme_identify_directives_to_json(buf, flags);
- break;
- default:
- break;
- }
- break;
- case NVME_DIRECTIVE_DTYPE_STREAMS:
- switch (doper) {
- case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM:
- j = nvme_streams_directive_params (buf, flags);
- break;
- case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS:
- j = nvme_streams_status_to_json(buf, flags);
- break;
- case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE:
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-
- if (j)
- nvme_print_object(j);
- else
- fprintf(stderr, "Unrecognized dtype:%d doper:%d\n", dtype, doper);
-}
-
-void nvme_feature_show_fields(__u32 fid, unsigned int result, void **buf,
- unsigned long flags)
-{
- nvme_print_object(nvme_feature_to_json(fid, result, 0, buf, flags));
-}
-
-void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
- enum nvme_print_flags flags)
-{
- nvme_lba_status_desc_list_to_json(list, flags);
-}
#include <json-c/json.h>
-#include "libnvme.h"
+#include <libnvme.h>
#include "nvme.h"
enum nvme_print_flags {
return (uint64_t)unalign_int((uint8_t *)data, 6);
}
-static inline __u64 read64(void *addr)
-{
- __le32 *p = addr;
- return le32_to_cpu(*p) | ((__u64)le32_to_cpu(*(p + 1)) << 32);
-}
-
-static inline __u32 read32(void *addr)
-{
- __le32 *p = addr;
- return le32_to_cpu(*p);
-}
-
static inline void nvme_json_add_str_len(struct json_object *j, const char *n,
const char *v, int l, unsigned long flags)
{
static inline void nvme_json_add_le64_ptr(struct json_object *j, const char *n,
void *addr)
{
- __u64 v = read64(addr);
+ __u64 v = nvme_mmio_read64(addr);
nvme_json_add_int64(j, n, v);
}
static inline void nvme_json_add_le32_ptr(struct json_object *j, const char *n,
void *addr)
{
- __u32 v = read32(addr);
+ __u32 v = nvme_mmio_read32(addr);
nvme_json_add_int(j, n, v);
}