|
36 | 36 |
|
37 | 37 | #include "cleanup.h" |
38 | 38 | #include "private.h" |
| 39 | +#include "private-fabrics.h" |
39 | 40 | #include "compiler_attributes.h" |
40 | 41 |
|
41 | 42 | const char *nvmf_dev = "/dev/nvme-fabrics"; |
@@ -1297,16 +1298,19 @@ static int nvmf_connect_disc_entry(libnvme_host_t h, |
1297 | 1298 | */ |
1298 | 1299 | #define DISCOVERY_HEADER_LEN 20 |
1299 | 1300 |
|
1300 | | -static int nvme_discovery_log(const struct libnvme_get_discovery_args *args, |
| 1301 | +static int nvme_discovery_log(libnvme_ctrl_t ctrl, |
| 1302 | + const struct nvmf_discovery_args *args, |
1301 | 1303 | struct nvmf_discovery_log **logp) |
1302 | 1304 | { |
1303 | | - struct libnvme_global_ctx *ctx = args->c->ctx; |
| 1305 | + struct libnvme_global_ctx *ctx = ctrl->ctx; |
1304 | 1306 | struct nvmf_discovery_log *log; |
1305 | 1307 | int retries = 0; |
1306 | 1308 | int err; |
1307 | | - const char *name = libnvme_ctrl_get_name(args->c); |
| 1309 | + const char *name = libnvme_ctrl_get_name(ctrl); |
1308 | 1310 | uint64_t genctr, numrec; |
1309 | | - struct libnvme_transport_handle *hdl = libnvme_ctrl_get_transport_handle(args->c); |
| 1311 | + struct libnvme_transport_handle *hdl; |
| 1312 | + |
| 1313 | + hdl = libnvme_ctrl_get_transport_handle(ctrl); |
1310 | 1314 | struct libnvme_passthru_cmd cmd; |
1311 | 1315 |
|
1312 | 1316 | log = __libnvme_alloc(sizeof(*log)); |
@@ -1421,37 +1425,57 @@ static void sanitize_discovery_log_entry(struct libnvme_global_ctx *ctx, |
1421 | 1425 | } |
1422 | 1426 | } |
1423 | 1427 |
|
1424 | | -__public int nvmf_get_discovery_log(libnvme_ctrl_t c, struct nvmf_discovery_log **logp, |
1425 | | - int max_retries) |
| 1428 | +__public int nvmf_discovery_args_create(struct nvmf_discovery_args **argsp) |
1426 | 1429 | { |
1427 | | - struct libnvme_get_discovery_args args = { |
1428 | | - .c = c, |
1429 | | - .max_retries = max_retries, |
1430 | | - .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, |
1431 | | - .lsp = NVMF_LOG_DISC_LSP_NONE, |
1432 | | - }; |
| 1430 | + struct nvmf_discovery_args *args; |
| 1431 | + |
| 1432 | + if (!argsp) |
| 1433 | + return -EINVAL; |
| 1434 | + |
| 1435 | + args = calloc(1, sizeof(*args)); |
| 1436 | + if (!args) |
| 1437 | + return -ENOMEM; |
1433 | 1438 |
|
| 1439 | + args->max_retries = 6; |
| 1440 | + args->timeout = NVME_DEFAULT_IOCTL_TIMEOUT; |
| 1441 | + args->lsp = NVMF_LOG_DISC_LSP_NONE; |
1434 | 1442 |
|
1435 | | - return nvmf_get_discovery_wargs(&args, logp); |
| 1443 | + *argsp = args; |
| 1444 | + return 0; |
| 1445 | +} |
| 1446 | + |
| 1447 | +__public void nvmf_discovery_args_free(struct nvmf_discovery_args *args) |
| 1448 | +{ |
| 1449 | + free(args); |
1436 | 1450 | } |
1437 | 1451 |
|
1438 | | -__public int nvmf_get_discovery_wargs(struct libnvme_get_discovery_args *args, |
1439 | | - struct nvmf_discovery_log **logp) |
| 1452 | +__public int nvmf_get_discovery_log(libnvme_ctrl_t ctrl, |
| 1453 | + const struct nvmf_discovery_args *args, |
| 1454 | + struct nvmf_discovery_log **logp) |
1440 | 1455 | { |
| 1456 | + static const struct nvmf_discovery_args defaults = { |
| 1457 | + .max_retries = 6, |
| 1458 | + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, |
| 1459 | + .lsp = NVMF_LOG_DISC_LSP_NONE, |
| 1460 | + }; |
1441 | 1461 | struct nvmf_discovery_log *log; |
1442 | 1462 | int err; |
1443 | 1463 |
|
1444 | | - err = nvme_discovery_log(args, &log); |
| 1464 | + if (!args) |
| 1465 | + args = &defaults; |
| 1466 | + |
| 1467 | + err = nvme_discovery_log(ctrl, args, &log); |
1445 | 1468 | if (err) |
1446 | 1469 | return err; |
1447 | 1470 |
|
1448 | 1471 | for (int i = 0; i < le64_to_cpu(log->numrec); i++) |
1449 | | - sanitize_discovery_log_entry(args->c->ctx, &log->entries[i]); |
| 1472 | + sanitize_discovery_log_entry(ctrl->ctx, &log->entries[i]); |
1450 | 1473 |
|
1451 | 1474 | *logp = log; |
1452 | 1475 | return 0; |
1453 | 1476 | } |
1454 | 1477 |
|
| 1478 | + |
1455 | 1479 | /** |
1456 | 1480 | * nvmf_get_tel() - Calculate the amount of memory needed for a DIE. |
1457 | 1481 | * @hostsymname: Symbolic name (may be NULL) |
@@ -1985,15 +2009,13 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx, |
1985 | 2009 | uint64_t numrec; |
1986 | 2010 | int err; |
1987 | 2011 |
|
1988 | | - struct libnvme_get_discovery_args args = { |
1989 | | - .c = c, |
1990 | | - .args_size = sizeof(args), |
| 2012 | + struct nvmf_discovery_args args = { |
1991 | 2013 | .max_retries = fctx->default_max_discovery_retries, |
1992 | 2014 | .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, |
1993 | 2015 | .lsp = NVMF_LOG_DISC_LSP_NONE, |
1994 | 2016 | }; |
1995 | 2017 |
|
1996 | | - err = nvmf_get_discovery_wargs(&args, &log); |
| 2018 | + err = nvme_discovery_log(c, &args, &log); |
1997 | 2019 | if (err) { |
1998 | 2020 | libnvme_msg(ctx, LOG_ERR, "failed to get discovery log: %s\n", |
1999 | 2021 | libnvme_strerror(err)); |
@@ -2668,15 +2690,13 @@ static int nbft_discovery(struct libnvme_global_ctx *ctx, |
2668 | 2690 | int ret; |
2669 | 2691 | int i; |
2670 | 2692 |
|
2671 | | - struct libnvme_get_discovery_args args = { |
2672 | | - .c = c, |
2673 | | - .args_size = sizeof(args), |
| 2693 | + struct nvmf_discovery_args args = { |
2674 | 2694 | .max_retries = 10 /* MAX_DISC_RETRIES */, |
2675 | 2695 | .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, |
2676 | 2696 | .lsp = NVMF_LOG_DISC_LSP_NONE, |
2677 | 2697 | }; |
2678 | 2698 |
|
2679 | | - ret = nvmf_get_discovery_wargs(&args, &log); |
| 2699 | + ret = nvme_discovery_log(c, &args, &log); |
2680 | 2700 | if (ret) { |
2681 | 2701 | libnvme_msg(ctx, LOG_ERR, |
2682 | 2702 | "Discovery Descriptor %d: failed to get discovery log: %s\n", |
|
0 commit comments