Adding upstream version 2.14.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
94a061187a
commit
dbdc28cb89
572 changed files with 4636 additions and 1730 deletions
|
@ -11,9 +11,10 @@
|
|||
#include "nvme-print.h"
|
||||
|
||||
#include "util/json.h"
|
||||
#include "util/logging.h"
|
||||
#include "logging.h"
|
||||
#include "nvme.h"
|
||||
#include "common.h"
|
||||
#include "libnvme.h"
|
||||
|
||||
#define ERROR_MSG_LEN 100
|
||||
#define NAME_LEN 128
|
||||
|
@ -40,10 +41,12 @@
|
|||
#define obj_add_nprix64 json_object_add_nprix64
|
||||
#define obj_add_uint_0nx json_object_add_uint_0nx
|
||||
#define obj_add_0nprix64 json_object_add_0nprix64
|
||||
#define obj_add_string json_object_add_string
|
||||
|
||||
static const uint8_t zero_uuid[16] = { 0 };
|
||||
static struct print_ops json_print_ops;
|
||||
static struct json_object *json_r;
|
||||
static int json_init;
|
||||
|
||||
static void json_feature_show_fields(enum nvme_features_id fid, unsigned int result,
|
||||
unsigned char *buf);
|
||||
|
@ -197,9 +200,9 @@ static void json_id_iocs_iocsc(struct json_object *obj_iocsc, __u64 iocsc)
|
|||
obj_add_str(obj_iocsc, "NVM Command Set", nvmcs ? "Selected" : "Not selected");
|
||||
}
|
||||
|
||||
static bool human(void)
|
||||
static bool verbose_mode(void)
|
||||
{
|
||||
return json_print_ops.flags & VERBOSE;
|
||||
return json_print_ops.flags & VERBOSE || nvme_cfg.output_format_ver == 2;
|
||||
}
|
||||
|
||||
static void json_id_iocs(struct nvme_id_iocs *iocs)
|
||||
|
@ -224,6 +227,32 @@ static void json_id_iocs(struct nvme_id_iocs *iocs)
|
|||
json_print(r);
|
||||
}
|
||||
|
||||
static void json_nvme_id_ns_lbaf(struct nvme_id_ns *ns, int i, struct json_object *lbafs)
|
||||
{
|
||||
struct json_object *lbaf = json_create_object();
|
||||
__u8 flbas;
|
||||
|
||||
nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &flbas);
|
||||
|
||||
if (verbose_mode()) {
|
||||
obj_add_int(lbaf, "LBA Format", i);
|
||||
obj_add_string(lbaf, "Metadata Size", "%d bytes", le16_to_cpu(ns->lbaf[i].ms));
|
||||
obj_add_string(lbaf, "Data Size", "%d bytes", 1 << ns->lbaf[i].ds);
|
||||
obj_add_string(lbaf, "Relative Performance", "0x%x %s", ns->lbaf[i].rp,
|
||||
ns->lbaf[i].rp == 3 ? "Degraded" : ns->lbaf[i].rp == 2 ? "Good" :
|
||||
ns->lbaf[i].rp == 1 ? "Better" : "Best");
|
||||
obj_add_str(lbaf, "in use", i == flbas ? "yes" : "no");
|
||||
} else {
|
||||
obj_add_int(lbaf, "lbaf", i);
|
||||
obj_add_int(lbaf, "ms", le16_to_cpu(ns->lbaf[i].ms));
|
||||
obj_add_int(lbaf, "ds", ns->lbaf[i].ds);
|
||||
obj_add_int(lbaf, "rp", ns->lbaf[i].rp);
|
||||
obj_add_int(lbaf, "in_use", i == flbas);
|
||||
}
|
||||
|
||||
array_add_obj(lbafs, lbaf);
|
||||
}
|
||||
|
||||
static void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
|
||||
unsigned int lba_index, bool cap_only)
|
||||
{
|
||||
|
@ -306,15 +335,8 @@ static void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
|
|||
|
||||
obj_add_array(r, "lbafs", lbafs);
|
||||
|
||||
for (i = 0; i <= ns->nlbaf; i++) {
|
||||
struct json_object *lbaf = json_create_object();
|
||||
|
||||
obj_add_int(lbaf, "ms", le16_to_cpu(ns->lbaf[i].ms));
|
||||
obj_add_int(lbaf, "ds", ns->lbaf[i].ds);
|
||||
obj_add_int(lbaf, "rp", ns->lbaf[i].rp);
|
||||
|
||||
array_add_obj(lbafs, lbaf);
|
||||
}
|
||||
for (i = 0; i <= ns->nlbaf; i++)
|
||||
json_nvme_id_ns_lbaf(ns, i, lbafs);
|
||||
|
||||
d_json(ns->vs, strnlen((const char *)ns->vs, sizeof(ns->vs)), 16, 1, vs);
|
||||
obj_add_array(r, "vs", vs);
|
||||
|
@ -699,7 +721,7 @@ static void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
|
|||
nvme_uint128_t media_errors = le128_to_cpu(smart->media_errors);
|
||||
nvme_uint128_t num_err_log_entries = le128_to_cpu(smart->num_err_log_entries);
|
||||
|
||||
if (human()) {
|
||||
if (verbose_mode()) {
|
||||
struct json_object *crt = json_create_object();
|
||||
|
||||
obj_add_int(crt, "value", smart->critical_warning);
|
||||
|
@ -1357,7 +1379,7 @@ static void json_single_property(int offset, uint64_t value64)
|
|||
char json_str[STR_LEN];
|
||||
uint32_t value32 = (uint32_t)value64;
|
||||
|
||||
if (human()) {
|
||||
if (verbose_mode()) {
|
||||
json_single_property_human(offset, value64, r);
|
||||
} else {
|
||||
sprintf(json_str, "0x%02x", offset);
|
||||
|
@ -1836,7 +1858,7 @@ static void json_pevent_entry(void *pevent_log_info, __u8 action, __u32 size, co
|
|||
break;
|
||||
case NVME_PEL_POWER_ON_RESET_EVENT:
|
||||
json_pel_power_on_reset(pevent_log_info, offset, valid_attrs,
|
||||
pevent_entry_head->el, pevent_entry_head->vsil);
|
||||
pevent_entry_head->vsil, pevent_entry_head->el);
|
||||
break;
|
||||
case NVME_PEL_NSS_HW_ERROR_EVENT:
|
||||
json_pel_nss_hw_error(pevent_log_info, offset, valid_attrs);
|
||||
|
@ -2540,9 +2562,11 @@ static void json_print_nvme_subsystem_list(nvme_root_t r, bool show_ana)
|
|||
obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s));
|
||||
obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_nqn(s));
|
||||
|
||||
if (json_print_ops.flags & VERBOSE) {
|
||||
if (verbose_mode()) {
|
||||
obj_add_str(subsystem_attrs, "Model",
|
||||
nvme_subsystem_get_model(s));
|
||||
obj_add_str(subsystem_attrs, "Serial",
|
||||
nvme_subsystem_get_serial(s));
|
||||
obj_add_str(subsystem_attrs, "Firmware",
|
||||
nvme_subsystem_get_fw_rev(s));
|
||||
obj_add_str(subsystem_attrs, "IOPolicy",
|
||||
|
@ -2570,7 +2594,7 @@ static void json_ctrl_registers_cap(void *bar, struct json_object *r)
|
|||
{
|
||||
uint64_t cap = mmio_read64(bar + NVME_REG_CAP);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_cap((struct nvme_bar_cap *)&cap, obj_create_array_obj(r, "cap"));
|
||||
else
|
||||
obj_add_uint64(r, "cap", cap);
|
||||
|
@ -2580,7 +2604,7 @@ static void json_ctrl_registers_vs(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t vs = mmio_read32(bar + NVME_REG_VS);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_version(vs, obj_create_array_obj(r, "vs"));
|
||||
else
|
||||
obj_add_int(r, "vs", vs);
|
||||
|
@ -2590,7 +2614,7 @@ static void json_ctrl_registers_intms(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t intms = mmio_read32(bar + NVME_REG_INTMS);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_intms(intms, obj_create_array_obj(r, "intms"));
|
||||
else
|
||||
obj_add_int(r, "intms", intms);
|
||||
|
@ -2600,7 +2624,7 @@ static void json_ctrl_registers_intmc(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t intmc = mmio_read32(bar + NVME_REG_INTMC);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_intmc(intmc, obj_create_array_obj(r, "intmc"));
|
||||
else
|
||||
obj_add_int(r, "intmc", intmc);
|
||||
|
@ -2610,7 +2634,7 @@ static void json_ctrl_registers_cc(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t cc = mmio_read32(bar + NVME_REG_CC);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_cc(cc, obj_create_array_obj(r, "cc"));
|
||||
else
|
||||
obj_add_int(r, "cc", cc);
|
||||
|
@ -2620,7 +2644,7 @@ static void json_ctrl_registers_csts(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t csts = mmio_read32(bar + NVME_REG_CSTS);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_csts(csts, obj_create_array_obj(r, "csts"));
|
||||
else
|
||||
obj_add_int(r, "csts", csts);
|
||||
|
@ -2630,7 +2654,7 @@ static void json_ctrl_registers_nssr(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t nssr = mmio_read32(bar + NVME_REG_NSSR);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_nssr(nssr, obj_create_array_obj(r, "nssr"));
|
||||
else
|
||||
obj_add_int(r, "nssr", nssr);
|
||||
|
@ -2640,7 +2664,7 @@ static void json_ctrl_registers_nssd(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t nssd = mmio_read32(bar + NVME_REG_NSSD);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_nssd(nssd, obj_create_array_obj(r, "nssd"));
|
||||
else
|
||||
obj_add_int(r, "nssd", nssd);
|
||||
|
@ -2650,7 +2674,7 @@ static void json_ctrl_registers_crto(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t crto = mmio_read32(bar + NVME_REG_CRTO);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_crto(crto, obj_create_array_obj(r, "crto"));
|
||||
else
|
||||
obj_add_int(r, "crto", crto);
|
||||
|
@ -2660,7 +2684,7 @@ static void json_ctrl_registers_aqa(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t aqa = mmio_read32(bar + NVME_REG_AQA);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_aqa(aqa, obj_create_array_obj(r, "aqa"));
|
||||
else
|
||||
obj_add_int(r, "aqa", aqa);
|
||||
|
@ -2670,7 +2694,7 @@ static void json_ctrl_registers_asq(void *bar, struct json_object *r)
|
|||
{
|
||||
uint64_t asq = mmio_read64(bar + NVME_REG_ASQ);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_asq(asq, obj_create_array_obj(r, "asq"));
|
||||
else
|
||||
obj_add_uint64(r, "asq", asq);
|
||||
|
@ -2680,7 +2704,7 @@ static void json_ctrl_registers_acq(void *bar, struct json_object *r)
|
|||
{
|
||||
uint64_t acq = mmio_read64(bar + NVME_REG_ACQ);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_acq(acq, obj_create_array_obj(r, "acq"));
|
||||
else
|
||||
obj_add_uint64(r, "acq", acq);
|
||||
|
@ -2692,7 +2716,7 @@ static void json_ctrl_registers_cmbloc(void *bar, struct json_object *r)
|
|||
uint32_t cmbsz;
|
||||
bool support;
|
||||
|
||||
if (human()) {
|
||||
if (verbose_mode()) {
|
||||
cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
|
||||
support = nvme_registers_cmbloc_support(cmbsz);
|
||||
json_registers_cmbloc(cmbloc, support, obj_create_array_obj(r, "cmbloc"));
|
||||
|
@ -2705,7 +2729,7 @@ static void json_ctrl_registers_cmbsz(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_cmbsz(cmbsz, obj_create_array_obj(r, "cmbsz"));
|
||||
else
|
||||
obj_add_int(r, "cmbsz", cmbsz);
|
||||
|
@ -2715,7 +2739,7 @@ static void json_ctrl_registers_bpinfo(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t bpinfo = mmio_read32(bar + NVME_REG_BPINFO);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_bpinfo(bpinfo, obj_create_array_obj(r, "bpinfo"));
|
||||
else
|
||||
obj_add_int(r, "bpinfo", bpinfo);
|
||||
|
@ -2725,7 +2749,7 @@ static void json_ctrl_registers_bprsel(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t bprsel = mmio_read32(bar + NVME_REG_BPRSEL);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_bprsel(bprsel, obj_create_array_obj(r, "bprsel"));
|
||||
else
|
||||
obj_add_int(r, "bprsel", bprsel);
|
||||
|
@ -2735,7 +2759,7 @@ static void json_ctrl_registers_bpmbl(void *bar, struct json_object *r)
|
|||
{
|
||||
uint64_t bpmbl = mmio_read64(bar + NVME_REG_BPMBL);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_bpmbl(bpmbl, obj_create_array_obj(r, "bpmbl"));
|
||||
else
|
||||
obj_add_uint64(r, "bpmbl", bpmbl);
|
||||
|
@ -2745,7 +2769,7 @@ static void json_ctrl_registers_cmbmsc(void *bar, struct json_object *r)
|
|||
{
|
||||
uint64_t cmbmsc = mmio_read64(bar + NVME_REG_CMBMSC);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_cmbmsc(cmbmsc, obj_create_array_obj(r, "cmbmsc"));
|
||||
else
|
||||
obj_add_uint64(r, "cmbmsc", cmbmsc);
|
||||
|
@ -2755,7 +2779,7 @@ static void json_ctrl_registers_cmbsts(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t cmbsts = mmio_read32(bar + NVME_REG_CMBSTS);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_cmbsts(cmbsts, obj_create_array_obj(r, "cmbsts"));
|
||||
else
|
||||
obj_add_int(r, "cmbsts", cmbsts);
|
||||
|
@ -2765,7 +2789,7 @@ static void json_ctrl_registers_cmbebs(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t cmbebs = mmio_read32(bar + NVME_REG_CMBEBS);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_cmbebs(cmbebs, obj_create_array_obj(r, "cmbebs"));
|
||||
else
|
||||
obj_add_int(r, "cmbebs", cmbebs);
|
||||
|
@ -2775,7 +2799,7 @@ static void json_ctrl_registers_cmbswtp(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t cmbswtp = mmio_read32(bar + NVME_REG_CMBSWTP);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_cmbswtp(cmbswtp, obj_create_array_obj(r, "cmbswtp"));
|
||||
else
|
||||
obj_add_int(r, "cmbswtp", cmbswtp);
|
||||
|
@ -2785,7 +2809,7 @@ static void json_ctrl_registers_pmrcap(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t pmrcap = mmio_read32(bar + NVME_REG_PMRCAP);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_pmrcap(pmrcap, obj_create_array_obj(r, "pmrcap"));
|
||||
else
|
||||
obj_add_int(r, "pmrcap", pmrcap);
|
||||
|
@ -2795,7 +2819,7 @@ static void json_ctrl_registers_pmrctl(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_pmrctl(pmrctl, obj_create_array_obj(r, "pmrctl"));
|
||||
else
|
||||
obj_add_int(r, "pmrctl", pmrctl);
|
||||
|
@ -2807,7 +2831,7 @@ static void json_ctrl_registers_pmrsts(void *bar, struct json_object *r)
|
|||
uint32_t pmrctl;
|
||||
bool ready;
|
||||
|
||||
if (human()) {
|
||||
if (verbose_mode()) {
|
||||
pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
|
||||
ready = nvme_registers_pmrctl_ready(pmrctl);
|
||||
json_registers_pmrsts(pmrsts, ready, obj_create_array_obj(r, "pmrsts"));
|
||||
|
@ -2820,7 +2844,7 @@ static void json_ctrl_registers_pmrebs(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t pmrebs = mmio_read32(bar + NVME_REG_PMREBS);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_pmrebs(pmrebs, obj_create_array_obj(r, "pmrebs"));
|
||||
else
|
||||
obj_add_int(r, "pmrebs", pmrebs);
|
||||
|
@ -2830,7 +2854,7 @@ static void json_ctrl_registers_pmrswtp(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t pmrswtp = mmio_read32(bar + NVME_REG_PMRSWTP);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_pmrswtp(pmrswtp, obj_create_array_obj(r, "pmrswtp"));
|
||||
else
|
||||
obj_add_int(r, "pmrswtp", pmrswtp);
|
||||
|
@ -2840,7 +2864,7 @@ static void json_ctrl_registers_pmrmscl(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t pmrmscl = mmio_read32(bar + NVME_REG_PMRMSCL);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_pmrmscl(pmrmscl, obj_create_array_obj(r, "pmrmscl"));
|
||||
else
|
||||
obj_add_uint(r, "pmrmscl", pmrmscl);
|
||||
|
@ -2850,7 +2874,7 @@ static void json_ctrl_registers_pmrmscu(void *bar, struct json_object *r)
|
|||
{
|
||||
uint32_t pmrmscu = mmio_read32(bar + NVME_REG_PMRMSCU);
|
||||
|
||||
if (human())
|
||||
if (verbose_mode())
|
||||
json_registers_pmrmscu(pmrmscu, obj_create_array_obj(r, "pmrmscu"));
|
||||
else
|
||||
obj_add_uint(r, "pmrmscu", pmrmscu);
|
||||
|
@ -2995,14 +3019,13 @@ static void json_ctrl_register_human(int offset, uint64_t value, struct json_obj
|
|||
|
||||
static void json_ctrl_register(int offset, uint64_t value)
|
||||
{
|
||||
bool human = json_print_ops.flags & VERBOSE;
|
||||
struct json_object *r;
|
||||
char json_str[STR_LEN];
|
||||
|
||||
sprintf(json_str, "register: %#04x", offset);
|
||||
r = obj_create(json_str);
|
||||
|
||||
if (human) {
|
||||
if (verbose_mode()) {
|
||||
obj_add_uint64(r, nvme_register_to_string(offset), value);
|
||||
json_ctrl_register_human(offset, value, r);
|
||||
} else {
|
||||
|
@ -3130,7 +3153,7 @@ static void json_nvme_id_ctrl_nvm(struct nvme_id_ctrl_nvm *ctrl_nvm)
|
|||
obj_add_uint(r, "wzdsl", ctrl_nvm->wzdsl);
|
||||
obj_add_uint(r, "aocs", le16_to_cpu(ctrl_nvm->aocs));
|
||||
|
||||
if (json_print_ops.flags & VERBOSE) {
|
||||
if (verbose_mode()) {
|
||||
__u16 rsvd = (ctrl_nvm->aocs & 0xfffe) >> 1;
|
||||
__u8 ralbas = ctrl_nvm->aocs & 0x1;
|
||||
|
||||
|
@ -3712,6 +3735,72 @@ static void json_feature_show_fields_power_loss_signal(struct json_object *r, un
|
|||
nvme_pls_mode_to_string(NVME_GET(result, FEAT_PLS_MODE)));
|
||||
}
|
||||
|
||||
static void json_feat_perfc_std(struct json_object *r, struct nvme_std_perf_attr *data)
|
||||
{
|
||||
obj_add_str(r, "random 4 kib average read latency",
|
||||
nvme_feature_perfc_r4karl_to_string(data->r4karl));
|
||||
obj_add_uint_02x(r, "R4KARL", data->r4karl);
|
||||
}
|
||||
|
||||
static void json_feat_perfc_id_list(struct json_object *r, struct nvme_perf_attr_id_list *data)
|
||||
{
|
||||
int i;
|
||||
int attri_vs;
|
||||
char json_str[STR_LEN];
|
||||
struct json_object *paida = json_create_array();
|
||||
struct json_object *paide;
|
||||
|
||||
obj_add_str(r, "attribute type", nvme_feature_perfc_attrtyp_to_string(data->attrtyp));
|
||||
obj_add_uint_02x(r, "ATTRTYP", data->attrtyp);
|
||||
obj_add_int(r, "maximum saveable vendor specific performance attributes (MSVSPA)",
|
||||
data->msvspa);
|
||||
obj_add_int(r, "unused saveable vendor specific performance attributes (USVSPA)",
|
||||
data->usvspa);
|
||||
|
||||
obj_add_array(r, "performance attribute identifier list", paida);
|
||||
for (i = 0; i < ARRAY_SIZE(data->id_list); i++) {
|
||||
paide = json_create_object();
|
||||
array_add_obj(paida, paide);
|
||||
attri_vs = i + NVME_FEAT_PERFC_ATTRI_VS_MIN;
|
||||
sprintf(json_str, "performance attribute %02xh identifier (PA%02XHI)", attri_vs,
|
||||
attri_vs);
|
||||
obj_add_str(paide, json_str, util_uuid_to_string(data->id_list[i].id));
|
||||
}
|
||||
}
|
||||
|
||||
static void json_feat_perfc_vs(struct json_object *r, struct nvme_vs_perf_attr *data)
|
||||
{
|
||||
obj_add_str(r, "performance attribute identifier (PAID)", util_uuid_to_string(data->paid));
|
||||
obj_add_uint(r, "attribute length (ATTRL)", data->attrl);
|
||||
obj_d(r, "vendor specific (VS)", (unsigned char *)data->vs, data->attrl, 16, 1);
|
||||
}
|
||||
|
||||
static void json_feat_perfc(struct json_object *r, enum nvme_features_id fid, unsigned int result,
|
||||
struct nvme_perf_characteristics *data)
|
||||
{
|
||||
__u8 attri;
|
||||
bool rvspa;
|
||||
|
||||
nvme_feature_decode_perf_characteristics(result, &attri, &rvspa);
|
||||
|
||||
obj_add_str(r, "attribute index", nvme_feature_perfc_attri_to_string(attri));
|
||||
obj_add_uint_02x(r, "ATTRI", attri);
|
||||
|
||||
switch (attri) {
|
||||
case NVME_FEAT_PERFC_ATTRI_STD:
|
||||
json_feat_perfc_std(r, data->std_perf);
|
||||
break;
|
||||
case NVME_FEAT_PERFC_ATTRI_ID_LIST:
|
||||
json_feat_perfc_id_list(r, data->id_list);
|
||||
break;
|
||||
case NVME_FEAT_PERFC_ATTRI_VS_MIN ... NVME_FEAT_PERFC_ATTRI_VS_MAX:
|
||||
json_feat_perfc_vs(r, data->vs_perf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void json_host_metadata(struct json_object *r, enum nvme_features_id fid,
|
||||
struct nvme_host_metadata *data)
|
||||
{
|
||||
|
@ -3818,6 +3907,16 @@ static void json_feature_show_fields_fdp_events(struct json_object *r, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
static void json_feature_show_fields_bpwp(struct json_object *r, unsigned int result)
|
||||
{
|
||||
__u8 field;
|
||||
|
||||
field = NVME_FEAT_BPWPC_BP0WPS(result);
|
||||
obj_add_str(r, "Boot Partition 0 Write Protection State", nvme_bpwps_to_string(field));
|
||||
field = NVME_FEAT_BPWPC_BP1WPS(result);
|
||||
obj_add_str(r, "Boot Partition 1 Write Protection State", nvme_bpwps_to_string(field));
|
||||
}
|
||||
|
||||
static void json_feature_show(enum nvme_features_id fid, int sel, unsigned int result)
|
||||
{
|
||||
struct json_object *r;
|
||||
|
@ -3925,6 +4024,9 @@ static void json_feature_show_fields(enum nvme_features_id fid, unsigned int res
|
|||
case NVME_FEAT_FID_POWER_LOSS_SIGNAL:
|
||||
json_feature_show_fields_power_loss_signal(r, result);
|
||||
break;
|
||||
case NVME_FEAT_FID_PERF_CHARACTERISTICS:
|
||||
json_feat_perfc(r, fid, result, (struct nvme_perf_characteristics *)buf);
|
||||
break;
|
||||
case NVME_FEAT_FID_ENH_CTRL_METADATA:
|
||||
case NVME_FEAT_FID_CTRL_METADATA:
|
||||
case NVME_FEAT_FID_NS_METADATA:
|
||||
|
@ -3951,6 +4053,9 @@ static void json_feature_show_fields(enum nvme_features_id fid, unsigned int res
|
|||
case NVME_FEAT_FID_FDP_EVENTS:
|
||||
json_feature_show_fields_fdp_events(r, result, buf);
|
||||
break;
|
||||
case NVME_FEAT_FID_BP_WRITE_PROTECT:
|
||||
json_feature_show_fields_bpwp(r, result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -4406,7 +4511,7 @@ static void json_list_item(nvme_ns_t n)
|
|||
|
||||
static void json_print_list_items(nvme_root_t t)
|
||||
{
|
||||
if (json_print_ops.flags & VERBOSE)
|
||||
if (verbose_mode())
|
||||
json_detail_list(t);
|
||||
else
|
||||
json_simple_list(t);
|
||||
|
@ -4503,9 +4608,11 @@ static void json_simple_topology(nvme_root_t r)
|
|||
obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s));
|
||||
obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_nqn(s));
|
||||
|
||||
if (json_print_ops.flags & VERBOSE) {
|
||||
if (verbose_mode()) {
|
||||
obj_add_str(subsystem_attrs, "Model",
|
||||
nvme_subsystem_get_model(s));
|
||||
obj_add_str(subsystem_attrs, "Serial",
|
||||
nvme_subsystem_get_serial(s));
|
||||
obj_add_str(subsystem_attrs, "Firmware",
|
||||
nvme_subsystem_get_fw_rev(s));
|
||||
obj_add_str(subsystem_attrs, "IOPolicy",
|
||||
|
@ -4641,7 +4748,7 @@ static void json_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __
|
|||
sprintf(json_str, "%#x", result);
|
||||
obj_add_result(r, json_str);
|
||||
|
||||
if (json_print_ops.flags & VERBOSE) {
|
||||
if (verbose_mode()) {
|
||||
json_directive_show_fields(type, oper, result, buf, r);
|
||||
} else if (buf) {
|
||||
data = json_create_array();
|
||||
|
@ -4815,13 +4922,60 @@ static void json_output_perror(const char *msg, va_list ap)
|
|||
json_output_object(r);
|
||||
}
|
||||
|
||||
static char *trim_white_space(char *str)
|
||||
{
|
||||
char *end;
|
||||
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
/* Trim leading space */
|
||||
while (isspace((unsigned char)*str))
|
||||
str++;
|
||||
|
||||
/* All spaces */
|
||||
if (!*str)
|
||||
return str;
|
||||
|
||||
/* Trim trailing space */
|
||||
end = str + strlen(str) - 1;
|
||||
while (end > str && isspace((unsigned char)*end))
|
||||
end--;
|
||||
|
||||
/* Write new null terminator character */
|
||||
end[1] = '\0';
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static void json_output_key_value(const char *key, const char *val, va_list ap)
|
||||
{
|
||||
struct json_object *r = json_r ? json_r : json_create_object();
|
||||
|
||||
_cleanup_free_ char *value = NULL;
|
||||
_cleanup_free_ char *key_trim = trim_white_space(strdup(key));
|
||||
|
||||
if (vasprintf(&value, val, ap) < 0)
|
||||
value = NULL;
|
||||
|
||||
obj_add_str(r, key_trim ? key_trim : key, value ? value : "Could not allocate string");
|
||||
|
||||
obj_print(r);
|
||||
}
|
||||
|
||||
void json_show_init(void)
|
||||
{
|
||||
json_r = json_create_object();
|
||||
json_init++;
|
||||
|
||||
if (!json_r)
|
||||
json_r = json_create_object();
|
||||
}
|
||||
|
||||
void json_show_finish(void)
|
||||
{
|
||||
if (--json_init)
|
||||
return;
|
||||
|
||||
if (json_r)
|
||||
json_output_object(json_r);
|
||||
|
||||
|
@ -5179,6 +5333,7 @@ static struct print_ops json_print_ops = {
|
|||
.show_perror = json_output_perror,
|
||||
.show_status = json_output_status,
|
||||
.show_error_status = json_output_error_status,
|
||||
.show_key_value = json_output_key_value,
|
||||
};
|
||||
|
||||
struct print_ops *nvme_get_json_print_ops(nvme_print_flags_t flags)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue