Skip to content

Commit

Permalink
nvme: Support show-regs for nvmeof
Browse files Browse the repository at this point in the history
Get properties only at offsets that support nvme fabric registers.
Since crto was not found in the nvmeof spec, it is removed.
Also, NSSR is only optional register. If the device is not supported by
the optional register, the error is ignored.

Reviewed-by: Steven Seungcheol <[email protected]>
Signed-off-by: Minsik Jeon <[email protected]>
  • Loading branch information
hmi-jeon authored and igaw committed Oct 2, 2024
1 parent 2371a4f commit b4628c3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
13 changes: 12 additions & 1 deletion nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,18 @@ bool nvme_is_fabrics_reg(int offset)
case NVME_REG_CC:
case NVME_REG_CSTS:
case NVME_REG_NSSR:
case NVME_REG_CRTO:
return true;
default:
break;
}

return false;
}

bool nvme_is_fabrics_optional_reg(int offset)
{
switch (offset) {
case NVME_REG_NSSR:
return true;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ void nvme_show_error_status(int status, const char *msg, ...);
void nvme_show_init(void);
void nvme_show_finish(void);
bool nvme_is_fabrics_reg(int offset);
bool nvme_is_fabrics_optional_reg(int offset);
bool nvme_registers_cmbloc_support(__u32 cmbsz);
bool nvme_registers_pmrctl_ready(__u32 pmrctl);
const char *nvme_degrees_string(long t);
Expand Down
16 changes: 12 additions & 4 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -5285,6 +5285,11 @@ static int nvme_get_single_property(int fd, struct get_reg_config *cfg, __u64 *v
if (!err)
return 0;

if (cfg->fabrics && nvme_is_fabrics_optional_reg(cfg->offset)) {
*value = -1;
return 0;
}

if (!cfg->fabrics &&
nvme_status_equals(err, NVME_STATUS_TYPE_NVME, NVME_SC_INVALID_FIELD)) {
*value = -1;
Expand Down Expand Up @@ -5316,6 +5321,9 @@ static int nvme_get_properties(int fd, void **pbar, struct get_reg_config *cfg)
memset(bar, 0xff, size);
for (offset = NVME_REG_CAP; offset <= NVME_REG_CMBSZ;
offset += is_64bit ? sizeof(uint64_t) : sizeof(uint32_t)) {
if (!nvme_is_fabrics_reg(offset))
continue;

cfg->offset = offset;
err = nvme_get_single_property(fd, cfg, &value);
if (err)
Expand Down Expand Up @@ -5380,12 +5388,12 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu

_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
bool fabrics = false;
void *bar;
int err;

struct get_reg_config cfg = {
.human_readable = false,
.fabrics = false,
};

NVME_ARGS(opts,
Expand All @@ -5406,14 +5414,14 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu

bar = mmap_registers(dev, false);
if (!bar) {
cfg.fabrics = true;
err = nvme_get_properties(dev_fd(dev), &bar, &cfg);
if (err)
return err;
fabrics = true;
}

nvme_show_ctrl_registers(bar, fabrics, flags);
if (fabrics)
nvme_show_ctrl_registers(bar, cfg.fabrics, flags);
if (cfg.fabrics)
free(bar);
else
munmap(bar, getpagesize());
Expand Down

0 comments on commit b4628c3

Please sign in to comment.