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

nvme: Support show-regs for nvmeof #2521

Merged
merged 1 commit into from
Oct 2, 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
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:
igaw marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -322,6 +322,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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't seem necessary. nvme_get_properties operates only on offsets. Anyway, the whole logic is already a bit complex so I'd rather avoid this type of additional info passed into the getters.

Copy link
Contributor Author

@hmi-jeon hmi-jeon Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But If the device does not support NSSR, it will fail.
So If it is cfg.fabrics, In the nvme_get_single_property check optional register.
Is there a better fix?

Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, we already use it. This is so horrible code. I shouldn't have merged it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I understood it.
As you said, it looks like refactoring is needed.

};

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