Skip to content

Commit 7b12a63

Browse files
committed
fabrics: add documentation to the new discovery/connnect API
Signed-off-by: Daniel Wagner <[email protected]>
1 parent b020730 commit 7b12a63

1 file changed

Lines changed: 245 additions & 45 deletions

File tree

libnvme/src/nvme/fabrics.h

Lines changed: 245 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,6 @@
2323
/* default to 600 seconds of reconnect attempts before giving up */
2424
#define NVMF_DEF_CTRL_LOSS_TMO 600
2525

26-
struct nvmf_context;
27-
28-
int nvmf_context_create(struct nvme_global_ctx *ctx,
29-
bool (*decide_retry)(struct nvmf_context *fctx, int err,
30-
void *user_data),
31-
void (*connected)(struct nvmf_context *fctx,
32-
struct nvme_ctrl *c, void *user_data),
33-
void (*already_connected)(struct nvmf_context *fctx,
34-
struct nvme_host *host, const char *subsysnqn,
35-
const char *transport, const char *traddr,
36-
const char *trsvcid, void *user_data),
37-
void *user_data, struct nvmf_context **fctxp);
38-
int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx,
39-
void (*discovery_log)(struct nvmf_context *fctx,
40-
bool connect,
41-
struct nvmf_discovery_log *log,
42-
uint64_t numrec, void *user_data),
43-
int (*parser_init)(struct nvmf_context *fctx,
44-
void *user_data),
45-
void (*parser_cleanup)(struct nvmf_context *fctx,
46-
void *user_data),
47-
int (*parser_next_line)(struct nvmf_context *fctx,
48-
void *user_data));
49-
int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx,
50-
int max_discovery_retries, int keep_alive_timeout);
51-
int nvmf_context_set_fabrics_config(struct nvmf_context *fctx,
52-
struct nvme_fabrics_config *cfg);
53-
int nvmf_context_set_connection(struct nvmf_context *fctx,
54-
const char *subsysnqn, const char *transport,
55-
const char *traddr, const char *trsvcid,
56-
const char *host_traddr, const char *host_iface);
57-
int nvmf_context_set_hostnqn(struct nvmf_context *fctx,
58-
const char *hostnqn, const char *hostid);
59-
int nvmf_context_set_crypto(struct nvmf_context *fctx,
60-
const char *hostkey, const char *ctrlkey,
61-
const char *keyring, const char *tls_key,
62-
const char *tls_key_identity);
63-
int nvmf_context_set_persistent(struct nvmf_context *fctx, bool persistent);
64-
int nvmf_context_set_device(struct nvmf_context *fctx, const char *device);
65-
6626
/**
6727
* struct nvme_fabrics_config - Defines all linux nvme fabrics initiator options
6828
* @queue_size: Number of IO queue entries
@@ -427,27 +387,267 @@ int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **uri);
427387
*/
428388
void nvme_free_uri(struct nvme_fabrics_uri *uri);
429389

390+
391+
/**
392+
* nvmf_get_default_trsvcid() - Get default transport service ID
393+
* @transport: Transport type string (e.g., "tcp", "rdma")
394+
* @discovery_ctrl: True if for discovery controller, false otherwise
395+
*
396+
* Returns the default trsvcid (port) for the given transport and controller type.
397+
*
398+
* Return: Allocated string with default trsvcid, or NULL on failure. Caller must free.
399+
*/
430400
char *nvmf_get_default_trsvcid(const char *transport, bool discovery_ctrl);
431401

402+
403+
/**
404+
* struct nvmf_context - Opaque context for NVMe-oF operations
405+
*
406+
* Used to manage state and configuration for NVMe-oF discovery and connect operations.
407+
*/
408+
struct nvmf_context;
409+
410+
/**
411+
* nvmf_context_create() - Create a new NVMe-oF context
412+
* @ctx: Global context
413+
* @decide_retry: Callback to decide if a retry should be attempted
414+
* @connected: Callback invoked when a connection is established
415+
* @already_connected: Callback invoked if already connected
416+
* @user_data: User data passed to callbacks
417+
* @fctxp: Pointer to store the created context
418+
*
419+
* Allocates and initializes a new NVMe-oF context for discovery/connect operations.
420+
*
421+
* Return: 0 on success, or a negative error code on failure.
422+
*/
423+
int nvmf_context_create(struct nvme_global_ctx *ctx,
424+
bool (*decide_retry)(struct nvmf_context *fctx, int err,
425+
void *user_data),
426+
void (*connected)(struct nvmf_context *fctx,
427+
struct nvme_ctrl *c, void *user_data),
428+
void (*already_connected)(struct nvmf_context *fctx,
429+
struct nvme_host *host, const char *subsysnqn,
430+
const char *transport, const char *traddr,
431+
const char *trsvcid, void *user_data),
432+
void *user_data, struct nvmf_context **fctxp);
433+
/**
434+
* nvmf_context_set_discovery_cbs() - Set discovery callbacks for context
435+
* @fctx: NVMe-oF context
436+
* @discovery_log: Callback for discovery log events
437+
* @parser_init: Callback to initialize parser
438+
* @parser_cleanup: Callback to cleanup parser
439+
* @parser_next_line: Callback to parse next line
440+
*
441+
* Sets the callbacks used during discovery operations for the given context.
442+
*
443+
* Return: 0 on success, or a negative error code on failure.
444+
*/
445+
int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx,
446+
void (*discovery_log)(struct nvmf_context *fctx,
447+
bool connect,
448+
struct nvmf_discovery_log *log,
449+
uint64_t numrec, void *user_data),
450+
int (*parser_init)(struct nvmf_context *fctx,
451+
void *user_data),
452+
void (*parser_cleanup)(struct nvmf_context *fctx,
453+
void *user_data),
454+
int (*parser_next_line)(struct nvmf_context *fctx,
455+
void *user_data));
456+
/**
457+
* nvmf_context_set_discovery_defaults() - Set default discovery parameters
458+
* @fctx: NVMe-oF context
459+
* @max_discovery_retries: Maximum number of discovery retries
460+
* @keep_alive_timeout: Keep-alive timeout in seconds
461+
*
462+
* Sets default values for discovery retries and keep-alive timeout.
463+
*
464+
* Return: 0 on success, or a negative error code on failure.
465+
*/
466+
int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx,
467+
int max_discovery_retries, int keep_alive_timeout);
468+
/**
469+
* nvmf_context_set_fabrics_config() - Set fabrics configuration for context
470+
* @fctx: NVMe-oF context
471+
* @cfg: Fabrics configuration to apply
472+
*
473+
* Applies the given fabrics configuration to the context.
474+
*
475+
* Return: 0 on success, or a negative error code on failure.
476+
*/
477+
int nvmf_context_set_fabrics_config(struct nvmf_context *fctx,
478+
struct nvme_fabrics_config *cfg);
479+
/**
480+
* nvmf_context_set_connection() - Set connection parameters for context
481+
* @fctx: NVMe-oF context
482+
* @subsysnqn: Subsystem NQN
483+
* @transport: Transport type
484+
* @traddr: Transport address
485+
* @trsvcid: Transport service ID
486+
* @host_traddr: Host transport address
487+
* @host_iface: Host interface
488+
*
489+
* Sets the connection parameters for the context.
490+
*
491+
* Return: 0 on success, or a negative error code on failure.
492+
*/
493+
int nvmf_context_set_connection(struct nvmf_context *fctx,
494+
const char *subsysnqn, const char *transport,
495+
const char *traddr, const char *trsvcid,
496+
const char *host_traddr, const char *host_iface);
497+
/**
498+
* nvmf_context_set_hostnqn() - Set host NQN and host ID for context
499+
* @fctx: NVMe-oF context
500+
* @hostnqn: Host NQN
501+
* @hostid: Host identifier
502+
*
503+
* Sets the host NQN and host ID for the context.
504+
*
505+
* Return: 0 on success, or a negative error code on failure.
506+
*/
507+
int nvmf_context_set_hostnqn(struct nvmf_context *fctx,
508+
const char *hostnqn, const char *hostid);
509+
/**
510+
* nvmf_context_set_crypto() - Set cryptographic parameters for context
511+
* @fctx: NVMe-oF context
512+
* @hostkey: Host key
513+
* @ctrlkey: Controller key
514+
* @keyring: Keyring identifier
515+
* @tls_key: TLS key
516+
* @tls_key_identity: TLS key identity
517+
*
518+
* Sets cryptographic and TLS parameters for the context.
519+
*
520+
* Return: 0 on success, or a negative error code on failure.
521+
*/
522+
int nvmf_context_set_crypto(struct nvmf_context *fctx,
523+
const char *hostkey, const char *ctrlkey,
524+
const char *keyring, const char *tls_key,
525+
const char *tls_key_identity);
526+
/**
527+
* nvmf_context_set_persistent() - Set persistence for context
528+
* @fctx: NVMe-oF context
529+
* @persistent: Whether to enable persistent connections
530+
*
531+
* Sets whether the context should use persistent connections.
532+
*
533+
* Return: 0 on success, or a negative error code on failure.
534+
*/
535+
int nvmf_context_set_persistent(struct nvmf_context *fctx, bool persistent);
536+
/**
537+
* nvmf_context_set_device() - Set device for context
538+
* @fctx: NVMe-oF context
539+
* @device: Device path or identifier
540+
*
541+
* Sets the device to be used by the context.
542+
*
543+
* Return: 0 on success, or a negative error code on failure.
544+
*/
545+
int nvmf_context_set_device(struct nvmf_context *fctx, const char *device);
546+
547+
/**
548+
* nvmf_discovery() - Perform NVMe-oF discovery
549+
* @ctx: Global context
550+
* @fctx: NVMe-oF context
551+
* @connect: Whether to connect discovered subsystems
552+
* @force: Force discovery even if already connected
553+
*
554+
* Performs discovery for NVMe-oF subsystems and optionally connects.
555+
*
556+
* Return: 0 on success, or a negative error code on failure.
557+
*/
432558
int nvmf_discovery(struct nvme_global_ctx *ctx,
433-
struct nvmf_context *fctx, bool connect, bool force);
559+
struct nvmf_context *fctx, bool connect, bool force);
560+
/**
561+
* nvmf_discovery_config_json() - Perform discovery using JSON config
562+
* @ctx: Global context
563+
* @fctx: NVMe-oF context
564+
* @connect: Whether to connect discovered subsystems
565+
* @force: Force discovery even if already connected
566+
*
567+
* Performs discovery using a JSON configuration.
568+
*
569+
* Return: 0 on success, or a negative error code on failure.
570+
*/
434571
int nvmf_discovery_config_json(struct nvme_global_ctx *ctx,
435-
struct nvmf_context *fctx, bool connect, bool force);
572+
struct nvmf_context *fctx, bool connect, bool force);
573+
/**
574+
* nvmf_discovery_config_file() - Perform discovery using config file
575+
* @ctx: Global context
576+
* @fctx: NVMe-oF context
577+
* @connect: Whether to connect discovered subsystems
578+
* @force: Force discovery even if already connected
579+
*
580+
* Performs discovery using a configuration file.
581+
*
582+
* Return: 0 on success, or a negative error code on failure.
583+
*/
436584
int nvmf_discovery_config_file(struct nvme_global_ctx *ctx,
437-
struct nvmf_context *fctx, bool connect, bool force);
585+
struct nvmf_context *fctx, bool connect, bool force);
586+
/**
587+
* nvmf_discovery_nbft() - Perform discovery using NBFT
588+
* @ctx: Global context
589+
* @fctx: NVMe-oF context
590+
* @connect: Whether to connect discovered subsystems
591+
* @nbft_path: Path to NBFT file
592+
*
593+
* Performs discovery using the specified NBFT file.
594+
*
595+
* Return: 0 on success, or a negative error code on failure.
596+
*/
438597
int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
439-
struct nvmf_context *fctx, bool connect, char *nbft_path);
598+
struct nvmf_context *fctx, bool connect, char *nbft_path);
440599

600+
/**
601+
* nvmf_connect() - Connect to NVMe-oF subsystem
602+
* @ctx: Global context
603+
* @fctx: NVMe-oF context
604+
*
605+
* Connects to the NVMe-oF subsystem using the provided context.
606+
*
607+
* Return: 0 on success, or a negative error code on failure.
608+
*/
441609
int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx);
610+
/**
611+
* nvmf_connect_config_json() - Connect using JSON config
612+
* @ctx: Global context
613+
* @fctx: NVMe-oF context
614+
*
615+
* Connects to the NVMe-oF subsystem using a JSON configuration.
616+
*
617+
* Return: 0 on success, or a negative error code on failure.
618+
*/
442619
int nvmf_connect_config_json(struct nvme_global_ctx *ctx,
443-
struct nvmf_context *fctx);
620+
struct nvmf_context *fctx);
444621

622+
623+
/**
624+
* struct nbft_file_entry - Linked list entry for NBFT files
625+
* @next: Pointer to next entry
626+
* @nbft: Pointer to NBFT info structure
627+
*/
445628
struct nbft_file_entry {
446629
struct nbft_file_entry *next;
447630
struct nbft_info *nbft;
448631
};
449632

633+
634+
/**
635+
* nvmf_nbft_read_files() - Read NBFT files from path
636+
* @path: Path to NBFT files
637+
* @head: Pointer to store linked list of NBFT file entries
638+
*
639+
* Reads NBFT files from the specified path and populates a linked list.
640+
*
641+
* Return: 0 on success, or a negative error code on failure.
642+
*/
450643
int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head);
644+
645+
/**
646+
* nvmf_nbft_free() - Free NBFT file entry list
647+
* @head: Head of the NBFT file entry list
648+
*
649+
* Frees all memory associated with the NBFT file entry list.
650+
*/
451651
void nvmf_nbft_free(struct nbft_file_entry *head);
452652

453653
#endif /* _LIBNVME_FABRICS_H */

0 commit comments

Comments
 (0)