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
101 changes: 37 additions & 64 deletions plugins/lm/lm-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ static int lm_create_cdq(int argc, char **argv, struct command *acmd, struct plu
"will write to invalid memory, inevitably leading to MMU faults or "
"worse.";

_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_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;
struct lba_migration_queue_entry_type_0 *queue = NULL;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
struct nvme_passthru_cmd cmd;
int err = -1;

struct config {
Expand Down Expand Up @@ -105,22 +106,17 @@ static int lm_create_cdq(int argc, char **argv, struct command *acmd, struct plu
return -ENOMEM;
}

struct nvme_lm_cdq_args args = {
.args_size = sizeof(args),
.sel = NVME_LM_SEL_CREATE_CDQ,
.mos = NVME_SET(cfg.qt, LM_QT),
.cntlid = cfg.cntlid,
.sz = cfg.sz,
.data = queue
};

err = nvme_lm_cdq(hdl, &args);
// FIX: cdqid (last argument) has to be adapted
nvme_init_lm_cdq(&cmd, NVME_LM_SEL_CREATE_CDQ, NVME_SET(cfg.qt, LM_QT),
cfg.cntlid, cfg.sz, queue, 0xff);
err = nvme_submit_admin_passthru(hdl, &cmd, NULL);
if (err < 0)
nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", nvme_strerror(errno));
else if (err)
nvme_show_status(err);
else
printf("Create CDQ Successful: CDQID=0x%04x\n", args.cdqid);
// FIX: where to get the CDQID
printf("Create CDQ Successful: CDQID=0x%04x\n", 0xff);

return err;
}
Expand All @@ -130,8 +126,9 @@ static int lm_delete_cdq(int argc, char **argv, struct command *acmd, struct plu
const char *desc = "Delete Controller Data Queue";
const char *cdqid = "Controller Data Queue ID";

_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;
struct nvme_passthru_cmd cmd;
int err = -1;

struct config {
Expand All @@ -151,13 +148,9 @@ static int lm_delete_cdq(int argc, char **argv, struct command *acmd, struct plu
if (err)
return err;

struct nvme_lm_cdq_args args = {
.args_size = sizeof(args),
.sel = NVME_LM_SEL_DELETE_CDQ,
.cdqid = cfg.cdqid,
};

err = nvme_lm_cdq(hdl, &args);
nvme_init_lm_cdq(&cmd, NVME_LM_SEL_DELETE_CDQ, 0, 0, 0, NULL,
cfg.cdqid);
err = nvme_submit_admin_passthru(hdl, &cmd, NULL);
if (err < 0)
nvme_show_error("ERROR: nvme_lm_cdq() failed: %s", nvme_strerror(errno));
else if (err > 0)
Expand Down Expand Up @@ -186,8 +179,9 @@ static int lm_track_send(int argc, char **argv, struct command *acmd, struct plu
const char *stop = "Equivalent to stop tracking with defaults";


_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;
struct nvme_passthru_cmd cmd;
int err = -1;

struct config {
Expand Down Expand Up @@ -240,14 +234,8 @@ static int lm_track_send(int argc, char **argv, struct command *acmd, struct plu
cfg.mos = NVME_SET(NVME_LM_LACT_STOP_LOGGING, LM_LACT);
}

struct nvme_lm_track_send_args args = {
.args_size = sizeof(args),
.cdqid = cfg.cdqid,
.sel = cfg.sel,
.mos = cfg.mos,
};

err = nvme_lm_track_send(hdl, &args);
nvme_init_lm_track_send(&cmd, cfg.sel, cfg.mos, cfg.cdqid);
err = nvme_submit_admin_passthru(hdl, &cmd, NULL);
if (err < 0)
nvme_show_error("ERROR: nvme_lm_track_send() failed %s", strerror(errno));
else if (err)
Expand Down Expand Up @@ -291,10 +279,11 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct
const char *numd = "Number of Dwords (NUMD)";
const char *input = "Controller State Data input file";

_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
_cleanup_file_ FILE *file = NULL;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_cleanup_file_ FILE *file = NULL;
struct nvme_passthru_cmd cmd;
void *data = NULL;
int err = -1;

Expand Down Expand Up @@ -390,21 +379,12 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct
}
}

struct nvme_lm_migration_send_args args = {
.args_size = sizeof(args),
.sel = cfg.sel,
.mos = NVME_SET(cfg.seqind, LM_SEQIND),
.cntlid = cfg.cntlid,
.csuuidi = cfg.csuuidi,
.uidx = cfg.uidx,
.stype = cfg.stype,
.offset = cfg.offset,
.dudmq = cfg.dudmq,
.numd = cfg.numd,
.data = data,
};

err = nvme_lm_migration_send(hdl, &args);
nvme_init_lm_migration_send(&cmd, cfg.sel,
NVME_SET(cfg.seqind, LM_SEQIND), cfg.cntlid,
cfg.stype, cfg.dudmq, cfg.csvi, cfg.csuuidi,
cfg.offset, cfg.uidx, data,
(cfg.numd << 2));
err = nvme_submit_admin_passthru(hdl, &cmd, NULL);
if (err < 0)
nvme_show_error("ERROR: nvme_lm_migration_send() failed %s", strerror(errno));
else if (err > 0)
Expand Down Expand Up @@ -433,13 +413,16 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct
const char *output = "Controller State Data output file";
const char *human_readable_info = "show info in readable format";

_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
_cleanup_file_ FILE *fd = NULL;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_cleanup_file_ FILE *fd = NULL;
struct nvme_passthru_cmd cmd;
nvme_print_flags_t flags;
void *data = NULL;
__u32 result = 0;
int err = -1;
__u16 mos;

struct config {
__u8 sel;
Expand Down Expand Up @@ -511,21 +494,11 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct
if (!data)
return -ENOMEM;

__u32 result = 0;
struct nvme_lm_migration_recv_args args = {
.args_size = sizeof(args),
.sel = cfg.sel,
.mos = NVME_SET(cfg.csvi, LM_GET_CONTROLLER_STATE_CSVI),
.uidx = cfg.uidx,
.csuuidi = cfg.csuuidi,
.offset = cfg.offset,
.cntlid = cfg.cntlid,
.numd = cfg.numd,
.data = data,
.result = &result,
};

err = nvme_lm_migration_recv(hdl, &args);
mos = NVME_SET(cfg.csvi, LM_GET_CONTROLLER_STATE_CSVI);
nvme_init_lm_migration_recv(&cmd, cfg.offset, mos, cfg.cntlid,
cfg.csuuidi, cfg.sel, cfg.uidx, 0, data,
(cfg.numd + 1) << 2);
err = nvme_submit_admin_passthru(hdl, &cmd, &result);
if (err < 0)
nvme_show_error("ERROR: nvme_lm_migration_recv() failed %s", strerror(errno));
else if (err)
Expand Down
Loading