Skip to content

Commit f595a36

Browse files
committed
src: rework nvme_io_mgmt_recv commands
libnvme changed the API for the nvme_io_mgmt_recv commands. Update the callsite accordingly Signed-off-by: Dennis Maisenbacher <[email protected]>
1 parent 771d3d6 commit f595a36

2 files changed

Lines changed: 38 additions & 41 deletions

File tree

nvme.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,16 +2172,17 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug
21722172
const char *desc = "I/O Management Receive";
21732173
const char *data = "optional file for data (default stdout)";
21742174

2175-
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
21762175
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
2176+
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
21772177
_cleanup_free_ void *buf = NULL;
2178-
int err = -1;
2178+
struct nvme_passthru_cmd cmd;
21792179
_cleanup_fd_ int dfd = -1;
2180+
int err = -1;
21802181

21812182
struct config {
21822183
__u16 mos;
21832184
__u8 mo;
2184-
__u32 namespace_id;
2185+
__u32 nsid;
21852186
char *file;
21862187
__u32 data_len;
21872188
};
@@ -2191,18 +2192,18 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug
21912192
};
21922193

21932194
NVME_ARGS(opts,
2194-
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
2195-
OPT_SHRT("mos", 's', &cfg.mos, mos),
2196-
OPT_BYTE("mo", 'm', &cfg.mo, mo),
2197-
OPT_FILE("data", 'd', &cfg.file, data),
2198-
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));
2195+
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id_desired),
2196+
OPT_SHRT("mos", 's', &cfg.mos, mos),
2197+
OPT_BYTE("mo", 'm', &cfg.mo, mo),
2198+
OPT_FILE("data", 'd', &cfg.file, data),
2199+
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));
21992200

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

2204-
if (!cfg.namespace_id) {
2205-
err = nvme_get_nsid(hdl, &cfg.namespace_id);
2205+
if (!cfg.nsid) {
2206+
err = nvme_get_nsid(hdl, &cfg.nsid);
22062207
if (err < 0) {
22072208
nvme_show_perror("get-namespace-id");
22082209
return err;
@@ -2215,20 +2216,12 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug
22152216
return -ENOMEM;
22162217
}
22172218

2218-
struct nvme_io_mgmt_recv_args args = {
2219-
.args_size = sizeof(args),
2220-
.nsid = cfg.namespace_id,
2221-
.mos = cfg.mos,
2222-
.mo = cfg.mo,
2223-
.data_len = cfg.data_len,
2224-
.data = buf,
2225-
.timeout = nvme_cfg.timeout,
2226-
};
2227-
2228-
err = nvme_io_mgmt_recv(hdl, &args);
2219+
nvme_init_io_mgmt_recv(&cmd, cfg.nsid, cfg.mo, cfg.mos, buf,
2220+
cfg.data_len);
2221+
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
22292222
if (!err) {
22302223
printf("io-mgmt-recv: Success, mos:%u mo:%u nsid:%d\n",
2231-
cfg.mos, cfg.mo, cfg.namespace_id);
2224+
cfg.mos, cfg.mo, cfg.nsid);
22322225

22332226
if (cfg.file) {
22342227
dfd = open(cfg.file, O_WRONLY | O_CREAT, 0644);

plugins/fdp/fdp.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,17 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin
293293
const char *namespace_id = "Namespace identifier";
294294
const char *raw = "use binary output";
295295

296-
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
297296
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
297+
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
298298
_cleanup_free_ void *buf = NULL;
299299
struct nvme_fdp_ruh_status hdr;
300+
struct nvme_passthru_cmd cmd;
300301
nvme_print_flags_t flags;
301302
int err = -1;
302303
size_t len;
303304

304305
struct config {
305-
__u32 namespace_id;
306+
__u32 nsid;
306307
char *output_format;
307308
bool raw_binary;
308309
};
@@ -313,9 +314,9 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin
313314
};
314315

315316
OPT_ARGS(opts) = {
316-
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
317-
OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
318-
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
317+
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id),
318+
OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
319+
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
319320
OPT_END()
320321
};
321322

@@ -330,16 +331,17 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin
330331
if (cfg.raw_binary)
331332
flags = BINARY;
332333

333-
if (!cfg.namespace_id) {
334-
err = nvme_get_nsid(hdl, &cfg.namespace_id);
334+
if (!cfg.nsid) {
335+
err = nvme_get_nsid(hdl, &cfg.nsid);
335336
if (err < 0) {
336337
perror("get-namespace-id");
337338
return err;
338339
}
339340
}
340341

341-
err = nvme_fdp_reclaim_unit_handle_status(hdl,
342-
cfg.namespace_id, sizeof(hdr), &hdr);
342+
nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, &hdr,
343+
sizeof(hdr));
344+
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
343345
if (err) {
344346
nvme_show_status(err);
345347
return err;
@@ -351,8 +353,8 @@ static int fdp_status(int argc, char **argv, struct command *acmd, struct plugin
351353
if (!buf)
352354
return -ENOMEM;
353355

354-
err = nvme_fdp_reclaim_unit_handle_status(hdl,
355-
cfg.namespace_id, len, buf);
356+
nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, buf, len);
357+
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
356358
if (err) {
357359
nvme_show_status(err);
358360
return err;
@@ -369,15 +371,16 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin
369371
const char *namespace_id = "Namespace identifier";
370372
const char *_pids = "Comma-separated list of placement identifiers to update";
371373

372-
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
373374
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
375+
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
376+
struct nvme_passthru_cmd cmd;
374377
unsigned short pids[256];
375378
__u16 buf[256];
376-
int npids;
377379
int err = -1;
380+
int npids;
378381

379382
struct config {
380-
__u32 namespace_id;
383+
__u32 nsid;
381384
char *pids;
382385
};
383386

@@ -386,8 +389,8 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin
386389
};
387390

388391
OPT_ARGS(opts) = {
389-
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
390-
OPT_LIST("pids", 'p', &cfg.pids, _pids),
392+
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_id),
393+
OPT_LIST("pids", 'p', &cfg.pids, _pids),
391394
OPT_END()
392395
};
393396

@@ -404,8 +407,8 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin
404407
return -EINVAL;
405408
}
406409

407-
if (!cfg.namespace_id) {
408-
err = nvme_get_nsid(hdl, &cfg.namespace_id);
410+
if (!cfg.nsid) {
411+
err = nvme_get_nsid(hdl, &cfg.nsid);
409412
if (err < 0) {
410413
perror("get-namespace-id");
411414
return err;
@@ -415,7 +418,8 @@ static int fdp_update(int argc, char **argv, struct command *acmd, struct plugin
415418
for (unsigned int i = 0; i < npids; i++)
416419
buf[i] = cpu_to_le16(pids[i]);
417420

418-
err = nvme_fdp_reclaim_unit_handle_update(hdl, cfg.namespace_id, npids, buf);
421+
nvme_init_fdp_reclaim_unit_handle_status(&cmd, cfg.nsid, buf, npids);
422+
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
419423
if (err) {
420424
nvme_show_status(err);
421425
return err;

0 commit comments

Comments
 (0)