Skip to content
Closed
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
144 changes: 58 additions & 86 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,16 +2088,17 @@
const char *desc = "I/O Management Send";
const char *data = "optional file for data (default stdin)";

_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_fd_ int dfd = STDIN_FILENO;

Check failure on line 2093 in nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Missing a blank line after declarations
_cleanup_free_ void *buf = NULL;
struct nvme_passthru_cmd cmd;
int err = -1;
_cleanup_fd_ int dfd = STDIN_FILENO;

struct config {
__u32 nsid;
__u16 mos;
__u8 mo;
__u32 namespace_id;
char *file;
__u32 data_len;
};
Expand All @@ -2107,18 +2108,18 @@
};

NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SHRT("mos", 's', &cfg.mos, mos),
OPT_BYTE("mo", 'm', &cfg.mo, mo),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id_desired),
OPT_SHRT("mos", 's', &cfg.mos, mos),
OPT_BYTE("mo", 'm', &cfg.mo, mo),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));

err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
if (err)
return err;

if (!cfg.namespace_id) {
err = nvme_get_nsid(hdl, &cfg.namespace_id);
if (!cfg.nsid) {
err = nvme_get_nsid(hdl, &cfg.nsid);
if (err < 0) {
nvme_show_perror("get-namespace-id");
return err;
Expand All @@ -2145,20 +2146,11 @@
return err;
}

struct nvme_io_mgmt_send_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.mos = cfg.mos,
.mo = cfg.mo,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
};

err = nvme_io_mgmt_send(hdl, &args);
nvme_init_io_mgmt_send(&cmd, cfg.nsid, cfg.mo, cfg.mos, buf, cfg.data_len);
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
if (!err)
printf("io-mgmt-send: Success, mos:%u mo:%u nsid:%d\n",
cfg.mos, cfg.mo, cfg.namespace_id);
cfg.mos, cfg.mo, cfg.nsid);
else if (err > 0)
nvme_show_status(err);
else
Expand All @@ -2172,16 +2164,17 @@
const char *desc = "I/O Management Receive";
const char *data = "optional file for data (default stdout)";

_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_free_ void *buf = NULL;
int err = -1;
struct nvme_passthru_cmd cmd;
_cleanup_fd_ int dfd = -1;
int err = -1;

struct config {
__u16 mos;
__u8 mo;
__u32 namespace_id;
__u32 nsid;
char *file;
__u32 data_len;
};
Expand All @@ -2191,18 +2184,18 @@
};

NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SHRT("mos", 's', &cfg.mos, mos),
OPT_BYTE("mo", 'm', &cfg.mo, mo),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id_desired),
OPT_SHRT("mos", 's', &cfg.mos, mos),
OPT_BYTE("mo", 'm', &cfg.mo, mo),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));

err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
if (err)
return err;

if (!cfg.namespace_id) {
err = nvme_get_nsid(hdl, &cfg.namespace_id);
if (!cfg.nsid) {
err = nvme_get_nsid(hdl, &cfg.nsid);
if (err < 0) {
nvme_show_perror("get-namespace-id");
return err;
Expand All @@ -2215,20 +2208,12 @@
return -ENOMEM;
}

struct nvme_io_mgmt_recv_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.mos = cfg.mos,
.mo = cfg.mo,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
};

err = nvme_io_mgmt_recv(hdl, &args);
nvme_init_io_mgmt_recv(&cmd, cfg.nsid, cfg.mo, cfg.mos, buf,
cfg.data_len);
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
if (!err) {
printf("io-mgmt-recv: Success, mos:%u mo:%u nsid:%d\n",
cfg.mos, cfg.mo, cfg.namespace_id);
cfg.mos, cfg.mo, cfg.nsid);

if (cfg.file) {
dfd = open(cfg.file, O_WRONLY | O_CREAT, 0644);
Expand Down Expand Up @@ -7814,33 +7799,35 @@
"the issuing controller are notified.";
const char *rrela = "reservation release action";

_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
int err;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
struct nvme_passthru_cmd cmd;
nvme_print_flags_t flags;
__le64 payload[1];
int err;

struct config {
__u32 namespace_id;
__u32 nsid;
__u64 crkey;
__u8 rtype;
__u8 rrela;
__u8 iekey;
};

struct config cfg = {
.namespace_id = 0,
.nsid = 0,
.crkey = 0,
.rtype = 0,
.rrela = 0,
.iekey = 0,
};

NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_SUFFIX("crkey", 'c', &cfg.crkey, crkey),
OPT_BYTE("rtype", 't', &cfg.rtype, rtype),
OPT_BYTE("rrela", 'a', &cfg.rrela, rrela),
OPT_FLAG("iekey", 'i', &cfg.iekey, iekey));
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_desired),
OPT_SUFFIX("crkey", 'c', &cfg.crkey, crkey),
OPT_BYTE("rtype", 't', &cfg.rtype, rtype),
OPT_BYTE("rrela", 'a', &cfg.rrela, rrela),
OPT_FLAG("iekey", 'i', &cfg.iekey, iekey));

err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
if (err)
Expand All @@ -7852,8 +7839,8 @@
return err;
}

if (!cfg.namespace_id) {
err = nvme_get_nsid(hdl, &cfg.namespace_id);
if (!cfg.nsid) {
err = nvme_get_nsid(hdl, &cfg.nsid);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(-err));
return err;
Expand All @@ -7864,17 +7851,9 @@
return -EINVAL;
}

struct nvme_resv_release_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.rtype = cfg.rtype,
.rrela = cfg.rrela,
.iekey = !!cfg.iekey,
.crkey = cfg.crkey,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_resv_release(hdl, &args);
nvme_init_resv_release(&cmd, cfg.nsid, cfg.rrela, cfg.iekey, false,
cfg.rtype, cfg.crkey, payload);
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
if (err < 0)
nvme_show_error("reservation release: %s", nvme_strerror(-err));
else if (err != 0)
Expand All @@ -7894,32 +7873,33 @@
const char *numd = "number of dwords to transfer";
const char *eds = "request extended data structure";

_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_free_ struct nvme_resv_status *status = NULL;
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
struct nvme_passthru_cmd cmd;
nvme_print_flags_t flags;
int err, size;

struct config {
__u32 namespace_id;
__u32 nsid;
__u32 numd;
__u8 eds;
bool raw_binary;
};

struct config cfg = {
.namespace_id = 0,
.nsid = 0,

Check failure on line 7892 in nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Missing a blank line after declarations
.numd = 0,
.eds = false,
.raw_binary = false,
};

NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_UINT("numd", 'd', &cfg.numd, numd),
OPT_FLAG("eds", 'e', &cfg.eds, eds),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump));
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id_desired),
OPT_UINT("numd", 'd', &cfg.numd, numd),
OPT_FLAG("eds", 'e', &cfg.eds, eds),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump));

err = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
if (err)
Expand All @@ -7934,8 +7914,8 @@
if (cfg.raw_binary)
flags = BINARY;

if (!cfg.namespace_id) {
err = nvme_get_nsid(hdl, &cfg.namespace_id);
if (!cfg.nsid) {
err = nvme_get_nsid(hdl, &cfg.nsid);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(-err));
return err;
Expand Down Expand Up @@ -7966,16 +7946,8 @@
if (!status)
return -ENOMEM;

struct nvme_resv_report_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.eds = cfg.eds,
.len = size,
.report = status,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_resv_report(hdl, &args);
nvme_init_resv_report(&cmd, cfg.nsid, cfg.eds, false, status, size);
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
if (!err)
nvme_show_resv_report(status, size, cfg.eds, flags);
else if (err > 0)
Expand Down
Loading