Skip to content
Merged
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
64 changes: 43 additions & 21 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,42 @@
return 0;
}

static int open_fallback_chardev(struct nvme_global_ctx *ctx,
__u32 nsid,
struct nvme_transport_handle **phdl)
{
struct nvme_transport_handle *hdl = *phdl;
int err;

if (nvme_transport_handle_is_chardev(hdl)) {
_cleanup_free_ char *cdev = NULL;

if (!nsid) {
nvme_show_error("char device not supported without --namespace-id");

Check failure on line 459 in nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 92 exceeds 80 columns
return -EINVAL;
}

if (asprintf(&cdev, "/dev/%sn%d",
nvme_transport_handle_get_name(hdl), nsid) < 0)
return -ENOMEM;

nvme_close(hdl);

err = nvme_open(ctx, cdev, &hdl);
if (err) {
*phdl = NULL;

nvme_show_error("could not open %s", cdev);
return err;
}

*phdl = hdl;
}

return 0;
}


int validate_output_format(const char *format, nvme_print_flags_t *flags)
{
nvme_print_flags_t f;
Expand Down Expand Up @@ -7364,27 +7400,9 @@
if (err)
return err;

if (nvme_transport_handle_is_chardev(hdl)) {
_cleanup_free_ char *cdev = NULL;

if (!cfg.namespace_id) {
nvme_show_error("char device not supported without --namespace-id");
return -EINVAL;
}

if (asprintf(&cdev, "/dev/%sn%d",
nvme_transport_handle_get_name(hdl),
cfg.namespace_id) < 0)
return -ENOMEM;

nvme_close(hdl);

err = nvme_open(ctx, cdev, &hdl);
if (err) {
nvme_show_error("could not open %s", cdev);
return err;
}
}
err = open_fallback_chardev(ctx, cfg.namespace_id, &hdl);
if (err)
return err;

err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
Expand Down Expand Up @@ -7681,6 +7699,10 @@
if (err)
return err;

err = open_fallback_chardev(ctx, cfg.namespace_id, &hdl);
if (err)
return err;

if (!cfg.namespace_id) {
err = nvme_get_nsid(hdl, &cfg.namespace_id);
if (err < 0) {
Expand Down