3636
3737#include "cleanup.h"
3838#include "private.h"
39+ #include "private-fabrics.h"
3940#include "compiler_attributes.h"
4041
4142const char * nvmf_dev = "/dev/nvme-fabrics" ;
@@ -1297,16 +1298,17 @@ static int nvmf_connect_disc_entry(libnvme_host_t h,
12971298 */
12981299#define DISCOVERY_HEADER_LEN 20
12991300
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 ,
13011303 struct nvmf_discovery_log * * logp )
13021304{
1303- struct libnvme_global_ctx * ctx = args -> c -> ctx ;
1305+ struct libnvme_global_ctx * ctx = ctrl -> ctx ;
13041306 struct nvmf_discovery_log * log ;
13051307 int retries = 0 ;
13061308 int err ;
1307- const char * name = libnvme_ctrl_get_name (args -> c );
1309+ const char * name = libnvme_ctrl_get_name (ctrl );
13081310 uint64_t genctr , numrec ;
1309- struct libnvme_transport_handle * hdl = libnvme_ctrl_get_transport_handle (args -> c );
1311+ struct libnvme_transport_handle * hdl = libnvme_ctrl_get_transport_handle (ctrl );
13101312 struct libnvme_passthru_cmd cmd ;
13111313
13121314 log = __libnvme_alloc (sizeof (* log ));
@@ -1319,6 +1321,7 @@ static int nvme_discovery_log(const struct libnvme_get_discovery_args *args,
13191321 libnvme_msg (ctx , LOG_DEBUG , "%s: get header (try %d/%d)\n" ,
13201322 name , retries , args -> max_retries );
13211323 nvme_init_get_log_discovery (& cmd , 0 , log , DISCOVERY_HEADER_LEN );
1324+ cmd .timeout_ms = args -> timeout ;
13221325 err = libnvme_get_log (hdl , & cmd , false, DISCOVERY_HEADER_LEN );
13231326 if (err ) {
13241327 libnvme_msg (ctx , LOG_INFO ,
@@ -1350,6 +1353,7 @@ static int nvme_discovery_log(const struct libnvme_get_discovery_args *args,
13501353 name , numrec , genctr );
13511354
13521355 nvme_init_get_log_discovery (& cmd , sizeof (* log ), log -> entries , entries_size );
1356+ cmd .timeout_ms = args -> timeout ;
13531357 cmd .cdw10 |= NVME_FIELD_ENCODE (args -> lsp ,
13541358 NVME_LOG_CDW10_LSP_SHIFT ,
13551359 NVME_LOG_CDW10_LSP_MASK );
@@ -1368,6 +1372,7 @@ static int nvme_discovery_log(const struct libnvme_get_discovery_args *args,
13681372 libnvme_msg (ctx , LOG_DEBUG , "%s: get header again\n" , name );
13691373
13701374 nvme_init_get_log_discovery (& cmd , 0 , log , DISCOVERY_HEADER_LEN );
1375+ cmd .timeout_ms = args -> timeout ;
13711376 err = libnvme_get_log (hdl , & cmd , false, DISCOVERY_HEADER_LEN );
13721377 if (err ) {
13731378 libnvme_msg (ctx , LOG_INFO ,
@@ -1414,27 +1419,38 @@ static void sanitize_discovery_log_entry(struct nvmf_disc_log_entry *e)
14141419 }
14151420}
14161421
1417- __public int nvmf_get_discovery_log (libnvme_ctrl_t c , struct nvmf_discovery_log * * logp ,
1418- int max_retries )
1422+ __public int nvmf_discovery_args_create (struct nvmf_discovery_args * * argsp )
14191423{
1420- struct libnvme_get_discovery_args args = {
1421- .c = c ,
1422- .max_retries = max_retries ,
1423- .timeout = NVME_DEFAULT_IOCTL_TIMEOUT ,
1424- .lsp = NVMF_LOG_DISC_LSP_NONE ,
1425- };
1424+ struct nvmf_discovery_args * args ;
1425+
1426+ if (!argsp )
1427+ return - EINVAL ;
1428+
1429+ args = calloc (1 , sizeof (* args ));
1430+ if (!args )
1431+ return - ENOMEM ;
14261432
1433+ args -> max_retries = 6 ;
1434+ args -> timeout = NVME_DEFAULT_IOCTL_TIMEOUT ;
1435+ args -> lsp = NVMF_LOG_DISC_LSP_NONE ;
14271436
1428- return nvmf_get_discovery_wargs (& args , logp );
1437+ * argsp = args ;
1438+ return 0 ;
14291439}
14301440
1431- __public int nvmf_get_discovery_wargs (struct libnvme_get_discovery_args * args ,
1432- struct nvmf_discovery_log * * logp )
1441+ __public void nvmf_discovery_args_free (struct nvmf_discovery_args * args )
1442+ {
1443+ free (args );
1444+ }
1445+
1446+ __public int nvmf_get_discovery_log (libnvme_ctrl_t ctrl ,
1447+ struct nvmf_discovery_args * args ,
1448+ struct nvmf_discovery_log * * logp )
14331449{
14341450 struct nvmf_discovery_log * log ;
14351451 int err ;
14361452
1437- err = nvme_discovery_log (args , & log );
1453+ err = nvme_discovery_log (ctrl , args , & log );
14381454 if (err )
14391455 return err ;
14401456
@@ -1445,6 +1461,7 @@ __public int nvmf_get_discovery_wargs(struct libnvme_get_discovery_args *args,
14451461 return 0 ;
14461462}
14471463
1464+
14481465/**
14491466 * nvmf_get_tel() - Calculate the amount of memory needed for a DIE.
14501467 * @hostsymname: Symbolic name (may be NULL)
@@ -1978,15 +1995,13 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx,
19781995 uint64_t numrec ;
19791996 int err ;
19801997
1981- struct libnvme_get_discovery_args args = {
1982- .c = c ,
1983- .args_size = sizeof (args ),
1998+ struct nvmf_discovery_args args = {
19841999 .max_retries = fctx -> default_max_discovery_retries ,
1985- .result = 0 ,
1986- .lsp = 0 ,
2000+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT ,
2001+ .lsp = NVMF_LOG_DISC_LSP_NONE ,
19872002 };
19882003
1989- err = nvmf_get_discovery_wargs ( & args , & log );
2004+ err = nvme_discovery_log ( c , & args , & log );
19902005 if (err ) {
19912006 libnvme_msg (ctx , LOG_ERR , "failed to get discovery log: %s\n" ,
19922007 libnvme_strerror (err ));
@@ -2661,16 +2676,13 @@ static int nbft_discovery(struct libnvme_global_ctx *ctx,
26612676 int ret ;
26622677 int i ;
26632678
2664- struct libnvme_get_discovery_args args = {
2665- .c = c ,
2666- .args_size = sizeof (args ),
2679+ struct nvmf_discovery_args args = {
26672680 .max_retries = 10 /* MAX_DISC_RETRIES */ ,
2668- .result = 0 ,
26692681 .timeout = NVME_DEFAULT_IOCTL_TIMEOUT ,
2670- .lsp = 0 ,
2682+ .lsp = NVMF_LOG_DISC_LSP_NONE ,
26712683 };
26722684
2673- ret = nvmf_get_discovery_wargs ( & args , & log );
2685+ ret = nvme_discovery_log ( c , & args , & log );
26742686 if (ret ) {
26752687 libnvme_msg (ctx , LOG_ERR ,
26762688 "Discovery Descriptor %d: failed to get discovery log: %s\n" ,
0 commit comments